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 <saza@webrtc.org>
Commit-Queue: Ivo Creusen <ivoc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33043}
This commit is contained in:
Ivo Creusen 2021-01-18 16:25:22 +01:00 committed by Commit Bot
parent 5eb43b4777
commit 812c73cdc2

View File

@ -18,6 +18,7 @@
#include "modules/audio_coding/codecs/ilbc/enhancer_interface.h"
#include <stdlib.h>
#include <string.h>
#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);