[pypy-dev] RPython function callback from C
Hart's Antler
bhartsho at yahoo.com
Sat Aug 14 03:51:00 CEST 2010
I have the PortAudio blocking API working, simple reading and writing to the sound card works. PortAudio also has an async API where samples are fed to a callback as they stream in. But i'm not sure how to define a RPython function that will be called as a callback from C, is this even possible? I see some references in the source of rffi that seems to suggest it is possible. Full source code is here http://pastebin.com/6YHbT7CU
I'm passing the callback like this:
def stream_callback( *args ):
print 'stream callback'
return 0 # 0=continue, 1=complete, 2=abort
stream_callback_ptr = rffi.CCallback([], rffi.INT)
OpenDefaultStream = rffi.llexternal( 'Pa_OpenDefaultStream',
[
StreamRefPtr, # PaStream**
rffi.INT, # numInputChannels
rffi.INT, # numOutputChannels
rffi.INT, # sampleFormat
rffi.DOUBLE, # double sampleRate
rffi.INT, # unsigned long framesPerBuffer
#rffi.VOIDP, #PaStreamCallback *streamCallback
stream_callback_ptr,
rffi.VOIDP, #void *userData
],
rffi.INT, # return
compilation_info=eci,
_callable=stream_callback
)
entrypoint():
...
callback = lltype.nullptr( stream_callback_ptr.TO )
ok = OpenDefaultStream( streamptr, 2, 2, Int16, 22050.0, 512, callback, userdata )
More information about the Pypy-dev
mailing list