omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    ctypes question

    Pythonista
    2
    3
    1420
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JonB
      JonB last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        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).

        1 Reply Last reply Reply Quote 0
        • JonB
          JonB last edited by

          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?

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors