webrtc(一) agc

                       

一、参数

(一)、mode

  enum Mode {    // Adaptive mode intended for use if an analog volume control is available    // on the capture device. It will require the user to provide coupling    // between the OS mixer controls and AGC through the |stream_analog_level()|    // functions.    //      // It consists of an analog gain prescription for the audio device and a    // digital compression stage.    kAdaptiveAnalog,    // Adaptive mode intended for situations in which an analog volume control    // is unavailable. It operates in a similar fashion to the adaptive analog    // mode, but with scaling instead applied in the digital domain. As with    // the analog mode, it additionally uses a digital compression stage.    kAdaptiveDigital,    // Fixed mode which enables only the digital compression stage also used by    // the two adaptive modes.    //      // It is distinguished from the adaptive modes by considering only a    // short time-window of the input signal. It applies a fixed gain through    // most of the input level range, and compresses (gradually reduces gain    // with increasing level) the input signal at higher levels. This mode is    // preferred on embedded devices where the capture signal level is    // predictable, so that a known gain can be applied.    kFixedDigital  };
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  1. kAdaptiveAnalog
    适合用desktop platforms,模拟信号可控音量
  2. kAdaptiveDigital
    适合用mobile device,没有音量控制
  3. kFixedDigital
    固定增益

(二)、parameter

以下摘自于 http://rg4.net/archives/797.html
——————————————-
AGC parameters:
——————————————-
1. Target level DBFS
——————————————-
According to the description of webrtc:
 Change of this parameter will set the target peak |level| (or envelope) of the AGC in dBFs (decibels from digital full-scale).
 The convention is to use positive values.
 For instance, passing in a value of 3 corresponds to -3 dBFs, or a target level 3 dB below full-scale.

Value range: limited to [0, 31].

TODO(ajm): use a negative value here instead, if/when VoE will similarly update its interface.
——————————————-
2. Compression gain DB
——————————————-
Sets the maximum |gain| the digital compression stage may apply, in dB. A higher number corresponds to greater compression, while a value of 0 will leave the signal uncompressed.

Value range: limited to [0, 90]

——————————————-
3. Enable limiter or not
——————————————-
When enabled, the compression stage will hard limit the signal to the target level. Otherwise, the signal will be compressed but not limited above the target level.

——————————————-
4. Analog level limits
——————————————-
Sets the |minimum| and |maximum| analog levels of the audio capture device.
 Must be set if and only if an analog mode is used.

Value range: limited to [0, 65535].

——————————————-
5. Stream saturated or not
——————————————-
Returns true if the AGC has detected a saturation event (period where the signal reaches digital full-scale) in the current frame and the analog level cannot be reduced.
 This could be used as an indicator to reduce or disable analog mic gain at the audio HAL.
以上摘自于 http://rg4.net/archives/797.html


二、使用

由于不同版本的代码差距较大,首先声明下面使用例子来自于下面的commit

commit 99f8566524b3764bf84b7f4cbd8232bdf6c142a5Author: kjellander <kjellander@webrtc.org>Date:   Sun Nov 29 20:50:44 2015 -0800
  
  
  • 1
  • 2
  • 3

使用自动增益控制放大的音量比较有限,所以使用了固定增益模式

int agcTest2(char *filename, char *outfilename, int mode){    //init agc    void *agcInst = WebRtcAgc_Create();    int minLevel = 0;    int maxLevel = 255;    int agcMode  = kAgcModeFixedDigital;    int fs       = 16000;    int status   = 0;     status = WebRtcAgc_Init(agcInst, minLevel, maxLevel, agcMode, fs);    if(status != 0)    {        printf("failed in WebRtcAgc_Init\n");        return -1;    }    WebRtcAgcConfig agcConfig;    agcConfig.compressionGaindB = 20;//在Fixed模式下,越大声音越大    agcConfig.limiterEnable = 1;    agcConfig.targetLevelDbfs = 3;   //dbfs表示相对于full scale的下降值,0表示full scale,越小声音越大    status = WebRtcAgc_set_config(agcInst, agcConfig);    if(status != 0)    {        printf("failed in WebRtcAgc_set_config\n");        return -1;    }    //alloc    FILE *infp=fopen(filename,"r");    int nBands = 1;    int frameSize = 160;//10ms对应于160个short    short **pData = (short**)malloc(nBands*sizeof(short*));    pData[0] = (short*)malloc(frameSize*sizeof(short));    short **pOutData = (short**)malloc(nBands*sizeof(short*));    pOutData[0] = (short*)malloc(frameSize*sizeof(short));    //process    FILE *outfp = fopen(outfilename,"w");    int len = frameSize;    int micLevelIn = 0;    int micLevelOut = 0;    while(len > 0)    {        memset(pData[0], 0, frameSize*sizeof(short));        len = fread(pData[0], sizeof(short), frameSize, infp);        int inMicLevel  = micLevelOut;        int outMicLevel = 0;        uint8_t saturationWarning;        status = WebRtcAgc_Process(agcInst, pData, nBands, frameSize, pOutData, inMicLevel, &outMicLevel, 0, &saturationWarning);        if (status != 0)        {            printf("failed in WebRtcAgc_Process\n");            return -1;        }        if (saturationWarning == 1)        {            printf("saturationWarning\n");        }        micLevelIn = outMicLevel;        //write file        len = fwrite(pOutData[0], sizeof(short), len, outfp);    }    fclose(infp);    fclose(outfp);    WebRtcAgc_Free(agcInst);    free(pData[0]);    free(pData);    free(pOutData[0]);    free(pOutData);
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71

代码使用参考:webrtc/modules/audio_processing/gain_control_impl.cc


三、原理

经过google邮件和论坛考证,确定没有公布出相关的参考文献和原理说明文档。
想不通为什么代码都开源了,好歹说几个参考文献啊!源码也没怎么看,大致看了下注释,所以我在使用过程中,参数的含义和使用基本上靠猜和试验,后续有时间读几篇ns的文献再来细聊,有什么错误麻烦指正!

           
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值