Writing tapped buffers to disk asynchronously

I'd like to understand the most robust way to record audio to disk using AVAudioNodes installTap(onBus:bufferSize:format:block:) method.

Currently, I'm dispatching out the buffers I receive in my AVAudioNodeTapBlock to a serial dispatch queue then writing to disk using some Audio Toolbox methods, but my concern is that if I hold on to the buffer provided in the AVAudioNodeTapBlock for too long (due to disk I/O for example), I'll end up getting issues.

What I'm considering is creating my own larger pool of preallocated AVAudioPCMBuffers (a few seconds worth) and copying across the data from the buffer provided by the tap into one of the buffers from this larger pool in the AVAudioNodeTapBlock directly (no dispatch queue).

Is there a simpler way of handling this, or does this sound like the best route?

Replies

Running some tests, it looks like installTap(onBus:bufferSize:format:block:) manages its own buffer pool and will automatically create new buffers if you need to hold onto them for some duration. So no need to create your own buffer pool.