Iphone – AudioQueueNewInput decreases playback volume for AVAudioPlayer

iphone

I am using Stephen Celis' SCListener class to record iPhone microphone audio levels. I also am playing audio through the use of AVAudioPlayer. For example, the user presses 'Play' to kick off a sound playing in the background and then has the option to blow into the microphone to play additional, shorter sounds. The code all works fine, playing all the sounds when they should be played, however, the AVAudioPlayer sound volume greatly decreases when you begin listening with the SCListener. I have narrowed down the culprit to this line in the SCListener source code:

AudioQueueNewInput(&format, listeningCallback, self, NULL, NULL, 0, &queue);

I have racked my brain and can not find out how to keep the playback volume at it's highest level once this line has executed. I have spoken with Stephen Celis, too, and he does not know what is happening. It is possible, I suppose, that the iPhone turns down the output volume when the microphone is being used so that feedback isn't introduced, but it seems like there should be a way to disable that.

In summary:

  1. Start playing long audio file with AVAudioPlayer – 100% volume (loud).
  2. Enable SCListener and begin listening (which calls AudioQueueNewInput).
  3. The output volume on the AVAudioPlayer sound greatly decreases
  4. Call [[SCListener sharedListener] stop] to dispose of the queue
  5. AVAudioPlayer sound resumes higher playback volume

Has anyone seen anything like this or have any ideas on how to keep the playback volume higher? I have explicitly set the volume parameter to 1.0f to ensure that the gain is at it's highest level.

Best Answer

you can try this:

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);