Bounding the AEC3 suppression gain for poorly estimated residual echoes
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 <gustaf@webrtc.org>
Commit-Queue: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20081}
diff --git a/modules/audio_processing/aec3/suppression_gain.cc b/modules/audio_processing/aec3/suppression_gain.cc
index 0bed664..83ae63c 100644
--- a/modules/audio_processing/aec3/suppression_gain.cc
+++ b/modules/audio_processing/aec3/suppression_gain.cc
@@ -192,6 +192,9 @@
}
}
+// 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<float, kFftLengthBy2Plus1>& nearend,
@@ -205,11 +208,31 @@
(*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<float, kFftLengthBy2Plus1>* gain) {
+ constexpr float oneByBandsInSum =
+ 1 / static_cast<float>(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 @@
}
}
+ // 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_);