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_filterbank.h" | 11 #include "webrtc/common_audio/vad/vad_filterbank.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/typedefs.h" | 15 #include "webrtc/typedefs.h" |
17 | 16 |
18 // Constants used in LogOfEnergy(). | 17 // Constants used in LogOfEnergy(). |
19 static const int16_t kLogConst = 24660; // 160*log10(2) in Q9. | 18 static const int16_t kLogConst = 24660; // 160*log10(2) in Q9. |
20 static const int16_t kLogEnergyIntPart = 14336; // 14 in Q10 | 19 static const int16_t kLogEnergyIntPart = 14336; // 14 in Q10 |
21 | 20 |
22 // Coefficients used by HighPassFilter, Q14. | 21 // Coefficients used by HighPassFilter, Q14. |
23 static const int16_t kHpZeroCoefs[3] = { 6631, -13262, 6631 }; | 22 static const int16_t kHpZeroCoefs[3] = { 6631, -13262, 6631 }; |
24 static const int16_t kHpPoleCoefs[3] = { 16384, -7756, 5620 }; | 23 static const int16_t kHpPoleCoefs[3] = { 16384, -7756, 5620 }; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // - log_energy [o] : 10 * log10("energy of |data_in|") given in Q4. | 152 // - log_energy [o] : 10 * log10("energy of |data_in|") given in Q4. |
154 static void LogOfEnergy(const int16_t* data_in, size_t data_length, | 153 static void LogOfEnergy(const int16_t* data_in, size_t data_length, |
155 int16_t offset, int16_t* total_energy, | 154 int16_t offset, int16_t* total_energy, |
156 int16_t* log_energy) { | 155 int16_t* log_energy) { |
157 // |tot_rshifts| accumulates the number of right shifts performed on |energy|. | 156 // |tot_rshifts| accumulates the number of right shifts performed on |energy|. |
158 int tot_rshifts = 0; | 157 int tot_rshifts = 0; |
159 // The |energy| will be normalized to 15 bits. We use unsigned integer because | 158 // The |energy| will be normalized to 15 bits. We use unsigned integer because |
160 // we eventually will mask out the fractional part. | 159 // we eventually will mask out the fractional part. |
161 uint32_t energy = 0; | 160 uint32_t energy = 0; |
162 | 161 |
163 assert(data_in != NULL); | 162 RTC_DCHECK(data_in); |
164 assert(data_length > 0); | 163 RTC_DCHECK_GT(data_length, 0); |
165 | 164 |
166 energy = (uint32_t) WebRtcSpl_Energy((int16_t*) data_in, data_length, | 165 energy = (uint32_t) WebRtcSpl_Energy((int16_t*) data_in, data_length, |
167 &tot_rshifts); | 166 &tot_rshifts); |
168 | 167 |
169 if (energy != 0) { | 168 if (energy != 0) { |
170 // By construction, normalizing to 15 bits is equivalent with 17 leading | 169 // By construction, normalizing to 15 bits is equivalent with 17 leading |
171 // zeros of an unsigned 32 bit value. | 170 // zeros of an unsigned 32 bit value. |
172 int normalizing_rshifts = 17 - WebRtcSpl_NormU32(energy); | 171 int normalizing_rshifts = 17 - WebRtcSpl_NormU32(energy); |
173 // In a 15 bit representation the leading bit is 2^14. log2(2^14) in Q10 is | 172 // In a 15 bit representation the leading bit is 2^14. log2(2^14) in Q10 is |
174 // (14 << 10), which is what we initialize |log2_energy| with. For a more | 173 // (14 << 10), which is what we initialize |log2_energy| with. For a more |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 const size_t half_data_length = data_length >> 1; | 253 const size_t half_data_length = data_length >> 1; |
255 size_t length = half_data_length; // |data_length| / 2, corresponds to | 254 size_t length = half_data_length; // |data_length| / 2, corresponds to |
256 // bandwidth = 2000 Hz after downsampling. | 255 // bandwidth = 2000 Hz after downsampling. |
257 | 256 |
258 // Initialize variables for the first SplitFilter(). | 257 // Initialize variables for the first SplitFilter(). |
259 int frequency_band = 0; | 258 int frequency_band = 0; |
260 const int16_t* in_ptr = data_in; // [0 - 4000] Hz. | 259 const int16_t* in_ptr = data_in; // [0 - 4000] Hz. |
261 int16_t* hp_out_ptr = hp_120; // [2000 - 4000] Hz. | 260 int16_t* hp_out_ptr = hp_120; // [2000 - 4000] Hz. |
262 int16_t* lp_out_ptr = lp_120; // [0 - 2000] Hz. | 261 int16_t* lp_out_ptr = lp_120; // [0 - 2000] Hz. |
263 | 262 |
264 assert(data_length <= 240); | 263 RTC_DCHECK_LE(data_length, 240); |
265 assert(4 < kNumChannels - 1); // Checking maximum |frequency_band|. | 264 RTC_DCHECK_LT(4, kNumChannels - 1); // Checking maximum |frequency_band|. |
266 | 265 |
267 // Split at 2000 Hz and downsample. | 266 // Split at 2000 Hz and downsample. |
268 SplitFilter(in_ptr, data_length, &self->upper_state[frequency_band], | 267 SplitFilter(in_ptr, data_length, &self->upper_state[frequency_band], |
269 &self->lower_state[frequency_band], hp_out_ptr, lp_out_ptr); | 268 &self->lower_state[frequency_band], hp_out_ptr, lp_out_ptr); |
270 | 269 |
271 // For the upper band (2000 Hz - 4000 Hz) split at 3000 Hz and downsample. | 270 // For the upper band (2000 Hz - 4000 Hz) split at 3000 Hz and downsample. |
272 frequency_band = 1; | 271 frequency_band = 1; |
273 in_ptr = hp_120; // [2000 - 4000] Hz. | 272 in_ptr = hp_120; // [2000 - 4000] Hz. |
274 hp_out_ptr = hp_60; // [3000 - 4000] Hz. | 273 hp_out_ptr = hp_60; // [3000 - 4000] Hz. |
275 lp_out_ptr = lp_60; // [2000 - 3000] Hz. | 274 lp_out_ptr = lp_60; // [2000 - 3000] Hz. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 LogOfEnergy(hp_60, length, kOffsetVector[1], &total_energy, &features[1]); | 321 LogOfEnergy(hp_60, length, kOffsetVector[1], &total_energy, &features[1]); |
323 | 322 |
324 // Remove 0 Hz - 80 Hz, by high pass filtering the lower band. | 323 // Remove 0 Hz - 80 Hz, by high pass filtering the lower band. |
325 HighPassFilter(lp_60, length, self->hp_filter_state, hp_120); | 324 HighPassFilter(lp_60, length, self->hp_filter_state, hp_120); |
326 | 325 |
327 // Energy in 80 Hz - 250 Hz. | 326 // Energy in 80 Hz - 250 Hz. |
328 LogOfEnergy(hp_120, length, kOffsetVector[0], &total_energy, &features[0]); | 327 LogOfEnergy(hp_120, length, kOffsetVector[0], &total_energy, &features[0]); |
329 | 328 |
330 return total_energy; | 329 return total_energy; |
331 } | 330 } |
OLD | NEW |