From fb2fa3f54e97c4465a6fd6fd992903a52397d739 Mon Sep 17 00:00:00 2001 From: peah Date: Wed, 13 Sep 2017 06:28:16 -0700 Subject: [PATCH] Fixed the overflow in the AGC BUG=webrtc:8236 Review-Url: https://codereview.webrtc.org/3009373002 Cr-Commit-Position: refs/heads/master@{#19818} --- .../audio_processing/agc/legacy/digital_agc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/webrtc/modules/audio_processing/agc/legacy/digital_agc.c b/webrtc/modules/audio_processing/agc/legacy/digital_agc.c index a9ad55ae8c..7f59785bda 100644 --- a/webrtc/modules/audio_processing/agc/legacy/digital_agc.c +++ b/webrtc/modules/audio_processing/agc/legacy/digital_agc.c @@ -524,8 +524,17 @@ int32_t WebRtcAgc_ProcessDigital(DigitalAgc* stt, // iterate over samples for (n = 0; n < L; n++) { for (i = 0; i < num_bands; ++i) { - tmp32 = out[i][k * L + n] * (gain32 >> 4); - out[i][k * L + n] = (int16_t)(tmp32 >> 16); + int64_t tmp64 = ((int64_t)(out[i][k * L + n])) * (gain32 >> 4); + tmp64 = tmp64 >> 16; + if (tmp64 > 32767) { + out[i][k * L + n] = 32767; + } + else if (tmp64 < -32768) { + out[i][k * L + n] = -32768; + } + else { + out[i][k * L + n] = (int16_t)(tmp64); + } } gain32 += delta; }