Chromium Code Reviews

Side by Side Diff: webrtc/common_audio/signal_processing/levinson_durbin.c

Issue 2680973005: Fix for left shift of potentially negative value. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 57 matching lines...)
68 K[0] = K_hi; 68 K[0] = K_hi;
69 69
70 temp1W32 >>= 4; // A[1] in Q27. 70 temp1W32 >>= 4; // A[1] in Q27.
71 71
72 // Put A[1] in hi and low format 72 // Put A[1] in hi and low format
73 A_hi[1] = (int16_t)(temp1W32 >> 16); 73 A_hi[1] = (int16_t)(temp1W32 >> 16);
74 A_low[1] = (int16_t)((temp1W32 - ((int32_t)A_hi[1] * 65536)) >> 1); 74 A_low[1] = (int16_t)((temp1W32 - ((int32_t)A_hi[1] * 65536)) >> 1);
75 75
76 // Alpha = R[0] * (1-K^2) 76 // Alpha = R[0] * (1-K^2)
77 77
78 temp1W32 = ((K_hi * K_low >> 14) + K_hi * K_hi) << 1; // = k^2 in Q31 78 temp1W32 = ((K_hi * K_low >> 14) + K_hi * K_hi) * 2; // = k^2 in Q31
79 79
80 temp1W32 = WEBRTC_SPL_ABS_W32(temp1W32); // Guard against <0 80 temp1W32 = WEBRTC_SPL_ABS_W32(temp1W32); // Guard against <0
81 temp1W32 = (int32_t)0x7fffffffL - temp1W32; // temp1W32 = (1 - K[0]*K[0]) in Q31 81 temp1W32 = (int32_t)0x7fffffffL - temp1W32; // temp1W32 = (1 - K[0]*K[0]) in Q31
82 82
83 // Store temp1W32 = 1 - K[0]*K[0] on hi and low format 83 // Store temp1W32 = 1 - K[0]*K[0] on hi and low format
84 tmp_hi = (int16_t)(temp1W32 >> 16); 84 tmp_hi = (int16_t)(temp1W32 >> 16);
85 tmp_low = (int16_t)((temp1W32 - ((int32_t)tmp_hi << 16)) >> 1); 85 tmp_low = (int16_t)((temp1W32 - ((int32_t)tmp_hi << 16)) >> 1);
86 86
87 // Calculate Alpha in Q31 87 // Calculate Alpha in Q31
88 temp1W32 = (R_hi[0] * tmp_hi + (R_hi[0] * tmp_low >> 15) + 88 temp1W32 = (R_hi[0] * tmp_hi + (R_hi[0] * tmp_low >> 15) +
(...skipping 147 matching lines...)
236 for (i = 1; i <= order; i++) 236 for (i = 1; i <= order; i++)
237 { 237 {
238 // temp1W32 in Q27 238 // temp1W32 in Q27
239 temp1W32 = (int32_t)A_hi[i] * 65536 239 temp1W32 = (int32_t)A_hi[i] * 65536
240 + WEBRTC_SPL_LSHIFT_W32((int32_t)A_low[i], 1); 240 + WEBRTC_SPL_LSHIFT_W32((int32_t)A_low[i], 1);
241 // Round and store upper word 241 // Round and store upper word
242 A[i] = (int16_t)(((temp1W32 * 2) + 32768) >> 16); 242 A[i] = (int16_t)(((temp1W32 * 2) + 32768) >> 16);
243 } 243 }
244 return 1; // Stable filters 244 return 1; // Stable filters
245 } 245 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine