Is BMax fast enough for realtime sound synthesis?

BlitzMax Forums/BlitzMax Programming/Is BMax fast enough for realtime sound synthesis?

'ere be a test.

2 issues:
- obvious stutter, is this all BMax can do, or am I coding p00?
- What's up with that sample format? I clearly chose a 16bit signed format, and yet the result seems to be 8bit unsigned. o_O (move mouse below 127)

SuperStrict

Const freq:Int=44100
Const updatespeed:Int=10
Const buffersize:Int=freq/updatespeed

Global my:Int ' mouse y position

Local buffer:TAudioSample[2]
	buffer[0]=CreateAudioSample(buffersize,freq,SF_STEREO16BE)
	buffer[1]=CreateAudioSample(buffersize,freq,SF_STEREO16BE)
	
Local channel:TChannel[2]
	channel[0]=AllocChannel()
	channel[1]=AllocChannel()
	

Local sound:TSound[2]
	sound[0]=LoadSound(buffer[0])
	sound[1]=LoadSound(buffer[1])

Local timer:TTimer=CreateTimer(updatespeed)

Graphics 640,480

Local currentbuffer:Int
Local t:Int


Repeat
	WaitEvent()
	
	If EventID()=EVENT_TIMERTICK
	
		PlaySound sound[currentbuffer],channel[currentbuffer]
		
		currentbuffer=1-currentbuffer
		
		Cls				
		
		calcnew buffer,currentbuffer
		sound[currentbuffer]=LoadSound(buffer[currentbuffer])
		
		SetColor 255,255,255
		For t=0 Until Min(buffersize,640)
			Plot t,240+buffer[currentbuffer].samples[t]
		Next
		DrawText my,0,0
		Flip
	EndIf
	
	my=MouseY()
	
	If KeyDown(KEY_ESCAPE) End
Forever


Function calcnew(buffer:TAudioSample[],index:Int)
	Local ratio:Int=Rnd(15)
	Cls
	Local a:Int
	For Local t:Int=0 Until buffersize
		a=Sin((t*ratio))*my
		buffer[index].samples[t]=a
		SetColor 255,128,64
		Plot t,240+a
	Next
End Function