Still the same sounds, but I've added some post effects like echo and reverb. It will all make more sense when I've added more modifiers and a GUI with simple sliders for everything.

`import "Random.lib"`

constant:

SAMPLE_RATE 11025

BITS_8 8

BITS_16 16

hidden:

' Duration in seconds.

duration# = 0.75

' Base volume.

baseVolume# = 0.5

' Data in float format [-1..1]

data#[int(float(SAMPLE_RATE)*duration)]

' Generate explosion sound.

vol# = 1.0

for i = 0 to sizeof(data) - 1

' Noise.

data[i] = (RandomFloat(2.0) - 1.0)*baseVolume*vol

' Fade out.

vol = vol - 1.0/float(sizeof(data))

next

data#[] = Smooth(data, 8)

data#[] = Echo(data, 4, 0.5, 0.25)

data#[] = Reverb(data, 0.02, 0.5)

' Write file

_WriteWave "noise.wav", BITS_16, SAMPLE_RATE, data

' Generate beep sound with square/sine mix.

data#[int(float(SAMPLE_RATE)*duration)]

a# = 0.0

vol# = 1.0

' 50% square, 50% sine

square# = 0.5

for i = 0 to sizeof(data) - 1

value# = (1.0 - square)*sin(a)

if sin(a) > 0.0; value = value + square

else; value = value - square

endif

data[i] = value*baseVolume*vol

a = a + 8.0

while a > 360.0; a = a - 360.0; wend

' Fade out.

vol = vol - 1.0/float(sizeof(data))

next

' Write file

_WriteWave "sine.wav", BITS_16, SAMPLE_RATE, data

' Generate ... weird sound.

data#[int(float(SAMPLE_RATE)*duration)]

a# = 0.0

b# = 0.0

vol# = 1.0

volIn# = 0.0

for i = 0 to sizeof(data) - 1

' Weird.

data[i] = sin(a)*baseVolume*volIn*vol

a = a + (1.0 + sin(b))*8.0

b = b + 0.5

while a > 360.0; a = a - 360.0; wend

while b > 360.0; b = b - 360.0; wend

' Fade out.

volIn = min#(volIn + 4.0/float(sizeof(data)), 1.0)

vol = vol - 1.0/float(sizeof(data))

next

data#[] = Echo(data, 2, 0.65, 0.4)

data#[] = Reverb(data, 0.02, 0.5)

' Write file

_WriteWave "weird.wav", BITS_16, SAMPLE_RATE, data

' Load the files.

load sound 0, "noise.wav"

load sound 1, "sine.wav"

load sound 2, "weird.wav"

' Play the sound effect when player presses the space bar.

set caret width(primary)/2, 8

center "[1] Play explosion"

center "[2] Play beep "

center "[3] Play weird "

center

center "[Esc] Exit "

do

if keydown("1", true) then play sound 0

if keydown("2", true) then play sound 1

if keydown("3", true) then play sound 2

wait 16

until keydown(27, true)

' ==============================================================================

' Apply echo effect to data and return as new buffer.

' count - number of echoes

' delay - echo delay in seconds

' drop - volume drop in percent for each echo

' ==============================================================================

function Echo#[](&data#[], count, delay#, drop#)

delayi = int(delay*float(SAMPLE_RATE))

vol# = 1.0*drop

newData#[sizeof(data) + delayi*count]

for i = 0 to sizeof(data) - 1; newData[i] = data[i]; next

for i = 1 to count

for j = 0 to sizeof(data) - 1

newData[i*delayi + j] = max#(min#(newData[i*delayi + j] + data[j]*vol, 1.0), -1.0)

next

vol = vol*drop

next

return newData

endfunc

function Reverb#[](&data#[], delay#, drop#)

delayi = int(delay*float(SAMPLE_RATE))

newData#[sizeof(data) + delayi]

for i = 0 to sizeof(data) - 1; newData[i] = data[i]; next

for i = 0 to sizeof(data) - 1

newData[i + delayi] = max#(min#(newData[i + delayi] + newData[i]*drop, 1.0), -1.0)

next

return newData

endfunc

function Smooth#[](&data#[], steps)

newData#[sizeof(data)]

mx = sizeof(data) - 1

for i = 0 to sizeof(data) - 1

sum#

c

for j = -steps to steps

sum = sum + data[min(max(i + j, 0), mx)]

ADD c 1

next

newData[i] = sum/float(c)

next

return newData

endfunc

' ===============================================================================

' Write wave file from float data.

' filename - name of output file (wav)

' fmt - BITS_8 or BITS_16

' rate - sample rate (11025, 22050 ...)

' data - sound data as float array, values in range [-1 .. 1]

' ===============================================================================

procedure WriteWave(filename$, fmt, rate, &data#[])

rate = rate

create file 0, filename$, true

' Write header.

_WriteBytes 0, "RIFF"

if fmt = BITS_8

write32 0, 36 + sizeof(data)

else

write32 0, 36 + sizeof(data)*2

endif

_WriteBytes 0, "WAVE"

_WriteBytes 0, "fmt "

write32 0, 16

write16 0, 1

write16 0, 1

' Sampe rate.

write32 0, rate

' Byte rate.

if fmt = BITS_8

write32 0, rate

else

write32 0, rate*2

endif

if fmt = BITS_8

write16 0, 1

write16 0, 8

else

write16 0, 2

write16 0, 16

endif

_WriteBytes 0, "data"

if fmt = BITS_8

write32 0, sizeof(data)

else

write32 0, sizeof(data)*2

endif

' Write data.

if fmt = BITS_8

for i = 0 to sizeof(data) - 1

write8 0, 127 + int(data[i]*127.0)

next

else

for i = 0 to sizeof(data) - 1

write16 0, int(data[i]*32000.0)

next

endif

free file 0

endproc

' ===============================================================================

' Write string as bytes.

' ===============================================================================

procedure WriteBytes(f, bytes$)

for i = 0 to len(bytes) - 1

write8 f, asc(mid(bytes, i))

next

endproc