How to control microphone gain / input level on iPhone?

My audio analysis function responds better to the iPad (2) than the iPhone (4). It seems sensitive to softer sounds on the iPad, while the iPhone requires a much louder input for the correct response. Regardless of whether this is due to the placement of the microphone, various components, various software configurations, or any other factor, I would like to be able to control this in my application.

Obviously, I could just multiply all of my sound samples to apply the gain programmatically. Of course, it also has a software cost, so:

Is it possible to control the microphone gain from software in iOS, like in MacOS? I can not find the documentation on this, but I hope that I just skip it somehow.

+8
ios core-audio remoteio
source share
2 answers

On ios6 + you can use AVAudioSession properties

CGFloat gain = sender.value; NSError* error; self.audioSession = [AVAudioSession sharedInstance]; if (self.audioSession.isInputGainSettable) { BOOL success = [self.audioSession setInputGain:gain error:&error]; if (!success){} //error handling } else { NSLog(@"ios6 - cannot set input gain"); } 

On ios5, you can get / set the gain properties of the input audio signal using the AudioSession functions

  UInt32 ui32propSize = sizeof(UInt32); UInt32 f32propSize = sizeof(Float32); UInt32 inputGainAvailable = 0; Float32 inputGain = sender.value; OSStatus err = AudioSessionGetProperty(kAudioSessionProperty_InputGainAvailable , &ui32propSize , &inputGainAvailable); if (inputGainAvailable) { OSStatus err = AudioSessionSetProperty(kAudioSessionProperty_InputGainScalar , sizeof(inputGain) , &inputGain); } else { NSLog(@"ios5 - cannot set input gain"); } OSStatus err = AudioSessionGetProperty(kAudioSessionProperty_InputGainScalar , &f32propSize , &inputGain); NSLog(@"inputGain: %0.2f",inputGain); 

(processing error omitted)

Since you are interested in controlling the gain of the input signal, you can also turn off the automatic gain control by setting the audio session mode to AVAudioSessionModeMeasurement (ios5 + 6)

 [self.audioSession setMode:AVAudioSessionModeMeasurement error:nil]; NSLog(@"mode:%@",self.audioSession.mode); 

These settings are quite specific to the hardware, so accessibility must not be allowed. For example, I can change the gain on iPhone3GS / ios6 and iPhone4S / ios5.1, but not on ipadMini / ios6.1. I can disable AGC on iPhone3G and iPad mini, but not iPhone4S.

+17
source share
-2
source share

All Articles