ZX Spectrum BEEP in BlitzMax

Posted by TCK on 30 Mar 2008 | Tagged as: Programming, Remakes

I’ve been playing around with the idea of doing something in a very retro style – ZX Spectrum palette and UDG type graphics, so I wrote a little function to recreate the BEEP command so that you can play sounds just like on a Speccy.

The example tune from the ZX Spectrum 48K manual works without any alteration, apart from the removal of line numbers of course.

Here is the code and example for anyone who is interested…

Strict

' create audio sample

Local sample:TAudioSample=CreateAudioSample( 41,11025,SF_MONO8 )
For Local k=0 to 41
        sample.samples[k]=Sin(k*360/42)*120+120
Next

Global beepsound:TSound=LoadSound( sample,True )
Global beepchannel:TChannel

' Spectrum BEEP function
' note: program is halted while a BEEP is playing

Function BEEP (length:Float,note:Float)

	Local rate:Float=2^(note/12)
	beepchannel=PlaySound(beepsound)
	SetChannelRate(beepchannel,rate)

	Delay length*1000 ' wait for our note to finish
	StopChannel(beepchannel)

End Function

'an example tune from the ZX Spectrum 48K BASIC Manual

Print "Frere Gustav"
BEEP 1,0
BEEP 1,2
BEEP .5,3
BEEP .5,2
BEEP 1,0
BEEP 1,0
BEEP 1,2
BEEP .5,3
BEEP.5,2
BEEP 1,0
BEEP 1,3
BEEP 1,5
BEEP 2,7
BEEP 1,3
BEEP 1,5
BEEP 2,7
BEEP .75,7
BEEP .25,8
BEEP .5,7
BEEP .5,5
BEEP .5,3
BEEP.5,2
BEEP 1,0
BEEP .75,7
BEEP .25,8
BEEP .5,7
BEEP .5,5
BEEP .5,3
BEEP .5,2
BEEP 1,0
BEEP 1,0
BEEP 1,-5
BEEP 2,0
BEEP 1,0
BEEP 1,-5
BEEP 2,0

It’s very simple but it does the job and even halts your program until the sound is finished just like on the real machine.

Probably next is making a function for the music like in Manic Miner etc that plays (seemingly) without stopping the gameplay. I guess some kind of “BEEP queue” would do the trick.

I don’t think I have the grey matter to put together my own colour clash routine but thanks to Trashman on the RetroRemakes forums I know it’s possible – his BMax engine is very impressive and I can’t wait to see the resulting game that comes from it.

Share and Enjoy:
  • Digg
  • del.icio.us
  • StumbleUpon
  • Facebook
  • Slashdot
  • Google

One Response to “ZX Spectrum BEEP in BlitzMax”

  1. on 03 May 2008 at 2:00 pm 1.Sloan Kelly said …

    Brilliant! Brings back so many happy memories of reading the speccy manual cover to cover hundreds of times!

Trackback This Post | Subscribe to the comments through RSS Feed

Leave a Reply