Glad to see a coding challenge with no media!
I would like to contribute you a code ported from DBP,
so you can create sound effects with code!
Raise the bar
/*
AGK Wave sound creator
======================
by Ric, and:
Tommy S - Original waveform code
Green Gandalf - Memblock format
Lampton Worm - Load/Save format
Lampton Worm/Raven - Real time parameter editor
Xtom - GUI/parameter editor
ported by Jack from DBP to AGK
*/
render_x = 1024
render_y = 768
SetOrientationAllowed( 0, 0, 1, 0 )
SetWindowSize( render_x, render_y, 1 )
setvirtualresolution(render_x,render_y)
SetResolutionMode( 1 )
SetScreenResolution( render_x,render_y )
SetSyncRate(60,0)
print("please wait")
sync()
createsound("sound effect",1,2995,2000,8000,0.02,0.1,0.60,3,0.64,5,10)
createsound("explosion",2,6200,200,2000,20,0.2,0,0,0,0,10)
createsound("explosion2",3,1200,600,3000,10,0.1,0,0,0,0,10)
createsound("powerup",4,800,700,8000,-0.02,0.2,0,0,0,0,10)
createsound("warning",5,800,1000,6000,0.5,0.1,0,0,0,0,5)
createsound("vibrato1",6,500,2000,8000,0,0.1,0.05,0.2,0,0,1)
createsound("vibrato2",7,400,2000,8000,0,0.1,0.05,0.2,0,0,1)
createsound("vibrato3",8,600,2000,8000,0,0.1,0.05,0.2,0,0,1)
createsound("bass hit",9,30,50,16000,0.00,1.5,.0,0,0,0,100)
createsound("hihat",10,800,40,5000,60.06,2.2,.1,0,0,0,10)
createsound("door knock",11,200,20,8000,.1,4.0,2.1,10,9.2,9.2,10)
createsound("vinyl scratch",12,500,80,8000,0.06,0.2,.1,0,0,0,10)
createsound("cb1",13,250,50,2500,0.00001,0.1,4.0,0.4,0,0,10)
createsound("cb2",14,500,50,2500,0.00001,0.1,4.0,0.4,0,0,10)
createsound("cb3",15,437.5,150,1500,0.0001,0.1,0.0,4.0,0.4,0,10)
createsound("cb4",16,573.75,150,1500,0.0,0.1,4.0,0.4,0,0,10)
createsound("bubble burst",17,50,80,6000,-.4,2.0,0.1,10,1.2,0.2,10)
SetPrintSize(20)
do
print("Press keys to play a sound (sound warning!):")
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("q: cowbell")
print("w: bubble burst")
if GetRawKeyPressed(49)=1
PlaySound(1)
print("1")
sleep( 300 )
endif
if GetRawKeyPressed(50)=1
PlaySound(2)
print("2")
sleep( 300 )
endif
if GetRawKeyPressed(51)=1
PlaySound(3)
print("3")
sleep( 300 )
endif
if GetRawKeyPressed(52)=1
PlaySound(4)
print("4")
sleep( 300 )
endif
if GetRawKeyPressed(53)=1
PlaySound(5)
print("5")
sleep( 300 )
endif
if GetRawKeyPressed(54)=1
PlaySound( 6)
PlaySound( 7)
PlaySound( 8)
print("6")
sleep( 300 )
endif
if GetRawKeyPressed(55)=1
PlaySound(9)
sleep( 300 )
print("7")
endif
if GetRawKeyPressed(56)=1
PlaySound(10)
sleep( 300 )
endif
if GetRawKeyPressed(57)=1
PlaySound(11)
sleep( 300 )
endif
if GetRawKeyPressed(48)=1
PlaySound(12)
sleep( 300 )
endif
if GetRawKeyPressed(81)=1
PlaySound(13)
PlaySound(14)
PlaySound(15)
PlaySound(16)
sleep( 300 )
endif
if GetRawKeyPressed(87)=1
PlaySound(17)
sleep( 300 )
endif
sync()
loop
function createsound(name$,soundnumber,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#,attack#)
// define temporary variables
outWord as integer
dword1 as integer
dword3 as integer
dword4 as integer
dword5 as integer
fallinloudness# as float
phi# as float
theta# as float
position as integer
samples as integer
samples=(length#/1000)*44100
// create a new, empty memblock 1
if GetMemblockExists(1)=1 then DeleteMemblock(1)
CreateMemblock(1,samples*2+28)
` header bytes
channels=1 ` CHANNELS (2 bytes)
bits=8 ` BITS (2 bytes)
hz=44100 ` HZ (4 bytes)
totallength=samples*(bits/8)*channels ` TOTAL LENGTH (4 bytes)
// Header for a wav file
SetMemblockShort(1,position,channels)
inc position,2
SetMemblockShort(1,position,bits)
inc position,2
SetMemblockInt(1,position,hz)
inc position,4
SetMemblockInt(1,position,totallength)
inc position,4
// generate and write wave - actual content
riseinloudness#=loudness#
for x=1 to samples
outInteger=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
SetMemblockbyte(1,position,outWord)
inc position,2
next x
// create sound file from memblock
if GetSoundExists(soundnumber)=1 then DeleteSound(soundnumber)
CreateSoundFromMemblock(soundnumber,1)
// memblock no longer required
DeleteMemblock(1)
endfunction