Forum Archive

ctypes question

JonB

I'm updating the AudioRecorder.py to record as a wav (so that wave module can get raw samples for plotting/visualization). Also, I wanted to use recordForDuration instead of record.

I'm trying to understand how to pass an argument to the function. The prototype is:

(BOOL)recordForDuration:(NSTimeInterval)duration

where

typedef double NSTimeInterval;

I thought in ctypes I would use this as follows:

started_recording=msg(recorder, c_bool, 'recordForDuration',[c_double], 1.0)

to record for 1 second. Is this the right way to pass a double into this function?

This call crashes pythonista. Strangely, after I reopen pythonista, the recorded file is exactly 1 second, so it seems like it is working, but just also crashing.

Any thoughts?

omz

Haven't tried this myself yet, so there might be other problems, but your selector string is incorrect, it should be 'recordForDuration:' (with a colon at the end).

JonB

Thanks. That may have helped. What finally worked, sort of, is that I had to ensure the object stayed in scope long enough for the record to complete (I.e sleep).

Does garbage collection have some way of knowing that a ctypes object can't be gc'd yet? Or do we sort of need to manage our own references? I guess in this case I also need to wait until it is done so I can release the object, since I'm guessing ctypes has no way of knowing which objects need to be explicitly released by objc?