blob: 79e5465e3cd87b4a6e81b59c15437c5e6bec238e [file] [log] [blame]
peah522d71b2017-02-23 13:16:261/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 04:47:3111#include "modules/audio_processing/aec3/erl_estimator.h"
peah522d71b2017-02-23 13:16:2612
Sam Zackrisson6e5433c2019-10-18 14:49:1313#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3114#include "test/gtest.h"
peah522d71b2017-02-23 13:16:2615
16namespace webrtc {
17
18namespace {
Sam Zackrisson6e5433c2019-10-18 14:49:1319std::string ProduceDebugText(size_t num_render_channels,
20 size_t num_capture_channels) {
21 rtc::StringBuilder ss;
22 ss << "Render channels: " << num_render_channels;
23 ss << ", Capture channels: " << num_capture_channels;
24 return ss.Release();
25}
peah522d71b2017-02-23 13:16:2626
27void VerifyErl(const std::array<float, kFftLengthBy2Plus1>& erl,
Gustaf Ullbergfe4d6732017-11-16 08:31:2728 float erl_time_domain,
peah522d71b2017-02-23 13:16:2629 float reference) {
30 std::for_each(erl.begin(), erl.end(),
31 [reference](float a) { EXPECT_NEAR(reference, a, 0.001); });
Gustaf Ullbergfe4d6732017-11-16 08:31:2732 EXPECT_NEAR(reference, erl_time_domain, 0.001);
peah522d71b2017-02-23 13:16:2633}
34
35} // namespace
36
Sam Zackrissonb18c4eb2020-01-24 11:55:1737class ErlEstimatorMultiChannel
38 : public ::testing::Test,
39 public ::testing::WithParamInterface<std::tuple<size_t, size_t>> {};
40
41INSTANTIATE_TEST_SUITE_P(MultiChannel,
42 ErlEstimatorMultiChannel,
43 ::testing::Combine(::testing::Values(1, 2, 8),
44 ::testing::Values(1, 2, 8)));
45
peah522d71b2017-02-23 13:16:2646// Verifies that the correct ERL estimates are achieved.
Sam Zackrissonb18c4eb2020-01-24 11:55:1747TEST_P(ErlEstimatorMultiChannel, Estimates) {
48 const size_t num_render_channels = std::get<0>(GetParam());
49 const size_t num_capture_channels = std::get<1>(GetParam());
50 SCOPED_TRACE(ProduceDebugText(num_render_channels, num_capture_channels));
51 std::vector<std::array<float, kFftLengthBy2Plus1>> X2(num_render_channels);
52 for (auto& X2_ch : X2) {
53 X2_ch.fill(0.f);
peah522d71b2017-02-23 13:16:2654 }
Sam Zackrissonb18c4eb2020-01-24 11:55:1755 std::vector<std::array<float, kFftLengthBy2Plus1>> Y2(num_capture_channels);
56 for (auto& Y2_ch : Y2) {
57 Y2_ch.fill(0.f);
58 }
59 std::vector<bool> converged_filters(num_capture_channels, false);
60 const size_t converged_idx = num_capture_channels - 1;
61 converged_filters[converged_idx] = true;
peah522d71b2017-02-23 13:16:2662
Sam Zackrissonb18c4eb2020-01-24 11:55:1763 ErlEstimator estimator(0);
64
65 // Verifies that the ERL estimate is properly reduced to lower values.
66 for (auto& X2_ch : X2) {
67 X2_ch.fill(500 * 1000.f * 1000.f);
68 }
69 Y2[converged_idx].fill(10 * X2[0][0]);
70 for (size_t k = 0; k < 200; ++k) {
71 estimator.Update(converged_filters, X2, Y2);
72 }
73 VerifyErl(estimator.Erl(), estimator.ErlTimeDomain(), 10.f);
74
75 // Verifies that the ERL is not immediately increased when the ERL in the
76 // data increases.
77 Y2[converged_idx].fill(10000 * X2[0][0]);
78 for (size_t k = 0; k < 998; ++k) {
79 estimator.Update(converged_filters, X2, Y2);
80 }
81 VerifyErl(estimator.Erl(), estimator.ErlTimeDomain(), 10.f);
82
83 // Verifies that the rate of increase is 3 dB.
84 estimator.Update(converged_filters, X2, Y2);
85 VerifyErl(estimator.Erl(), estimator.ErlTimeDomain(), 20.f);
86
87 // Verifies that the maximum ERL is achieved when there are no low RLE
88 // estimates.
89 for (size_t k = 0; k < 1000; ++k) {
90 estimator.Update(converged_filters, X2, Y2);
91 }
92 VerifyErl(estimator.Erl(), estimator.ErlTimeDomain(), 1000.f);
93
94 // Verifies that the ERL estimate is is not updated for low-level signals
95 for (auto& X2_ch : X2) {
96 X2_ch.fill(1000.f * 1000.f);
97 }
98 Y2[converged_idx].fill(10 * X2[0][0]);
99 for (size_t k = 0; k < 200; ++k) {
100 estimator.Update(converged_filters, X2, Y2);
101 }
102 VerifyErl(estimator.Erl(), estimator.ErlTimeDomain(), 1000.f);
103}
peah522d71b2017-02-23 13:16:26104} // namespace webrtc