Some experiments on My4TH (2): Playing music

In the 1960s and 1970s, Broadcast radio receiver was an essential tool for debugging computer memory. Users could use an ordinary broadcast radio to monitor the electromagnetic radiation emitted by the computer, confirming the operational status of magnetic core memory and the bus. Users quickly discovered that this phenomenon could be used to play music (e.g. here and here).

While My4TH utilizes modern EPROM and SRAM, its bus still generates some electromagnetic radiation. Experiments have shown that a regular AM radio can pick up the electromagnetic radiation caused by status changes in the bus.

By changing the final values of a nested loop, it is possible to control the frequency and duration of the state changes on the bus. This allows music to be played in a radio.

With the power of Forth, musical scores can be conveniently transcribed into programs:

250 value tempo \ smaller is faster
: delay ( n -- ) 0 do loop ;
: tone ( duration tone -- ) swap tempo * over /
   0 do dup delay loop drop ;
   
: P ( duration -- ) tempo * delay ; \ pausa
: D5 7 tone ; : C5 8 tone ; : B4 9 tone ; : A4 10 tone ;
: G4 12 tone ; : F4 14 tone ; : E4 15 tone ; : D4 17 tone ;
: C4 20 tone ; : B3 21 tone ; : A3 24 tone ; : G3 27 tone ;
: F3 31 tone ; : E3 33 tone ; : D3 38 tone ; : C3 43 tone ;
: B2 46 tone ; : A2 51 tone ; : G2 58 tone ; : F2 66 tone ;
: E2 70 tone ; : D2 80 tone ; : C2 90 tone ; ( duration -- )
: F#3 29 tone ; : G#3 26 tone ;

The following example runs at 16MHz, playing “An die Freude”:

: freude1 8 e4 8 e4 8 f4 8 g4 8 g4 8 f4 8 e4 8 d4
   8 c4 8 c4 8 d4 8 e4 ;
: freude2 freude1 12 e4 4 d4 16 d4 ;
: freude3 freude1 12 d4 4 c4 16 c4 ;
: freude4 8 d4 8 d4 8 e4 8 c4 8 d4 4 e4 4 f4 8 e4 8 c4
   8 d4 4 e4 4 f4 8 e4 8 d4 8 c4 8 d4 16 g3 ;
: freude tempo 200 to tempo freude2 freude3 freude4 freude3
   to tempo ;

freude

(Download video here in case of network error)