如何在iPhone上控制硬件麦克风输入增益/电平? [英] How to control hardware mic input gain/level on iPhone?

查看:1598
本文介绍了如何在iPhone上控制硬件麦克风输入增益/电平?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的音频分析功能在iPad(2)上比iPhone(4)响应更好。它似乎对iPad上较柔和的声音很敏感,而iPhone需要更响亮的输入才能正确响应。无论是因为麦克风放置,不同组件,不同软件配置还是其他因素,我都希望能够在我的应用中控制它。

My audio-analysis function responds better on the iPad (2) than the iPhone (4). It seems sensitive to softer sounds on the iPad, whereas the iPhone requires much louder input to respond properly. Whether this is because of mic placement, different components, different software configurations or some other factor, I'd like to be able to control for it in my app.

显然我可以将所有音频样本相乘以编程方式应用增益。当然这也有软件成本,所以:

Obviously I could just multiply all of my audio samples to programmatically apply gain. Of course that has a software cost too, so:

是否可以通过iOS中的软件控制麦克风的增益,与MacOS中的相似?我找不到任何关于此的文档,但我希望我能以某种方式错过它。

Is it possible to control the mic's gain from software in iOS, similarly to how it is in MacOS? I can't find any documentation on this but I'm hoping I'm just missing it somehow.

推荐答案

在ios6 +上你可以使用AVAudioSession属性

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");
        }               

在ios5上,您可以使用AudioSession函数获取/设置音频输入增益属性

On ios5 you can get/set audio input gain properties using 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);

(错误处理省略)

As您有兴趣控制输入增益,您可能还想通过将音频会话模式设置为 AVAudioSessionModeMeasurement (ios5 + 6)

As you are interested in controlling input gain, you may also want to disable automatic gain control by setting the audio session mode to AVAudioSessionModeMeasurement (ios5+6)

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

这些设置是特定于硬件的,因此无法假定可用性。例如,我可以改变iPhone3GS / ios6和iPhone4S / ios5.1上的增益,但不能改变ipadMini / ios6.1上的增益。我可以在iPhone3G和iPad mini上禁用AGC,但不能在iPhone4S上禁用。

These settings are fairly hardware-specific so availability cannot be assumed. For example, I can alter the gain on iPhone3GS/ios6 and iPhone4S/ios5.1, but not on ipadMini/ios6.1. I can disable AGC on the iPhone3G and the iPad mini, but not the iPhone4S.

这篇关于如何在iPhone上控制硬件麦克风输入增益/电平?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆