I have a strange bug in some code I'm writing - I'm streaming sound using FMOD, which calls a callback function where the user can write their sample data. (See my callback function below). I had it working, then tried to make some improvements and the sound became broken/choppy - weird thing is I can get rid of the problem by removing a for/next that iterates through a list from the function. The loop causes a problem even if it contains no code or there are no elements in the list. Can anyone shed any light on this?
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 DebugLog CountList(l_tone_list) DebugLog CountList(r_tone_list) For n=0 To (length/4)-1 l_sound#=0.0 r_sound#=0.0 rem For l_tone:toneinfo=EachIn l_tone_list l_sound:+l_tone.amp*Sin(l_tone.phase) l_tone.phase:+l_tone.dphase DebugLog l_tone.phase Next endrem 'Comment this for/next out and the jitters disappear! For r_tone:toneinfo=EachIn r_tone_list r_sound:+r_tone.amp*Sin(r_tone.phase) r_tone.phase:+r_tone.dphase Next '...... l_sound=32767.0*Sin(Float(sample)) r_sound=0.0 sample:+1 snd_ptr[0]=makesignedshort(l_sound) 'Left speaker snd_ptr[1]=makesignedshort(r_sound) 'Right speaker snd_ptr:+2 Next Return 1 End Function