1 /* 2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_FEATURES_EXTRACTION_H_ 12 #define MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_FEATURES_EXTRACTION_H_ 13 14 #include <vector> 15 16 #include "api/array_view.h" 17 #include "modules/audio_processing/agc2/biquad_filter.h" 18 #include "modules/audio_processing/agc2/rnn_vad/common.h" 19 #include "modules/audio_processing/agc2/rnn_vad/pitch_info.h" 20 #include "modules/audio_processing/agc2/rnn_vad/pitch_search.h" 21 #include "modules/audio_processing/agc2/rnn_vad/sequence_buffer.h" 22 #include "modules/audio_processing/agc2/rnn_vad/spectral_features.h" 23 24 namespace webrtc { 25 namespace rnn_vad { 26 27 // Feature extractor to feed the VAD RNN. 28 class FeaturesExtractor { 29 public: 30 FeaturesExtractor(); 31 FeaturesExtractor(const FeaturesExtractor&) = delete; 32 FeaturesExtractor& operator=(const FeaturesExtractor&) = delete; 33 ~FeaturesExtractor(); 34 void Reset(); 35 // Analyzes the samples, computes the feature vector and returns true if 36 // silence is detected (false if not). When silence is detected, 37 // |feature_vector| is partially written and therefore must not be used to 38 // feed the VAD RNN. 39 bool CheckSilenceComputeFeatures( 40 rtc::ArrayView<const float, kFrameSize10ms24kHz> samples, 41 rtc::ArrayView<float, kFeatureVectorSize> feature_vector); 42 43 private: 44 const bool use_high_pass_filter_; 45 // TODO(bugs.webrtc.org/7494): Remove HPF depending on how AGC2 is used in APM 46 // and on whether an HPF is already used as pre-processing step in APM. 47 BiQuadFilter hpf_; 48 SequenceBuffer<float, kBufSize24kHz, kFrameSize10ms24kHz, kFrameSize20ms24kHz> 49 pitch_buf_24kHz_; 50 rtc::ArrayView<const float, kBufSize24kHz> pitch_buf_24kHz_view_; 51 std::vector<float> lp_residual_; 52 rtc::ArrayView<float, kBufSize24kHz> lp_residual_view_; 53 PitchEstimator pitch_estimator_; 54 rtc::ArrayView<const float, kFrameSize20ms24kHz> reference_frame_view_; 55 SpectralFeaturesExtractor spectral_features_extractor_; 56 PitchInfo pitch_info_48kHz_; 57 }; 58 59 } // namespace rnn_vad 60 } // namespace webrtc 61 62 #endif // MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_FEATURES_EXTRACTION_H_ 63