【问题标题】:How to change the input gain for AVAudioSession? xcode如何更改 AVAudioSession 的输入增益?代码
【发布时间】:2012-12-10 10:37:03
【问题描述】:

在使用 AVFoundations 框架中的 AVAudioSession 和 AVAudioRecorder 录制时,我在尝试调整输入增益时遇到了一些问题。我找到了 setInputGain 方法,它接受一个浮点数 [0.0, 1.0],到目前为止,它看起来像这样:

在我看来DidLoad:

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

【问题讨论】:

    标签: xcode audio audio-recording avaudiosession


    【解决方案1】:

    我测试过的所有设备都不允许设置输入增益。我还没有找到苹果的官方设备列表......这是我尝试过的设备: iphone 4s iphone 6s ipad专业版

    【讨论】:

      【解决方案2】:

      从官方文档,我看到以下几行,

      讨论

      在调用此方法之前,您应该检查 inputGainSettable 属性中的值,以确保当前输入的输入增益级别是可设置的。

      那么有没有可能设备不支持更改它?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-26
        • 1970-01-01
        • 2013-09-26
        • 2019-04-29
        • 2022-11-02
        • 2012-10-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多