Flushmem a pain in the RRR

BlitzMax Forums/BlitzMax Programming/Flushmem a pain in the RRR

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.

Use your amazing powers to get this working then, Superduck. I'm sure it's a flushmem() problem.

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 slider_list:TList=CreateList()

sample_rate=44100
dt#=1.0/Float(sample_rate)

Type toneinfo
	Field amp# 'Max 32767
	Field dphase#
	Field phase#=0.0
	
	Function create:toneinfo(freq#,amp#,dt#,chan:String)
		temp:toneinfo=New toneinfo
		temp.dphase=360.0*freq*dt
		temp.amp=amp
		Select chan
			Case "l"
				DebugLog "creating tone on left channel"
				l_tone_list.addlast(temp)

			Case "r"
				DebugLog "creating tone on right channel"
				r_tone_list.addlast(temp)
			Default
				DebugLog "no channel assigned"
				temp=Null
		EndSelect
		
		Return temp
	End Function
End Type

Global l_tone_list:TList=CreateList()
Global r_tone_list:TList=CreateList()

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)
	
	
	Local snd_ptr:Short Ptr=Short Ptr(buff)
		
	For n=0 To (length/4)-1
	
		l_sound#=0.0
		r_sound#=0.0
		
		For l_tone:toneinfo=EachIn l_tone_list 
			l_sound:+l_tone.amp*Sin(l_tone.phase)
			l_tone.phase:+l_tone.dphase
		Next
		
		For r_tone:toneinfo=EachIn r_tone_list 
			r_sound:+r_tone.amp*Sin(r_tone.phase)
			r_tone.phase:+r_tone.dphase
		Next								
																																																																																									
		snd_ptr[0]=makesignedshort(l_sound)		'Left speaker
		snd_ptr[1]=makesignedshort(r_sound)		'Right speaker
		snd_ptr:+2

	Next
	
	l_tone.phase:Mod 360.0
	r_tone.phase:Mod 360.0	
	
	FlushMem()	
	
	Return 1
End Function

Local CallbackPtr:Byte Ptr = FMOD_Stream_Callback

Graphics 800,600

?Mac
FSOUND_SetOutput(FSOUND_OUTPUT_MAC)
?

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

toneinfo.create(100.0,32000.0,dt,"l")
toneinfo.create(107.83,32000.0,dt,"r")

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

Tslider.create(10,100,600,20,0,100,50)
While Not KeyHit(KEY_ESCAPE)
	Cls	
	Tslider.draw_all()
	FlushMem()
	Flip()
Wend

FSOUND_Stream_Close(stream)
FSOUND_Close()

End

Type Tslider
	Field x#,y#
	Field width#,height#
	Field minval#,maxval#
	Field val#
	Field colr#=200,colg#=200,colb#=200
	
	Function create:Tslider(x#,y#,width#,height#,minval#,maxval#,startval#)
		temp:Tslider=New Tslider
		temp.x=x
		temp.y=y
		temp.width=width
		temp.height=height
		temp.minval=minval
		temp.maxval=maxval
		temp.val=startval
		ListAddLast(slider_list,temp)
		Return temp
	End Function
	
	Function draw_all()
		For s:Tslider=EachIn slider_list
			SetColor s.colr,s.colg,s.colb
			DrawRect s.x,s.y,s.width,s.height
			SetColor 1.0,1.0,1.0
			DrawRect s.pos_at_val(s.val),s.y,1.0,s.height 
		Next
	End Function
	
	Method pos_at_val(value#)
		pos#=Self.x+((value-Self.minval)/(Self.maxval-Self.minval))*Self.width
		Return pos
	End Method
	
End Type
'No