0

CoreAudio is always a mystery due to lack of documentations. Recently I hit some stone again:

In my program, I invoke RemoteIO and VoiceProcessingIO (VPIO) back and forth, and also change AVAudiosession in between. I tried to turn off AGC on VPIO with the follwing code:

if (ASBD.componentSubType == kAudioUnitSubType_VoiceProcessingIO) {
    UInt32 turnOff = 0;
    status = AudioUnitSetProperty(_myAudioUnit,
                                  kAUVoiceIOProperty_VoiceProcessingEnableAGC,
                                  kAudioUnitScope_Global,
                                  0,
                                  &turnOff,
                                  sizeof(turnOff));
    NSAssert1(status == noErr, @"Error setting AGC status: %d", (int)status);
}

Well I'm still not sure if this code disables AGC on the microphone side or the speaker side on VPIO, but anyways, let's continue. Here's the sequence to reproduce the problem:

  1. Create a RemoteIO output audio unit with PlayAndRecord audio session category, work with it and destroy the unit;

  2. Switch audio session to Playback only category;

  3. Switch audio session to PlayAndRecord again and create another VPIO, work with it and destroy it;

  4. Switch audio session to Playback and then PlayAndRecord category;

After these steps, then whatever RemoteIO/VPIO created later will bear this amplified microphone signal (as if a huge AGC is always applied) and there's no way to go back until manually kill the app and start over.

Maybe it's my particular sequence that triggered this, wonder if anyone seen this before and maybe know a correct workaround?

Kitetaka
  • 527
  • 4
  • 20
  • What do you mean by "second time"? `RemoteIO` doesn't do AGC as far as I know, VPIO _does_ have AGC on the input data. Can you show how you're disabling it? – Rhythmic Fistman Jun 10 '21 at 14:16
  • Sorry, I think the original description wasn't clear. I edited the question with more details, see if this description helps? – Kitetaka Jun 11 '21 at 02:02
  • I don't suppose you have a runnable, sharable project? – Rhythmic Fistman Jun 11 '21 at 05:59
  • 1
    Update: a partial answer is that I was using old "setCategory:withOptions:error" API instead of the newer "setCategory:mode:options:error" API. After switching to the new API with mode added, the problem alleviated a bit, i.e. recorded audio is not crazy loud this time. However the gain between step 1 RemoteIO and step RemoteIO is still very different, and that "ghost AGC" can't be turned off since. – Kitetaka Jun 12 '21 at 15:09
  • Looks like it's the lingering problem mentioned here https://stackoverflow.com/questions/13801297/recording-volume-drop-switching-between-remoteio-and-vpio – Kitetaka Jun 12 '21 at 15:13

1 Answers1

0

Try setting the mode AVAudioSessionModeMeasurement, or AVAudioSession.Mode .measurement, when configuring your app's Audio Session.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • I do need both playback & and recording, plus sometimes uses VPIO's echo canceller, so measurement may not be the best. thanks for the suggestion though! – Kitetaka Jun 11 '21 at 01:52