1 /* 2 * Copyright (c) 2017 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_RESIDUAL_ECHO_ESTIMATOR_H_ 12 #define MODULES_AUDIO_PROCESSING_AEC3_RESIDUAL_ECHO_ESTIMATOR_H_ 13 14 #include <array> 15 #include <memory> 16 17 #include "absl/types/optional.h" 18 #include "api/audio/echo_canceller3_config.h" 19 #include "modules/audio_processing/aec3/aec3_common.h" 20 #include "modules/audio_processing/aec3/aec_state.h" 21 #include "modules/audio_processing/aec3/render_buffer.h" 22 #include "modules/audio_processing/aec3/reverb_model.h" 23 #include "modules/audio_processing/aec3/spectrum_buffer.h" 24 #include "rtc_base/checks.h" 25 26 namespace webrtc { 27 28 class ResidualEchoEstimator { 29 public: 30 ResidualEchoEstimator(const EchoCanceller3Config& config, 31 size_t num_render_channels); 32 ~ResidualEchoEstimator(); 33 34 ResidualEchoEstimator(const ResidualEchoEstimator&) = delete; 35 ResidualEchoEstimator& operator=(const ResidualEchoEstimator&) = delete; 36 37 void Estimate( 38 const AecState& aec_state, 39 const RenderBuffer& render_buffer, 40 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> S2_linear, 41 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> Y2, 42 bool dominant_nearend, 43 rtc::ArrayView<std::array<float, kFftLengthBy2Plus1>> R2, 44 rtc::ArrayView<std::array<float, kFftLengthBy2Plus1>> R2_unbounded); 45 46 private: 47 enum class ReverbType { kLinear, kNonLinear }; 48 49 // Resets the state. 50 void Reset(); 51 52 // Updates estimate for the power of the stationary noise component in the 53 // render signal. 54 void UpdateRenderNoisePower(const RenderBuffer& render_buffer); 55 56 // Updates the reverb estimation. 57 void UpdateReverb(ReverbType reverb_type, 58 const AecState& aec_state, 59 const RenderBuffer& render_buffer, 60 bool dominant_nearend); 61 62 // Adds the estimated unmodelled echo power to the residual echo power 63 // estimate. 64 void AddReverb( 65 rtc::ArrayView<std::array<float, kFftLengthBy2Plus1>> R2) const; 66 67 // Gets the echo path gain to apply. 68 float GetEchoPathGain(const AecState& aec_state, 69 bool gain_for_early_reflections) const; 70 71 const EchoCanceller3Config config_; 72 const size_t num_render_channels_; 73 const float early_reflections_transparent_mode_gain_; 74 const float late_reflections_transparent_mode_gain_; 75 const float early_reflections_general_gain_; 76 const float late_reflections_general_gain_; 77 const bool erle_onset_compensation_in_dominant_nearend_; 78 std::array<float, kFftLengthBy2Plus1> X2_noise_floor_; 79 std::array<int, kFftLengthBy2Plus1> X2_noise_floor_counter_; 80 ReverbModel echo_reverb_; 81 }; 82 83 } // namespace webrtc 84 85 #endif // MODULES_AUDIO_PROCESSING_AEC3_RESIDUAL_ECHO_ESTIMATOR_H_ 86