Pre echo delay estimator: Explicitly considering the initial region when updating the pre echo delay histogram.

Bug: webrtc:14205
Change-Id: Iaa075a52c07ab87fe21da7c40be806c7f80f0e32
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/280540
Reviewed-by: Lionel Koenig <lionelk@webrtc.org>
Reviewed-by: Lionel Koenig <lionelk@google.com>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Jesus de Vicente Pena <devicentepena@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38489}
This commit is contained in:
Jesús de Vicente Peña
2022-10-27 12:19:14 +02:00
committed by WebRTC LUCI CQ
parent f36d607c4a
commit bb4ccf8495
2 changed files with 8 additions and 6 deletions

View File

@ -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<RenderDelayBuffer> render_delay_buffer(
RenderDelayBuffer::Create(config, kSampleRateHz, kNumRenderChannels));

View File

@ -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<int>(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;