Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Unified Diff: webrtc/modules/audio_processing/agc/legacy/digital_agc.c

Issue 2003623003: Re-enable UBsan on AGC. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: new solution Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/agc/legacy/digital_agc.c
diff --git a/webrtc/modules/audio_processing/agc/legacy/digital_agc.c b/webrtc/modules/audio_processing/agc/legacy/digital_agc.c
index 2ca967a4aae1a0d0a00758b4861a4838b1d11d46..ea5a0ca1fef362bb317cbc2f405c8e63d838fbb4 100644
--- a/webrtc/modules/audio_processing/agc/legacy/digital_agc.c
+++ b/webrtc/modules/audio_processing/agc/legacy/digital_agc.c
@@ -189,7 +189,7 @@ int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16
// Calculate ratio
// Shift |numFIX| as much as possible.
// Ensure we avoid wrap-around in |den| as well.
- if (numFIX > (den >> 8)) // |den| is Q8.
+ if (numFIX > (den >> 8) || -numFIX > (den >> 8)) // |den| is Q8.
peah-webrtc 2016/06/03 05:10:35 The if-condition will compute den >> 8 twice. Plea
{
zeros = WebRtcSpl_NormW32(numFIX);
} else {
@@ -198,13 +198,10 @@ int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16
numFIX *= 1 << zeros; // Q(14+zeros)
// Shift den so we end up in Qy1
- tmp32no1 = WEBRTC_SPL_SHIFT_W32(den, zeros - 8); // Q(zeros)
- if (numFIX < 0) {
- numFIX -= tmp32no1 / 2;
- } else {
- numFIX += tmp32no1 / 2;
- }
- y32 = numFIX / tmp32no1; // in Q14
+ tmp32no1 = WEBRTC_SPL_SHIFT_W32(den, zeros - 9); // Q(zeros - 1)
+ y32 = numFIX / tmp32no1; // in Q15
+ y32 = (y32 + 1) / 2; // in Q14 rounded
peah-webrtc 2016/06/03 05:10:35 Nice! This should work apart from that the roundi
peah-webrtc 2016/06/03 05:11:05 Sorry, meant right shift.
minyue-webrtc 2016/06/03 06:40:05 Nice catch! I was careless there. To round negativ
+
if (limiterEnable && (i < limiterIdx)) {
tmp32 = WEBRTC_SPL_MUL_16_U16(i - 1, kLog10_2); // Q14
tmp32 -= limiterLvl * (1 << 14); // Q14

Powered by Google App Engine
This is Rietveld 408576698