I’m using AVAudioEngine
to get a stream of AVAudioPCMBuffer
s from the device’s microphone using the usual installTap(onBus:)
setup.
To distribute the audio stream to other parts of the program, I’m sending the buffers to a Combine publisher similar to the following:
private let publisher = PassthroughSubject<AVAudioPCMBuffer, Never>()
I’m starting to suspect I have some kind of concurrency or memory management issue with the buffers, because when consuming the buffers elsewhere I’m getting a range of crashes that suggest some internal pointer in a buffer is NULL
(specifically, I’m seeing crashes in vDSP.convertElements(of:to:)
when I try to read samples from the buffer).
These crashes are in production and fairly rare — I can’t reproduce them locally.
I never modify the audio buffers, only read them for analysis.
My question is: should it be possible to put AVAudioPCMBuffer
s into a Combine pipeline? Does the AVAudioPCMBuffer
class not retain/release the underlying AudioBufferList
’s memory the way I’m assuming? Is this a fundamentally flawed approach?