I'm using AudioUnit for access to RemoteIO for high-performance audio. My app decodes signals which are embedded in audio received from the microphone. For accuracy, I need to keep audio filtering & manipulation down to a minimum. I do this to the audio session:
UInt32 mode = kAudioSessionMode_Measurement;
Float32 zeroF = 0;
UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_Mode, sizeof(mode), &mode);
AudioSessionSetProperty(kAudioSessionProperty_InputGainScalar, sizeof(zeroF), &zeroF);
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory);
and this to the audio unit:
UInt32 one = 1;
UInt32 zero = 0;
AudioUnitSetProperty(rioUnit, kAUVoiceIOProperty_BypassVoiceProcessing, kAudioUnitScope_Input, 0, &one, sizeof(one));
AudioUnitSetProperty(rioUnit, kAUVoiceIOProperty_VoiceProcessingEnableAGC, kAudioUnitScope_Input, 0, &zero, sizeof(zero));
AudioUnitSetProperty(rioUnit, kAUVoiceIOProperty_DuckNonVoiceAudio, kAudioUnitScope_Input, 0, &zero, sizeof(zero));
This seems to work, although there's definitely still some gain correction going on.
My problem is when the user presses the Home button to leave the app, then taps the app icon to return to it. Something changes about the audio, and it appears to be that iOS is enabling noise suppression and gain control. Here's a spectrogram of the audio - note the huge dropoff in power across the whole audio spectrum, halfway through the graph. This is when I left the app and then re-opened it.
- X axis is time
- Y axis is frequency (0-22050 Hz)
- pixel lightness is power (black=-128 dB, white = 0 dB)
I feel like I've tried everything – stopping & restarting the audio unit, stopping & restarting the audio session... nothing seems to help at all. Would love any tips for what to try.