2012-12-10 40 views
1

從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]; 

回答

0

來自官方的文件,我看到下面的行,

討論

調用此方法之前,您應該檢查值在inputGainSettable屬性中確保可以爲當前輸入設置輸入增益級別。

那麼有沒有可能設備不支持改變它?

0

我測試過的這些設備都不允許設置輸入增益。我還沒有發現設備的正式名單從蘋果尚未...這裏是我試過的設備: iPhone 4S的 iphone 6S iPad的親