diff options
author | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2008-05-15 13:50:56 +0400 |
---|---|---|
committer | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2008-05-15 13:50:56 +0400 |
commit | 497379924e01823fd632454b10449f32ee6b2072 (patch) | |
tree | 7d66ca00e2ce158f4bcef790faaefd882dcc87a2 /libspeex | |
parent | 09d20918021a82586fcc716194a5e8a0718e46ef (diff) |
better saturation handling in the echo canceller (prevent overflows and
removed unnecessary muting)
git-svn-id: http://svn.xiph.org/trunk/speex@14886 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'libspeex')
-rw-r--r-- | libspeex/mdf.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/libspeex/mdf.c b/libspeex/mdf.c index 348b40a..dbb4b8a 100644 --- a/libspeex/mdf.c +++ b/libspeex/mdf.c @@ -88,6 +88,12 @@ #define WEIGHT_SHIFT 0 #endif +#ifdef FIXED_POINT +#define WORD2INT(x) ((x) < -32767 ? -32768 : ((x) > 32766 ? 32767 : (x))) +#else +#define WORD2INT(x) ((x) < -32767.5f ? -32768 : ((x) > 32766.5f ? 32767 : floor(.5+(x)))) +#endif + /* If enabled, the AEC will use a foreground filter and a background filter to be more robust to double-talk and difficult signals in general. The cost is an extra FFT and a matrix-vector multiply */ #define TWO_PATH @@ -877,11 +883,6 @@ EXPORT void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, c #else tmp_out = SUB32(EXTEND32(st->input[i]), EXTEND32(st->y[i+st->frame_size])); #endif - /* Saturation */ - if (tmp_out>32767) - tmp_out = 32767; - else if (tmp_out<-32768) - tmp_out = -32768; tmp_out = ADD32(tmp_out, EXTEND32(MULT16_16_P15(st->preemph, st->memE))); /* This is an arbitrary test for saturation in the microphone signal */ if (in[i] <= -32000 || in[i] >= 32000) @@ -890,7 +891,7 @@ EXPORT void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, c if (st->saturated == 0) st->saturated = 1; } - out[i] = (spx_int16_t)tmp_out; + out[i] = WORD2INT(tmp_out); st->memE = tmp_out; } |