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

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

Issue 2644123002: Adding full initial version of delay estimation functionality in echo canceller 3 (Closed)
Patch Set: Rebase Created 3 years, 10 months 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/matched_filter_lag_aggregator.cc
diff --git a/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc b/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d9176efa94fbd76f6d2fbbffa121e7ba2f68e54d
--- /dev/null
+++ b/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc
@@ -0,0 +1,66 @@
+/*
+ * 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/matched_filter_lag_aggregator.h"
+
+#include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
+
+namespace webrtc {
+
+MatchedFilterLagAggregator::MatchedFilterLagAggregator(
+ ApmDataDumper* data_dumper,
+ size_t num_lag_estimates)
+ : data_dumper_(data_dumper), lag_updates_in_a_row_(num_lag_estimates, 0) {
+ RTC_DCHECK(data_dumper);
+ RTC_DCHECK_LT(0, num_lag_estimates);
+}
+
+MatchedFilterLagAggregator::~MatchedFilterLagAggregator() = default;
+
+rtc::Optional<size_t> MatchedFilterLagAggregator::Aggregate(
+ rtc::ArrayView<const MatchedFilter::LagEstimate> lag_estimates) {
+ RTC_DCHECK_EQ(lag_updates_in_a_row_.size(), lag_estimates.size());
+
+ // Count the number of lag updates in a row to ensure that only stable lags
+ // are taken into account.
+ for (size_t k = 0; k < lag_estimates.size(); ++k) {
+ lag_updates_in_a_row_[k] =
+ lag_estimates[k].updated ? lag_updates_in_a_row_[k] + 1 : 0;
+ }
+
+ // If available, choose the strongest lag estimate as the best one.
+ int best_lag_estimate_index = -1;
+ for (size_t k = 0; k < lag_estimates.size(); ++k) {
+ if (lag_updates_in_a_row_[k] > 10 && lag_estimates[k].reliable &&
+ (best_lag_estimate_index == -1 ||
+ lag_estimates[k].accuracy >
+ lag_estimates[best_lag_estimate_index].accuracy)) {
+ best_lag_estimate_index = k;
+ }
+ }
+
+ // TODO(peah): Remove this logging once all development is done.
+ data_dumper_->DumpRaw("aec3_echo_path_delay_estimator_best_index",
+ best_lag_estimate_index);
+
+ // Require the same lag to be detected 10 times in a row before considering
+ // it reliable.
+ if (best_lag_estimate_index >= 0) {
+ candidate_counter_ =
+ (candidate_ == lag_estimates[best_lag_estimate_index].lag)
+ ? candidate_counter_ + 1
+ : 0;
+ candidate_ = lag_estimates[best_lag_estimate_index].lag;
+ }
+
+ return candidate_counter_ >= 10 ? rtc::Optional<size_t>(candidate_)
+ : rtc::Optional<size_t>();
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698