Background Music  (a Kind of ASCII ART)


Author Message
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1485
Posted: 10:59am 17 Oct 2022      

After a discussion with Volhout how to Tokenise Music,here is my proposal.
I tried out MidiNote and store as Ascii
as the Note C2 starts at 36 and B7 is 107 this range should cover almost all possibilities
We are able to store a complete Voice of a Melody in one String where Every Note  uses just one Byte..
As 36 is the First Character that we use, we dont get in trouble with the " Char (34)

the Player is "Tick" driven so it runs independend in Background and you can insert your Main Program in Frontground.
This excample is just 2 Voice polyphone but 4 Voce will be possible


'Test ASCII Coded Background Music (with reference to MIDI note numbers)
'limitation to 255 Notes song length,since the max Stringlenght is 255
' Exeptions: Space pauses the Note, # ends the song
Dim FRQ%(128)
Dim notes%(4,255)
mt%=1:CNT%=1
Dim ADSR%(10)=(25,25,25,24,22,20,18,13,7,3,0)
Dim ADSR2%(10)=(2,8,12,17,22,20,15,10,5,2,0)
For f%=36 To 107:Read FRQ%(f%):Next :FRQ%(32)=1
'Sample Music just for this Test
AA$="<>@ C C EC @ < > @ @ > < >    <>@ C C EC @ < > @ @ > > <   "
AA$=AA$+"A  A  E E  E C C @ >  <>@ C C EC @ < >@ @ > > <   #"
AB$="  $0$0$0$0$0$0$0$0$0$0$0$0+7+7+7$0$0$0$0$0$0$0$0$0$0$0$0$"
AB$=AB$+"                           $0$0$0$0$0$0$0$0$0+7+7$ #"
cnt%=Len(AA$):Spos%=1
SetTick 20, music,4
MODE 2
Do
Colour RGB(255,mt%*25,255)
Print @(1,1)"'your Program here"
Loop

Sub music
Local Fcent%,F1%,F2%,FL%,FR%
 If mt%=1 Then
  nt%=Asc(Mid$(AA$,CNT%,1))
  If nt%=35 Then CNT%=1:nt%=Asc(Mid$(AA$,CNT%,1))
  Freq1%=FRQ%(nt%)
  Freq2%=FRQ%(Asc(Mid$(AB$,CNT%,1)))
Inc cnt%
EndIf
'Pseudo Chorus
Fcent%=Int(Freq1%/100)
FL%=Freq1% - Fcent%
FR%=Freq1% + Fcent%
EndIf
If Freq1%>1 Then Play sound 1,"L","q",FL%,adsr%(mt%):Play sound 3,"R","q",FR%,a
dsr%(mt%)
If Freq2%>1  Then Play sound 2,"B","w",Freq2%,adsr2%(mt%)
Inc mt%:If mt%>10 Then mt%=1

End Sub

'Note to Frequency, starting with C2 (Midi 36) up to B7 (Midi 107)
Data 65,69,73,78,82,87,93,98,104,110,117,123
Data 131,139,147,156,165,175,185,196,208,220,233,247
Data 262,277,294,311,330,349,370,392,415,440,466,494
Data 523,554,587,622,659,698,740,784,831,880,932,988,1047
Data 1109,1175,1245,1319,1397,1480,1568,1661,1760,1865,1976
Data 2093,2217,2349,2489,2637,2794,2960,3136,3322,3520,3729,3951


Cheers
  Martin
Edited 2022-10-17 21:01 by Martin H.