pyFMOD writing a callback function in Python

Marian Aldenhövel marian at mba-software.de
Thu Feb 10 04:01:47 EST 2005


Hi,

I am using the FMOD audio-library with the pyFMOD python bindings. pyFMOD uses
ctypes. It is possible to register callback functions with FMOD that are
called at certain points in the processing pipeline or when certain events
happen.

I am expecially interested in the one that fires when a currently playing
stream ends. This is what the declaration in pyFMOD looks like:

   _FSOUND_Stream_SetEndCallback =
      getattr(fmod,"_FSOUND_Stream_SetEndCallback at 12")
   _FSOUND_Stream_SetEndCallback.restype = c_byte
   def FSOUND_Stream_SetEndCallback(stream, callback, userdata):
      result = _FSOUND_Stream_SetEndCallback(c_int(stream), c_int(callback),
                                             c_int(userdata))
      if not result: raise fmod_exception()

I cannot make it work, however. I tried:

   def _sound_end_callback(stream,buf,len,userdata):
     print "_sound_end_callback(): Stream has reached the end."

as simplest possible callback function. I am registering it like this:

   pyFMOD.FSOUND_Stream_SetEndCallback(_currenttrack,_sound_end_callback,0)
				
And this is how my program dies:

   File "d:\projekte\eclipse\workspace\gettone\gettonesound.py", line 175, in 
sound_tick
     pyFMOD.FSOUND_Stream_SetEndCallback(_currenttrack,_sound_end_callback,0)
   File "c:\programme\Python23\lib\site-packages\pyFMOD.py", line 690, in 
FSOUND_Stream_SetEndCallback
     result = _FSOUND_Stream_SetEndCallback(c_int(stream), c_int(callback), 
c_int(userdata))
TypeError: int expected instead of function instance

I am very new to Python and have zero idea what the problem is nor how to
solve it. In some of my other languages I would have to explicitly make a
function pointer and possibly have to cast that to an int to pass it to
SetEndCallback, but that seems very inappropriate in Python...

Ciao, MM
-- 
Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.
http://www.marian-aldenhoevel.de
"Wir brauchen keine Opposition, wir sind bereits Demokraten."



More information about the Python-list mailing list