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

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: 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 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Shift |numFIX| as much as possible.
191 // Ensure we avoid wrap-around in |den| as well. 191 // Ensure we avoid wrap-around in |den| as well.
192 if (numFIX > (den >> 8)) // |den| is Q8. 192 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!
193 { 193 {
194 zeros = WebRtcSpl_NormW32(numFIX); 194 zeros = WebRtcSpl_NormW32(numFIX);
195 } else { 195 } else {
196 zeros = WebRtcSpl_NormW32(den) + 8; 196 zeros = WebRtcSpl_NormW32(den) + 8;
197 } 197 }
198 numFIX *= 1 << zeros; // Q(14+zeros) 198 numFIX *= 1 << zeros; // Q(14+zeros)
199 199
200 // Shift den so we end up in Qy1 200 // Shift den so we end up in Qy1
201 tmp32no1 = WEBRTC_SPL_SHIFT_W32(den, zeros - 8); // Q(zeros) 201 tmp32no1 = WEBRTC_SPL_SHIFT_W32(den, zeros - 8); // Q(zeros)
202 if (numFIX < 0) { 202 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
203 numFIX -= tmp32no1 / 2; 203 int remainder = numFIX % tmp32no1;
minyue-webrtc 2016/05/23 07:40:48 this part is a new solution to rounding numFIX / t
204 } else { 204 int round_threshold = den / 2 + den % 2;
205 numFIX += tmp32no1 / 2; 205 if (remainder != 0) {
206 if (remainder >= round_threshold) {
207 y32++; // Valid since |den| is always positive.
208 } else if (remainder <= -round_threshold) {
209 y32--; // Valid since |den| is always positive.
210 }
206 } 211 }
207 y32 = numFIX / tmp32no1; // in Q14 212
208 if (limiterEnable && (i < limiterIdx)) { 213 if (limiterEnable && (i < limiterIdx)) {
209 tmp32 = WEBRTC_SPL_MUL_16_U16(i - 1, kLog10_2); // Q14 214 tmp32 = WEBRTC_SPL_MUL_16_U16(i - 1, kLog10_2); // Q14
210 tmp32 -= limiterLvl * (1 << 14); // Q14 215 tmp32 -= limiterLvl * (1 << 14); // Q14
211 y32 = WebRtcSpl_DivW32W16(tmp32 + 10, 20); 216 y32 = WebRtcSpl_DivW32W16(tmp32 + 10, 20);
212 } 217 }
213 if (y32 > 39000) { 218 if (y32 > 39000) {
214 tmp32 = (y32 >> 1) * kLog10 + 4096; // in Q27 219 tmp32 = (y32 >> 1) * kLog10 + 4096; // in Q27
215 tmp32 >>= 13; // In Q14. 220 tmp32 >>= 13; // In Q14.
216 } else { 221 } else {
217 tmp32 = y32 * kLog10 + 8192; // in Q28 222 tmp32 = y32 * kLog10 + 8192; // in Q28
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // limit 686 // limit
682 if (state->logRatio > 2048) { 687 if (state->logRatio > 2048) {
683 state->logRatio = 2048; 688 state->logRatio = 2048;
684 } 689 }
685 if (state->logRatio < -2048) { 690 if (state->logRatio < -2048) {
686 state->logRatio = -2048; 691 state->logRatio = -2048;
687 } 692 }
688 693
689 return state->logRatio; // Q10 694 return state->logRatio; // Q10
690 } 695 }
OLDNEW
« 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