@Ric
Here is my first attempt - no wav files!
The program is based on your original code and uses the DBP5.8 memblock format.
The program seems to produce the sounds correctly - but for some reason all the sounds are the same and equal to the first sound created (so if you rem out some of the samples as in the code below and re-run it you hear a different sound). There must be a silly error in my code but I cannot see it. Could you give it a try? (I tried using DBP5.7 and 8 bit sound first and got the same problem.)
I'm baffled because the memblocks ARE different (this is why I included some code to write these out as .txt files so I could examine them in Notepad). Once we've eliminated the bug those lines can be deleted, of course.
I've also included some queries after the header bytes - I can't
find any "Help" information describing these - and the DBP5.8 example files don't include examples!
If you can help, I'd be very grateful!
My code follows:
` *** N.B. This program requires DBPro5.8 because of the memblock format
global dirset
` N.B. there is no need to rem out the following lines - just done for illustration,
` try remming out a different set and see what happens
`createsound("laser",1,1500,700,8000,0.01,0.2,0,0,0,0)
`createsound("explosion",2,6200,700,2000,20,0.2,0,0,0,0)
`createsound("explosion2",3,1200,1400,3000,10,0.1,0,0,0,0)
createsound("powerup",4,800,700,8000,-0.02,0.2,0,0,0,0)
createsound("warning",5,800,1000,6000,0.5,0.1,0,0,0,0)
`createsound("vibrato1",6,500,2000,8000,0,0.1,0.05,0.2,0,0)
`createsound("vibrato2",7,400,2000,8000,0,0.1,0.05,0.2,0,0)
`createsound("vibrato3",8,600,2000,8000,0,0.1,0.05,0.2,0,0)
`createsound("bass hit",9,20,200,14000,0.00,1.2,.0,0,0,0)
`createsound("hihat",10,800,200,5000,60.06,2.2,.1,0,0,0)
`createsound("door knock",11,200,200,8000,.1,4.0,2.1,10,9.2,9.2)
createsound("vinyl scratch",12,500,200,8000,0.06,0.2,.1,0,0,0)
`createsound("cb1",13,250,500,2500,0.00001,0.2,4.0,0.4,0,0)
`createsound("cb2",14,500,500,2500,0.00001,0.2,4.0,0.4,0,0)
`createsound("cb3",15,437.5,1500,1500,0.0001,0.2,0.0,4.0,0.4,0)
`createsound("cb4",16,573.75,1500,1500,0.0,0.2,4.0,0.4,0,0)
`createsound("bubble burst",17,100,800,6000,-.4,2.0,0.1,10,1.2,0.2)
set text font "arial"
set text size 16
do
text 0,0,"Press keys 1 upwards:"
text 0,20,"1: laser"
text 0,40,"2: explosion1"
text 0,60,"3: explosion2"
text 0,80,"4: powerup"
text 0,100,"5: warning"
text 0,120,"6: vibrato"
text 0,140,"7: bass hit"
text 0,160,"8: hihat"
text 0,180,"9: door knock"
text 0,200,"0: vinyl scratch"
text 0,220,"-: cowbell"
text 0,240,"+: bubble burst"
if inkey$()="1" then if sound exist(1) then play sound 1:wait 300
if inkey$()="2" then if sound exist(2) then play sound 2:wait 300
if inkey$()="3" then if sound exist(3) then play sound 3:wait 300
if inkey$()="4" then if sound exist(4) then play sound 4:wait 300
if inkey$()="5" then if sound exist(5) then play sound 5:wait 300
if inkey$()="6" then if sound exist(6) then play sound 6:play sound 7:play sound 8:wait 300
if inkey$()="7" then if sound exist(9) then play sound 9:wait 300
if inkey$()="8" then if sound exist(10) then play sound 10:wait 300
if inkey$()="9" then if sound exist(11) then play sound 11:wait 300
if inkey$()="0" then if sound exist(12) then play sound 12:wait 300
if inkey$()="-" then if sound exist(13) then play sound 13:play sound 14:play sound 15:play sound 16:wait 300
if inkey$()="+" then if sound exist(17) then play sound 17:wait 300
loop
function createsound(name$,soundnumber,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#)
local outWord as word
local dword1 as dword
local dword2 as dword
local dword3 as dword
local dword4 as dword
local dword5 as dword
local dword6 as dword
local dword7 as dword
samples=int((length#/1000)*44100)
if memblock exist(soundnumber) then delete memblock soundnumber
make memblock soundnumber,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 soundnumber, position, dword1 : inc position,4
write memblock dword soundnumber, position, dword2 : inc position,4
write memblock dword soundnumber, position, dword3 : inc position,4
write memblock dword soundnumber, position, dword4 : inc position,4
write memblock dword soundnumber, position, dword5 : inc position,4
write memblock dword soundnumber, position, dword6 : inc position,4
write memblock dword soundnumber, position, dword7 : inc position,4
rem generate and write wave
for x=1 to samples
` gg output#=int(sin((x/122.5)*(frequency#+vibratodepth#*sin(theta#)))*(loudness#+tremelodepth#*sin(phi#)))*3.0
outInteger=int(sin((x/122.5)*(frequency#+vibratodepth#*sin(theta#)))*(loudness#+tremelodepth#*sin(phi#)))*3.0 ` gg
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 loudness#>0 then dec loudness#,decay#
write memblock word soundnumber, position, outWord : inc position,2
next x
make sound from memblock soundnumber, soundnumber
` save memblock data as txt file for manual checking
if dirset=0
dirset=1
set dir "media"
endif
blockSize=get memblock size(soundnumber)
fileName$="Sound"+str$(soundnumber)+".txt"
if file exist(fileName$) then delete file fileName$
open to write soundnumber,"Sound"+str$(soundnumber)+".txt"
` first print some summary data
write string soundnumber, "memblock size = "+str$(blockSize)
` now print the memblock, four bytes per line
block4=0: lineOut$=""
for i=0 to blockSize-1
newByteString$=str$(memblock byte(soundnumber,i))
newString$=space$(4-len(newByteString$))+newByteString$
lineOut$=lineOut$+newString$
inc block4
if block4=4
write string soundnumber, lineOut$
lineOut$=""
block4=0
endif
next i
` print final incomplete line if necessary
if block4>0 then write string soundnumber, lineOut$
` now test the sound
play sound soundnumber
wait key
endfunction