From b2b58d84e329e5c8de07ec51d18f854fc2318b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Mon, 2 Dec 2019 14:59:40 +0100 Subject: [PATCH] AEC3: Adding default AEC3 configurations that are setup specific MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds functionality to AEC3 to produce setup-specific default configurations that are tailored to work well for the number of channels at hand. The tunings are only used for the case when no echo control factory has been provided. Bug: webrtc:11151,chromium:1029717 Change-Id: I1bd2d10327300c7b0f3169a52bf66700b781fd6b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/161086 Reviewed-by: Sam Zackrisson Commit-Queue: Per Ã…hgren Cr-Commit-Position: refs/heads/master@{#29972} --- .../audio_processing/aec3/echo_canceller3.cc | 19 +++++++++++++++++++ .../audio_processing/aec3/echo_canceller3.h | 5 +++++ .../audio_processing/audio_processing_impl.cc | 17 ++++++++++++++++- .../audio_processing/audio_processing_impl.h | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/modules/audio_processing/aec3/echo_canceller3.cc b/modules/audio_processing/aec3/echo_canceller3.cc index e387940885..8c8f8bbd2b 100644 --- a/modules/audio_processing/aec3/echo_canceller3.cc +++ b/modules/audio_processing/aec3/echo_canceller3.cc @@ -445,6 +445,25 @@ bool EchoCanceller3::ActiveProcessing() const { return true; } +EchoCanceller3Config EchoCanceller3::CreateDefaultConfig( + size_t num_render_channels, + size_t num_capture_channels) { + EchoCanceller3Config cfg; + if (num_render_channels > 1) { + // Use shorter and more rapidly adapting shadow 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; + + // Use more concervative suppressor behavior for non-nearend speech. + cfg.suppressor.normal_tuning.max_dec_factor_lf = 0.35f; + cfg.suppressor.normal_tuning.max_inc_factor = 1.5f; + } + return cfg; +} + void EchoCanceller3::EmptyRenderQueue() { RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); bool frame_to_buffer = diff --git a/modules/audio_processing/aec3/echo_canceller3.h b/modules/audio_processing/aec3/echo_canceller3.h index a828d5712b..f346f189bf 100644 --- a/modules/audio_processing/aec3/echo_canceller3.h +++ b/modules/audio_processing/aec3/echo_canceller3.h @@ -124,6 +124,11 @@ class EchoCanceller3 : public EchoControl { block_processor_->UpdateEchoLeakageStatus(leakage_detected); } + // Produces a default configuration that is suitable for a certain combination + // of render and capture channels. + static EchoCanceller3Config CreateDefaultConfig(size_t num_render_channels, + size_t num_capture_channels); + private: class RenderWriter; diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc index 0e375c9b9b..3e49c0cb76 100644 --- a/modules/audio_processing/audio_processing_impl.cc +++ b/modules/audio_processing/audio_processing_impl.cc @@ -75,6 +75,14 @@ bool DetectLegacyNsEnforcement() { return field_trial::IsEnabled("WebRTC-NewNoiseSuppressionKillSwitch"); } +// Checks whether AEC3 should be allowed to decide what the default +// configuration should be based on the render and capture channel configuration +// at hand. +bool UseSetupSpecificDefaultAec3Congfig() { + return !field_trial::IsEnabled( + "WebRTC-Aec3SetupSpecificDefaultConfigDefaultsKillSwitch"); +} + // Identify the native processing rate that best handles a sample rate. int SuitableProcessRate(int minimum_rate, int max_splitting_rate, @@ -312,6 +320,8 @@ AudioProcessingImpl::AudioProcessingImpl( : data_dumper_( new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))), enforced_usage_of_legacy_ns_(DetectLegacyNsEnforcement()), + use_setup_specific_default_aec3_config_( + UseSetupSpecificDefaultAec3Congfig()), capture_runtime_settings_(kRuntimeSettingQueueSize), render_runtime_settings_(kRuntimeSettingQueueSize), capture_runtime_settings_enqueuer_(&capture_runtime_settings_), @@ -1826,8 +1836,13 @@ void AudioProcessingImpl::InitializeEchoController() { proc_sample_rate_hz(), num_reverse_channels(), num_proc_channels()); RTC_DCHECK(submodules_.echo_controller); } else { + EchoCanceller3Config config = + use_setup_specific_default_aec3_config_ + ? EchoCanceller3::CreateDefaultConfig(num_reverse_channels(), + num_proc_channels()) + : EchoCanceller3Config(); submodules_.echo_controller = std::make_unique( - EchoCanceller3Config(), proc_sample_rate_hz(), num_reverse_channels(), + config, proc_sample_rate_hz(), num_reverse_channels(), num_proc_channels()); } diff --git a/modules/audio_processing/audio_processing_impl.h b/modules/audio_processing/audio_processing_impl.h index 5f1d12ff32..e5d0573e12 100644 --- a/modules/audio_processing/audio_processing_impl.h +++ b/modules/audio_processing/audio_processing_impl.h @@ -153,6 +153,7 @@ class AudioProcessingImpl : public AudioProcessing { std::unique_ptr data_dumper_; static int instance_count_; const bool enforced_usage_of_legacy_ns_; + const bool use_setup_specific_default_aec3_config_; SwapQueue capture_runtime_settings_; SwapQueue render_runtime_settings_;