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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 180 }
181 logApprox = 0; 181 logApprox = 0;
182 if (tmpU32no2 < tmpU32no1) { 182 if (tmpU32no2 < tmpU32no1) {
183 logApprox = (tmpU32no1 - tmpU32no2) >> (8 - zerosScale); // Q14 183 logApprox = (tmpU32no1 - tmpU32no2) >> (8 - zerosScale); // Q14
184 } 184 }
185 } 185 }
186 numFIX = (maxGain * constMaxGain) * (1 << 6); // Q14 186 numFIX = (maxGain * constMaxGain) * (1 << 6); // Q14
187 numFIX -= (int32_t)logApprox * diffGain; // Q14 187 numFIX -= (int32_t)logApprox * diffGain; // Q14
188 188
189 // Calculate ratio 189 // Calculate ratio
190 // Shift |numFIX| as much as possible. 190 // 1) Shift |numFIX| as much as possible. Since we later add |den| / 2 to
191 // Ensure we avoid wrap-around in |den| as well. 191 // |numFIX| before dividing |den| to round the ratio, we use |numFIX| *2 to
192 if (numFIX > (den >> 8)) // |den| is Q8. 192 // calculate the bit for shifting.
minyue-webrtc 2016/05/21 12:33:37 Two problems were with this part 1. if |numFIX| i
193 { 193 // 2) Ensure we avoid wrap-around in |den| as well.
194 zeros = WebRtcSpl_NormW32(numFIX); 194 zeros = WEBRTC_SPL_MIN(WebRtcSpl_NormW32(numFIX * 2),
peah-webrtc 2016/05/23 04:59:37 The norm computation is on some platforms fairly c
peah-webrtc 2016/05/23 04:59:37 How do you know that numFIX * 2 does not overflow?
minyue-webrtc 2016/05/23 07:40:48 Good question, after a second thought, I see that
195 } else { 195 WebRtcSpl_NormW32(den) + 8);
196 zeros = WebRtcSpl_NormW32(den) + 8;
197 }
198 numFIX *= 1 << zeros; // Q(14+zeros) 196 numFIX *= 1 << zeros; // Q(14+zeros)
199 197
200 // Shift den so we end up in Qy1 198 // Shift den so we end up in Qy1
201 tmp32no1 = WEBRTC_SPL_SHIFT_W32(den, zeros - 8); // Q(zeros) 199 tmp32no1 = WEBRTC_SPL_SHIFT_W32(den, zeros - 8); // Q(zeros)
202 if (numFIX < 0) { 200 if (numFIX < 0) {
203 numFIX -= tmp32no1 / 2; 201 numFIX -= tmp32no1 / 2;
peah-webrtc 2016/05/23 04:59:36 Does changing WebRtcSpl_NormW32(numFIX) to WebRtcS
204 } else { 202 } else {
205 numFIX += tmp32no1 / 2; 203 numFIX += tmp32no1 / 2;
206 } 204 }
207 y32 = numFIX / tmp32no1; // in Q14 205 y32 = numFIX / tmp32no1; // in Q14
208 if (limiterEnable && (i < limiterIdx)) { 206 if (limiterEnable && (i < limiterIdx)) {
209 tmp32 = WEBRTC_SPL_MUL_16_U16(i - 1, kLog10_2); // Q14 207 tmp32 = WEBRTC_SPL_MUL_16_U16(i - 1, kLog10_2); // Q14
210 tmp32 -= limiterLvl * (1 << 14); // Q14 208 tmp32 -= limiterLvl * (1 << 14); // Q14
211 y32 = WebRtcSpl_DivW32W16(tmp32 + 10, 20); 209 y32 = WebRtcSpl_DivW32W16(tmp32 + 10, 20);
212 } 210 }
213 if (y32 > 39000) { 211 if (y32 > 39000) {
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // limit 679 // limit
682 if (state->logRatio > 2048) { 680 if (state->logRatio > 2048) {
683 state->logRatio = 2048; 681 state->logRatio = 2048;
684 } 682 }
685 if (state->logRatio < -2048) { 683 if (state->logRatio < -2048) {
686 state->logRatio = -2048; 684 state->logRatio = -2048;
687 } 685 }
688 686
689 return state->logRatio; // Q10 687 return state->logRatio; // Q10
690 } 688 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698