From: Steve K. <st...@st...> - 2004-09-30 14:03:58
|
At astricon, some iaxclient users had talked with me about a problem they have where clients would have poor audio quality (from microphone), when using iaxclient, because their mixer settings were too high, and the incoming audio was clipping. This is a patch which needs further testing, which implements a loose mixer-based AGC method to iaxclient. Basically the way it works is that when iaxclient detects speech, it looks at the signal level, and makes adjustments to the mixer levels. The adjustment is slow, and has a high level of hysteresis, so that once it finds the proper position, it shouldn't move, and fine adjustments will be done with multiplication. [otherwise, the other DSP functions, like denoising, would get confused by the changing input levels]. Index: audio_encode.c =================================================================== RCS file: /cvsroot/iaxclient/iaxclient/lib/audio_encode.c,v retrieving revision 1.18 diff -u -r1.18 audio_encode.c --- audio_encode.c 25 Jun 2004 19:38:59 -0000 1.18 +++ audio_encode.c 2 Aug 2004 23:09:23 -0000 @@ -86,6 +86,29 @@ /* only preprocess if we're interested in VAD, AGC, or DENOISE */ if((iaxc_filters & (IAXC_FILTER_DENOISE | IAXC_FILTER_AGC)) || iaxc_silence_threshold > 0) silent = !speex_preprocess(st, audio, NULL); + /* bring speex AGC gain out to mixer */ + if(!silent && (iaxc_filters & IAXC_FILTER_AGC )) { + static int i; + double level; + i++; + + if((i&0x3f) == 0) { + /* fprintf(stderr, "loudness = %f\n", st->loudness2); */ + level = iaxc_input_level_get(); + /* lower quickly if we're too hot */ + if(st->loudness2 > 20000 && level > 0.3) { + level -= 0.2; + iaxc_input_level_set(level); + } /* lower slowly */ + else if(st->loudness2 > 8000) { + if(level >= 0.1) iaxc_input_level_set(level - 0.1); + } + /* raise slowly if we're cold */ + else if( st->loudness2 < 4000) { + if(level <= 0.9) iaxc_input_level_set(level + 0.1); + } + } + } Comments on this are welcome. The one thing that should probably be added with this is to set the input volume up to the max on startup. Because if the input levels are too low to start with, speech won't ever be detected, and the AGC won't have any effect. -SteveK |