iosswiftaudioavaudioengine

What is AVAudioEngine's max microphone tap speed?


In an iOS app, using swift, I'm doing this in order to get waveform data from the microphone:

let BUFSZ = 2400
AVAudioEngine.inputNode.installTap(onBus: 0, bufferSize: BUFSZ, format: AVAudioEngine.inputNode.outputFormat(forBus: 0)) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
   my callback
}

I've discovered that the fastest I can get my callback is about 10hz, and the minimum resulting frame size of the buffer in the tap callback is 4800, no matter how small I make BUFSZ.

Is this expected? It seems slow, especially if I want to make real-timey apps. Is there a way in the apple ecosystem for iOS to get data from the microphone faster?


Solution

  • Taps are not meant for real-time access to audio data. They're "to the side," not part of the pipeline. They're convenient when you just need the data "soon," but not what you want for real-time applications.

    If you want to be integrated directly into the pipeline, use an AVAudioSinkNode to consume the data.