Quantcast
Channel: stardot.org.uk
Viewing all articles
Browse latest Browse all 5552

8-bit acorn software: other • Coding BASIC Christmas Music

$
0
0
Season's Greetings,

A couple of people have asked about the music code I write so I thought I'd share a little 16-bar loop of a well known Christmas song. Feel free to add to/reuse/improve this as you see fit. I'd also be curious to know how it sounds on real hardware.

The chords and drums are in a fairly simple loop. The DATA containing the bass and lead lines, and whether to 'hold' or not to 'hold', is fed into the loop.
Envelopes 1 is for drums. I can't remember what Envelope 2 was for but it's not being used here. Envelopes 3 to 7 are for the 5 kinds of chord shape required for the tune. I've been working on generating more complex chords within a single envelope statement and this is the result. Envelope 8 is for the lead line (when it comes in after 8 bars) and Envelope 9 is the bass sound such as it is.

On the disk is the same code in a file named 'XMAS' plus some earlier drafts to show how I built it out. From a coding point of view it might not be the most sensible way of doing things with regards to timing and memory management but from a creative standpoint I find it a nice way to work. Tuning can be a little ... interesting on the Beeb.

Code:

   10 MODE4:CLS:PRINTTAB(7,10)"[ INSERT XMAS MESSAGE HERE ]"   20 ENVELOPE1,1,0,0,0,0,0,0,126,-30,0,-1,126,0   30 ENVELOPE2,1,1,0,0,10,0,0,100,-20,0,-1,80,0   40 ENVELOPE3,3,28,-16,28,2,1,1,80,0,0,-10,80,0:REM START 5TH LOWER   50 ENVELOPE4,3,20,-8,20,2,1,1,80,0,0,-10,80,0:REM START 4TH LOWER   60 ENVELOPE5,3,12,20,16,2,1,1,80,0,0,-10,80,0:REM START m3RD LOWER   70 ENVELOPE6,3,28,-12,28,2,1,1,80,0,0,-10,80,0:REM START 5TH LOWER   80 ENVELOPE7,3,16,8,12,2,1,1,80,0,0,-10,80,0:REM START M3RD LOWER   90 ENVELOPE8,9,1,-1,0,1,1,0,80,0,0,-1,80,30   100 ENVELOPE9,1,1,0,0,1,0,0,80,0,0,-4,60,30   110 tempo=540  120 tuning=1  130    140 PROCpattern1:PROCpattern1:PROCpattern2:PROCpattern3  150 PROCpattern1:PROCpattern1:PROCpattern2:PROCpattern3  160 RESTORE710:GOTO140  170     180 DEFPROCpattern1  190 PROCBeat1(3,48,6):PROCBeat2(3,48,6)   200 PROCBeat1(3,48,4):PROCBeat2(3,48,4)  210 PROCBeat1(4,56,6):PROCBeat2(4,56,6)   220 PROCBeat1(4,56,4):PROCBeat2(4,56,4)   230 PROCBeat1(3,48,6):PROCBeat2(3,48,6)   240 PROCBeat1(3,48,4):PROCBeat2(4,56,4)  250 PROCBeat1(0,0,6):PROCBeat2(3,48,6)  260 PROCBeat1(5,64,4):PROCBeat2(0,0,4)  270 ENDPROC  280    290 DEFPROCpattern2  300 PROCBeat1(3,68,6):PROCBeat2(3,68,6)    310 PROCBeat1(3,68,4):PROCBeat2(3,68,4)   320 PROCBeat1(4,76,6):PROCBeat2(4,76,6)   330 PROCBeat1(4,76,4):PROCBeat2(4,76,4)   340 PROCBeat1(3,68,6):PROCBeat2(3,68,6)   350 PROCBeat1(3,68,4):PROCBeat2(4,76,4)   360 PROCBeat1(0,0,6):PROCBeat2(3,68,6)   370 PROCBeat1(5,84,4):PROCBeat2(0,0,4)    380 ENDPROC  390    400 DEFPROCpattern3  410 PROCBeat1(6,52,6):PROCBeat2(6,52,6)  420 PROCBeat1(6,52,4):PROCBeat2(6,52,4)  430 PROCBeat1(7,64,6):PROCBeat2(7,64,6)   440 PROCBeat1(7,64,4):PROCBeat2(7,64,4)   450 PROCBeat1(6,52,6):PROCBeat2(6,52,6)  460 PROCBeat1(6,52,4):PROCBeat2(7,64,4)  470 PROCBeat1(0,0,6):PROCBeat2(6,52,6)  480 PROCBeat1(7,64,4):PROCBeat2(0,0,4)  490 ENDPROC  500    510 DEFPROCBeat1(Env,Pit,Dru)   520 READ Hold,Tune,HoldB,Bass  530 IF Hold=0:H=&0003  540 IF Hold=1:H=&1003  550 IF HoldB=0:B=&0002   560 IF HoldB=1:B=&1002    570 SOUND0,1,Dru,1:SOUND1,Env,Pit,1:SOUNDH,8,Tune+tuning,1:SOUNDB,9,Bass,1   580 FORT=1TOtempo:NEXT  590 ENDPROC  600   610 DEFPROCBeat2(Env,Pit,Dru)   620 READ Hold,Tune,HoldB,Bass  630 IF Hold=0:H=&0003    640 IF Hold=1:H=&1003   650 IF HoldB=0:B=&0002  660 IF HoldB=1:B=&1002  670 SOUND1,Env,Pit,1:SOUNDH,8,Tune+tuning,1:SOUNDB,9,Bass,1    680 FORT=1TOtempo:NEXT   690 ENDPROC  700   710 DATA 1,0,0,12,1,0,0,12,1,0,0,12,1,0,0,12,1,0,0,12,1,0,0,12,1,0,0,12,1,0,0,12  720 DATA 1,0,0,12,1,0,0,12,1,0,0,12,1,0,0,12,1,0,0,8,1,0,0,12,1,0,0,8,1,0,0,12   730 DATA 1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0  740 DATA 1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,48,1,0,1,0,1,0,0,28,1,0,0,0  750 DATA 1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20  760 DATA 1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,28,1,0,0,32,1,0,0,28,1,0,0,32  770 DATA 1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40  780 DATA 1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,0,1,0,0,8  790 DATA 0,88,0,12,1,0,0,12,1,0,0,12,1,0,0,12,0,136,0,12,1,0,0,12,1,0,0,12,1,0,0,12  800 DATA 1,0,0,12,1,0,0,12,1,0,0,12,1,0,0,12,0,88,0,8,0,96,0,12,0,104,0,8,0,108,0,12  810 DATA 0,116,0,0,1,0,0,0,0,108,0,0,1,0,0,0,0,96,0,0,1,0,0,0,1,0,0,0,1,0,0,0  820 DATA 1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,136,0,48,0,124,1,0,0,108,0,28,0,96,0,0  830 DATA 0,80,0,20,1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20    840 DATA 1,0,0,20,1,0,0,20,1,0,0,20,1,0,0,20,0,144,0,28,0,128,0,32,0,116,0,28,0,104,0,32  850 DATA 0,88,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40  860 DATA 1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,40,1,0,0,0,1,0,0,8

Statistics: Posted by keyscompany — Thu Dec 04, 2025 5:00 pm



Viewing all articles
Browse latest Browse all 5552

Trending Articles