Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1850)

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

Issue 2584493002: Added first layer of the echo canceller 3 functionality (Closed)
Patch Set: Restricted the AnalyzeRender access, added ability to add external reporting of echo failure, and o… Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.cc
diff --git a/webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.cc b/webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..539cdf15a108019ebc3a3e7ec2780218388117d0
--- /dev/null
+++ b/webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.cc
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2016 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/cascaded_biquad_filter.h"
+
+#include "webrtc/base/checks.h"
+
+namespace webrtc {
+
+void CascadedBiQuadFilter::Process(rtc::ArrayView<const float> x,
+ rtc::ArrayView<float> y) {
+ ApplyBiQuad(x, y, &biquad_states_[0]);
+ for (size_t k = 1; k < biquad_states_.size(); ++k) {
+ ApplyBiQuad(y, y, &biquad_states_[k]);
+ }
+}
+
+void CascadedBiQuadFilter::Process(rtc::ArrayView<float> y) {
+ for (auto& biquad : biquad_states_) {
+ ApplyBiQuad(y, y, &biquad);
+ }
+}
+
+CascadedBiQuadFilter::CascadedBiQuadFilter(
hlundin-webrtc 2016/12/16 10:04:46 Order of methods is not the same as in h-file. Mov
peah-webrtc 2016/12/20 10:10:24 Done.
+ const CascadedBiQuadFilter::BiQuadCoefficients& coefficients,
+ size_t num_biquads)
+ : num_biquads_(num_biquads),
+ biquad_states_(num_biquads_),
+ coefficients_(coefficients) {
+ for (auto& biquad_state : biquad_states_) {
+ biquad_state.a[0] = biquad_state.a[1] = 0;
hlundin-webrtc 2016/12/16 10:04:46 Probably doesn't matter, but 0.f.
ivoc 2016/12/19 11:30:21 Is it possible to do this initialization in the he
peah-webrtc 2016/12/20 10:10:24 Done.
peah-webrtc 2016/12/20 10:10:24 Not as far as I can see. Afaics brace initializati
ivoc 2016/12/21 13:04:04 Acknowledged.
peah-webrtc 2016/12/21 23:13:48 Acknowledged.
+ biquad_state.b[0] = biquad_state.b[1] = 0;
hlundin-webrtc 2016/12/16 10:04:46 0.f
peah-webrtc 2016/12/20 10:10:24 Done.
+ }
+}
+
+CascadedBiQuadFilter::~CascadedBiQuadFilter() {}
+
+void CascadedBiQuadFilter::ApplyBiQuad(
+ rtc::ArrayView<const float> x,
+ rtc::ArrayView<float> y,
+ CascadedBiQuadFilter::BiQuadState* biquad_state) {
+ const auto coefficients_b = coefficients_.b;
hlundin-webrtc 2016/12/16 10:04:46 Since you are introducing these local variables to
peah-webrtc 2016/12/20 10:10:24 Done.
+ const auto coefficients_a = coefficients_.a;
+ auto memory_b = biquad_state->b;
hlundin-webrtc 2016/12/16 10:04:46 Following the notation of https://en.wikipedia.org
peah-webrtc 2016/12/20 10:10:24 I'll change to _x and _y. I think that since we an
hlundin-webrtc 2016/12/20 15:10:34 Acknowledged.
peah-webrtc 2016/12/21 23:13:48 Acknowledged.
+ auto memory_a = biquad_state->a;
+ for (size_t k = 0; k < x.size(); ++k) {
+ const float tmp = x[k];
+ y[k] = coefficients_b[0] * tmp + coefficients_b[1] * memory_b[0] +
+ coefficients_b[2] * memory_b[1] - coefficients_a[0] * memory_a[0] -
+ coefficients_a[1] * memory_a[1];
+ memory_b[1] = memory_b[0];
+ memory_b[0] = tmp;
+ memory_a[1] = memory_a[0];
+ memory_a[0] = y[k];
+ }
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698