Reputation: 31
I've been having some problems trying to adjust the input gain when recording using the AVAudioSession and AVAudioRecorder from the AVFoundations framework. I've found the method setInputGain which accepts a float [0.0, 1.0], So far, it kinda looks like this:
In my viewDidLoad:
//Initialise the AVAudioSession, and share between different functions
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];
[audioSession setInputGain:1.0 error:nil];
However, the setInputGain method only gives you additional gain on top of what is currently being recorded, so setting it at 0.0 is not going to mute it but setting it at 1.0 is going to make the input louder. There is a property that I've found in the AudioSession class called kAudioSessionProperty_InputGainScalar but can't seem to write a value into it. I need a little help, please.
This is the recording function, which follows another tutorial:
//Creating a temporary place to record
tempRecFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"sound.caf"]];
recorder = [[AVAudioRecorder alloc] initWithURL:tempRecFile
settings:nil
error:nil];
[recorder setDelegate:self];
//Setting the input gain for the recording, then proceed to record
//[audioSession setInputGain:inputGainSlider.value error:nil];
[recorder prepareToRecord];
[recorder record];
[self.inputGainSlider setEnabled:NO];
Upvotes: 3
Views: 2880
Reputation: 11
none of the devices I've tested this on allows for setting input gain. I haven't found an official list of devices from apple yet... Here are the devices I tried: iphone 4s iphone 6s ipad pro
Upvotes: 1
Reputation: 285
From official document, I see following lines,
Discussion
Before calling this method, you should check the value in the inputGainSettable property to make sure the input gain level is settable for the current inputs.
so is there any possibility that device doesn't support change it?
Upvotes: 0