493: Undecipherable



-About me-


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#define ATTACK_A    (conf->clock_rate / conf->samples_per_frame)
 2#define ATTACK_B    1
 3#define DECAY_A     0
 4#define DECAY_B     1
 6#define SIMPLE_AGC(last, target) \
 7    if (target >= last) \
 8    target = (ATTACK_A*(last+1)+ATTACK_B*target)/(ATTACK_A+ATTACK_B); \
 9    else \
10    target = (DECAY_A*last+DECAY_B*target)/(DECAY_A+DECAY_B)
12#define MAX_LEVEL   (32767)
13#define MIN_LEVEL   (-32768)
15#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!