從AVFoundations框架使用AVAudioSession和AVAudioRecorder進行錄製時,我一直在嘗試調整輸入增益時遇到一些問題。我發現它接受一個浮[0.0,1.0]的方法setInputGain,到目前爲止,它有點類似於:如何更改AVAudioSession的輸入增益? xcode
在我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];
然而,setInputGain方法只給你額外的在當前正在錄製的內容之上獲得增益,因此將其設置爲0.0不會使其靜音,但將其設置爲1.0會使輸入變大。我在AudioSession類中找到了一個名爲kAudioSessionProperty_InputGainScalar的屬性,但似乎無法向其中寫入值。我需要一點幫助。
這是錄音功能,它遵循另一個教程:
//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];