OLD | NEW |
---|---|
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 { | 141 { |
142 temp3W32 = (int32_t)0x7fffffffL; | 142 temp3W32 = (int32_t)0x7fffffffL; |
143 } else | 143 } else |
144 { | 144 { |
145 temp3W32 = (int32_t)0x80000000L; | 145 temp3W32 = (int32_t)0x80000000L; |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 // Put K on hi and low format | 149 // Put K on hi and low format |
150 K_hi = (int16_t)(temp3W32 >> 16); | 150 K_hi = (int16_t)(temp3W32 >> 16); |
151 K_low = (int16_t)((temp3W32 - ((int32_t)K_hi * 65536)) >> 1); | 151 K_low = (int16_t)((temp3W32 - ((int32_t)K_hi * 65536)) >> 1); |
ivoc
2017/01/09 16:52:35
When temp3W32 is a negative number (which can happ
kwiberg-webrtc
2017/01/09 17:51:37
So the value that's being shifted (the "shiftee"?)
ivoc
2017/01/10 09:18:27
Well, the shift on this line is not a problem, it'
kwiberg-webrtc
2017/01/10 10:08:00
Got it.
| |
152 | 152 |
153 // Store Reflection coefficient in Q15 | 153 // Store Reflection coefficient in Q15 |
154 K[i - 1] = K_hi; | 154 K[i - 1] = K_hi; |
155 | 155 |
156 // Test for unstable filter. | 156 // Test for unstable filter. |
157 // If unstable return 0 and let the user decide what to do in that case | 157 // If unstable return 0 and let the user decide what to do in that case |
158 | 158 |
159 if ((int32_t)WEBRTC_SPL_ABS_W16(K_hi) > (int32_t)32750) | 159 if ((int32_t)WEBRTC_SPL_ABS_W16(K_hi) > (int32_t)32750) |
160 { | 160 { |
161 return 0; // Unstable filter | 161 return 0; // Unstable filter |
(...skipping 24 matching lines...) Expand all Loading... | |
186 // temp3W32 = K in Q27 (Convert from Q31 to Q27) | 186 // temp3W32 = K in Q27 (Convert from Q31 to Q27) |
187 temp3W32 >>= 4; | 187 temp3W32 >>= 4; |
188 | 188 |
189 // Store Anew in hi and low format | 189 // Store Anew in hi and low format |
190 A_upd_hi[i] = (int16_t)(temp3W32 >> 16); | 190 A_upd_hi[i] = (int16_t)(temp3W32 >> 16); |
191 A_upd_low[i] = (int16_t)( | 191 A_upd_low[i] = (int16_t)( |
192 (temp3W32 - ((int32_t)A_upd_hi[i] * 65536)) >> 1); | 192 (temp3W32 - ((int32_t)A_upd_hi[i] * 65536)) >> 1); |
193 | 193 |
194 // Alpha = Alpha * (1-K^2) | 194 // Alpha = Alpha * (1-K^2) |
195 | 195 |
196 temp1W32 = ((K_hi * K_low >> 14) + K_hi * K_hi) << 1; // K*K in Q31 | 196 temp1W32 = ((K_hi * K_low >> 14) + K_hi * K_hi) * 2; // K*K in Q31 |
ivoc
2017/01/09 16:52:35
When K_hi is negative and K_low is positive, ((K_h
kwiberg-webrtc
2017/01/09 17:51:36
Umm... I would've thought that K*K would always be
ivoc
2017/01/10 09:18:27
This is from the testcase that the fuzzer came up
kwiberg-webrtc
2017/01/10 10:08:01
Hmm. (a+b)^2 = a^2 + 2*a*b + b^2 should be nonzero
ivoc
2017/01/10 10:17:24
In the line below this one they guard against temp
hlundin-webrtc
2017/01/10 10:18:40
I say leave it like this.
kwiberg-webrtc
2017/01/10 10:32:58
Yes. (I'm not sure that leaving out the small term
| |
197 | 197 |
198 temp1W32 = WEBRTC_SPL_ABS_W32(temp1W32); // Guard against <0 | 198 temp1W32 = WEBRTC_SPL_ABS_W32(temp1W32); // Guard against <0 |
199 temp1W32 = (int32_t)0x7fffffffL - temp1W32; // 1 - K*K in Q31 | 199 temp1W32 = (int32_t)0x7fffffffL - temp1W32; // 1 - K*K in Q31 |
200 | 200 |
201 // Convert 1- K^2 in hi and low format | 201 // Convert 1- K^2 in hi and low format |
202 tmp_hi = (int16_t)(temp1W32 >> 16); | 202 tmp_hi = (int16_t)(temp1W32 >> 16); |
203 tmp_low = (int16_t)((temp1W32 - ((int32_t)tmp_hi << 16)) >> 1); | 203 tmp_low = (int16_t)((temp1W32 - ((int32_t)tmp_hi << 16)) >> 1); |
204 | 204 |
205 // Calculate Alpha = Alpha * (1-K^2) in Q31 | 205 // Calculate Alpha = Alpha * (1-K^2) in Q31 |
206 temp1W32 = (Alpha_hi * tmp_hi + (Alpha_hi * tmp_low >> 15) + | 206 temp1W32 = (Alpha_hi * tmp_hi + (Alpha_hi * tmp_low >> 15) + |
(...skipping 29 matching lines...) Expand all Loading... | |
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 } |
OLD | NEW |