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