WebRTC AGC (Automatic Gain Control)

C++Signal ProcessingWebrtc

C++ Problem Overview


I am testing the WebRTC AGC but I must be doing something wrong because the signal just passes through unmodified.

Here's how I create and initialize the AGC:

agcConfig.compressionGaindB = 9;
agcConfig.limiterEnable = 1;
agcConfig.targetLevelDbfs = 9;   /* 9dB below full scale */

WebRtcAgc_Create(&agc);
WebRtcAgc_Init(agc, minLevel, maxLevel, kAgcModeFixedDigital, 8000);
WebRtcAgc_set_config(agc, agcConfig);

And then for each 10ms sample block I do the following:

WebRtcAgc_Process(agc, micData, NULL, 80, micData, NULL, micLevelIn, &micLevelOut, 0, &saturationWarning);

Where micLevelIn is set to 0.

Can somebody tell me what I'm doing wrong?

I expected that a full scale sine tone would be attenuated to the target DBFS level; and a low level sine tone (i.e. -30dBFS) would be amplified to match the target DBFS level. But that's not what I'm seeing.

C++ Solutions


Solution 1 - C++

Here is the sequence of operations to be used for Webrtc_AGC:

  1. Create AGC: WebRtcAgc_Create
  2. Initialize AGC: WebRtcAgc_Init
  3. Set Config: WebRtcAgc_set_config
  4. Initialize capture_level = 0
  5. For kAgcModeAdaptiveDigital, invoke VirtualMic: WebRtcAgc_VirtualMic
  6. Process Buffer with capture_level: WebRtcAgc_Process
  7. Get the out capture level returned from WebRtcAgc_Process and set it to capture_level
  8. Repeat 5 to 7 for the audio buffers
  9. Destroy the AGC: WebRtcAgc_Free

Check webrtc/modules/audio_processing/gain_control_impl.cc for reference.

Solution 2 - C++

Try this:

agcConfig.compressionGaindB = 9;
agcConfig.limiterEnable = 1;
agcConfig.targetLevelDbfs = 9;   /* 9dB below full scale */

WebRtcAgc_Create(&agc);
WebRtcAgc_Init(&agc, minLevel, maxLevel, kAgcModeFixedDigital, 8000);
WebRtcAgc_set_config(&agc, &agcConfig);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1884325View Question on Stackoverflow
Solution 1 - C++sskView Answer on Stackoverflow
Solution 2 - C++Muhammad FaizanView Answer on Stackoverflow