From bb4ccf8495deedae954bff6b1ce75608aa723051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20de=20Vicente=20Pe=C3=B1a?= Date: Thu, 27 Oct 2022 12:19:14 +0200 Subject: [PATCH] Pre echo delay estimator: Explicitly considering the initial region when updating the pre echo delay histogram. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:14205 Change-Id: Iaa075a52c07ab87fe21da7c40be806c7f80f0e32 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/280540 Reviewed-by: Lionel Koenig Reviewed-by: Lionel Koenig Reviewed-by: Per Ã…hgren Commit-Queue: Jesus de Vicente Pena Cr-Commit-Position: refs/heads/main@{#38489} --- .../aec3/echo_path_delay_estimator_unittest.cc | 5 +---- .../aec3/matched_filter_lag_aggregator.cc | 9 +++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) 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 ae9c8736ae..e2c101fb04 100644 --- a/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc +++ b/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc @@ -70,7 +70,7 @@ TEST(EchoPathDelayEstimator, DelayEstimation) { constexpr size_t kNumCaptureChannels = 1; constexpr int kSampleRateHz = 48000; constexpr size_t kNumBands = NumBandsForRate(kSampleRateHz); - + Random random_generator(42U); Block render(kNumBands, kNumRenderChannels); Block capture(/*num_bands=*/1, kNumCaptureChannels); ApmDataDumper data_dumper(0); @@ -81,9 +81,6 @@ TEST(EchoPathDelayEstimator, DelayEstimation) { config.delay.down_sampling_factor = down_sampling_factor; config.delay.num_filters = 10; for (size_t delay_samples : {30, 64, 150, 200, 800, 4000}) { - // Random generator become periodic after a while. To avoid issue in the - // unittest we ensure to seed it for every case. - Random random_generator(42U); SCOPED_TRACE(ProduceDebugText(delay_samples, down_sampling_factor)); std::unique_ptr render_delay_buffer( RenderDelayBuffer::Create(config, kSampleRateHz, kNumRenderChannels)); diff --git a/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc b/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc index 17f517a001..bea7868a91 100644 --- a/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc +++ b/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc @@ -18,6 +18,8 @@ namespace webrtc { namespace { +constexpr int kPreEchoHistogramDataNotUpdated = -1; + int GetDownSamplingBlockSizeLog2(int down_sampling_factor) { int down_sampling_factor_log2 = 0; down_sampling_factor >>= 1; @@ -129,7 +131,7 @@ MatchedFilterLagAggregator::PreEchoLagAggregator::PreEchoLagAggregator( void MatchedFilterLagAggregator::PreEchoLagAggregator::Reset() { std::fill(histogram_.begin(), histogram_.end(), 0); - histogram_data_.fill(0); + histogram_data_.fill(kPreEchoHistogramDataNotUpdated); histogram_data_index_ = 0; pre_echo_candidate_ = 0; } @@ -141,7 +143,10 @@ void MatchedFilterLagAggregator::PreEchoLagAggregator::Aggregate( pre_echo_block_size < static_cast(histogram_.size())); pre_echo_block_size = rtc::SafeClamp(pre_echo_block_size, 0, histogram_.size() - 1); - if (histogram_[histogram_data_[histogram_data_index_]] > 0) { + // Remove the oldest point from the `histogram_`, it ignores the initial + // points where no updates have been done to the `histogram_data_` array. + if (histogram_data_[histogram_data_index_] != + kPreEchoHistogramDataNotUpdated) { --histogram_[histogram_data_[histogram_data_index_]]; } histogram_data_[histogram_data_index_] = pre_echo_block_size;