493: Undecipherable

-Blog-

-Projects-

-About me-

-RSS-

PJSIP Automatic Gain Control

Dennis Guse

PJSIP contains an un-documentated feature that does volume adjustments during media-flow.

The conference bridge contains a very basic Automatic Gain Control that adjusts the volume level of each to-be-mixed signals, if the volume difference to the previous frame is to large.

It is however implement as define-directive in the C-code and thus enabled during compile time.

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#define ATTACK_A    (conf->clock_rate / conf->samples_per_frame)
#define ATTACK_B    1
#define DECAY_A	    0
#define DECAY_B	    1

#define SIMPLE_AGC(last, target) \
    if (target >= last) \
    target = (ATTACK_A*(last+1)+ATTACK_B*target)/(ATTACK_A+ATTACK_B); \
    else \
    target = (DECAY_A*last+DECAY_B*target)/(DECAY_A+DECAY_B)

#define MAX_LEVEL   (32767)
#define MIN_LEVEL   (-32768)

#define IS_OVERFLOW(s) ((s > MAX_LEVEL) || (s < MIN_LEVEL))

The investigation for this feature started as some severe “quality changes” (during a call the sound got quantizied heavily with a lower volume) unexpectetedly occured using PJSIP under perfect conditions:

Finding and disabling the AGC lead us to another issue that was masked by it. Somehow the EchoCanceler kicks in after around 5s seconds of continuous speech and the resulting signal is sounds heavily reduced in volume (spectogram is similar to original signal). And the AGC increases the volume again fast enough leading to “quantisation“-like sound.

So disabling the EchoCanceler (a runtime option) as well as (just to be sure) the AGC fixes the problem.

Thanks to Frank Haase for his support and wisdom!