Wrapping C, void pointer
I am wrapping PortAudio for RPython. Following the source code in RSDL as a guide i can clearly see what to do with constants, structs, functions and so on. So far so good until i reached something new in PortAudio i am not sure how to deal with, a void typedef and a void pointer. In the RSDL example pointers were defined by Ptr = lltype.Ptr(lltype.ForwardReference()), then in the CConfig class the struct was defined and rffi_platform.configure parses, finally the Ptr is told TO become the type - given the output of platform.configure. How do we deal with this situation from PortAudio? # from portaudio.h typedef void PaStream; PaError Pa_OpenStream( PaStream** stream, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData ); ############################### I have tried the following but it fails when i try to malloc the void pointer. OpenDefaultStream = external( 'Pa_OpenDefaultStream', [ rffi.VOIDPP, # PaStream** rffi.INT, # numInputChannels rffi.INT, # numOutputChannels rffi.INT, # sampleFormat rffi.INT, # sampleRate rffi.INT, # framesPerBuffer rffi.INT, #streamcallback rffi.VOIDP, #userData ], rffi.INT ) Stream = lltype.Void #rffi.VOIDP def test(): print 'portaudio version %s' %GetVersion() assert Initialize() == 0 # paNoError = 0, error code is returned on init fail. stream = lltype.malloc(Stream, flavor='raw') try: ok = OpenDefaultStream( stream, 1, 1, Int16, 22050, FramesPerBufferUnspecified, 0 ) finally: lltype.free(stream, flavor='raw') Terminate() -brett
Hi Armin, i wanted something faster than ctypes, i think thats why Hubert Pham used the Python C API when doing pyaudio before, also i want to do DSP on the samples and want to option to do as many effects as possible in real-time. I figured out my problem, rpyportaudio is on google code now, http://code.google.com/p/rpyportaudio/ --- On Fri, 8/13/10, Armin Rigo <arigo@tunes.org> wrote:
From: Armin Rigo <arigo@tunes.org> Subject: Re: [pypy-dev] Wrapping C, void pointer To: "Hart's Antler" <bhartsho@yahoo.com> Cc: pypy-dev@codespeak.net Date: Friday, 13 August, 2010, 1:39 AM Hi Hart,
On Thu, Aug 12, 2010 at 06:42:23PM -0700, Hart's Antler wrote:
I am wrapping PortAudio for RPython.
Why? Writing it in standard ctypes would give really bad performance?
Armin
participants (2)
-
Armin Rigo -
Hart's Antler