OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_processing/aec3/power_echo_model.h" | 11 #include "webrtc/modules/audio_processing/aec3/power_echo_model.h" |
12 | 12 |
13 #include <array> | 13 #include <array> |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/random.h" | 17 #include "webrtc/base/random.h" |
18 #include "webrtc/modules/audio_processing/aec3/aec_state.h" | 18 #include "webrtc/modules/audio_processing/aec3/aec_state.h" |
19 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" | 19 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" |
20 #include "webrtc/modules/audio_processing/aec3/aec3_fft.h" | 20 #include "webrtc/modules/audio_processing/aec3/aec3_fft.h" |
21 #include "webrtc/modules/audio_processing/aec3/echo_path_variability.h" | 21 #include "webrtc/modules/audio_processing/aec3/echo_path_variability.h" |
22 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" | 22 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" |
23 | 23 |
24 #include "webrtc/test/gtest.h" | 24 #include "webrtc/test/gtest.h" |
25 | 25 |
26 namespace webrtc { | 26 namespace webrtc { |
27 namespace { | |
28 | |
29 std::string ProduceDebugText(size_t delay, bool known_delay) { | |
30 std::ostringstream ss; | |
31 ss << "True delay: " << delay; | |
32 ss << ", Delay known: " << (known_delay ? "true" : "false"); | |
33 return ss.str(); | |
34 } | |
35 | |
36 } // namespace | |
37 | 27 |
38 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 28 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
39 | 29 |
40 // Verifies that the check for non-null output parameter works. | 30 // Verifies that the check for non-null output parameter works. |
41 TEST(PowerEchoModel, NullEstimateEchoOutput) { | 31 TEST(PowerEchoModel, NullEstimateEchoOutput) { |
42 PowerEchoModel model; | 32 PowerEchoModel model; |
43 std::array<float, kFftLengthBy2Plus1> Y2; | 33 std::array<float, kFftLengthBy2Plus1> Y2; |
44 AecState aec_state; | 34 AecState aec_state; |
45 FftBuffer X_buffer(Aec3Optimization::kNone, model.MinFarendBufferLength(), | 35 RenderBuffer X_buffer(Aec3Optimization::kNone, model.MinFarendBufferLength(), |
46 std::vector<size_t>(1, model.MinFarendBufferLength())); | 36 std::vector<size_t>(1, model.MinFarendBufferLength())); |
47 | 37 |
48 EXPECT_DEATH(model.EstimateEcho(X_buffer, Y2, aec_state, nullptr), ""); | 38 EXPECT_DEATH(model.EstimateEcho(X_buffer, Y2, aec_state, nullptr), ""); |
49 } | 39 } |
50 | 40 |
51 #endif | 41 #endif |
52 | 42 |
53 TEST(PowerEchoModel, BasicSetup) { | |
54 PowerEchoModel model; | |
55 Random random_generator(42U); | |
56 AecState aec_state; | |
57 Aec3Fft fft; | |
58 std::array<float, kFftLengthBy2Plus1> Y2; | |
59 std::array<float, kFftLengthBy2Plus1> S2; | |
60 std::array<float, kFftLengthBy2Plus1> E2_main; | |
61 std::array<float, kFftLengthBy2Plus1> E2_shadow; | |
62 std::array<float, kBlockSize> x_old; | |
63 std::array<float, kBlockSize> y; | |
64 std::vector<float> x(kBlockSize, 0.f); | |
65 FftData X; | |
66 FftData Y; | |
67 x_old.fill(0.f); | |
68 | |
69 FftBuffer X_buffer(Aec3Optimization::kNone, model.MinFarendBufferLength(), | |
70 std::vector<size_t>(1, model.MinFarendBufferLength())); | |
71 | |
72 for (size_t delay_samples : {0, 64, 301}) { | |
73 DelayBuffer<float> delay_buffer(delay_samples); | |
74 auto model_applier = [&](int num_iterations, float y_scale, | |
75 bool known_delay) { | |
76 for (int k = 0; k < num_iterations; ++k) { | |
77 RandomizeSampleVector(&random_generator, x); | |
78 delay_buffer.Delay(x, y); | |
79 std::for_each(y.begin(), y.end(), [&](float& a) { a *= y_scale; }); | |
80 | |
81 fft.PaddedFft(x, x_old, &X); | |
82 X_buffer.Insert(X); | |
83 | |
84 fft.ZeroPaddedFft(y, &Y); | |
85 Y.Spectrum(Aec3Optimization::kNone, &Y2); | |
86 | |
87 aec_state.Update(std::vector<std::array<float, kFftLengthBy2Plus1>>( | |
88 10, std::array<float, kFftLengthBy2Plus1>()), | |
89 known_delay ? rtc::Optional<size_t>(delay_samples) | |
90 : rtc::Optional<size_t>(), | |
91 X_buffer, E2_main, E2_shadow, Y2, x, | |
92 EchoPathVariability(false, false), false); | |
93 | |
94 model.EstimateEcho(X_buffer, Y2, aec_state, &S2); | |
95 } | |
96 }; | |
97 | |
98 for (int j = 0; j < 2; ++j) { | |
99 bool known_delay = j == 0; | |
100 SCOPED_TRACE(ProduceDebugText(delay_samples, known_delay)); | |
101 // Verify that the echo path estimates converges downwards to a fairly | |
102 // tight bound estimate. | |
103 model_applier(600, 1.f, known_delay); | |
104 for (size_t k = 1; k < S2.size() - 1; ++k) { | |
105 EXPECT_LE(Y2[k], 2.f * S2[k]); | |
106 } | |
107 | |
108 // Verify that stronger echo paths are detected immediately. | |
109 model_applier(100, 10.f, known_delay); | |
110 for (size_t k = 1; k < S2.size() - 1; ++k) { | |
111 EXPECT_LE(Y2[k], 5.f * S2[k]); | |
112 } | |
113 | |
114 // Verify that there is a delay until a weaker echo path is detected. | |
115 model_applier(50, 100.f, known_delay); | |
116 model_applier(50, 1.f, known_delay); | |
117 for (size_t k = 1; k < S2.size() - 1; ++k) { | |
118 EXPECT_LE(100.f * Y2[k], S2[k]); | |
119 } | |
120 | |
121 // Verify that an echo path change causes the echo path estimate to be | |
122 // reset. | |
123 model_applier(600, 0.1f, known_delay); | |
124 model.HandleEchoPathChange(EchoPathVariability(true, false)); | |
125 model_applier(50, 0.1f, known_delay); | |
126 for (size_t k = 1; k < S2.size() - 1; ++k) { | |
127 EXPECT_LE(10.f * Y2[k], S2[k]); | |
128 } | |
129 } | |
130 } | |
131 } | |
132 | 43 |
133 } // namespace webrtc | 44 } // namespace webrtc |
OLD | NEW |