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

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: safer method 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..bd3e60c2e5262e7d00dec858f332dbc1480ec9c2 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.
minyue-webrtc 2016/05/23 07:40:48 this part is switched back to the old style, but a
peah-webrtc 2016/05/23 12:00:19 Nice!
{
zeros = WebRtcSpl_NormW32(numFIX);
} else {
@@ -199,12 +199,17 @@ int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16
// 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
peah-webrtc 2016/05/23 12:00:19 I don't think this is the right approach, even tho
minyue-webrtc 2016/05/24 01:32:26 + 1<<(zeros-1) is to do ceil(), what we want here
peah-webrtc 2016/05/24 06:16:20 Sorry, I realize that I was wrong about that the a
minyue-webrtc 2016/05/24 07:16:12 I also realized that +1<<(zero-1) does not do ceil
peah-webrtc 2016/05/24 10:46:29 I strongly doubt that we really need a rounding di
minyue-webrtc 2016/05/24 13:05:45 1) y32++ and -- is surely safe, since as long as |
peah-webrtc 2016/05/24 13:37:10 Looking at it again, I see that the division is wr
minyue-webrtc 2016/05/26 02:28:20 not really. y32 is supposed to be Q14, and the rou
peah-webrtc 2016/05/26 07:48:38 Good find, sorry about that. I also realized that
peah-webrtc 2016/05/26 12:27:54 Having looked at it again, I think the proper code
minyue-webrtc 2016/06/01 04:45:11 I see the point: do division so that the quotient
+ int remainder = numFIX % tmp32no1;
minyue-webrtc 2016/05/23 07:40:48 this part is a new solution to rounding numFIX / t
+ int round_threshold = den / 2 + den % 2;
+ if (remainder != 0) {
+ if (remainder >= round_threshold) {
+ y32++; // Valid since |den| is always positive.
+ } else if (remainder <= -round_threshold) {
+ y32--; // Valid since |den| is always positive.
+ }
+ }
+
if (limiterEnable && (i < limiterIdx)) {
tmp32 = WEBRTC_SPL_MUL_16_U16(i - 1, kLog10_2); // Q14
tmp32 -= limiterLvl * (1 << 14); // Q14
« no previous file with comments | « webrtc/modules/audio_processing/agc/legacy/analog_agc.c ('k') | webrtc/modules/audio_processing/gain_control_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698