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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 */ | 133 */ |
134 | 134 |
135 int16_t x_norm, nshift, t16, sh; | 135 int16_t x_norm, nshift, t16, sh; |
136 int32_t A; | 136 int32_t A; |
137 | 137 |
138 int16_t k_sqrt_2 = 23170; // 1/sqrt2 (==5a82) | 138 int16_t k_sqrt_2 = 23170; // 1/sqrt2 (==5a82) |
139 | 139 |
140 A = value; | 140 A = value; |
141 | 141 |
142 if (A == 0) | 142 // The convention in this function is to calculate sqrt(abs(A)). Negate the |
143 return (int32_t)0; // sqrt(0) = 0 | 143 // input if it is negative. |
| 144 if (A < 0) { |
| 145 if (A == WEBRTC_SPL_WORD32_MIN) { |
| 146 // This number cannot be held in an int32_t after negating. |
| 147 // Map it to the maximum positive value. |
| 148 A = WEBRTC_SPL_WORD32_MAX; |
| 149 } else { |
| 150 A = -A; |
| 151 } |
| 152 } else if (A == 0) { |
| 153 return 0; // sqrt(0) = 0 |
| 154 } |
144 | 155 |
145 sh = WebRtcSpl_NormW32(A); // # shifts to normalize A | 156 sh = WebRtcSpl_NormW32(A); // # shifts to normalize A |
146 A = WEBRTC_SPL_LSHIFT_W32(A, sh); // Normalize A | 157 A = WEBRTC_SPL_LSHIFT_W32(A, sh); // Normalize A |
147 if (A < (WEBRTC_SPL_WORD32_MAX - 32767)) | 158 if (A < (WEBRTC_SPL_WORD32_MAX - 32767)) |
148 { | 159 { |
149 A = A + ((int32_t)32768); // Round off bit | 160 A = A + ((int32_t)32768); // Round off bit |
150 } else | 161 } else |
151 { | 162 { |
152 A = WEBRTC_SPL_WORD32_MAX; | 163 A = WEBRTC_SPL_WORD32_MAX; |
153 } | 164 } |
(...skipping 21 matching lines...) Expand all Loading... |
175 } else | 186 } else |
176 { | 187 { |
177 A >>= 16; // A = A>>16 | 188 A >>= 16; // A = A>>16 |
178 } | 189 } |
179 | 190 |
180 A = A & ((int32_t)0x0000ffff); | 191 A = A & ((int32_t)0x0000ffff); |
181 A >>= nshift; // De-normalize the result. | 192 A >>= nshift; // De-normalize the result. |
182 | 193 |
183 return A; | 194 return A; |
184 } | 195 } |
OLD | NEW |