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_AEC3_SIGNAL_DEPENDENT_ERLE_ESTIMATOR_H_ 12 #define MODULES_AUDIO_PROCESSING_AEC3_SIGNAL_DEPENDENT_ERLE_ESTIMATOR_H_ 13 14 #include <memory> 15 #include <vector> 16 17 #include "api/array_view.h" 18 #include "api/audio/echo_canceller3_config.h" 19 #include "modules/audio_processing/aec3/aec3_common.h" 20 #include "modules/audio_processing/aec3/render_buffer.h" 21 #include "modules/audio_processing/logging/apm_data_dumper.h" 22 23 namespace webrtc { 24 25 // This class estimates the dependency of the Erle to the input signal. By 26 // looking at the input signal, an estimation on whether the current echo 27 // estimate is due to the direct path or to a more reverberant one is performed. 28 // Once that estimation is done, it is possible to refine the average Erle that 29 // this class receive as an input. 30 class SignalDependentErleEstimator { 31 public: 32 SignalDependentErleEstimator(const EchoCanceller3Config& config, 33 size_t num_capture_channels); 34 35 ~SignalDependentErleEstimator(); 36 37 void Reset(); 38 39 // Returns the Erle per frequency subband. Erle(bool onset_compensated)40 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> Erle( 41 bool onset_compensated) const { 42 return onset_compensated && use_onset_detection_ ? erle_onset_compensated_ 43 : erle_; 44 } 45 46 // Updates the Erle estimate. The Erle that is passed as an input is required 47 // to be an estimation of the average Erle achieved by the linear filter. 48 void Update( 49 const RenderBuffer& render_buffer, 50 rtc::ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>> 51 filter_frequency_response, 52 rtc::ArrayView<const float, kFftLengthBy2Plus1> X2, 53 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> Y2, 54 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> E2, 55 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> average_erle, 56 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> 57 average_erle_onset_compensated, 58 const std::vector<bool>& converged_filters); 59 60 void Dump(const std::unique_ptr<ApmDataDumper>& data_dumper) const; 61 62 static constexpr size_t kSubbands = 6; 63 64 private: 65 void ComputeNumberOfActiveFilterSections( 66 const RenderBuffer& render_buffer, 67 rtc::ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>> 68 filter_frequency_responses); 69 70 void UpdateCorrectionFactors( 71 rtc::ArrayView<const float, kFftLengthBy2Plus1> X2, 72 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> Y2, 73 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> E2, 74 const std::vector<bool>& converged_filters); 75 76 void ComputeEchoEstimatePerFilterSection( 77 const RenderBuffer& render_buffer, 78 rtc::ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>> 79 filter_frequency_responses); 80 81 void ComputeActiveFilterSections(); 82 83 const float min_erle_; 84 const size_t num_sections_; 85 const size_t num_blocks_; 86 const size_t delay_headroom_blocks_; 87 const std::array<size_t, kFftLengthBy2Plus1> band_to_subband_; 88 const std::array<float, kSubbands> max_erle_; 89 const std::vector<size_t> section_boundaries_blocks_; 90 const bool use_onset_detection_; 91 std::vector<std::array<float, kFftLengthBy2Plus1>> erle_; 92 std::vector<std::array<float, kFftLengthBy2Plus1>> erle_onset_compensated_; 93 std::vector<std::vector<std::array<float, kFftLengthBy2Plus1>>> 94 S2_section_accum_; 95 std::vector<std::vector<std::array<float, kSubbands>>> erle_estimators_; 96 std::vector<std::array<float, kSubbands>> erle_ref_; 97 std::vector<std::vector<std::array<float, kSubbands>>> correction_factors_; 98 std::vector<std::array<int, kSubbands>> num_updates_; 99 std::vector<std::array<size_t, kFftLengthBy2Plus1>> n_active_sections_; 100 }; 101 102 } // namespace webrtc 103 104 #endif // MODULES_AUDIO_PROCESSING_AEC3_SIGNAL_DEPENDENT_ERLE_ESTIMATOR_H_ 105