erle_estimator.cc (3656B)
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 #include "modules/audio_processing/aec3/erle_estimator.h" 12 13 #include <array> 14 #include <cstddef> 15 #include <memory> 16 #include <vector> 17 18 #include "api/array_view.h" 19 #include "api/audio/echo_canceller3_config.h" 20 #include "api/environment/environment.h" 21 #include "modules/audio_processing/aec3/aec3_common.h" 22 #include "modules/audio_processing/aec3/render_buffer.h" 23 #include "modules/audio_processing/aec3/signal_dependent_erle_estimator.h" 24 #include "modules/audio_processing/logging/apm_data_dumper.h" 25 #include "rtc_base/checks.h" 26 27 namespace webrtc { 28 29 ErleEstimator::ErleEstimator(const Environment& env, 30 size_t startup_phase_length_blocks, 31 const EchoCanceller3Config& config, 32 size_t num_capture_channels) 33 : startup_phase_length_blocks_(startup_phase_length_blocks), 34 fullband_erle_estimator_(config.erle, num_capture_channels), 35 subband_erle_estimator_(env, config, num_capture_channels) { 36 if (config.erle.num_sections > 1) { 37 signal_dependent_erle_estimator_ = 38 std::make_unique<SignalDependentErleEstimator>(config, 39 num_capture_channels); 40 } 41 Reset(true); 42 } 43 44 ErleEstimator::~ErleEstimator() = default; 45 46 void ErleEstimator::Reset(bool delay_change) { 47 fullband_erle_estimator_.Reset(); 48 subband_erle_estimator_.Reset(); 49 if (signal_dependent_erle_estimator_) { 50 signal_dependent_erle_estimator_->Reset(); 51 } 52 if (delay_change) { 53 blocks_since_reset_ = 0; 54 } 55 } 56 57 void ErleEstimator::Update( 58 const RenderBuffer& render_buffer, 59 ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>> 60 filter_frequency_responses, 61 ArrayView<const float, kFftLengthBy2Plus1> avg_render_spectrum_with_reverb, 62 ArrayView<const std::array<float, kFftLengthBy2Plus1>> capture_spectra, 63 ArrayView<const std::array<float, kFftLengthBy2Plus1>> subtractor_spectra, 64 const std::vector<bool>& converged_filters) { 65 RTC_DCHECK_EQ(subband_erle_estimator_.Erle(/*onset_compensated=*/true).size(), 66 capture_spectra.size()); 67 RTC_DCHECK_EQ(subband_erle_estimator_.Erle(/*onset_compensated=*/true).size(), 68 subtractor_spectra.size()); 69 const auto& X2_reverb = avg_render_spectrum_with_reverb; 70 const auto& Y2 = capture_spectra; 71 const auto& E2 = subtractor_spectra; 72 73 if (++blocks_since_reset_ < startup_phase_length_blocks_) { 74 return; 75 } 76 77 subband_erle_estimator_.Update(X2_reverb, Y2, E2, converged_filters); 78 79 if (signal_dependent_erle_estimator_) { 80 signal_dependent_erle_estimator_->Update( 81 render_buffer, filter_frequency_responses, X2_reverb, Y2, E2, 82 subband_erle_estimator_.Erle(/*onset_compensated=*/false), 83 subband_erle_estimator_.Erle(/*onset_compensated=*/true), 84 converged_filters); 85 } 86 87 fullband_erle_estimator_.Update(X2_reverb, Y2, E2, converged_filters); 88 } 89 90 void ErleEstimator::Dump( 91 const std::unique_ptr<ApmDataDumper>& data_dumper) const { 92 fullband_erle_estimator_.Dump(data_dumper); 93 subband_erle_estimator_.Dump(data_dumper); 94 if (signal_dependent_erle_estimator_) { 95 signal_dependent_erle_estimator_->Dump(data_dumper); 96 } 97 } 98 99 } // namespace webrtc