This is a modified version of some code written (I think, correct me if I'm wrong) by Ric and Tommy S. It now writes directly to a .wav file, and then loaded, so can be used in any version of DBP (DBC?). Also, this means that you can now load it as a 3d sound if you wish!
The code:
function createsound(name$,soundtype,soundnumber,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#,attack#)
outWord as word
dword1 as dword: dword2 as dword: dword3 as dword: dword4 as dword
dword5 as dword: dword6 as dword: dword7 as dword
samples=int((length#/1000)*44100)
if memblock exist(1) then delete memblock 1
make memblock 1,samples*2+44
` write 28 memblock header bytes
dword1=1 ` gg query: is this the number of channels?
dword2=2
dword3=22050 ` gg query: seems to be half the number of samples per second - why?
dword4=88200 ` gg query: is this the number of bytes per second?
dword5=4 ` gg query: what does this represent?
dword6=16 ` gg query: (ditto) ?
dword7=0 ` gg query: (ditto) ?
position=0
write memblock byte 1, position, asc("R") : inc position
write memblock byte 1, position, asc("I") : inc position
write memblock byte 1, position, asc("F") : inc position
write memblock byte 1, position, asc("F") : inc position
write memblock dword 1, position, samples*2+36 : inc position,4
write memblock byte 1, position, asc("W") : inc position
write memblock byte 1, position, asc("A") : inc position
write memblock byte 1, position, asc("V") : inc position
write memblock byte 1, position, asc("E") : inc position
write memblock byte 1, position, asc("f") : inc position
write memblock byte 1, position, asc("m") : inc position
write memblock byte 1, position, asc("t") : inc position
write memblock byte 1, position, asc(" ") : inc position
write memblock dword 1, position, 16 : inc position,4
write memblock word 1, position, dword1 : inc position,2
write memblock word 1, position, dword2 : inc position,2
write memblock dword 1, position, dword3 : inc position,4
write memblock dword 1, position, dword4 : inc position,4
write memblock word 1, position, dword5 : inc position,2
write memblock word 1, position, dword6 : inc position,2
`write memblock word 1, position, dword7 : inc position,2 `MAYBE UNCOMMENT?
write memblock byte 1, position, asc("d") : inc position
write memblock byte 1, position, asc("a") : inc position
write memblock byte 1, position, asc("t") : inc position
write memblock byte 1, position, asc("a") : inc position
write memblock dword 1, position, samples*2 : inc position,4
rem generate and write wave
`inc param_attackamount#,0.0001
riseinloudness#=loudness#
for x=1 to samples
outInteger=int(sin((x/122.5)*(frequency#+vibratodepth#*sin(theta#)))*(loudness#-fallinloudness#-riseinloudness#+tremelodepth#*sin(phi#)))*3.0
if outInteger <-32767 then outInteger=-32767 ` gg query: is this the valid range?
if outInteger>32767 then outInteger=32767 ` gg query: (ditto) ?
outWord=outInteger
inc theta#,vibratospeed#
inc phi#,tremelospeed#
dec frequency#,bend#
if fallinloudness#<loudness#
inc fallinloudness#,decay#
endif
if riseinloudness#>0
dec riseinloudness#,attack#
endif
write memblock word 1,position,outWord : inc position,2
next x
open to write 1,name$+".wav"
make file from memblock 1,1
close file 1
if sound exist(soundnumber)=1 then delete sound soundnumber
if soundtype
load 3dsound name$+".wav", soundnumber
else
load sound name$+".wav", soundnumber
endif
` memblock no longer required
delete memblock 1
endfunction
It works exactly the same as before, but has 1 extra parameter called 'soundtype'. Anything other than 0 will make it a 3d sound rather than a normal sound.