BASICally Melodic

Type
Sound
Category
Four-voice music player in BASIC
Author
Clayton Walnum
Published in
ANALOG Computing, May 1987; GIA Software version (1989) on the Czech disk magazine Flop, issue 5
Year
1987
Language
Atari BASIC
Requirements
Any 8-bit Atari with Atari BASIC

About the program

Clayton Walnum was an ANALOG Computing stalwart. This listing's REMs credit it "(c) 1987 by Clayton Walnum, ANALOG Computing 5/1987", and GIA Software's 1989 note says it's for all XL/XE machines. It shows that you don't need machine language to get a proper little arrangement out of POKEY. The engine is only nine lines long (110–190). Everything else is the score: 18 numbered "measures" of DATA, each with eight time steps, and each step giving a pitch and a volume for all four voices.

The copy reproduced here is the one GIA Software prepared, which was distributed on the Czech disk magazine Flop 5.

Typing it in

The REM banner in lines 10–30 uses CTRL-Q, CTRL-R, CTRL-E, CTRL-Z and CTRL-C box-drawing characters, and is purely decorative. Everything else is plain numbers. Every DATA line must hold exactly eight values, because a missing or extra number shifts every following step into the wrong voice. The REM MEASURE n lines between the blocks make it easy to check your typing against the listing a bar at a time.

How to use it

Just RUN it and listen. The tune loops forever. Press BREAK, then type END, to stop the sound.

How it works

  • One step = one DATA line: line 120 reads eight numbers, which are a pitch and a volume for each of voices 0–3.
  • Drums on voice 0: SOUND 0,F0,0,P0 uses distortion 0, POKEY's noise setting. The pitches 50 and 1 give two different drum sounds, and a volume of 0 makes a rest.
  • Articulation: line 130 sounds each voice at the volume from the DATA, then line 150 immediately resets the volumes to fixed levels (4, 8 and 6). A step with volume 0 therefore makes a tiny gap, which re-attacks a note of the same pitch, while a non-zero value just carries the note on.
  • Song structure with TRAP: when READ runs off the end of the DATA, error 6 jumps to line 180. That sets PASS=2 and restarts from line 1370 (measure 5). On this second pass, line 140 brings in voice 3, the melody. When the data runs out again, line 190 resets everything and the song starts from the top. Using TRAP as a loop counter keeps the engine tiny.
  • Tempo: the FOR X=1 TO 50 delay in line 160 sets the speed. Lower it to play faster.

Variations to try

Write your own tune. Keep the eight-number format, use distortion-10 pitch values for the tonal voices (for example 121 = middle C, 108 = D, 96 = E, 81 = G) and adjust the RESTORE 1370 in line 180 to the line where you want the repeat to begin.

Listing

10 REM {CTRL-Q}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-E}
20 REM | BASICally Melodic |
30 REM {CTRL-Z}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-C}
40 REM - for all ATARI XL/XE
50 REM (c) 1987
60 REM by Clayton Walnum
70 REM ANALOG Computing 5/1987
80 REM (p) 1989
90 REM by GIA Software
110 TRAP 180
120 READ F0,P0,F1,P1,F2,P2,F3,P3
130 SOUND 0,F0,0,P0:SOUND 1,F1,10,P1:SOUND 2,F2,10,P2
140 IF PASS=2 THEN SOUND 3,F3,10,6
150 SOUND 0,F0,0,4:SOUND 1,F1,10,8:SOUND 2,F2,10,6
160 FOR X=1 TO 50:NEXT X
170 GOTO 120
180 PASS=2:RESTORE 1370:TRAP 190:GOTO 120
190 RESTORE:PASS=1:SOUND 3,0,0,0:GOTO 110
999 STOP
1000 REM MEASURE 1
1010 DATA 50,4,0,0,0,0,0,0
1020 DATA 0,0,0,0,0,0,0,0
1030 DATA 1,4,0,0,0,0,0,0
1040 DATA 1,0,0,0,0,0,0,0
1050 DATA 50,4,0,0,0,0,0,0
1060 DATA 50,0,0,0,0,0,0,0
1070 DATA 1,4,0,0,0,0,0,0
1080 DATA 1,0,0,0,0,0,0,0
1090 REM MEASURE 2
1100 DATA 50,4,0,0,0,0,0,0
1110 DATA 0,0,0,0,0,0,0,0
1120 DATA 1,4,0,0,0,0,0,0
1130 DATA 1,0,0,0,0,0,0,0
1140 DATA 50,4,0,0,0,0,0,0
1150 DATA 50,0,0,0,0,0,0,0
1160 DATA 1,4,0,0,0,0,0,0
1170 DATA 1,0,0,0,0,0,0,0
1180 REM MEASURE 3
1190 DATA 50,4,0,0,144,6,0,0
1200 DATA 0,0,0,0,144,6,0,0
1210 DATA 1,4,0,0,0,0,0,0
1220 DATA 1,0,0,0,144,6,0,0
1230 DATA 50,4,0,0,144,0,0,0
1240 DATA 50,0,0,0,144,6,0,0
1250 DATA 1,4,0,0,0,0,0,0
1260 DATA 1,0,0,8,0,0,0,0
1270 REM MEASURE 4
1280 DATA 50,4,0,0,144,6,0,0
1290 DATA 0,0,0,0,144,6,0,0
1300 DATA 1,4,0,0,0,0,0,0
1310 DATA 1,0,0,0,144,6,0,0
1320 DATA 50,4,0,0,144,0,0,0
1330 DATA 50,0,0,0,144,6,0,0
1340 DATA 1,4,0,0,0,0,0,0
1350 DATA 1,0,0,8,0,0,0,0
1360 REM MEASURE 5
1370 DATA 50,4,0,0,144,6,0,0
1380 DATA 0,0,0,0,144,6,0,0
1390 DATA 1,4,60,0,0,0,47,4
1400 DATA 1,0,53,0,144,6,45,4
1410 DATA 50,4,47,0,144,0,40,4
1420 DATA 50,0,53,0,144,6,45,4
1430 DATA 1,4,60,0,0,0,47,4
1440 DATA 1,0,47,8,0,0,40,4
1450 REM MEASURE 6
1460 DATA 50,4,47,8,144,6,40,4
1470 DATA 0,0,47,8,144,6,40,4
1480 DATA 1,4,60,0,0,0,47,4
1490 DATA 1,0,53,0,144,6,45,4
1500 DATA 50,4,47,0,144,0,40,4
1510 DATA 50,0,53,0,144,6,45,4
1520 DATA 1,4,60,0,0,0,47,4
1530 DATA 1,0,47,8,0,0,40,4
1540 REM MEASURE 7
1550 DATA 50,4,47,8,192,6,64,4
1560 DATA 0,0,47,8,192,6,60,4
1570 DATA 1,4,64,0,0,0,53,4
1580 DATA 1,0,60,0,192,6,47,4
1590 DATA 50,4,53,8,192,0,45,4
1600 DATA 50,0,60,0,192,6,40,4
1610 DATA 1,4,64,0,0,0,35,4
1620 DATA 1,0,53,0,0,0,31,4
1630 REM MEASURE 8
1640 DATA 50,4,53,8,192,6,35,4
1650 DATA 0,0,53,8,192,6,40,4
1660 DATA 1,4,64,0,0,0,45,4
1670 DATA 1,0,60,0,192,6,47,4
1680 DATA 50,4,53,0,192,0,53,4
1690 DATA 50,0,60,0,192,6,60,4
1700 DATA 1,4,64,0,0,0,64,4
1710 DATA 1,0,53,0,0,0,64,4
1720 REM MEASURE 9
1730 DATA 50,4,53,8,182,6,72,4
1740 DATA 0,0,53,8,182,6,64,4
1750 DATA 1,4,72,0,0,0,60,4
1760 DATA 1,0,64,0,182,6,53,3
1770 DATA 50,4,60,0,182,0,47,4
1780 DATA 50,0,64,0,182,6,53,4
1790 DATA 1,4,72,0,0,0,60,4
1800 DATA 1,0,60,0,0,0,47,4
1810 REM MEASURE 10
1820 DATA 50,4,60,8,182,6,47,4
1830 DATA 0,0,60,8,182,6,47,4
1840 DATA 1,4,72,0,0,0,60,4
1850 DATA 1,0,64,0,182,6,53,4
1860 DATA 50,4,60,0,182,0,47,4
1870 DATA 50,0,64,0,182,6,53,4
1880 DATA 1,4,72,8,0,0,60,4
1890 DATA 1,0,72,8,0,0,60,4
1900 REM MEASURE 11
1910 DATA 50,4,81,8,162,6,29,4
1920 DATA 0,0,81,8,162,6,57,4
1930 DATA 1,4,81,8,0,0,31,4
1940 DATA 1,0,81,8,162,6,64,4
1950 DATA 50,4,81,8,162,0,35,4
1960 DATA 50,0,81,8,162,6,72,4
1970 DATA 1,4,81,8,0,0,40,4
1980 DATA 1,0,81,8,0,0,81,4
1990 REM MEASURE 12
2000 DATA 50,4,91,8,162,6,45,4
2010 DATA 0,0,91,8,162,6,91,4
2020 DATA 1,4,91,8,0,0,47,4
2030 DATA 1,0,91,8,162,6,96,4
2040 DATA 50,4,81,8,162,0,53,4
2050 DATA 50,0,91,8,162,6,108,4
2060 DATA 1,4,91,8,0,0,60,4
2070 DATA 1,0,91,8,0,0,121,4
2080 REM MEASURE 13
2090 DATA 50,4,96,8,192,6,0,0
2100 DATA 0,0,96,8,192,6,0,0
2110 DATA 1,4,96,8,0,0,0,0
2120 DATA 1,0,96,8,192,6,0,0
2130 DATA 50,4,96,8,192,0,0,0
2140 DATA 50,0,96,8,192,6,0,0
2150 DATA 1,4,96,8,0,0,0,0
2160 DATA 1,0,96,8,0,0,0,0
2170 REM MEASURE 14
2180 DATA 50,4,96,8,192,6,76,4
2190 DATA 0,0,96,8,192,6,76,4
2200 DATA 1,4,96,8,0,0,76,4
2210 DATA 1,0,96,8,192,6,76,4
2220 DATA 50,4,96,8,192,0,76,4
2230 DATA 50,0,96,8,192,6,76,4
2240 DATA 1,4,96,8,0,0,76,4
2250 DATA 1,0,96,8,0,0,76,4
2260 REM MEASURE 15
2270 DATA 50,4,76,8,192,6,64,4
2280 DATA 0,0,76,8,192,6,64,4
2290 DATA 1,4,76,8,0,0,64,4
2300 DATA 1,0,76,8,192,6,64,4
2310 DATA 50,4,76,8,192,0,64,4
2320 DATA 50,0,76,8,192,6,64,4
2330 DATA 1,4,76,8,0,0,64,4
2340 DATA 1,0,76,8,0,0,64,4
2350 REM MEASURE 16
2360 DATA 50,4,64,8,192,6,53,4
2370 DATA 0,0,64,8,192,6,53,4
2380 DATA 1,4,64,8,0,0,53,4
2390 DATA 1,0,64,8,192,6,53,4
2400 DATA 50,4,64,8,192,0,53,4
2410 DATA 50,0,64,8,192,6,53,4
2420 DATA 1,4,64,8,0,0,53,4
2430 DATA 1,0,64,8,0,0,53,4
2440 REM MEASURE 17
2450 DATA 50,4,53,8,192,6,45,4
2460 DATA 0,0,53,8,192,6,45,4
2470 DATA 1,4,53,8,0,0,45,4
2480 DATA 1,0,53,8,192,6,45,4
2490 DATA 50,4,53,8,192,0,45,4
2500 DATA 50,0,53,8,192,6,45,4
2510 DATA 1,4,53,8,0,0,45,4
2520 DATA 1,0,53,8,0,0,45,4
2530 REM MEASURE 18
2540 DATA 50,4,53,8,192,6,45,4
2550 DATA 0,0,53,8,192,6,45,4
2560 DATA 1,4,53,8,0,0,45,4
2570 DATA 1,0,53,8,192,6,45,4
2580 DATA 50,4,53,8,192,0,45,4
2590 DATA 50,0,53,8,192,6,45,4
2600 DATA 1,4,53,8,0,0,45,4
2610 DATA 1,0,53,8,0,0,45,4

Credits