Processing data with Audio Unit recording callback [iOS][Swift]

前端 未结 1 482
暖寄归人
暖寄归人 2021-01-17 04:45

I am creating a cross platform VOIP application which uses UDP to send and receive data. I am using audio units for the real time recording and playback. The communication i

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-17 05:11

    Apple recommends against using semaphores or calling Swift methods (such as encoders) inside any real-time Audio Unit callback. Just copy the data into a pre-allocated circular buffer inside the audio unit callback. Period. Do everything else outside the callback. Semaphores and signals included.

    So, you need to create a polling thread.

    Do everything inside a polling loop, timer callback, or network ready callback. Do your work anytime there is enough data in the FIFO. Call (poll) often enough (high enough polling frequency or timer callback rate) that you do not lose data. Handle all the data you can (perhaps multiple buffers at a time, if available) in each iteration of the polling loop.

    You may need to pre-fill the circular buffer a bit (perhaps a few multiples of your 640 UDP frame size) before starting to send, to account for network and timer jitter.

    0 讨论(0)
提交回复
热议问题