From 9d66198d35080ee7c21af5cf84d14a60e6549ad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Fri, 20 Mar 2020 11:26:48 +0100 Subject: [PATCH] AEC3: Rename shadow filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL renames the shadow filter in AEC3 to have the more accurate name coarse filter. The CL consists of 3 main initial patch sets, designed to simplify the review: 1) Replaces "shadow" with "coarse" and adds a fall-back functionality to support the old filter naming. 2) Renames the files according to the new naming. 3) Performs a "git cl format" Bug: webrtc:8671 Change-Id: I28d6041d0d34e85f8f8048d004b44a1a5f07bb07 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170981 Commit-Queue: Per Ã…hgren Reviewed-by: Sam Zackrisson Cr-Commit-Position: refs/heads/master@{#30846} --- api/audio/echo_canceller3_config.cc | 13 +++ api/audio/echo_canceller3_config.h | 13 ++- api/audio/echo_canceller3_config_json.cc | 21 ++++- .../echo_canceller3_config_json_unittest.cc | 7 +- modules/audio_processing/aec3/BUILD.gn | 6 +- .../aec3/adaptive_fir_filter_unittest.cc | 12 +-- modules/audio_processing/aec3/aec_state.cc | 2 +- ...e_gain.cc => coarse_filter_update_gain.cc} | 18 ++-- ...ate_gain.h => coarse_filter_update_gain.h} | 24 ++--- ... => coarse_filter_update_gain_unittest.cc} | 55 +++++------ .../audio_processing/aec3/echo_canceller3.cc | 14 ++- modules/audio_processing/aec3/echo_remover.cc | 26 ++--- .../aec3/refined_filter_update_gain.cc | 4 +- .../refined_filter_update_gain_unittest.cc | 38 ++++---- modules/audio_processing/aec3/subtractor.cc | 94 +++++++++---------- modules/audio_processing/aec3/subtractor.h | 10 +- .../aec3/subtractor_output.cc | 24 ++--- .../audio_processing/aec3/subtractor_output.h | 12 +-- .../aec3/subtractor_output_analyzer.cc | 10 +- .../aec3/subtractor_unittest.cc | 16 ++-- 20 files changed, 231 insertions(+), 188 deletions(-) rename modules/audio_processing/aec3/{shadow_filter_update_gain.cc => coarse_filter_update_gain.cc} (86%) rename modules/audio_processing/aec3/{shadow_filter_update_gain.h => coarse_filter_update_gain.h} (73%) rename modules/audio_processing/aec3/{shadow_filter_update_gain_unittest.cc => coarse_filter_update_gain_unittest.cc} (85%) diff --git a/api/audio/echo_canceller3_config.cc b/api/audio/echo_canceller3_config.cc index 1122d4c6b0..2438738375 100644 --- a/api/audio/echo_canceller3_config.cc +++ b/api/audio/echo_canceller3_config.cc @@ -170,6 +170,19 @@ bool EchoCanceller3Config::Validate(EchoCanceller3Config* config) { res = false; } + res = res & FloorLimit(&c->filter.coarse.length_blocks, 1); + res = res & Limit(&c->filter.coarse.rate, 0.f, 1.f); + res = res & Limit(&c->filter.coarse.noise_gate, 0.f, 100000000.f); + + res = res & FloorLimit(&c->filter.coarse_initial.length_blocks, 1); + res = res & Limit(&c->filter.coarse_initial.rate, 0.f, 1.f); + res = res & Limit(&c->filter.coarse_initial.noise_gate, 0.f, 100000000.f); + + if (c->filter.coarse.length_blocks < c->filter.coarse_initial.length_blocks) { + c->filter.coarse_initial.length_blocks = c->filter.coarse.length_blocks; + res = false; + } + res = res & Limit(&c->filter.config_change_duration_blocks, 0, 100000); res = res & Limit(&c->filter.initial_state_seconds, 0.f, 100.f); diff --git a/api/audio/echo_canceller3_config.h b/api/audio/echo_canceller3_config.h index 66989db706..523cf94e2f 100644 --- a/api/audio/echo_canceller3_config.h +++ b/api/audio/echo_canceller3_config.h @@ -70,31 +70,34 @@ struct RTC_EXPORT EchoCanceller3Config { float noise_gate; }; - struct ShadowConfiguration { + struct CoarseConfiguration { size_t length_blocks; float rate; float noise_gate; }; RefinedConfiguration main = {13, 0.00005f, 0.05f, 0.001f, 2.f, 20075344.f}; - ShadowConfiguration shadow = {13, 0.7f, 20075344.f}; + CoarseConfiguration shadow = {13, 0.7f, 20075344.f}; RefinedConfiguration refined = {13, 0.00005f, 0.05f, 0.001f, 2.f, 20075344.f}; + CoarseConfiguration coarse = {13, 0.7f, 20075344.f}; RefinedConfiguration main_initial = {12, 0.005f, 0.5f, 0.001f, 2.f, 20075344.f}; - ShadowConfiguration shadow_initial = {12, 0.9f, 20075344.f}; + CoarseConfiguration shadow_initial = {12, 0.9f, 20075344.f}; RefinedConfiguration refined_initial = {12, 0.005f, 0.5f, 0.001f, 2.f, 20075344.f}; + CoarseConfiguration coarse_initial = {12, 0.9f, 20075344.f}; size_t config_change_duration_blocks = 250; float initial_state_seconds = 2.5f; bool conservative_initial_phase = false; bool enable_shadow_filter_output_usage = true; + bool enable_coarse_filter_output_usage = true; bool use_linear_filter = true; bool export_linear_aec_output = false; - // Uses the filter configurations named main rather than those named - // refined. + // Uses the filter configurations named main and shadow rather than those + // named refined and coarse. bool use_legacy_filter_naming = true; } filter; diff --git a/api/audio/echo_canceller3_config_json.cc b/api/audio/echo_canceller3_config_json.cc index fd06fa9b8a..7734e3275a 100644 --- a/api/audio/echo_canceller3_config_json.cc +++ b/api/audio/echo_canceller3_config_json.cc @@ -76,7 +76,7 @@ void ReadParam(const Json::Value& root, void ReadParam(const Json::Value& root, std::string param_name, - EchoCanceller3Config::Filter::ShadowConfiguration* param) { + EchoCanceller3Config::Filter::CoarseConfiguration* param) { RTC_DCHECK(param); Json::Value json_array; if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) { @@ -218,9 +218,11 @@ void Aec3ConfigFromJsonString(absl::string_view json_string, ReadParam(section, "main", &cfg.filter.main); ReadParam(section, "refined", &cfg.filter.refined); ReadParam(section, "shadow", &cfg.filter.shadow); + ReadParam(section, "coarse", &cfg.filter.coarse); ReadParam(section, "main_initial", &cfg.filter.main_initial); ReadParam(section, "refined_initial", &cfg.filter.refined_initial); ReadParam(section, "shadow_initial", &cfg.filter.shadow_initial); + ReadParam(section, "coarse_initial", &cfg.filter.coarse_initial); ReadParam(section, "config_change_duration_blocks", &cfg.filter.config_change_duration_blocks); ReadParam(section, "initial_state_seconds", @@ -229,6 +231,8 @@ void Aec3ConfigFromJsonString(absl::string_view json_string, &cfg.filter.conservative_initial_phase); ReadParam(section, "enable_shadow_filter_output_usage", &cfg.filter.enable_shadow_filter_output_usage); + ReadParam(section, "enable_coarse_filter_output_usage", + &cfg.filter.enable_coarse_filter_output_usage); ReadParam(section, "use_linear_filter", &cfg.filter.use_linear_filter); ReadParam(section, "export_linear_aec_output", &cfg.filter.export_linear_aec_output); @@ -487,6 +491,12 @@ std::string Aec3ConfigToJsonString(const EchoCanceller3Config& config) { ost << config.filter.shadow.noise_gate; ost << "],"; + ost << "\"coarse\": ["; + ost << config.filter.coarse.length_blocks << ","; + ost << config.filter.coarse.rate << ","; + ost << config.filter.coarse.noise_gate; + ost << "],"; + ost << "\"main_initial\": ["; ost << config.filter.main_initial.length_blocks << ","; ost << config.filter.main_initial.leakage_converged << ","; @@ -511,6 +521,12 @@ std::string Aec3ConfigToJsonString(const EchoCanceller3Config& config) { ost << config.filter.shadow_initial.noise_gate; ost << "],"; + ost << "\"coarse_initial\": ["; + ost << config.filter.coarse_initial.length_blocks << ","; + ost << config.filter.coarse_initial.rate << ","; + ost << config.filter.coarse_initial.noise_gate; + ost << "],"; + ost << "\"config_change_duration_blocks\": " << config.filter.config_change_duration_blocks << ","; ost << "\"initial_state_seconds\": " << config.filter.initial_state_seconds @@ -520,6 +536,9 @@ std::string Aec3ConfigToJsonString(const EchoCanceller3Config& config) { ost << "\"enable_shadow_filter_output_usage\": " << (config.filter.enable_shadow_filter_output_usage ? "true" : "false") << ","; + ost << "\"enable_coarse_filter_output_usage\": " + << (config.filter.enable_coarse_filter_output_usage ? "true" : "false") + << ","; ost << "\"use_linear_filter\": " << (config.filter.use_linear_filter ? "true" : "false") << ","; ost << "\"export_linear_aec_output\": " diff --git a/api/audio/test/echo_canceller3_config_json_unittest.cc b/api/audio/test/echo_canceller3_config_json_unittest.cc index 2cc34635af..f5c26752ca 100644 --- a/api/audio/test/echo_canceller3_config_json_unittest.cc +++ b/api/audio/test/echo_canceller3_config_json_unittest.cc @@ -22,6 +22,7 @@ TEST(EchoCanceller3JsonHelpers, ToStringAndParseJson) { cfg.filter.main.error_floor = 1.f; cfg.filter.refined.error_floor = 2.f; cfg.filter.shadow_initial.length_blocks = 7u; + cfg.filter.coarse_initial.length_blocks = 3u; cfg.suppressor.normal_tuning.mask_hf.enr_suppress = .5f; cfg.suppressor.subband_nearend_detection.nearend_average_blocks = 3; cfg.suppressor.subband_nearend_detection.subband1 = {1, 3}; @@ -42,12 +43,14 @@ TEST(EchoCanceller3JsonHelpers, ToStringAndParseJson) { cfg_transformed.delay.down_sampling_factor); EXPECT_EQ(cfg.delay.log_warning_on_delay_changes, cfg_transformed.delay.log_warning_on_delay_changes); + EXPECT_EQ(cfg.filter.coarse_initial.length_blocks, + cfg_transformed.filter.coarse_initial.length_blocks); + EXPECT_EQ(cfg.filter.shadow_initial.length_blocks, + cfg_transformed.filter.shadow_initial.length_blocks); EXPECT_EQ(cfg.filter.main.error_floor, cfg_transformed.filter.main.error_floor); EXPECT_EQ(cfg.filter.refined.error_floor, cfg_transformed.filter.refined.error_floor); - EXPECT_EQ(cfg.filter.shadow_initial.length_blocks, - cfg_transformed.filter.shadow_initial.length_blocks); EXPECT_EQ(cfg.suppressor.normal_tuning.mask_hf.enr_suppress, cfg_transformed.suppressor.normal_tuning.mask_hf.enr_suppress); EXPECT_EQ(cfg.suppressor.subband_nearend_detection.nearend_average_blocks, diff --git a/modules/audio_processing/aec3/BUILD.gn b/modules/audio_processing/aec3/BUILD.gn index e67c80299c..c56f05ce13 100644 --- a/modules/audio_processing/aec3/BUILD.gn +++ b/modules/audio_processing/aec3/BUILD.gn @@ -38,6 +38,8 @@ rtc_library("aec3") { "block_processor_metrics.h", "clockdrift_detector.cc", "clockdrift_detector.h", + "coarse_filter_update_gain.cc", + "coarse_filter_update_gain.h", "comfort_noise_generator.cc", "comfort_noise_generator.h", "decimator.cc", @@ -101,8 +103,6 @@ rtc_library("aec3") { "reverb_model.h", "reverb_model_estimator.cc", "reverb_model_estimator.h", - "shadow_filter_update_gain.cc", - "shadow_filter_update_gain.h", "signal_dependent_erle_estimator.cc", "signal_dependent_erle_estimator.h", "spectrum_buffer.cc", @@ -203,6 +203,7 @@ if (rtc_include_tests) { "block_processor_metrics_unittest.cc", "block_processor_unittest.cc", "clockdrift_detector_unittest.cc", + "coarse_filter_update_gain_unittest.cc", "comfort_noise_generator_unittest.cc", "decimator_unittest.cc", "echo_canceller3_unittest.cc", @@ -226,7 +227,6 @@ if (rtc_include_tests) { "render_signal_analyzer_unittest.cc", "residual_echo_estimator_unittest.cc", "reverb_model_estimator_unittest.cc", - "shadow_filter_update_gain_unittest.cc", "signal_dependent_erle_estimator_unittest.cc", "subtractor_unittest.cc", "suppression_filter_unittest.cc", diff --git a/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc b/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc index 7e0591d0d1..8e4f5d9644 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc +++ b/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc @@ -25,9 +25,9 @@ #include "modules/audio_processing/aec3/adaptive_fir_filter_erl.h" #include "modules/audio_processing/aec3/aec3_fft.h" #include "modules/audio_processing/aec3/aec_state.h" +#include "modules/audio_processing/aec3/coarse_filter_update_gain.h" #include "modules/audio_processing/aec3/render_delay_buffer.h" #include "modules/audio_processing/aec3/render_signal_analyzer.h" -#include "modules/audio_processing/aec3/shadow_filter_update_gain.h" #include "modules/audio_processing/logging/apm_data_dumper.h" #include "modules/audio_processing/test/echo_canceller_test_tools.h" #include "modules/audio_processing/utility/cascaded_biquad_filter.h" @@ -354,9 +354,9 @@ TEST_P(AdaptiveFirFilterMultiChannel, FilterAndAdapt) { if (num_render_channels == 33) { config.filter.refined = {13, 0.00005f, 0.0005f, 0.0001f, 2.f, 20075344.f}; - config.filter.shadow = {13, 0.1f, 20075344.f}; + config.filter.coarse = {13, 0.1f, 20075344.f}; config.filter.refined_initial = {12, 0.005f, 0.5f, 0.001f, 2.f, 20075344.f}; - config.filter.shadow_initial = {12, 0.7f, 20075344.f}; + config.filter.coarse_initial = {12, 0.7f, 20075344.f}; } AdaptiveFirFilter filter( @@ -375,7 +375,7 @@ TEST_P(AdaptiveFirFilterMultiChannel, FilterAndAdapt) { config.delay.default_delay = 1; std::unique_ptr render_delay_buffer( RenderDelayBuffer::Create(config, kSampleRateHz, num_render_channels)); - ShadowFilterUpdateGain gain(config.filter.shadow, + CoarseFilterUpdateGain gain(config.filter.coarse, config.filter.config_change_duration_blocks); Random random_generator(42U); std::vector>> x( @@ -395,7 +395,7 @@ TEST_P(AdaptiveFirFilterMultiChannel, FilterAndAdapt) { std::vector> Y2(num_capture_channels); std::vector> E2_refined( num_capture_channels); - std::array E2_shadow; + std::array E2_coarse; // [B,A] = butter(2,100/8000,'high') constexpr CascadedBiQuadFilter::BiQuadCoefficients kHighPassFilterCoefficients = {{0.97261f, -1.94523f, 0.97261f}, @@ -406,7 +406,7 @@ TEST_P(AdaptiveFirFilterMultiChannel, FilterAndAdapt) { for (auto& E2_refined_ch : E2_refined) { E2_refined_ch.fill(0.f); } - E2_shadow.fill(0.f); + E2_coarse.fill(0.f); for (auto& subtractor_output : output) { subtractor_output.Reset(); } diff --git a/modules/audio_processing/aec3/aec_state.cc b/modules/audio_processing/aec3/aec_state.cc index b4b1411daa..3c2a4033db 100644 --- a/modules/audio_processing/aec3/aec_state.cc +++ b/modules/audio_processing/aec3/aec_state.cc @@ -512,7 +512,7 @@ void AecState::SaturationDetector::Update( saturated_echo_ = saturated_echo_ || (subtractor_output[ch].s_refined_max_abs > kSaturationThreshold || - subtractor_output[ch].s_shadow_max_abs > kSaturationThreshold); + subtractor_output[ch].s_coarse_max_abs > kSaturationThreshold); } } else { float max_sample = 0.f; diff --git a/modules/audio_processing/aec3/shadow_filter_update_gain.cc b/modules/audio_processing/aec3/coarse_filter_update_gain.cc similarity index 86% rename from modules/audio_processing/aec3/shadow_filter_update_gain.cc rename to modules/audio_processing/aec3/coarse_filter_update_gain.cc index 51ead2e540..f4fb74d20d 100644 --- a/modules/audio_processing/aec3/shadow_filter_update_gain.cc +++ b/modules/audio_processing/aec3/coarse_filter_update_gain.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "modules/audio_processing/aec3/shadow_filter_update_gain.h" +#include "modules/audio_processing/aec3/coarse_filter_update_gain.h" #include #include @@ -17,8 +17,8 @@ namespace webrtc { -ShadowFilterUpdateGain::ShadowFilterUpdateGain( - const EchoCanceller3Config::Filter::ShadowConfiguration& config, +CoarseFilterUpdateGain::CoarseFilterUpdateGain( + const EchoCanceller3Config::Filter::CoarseConfiguration& config, size_t config_change_duration_blocks) : config_change_duration_blocks_( static_cast(config_change_duration_blocks)) { @@ -27,15 +27,15 @@ ShadowFilterUpdateGain::ShadowFilterUpdateGain( one_by_config_change_duration_blocks_ = 1.f / config_change_duration_blocks_; } -void ShadowFilterUpdateGain::HandleEchoPathChange() { +void CoarseFilterUpdateGain::HandleEchoPathChange() { poor_signal_excitation_counter_ = 0; call_counter_ = 0; } -void ShadowFilterUpdateGain::Compute( +void CoarseFilterUpdateGain::Compute( const std::array& render_power, const RenderSignalAnalyzer& render_signal_analyzer, - const FftData& E_shadow, + const FftData& E_coarse, size_t size_partitions, bool saturated_capture_signal, FftData* G) { @@ -72,12 +72,12 @@ void ShadowFilterUpdateGain::Compute( // G = mu * E * X2. for (size_t k = 0; k < kFftLengthBy2Plus1; ++k) { - G->re[k] = mu[k] * E_shadow.re[k]; - G->im[k] = mu[k] * E_shadow.im[k]; + G->re[k] = mu[k] * E_coarse.re[k]; + G->im[k] = mu[k] * E_coarse.im[k]; } } -void ShadowFilterUpdateGain::UpdateCurrentConfig() { +void CoarseFilterUpdateGain::UpdateCurrentConfig() { RTC_DCHECK_GE(config_change_duration_blocks_, config_change_counter_); if (config_change_counter_ > 0) { if (--config_change_counter_ > 0) { diff --git a/modules/audio_processing/aec3/shadow_filter_update_gain.h b/modules/audio_processing/aec3/coarse_filter_update_gain.h similarity index 73% rename from modules/audio_processing/aec3/shadow_filter_update_gain.h rename to modules/audio_processing/aec3/coarse_filter_update_gain.h index 9d14807ef3..a1a1399b2c 100644 --- a/modules/audio_processing/aec3/shadow_filter_update_gain.h +++ b/modules/audio_processing/aec3/coarse_filter_update_gain.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef MODULES_AUDIO_PROCESSING_AEC3_SHADOW_FILTER_UPDATE_GAIN_H_ -#define MODULES_AUDIO_PROCESSING_AEC3_SHADOW_FILTER_UPDATE_GAIN_H_ +#ifndef MODULES_AUDIO_PROCESSING_AEC3_COARSE_FILTER_UPDATE_GAIN_H_ +#define MODULES_AUDIO_PROCESSING_AEC3_COARSE_FILTER_UPDATE_GAIN_H_ #include @@ -22,11 +22,11 @@ namespace webrtc { -// Provides functionality for computing the fixed gain for the shadow filter. -class ShadowFilterUpdateGain { +// Provides functionality for computing the fixed gain for the coarse filter. +class CoarseFilterUpdateGain { public: - explicit ShadowFilterUpdateGain( - const EchoCanceller3Config::Filter::ShadowConfiguration& config, + explicit CoarseFilterUpdateGain( + const EchoCanceller3Config::Filter::CoarseConfiguration& config, size_t config_change_duration_blocks); // Takes action in the case of a known echo path change. @@ -35,14 +35,14 @@ class ShadowFilterUpdateGain { // Computes the gain. void Compute(const std::array& render_power, const RenderSignalAnalyzer& render_signal_analyzer, - const FftData& E_shadow, + const FftData& E_coarse, size_t size_partitions, bool saturated_capture_signal, FftData* G); // Sets a new config. void SetConfig( - const EchoCanceller3Config::Filter::ShadowConfiguration& config, + const EchoCanceller3Config::Filter::CoarseConfiguration& config, bool immediate_effect) { if (immediate_effect) { old_target_config_ = current_config_ = target_config_ = config; @@ -55,9 +55,9 @@ class ShadowFilterUpdateGain { } private: - EchoCanceller3Config::Filter::ShadowConfiguration current_config_; - EchoCanceller3Config::Filter::ShadowConfiguration target_config_; - EchoCanceller3Config::Filter::ShadowConfiguration old_target_config_; + EchoCanceller3Config::Filter::CoarseConfiguration current_config_; + EchoCanceller3Config::Filter::CoarseConfiguration target_config_; + EchoCanceller3Config::Filter::CoarseConfiguration old_target_config_; const int config_change_duration_blocks_; float one_by_config_change_duration_blocks_; // TODO(peah): Check whether this counter should instead be initialized to a @@ -71,4 +71,4 @@ class ShadowFilterUpdateGain { } // namespace webrtc -#endif // MODULES_AUDIO_PROCESSING_AEC3_SHADOW_FILTER_UPDATE_GAIN_H_ +#endif // MODULES_AUDIO_PROCESSING_AEC3_COARSE_FILTER_UPDATE_GAIN_H_ diff --git a/modules/audio_processing/aec3/shadow_filter_update_gain_unittest.cc b/modules/audio_processing/aec3/coarse_filter_update_gain_unittest.cc similarity index 85% rename from modules/audio_processing/aec3/shadow_filter_update_gain_unittest.cc rename to modules/audio_processing/aec3/coarse_filter_update_gain_unittest.cc index ccac9b3193..4185c1adb8 100644 --- a/modules/audio_processing/aec3/shadow_filter_update_gain_unittest.cc +++ b/modules/audio_processing/aec3/coarse_filter_update_gain_unittest.cc @@ -8,9 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "modules/audio_processing/aec3/shadow_filter_update_gain.h" +#include "modules/audio_processing/aec3/coarse_filter_update_gain.h" #include +#include #include #include #include @@ -44,8 +45,8 @@ void RunFilterUpdateTest(int num_blocks_to_process, config.filter.refined.length_blocks, config.filter.refined.length_blocks, config.filter.config_change_duration_blocks, num_render_channels, DetectOptimization(), &data_dumper); - AdaptiveFirFilter shadow_filter( - config.filter.shadow.length_blocks, config.filter.shadow.length_blocks, + AdaptiveFirFilter coarse_filter( + config.filter.coarse.length_blocks, config.filter.coarse.length_blocks, config.filter.config_change_duration_blocks, num_render_channels, DetectOptimization(), &data_dumper); Aec3Fft fft; @@ -55,8 +56,8 @@ void RunFilterUpdateTest(int num_blocks_to_process, std::unique_ptr render_delay_buffer( RenderDelayBuffer::Create(config, kSampleRateHz, num_render_channels)); - ShadowFilterUpdateGain shadow_gain( - config.filter.shadow, config.filter.config_change_duration_blocks); + CoarseFilterUpdateGain coarse_gain( + config.filter.coarse, config.filter.config_change_duration_blocks); Random random_generator(42U); std::vector>> x( NumBandsForRate(kSampleRateHz), @@ -67,8 +68,8 @@ void RunFilterUpdateTest(int num_blocks_to_process, std::array s; FftData S; FftData G; - FftData E_shadow; - std::array e_shadow; + FftData E_coarse; + std::array e_coarse; constexpr float kScale = 1.0f / kFftLengthBy2; @@ -96,24 +97,24 @@ void RunFilterUpdateTest(int num_blocks_to_process, render_signal_analyzer.Update(*render_delay_buffer->GetRenderBuffer(), delay_samples / kBlockSize); - shadow_filter.Filter(*render_delay_buffer->GetRenderBuffer(), &S); + coarse_filter.Filter(*render_delay_buffer->GetRenderBuffer(), &S); fft.Ifft(S, &s); std::transform(y.begin(), y.end(), s.begin() + kFftLengthBy2, - e_shadow.begin(), + e_coarse.begin(), [&](float a, float b) { return a - b * kScale; }); - std::for_each(e_shadow.begin(), e_shadow.end(), + std::for_each(e_coarse.begin(), e_coarse.end(), [](float& a) { a = rtc::SafeClamp(a, -32768.f, 32767.f); }); - fft.ZeroPaddedFft(e_shadow, Aec3Fft::Window::kRectangular, &E_shadow); + fft.ZeroPaddedFft(e_coarse, Aec3Fft::Window::kRectangular, &E_coarse); std::array render_power; render_delay_buffer->GetRenderBuffer()->SpectralSum( - shadow_filter.SizePartitions(), &render_power); - shadow_gain.Compute(render_power, render_signal_analyzer, E_shadow, - shadow_filter.SizePartitions(), saturation, &G); - shadow_filter.Adapt(*render_delay_buffer->GetRenderBuffer(), G); + coarse_filter.SizePartitions(), &render_power); + coarse_gain.Compute(render_power, render_signal_analyzer, E_coarse, + coarse_filter.SizePartitions(), saturation, &G); + coarse_filter.Adapt(*render_delay_buffer->GetRenderBuffer(), G); } - std::copy(e_shadow.begin(), e_shadow.end(), e_last_block->begin()); + std::copy(e_coarse.begin(), e_coarse.end(), e_last_block->begin()); std::copy(y.begin(), y.end(), y_last_block->begin()); std::copy(G.re.begin(), G.re.end(), G_last_block->re.begin()); std::copy(G.im.begin(), G.im.end(), G_last_block->im.begin()); @@ -137,14 +138,14 @@ std::string ProduceDebugText(size_t delay, int filter_length_blocks) { #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) // Verifies that the check for non-null output gain parameter works. -TEST(ShadowFilterUpdateGain, NullDataOutputGain) { +TEST(CoarseFilterUpdateGain, NullDataOutputGain) { ApmDataDumper data_dumper(42); FftBuffer fft_buffer(1, 1); RenderSignalAnalyzer analyzer(EchoCanceller3Config{}); FftData E; - const EchoCanceller3Config::Filter::ShadowConfiguration& config = { + const EchoCanceller3Config::Filter::CoarseConfiguration& config = { 12, 0.5f, 220075344.f}; - ShadowFilterUpdateGain gain(config, 250); + CoarseFilterUpdateGain gain(config, 250); std::array render_power; render_power.fill(0.f); EXPECT_DEATH(gain.Compute(render_power, analyzer, E, 1, false, nullptr), ""); @@ -152,16 +153,16 @@ TEST(ShadowFilterUpdateGain, NullDataOutputGain) { #endif -class ShadowFilterUpdateGainOneTwoEightRenderChannels +class CoarseFilterUpdateGainOneTwoEightRenderChannels : public ::testing::Test, public ::testing::WithParamInterface {}; INSTANTIATE_TEST_SUITE_P(MultiChannel, - ShadowFilterUpdateGainOneTwoEightRenderChannels, + CoarseFilterUpdateGainOneTwoEightRenderChannels, ::testing::Values(1, 2, 8)); // Verifies that the gain formed causes the filter using it to converge. -TEST_P(ShadowFilterUpdateGainOneTwoEightRenderChannels, +TEST_P(CoarseFilterUpdateGainOneTwoEightRenderChannels, GainCausesFilterToConverge) { const size_t num_render_channels = GetParam(); std::vector blocks_with_echo_path_changes; @@ -193,7 +194,7 @@ TEST_P(ShadowFilterUpdateGainOneTwoEightRenderChannels, } // Verifies that the gain is zero when there is saturation. -TEST_P(ShadowFilterUpdateGainOneTwoEightRenderChannels, SaturationBehavior) { +TEST_P(CoarseFilterUpdateGainOneTwoEightRenderChannels, SaturationBehavior) { const size_t num_render_channels = GetParam(); std::vector blocks_with_echo_path_changes; std::vector blocks_with_saturation; @@ -218,22 +219,22 @@ TEST_P(ShadowFilterUpdateGainOneTwoEightRenderChannels, SaturationBehavior) { } } -class ShadowFilterUpdateGainOneTwoFourRenderChannels +class CoarseFilterUpdateGainOneTwoFourRenderChannels : public ::testing::Test, public ::testing::WithParamInterface {}; INSTANTIATE_TEST_SUITE_P( MultiChannel, - ShadowFilterUpdateGainOneTwoFourRenderChannels, + CoarseFilterUpdateGainOneTwoFourRenderChannels, ::testing::Values(1, 2, 4), [](const ::testing::TestParamInfo< - ShadowFilterUpdateGainOneTwoFourRenderChannels::ParamType>& info) { + CoarseFilterUpdateGainOneTwoFourRenderChannels::ParamType>& info) { return (rtc::StringBuilder() << "Render" << info.param).str(); }); // Verifies that the magnitude of the gain on average decreases for a // persistently exciting signal. -TEST_P(ShadowFilterUpdateGainOneTwoFourRenderChannels, DecreasingGain) { +TEST_P(CoarseFilterUpdateGainOneTwoFourRenderChannels, DecreasingGain) { const size_t num_render_channels = GetParam(); for (size_t filter_length_blocks : {12, 20, 30}) { SCOPED_TRACE(ProduceDebugText(filter_length_blocks)); diff --git a/modules/audio_processing/aec3/echo_canceller3.cc b/modules/audio_processing/aec3/echo_canceller3.cc index 30ae80b2b3..bd1b82a1f2 100644 --- a/modules/audio_processing/aec3/echo_canceller3.cc +++ b/modules/audio_processing/aec3/echo_canceller3.cc @@ -41,6 +41,10 @@ EchoCanceller3Config AdjustConfig(const EchoCanceller3Config& config) { if (adjusted_cfg.filter.use_legacy_filter_naming) { adjusted_cfg.filter.refined = adjusted_cfg.filter.main; adjusted_cfg.filter.refined_initial = adjusted_cfg.filter.main_initial; + adjusted_cfg.filter.coarse = adjusted_cfg.filter.shadow; + adjusted_cfg.filter.coarse_initial = adjusted_cfg.filter.shadow_initial; + adjusted_cfg.filter.enable_coarse_filter_output_usage = + adjusted_cfg.filter.enable_shadow_filter_output_usage; } if (field_trial::IsEnabled("WebRTC-Aec3ShortHeadroomKillSwitch")) { @@ -480,12 +484,12 @@ EchoCanceller3Config EchoCanceller3::CreateDefaultConfig( size_t num_capture_channels) { EchoCanceller3Config cfg; if (num_render_channels > 1) { - // Use shorter and more rapidly adapting shadow filter to compensate for + // Use shorter and more rapidly adapting coarse filter to compensate for // thge increased number of total filter parameters to adapt. - cfg.filter.shadow.length_blocks = 11; - cfg.filter.shadow.rate = 0.95f; - cfg.filter.shadow_initial.length_blocks = 11; - cfg.filter.shadow_initial.rate = 0.95f; + cfg.filter.coarse.length_blocks = 11; + cfg.filter.coarse.rate = 0.95f; + cfg.filter.coarse_initial.length_blocks = 11; + cfg.filter.coarse_initial.rate = 0.95f; // Use more concervative suppressor behavior for non-nearend speech. cfg.suppressor.normal_tuning.max_dec_factor_lf = 0.35f; diff --git a/modules/audio_processing/aec3/echo_remover.cc b/modules/audio_processing/aec3/echo_remover.cc index 55cfe4b54b..06f3b45a08 100644 --- a/modules/audio_processing/aec3/echo_remover.cc +++ b/modules/audio_processing/aec3/echo_remover.cc @@ -133,7 +133,7 @@ class EchoRemoverImpl final : public EchoRemover { } private: - // Selects which of the shadow and refined linear filter outputs that is most + // Selects which of the coarse and refined linear filter outputs that is most // appropriate to pass to the suppressor and forms the linear filter output by // smoothly transition between those. void FormLinearFilterOutput(const SubtractorOutput& subtractor_output, @@ -147,7 +147,7 @@ class EchoRemoverImpl final : public EchoRemover { const int sample_rate_hz_; const size_t num_render_channels_; const size_t num_capture_channels_; - const bool use_shadow_filter_output_; + const bool use_coarse_filter_output_; Subtractor subtractor_; SuppressionGain suppression_gain_; ComfortNoiseGenerator cng_; @@ -189,8 +189,8 @@ EchoRemoverImpl::EchoRemoverImpl(const EchoCanceller3Config& config, sample_rate_hz_(sample_rate_hz), num_render_channels_(num_render_channels), num_capture_channels_(num_capture_channels), - use_shadow_filter_output_( - config_.filter.enable_shadow_filter_output_usage), + use_coarse_filter_output_( + config_.filter.enable_coarse_filter_output_usage), subtractor_(config, num_render_channels_, num_capture_channels_, @@ -457,21 +457,21 @@ void EchoRemoverImpl::FormLinearFilterOutput( const SubtractorOutput& subtractor_output, rtc::ArrayView output) { RTC_DCHECK_EQ(subtractor_output.e_refined.size(), output.size()); - RTC_DCHECK_EQ(subtractor_output.e_shadow.size(), output.size()); + RTC_DCHECK_EQ(subtractor_output.e_coarse.size(), output.size()); bool use_refined_output = true; - if (use_shadow_filter_output_) { + if (use_coarse_filter_output_) { // As the output of the refined adaptive filter generally should be better - // than the shadow filter output, add a margin and threshold for when - // choosing the shadow filter output. - if (subtractor_output.e2_shadow < 0.9f * subtractor_output.e2_refined && + // than the coarse filter output, add a margin and threshold for when + // choosing the coarse filter output. + if (subtractor_output.e2_coarse < 0.9f * subtractor_output.e2_refined && subtractor_output.y2 > 30.f * 30.f * kBlockSize && (subtractor_output.s2_refined > 60.f * 60.f * kBlockSize || - subtractor_output.s2_shadow > 60.f * 60.f * kBlockSize)) { + subtractor_output.s2_coarse > 60.f * 60.f * kBlockSize)) { use_refined_output = false; } else { // If the refined filter is diverged, choose the filter output that has // the lowest power. - if (subtractor_output.e2_shadow < subtractor_output.e2_refined && + if (subtractor_output.e2_coarse < subtractor_output.e2_refined && subtractor_output.y2 < subtractor_output.e2_refined) { use_refined_output = false; } @@ -480,9 +480,9 @@ void EchoRemoverImpl::FormLinearFilterOutput( SignalTransition(refined_filter_output_last_selected_ ? subtractor_output.e_refined - : subtractor_output.e_shadow, + : subtractor_output.e_coarse, use_refined_output ? subtractor_output.e_refined - : subtractor_output.e_shadow, + : subtractor_output.e_coarse, output); refined_filter_output_last_selected_ = use_refined_output; } diff --git a/modules/audio_processing/aec3/refined_filter_update_gain.cc b/modules/audio_processing/aec3/refined_filter_update_gain.cc index bd79f870e8..138329ad38 100644 --- a/modules/audio_processing/aec3/refined_filter_update_gain.cc +++ b/modules/audio_processing/aec3/refined_filter_update_gain.cc @@ -78,7 +78,7 @@ void RefinedFilterUpdateGain::Compute( // Introducing shorter notation to improve readability. const FftData& E_refined = subtractor_output.E_refined; const auto& E2_refined = subtractor_output.E2_refined; - const auto& E2_shadow = subtractor_output.E2_shadow; + const auto& E2_coarse = subtractor_output.E2_coarse; FftData* G = gain_fft; const auto& X2 = render_power; @@ -125,7 +125,7 @@ void RefinedFilterUpdateGain::Compute( // H_error = H_error + factor * erl. for (size_t k = 0; k < kFftLengthBy2Plus1; ++k) { - if (E2_shadow[k] >= E2_refined[k]) { + if (E2_coarse[k] >= E2_refined[k]) { H_error_[k] += current_config_.leakage_converged * erl[k]; } else { H_error_[k] += current_config_.leakage_diverged * erl[k]; diff --git a/modules/audio_processing/aec3/refined_filter_update_gain_unittest.cc b/modules/audio_processing/aec3/refined_filter_update_gain_unittest.cc index 6ee880ad14..117f34508e 100644 --- a/modules/audio_processing/aec3/refined_filter_update_gain_unittest.cc +++ b/modules/audio_processing/aec3/refined_filter_update_gain_unittest.cc @@ -18,9 +18,9 @@ #include "modules/audio_processing/aec3/adaptive_fir_filter.h" #include "modules/audio_processing/aec3/adaptive_fir_filter_erl.h" #include "modules/audio_processing/aec3/aec_state.h" +#include "modules/audio_processing/aec3/coarse_filter_update_gain.h" #include "modules/audio_processing/aec3/render_delay_buffer.h" #include "modules/audio_processing/aec3/render_signal_analyzer.h" -#include "modules/audio_processing/aec3/shadow_filter_update_gain.h" #include "modules/audio_processing/aec3/subtractor_output.h" #include "modules/audio_processing/logging/apm_data_dumper.h" #include "modules/audio_processing/test/echo_canceller_test_tools.h" @@ -52,13 +52,13 @@ void RunFilterUpdateTest(int num_blocks_to_process, EchoCanceller3Config config; config.filter.refined.length_blocks = filter_length_blocks; - config.filter.shadow.length_blocks = filter_length_blocks; + config.filter.coarse.length_blocks = filter_length_blocks; AdaptiveFirFilter refined_filter( config.filter.refined.length_blocks, config.filter.refined.length_blocks, config.filter.config_change_duration_blocks, kNumRenderChannels, optimization, &data_dumper); - AdaptiveFirFilter shadow_filter( - config.filter.shadow.length_blocks, config.filter.shadow.length_blocks, + AdaptiveFirFilter coarse_filter( + config.filter.coarse.length_blocks, config.filter.coarse.length_blocks, config.filter.config_change_duration_blocks, kNumRenderChannels, optimization, &data_dumper); std::vector>> H2( @@ -79,8 +79,8 @@ void RunFilterUpdateTest(int num_blocks_to_process, Aec3Fft fft; std::array x_old; x_old.fill(0.f); - ShadowFilterUpdateGain shadow_gain( - config.filter.shadow, config.filter.config_change_duration_blocks); + CoarseFilterUpdateGain coarse_gain( + config.filter.coarse, config.filter.config_change_duration_blocks); RefinedFilterUpdateGain refined_gain( config.filter.refined, config.filter.config_change_duration_blocks); Random random_generator(42U); @@ -103,12 +103,12 @@ void RunFilterUpdateTest(int num_blocks_to_process, subtractor_output.Reset(); } FftData& E_refined = output[0].E_refined; - FftData E_shadow; + FftData E_coarse; std::vector> Y2(kNumCaptureChannels); std::vector> E2_refined( kNumCaptureChannels); std::array& e_refined = output[0].e_refined; - std::array& e_shadow = output[0].e_shadow; + std::array& e_coarse = output[0].e_coarse; for (auto& Y2_ch : Y2) { Y2_ch.fill(0.f); } @@ -167,27 +167,27 @@ void RunFilterUpdateTest(int num_blocks_to_process, s[k] = kScale * s_scratch[k + kFftLengthBy2]; } - // Apply the shadow filter. - shadow_filter.Filter(*render_delay_buffer->GetRenderBuffer(), &S); + // Apply the coarse filter. + coarse_filter.Filter(*render_delay_buffer->GetRenderBuffer(), &S); fft.Ifft(S, &s_scratch); std::transform(y.begin(), y.end(), s_scratch.begin() + kFftLengthBy2, - e_shadow.begin(), + e_coarse.begin(), [&](float a, float b) { return a - b * kScale; }); - std::for_each(e_shadow.begin(), e_shadow.end(), + std::for_each(e_coarse.begin(), e_coarse.end(), [](float& a) { a = rtc::SafeClamp(a, -32768.f, 32767.f); }); - fft.ZeroPaddedFft(e_shadow, Aec3Fft::Window::kRectangular, &E_shadow); + fft.ZeroPaddedFft(e_coarse, Aec3Fft::Window::kRectangular, &E_coarse); // Compute spectra for future use. E_refined.Spectrum(Aec3Optimization::kNone, output[0].E2_refined); - E_shadow.Spectrum(Aec3Optimization::kNone, output[0].E2_shadow); + E_coarse.Spectrum(Aec3Optimization::kNone, output[0].E2_coarse); - // Adapt the shadow filter. + // Adapt the coarse filter. std::array render_power; render_delay_buffer->GetRenderBuffer()->SpectralSum( - shadow_filter.SizePartitions(), &render_power); - shadow_gain.Compute(render_power, render_signal_analyzer, E_shadow, - shadow_filter.SizePartitions(), saturation, &G); - shadow_filter.Adapt(*render_delay_buffer->GetRenderBuffer(), G); + coarse_filter.SizePartitions(), &render_power); + coarse_gain.Compute(render_power, render_signal_analyzer, E_coarse, + coarse_filter.SizePartitions(), saturation, &G); + coarse_filter.Adapt(*render_delay_buffer->GetRenderBuffer(), G); // Adapt the refined filter render_delay_buffer->GetRenderBuffer()->SpectralSum( diff --git a/modules/audio_processing/aec3/subtractor.cc b/modules/audio_processing/aec3/subtractor.cc index da6fda1894..d15229934f 100644 --- a/modules/audio_processing/aec3/subtractor.cc +++ b/modules/audio_processing/aec3/subtractor.cc @@ -67,11 +67,11 @@ Subtractor::Subtractor(const EchoCanceller3Config& config, config_(config), num_capture_channels_(num_capture_channels), refined_filters_(num_capture_channels_), - shadow_filter_(num_capture_channels_), + coarse_filter_(num_capture_channels_), refined_gains_(num_capture_channels_), - shadow_gains_(num_capture_channels_), + coarse_gains_(num_capture_channels_), filter_misadjustment_estimators_(num_capture_channels_), - poor_shadow_filter_counters_(num_capture_channels_, 0), + poor_coarse_filter_counters_(num_capture_channels_, 0), refined_frequency_responses_( num_capture_channels_, std::vector>( @@ -91,16 +91,16 @@ Subtractor::Subtractor(const EchoCanceller3Config& config, config.filter.config_change_duration_blocks, num_render_channels, optimization, data_dumper_); - shadow_filter_[ch] = std::make_unique( - config_.filter.shadow.length_blocks, - config_.filter.shadow_initial.length_blocks, + coarse_filter_[ch] = std::make_unique( + config_.filter.coarse.length_blocks, + config_.filter.coarse_initial.length_blocks, config.filter.config_change_duration_blocks, num_render_channels, optimization, data_dumper_); refined_gains_[ch] = std::make_unique( config_.filter.refined_initial, config_.filter.config_change_duration_blocks); - shadow_gains_[ch] = std::make_unique( - config_.filter.shadow_initial, + coarse_gains_[ch] = std::make_unique( + config_.filter.coarse_initial, config.filter.config_change_duration_blocks); } @@ -119,15 +119,15 @@ void Subtractor::HandleEchoPathChange( const auto full_reset = [&]() { for (size_t ch = 0; ch < num_capture_channels_; ++ch) { refined_filters_[ch]->HandleEchoPathChange(); - shadow_filter_[ch]->HandleEchoPathChange(); + coarse_filter_[ch]->HandleEchoPathChange(); refined_gains_[ch]->HandleEchoPathChange(echo_path_variability); - shadow_gains_[ch]->HandleEchoPathChange(); + coarse_gains_[ch]->HandleEchoPathChange(); refined_gains_[ch]->SetConfig(config_.filter.refined_initial, true); - shadow_gains_[ch]->SetConfig(config_.filter.shadow_initial, true); + coarse_gains_[ch]->SetConfig(config_.filter.coarse_initial, true); refined_filters_[ch]->SetSizePartitions( config_.filter.refined_initial.length_blocks, true); - shadow_filter_[ch]->SetSizePartitions( - config_.filter.shadow_initial.length_blocks, true); + coarse_filter_[ch]->SetSizePartitions( + config_.filter.coarse_initial.length_blocks, true); } }; @@ -146,10 +146,10 @@ void Subtractor::HandleEchoPathChange( void Subtractor::ExitInitialState() { for (size_t ch = 0; ch < num_capture_channels_; ++ch) { refined_gains_[ch]->SetConfig(config_.filter.refined, false); - shadow_gains_[ch]->SetConfig(config_.filter.shadow, false); + coarse_gains_[ch]->SetConfig(config_.filter.coarse, false); refined_filters_[ch]->SetSizePartitions( config_.filter.refined.length_blocks, false); - shadow_filter_[ch]->SetSizePartitions(config_.filter.shadow.length_blocks, + coarse_filter_[ch]->SetSizePartitions(config_.filter.coarse.length_blocks, false); } } @@ -163,22 +163,22 @@ void Subtractor::Process(const RenderBuffer& render_buffer, // Compute the render powers. const bool same_filter_sizes = refined_filters_[0]->SizePartitions() == - shadow_filter_[0]->SizePartitions(); + coarse_filter_[0]->SizePartitions(); std::array X2_refined; - std::array X2_shadow_data; - auto& X2_shadow = same_filter_sizes ? X2_refined : X2_shadow_data; + std::array X2_coarse_data; + auto& X2_coarse = same_filter_sizes ? X2_refined : X2_coarse_data; if (same_filter_sizes) { render_buffer.SpectralSum(refined_filters_[0]->SizePartitions(), &X2_refined); } else if (refined_filters_[0]->SizePartitions() > - shadow_filter_[0]->SizePartitions()) { - render_buffer.SpectralSums(shadow_filter_[0]->SizePartitions(), + coarse_filter_[0]->SizePartitions()) { + render_buffer.SpectralSums(coarse_filter_[0]->SizePartitions(), refined_filters_[0]->SizePartitions(), - &X2_shadow, &X2_refined); + &X2_coarse, &X2_refined); } else { render_buffer.SpectralSums(refined_filters_[0]->SizePartitions(), - shadow_filter_[0]->SizePartitions(), &X2_refined, - &X2_shadow); + coarse_filter_[0]->SizePartitions(), &X2_refined, + &X2_coarse); } // Process all capture channels @@ -187,19 +187,19 @@ void Subtractor::Process(const RenderBuffer& render_buffer, SubtractorOutput& output = outputs[ch]; rtc::ArrayView y = capture[ch]; FftData& E_refined = output.E_refined; - FftData E_shadow; + FftData E_coarse; std::array& e_refined = output.e_refined; - std::array& e_shadow = output.e_shadow; + std::array& e_coarse = output.e_coarse; FftData S; FftData& G = S; - // Form the outputs of the refined and shadow filters. + // Form the outputs of the refined and coarse filters. refined_filters_[ch]->Filter(render_buffer, &S); PredictionError(fft_, S, y, &e_refined, &output.s_refined); - shadow_filter_[ch]->Filter(render_buffer, &S); - PredictionError(fft_, S, y, &e_shadow, &output.s_shadow); + coarse_filter_[ch]->Filter(render_buffer, &S); + PredictionError(fft_, S, y, &e_coarse, &output.s_coarse); // Compute the signal powers in the subtractor output. output.ComputeMetrics(y); @@ -218,12 +218,12 @@ void Subtractor::Process(const RenderBuffer& render_buffer, refined_filters_adjusted = true; } - // Compute the FFts of the refined and shadow filter outputs. + // Compute the FFts of the refined and coarse filter outputs. fft_.ZeroPaddedFft(e_refined, Aec3Fft::Window::kHanning, &E_refined); - fft_.ZeroPaddedFft(e_shadow, Aec3Fft::Window::kHanning, &E_shadow); + fft_.ZeroPaddedFft(e_coarse, Aec3Fft::Window::kHanning, &E_coarse); // Compute spectra for future use. - E_shadow.Spectrum(optimization_, output.E2_shadow); + E_coarse.Spectrum(optimization_, output.E2_coarse); E_refined.Spectrum(optimization_, output.E2_refined); // Update the refined filter. @@ -247,28 +247,28 @@ void Subtractor::Process(const RenderBuffer& render_buffer, data_dumper_->DumpRaw("aec3_subtractor_G_refined", G.im); } - // Update the shadow filter. - poor_shadow_filter_counters_[ch] = - output.e2_refined < output.e2_shadow - ? poor_shadow_filter_counters_[ch] + 1 + // Update the coarse filter. + poor_coarse_filter_counters_[ch] = + output.e2_refined < output.e2_coarse + ? poor_coarse_filter_counters_[ch] + 1 : 0; - if (poor_shadow_filter_counters_[ch] < 5) { - shadow_gains_[ch]->Compute(X2_shadow, render_signal_analyzer, E_shadow, - shadow_filter_[ch]->SizePartitions(), + if (poor_coarse_filter_counters_[ch] < 5) { + coarse_gains_[ch]->Compute(X2_coarse, render_signal_analyzer, E_coarse, + coarse_filter_[ch]->SizePartitions(), aec_state.SaturatedCapture(), &G); } else { - poor_shadow_filter_counters_[ch] = 0; - shadow_filter_[ch]->SetFilter(refined_filters_[ch]->SizePartitions(), + poor_coarse_filter_counters_[ch] = 0; + coarse_filter_[ch]->SetFilter(refined_filters_[ch]->SizePartitions(), refined_filters_[ch]->GetFilter()); - shadow_gains_[ch]->Compute(X2_shadow, render_signal_analyzer, E_refined, - shadow_filter_[ch]->SizePartitions(), + coarse_gains_[ch]->Compute(X2_coarse, render_signal_analyzer, E_refined, + coarse_filter_[ch]->SizePartitions(), aec_state.SaturatedCapture(), &G); } - shadow_filter_[ch]->Adapt(render_buffer, G); + coarse_filter_[ch]->Adapt(render_buffer, G); if (ch == 0) { - data_dumper_->DumpRaw("aec3_subtractor_G_shadow", G.re); - data_dumper_->DumpRaw("aec3_subtractor_G_shadow", G.im); + data_dumper_->DumpRaw("aec3_subtractor_G_coarse", G.re); + data_dumper_->DumpRaw("aec3_subtractor_G_coarse", G.im); filter_misadjustment_estimators_[ch].Dump(data_dumper_); DumpFilters(); } @@ -279,8 +279,8 @@ void Subtractor::Process(const RenderBuffer& render_buffer, if (ch == 0) { data_dumper_->DumpWav("aec3_refined_filters_output", kBlockSize, &e_refined[0], 16000, 1); - data_dumper_->DumpWav("aec3_shadow_filter_output", kBlockSize, - &e_shadow[0], 16000, 1); + data_dumper_->DumpWav("aec3_coarse_filter_output", kBlockSize, + &e_coarse[0], 16000, 1); } } } diff --git a/modules/audio_processing/aec3/subtractor.h b/modules/audio_processing/aec3/subtractor.h index 7b3e6ac15a..42ca3729ca 100644 --- a/modules/audio_processing/aec3/subtractor.h +++ b/modules/audio_processing/aec3/subtractor.h @@ -23,11 +23,11 @@ #include "modules/audio_processing/aec3/aec3_common.h" #include "modules/audio_processing/aec3/aec3_fft.h" #include "modules/audio_processing/aec3/aec_state.h" +#include "modules/audio_processing/aec3/coarse_filter_update_gain.h" #include "modules/audio_processing/aec3/echo_path_variability.h" #include "modules/audio_processing/aec3/refined_filter_update_gain.h" #include "modules/audio_processing/aec3/render_buffer.h" #include "modules/audio_processing/aec3/render_signal_analyzer.h" -#include "modules/audio_processing/aec3/shadow_filter_update_gain.h" #include "modules/audio_processing/aec3/subtractor_output.h" #include "modules/audio_processing/logging/apm_data_dumper.h" #include "rtc_base/checks.h" @@ -80,7 +80,7 @@ class Subtractor { refined_filters_[0]->max_filter_size_partitions()))); refined_filters_[0]->DumpFilter("aec3_subtractor_H_refined"); - shadow_filter_[0]->DumpFilter("aec3_subtractor_H_shadow"); + coarse_filter_[0]->DumpFilter("aec3_subtractor_H_coarse"); } private: @@ -122,11 +122,11 @@ class Subtractor { const size_t num_capture_channels_; std::vector> refined_filters_; - std::vector> shadow_filter_; + std::vector> coarse_filter_; std::vector> refined_gains_; - std::vector> shadow_gains_; + std::vector> coarse_gains_; std::vector filter_misadjustment_estimators_; - std::vector poor_shadow_filter_counters_; + std::vector poor_coarse_filter_counters_; std::vector>> refined_frequency_responses_; std::vector> refined_impulse_responses_; diff --git a/modules/audio_processing/aec3/subtractor_output.cc b/modules/audio_processing/aec3/subtractor_output.cc index 11c8174540..ed80101f06 100644 --- a/modules/audio_processing/aec3/subtractor_output.cc +++ b/modules/audio_processing/aec3/subtractor_output.cc @@ -19,17 +19,17 @@ SubtractorOutput::~SubtractorOutput() = default; void SubtractorOutput::Reset() { s_refined.fill(0.f); - s_shadow.fill(0.f); + s_coarse.fill(0.f); e_refined.fill(0.f); - e_shadow.fill(0.f); + e_coarse.fill(0.f); E_refined.re.fill(0.f); E_refined.im.fill(0.f); E2_refined.fill(0.f); - E2_shadow.fill(0.f); + E2_coarse.fill(0.f); e2_refined = 0.f; - e2_shadow = 0.f; + e2_coarse = 0.f; s2_refined = 0.f; - s2_shadow = 0.f; + s2_coarse = 0.f; y2 = 0.f; } @@ -38,21 +38,21 @@ void SubtractorOutput::ComputeMetrics(rtc::ArrayView y) { y2 = std::accumulate(y.begin(), y.end(), 0.f, sum_of_squares); e2_refined = std::accumulate(e_refined.begin(), e_refined.end(), 0.f, sum_of_squares); - e2_shadow = - std::accumulate(e_shadow.begin(), e_shadow.end(), 0.f, sum_of_squares); + e2_coarse = + std::accumulate(e_coarse.begin(), e_coarse.end(), 0.f, sum_of_squares); s2_refined = std::accumulate(s_refined.begin(), s_refined.end(), 0.f, sum_of_squares); - s2_shadow = - std::accumulate(s_shadow.begin(), s_shadow.end(), 0.f, sum_of_squares); + s2_coarse = + std::accumulate(s_coarse.begin(), s_coarse.end(), 0.f, sum_of_squares); s_refined_max_abs = *std::max_element(s_refined.begin(), s_refined.end()); s_refined_max_abs = std::max(s_refined_max_abs, -(*std::min_element(s_refined.begin(), s_refined.end()))); - s_shadow_max_abs = *std::max_element(s_shadow.begin(), s_shadow.end()); - s_shadow_max_abs = std::max( - s_shadow_max_abs, -(*std::min_element(s_shadow.begin(), s_shadow.end()))); + s_coarse_max_abs = *std::max_element(s_coarse.begin(), s_coarse.end()); + s_coarse_max_abs = std::max( + s_coarse_max_abs, -(*std::min_element(s_coarse.begin(), s_coarse.end()))); } } // namespace webrtc diff --git a/modules/audio_processing/aec3/subtractor_output.h b/modules/audio_processing/aec3/subtractor_output.h index 3f856d966e..d2d12082c6 100644 --- a/modules/audio_processing/aec3/subtractor_output.h +++ b/modules/audio_processing/aec3/subtractor_output.h @@ -26,19 +26,19 @@ struct SubtractorOutput { ~SubtractorOutput(); std::array s_refined; - std::array s_shadow; + std::array s_coarse; std::array e_refined; - std::array e_shadow; + std::array e_coarse; FftData E_refined; std::array E2_refined; - std::array E2_shadow; + std::array E2_coarse; float s2_refined = 0.f; - float s2_shadow = 0.f; + float s2_coarse = 0.f; float e2_refined = 0.f; - float e2_shadow = 0.f; + float e2_coarse = 0.f; float y2 = 0.f; float s_refined_max_abs = 0.f; - float s_shadow_max_abs = 0.f; + float s_coarse_max_abs = 0.f; // Reset the struct content. void Reset(); diff --git a/modules/audio_processing/aec3/subtractor_output_analyzer.cc b/modules/audio_processing/aec3/subtractor_output_analyzer.cc index ac29199dad..8b2218530f 100644 --- a/modules/audio_processing/aec3/subtractor_output_analyzer.cc +++ b/modules/audio_processing/aec3/subtractor_output_analyzer.cc @@ -33,17 +33,17 @@ void SubtractorOutputAnalyzer::Update( for (size_t ch = 0; ch < subtractor_output.size(); ++ch) { const float y2 = subtractor_output[ch].y2; const float e2_refined = subtractor_output[ch].e2_refined; - const float e2_shadow = subtractor_output[ch].e2_shadow; + const float e2_coarse = subtractor_output[ch].e2_coarse; constexpr float kConvergenceThreshold = 50 * 50 * kBlockSize; bool refined_filter_converged = e2_refined < 0.5f * y2 && y2 > kConvergenceThreshold; - bool shadow_filter_converged = - e2_shadow < 0.05f * y2 && y2 > kConvergenceThreshold; - float min_e2 = std::min(e2_refined, e2_shadow); + bool coarse_filter_converged = + e2_coarse < 0.05f * y2 && y2 > kConvergenceThreshold; + float min_e2 = std::min(e2_refined, e2_coarse); bool filter_diverged = min_e2 > 1.5f * y2 && y2 > 30.f * 30.f * kBlockSize; filters_converged_[ch] = - refined_filter_converged || shadow_filter_converged; + refined_filter_converged || coarse_filter_converged; *any_filter_converged = *any_filter_converged || filters_converged_[ch]; *all_filters_diverged = *all_filters_diverged && filter_diverged; diff --git a/modules/audio_processing/aec3/subtractor_unittest.cc b/modules/audio_processing/aec3/subtractor_unittest.cc index 56b0e938ec..72e57879a0 100644 --- a/modules/audio_processing/aec3/subtractor_unittest.cc +++ b/modules/audio_processing/aec3/subtractor_unittest.cc @@ -32,7 +32,7 @@ std::vector RunSubtractorTest( int num_blocks_to_process, int delay_samples, int refined_filter_length_blocks, - int shadow_filter_length_blocks, + int coarse_filter_length_blocks, bool uncorrelated_inputs, const std::vector& blocks_with_echo_path_changes) { ApmDataDumper data_dumper(42); @@ -40,7 +40,7 @@ std::vector RunSubtractorTest( constexpr size_t kNumBands = NumBandsForRate(kSampleRateHz); EchoCanceller3Config config; config.filter.refined.length_blocks = refined_filter_length_blocks; - config.filter.shadow.length_blocks = shadow_filter_length_blocks; + config.filter.coarse.length_blocks = coarse_filter_length_blocks; Subtractor subtractor(config, num_render_channels, num_capture_channels, &data_dumper, DetectOptimization()); @@ -61,7 +61,7 @@ std::vector RunSubtractorTest( std::vector> Y2(num_capture_channels); std::vector> E2_refined( num_capture_channels); - std::array E2_shadow; + std::array E2_coarse; AecState aec_state(config, num_capture_channels); x_old.fill(0.f); for (auto& Y2_ch : Y2) { @@ -70,7 +70,7 @@ std::vector RunSubtractorTest( for (auto& E2_refined_ch : E2_refined) { E2_refined_ch.fill(0.f); } - E2_shadow.fill(0.f); + E2_coarse.fill(0.f); std::vector>>> delay_buffer( num_capture_channels); @@ -232,8 +232,8 @@ TEST(Subtractor, Convergence) { } // Verifies that the subtractor is able to handle the case when the refined -// filter is longer than the shadow filter. -TEST(Subtractor, RefinedFilterLongerThanShadowFilter) { +// filter is longer than the coarse filter. +TEST(Subtractor, RefinedFilterLongerThanCoarseFilter) { std::vector blocks_with_echo_path_changes; std::vector echo_to_nearend_powers = RunSubtractorTest( 1, 1, 400, 64, 20, 15, false, blocks_with_echo_path_changes); @@ -242,9 +242,9 @@ TEST(Subtractor, RefinedFilterLongerThanShadowFilter) { } } -// Verifies that the subtractor is able to handle the case when the shadow +// Verifies that the subtractor is able to handle the case when the coarse // filter is longer than the refined filter. -TEST(Subtractor, ShadowFilterLongerThanRefinedFilter) { +TEST(Subtractor, CoarseFilterLongerThanRefinedFilter) { std::vector blocks_with_echo_path_changes; std::vector echo_to_nearend_powers = RunSubtractorTest( 1, 1, 400, 64, 15, 20, false, blocks_with_echo_path_changes);