I have some good news and bad news.
Bad news is the main game code file I was hoping to build on is proving unmanageable, I might have to re-write it from scratch. This is the problem with modding code.
Good news is I now have music and sounds!
I didn't mention it before but my goal with this project is to have no external media whatsoever, it all has to be generated by code. So here's the sound. (Note: I can't understand why it's not working in DBP, sorry but it should do and it works okay in DBC. If anyone can fix it for DBP I would be very thankful.)
remstart
Synth Tune Generator by Fluffy and Obese87 - 2013
remend
melTheme = newSound(8,"4C{8}E{4}G{4}a{9}-GGFFCCF{9}-eecc3aa4C{8}-{7}C{8}E{4}G{4}5C{9}-4bbaa5CCc{8}--CC4bbaab{8}-{8}")
basTheme = newSound(8,"3C{16}2F{16}3c{16}a{14}-C{16}F{16}2b{16}3e{16}")
selSnd = newSound(16,"5DA") :`select sound
desSnd = newSound(16,"4AD") :`deselect sound
ordSnd = newSound(16,"5D4D5A6D") :`give order sound
laserSnd = newSound(128,"0BAGFEDC1BAGFEDC2BAGFEDC3BAGFEDC4BAGFEDC5BAGFEDC6BAGFEDC7BAGFEDC")
claxonSnd = newSound(128,"1CcDeEFfGaAbB2CcDeEFfGaAbB3CcDeEFfGaAbB4CcDeEFfGaAbB5C{32}3BbAaGfFEeDcC2BbAaGfFEeDcC{32}-{64}")
warpSnd = newSound(64,"0CcDeEFfGaAbB1C0cDeEFfGaAbB1Cc0eEFfGaAbB1CcDe0FfGaAbB1CcDeF0GaAbB1CcDeEFfGaAbB2CcDeEFfGaAbB3CDEFGAB4CDEFGAB5CDEFGAB6CEG7CG8C9C")
warpFailSnd = newSound(64,"0CcDeEFfGaAbB1C0cDeEFfGaAbB1Cc0eEFfGaAbB1CcDe0FfGaAbB1CcDeF0GaAbB1CcDeEFfGaAbB2CcDeEFfGaAbB3CDEFGAB4CDEFGAB5CDE4CDEFGAB3CDEFGAB2CDEFGAB1CDEFGAB0CDEFGAB0BAGFEDC")
traviataBassSnd = newSound(16,"3C{4}-G{4}-G{4}-2G{4}-3G{4}-G{4}-3C{4}-G{4}-G{4}-2G{4}-3G{4}-G{4}-3C{4}-G{4}-G{4}-2G{4}-3G{4}-G{4}-3C{4}-G{4}-G{4}-2G{4}-3G{4}-G{4}-3C{4}-G{4}-G{4}-2G{4}-3G{4}-G{4}-2B{4}-3F{4}-3F{4}-2G{4}-3F{4}-3F{4}-")
traviataMeloSnd = newSound(16,"-{55}4G{4}-5E{16}-{4}4G{4}-5E{4}-5E{4}-4G{4}-5E{4}-5EEFEEe{4}-E{4}-G{16}-{4}F{4}-E{4}-D{4}--DDccDDEEED{4}--DDccDDEEED{8}--C{5}4G{8}-{157}")
hide mouse
print "PRESS 1 toggle theme music."
print "PRESS 2 to play select sound."
print "PRESS 3 to play deselect sound."
print "PRESS 4 to play confirm order sound."
print "PRESS 5 to fire ze lasers."
print "PRESS 6 to toggle claxon sound."
print "PRESS 7 to play warp sound."
print "PRESS 8 to play warp fail sound."
print "PRESS 9 to toggle La Traviata."
do
if key=0 then key= scancode() else key = 0-scancode()
select key
case 2
toggletheme = 1-toggletheme
if toggletheme=0
stop sound melTheme
stop sound basTheme
else
loop sound melTheme
loop sound basTheme
endif
endcase
case 3 : play sound selSnd : endcase
case 4 : play sound desSnd : endcase
case 5 : play sound ordSnd : endcase
case 6 : play sound laserSnd : endcase
case 7
toggleClaxon = 1-toggleClaxon
if toggleClaxon then loop sound claxonSnd else stop sound claxonSnd
endcase
case 8 : play sound warpSnd : endcase
case 9 : play sound warpFailSnd : endcase
case 10
toggleTraviata = 1-toggleTraviata
if toggleTraviata=1
loop sound traviataBassSnd
loop sound traviataMeloSnd
else
stop sound traviataBassSnd
stop sound traviataMeloSnd
endif
endcase
endselect
loop
end
function newSound(bps,music$)
rem Find available sound
for snd = 1 to 255
if sound exist(snd)=0 then exit
next snd
if snd > 255 then print "NO FREE SOUND NUMBER AVAILABLE." : end
rem Find available memblock.
for mem = 1 to 255
if memblock exist(mem)=0 then exit
next mem
if mem > 255 then print "NO FREE MEMBLOCK NUMBER AVAILABLE." : end
rem Define constants and variables.
strLen = len(music$)
memPtr = 12
samplerate# = 40000
` samplerate# = 26624 :`Why this number?
soundsize = samplerate# / bps
rem Find number of actual notes in music$.
i=0 :`forgot variables inside function are persistent: eugh DB is not a good example for new coders. No other language I know does this. :'(
for x = 1 to strLen
n$ = mid$(music$,x)
if val(n$)=0
rem Number inside curly brackets denotes note length.
if n$="{"
for bracket = x+1 to strLen
if mid$(music$,bracket) = "}"
numinbracket = val(snippet$(music$,x+1,bracket-1))-1 :`we minus one from the length because note will have been counted by itself.
inc i,numinbracket :`add number in brackets to note count.
x = bracket : `this just moves the x pointer past the brackets.
exit
endif
next bracket
else
inc i :`single note
endif
endif
next x
rem Make the soundblock
size=(soundsize*i)+12
make memblock mem,size
rem write header
write memblock dword mem,0,8
write memblock dword mem,4,samplerate#
write memblock dword mem,8,size
rem write notes
for x=1 to strLen
n$=mid$(music$,x)
if asc(n$) >= 48 and asc(n$) <=57 :`n$ is a number.
octave = val(n$)
else
rem Numbers inside curly brackets denotes note length.
if n$="{"
for bracket = x+1 to strLen
if mid$(music$,bracket) = "}"
numinbracket = val(snippet$(music$,x+1,bracket-1))-1 :`we minus one from the length because note will have been counted by itself.
n$ = mid$(music$,x-1) :`take the note before the brackets.
x = bracket : `this just moves the pointer past the brackets.
bracket = strLen
endif
next bracket
else
numinbracket = 1
endif
for noteLen = 1 to numinbracket
rem -- Store Note --
select n$
rem Based on 7th octave.
case "C" : nt#=2093.00 : endcase
case "c" : nt#=2217.46 : endcase :`C#/Db
case "D" : nt#=2349.32 : endcase
case "e" : nt#=2489.02 : endcase :`Eb/D#
case "E" : nt#=2637.02 : endcase
case "F" : nt#=2793.83 : endcase
case "f" : nt#=2959.96 : endcase :`F#/Gb
case "G" : nt#=3135.96 : endcase
case "a" : nt#=3322.44 : endcase :`Ab/G#
case "A" : nt#=3520.00 : endcase
case "b" : nt#=3729.31 : endcase :`Bb/A#
case "B" : nt#=3951.07 : endcase
case default : nt#=-1 : endcase :`no note (pause)
endselect
if nt#>-1
hz# = nt# / 2^(7.0-octave)
anginc# = 360.0 * hz# / samplerate#
for xx = memPtr to memPtr+soundsize-1
ang#=wrapvalue(ang#+anginc#)
b = 128 + sin(ang#) :`since integers are truncated b will always be 127 or 128. (Except when ang#= 90|270 then b= 126|129.)
write memblock byte mem,xx,b
next xx
endif
inc memPtr, soundsize
next noteLen
endif
next x
make sound from memblock snd,mem
set sound volume snd,5 :rem Default volume is bloody loud!
delete memblock mem
endfunction snd
`//
function snippet$(a$,head,tail)
return$ = right$(left$(a$,tail),tail+1-head)
endfunction return$
`//
This based on Fluffy Rabbit's function:
function sg(snd,mem,bps,not$)
oct=2
pow#=1.0
sec#=1.0/bps
samplerate=26624
soundsize=sec#*samplerate
l=len(not$)
i=0
for x=1 to l
if val(mid$(not$,x))=0 then i=i+1
next x
size=(soundsize*i)+12
make memblock mem,size
write memblock dword mem,0,8
write memblock dword mem,4,samplerate
write memblock dword mem,8,size
place=12
for y=1 to l
n$=mid$(not$,y)
i=val(n$)
if i!0
oct=i
pow#=0.5
for x=2 to oct
pow#=pow#*2.0
next x
else
nt=-1
if n$="a" then nt=110
if n$="A" then nt=117
if n$="b" then nt=123
if n$="B" then nt=127
if n$="c" then nt=131
if n$="C" then nt=139
if n$="d" then nt=147
if n$="D" then nt=156
if n$="e" then nt=165
if n$="E" then nt=175
if n$="f" then nt=175
if n$="F" then nt=185
if n$="g" then nt=196
if n$="G" then nt=208
if nt>-1
hz#=nt*pow#
p=samplerate/hz#
anginc#=360.0/p
for x=place to place+soundsize-1
ang#=wrapvalue(ang#+anginc#)
sign#=sin(ang#)
if sign# <=0 then b=128
if sign# > 0 then b=127
write memblock byte mem,x,b
next x
endif
place=place+soundsize
endif
next y
make sound from memblock snd,mem
delete memblock mem
endfunction
`//
"I am a big dumb babby!

" - TheComet