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