dominant_nearend_detector.h (2066B)
1 /* 2 * Copyright (c) 2019 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_AEC3_DOMINANT_NEAREND_DETECTOR_H_ 12 #define MODULES_AUDIO_PROCESSING_AEC3_DOMINANT_NEAREND_DETECTOR_H_ 13 14 #include <array> 15 #include <cstddef> 16 #include <vector> 17 18 #include "api/array_view.h" 19 #include "api/audio/echo_canceller3_config.h" 20 #include "modules/audio_processing/aec3/aec3_common.h" 21 #include "modules/audio_processing/aec3/nearend_detector.h" 22 23 namespace webrtc { 24 // Class for selecting whether the suppressor is in the nearend or echo state. 25 class DominantNearendDetector : public NearendDetector { 26 public: 27 DominantNearendDetector( 28 const EchoCanceller3Config::Suppressor::DominantNearendDetection& config, 29 size_t num_capture_channels); 30 31 // Returns whether the current state is the nearend state. 32 bool IsNearendState() const override { return nearend_state_; } 33 34 // Updates the state selection based on latest spectral estimates. 35 void Update( 36 ArrayView<const std::array<float, kFftLengthBy2Plus1>> nearend_spectrum, 37 ArrayView<const std::array<float, kFftLengthBy2Plus1>> 38 residual_echo_spectrum, 39 ArrayView<const std::array<float, kFftLengthBy2Plus1>> 40 comfort_noise_spectrum, 41 bool initial_state) override; 42 43 private: 44 const float enr_threshold_; 45 const float enr_exit_threshold_; 46 const float snr_threshold_; 47 const int hold_duration_; 48 const int trigger_threshold_; 49 const bool use_during_initial_phase_; 50 const size_t num_capture_channels_; 51 52 bool nearend_state_ = false; 53 std::vector<int> trigger_counters_; 54 std::vector<int> hold_counters_; 55 }; 56 57 } // namespace webrtc 58 59 #endif // MODULES_AUDIO_PROCESSING_AEC3_DOMINANT_NEAREND_DETECTOR_H_