Classic Computer Magazine Archive COMPUTE! ISSUE 80 / JANUARY 1987 / PAGE 63

Music Maker 64

Martin F. Staley


If you're interested in creating music on the Commodore 64, this program may provide the power you're looking for. Don't be deceived by its lack of fancy graphics and other frills-at the core of the program is a sophisticated machine language routine that can play complex, multi-part music. Yet you can use the program without being a machine language expert.


The Commodore 64's SID chip is one of the most advanced music chips in any personal computer. However, the 64's BASIC requires several POKE statements to play just a single note, much less an entire song. "Music Maker" vastly simplifies the process of making music on the Commodore 64. You're still responsible for telling the computer what, to play, but this program's system takes much of the drudgery out of entering music. It allows up to about 3000 notes in each voice and independent control of the 64's three voices (tone generators).
    Type in and save Music Maker. Although you'll probably be tempted to run the program immediately, you can't run it until you add some notes for it to play. This is done by typing additional DATA statements at the end of the program (when you do this, be careful not to disturb the DATA statements already included in the program). Here's an explanation of what to type.

Entering Music
In Music Maker, each note is specified by two numbers. The first, which I'll call the note number, is any integer from 10-127. The first digit or digits of the number correspond to the location of that note in a chromatic scale starting at C and going up to B. Rests should be given note numbers of 0. The following table can be used as a reference.

Note  
 
First digit(s) of note number
[rest] 0
C
1
C#
2
D
3
D#
4
E
5
F
6
F#
7
G
8
G#
9
A
10
A#
11
B
12

    The last digit of the note number is the octave (0-7, inclusive) in which the note is located. As examples of note numbers, a D in the fifth octave has a note number of 35, a B in octave zero (the lowest octave) has a note number of 120, an F sharp in the fourth octave has a note number of 74, and a C in the seventh (highest) octave has a note number of 17. This system becomes quite easy to use after only a little practice.
    The second number for each note, which I'll call the length number, is any integer (whole number) in the range 1-100 (the number can actually range up to 255-see below). The length number can be used in many different ways. One system is to let the length number equal three times the number of thirty-second notes that can fit in the note. When this system is used, a tempo of 950 equals approximately 120 beats per minute-a moderate tempo-and notes and rests have the length numbers shown here.

Note type

Length number
whole   
96
half   
48
quarter   
24
eighth   
12
sixteenth   
 6
thirty-second    3
dotted half   
72
dotted quarter   
36
dotted eighth   
18
dotted sixteenth    9
eighth note triplet   
 8
sixteenth note triplet   
 4
thirty-second note triplet    2
sixty-fourth note triplet    1

    The most important fact to remember about length numbers is that they must be correct in relation to one another. A half note should always be twice the length of a quarter note, and so on. If your musical composition doesn't use triplets, then it's acceptable to divide the length numbers of the other notes by three, since all their numbers are divisible by three. Or, if you need only half, quarter, eighth, and sixteenth notes, they can be given note numbers of eight, four, two, and one, respectively.
    In short, the length numbers can be adjusted in various ways to get different kinds of notes. If you need quintuplets, you can use quarter notes with length numbers of ten; then each note in the quintuplet will have a length number of two. If you need a grace note after a quarter note, that particular quarter note can be given a value slightly less than the value given to other quarter notes, and the gap filled with the grace note. Just remember that the length numbers must be integers.

Tonguing and Slurring
In music, there are two basic ways to articulate notes: tonguing and slurring. To tongue a note means to place a short interval of silence between that note and the preceding one, whereas slurred notes are connected. The previous description of note numbers stated that the length number for each note must be in the range 1-100. Lengths in this range create tongued notes. If you want a note to be slurred to the next note, add 100 to the length number it would otherwise have. For instance, length 105 gives you a slurred note with the length 5. Note that some attack/decay/sustain/ release (ADSR) settings cause notes to be tongued or slurred regardless of the length number.
    Program lines 380, 500, and 620 control a staccato feature. In conventional music, staccato notes are more clear-cut and separated than most notes in the song. The amount of staccato for each voice can be from zero (least) to 255 (most), and it remains in effect throughout the entire song. This feature has little effect all by itself, but serves as an enhancement to the ADSR settings and should be used in conjunction with them.

Multiple Voices
If your musical composition uses more than one voice, enter the music data in sequential order. That is, all the music data (a note number and length number for each note or rest) for voice one comes first. All the music data for voice two should come next, followed by the data for voice three.
    At the end of the data for each voice, include a value of -1. The negative value serves as a flag to Music Maker that it has reached the end of the data for a voice. When it reaches the third -1 value, Music Maker knows it has read all the data and can begin playing the song.
    After you've entered all the music data, save the program using a different filename to distinguish it from the original Music Maker.

Running Music Maker
Once the music data has been entered, you can run Music Maker to hear it play the song. When you do so, the computer spends a short time READing and POKEing the machine language routine into memory. Then it READs the music data at the end of the program and POKEs that into memory as well. After all the data is in place, it transfers control to the machine language routine, which actually plays the music. When the song is finished, the familiar READY prompt appears.
    Program lines 120-570 allow you to set the sound parameters: volume, filtering, attack/decay/ sustain/release (ADSR), high and low pulse width, and waveforms. These parameters are explained more fully in the 64 user's manual. Line 90 controls the tempo of the music, which can be any integer from 0-65535, with 65535 being the slowest speed. The variable S$ in line 100 controls a special effect known as synchronization. If you set S$ equal to "Y," voices two and three are synchronized with voice one whenever there is a rest in those voices. The result is an enriched sound in voice one.
    When it's first run, Music Maker needs to read both the machine language data and the music data. The machine language subroutine modifies itself, so its data must be read and POKEd in every time you run the program. However, the music data does not need to be read each time, and it would be a waste of time to do so, especially if your song is long. If R$ = "Y" in line 110, the music data will be read. To tell the program to skip the music data, set R$ to some string value other than Y. Do this only after having read the music data at least once. Keep in mind, too, that if you modify this data or add more notes, you must read the data again to hear the new version of the song.
    The machine language subroutine that plays the music starts at location 49152 ($0000) and is not relocatable. Since Music Maker uses other addresses in the area $0000-$CFFF and the computer's zero page of memory, you should not attempt to use Music Maker while any other machine language program is running.

Music Maker 64
For instructions on entering this program, please refer to "COMPUTE!'s Guide to Typing In Programs- in this issue of COMPUTE!.

RA 10 POKE 53281,15:POKE 53280
      ,12:PRINT"[CLR}[BLK}
      {7 DOWN}{14 RIGHT}PLEASE
       WAIT"
MG 20 FOR N=54272 TO 54296:POK
      E N,0:NEXT
SF 30
KK 40 FOR N=49152 TO 49595
CG 50 : READ B:POKE N,B:T=T+B
GJ 60 NEXT
MJ 70
FP 80 REM********** ALL VOICES
       **********
HB 90 TP=1000:REM* TEMPO
      {10 SPACES}0-65535
DK 100 S$="Y" :REM* SPECIAL EF
       FECT?[3 SPACES}Y/N
FF 110 R$="Y" :REM* READ MUSIC
        DATA?{2 SPACES}Y/N
CK 120 VO=15[2 SPACES}:REM* VO
       LUME:{11 SPACES}0-15
AA 130 FV=0{3 SPACES}:REM* FIL
       TER OFF/ON: 0/1,2,4
XF 140 HP=64{2 SPACES}:REM* HI
       GH PASS:(6 SPACES}0,64
DR 150 BP=0{3 SPACES}:REM* BAN
       D PASS:{6 SPACES}0,32
JA 160 LP=0{3 SPACES}:REM* LOW
        PASS:{7 SPACES}0,16
EE 170 LC=2{3 SPACES}:REM* LO
       {SPACE}CUTOFF FREQ.: 0-
       7
QB 180 HC=128 :REM* HI CUTOFF
       {SPACE}FREQ.: 0-255
QR 190 RS=240 :REM* RESONANCE:
       16,32,64,128
AS 200 POKE 54295,FV+RS
HA 210 POKE 54296,VO+HP+LP+BP
RX 220 POKE 54293,LC:POKE 5429
       4,HC
FC 230 POKE 53225,TP/256
XF 240 POKE 53224,256*(TP/256-
       INT(TP/256))
RA 250 ;
KB 260 ;
JF 270 REM********** VOICE 1 *
       ************
JX 280 AD=85 :REM** ATTACK/DEC
       AY:{4 SPACES}0-255
BF 290 SR=100:REM** SUSTAIN/RE
       LEASE: 0-255
KK 300 SC=50 :REM** STACCATO:
       {8 SPACES}0-255
EA 310 HI=8{2 SPACES}:REM** HI
        PULSE WIDTH:{2 SPACES}
       0-15
HS 320 LO=0{2 SPACES}:REM** LO
        PULSE WIDTH:{2 SPACES}
       0-255
BC 330 W1=65 :REM** WAVEFORM:
       {5 SPACES}17,33,65
RQ 340 POKE 54277,AD:POKE 5427
       8,SR
GP 350 POKE 54275,HI:POKE 5427
       4,LO
RS 360 POKE 53240,W1:POKE 4954
       3,SC
JJ 370 ;
EK 380 :
FP 390 REM********** VOICE 2
       ************
CG 400 AD=85 :REM** ATTACK/DEC
       AY:{4 SPACES}0-255
JQ 410 SR=100:REM** SUSTAIN/RE
       LEASE: 0-255
PB 420 SC=50 :REM** STACCATO:
       {8 SPACES}0-255
BJ 430 HI=8{2 SPACES}:REM** HI
       PULSE WIDTH:{2 SPACES}
      0-15
MG 440 LO=200:REM** LO PULSE W
       IDTH:{2 SPACES}0-255
XM 450 W2=65 :REM** WAVEFORM:
       {5 SPACES}17,33,65
SP 460 POKE 54284,AD:POKE 5428
       5,SR
CG 470 POKE 54282,HI:POKE 5428
       1,LO
XR 480 POKE 53241,W2:POKE 4955
       8,SC
QA 490 ;
FA 500 ;
MD 510 REM********** VOICE 3
       ************
SR 520 AD=85 :REM** ATTACK/DEC
       AY:{4 SPACES}0-255
FH 530 SR=100:REM** SUSTAIN/RE
       LEASE: 0-255
GK 540 SC=50 :REM** STACCATO:
       {8 SPACES}0-255
JB 550 HI=5{2 SPACES}:REM** HI
        PULSE WIDTH:{2 SPACES}
       0-15
CB 560 LO=90 :REM** LO PULSE W
       IDTH:{2 SPACES}0-255
BE 570 W3=33 :REM** WAVEFORM:
       {5 SPACES}17,33,65
SG 580 POKE 54291,AD:POKE 5429
       2,SR
DS 590 POKE 54289,HI:POKE 5428
       8,LO
HK 600 POKE 53242,W3:POKE 4957
       3,SC
GH 610 ;
MH 620 ;
XR 630 IF S$<>"Y" THEN660
JC 640 POKE 49203,173:POKE 492
       04,247:POKE 49205,207
JX 650 POKE 49239,173:POKE 492
       40,245:POKE 49241,207
ED 660 FOR N=53230 TO 53232:PO
       KE N,1:NEXT
SE 670 POKE 53222,0:POKE 53223
       ,0
MS 680 POKE 53226,0:POKE 53227
       ,0
GR 690 ;
PG 700 N=0
RC 710 IF R$<>"Y" THEN D=256*P
       EEK(53221)+PEEK(53220):
       GOTO920
BS 720 FOR C=31998 TO 37998 ST
       EP 3000
EQ 730 : POKE C,0:POKE C+1,0
FB 740 NEXT C
MA 750 POKE 50000,0:POKE 50001
       ,0
QP 760 FOR A=1 TO 12
AE 770 : FOR B=0 TO 15
RQ 780 :{3 SPACES}READ C:T=T+C
GK 790 :{3 SPACES}POKE 50000+2
       0*A+B,C
BM 800 : NEXT B
QR 810 NEXT A:IF T<>87973 THEN
        PRINT "ERROR IN ML DAT
       A":STOP
MK 820 READ A:IF A=-1 THEN N=0
       :GOTO850
BG 830 READ B:POKE 32000+N,A:P
       OKE 32001+N,B:IF B>100
       {SPACE}THEN B=B-100
DH 840 N=N+2:D=D+B:GOTO820
PD 850 READ A:IF A=-1 THEN N=0
       :GOTO870
KX 860 READ B:POKE 35000+N,A:P
       OKE 35001+N,BiN=N+2:GOT
       O850
DR 870 READ A:IF A=-1 THEN N=0
       :GOTO900
QX 880 READ B:POKE 38000+N,A:P
       OKE 38001+N,B:N=N+2:GOT
       0870
KK 890 ;
ED 900 POKE 53221,D/256
RC 910 POKE 53220,256*(D/256-I
       NT(D/256))
QD 920 PRINT"{CLR}[BLK)
       {7 DOWN}{16 RIGHT}PLAYI
       NG":SYS49152
JC 930 FOR N=54272 TO 54296:PO
       KE N,:NEXT
GA 940 END
ER 950 ;
JR 960 ;
AJ 970 REM**** MACHINE LANGUAG
       E DATA ****
XX 980 DATA173,254,124,10,170,
       189,80,195,141,243,207,
       189,81,195,141,242,207,
       173
AE 990 DATA182,136,10,170,189,
       80,195,141,245,207,189,
       81,195,141,244,207,173,
       110
SP 1000 DATA148,10,170,189,80,
        195,141,247,207,189,81
        ,195,141,246,207,76,75
        ,192,208
RJ 1010 DATA19,173,243,207,240
        ,14,141,15,212,173,242
        ,207,105,8,141,14,212,
        76,87
SA 1020 DATA192,173,247,207,14
        1,15,212,173,246,207,1
        41,14,212,76,111,192,2
        08,19
SE 1030 DATA173,243,207,240,14
        ,141,8,212,173,242,207
        ,233,8,141,7,212,76,12
        3,192
KC 1040 DATA173,245,207,141,8,
        212,173,244,207,141,7,
        212,173,243,207,141,1,
        212,173
CK 1050 DATA242,207,141,0,212,
        173,248,207,141,4,212,
        133,251,173,249,207,14
        1,11,212
JE 1060 DATA133,252,173,250,20
        7,141,18,212,133,253,2
        06,238,207,173,238,207
        ,201,100
HE 1070 DATA240,8,201,0,208,42
        ,162,16,134,251,238,19
        4,192,208,3,238,195,19
        2,238
DA 1080 DATA194,192,208,3,238,
        195,192,173,255,124,14
        1,238,207,238,1,192,20
        8,3,238
QQ 1090 DATA2,192,238,1,192,20
        8,3,238,2,192,206,239,
        207,173,239,207,201,10
        0,240,8
RC 1100 DATA201,0,208,42,162,1
        6,134,252,238,250,192,
        208,3,238,251,192,238,
        250,192
BD 1110 DATA208,3,238,251,192,
        173,183,136,141,239,20
        7,238,18,192,208,3,238
        ,19,192
MP 1120 DATA238,18,192,208,3,2
        38,19,192,206,240,207,
        173,240,207,201,100,24
        0,8,201
EF 1130 DATA 0,208,42,162,16,1
        34,253,238,50,193,208,
        3,238,51,193,238,50,1§
        3,208,3
CE 1140 DATA238,51,193,173,111
        ,148,141,240,207,238,3
        5,192,208,3,238,36,192
        ,238,35
JF 1150 DATA192,208,3,238,36,1
        92,174,232,207,172,233
        ,207,236,234,207,208,5
        ,204,235
JG 1160 DATA207,240,11,238,234
        ,207,208,3,238,235,207
        ,76,77,193,238,230,207
        ,208,3
DK 1170 DATA238,231,207,173,23
        0,207,205,228,207,208,
        9,173,231,207,205,229,
        207,208
KQ 1180 DATA1,96,32,234,255,32
        ,225,255,208,1,96,162,
        0,224,0,240,9,165,251,
        141,4
KG 1190 DATA212,232,76,134,193
        ,162,0,224,0,240,9,165
        ,252,141,11,212,232,76
        ,149,193
SD 1200 DATA162,0,224,0,240,9,
        165,253,141,18,212,232
        ,76,164,193,169,0,141,
        234,207
PC 1210 DATA141,235,207,76,0,1
        92
PJ 1220 DATA1,12,2,24,4,49,8,9
        8,16,195,33,134,67,12,
        134,24
RC 1230 DATA1,28,2,56,4,113,8,
        225,17,194,35,132,71,9
        ,142,18
XP 1240 DATA1,45,2,90,4,180,9,
        104,18,209,37,161,75,6
        6,150,132
AR 1250 DATA1,63,2,126,4,252,9
        ,247,19,239,39,222,79,
        188,159,120
EA 1260 DATA1,82,2,162,5,72,10
        ,143,21,30,42,61,84,12
        2,168,243
FD 1270 DATA1,102,2,204,5,152,
        11,48,22,96,44,192,89,
        127,178,255
PF 1280 DATA1,123,2,247,5,237,
        11,218,23,180,47,105,9
        4,210,189,164
JX 1290 DATA1,146,3,36,6,71,12
        ,143,25,29,50,59,100,1
        17,200,235
QR 1300 DATA1,170,3,83,6,167,1
        3,78,26,156,53,55,106,
        110,212,221
HJ 1310 DATA1,195,3,134,7,12,1
        4,24,28,49,56,97,112,1
        95,225,133
CC 1320 DATA1,222,3,188,7,119,
        14,239,29,222,59,188,1
        19,119,238,238
DK 1330 DATA1,250,3,245,7,233,
        15,210,31,164,63,73,12
        6,146,253,35
KF 1340 :
RJ 1350 REM** ENTER MUSIC DATA
         BELOW