I am trying the fmod library on mac OSX, using Xcode (gcc) and writing a test program using the Qt library from trolltech.
To signal the end of stream play I understood a callback is needed, and (thanks to suggestions from this forum) it is going on like this:
// in header
static signed char streamEndcallback(FSOUND_STREAM *stream, void *buff, int len, int param);
// in implementation
signed char myClass::streamEndcallback(FSOUND_STREAM *, void buff, int, int param)
myClass sourceObj = (myClass*)(param);
FSOUND_Stream_SetEndCallback(stream, myClass::streamEndcallback, (int)(this));
This works, but it forces to use (myClass)(param) that casts a pointer to an int (and viceversa of course), that is equivalent to a awful reinterpret_cast<myClass>(param).
This is dangerous, since there is no guarantee that on some other machine the cast of a pointer to and from an integer will succeed.
Being a multiplatform library, I believe it would be much better to have something like
static signed char streamEndcallback(FSOUND_STREAM stream, void *buff, int len, void param);
this would allow anybody to pass a & to anything, even an int of course.
I am not a very experienced C++ programmer so I may be wrong. Any opinion?
One more point about callback: stopping the stream and closing it in a function directly called by callback lead to a program crash. Triggering a timer with zero delay (that postpones the operation top next round of event loop) and there closing solved the situation. Is it a regular behaviour?
Well, since this is my fisrts post I say hi to everybody, and thank you!
- You must login to post comments
Please login first to submit.