Quit callback's calling from inside the callback => probl
Posted: Thu May 22, 2003 9:20 pm
Hi!
I've got a strange problem at the moment, which needs some more words to explain:
I just coded a small program, that plays a sound via a stream-callback using fmod (but you don't need to know fmod to understand my problem).
So there's a callback-procedure, that is called every time from the stream, when the stream-buffer is empty. The callback-procedure fills the buffer again with data. (using CopyMemory or leave it as it is)
I made this several times, and it always worked fine.
But now I tried to stop the stream, which is calling the callback-procedure, from the INSIDE of the callback-procedure to stop it exactly after one buffer-length.
When I start this program from PB, all is OK, and it works as expected.
But when I compile it to an EXE, the program hangs up immediately at the moment, when I stop the stream in this way.
[One more observation: The loopcounter increases + 1 from PB, from the EXE the program hangs up before I see the increased loopcount]
My question now:
Is this a problem of stdcall / cdecl or anything like that ? Is it perhaps unlogical to quit the 'callbacks caller' from the inside of the callback, or what is wrong with it, and why does it work from PB, but not from a compiled EXE ??
You can get the whole small (and well-commented) PB-code, a small WAV, the fmod.dll and a compiled EXE, here (193kB) : http://www.public.2mal2mal.de (samplelooper.zip)
Just run the program from PB or directly the EXE, choose the 'car.wav' to play, start it and then stop it through 'Stop immediately after actual loop'.
And here I post the callback-routine:
Does anyone have an idea ? 8O
I've got a strange problem at the moment, which needs some more words to explain:
I just coded a small program, that plays a sound via a stream-callback using fmod (but you don't need to know fmod to understand my problem).
So there's a callback-procedure, that is called every time from the stream, when the stream-buffer is empty. The callback-procedure fills the buffer again with data. (using CopyMemory or leave it as it is)
I made this several times, and it always worked fine.
But now I tried to stop the stream, which is calling the callback-procedure, from the INSIDE of the callback-procedure to stop it exactly after one buffer-length.
When I start this program from PB, all is OK, and it works as expected.
But when I compile it to an EXE, the program hangs up immediately at the moment, when I stop the stream in this way.
[One more observation: The loopcounter increases + 1 from PB, from the EXE the program hangs up before I see the increased loopcount]
My question now:
Is this a problem of stdcall / cdecl or anything like that ? Is it perhaps unlogical to quit the 'callbacks caller' from the inside of the callback, or what is wrong with it, and why does it work from PB, but not from a compiled EXE ??
You can get the whole small (and well-commented) PB-code, a small WAV, the fmod.dll and a compiled EXE, here (193kB) : http://www.public.2mal2mal.de (samplelooper.zip)
Just run the program from PB or directly the EXE, choose the 'car.wav' to play, start it and then stop it through 'Stop immediately after actual loop'.
And here I post the callback-routine:
Code: Select all
Procedure.l Loop_Callback (*hStream, *Buffer, length, dummy)
If loopcount <= 1 ; (load the data only the first two times to spare CPU-time - two times because of double-buffering -> *Buffer flips)
FSOUND_Sample_Lock(*hSample, 0, sample_length_bytes, @*SourceData, @*Dummy2, @SourceDataLen, @Dummy3)
If SourceDataLen = sample_length_bytes ; (just a small logical check)
CopyMemory(*SourceData, *Buffer, SourceDataLen)
EndIf
FSOUND_Sample_Unlock(*hSample, @*SourceData, @*Dummy2, @SourceDataLen, @Dummy3)
EndIf
;>>>>>>>>>>>>>>> NOW !
;>>>>>>>>>>>>>>> The next line stops this callback-procedure's calling stream
If stopplaying : FSOUND_Stream_Stop(*hLoopStream) : EndIf ; (stops immediately after the actual loop, exactly BEFORE this one, which would be the next.)
loopcount + 1
ProcedureReturn continueplaying ; (if continueplaying is 0, then sound stops after listening to the other buffer a last time)
EndProcedure