/* * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #include "common_audio/vad/vad_filterbank.h" #include "rtc_base/checks.h" #include "common_audio/signal_processing/include/signal_processing_library.h" // Constants used in LogOfEnergy(). static const int16_t kLogConst = …; // 160*log10(2) in Q9. static const int16_t kLogEnergyIntPart = …; // 14 in Q10 // Coefficients used by HighPassFilter, Q14. static const int16_t kHpZeroCoefs[3] = …; static const int16_t kHpPoleCoefs[3] = …; // Allpass filter coefficients, upper and lower, in Q15. // Upper: 0.64, Lower: 0.17 static const int16_t kAllPassCoefsQ15[2] = …; // Adjustment for division with two in SplitFilter. static const int16_t kOffsetVector[6] = …; // High pass filtering, with a cut-off frequency at 80 Hz, if the `data_in` is // sampled at 500 Hz. // // - data_in [i] : Input audio data sampled at 500 Hz. // - data_length [i] : Length of input and output data. // - filter_state [i/o] : State of the filter. // - data_out [o] : Output audio data in the frequency interval // 80 - 250 Hz. static void HighPassFilter(const int16_t* data_in, size_t data_length, int16_t* filter_state, int16_t* data_out) { … } // All pass filtering of `data_in`, used before splitting the signal into two // frequency bands (low pass vs high pass). // Note that `data_in` and `data_out` can NOT correspond to the same address. // // - data_in [i] : Input audio signal given in Q0. // - data_length [i] : Length of input and output data. // - filter_coefficient [i] : Given in Q15. // - filter_state [i/o] : State of the filter given in Q(-1). // - data_out [o] : Output audio signal given in Q(-1). static void AllPassFilter(const int16_t* data_in, size_t data_length, int16_t filter_coefficient, int16_t* filter_state, int16_t* data_out) { … } // Splits `data_in` into `hp_data_out` and `lp_data_out` corresponding to // an upper (high pass) part and a lower (low pass) part respectively. // // - data_in [i] : Input audio data to be split into two frequency bands. // - data_length [i] : Length of `data_in`. // - upper_state [i/o] : State of the upper filter, given in Q(-1). // - lower_state [i/o] : State of the lower filter, given in Q(-1). // - hp_data_out [o] : Output audio data of the upper half of the spectrum. // The length is `data_length` / 2. // - lp_data_out [o] : Output audio data of the lower half of the spectrum. // The length is `data_length` / 2. static void SplitFilter(const int16_t* data_in, size_t data_length, int16_t* upper_state, int16_t* lower_state, int16_t* hp_data_out, int16_t* lp_data_out) { … } // Calculates the energy of `data_in` in dB, and also updates an overall // `total_energy` if necessary. // // - data_in [i] : Input audio data for energy calculation. // - data_length [i] : Length of input data. // - offset [i] : Offset value added to `log_energy`. // - total_energy [i/o] : An external energy updated with the energy of // `data_in`. // NOTE: `total_energy` is only updated if // `total_energy` <= `kMinEnergy`. // - log_energy [o] : 10 * log10("energy of `data_in`") given in Q4. static void LogOfEnergy(const int16_t* data_in, size_t data_length, int16_t offset, int16_t* total_energy, int16_t* log_energy) { … } int16_t WebRtcVad_CalculateFeatures(VadInstT* self, const int16_t* data_in, size_t data_length, int16_t* features) { … }