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 "webrtc/base/checks.h" |
14 | |
15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 14 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
16 #include "webrtc/common_audio/vad/vad_core.h" | 15 #include "webrtc/common_audio/vad/vad_core.h" |
17 #include "webrtc/typedefs.h" | 16 #include "webrtc/typedefs.h" |
18 | 17 |
19 // Allpass filter coefficients, upper and lower, in Q13. | 18 // Allpass filter coefficients, upper and lower, in Q13. |
20 // Upper: 0.64, Lower: 0.17. | 19 // Upper: 0.64, Lower: 0.17. |
21 static const int16_t kAllPassCoefsQ13[2] = { 5243, 1392 }; // Q13. | 20 static const int16_t kAllPassCoefsQ13[2] = { 5243, 1392 }; // Q13. |
22 static const int16_t kSmoothingDown = 6553; // 0.2 in Q15. | 21 static const int16_t kSmoothingDown = 6553; // 0.2 in Q15. |
23 static const int16_t kSmoothingUp = 32439; // 0.99 in Q15. | 22 static const int16_t kSmoothingUp = 32439; // 0.99 in Q15. |
24 | 23 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // Offset to beginning of the 16 minimum values in memory. | 64 // Offset to beginning of the 16 minimum values in memory. |
66 const int offset = (channel << 4); | 65 const int offset = (channel << 4); |
67 int16_t current_median = 1600; | 66 int16_t current_median = 1600; |
68 int16_t alpha = 0; | 67 int16_t alpha = 0; |
69 int32_t tmp32 = 0; | 68 int32_t tmp32 = 0; |
70 // Pointer to memory for the 16 minimum values and the age of each value of | 69 // Pointer to memory for the 16 minimum values and the age of each value of |
71 // the |channel|. | 70 // the |channel|. |
72 int16_t* age = &self->index_vector[offset]; | 71 int16_t* age = &self->index_vector[offset]; |
73 int16_t* smallest_values = &self->low_value_vector[offset]; | 72 int16_t* smallest_values = &self->low_value_vector[offset]; |
74 | 73 |
75 assert(channel < kNumChannels); | 74 RTC_DCHECK_LT(channel, kNumChannels); |
76 | 75 |
77 // Each value in |smallest_values| is getting 1 loop older. Update |age|, and | 76 // Each value in |smallest_values| is getting 1 loop older. Update |age|, and |
78 // remove old values. | 77 // remove old values. |
79 for (i = 0; i < 16; i++) { | 78 for (i = 0; i < 16; i++) { |
80 if (age[i] != 100) { | 79 if (age[i] != 100) { |
81 age[i]++; | 80 age[i]++; |
82 } else { | 81 } else { |
83 // Too old value. Remove from memory and shift larger values downwards. | 82 // Too old value. Remove from memory and shift larger values downwards. |
84 for (j = i; j < 16; j++) { | 83 for (j = i; j < 16; j++) { |
85 smallest_values[j] = smallest_values[j + 1]; | 84 smallest_values[j] = smallest_values[j + 1]; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 alpha = kSmoothingUp; // 0.99 in Q15. | 168 alpha = kSmoothingUp; // 0.99 in Q15. |
170 } | 169 } |
171 } | 170 } |
172 tmp32 = (alpha + 1) * self->mean_value[channel]; | 171 tmp32 = (alpha + 1) * self->mean_value[channel]; |
173 tmp32 += (WEBRTC_SPL_WORD16_MAX - alpha) * current_median; | 172 tmp32 += (WEBRTC_SPL_WORD16_MAX - alpha) * current_median; |
174 tmp32 += 16384; | 173 tmp32 += 16384; |
175 self->mean_value[channel] = (int16_t) (tmp32 >> 15); | 174 self->mean_value[channel] = (int16_t) (tmp32 >> 15); |
176 | 175 |
177 return self->mean_value[channel]; | 176 return self->mean_value[channel]; |
178 } | 177 } |
OLD | NEW |