From 895ae9a0cdff3f174c08d3f23b7ee4170cf34ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Thu, 15 Mar 2018 16:31:27 +0100 Subject: [PATCH] Improving the speed of the delay estimator in AEC3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL significantly improves the response time of the AEC3 delay estimator to audio buffer issues. The CL adds ensures that the delay estimator correlators reacts to buffer issues from the zero state which is much faster than if it has already achieved a state matching a previous alignment. The CL has been extensively tested on offline recordings. Bug: webrtc:9023, chromium:822245 Change-Id: Ic149b9429e592d4c3535eb8432582f435a1b4745 Reviewed-on: https://webrtc-review.googlesource.com/62081 Commit-Queue: Per Ã…hgren Reviewed-by: Ivo Creusen Cr-Commit-Position: refs/heads/master@{#22461} --- .../aec3/echo_path_delay_estimator.cc | 15 +++++++++++++++ .../aec3/echo_path_delay_estimator.h | 2 ++ .../aec3/echo_path_delay_estimator_unittest.cc | 6 +++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/audio_processing/aec3/echo_path_delay_estimator.cc b/modules/audio_processing/aec3/echo_path_delay_estimator.cc index 21c3d193f8..0026522d53 100644 --- a/modules/audio_processing/aec3/echo_path_delay_estimator.cc +++ b/modules/audio_processing/aec3/echo_path_delay_estimator.cc @@ -48,6 +48,8 @@ void EchoPathDelayEstimator::Reset(bool soft_reset) { matched_filter_lag_aggregator_.Reset(); } matched_filter_.Reset(); + old_aggregated_lag_ = rtc::nullopt; + consistent_estimate_counter_ = 0; } rtc::Optional EchoPathDelayEstimator::EstimateDelay( @@ -84,6 +86,19 @@ rtc::Optional EchoPathDelayEstimator::EstimateDelay( if (aggregated_matched_filter_lag) { aggregated_matched_filter_lag->delay *= down_sampling_factor_; } + + if (old_aggregated_lag_ && aggregated_matched_filter_lag && + old_aggregated_lag_->delay == aggregated_matched_filter_lag->delay) { + ++consistent_estimate_counter_; + } else { + consistent_estimate_counter_ = 0; + } + old_aggregated_lag_ = aggregated_matched_filter_lag; + constexpr size_t kNumBlocksPerSecondBy2 = kNumBlocksPerSecond / 2; + if (consistent_estimate_counter_ > kNumBlocksPerSecondBy2) { + Reset(true); + } + return aggregated_matched_filter_lag; } diff --git a/modules/audio_processing/aec3/echo_path_delay_estimator.h b/modules/audio_processing/aec3/echo_path_delay_estimator.h index 3277f198a1..6389098102 100644 --- a/modules/audio_processing/aec3/echo_path_delay_estimator.h +++ b/modules/audio_processing/aec3/echo_path_delay_estimator.h @@ -55,6 +55,8 @@ class EchoPathDelayEstimator { Decimator capture_decimator_; MatchedFilter matched_filter_; MatchedFilterLagAggregator matched_filter_lag_aggregator_; + rtc::Optional old_aggregated_lag_; + size_t consistent_estimate_counter_ = 0; RTC_DISALLOW_COPY_AND_ASSIGN(EchoPathDelayEstimator); }; diff --git a/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc b/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc index acd7993782..38f31c9ea6 100644 --- a/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc +++ b/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc @@ -84,8 +84,12 @@ TEST(EchoPathDelayEstimator, DelayEstimation) { render_delay_buffer->PrepareCaptureProcessing(); - estimated_delay_samples = estimator.EstimateDelay( + auto estimate = estimator.EstimateDelay( render_delay_buffer->GetDownsampledRenderBuffer(), capture); + + if (estimate) { + estimated_delay_samples = estimate; + } } if (estimated_delay_samples) {