Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when installing a tap on audio engine input node

whenever the code reaches inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) {[weak self] (buffer:AVAudioPCMBuffer, when:AVAudioTime), app is crashing with following error

Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: format.sampleRate == hwFormat.sampleRate'

I tired removing taps before adding another and I'm making sure I'm not adding more than one tap. what is weird is that the app is working fine with iOS less than 12, and working fine on all simulators.

it is crashing only on real devices with iOS 12. I tried searching for a solution but could't find any thing.

like image 661
mahdi Avatar asked Nov 01 '25 07:11

mahdi


1 Answers

This is a sample rate mismatch.

The input node's format can't be changed so you need to match it. installTap listens to the output of a node, so use inputNode's output format.

inputNode.installTap(onBus: 0, bufferSize: 1024, format: inputNode.outputFormat(forBus: 0))

Another option is to connect the input to a mixer, then tap the mixer using the preferred recording format. Mixers perform implicit sample rate conversions between their inputs and output.

like image 116
dave234 Avatar answered Nov 03 '25 21:11

dave234