From 812c73cdc25ade1c08750873f0c1e8f8def206dc Mon Sep 17 00:00:00 2001 From: Ivo Creusen Date: Mon, 18 Jan 2021 16:25:22 +0100 Subject: [PATCH] Another ilbc cross correlation fix To determine the appropriate amount of shifting to prevent overflow in a cross correlation, it is necessary to have the max value of both sequences. However, only one was calculated in the ilbc code. This CL calculates the max of the other sequence and correctly takes both into account. Bug: chromium:1161837 Change-Id: I3ba8eee0814bb5eda3769c0ce6caf2681c7525e1 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/202253 Reviewed-by: Sam Zackrisson Commit-Queue: Ivo Creusen Cr-Commit-Position: refs/heads/master@{#33043} --- modules/audio_coding/codecs/ilbc/enhancer_interface.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/audio_coding/codecs/ilbc/enhancer_interface.c b/modules/audio_coding/codecs/ilbc/enhancer_interface.c index fb9740eb22..71436c24dc 100644 --- a/modules/audio_coding/codecs/ilbc/enhancer_interface.c +++ b/modules/audio_coding/codecs/ilbc/enhancer_interface.c @@ -18,6 +18,7 @@ #include "modules/audio_coding/codecs/ilbc/enhancer_interface.h" +#include #include #include "modules/audio_coding/codecs/ilbc/constants.h" @@ -203,11 +204,11 @@ size_t // (o) Estimated lag in end of in[] regressor=in+tlag-1; /* scaling */ - // Note that this is not abs-max, but it doesn't matter since we use only - // the square of it. + // Note that this is not abs-max, so we will take the absolute value below. max16 = regressor[WebRtcSpl_MaxAbsIndexW16(regressor, plc_blockl + 3 - 1)]; - - const int64_t max_val = plc_blockl * max16 * max16; + const int16_t max_target = + target[WebRtcSpl_MaxAbsIndexW16(target, plc_blockl + 3 - 1)]; + const int64_t max_val = plc_blockl * abs(max16 * max_target); const int32_t factor = max_val >> 31; shifts = factor == 0 ? 0 : 31 - WebRtcSpl_NormW32(factor);