From 85a11a35f176927cddc82a6a2af9072a338cb9e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Mon, 2 Oct 2017 14:42:06 +0200 Subject: [PATCH] Bounding the AEC3 suppression gain for poorly estimated residual echoes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL bounds the supppression gain for higher frequencies where the estimate of the residual echo sometimes is less accurate. Bug: webrtc:8320 Change-Id: I02b21e6b1758c7e8b6660c1631a05c956a45e4c8 Reviewed-on: https://webrtc-review.googlesource.com/5260 Reviewed-by: Gustaf Ullberg Commit-Queue: Per Ã…hgren Cr-Commit-Position: refs/heads/master@{#20081} --- .../audio_processing/aec3/suppression_gain.cc | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/audio_processing/aec3/suppression_gain.cc b/modules/audio_processing/aec3/suppression_gain.cc index 0bed664584..83ae63c95e 100644 --- a/modules/audio_processing/aec3/suppression_gain.cc +++ b/modules/audio_processing/aec3/suppression_gain.cc @@ -192,6 +192,9 @@ void GainToNoAudibleEcho( } } +// TODO(peah): Make adaptive to take the actual filter error into account. +constexpr size_t kUpperAccurateBandPlus1 = 29; + // Computes the signal output power that masks the echo signal. void MaskingPower(const AudioProcessing::Config::EchoCanceller3& config, const std::array& nearend, @@ -205,11 +208,31 @@ void MaskingPower(const AudioProcessing::Config::EchoCanceller3& config, (*masker)[k] = comfort_noise[k] + config.param.gain_mask.m4 * last_masker[k]; } - for (size_t k = 1; k < gain.size() - 1; ++k) { + + // Apply masking only between lower frequency bands. + RTC_DCHECK_LT(kUpperAccurateBandPlus1, gain.size()); + for (size_t k = 1; k < kUpperAccurateBandPlus1; ++k) { (*masker)[k] += 0.1f * (side_band_masker[k - 1] + side_band_masker[k + 1]); } } +// Limits the gain in the frequencies for which the adaptive filter has not +// converged. Currently, these frequencies are not hardcoded to the frequencies +// which are typically not excited by speech. +// TODO(peah): Make adaptive to take the actual filter error into account. +void AdjustNonConvergedFrequencies( + std::array* gain) { + constexpr float oneByBandsInSum = + 1 / static_cast(kUpperAccurateBandPlus1 - 20); + const float hf_gain_bound = + std::accumulate(gain->begin() + 20, + gain->begin() + kUpperAccurateBandPlus1, 0.f) * + oneByBandsInSum; + + std::for_each(gain->begin() + kUpperAccurateBandPlus1, gain->end(), + [hf_gain_bound](float& a) { a = std::min(a, hf_gain_bound); }); +} + } // namespace // TODO(peah): Add further optimizations, in particular for the divisions. @@ -270,6 +293,9 @@ void SuppressionGain::LowerBandGain( } } + // Adjust the gain for frequencies which have not yet converged. + AdjustNonConvergedFrequencies(gain); + // Update the allowed maximum gain increase. UpdateMaxGainIncrease(config_, no_saturation_counter_, low_noise_render, last_echo_, echo, last_gain_, *gain, &gain_increase_);