From 17e4c58318b4c05100551e274f879cbc0c8248d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Wed, 27 Nov 2019 08:13:24 +0100 Subject: [PATCH] Adding parametrization of the AEC3 howling mitigation behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:8671,b/145243047 Change-Id: If5bcbb66b72278b901a990cb9d6e11e42c9ac592 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160781 Reviewed-by: Gustaf Ullberg Commit-Queue: Per Ã…hgren Cr-Commit-Position: refs/heads/master@{#29930} --- api/audio/echo_canceller3_config.cc | 5 +++++ api/audio/echo_canceller3_config.h | 2 ++ api/audio/echo_canceller3_config_json.cc | 13 ++++++++++++- modules/audio_processing/aec3/suppression_gain.cc | 10 +++++++--- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/api/audio/echo_canceller3_config.cc b/api/audio/echo_canceller3_config.cc index 27308e6bab..f1d8881c76 100644 --- a/api/audio/echo_canceller3_config.cc +++ b/api/audio/echo_canceller3_config.cc @@ -234,6 +234,11 @@ bool EchoCanceller3Config::Validate(EchoCanceller3Config* config) { 1000000.f); res = res & Limit(&c->suppressor.high_bands_suppression.max_gain_during_echo, 0.f, 1.f); + res = res & Limit(&c->suppressor.high_bands_suppression + .anti_howling_activation_threshold, + 0.f, 32768.f * 32768.f); + res = res & Limit(&c->suppressor.high_bands_suppression.anti_howling_gain, + 0.f, 1.f); res = res & Limit(&c->suppressor.floor_first_increase, 0.f, 1000000.f); diff --git a/api/audio/echo_canceller3_config.h b/api/audio/echo_canceller3_config.h index 1e33f287bc..dddc220d3b 100644 --- a/api/audio/echo_canceller3_config.h +++ b/api/audio/echo_canceller3_config.h @@ -197,6 +197,8 @@ struct RTC_EXPORT EchoCanceller3Config { struct HighBandsSuppression { float enr_threshold = 1.f; float max_gain_during_echo = 1.f; + float anti_howling_activation_threshold = 25.f; + float anti_howling_gain = 0.01f; } high_bands_suppression; float floor_first_increase = 0.00001f; diff --git a/api/audio/echo_canceller3_config_json.cc b/api/audio/echo_canceller3_config_json.cc index f6b969281f..40f975a1f1 100644 --- a/api/audio/echo_canceller3_config_json.cc +++ b/api/audio/echo_canceller3_config_json.cc @@ -349,6 +349,11 @@ void Aec3ConfigFromJsonString(absl::string_view json_string, &cfg.suppressor.high_bands_suppression.enr_threshold); ReadParam(subsection, "max_gain_during_echo", &cfg.suppressor.high_bands_suppression.max_gain_during_echo); + ReadParam(subsection, "anti_howling_activation_threshold", + &cfg.suppressor.high_bands_suppression + .anti_howling_activation_threshold); + ReadParam(subsection, "anti_howling_gain", + &cfg.suppressor.high_bands_suppression.anti_howling_gain); } ReadParam(section, "floor_first_increase", @@ -602,7 +607,13 @@ std::string Aec3ConfigToJsonString(const EchoCanceller3Config& config) { ost << "\"enr_threshold\": " << config.suppressor.high_bands_suppression.enr_threshold << ","; ost << "\"max_gain_during_echo\": " - << config.suppressor.high_bands_suppression.max_gain_during_echo; + << config.suppressor.high_bands_suppression.max_gain_during_echo << ","; + ost << "\"anti_howling_activation_threshold\": " + << config.suppressor.high_bands_suppression + .anti_howling_activation_threshold + << ","; + ost << "\"anti_howling_gain\": " + << config.suppressor.high_bands_suppression.anti_howling_gain; ost << "},"; ost << "\"floor_first_increase\": " << config.suppressor.floor_first_increase; ost << "}"; diff --git a/modules/audio_processing/aec3/suppression_gain.cc b/modules/audio_processing/aec3/suppression_gain.cc index 71f6664ebf..ea7af505e0 100644 --- a/modules/audio_processing/aec3/suppression_gain.cc +++ b/modules/audio_processing/aec3/suppression_gain.cc @@ -151,14 +151,18 @@ float SuppressionGain::UpperBandsGain( // or if the power in upper frequencies is low, do not bound the gain in the // upper bands. float anti_howling_gain; - constexpr float kThreshold = kBlockSize * 10.f * 10.f / 4.f; - if (high_band_energy < std::max(low_band_energy, kThreshold)) { + const float activation_threshold = + kBlockSize * config_.suppressor.high_bands_suppression + .anti_howling_activation_threshold; + if (high_band_energy < std::max(low_band_energy, activation_threshold)) { anti_howling_gain = 1.f; } else { // In all other cases, bound the gain for upper frequencies. RTC_DCHECK_LE(low_band_energy, high_band_energy); RTC_DCHECK_NE(0.f, high_band_energy); - anti_howling_gain = 0.01f * sqrtf(low_band_energy / high_band_energy); + anti_howling_gain = + config_.suppressor.high_bands_suppression.anti_howling_gain * + sqrtf(low_band_energy / high_band_energy); } float gain_bound = 1.f;