I recently converted a program from DBPRO to AppGameKit, I believe the original was some kind of DBPRO Tutorial
but I couldn't find it in the newsletters but did find
https://www.thegamecreators.com/codebase/view/6c6649b8ae9a696be762832e939e2913
in the codebase and converted it as best as I could to AppGameKit and thought it needed its own thread
AGK Sound with Memblocks
//converted from the following darkbasic file in the code base
//https://www.thegamecreators.com/codebase/view/6c6649b8ae9a696be762832e939e2913
createsound(1,2995,2000,8000,0.02,0.1,0.60,3,0.64,5,10) //sound effect
createsound(2,6200,200,2000,20,0.2,0,0,0,0,10) //explosion
createsound(3,1200,600,3000,10,0.1,0,0,0,0,10) //explosion2
createsound(4,800,700,8000,-0.02,0.2,0,0,0,0,10) //powerup
createsound(5,800,1000,6000,0.5,0.1,0,0,0,0,5) //warning
createsound(6,500,2000,8000,0,0.1,0.05,0.2,0,0,1) //vibrato1
createsound(7,400,2000,8000,0,0.1,0.05,0.2,0,0,1) //vibrato2
createsound(8,600,2000,8000,0,0.1,0.05,0.2,0,0,1) //vibrator3
createsound(9,30,50,16000,0.00,1.5,.0,0,0,0,100) //bass hit
createsound(10,80,1000,5000,70.06,2.5,.1,0,0,0,2) //hihat
createsound(11,200,20,8000,.1,4.0,2.1,10,9.2,9.2,10) //door knock
createsound(12,500,80,8000,0.06,0.2,.1,0,0,0,10) //vinyl scratch
createsound(13,250,50,2500,0.00001,0.1,4.0,0.4,0,0,10) //cb1
createsound(14,500,50,2500,0.00001,0.1,4.0,0.4,0,0,10) //cb2
createsound(15,437.5,150,1500,0.0001,0.1,0.0,4.0,0.4,0,10) //cb3
createsound(16,573.75,150,1500,0.0,0.1,4.0,0.4,0.1,0.1,10) //cb4
createsound(17,50,80,6000,-.4,2.0,0.1,10,1.2,0.2,10) //bubbleburst
Hz=0
do
if GetRawKeyPressed(49) then PlaySound(1,100,0)
if GetRawKeyPressed(50) then PlaySound(2,100,0)
if GetRawKeyPressed(51) then PlaySound(3,100,0)
if GetRawKeyPressed(52) then PlaySound(4,100,0)
if GetRawKeyPressed(53) then PlaySound(5,100,0)
if GetRawKeyPressed(54)
PlaySound(6,100,0):PlaySound(7,100,0):PlaySound(8,100,0)
endif
if GetRawKeyPressed(55) then PlaySound(9,100,0)
if GetRawKeyPressed(56) then PlaySound(10,100,0)
if GetRawKeyPressed(57) then PlaySound(11,100,0)
if GetRawKeyPressed(58) then PlaySound(12,100,0)
if GetRawKeyPressed(48)
PlaySound(13,100,0):PlaySound(14,100,0):PlaySound(15,100,0):PlaySound(16,100,0)
endif
if GetRawKeyPressed(189) then PlaySound(17,100,0)
If GetRawKeyPressed(13)
//rain effect
for i =10 to 25
createsound(18+i,12*i,60*i,300+i,10*i,1.1*i,10*i,i,i,i,100*i)
PlaySound(18+i,100,0) //:sleep(300)
next i
Endif
if GetRawKeyPressed(32)
Hz=random(0,32767)
createsound(20,Hz,1000,6000,0.5,0.1,0,0,0,0,5)
PlaySound(20,100,1)
endif
Print("Press keys 1 upwards:")
Print("1: sound effect")
Print("2: explosion1")
Print("3: explosion2")
Print("4: powerup")
Print("5: warning")
Print("6: vibrato")
Print("7: bass hit")
Print("8: hihat")
Print("9: door knock")
Print("0: vinyl scratch")
Print("-: cowbell")
Print("+: bubble burst")
Print("Hz="+str(Hz))
sync()
loop
function createsound(soundnumber as integer,frequency as float,length as float,loudness as float,bend as float,decay as float,
vibratospeed as float,vibratodepth as float,tremelospeed as float,tremelodepth as float,attack as float)
//local sound as integer
local frames as integer
local data as integer
local size as integer
local mem as integer
local sec as float
local i as integer
local value as integer
//local Hz as float // the hertz of the sound
local w as float
sec = length/1000 //there is too big a delay here otherwise I'm not sure if in the original they were in milliseconds and not seconds
sec=1
data = sec * (44100 * (2*2)) // 176400 bytes per second
frames = data / 4
size = 2+2+4+4 + data
mem = CreateMemblock(size)
//samples = ((length / 1000) * 44100)
//mem=CreateMemblock(samples * 2 + 28)
SetMemblockByte(mem,0, 2) //The first 2 bytes of the memlbock store the number of channels (1 or 2 supported)
SetMemblockByte(mem,1, 0)
SetMemblockByte(mem,2,16) //the next 2 bytes store the bits per sample (8 (1 byte) or 16 (2 byte) supported)
SetMemblockByte(mem,3, 0)
SetMemblockint(mem,4,44100) // the next 4 bytes store the samples per second, for example 44100
SetMemblockint(mem,8,frames) // The next 4 bytes are the number of frames in the sound data, the size of the sound data in bytes can be calculated from this with the formula numFrames*(bitsPerSample/8)*channels.
//rem generate and write wave
local theta as float
local phi as float
local fallinloudness as float
local riseinloudness as float
theta = 0
phi = 0
fallinloudness = loudness
riseinloudness = loudness
position=0
for i=0 to data-1 step 4
outInteger = ceil(Sin(( i / 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
theta =theta+ vibratospeed
phi =phi+ tremelospeed
frequency =frequency-bend
if(fallinloudness < loudness)
fallinloudness =fallinloudness+ decay
endif
if(riseinloudness > 0)
riseinloudness = riseinloudness-attack
endif
SetMemblockShort(mem,12+position,outWord)
position = position+2
//SetMemblockShort(mem,12+i+0,outWord)
//SetMemblockShort(mem,12+i+2 ,outWord) // short 2 bytes −32768 through 32767
next
if getsoundexists(soundnumber)=1 then deletesound (soundnumber)
CreateSoundFromMemblock(soundnumber,mem)
DeleteMemblock(mem)
endfunction
It has some examples which kinda sound like theyre supposed to, I really need some way of appending two sounds
fubar