Ric, I've made some of the up/down buttons move in 0.01 amounts and I included a dba file with the download which contains the create sound function. When you save a .dbs sound file the last line in the file is the function call which you can copy and paste into the dba file or your own program etc.
I also added the attack code you had a couple of posts back, which wasn't in the first version even though it had the field. So many code snippets I missed it.
I updated the download in my first post.
And here's the version of code I'm using for create_sound(), it's also included with the program.
` DarkBASIC Pro create sound function - sounds without media!
` *** N.B. This program requires DBPro5.8 because of the memblock format
` produces sounds from memblocks - i.e. no need for .wav files, etc
` based on Ric's original code and modified to use memblocks by Green Gandalf
rem replace this line with the one at the bottom of your saved .dbs sound file
createsound("bomb_drop",1,3000,3000,2500,0.01,0.02,0.00,0,0.00,0,5)
print "Press space to play sound"
do
if spacekey()>0 and key_press<1
key_press=1
play sound 1
endif
if scancode()<1 then key_press=0
loop
function createsound(name$,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+28
` write 28 memblock header bytes
dword1=1 ` gg query: is this the number of channels?
dword2=2 ` gg query: is this the number of bytes per sample?
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 dword 1, position, dword1 : inc position,4
write memblock dword 1, position, dword2 : inc position,4
write memblock dword 1, position, dword3 : inc position,4
write memblock dword 1, position, dword4 : inc position,4
write memblock dword 1, position, dword5 : inc position,4
write memblock dword 1, position, dword6 : inc position,4
write memblock dword 1, position, dword7 : 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
if sound exist(soundnumber)=1 then delete sound soundnumber
make sound from memblock 999, 1 ` assumes you won't need sound number 999!
clone sound soundnumber, 999
delete sound 999
` memblock no longer required
delete memblock 1
endfunction
data 82,73,70,70,208,59,1,0,87
data 65,86,69,102,109,116,32,16
data 0,0,0,1,0,2,0,34,86,0
data 0,136,88,1,0,4,0,16,0
data 100,97,116,97
