I need to get the microphone output in a certain format that isn't equal to the hw format. To do this, I'm creating a AVAudioMixerNode which will have that format as it's output. However, I never receive any buffers when installing the tap on the mixer node. I thought the inputNode would flow upstream? Am I doing something wrong? Note that I'm not using AudioUnits or AudioQueues because I need to do some frequency filtering on the actual audio stream and thought this was the easiest way to do it.
Here's the code:
mixerNode = [[AVAudioMixerNode alloc]init];
//Attach node
[theEngine attachNode:mixerNode];
//Then connect inputNode (mic) to mixer node
[theEngine connect:theEngine.inputNode
to:mixerNode
format:[theEngine.inputNode outputFormatForBus:0]];
[theEngine startAndReturnError:&theError];
//Now set up the real audio format i want
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = 8000;
audioFormat.mChannelsPerFrame = numberOfChannels;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
audioFormat.mBitsPerChannel = 16;
audioFormat.mBytesPerPacket = audioFormat.mBytesPerFrame = (audioFormat.mBitsPerChannel / 8) * audioFormat.mChannelsPerFrame;
audioFormat.mFramesPerPacket = 1;
//Now install the tap on the mixer so we get the correct format
[mixerNode installTapOnBus:0
bufferSize:4096
format:[[AVAudioFormat alloc]initWithStreamDescription:&audioFormat]
block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
NSLog(@"got buff");
}];