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 |
11 | 11 |
12 /* | 12 /* |
13 * This file contains the function WebRtcSpl_Sqrt(). | 13 * This file contains the function WebRtcSpl_Sqrt(). |
14 * The description header can be found in signal_processing_library.h | 14 * The description header can be found in signal_processing_library.h |
15 * | 15 * |
16 */ | 16 */ |
17 | 17 |
| 18 #include "webrtc/base/checks.h" |
18 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
19 | 20 |
20 #include <assert.h> | |
21 | |
22 int32_t WebRtcSpl_SqrtLocal(int32_t in); | 21 int32_t WebRtcSpl_SqrtLocal(int32_t in); |
23 | 22 |
24 int32_t WebRtcSpl_SqrtLocal(int32_t in) | 23 int32_t WebRtcSpl_SqrtLocal(int32_t in) |
25 { | 24 { |
26 | 25 |
27 int16_t x_half, t16; | 26 int16_t x_half, t16; |
28 int32_t A, B, x2; | 27 int32_t A, B, x2; |
29 | 28 |
30 /* The following block performs: | 29 /* The following block performs: |
31 y=in/2 | 30 y=in/2 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 { | 158 { |
160 A = A + ((int32_t)32768); // Round off bit | 159 A = A + ((int32_t)32768); // Round off bit |
161 } else | 160 } else |
162 { | 161 { |
163 A = WEBRTC_SPL_WORD32_MAX; | 162 A = WEBRTC_SPL_WORD32_MAX; |
164 } | 163 } |
165 | 164 |
166 x_norm = (int16_t)(A >> 16); // x_norm = AH | 165 x_norm = (int16_t)(A >> 16); // x_norm = AH |
167 | 166 |
168 nshift = (sh / 2); | 167 nshift = (sh / 2); |
169 assert(nshift >= 0); | 168 RTC_DCHECK_GE(nshift, 0); |
170 | 169 |
171 A = (int32_t)WEBRTC_SPL_LSHIFT_W32((int32_t)x_norm, 16); | 170 A = (int32_t)WEBRTC_SPL_LSHIFT_W32((int32_t)x_norm, 16); |
172 A = WEBRTC_SPL_ABS_W32(A); // A = abs(x_norm<<16) | 171 A = WEBRTC_SPL_ABS_W32(A); // A = abs(x_norm<<16) |
173 A = WebRtcSpl_SqrtLocal(A); // A = sqrt(A) | 172 A = WebRtcSpl_SqrtLocal(A); // A = sqrt(A) |
174 | 173 |
175 if (2 * nshift == sh) { | 174 if (2 * nshift == sh) { |
176 // Even shift value case | 175 // Even shift value case |
177 | 176 |
178 t16 = (int16_t)(A >> 16); // t16 = AH | 177 t16 = (int16_t)(A >> 16); // t16 = AH |
179 | 178 |
180 A = k_sqrt_2 * t16 * 2; // A = 1/sqrt(2)*t16 | 179 A = k_sqrt_2 * t16 * 2; // A = 1/sqrt(2)*t16 |
181 A = A + ((int32_t)32768); // Round off | 180 A = A + ((int32_t)32768); // Round off |
182 A = A & ((int32_t)0x7fff0000); // Round off | 181 A = A & ((int32_t)0x7fff0000); // Round off |
183 | 182 |
184 A >>= 15; // A = A>>16 | 183 A >>= 15; // A = A>>16 |
185 | 184 |
186 } else | 185 } else |
187 { | 186 { |
188 A >>= 16; // A = A>>16 | 187 A >>= 16; // A = A>>16 |
189 } | 188 } |
190 | 189 |
191 A = A & ((int32_t)0x0000ffff); | 190 A = A & ((int32_t)0x0000ffff); |
192 A >>= nshift; // De-normalize the result. | 191 A >>= nshift; // De-normalize the result. |
193 | 192 |
194 return A; | 193 return A; |
195 } | 194 } |
OLD | NEW |