Ive added the Beep command into my ZX82 Engine which is being built using version 2 of the App Game Kit. Since AGKV2 doesnt run using VS2010 right now I coded it using AppGameKit basic and will port it to the real C++ version of the engine later.
It simulates the ZX Spectrum's Beep command. For example the command beep(1, 0) will play the note middle C for 1 second. I use the CreateSoundFromMemblock in AppGameKit version 2 to create each sound. This requires me to write each byte of the sound file manually. The video below is based on the beep command example in my ZX Spectrum Manual.
Here is a striped down function based on the one I used in my engine to produce and play a beep using memblocks.
function beep(soundNumber, duration#, frequency)
length = frequency * duration#
size = 12 + (length * 4)
memblock = CreateMemblock(size)
SetMemblockByte(memblock, 0, 1)
SetMemblockByte(memblock, 1, 0)
SetMemblockByte(memblock, 2, 8)
SetMemblockByte(memblock, 3, 0)
SetMemblockInt(memblock, 4, frequency)
SetMemblockInt(memblock, 8, length)
for i = 12 to (size/4) - 4 step 4
SetMemblockInt(memblock, i, 255)
next i
soundNumber = CreateSoundFromMemblock(1, memblock)
DeleteMemblock(memblock)
PlaySound(soundNumber)
endfunction