FMOD Community Project

BlitzMax Forums/BlitzMax Programming/FMOD Community Project

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Soz Petbom, not looked at that, but on a different note...

Framework brl.glmax2d
'----------------------
Import brl.retro
Import brl.blitz
Import brl.freeaudioaudio
'Import brl.oggloader   'causes probs with fmod on mac, thats why I had to use framework. Any help?
Import brl.system	
Import pub.fmod
Import brl.keycodes
Import brl.standardio

Global sample
sample=0

Function makesignedshort:Short(float_num#)
	x=Long(float_num)
	val_bits:Short=Short(x&%0111111111111111)
	sign_bit:Short=Short((x Shr 16)&%1000000000000000)
	short_val:Short=Short(sign_bit|val_bits)
	Return short_val
End Function
	
Function FMOD_Stream_Callback(stream:Byte Ptr, buff:Byte Ptr, length:Int, userdata:Byte Ptr)
	'Print "Hello"
	Print "callback!"
	Print length
	
	Local snd_ptr:Short Ptr=Short Ptr(buff)
	'Print "going to loop"
	'1942
	'2183
	
	For n=0 To (length/4)-1
		'Print n
		snd_ptr[0]=makesignedshort(32767.0*Sin(Float(sample)))		'Left speaker
		snd_ptr[1]=makesignedshort(32767.0*Sin(1.5*Float(sample)))	'Right speaker
		snd_ptr:+2
		sample:+1
	Next
	
	Return 1
End Function

Local CallbackPtr:Byte Ptr = FMOD_Stream_Callback

?Mac
FSOUND_SetOutput(FSOUND_OUTPUT_MAC)
?

FSOUND_SetDriver(0)
If Not FSOUND_Init(44100, 16, 0)
	Print "error"
EndIf

Local stream:Int = FSOUND_Stream_Create(CallbackPtr, 6*2048, FSOUND_NORMAL|FSOUND_16BITS|FSOUND_STEREO, 44100, Null)
FSOUND_Stream_Play(FSOUND_FREE, stream)

If (FSOUND_Stream_Play(FSOUND_FREE, NSFStream) = -1)
	Print("Error!")
EndIf

WaitKey()

FSOUND_Stream_Close(stream)
FSOUND_Close()

End

Finally got a streaming sound working with FMOD - ever taken absolute ages to get something working, and then forget why it was such a hassle? I did with this. Plays a different (streamed) tone through each speaker. Works fine on my Mac mini, untested on PC.