Chromium Code Reviews

Unified Diff: webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.cc

Issue 2678423005: Finalization of the first version of EchoCanceller 3 (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.cc
diff --git a/webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.cc b/webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3268df546b7af2ccf6916043f7e85380c0479577
--- /dev/null
+++ b/webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.cc
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.h"
+
+#include <algorithm>
+#include <functional>
+
+#include "webrtc/base/checks.h"
+#include "webrtc/modules/audio_processing/aec3/aec3_constants.h"
+
+namespace webrtc {
+
+void ShadowFilterUpdateGain::Compute(
+ const FftBuffer& X_buffer,
+ const RenderSignalAnalyzer& render_signal_analyzer,
+ const FftData& E_shadow,
+ size_t size_partitions,
+ bool saturated_capture_signal,
+ FftData* G) {
+ ++call_counter_;
+
+ if (render_signal_analyzer.PoorSignalExcitation()) {
+ poor_signal_excitation_counter_ = 0;
+ }
+
+ // Do not update the filter if the render is not sufficiently persistently
hlundin-webrtc 2017/02/13 21:37:01 "sufficiently persistently"?
peah-webrtc 2017/02/20 07:37:19 Done.
+ // exciting.
+ if (++poor_signal_excitation_counter_ < size_partitions ||
+ saturated_capture_signal || call_counter_ <= size_partitions) {
+ G->re.fill(0.f);
+ G->im.fill(0.f);
+ return;
+ }
+
+ // Compute mu.
+ constexpr float kX2Min = 44015068.0f;
+ constexpr float kMuFixed = .5f;
+ std::array<float, kFftLengthBy2Plus1> mu;
+ const std::array<float, kFftLengthBy2Plus1>& X2 =
hlundin-webrtc 2017/02/13 21:37:01 const auto& ?
peah-webrtc 2017/02/20 07:37:18 Done.
+ X_buffer.SpectralSum(size_partitions);
+ std::transform(X2.begin(), X2.end(), mu.begin(),
+ [&](float a) { return a > kX2Min ? kMuFixed / a : 0.f; });
+
+ // Avoid updating the filter close to narrow bands in the render signals.
+ render_signal_analyzer.MaskRegionsAroundNarrowBands(&mu);
+
+ // G = mu * E * X2.
+ std::transform(mu.begin(), mu.end(), E_shadow.re.begin(), G->re.begin(),
+ std::multiplies<float>());
+ std::transform(mu.begin(), mu.end(), E_shadow.im.begin(), G->im.begin(),
+ std::multiplies<float>());
+}
+
+} // namespace webrtc

Powered by Google App Engine