OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 #include "webrtc/common_audio/vad/vad_sp.h" | 11 #include "webrtc/common_audio/vad/vad_sp.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
16 #include "webrtc/common_audio/vad/vad_core.h" | 16 #include "webrtc/common_audio/vad/vad_core.h" |
17 #include "webrtc/typedefs.h" | 17 #include "webrtc/typedefs.h" |
18 | 18 |
19 // Allpass filter coefficients, upper and lower, in Q13. | 19 // Allpass filter coefficients, upper and lower, in Q13. |
20 // Upper: 0.64, Lower: 0.17. | 20 // Upper: 0.64, Lower: 0.17. |
21 static const int16_t kAllPassCoefsQ13[2] = { 5243, 1392 }; // Q13. | 21 static const int16_t kAllPassCoefsQ13[2] = { 5243, 1392 }; // Q13. |
22 static const int16_t kSmoothingDown = 6553; // 0.2 in Q15. | 22 static const int16_t kSmoothingDown = 6553; // 0.2 in Q15. |
23 static const int16_t kSmoothingUp = 32439; // 0.99 in Q15. | 23 static const int16_t kSmoothingUp = 32439; // 0.99 in Q15. |
24 | 24 |
25 // TODO(bjornv): Move this function to vad_filterbank.c. | 25 // TODO(bjornv): Move this function to vad_filterbank.c. |
26 // Downsampling filter based on splitting filter and allpass functions. | 26 // Downsampling filter based on splitting filter and allpass functions. |
27 void WebRtcVad_Downsampling(const int16_t* signal_in, | 27 void WebRtcVad_Downsampling(const int16_t* signal_in, |
28 int16_t* signal_out, | 28 int16_t* signal_out, |
29 int32_t* filter_state, | 29 int32_t* filter_state, |
30 int in_length) { | 30 size_t in_length) { |
31 int16_t tmp16_1 = 0, tmp16_2 = 0; | 31 int16_t tmp16_1 = 0, tmp16_2 = 0; |
32 int32_t tmp32_1 = filter_state[0]; | 32 int32_t tmp32_1 = filter_state[0]; |
33 int32_t tmp32_2 = filter_state[1]; | 33 int32_t tmp32_2 = filter_state[1]; |
34 int n = 0; | 34 size_t n = 0; |
35 int half_length = (in_length >> 1); // Downsampling by 2 gives half length. | 35 // Downsampling by 2 gives half length. |
| 36 size_t half_length = (in_length >> 1); |
36 | 37 |
37 // Filter coefficients in Q13, filter state in Q0. | 38 // Filter coefficients in Q13, filter state in Q0. |
38 for (n = 0; n < half_length; n++) { | 39 for (n = 0; n < half_length; n++) { |
39 // All-pass filtering upper branch. | 40 // All-pass filtering upper branch. |
40 tmp16_1 = (int16_t) ((tmp32_1 >> 1) + | 41 tmp16_1 = (int16_t) ((tmp32_1 >> 1) + |
41 ((kAllPassCoefsQ13[0] * *signal_in) >> 14)); | 42 ((kAllPassCoefsQ13[0] * *signal_in) >> 14)); |
42 *signal_out = tmp16_1; | 43 *signal_out = tmp16_1; |
43 tmp32_1 = (int32_t)(*signal_in++) - ((kAllPassCoefsQ13[0] * tmp16_1) >> 12); | 44 tmp32_1 = (int32_t)(*signal_in++) - ((kAllPassCoefsQ13[0] * tmp16_1) >> 12); |
44 | 45 |
45 // All-pass filtering lower branch. | 46 // All-pass filtering lower branch. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 alpha = kSmoothingUp; // 0.99 in Q15. | 169 alpha = kSmoothingUp; // 0.99 in Q15. |
169 } | 170 } |
170 } | 171 } |
171 tmp32 = (alpha + 1) * self->mean_value[channel]; | 172 tmp32 = (alpha + 1) * self->mean_value[channel]; |
172 tmp32 += (WEBRTC_SPL_WORD16_MAX - alpha) * current_median; | 173 tmp32 += (WEBRTC_SPL_WORD16_MAX - alpha) * current_median; |
173 tmp32 += 16384; | 174 tmp32 += 16384; |
174 self->mean_value[channel] = (int16_t) (tmp32 >> 15); | 175 self->mean_value[channel] = (int16_t) (tmp32 >> 15); |
175 | 176 |
176 return self->mean_value[channel]; | 177 return self->mean_value[channel]; |
177 } | 178 } |
OLD | NEW |