From a2376e7db6b6c7b8fbe070fe7e277e476361d3ff Mon Sep 17 00:00:00 2001 From: peah Date: Mon, 27 Feb 2017 01:15:24 -0800 Subject: [PATCH] Added post-adjustment of the suppression gains This CL adds correction of the echo suppressor gain It contains 2 changes: -Bounds the upper value for the echo suppression gain for bin 1 to avoid that the high-pass filter causes the gain to be high for bin 1, which in turn may impact the realization of any lower gains for the neighboring bins. -Bounds the upper values for the echo suppression gains for the higher bins to avoid any impact of the external anti-aliasing filters. BUG=webrtc:6018 Review-Url: https://codereview.webrtc.org/2718993002 Cr-Commit-Position: refs/heads/master@{#16854} --- .../aec3/suppression_filter.cc | 11 ++----- .../audio_processing/aec3/suppression_gain.cc | 29 ++++++++++++++++--- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/webrtc/modules/audio_processing/aec3/suppression_filter.cc b/webrtc/modules/audio_processing/aec3/suppression_filter.cc index 358aafbdfb..3b830a612e 100644 --- a/webrtc/modules/audio_processing/aec3/suppression_filter.cc +++ b/webrtc/modules/audio_processing/aec3/suppression_filter.cc @@ -138,17 +138,12 @@ void SuppressionFilter::ApplyGain( fft_.Ifft(E, &time_domain_high_band_noise); // Scale and apply the noise to the signals. - // TODO(peah): Ensure that the high bands are properly delayed. - constexpr int kNumBandsAveragingUpperGain = kFftLengthBy2 / 4; - constexpr float kOneByNumBandsAveragingUpperGain = - 1.f / kNumBandsAveragingUpperGain; + RTC_DCHECK_LT(3, suppression_gain.size()); float high_bands_gain = - std::accumulate(suppression_gain.end() - kNumBandsAveragingUpperGain, - suppression_gain.end(), 0.f) * - kOneByNumBandsAveragingUpperGain; + *std::min_element(suppression_gain.begin() + 3, suppression_gain.end()); float high_bands_noise_scaling = - 0.4f * std::max(1.f - high_bands_gain * high_bands_gain, 0.f); + 0.4f * std::max(1.f - high_bands_gain, 0.f); std::transform( (*e)[1].begin(), (*e)[1].end(), time_domain_high_band_noise.begin(), diff --git a/webrtc/modules/audio_processing/aec3/suppression_gain.cc b/webrtc/modules/audio_processing/aec3/suppression_gain.cc index 34bb9cb390..aa37e8cdbd 100644 --- a/webrtc/modules/audio_processing/aec3/suppression_gain.cc +++ b/webrtc/modules/audio_processing/aec3/suppression_gain.cc @@ -21,6 +21,25 @@ namespace webrtc { namespace { +void GainPostProcessing(std::array* gain_squared) { + // Limit the low frequency gains to avoid the impact of the high-pass filter + // on the lower-frequency gain influencing the overall achieved gain. + (*gain_squared)[1] = std::min((*gain_squared)[1], (*gain_squared)[2]); + (*gain_squared)[0] = (*gain_squared)[1]; + + // Limit the high frequency gains to avoid the impact of the anti-aliasing + // filter on the upper-frequency gains influencing the overall achieved + // gain. TODO(peah): Update this when new anti-aliasing filters are + // implemented. + constexpr size_t kAntiAliasingImpactLimit = 64 * 0.7f; + std::for_each(gain_squared->begin() + kAntiAliasingImpactLimit, + gain_squared->end(), + [gain_squared, kAntiAliasingImpactLimit](float& a) { + a = std::min(a, (*gain_squared)[kAntiAliasingImpactLimit]); + }); + (*gain_squared)[kFftLengthBy2] = (*gain_squared)[kFftLengthBy2Minus1]; +} + constexpr int kNumIterations = 2; constexpr float kEchoMaskingMargin = 1.f / 10.f; constexpr float kBandMaskingFactor = 1.f / 2.f; @@ -120,8 +139,9 @@ void ComputeGains_SSE2( : std::min(a, b * 2.f); }); - (*gain_squared)[0] = (*gain_squared)[1]; - (*gain_squared)[kFftLengthBy2] = (*gain_squared)[kFftLengthBy2Minus1]; + // Process the gains to avoid artefacts caused by gain realization in the + // filterbank and impact of external pre-processing of the signal. + GainPostProcessing(gain_squared); } std::copy(gain_squared->begin() + 1, gain_squared->end() - 1, @@ -231,8 +251,9 @@ void ComputeGains( : std::min(a, b * 2.f); }); - (*gain_squared)[0] = (*gain_squared)[1]; - (*gain_squared)[kFftLengthBy2] = (*gain_squared)[kFftLengthBy2Minus1]; + // Process the gains to avoid artefacts caused by gain realization in the + // filterbank and impact of external pre-processing of the signal. + GainPostProcessing(gain_squared); } std::copy(gain_squared->begin() + 1, gain_squared->end() - 1,