Random Music (White, Brown and 1/F)
- Type
- Sound
- Category
- Algorithmic music generator
- Author
- Charles Jackson
- Published in
- Antic, November 1983 (Vol. 2, No. 8)
- Year
- 1983
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit, Atari BASIC
About the program
"Can an Atari make a melody?" Charles Jackson, a recent UCLA graduate who had bought his Atari 800 for coursework, asked the question in Antic in November 1983. He began with one-line random tune generators, such as
1 SOUND 0,PEEK(53770),10,10:WAIT=2^3:GOTO 1
which uses the POKEY random-number register at 53770. He then explained why they don't sound like music: the notes aren't on a scale, the jumps are too big, and the "melody goes nowhere". Listing 1 compares three ways of picking notes, which two IBM physicists, Mandelbrot and Voss, had named after kinds of noise:
- White music picks every note at random.
- Brown music picks the interval at random, a random walk like Brownian motion.
- 1/F music lies between the two, which Voss found was typical of real music "from Ukrainian folk melodies to Indian sitar music". The method was described in Martin Gardner's Scientific American column of April 1978.
Jackson's verdict: the results will never make the top ten, "but some sound as good as 'dentist's office music.'"
Typing it in
The only special characters are the inverse letters in the REM on line 1. Everything else is plain.
How to use it
RUN it, type 1 (white), 2 (brown) or 3 (1/F) and press RETURN. The program plays 128 notes, prints each pitch number and plots the melody's contour on the GRAPHICS 3 screen, one dot per note. At the end it returns to GRAPHICS 0 and LISTs itself, which Jackson said was handy while debugging. Compare the three and decide which sounds most "musical".
To change the scale, move the DATA lines. The program reads whichever of the three scales comes first: C major (line 3005), pentatonic (3015) or "bugle notes" from the harmonic series (3025). Swap the line numbers to choose another, or type in your own scale or a short tune.
How it works
- Every note is played by the subroutine at line 50. A short burst on voice 2 adds a click (an "attack") so that each note is heard separately, and voice 3 plays the pitch from the table
P(). - Brown music (line 210) adds −2 to +2 to the last pitch and restarts in the middle if it goes out of range.
- 1/F music (lines 300–370) uses seven "dice". The note number is written in binary (line 325), and whenever a bit changes, the die for that bit is re-rolled (line 330). The pitch is the total of all the dice. The low bits change on every note, giving small steps. The high bits change rarely, giving big jumps now and then. That's the mixture between white and brown.
- The
WAITdelay is different for each mode (100, 105 and 1), because each loop takes a different time to work out its note. Jackson noted that it's hard to give all three exactly the same tempo.
Listing
0 REM PROGRAM LISTING ONE
1 REM {inv}ANTIC MAGAZINE{/inv}
5 GRAPHICS 3
10 DIM P(16),DICE(7),OLDICE(7),VALDICE(7)
15 COLOR 1
20 FOR I=1 TO 16:READ P:P(I)=P:NEXT I
25 ? "TYPE OF MUSIC":? "1=WHITE; 2= BROWN; 3=1/F":INPUT TYPE:ON TYPE GOTO 100,200,300
45 REM SOUND AND PLOT
50 SOUND 2,12,10,14
55 SOUND 3,P(PIT),10,10
60 SOUND 2,0,0,0
65 PLOT I-40*INT(I/40),18-PIT
70 FOR WT=1 TO WAIT:NEXT WT
75 IF (I-40*INT(I/40))=39 THEN GRAPHICS 3
80 RETURN
100 REM WHITE MUSIC
105 FOR I=1 TO 128
110 PIT=1+INT(16*RND(1))
120 ? "WHITE MUSIC",PIT
130 WAIT=100
140 GOSUB 50
150 NEXT I
160 GOTO 4000
200 REM BROWN MUSIC
205 FOR I=1 TO 128
210 PIT=PIT-2+INT(5*RND(1))
215 IF PIT<1 OR PIT>16 THEN PIT=10
220 ? "BROWN MUSIC",PIT
230 WAIT=105
240 GOSUB 50
250 NEXT I
260 GOTO 4000
300 REM 1/F MUSIC
305 FOR J=1 TO 7:VALDICE(J)=INT(3*RND(1)):DICE(J)=0:OLDICE(J)=0:NEXT J
310 FOR I=1 TO 128
315 PIT=0:NUM=I
320 FOR J=1 TO 7
325 DICE(J)=NUM-2*(INT(NUM/2)):NUM=INT(NUM/2)
330 IF DICE(J)<>OLDICE(J) THEN VALDICE(J)=INT(3*RND(1))
335 OLDICE(J)=DICE(J)
340 PIT=PIT+1+VALDICE(J)
345 NEXT J
350 ? "1/F MUSIC",PIT
355 IF PIT<1 OR PIT>16 THEN PIT=10
360 WAIT=1
365 GOSUB 50
370 NEXT I
375 GOTO 4000
3000 REM DIATONIC SCALE- C MAJOR
3005 DATA 162,144,128,121,108,96,91,81,72,64,60,53,47,45,40,35
3010 REM PENTONIC SCALE
3015 DATA 243,217,182,162,144,121,108,96,81,72,60,53,60,72,81,91
3020 REM BUGLE NOTES
3025 DATA 239,119,79,59,47,39,33,29,26,23,21,19,16,14,14,13,12
4000 GRAPHICS 0:LIST :REM RETURNS TO GR.0
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: RNDMUSIC.BAS.
Credits
- Program listing: Random Music (White, Brown and 1/F) — program listing (Antic, November 1983 (Vol. 2, No. 8)) — Charles Jackson
- Antic, November 1983 (Vol. 2 No. 8): Random Music, by Charles Jackson (atarimagazines.com) — Charles Jackson, 1983
- Antic disk, November 1983 - Vol. 2 No. 8: RNDMUSIC.BAS (detokenized listing) — AtariMagazines.com (Kevin Savetz), 1983
