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;