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/echo_path_delay_estimator.h" | 11 #include "webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <sstream> | 14 #include <sstream> |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "webrtc/base/random.h" | 17 #include "webrtc/base/random.h" |
18 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" | 18 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" |
19 #include "webrtc/modules/audio_processing/aec3/render_delay_buffer.h" | |
19 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | 20 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" |
20 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" | 21 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" |
21 #include "webrtc/test/gtest.h" | 22 #include "webrtc/test/gtest.h" |
22 | 23 |
23 namespace webrtc { | 24 namespace webrtc { |
24 namespace { | 25 namespace { |
25 | 26 |
26 std::string ProduceDebugText(size_t delay) { | 27 std::string ProduceDebugText(size_t delay) { |
27 std::ostringstream ss; | 28 std::ostringstream ss; |
28 ss << "Delay: " << delay; | 29 ss << "Delay: " << delay; |
29 return ss.str(); | 30 return ss.str(); |
30 } | 31 } |
31 | 32 |
32 } // namespace | 33 } // namespace |
33 | 34 |
34 // Verifies that the basic API calls work. | 35 // Verifies that the basic API calls work. |
35 TEST(EchoPathDelayEstimator, BasicApiCalls) { | 36 TEST(EchoPathDelayEstimator, BasicApiCalls) { |
36 ApmDataDumper data_dumper(0); | 37 ApmDataDumper data_dumper(0); |
38 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( | |
peah-webrtc
2017/03/30 05:36:56
These tests are basically the same, and the change
| |
39 RenderDelayBuffer::Create(3)); | |
37 EchoPathDelayEstimator estimator(&data_dumper); | 40 EchoPathDelayEstimator estimator(&data_dumper); |
38 std::vector<float> render(kBlockSize, 0.f); | 41 std::vector<std::vector<float>> render(3, |
42 std::vector<float>(kBlockSize, 0.f)); | |
39 std::vector<float> capture(kBlockSize, 0.f); | 43 std::vector<float> capture(kBlockSize, 0.f); |
40 for (size_t k = 0; k < 100; ++k) { | 44 for (size_t k = 0; k < 100; ++k) { |
41 estimator.EstimateDelay(render, capture); | 45 render_delay_buffer->Insert(&render); |
46 estimator.EstimateDelay(render_delay_buffer->GetDownsampledRenderBuffer(), | |
47 capture); | |
42 } | 48 } |
43 } | 49 } |
44 | 50 |
45 // Verifies that the delay estimator produces correct delay for artificially | 51 // Verifies that the delay estimator produces correct delay for artificially |
46 // delayed signals. | 52 // delayed signals. |
47 TEST(EchoPathDelayEstimator, DelayEstimation) { | 53 TEST(EchoPathDelayEstimator, DelayEstimation) { |
48 Random random_generator(42U); | 54 Random random_generator(42U); |
49 std::vector<float> render(kBlockSize, 0.f); | 55 std::vector<std::vector<float>> render(3, |
56 std::vector<float>(kBlockSize, 0.f)); | |
50 std::vector<float> capture(kBlockSize, 0.f); | 57 std::vector<float> capture(kBlockSize, 0.f); |
51 ApmDataDumper data_dumper(0); | 58 ApmDataDumper data_dumper(0); |
52 for (size_t delay_samples : {15, 64, 150, 200, 800, 4000}) { | 59 for (size_t delay_samples : {15, 64, 150, 200, 800, 4000}) { |
53 SCOPED_TRACE(ProduceDebugText(delay_samples)); | 60 SCOPED_TRACE(ProduceDebugText(delay_samples)); |
61 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( | |
62 RenderDelayBuffer::Create(3)); | |
54 DelayBuffer<float> signal_delay_buffer(delay_samples); | 63 DelayBuffer<float> signal_delay_buffer(delay_samples); |
55 EchoPathDelayEstimator estimator(&data_dumper); | 64 EchoPathDelayEstimator estimator(&data_dumper); |
56 | 65 |
57 rtc::Optional<size_t> estimated_delay_samples; | 66 rtc::Optional<size_t> estimated_delay_samples; |
58 for (size_t k = 0; k < (100 + delay_samples / kBlockSize); ++k) { | 67 for (size_t k = 0; k < (100 + delay_samples / kBlockSize); ++k) { |
59 RandomizeSampleVector(&random_generator, render); | 68 RandomizeSampleVector(&random_generator, render[0]); |
60 signal_delay_buffer.Delay(render, capture); | 69 signal_delay_buffer.Delay(render[0], capture); |
61 estimated_delay_samples = estimator.EstimateDelay(render, capture); | 70 render_delay_buffer->Insert(&render); |
71 render_delay_buffer->UpdateBuffers(); | |
72 estimated_delay_samples = estimator.EstimateDelay( | |
73 render_delay_buffer->GetDownsampledRenderBuffer(), capture); | |
62 } | 74 } |
63 if (estimated_delay_samples) { | 75 if (estimated_delay_samples) { |
64 // Due to the internal down-sampling by 4 done inside the delay estimator | 76 // Due to the internal down-sampling by 4 done inside the delay estimator |
65 // the estimated delay cannot be expected to be closer than 4 samples to | 77 // the estimated delay cannot be expected to be closer than 4 samples to |
66 // the true delay. | 78 // the true delay. |
67 EXPECT_NEAR(delay_samples, *estimated_delay_samples, 4); | 79 EXPECT_NEAR(delay_samples, *estimated_delay_samples, 4); |
68 } else { | 80 } else { |
69 ADD_FAILURE(); | 81 ADD_FAILURE(); |
70 } | 82 } |
71 } | 83 } |
72 } | 84 } |
73 | 85 |
74 // Verifies that the delay estimator does not produce delay estimates too | 86 // Verifies that the delay estimator does not produce delay estimates too |
75 // quickly. | 87 // quickly. |
76 TEST(EchoPathDelayEstimator, NoInitialDelayestimates) { | 88 TEST(EchoPathDelayEstimator, NoInitialDelayestimates) { |
77 Random random_generator(42U); | 89 Random random_generator(42U); |
78 std::vector<float> render(kBlockSize, 0.f); | 90 std::vector<std::vector<float>> render(3, |
91 std::vector<float>(kBlockSize, 0.f)); | |
79 std::vector<float> capture(kBlockSize, 0.f); | 92 std::vector<float> capture(kBlockSize, 0.f); |
80 ApmDataDumper data_dumper(0); | 93 ApmDataDumper data_dumper(0); |
94 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( | |
95 RenderDelayBuffer::Create(3)); | |
81 | 96 |
82 EchoPathDelayEstimator estimator(&data_dumper); | 97 EchoPathDelayEstimator estimator(&data_dumper); |
83 for (size_t k = 0; k < 19; ++k) { | 98 for (size_t k = 0; k < 19; ++k) { |
84 RandomizeSampleVector(&random_generator, render); | 99 RandomizeSampleVector(&random_generator, render[0]); |
85 std::copy(render.begin(), render.end(), capture.begin()); | 100 std::copy(render[0].begin(), render[0].end(), capture.begin()); |
86 EXPECT_FALSE(estimator.EstimateDelay(render, capture)); | 101 render_delay_buffer->Insert(&render); |
102 render_delay_buffer->UpdateBuffers(); | |
103 EXPECT_FALSE(estimator.EstimateDelay( | |
104 render_delay_buffer->GetDownsampledRenderBuffer(), capture)); | |
87 } | 105 } |
88 } | 106 } |
89 | 107 |
90 // Verifies that the delay estimator does not produce delay estimates for render | 108 // Verifies that the delay estimator does not produce delay estimates for render |
91 // signals of low level. | 109 // signals of low level. |
92 TEST(EchoPathDelayEstimator, NoDelayEstimatesForLowLevelRenderSignals) { | 110 TEST(EchoPathDelayEstimator, NoDelayEstimatesForLowLevelRenderSignals) { |
93 Random random_generator(42U); | 111 Random random_generator(42U); |
94 std::vector<float> render(kBlockSize, 0.f); | 112 std::vector<std::vector<float>> render(3, |
113 std::vector<float>(kBlockSize, 0.f)); | |
95 std::vector<float> capture(kBlockSize, 0.f); | 114 std::vector<float> capture(kBlockSize, 0.f); |
96 ApmDataDumper data_dumper(0); | 115 ApmDataDumper data_dumper(0); |
97 EchoPathDelayEstimator estimator(&data_dumper); | 116 EchoPathDelayEstimator estimator(&data_dumper); |
117 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( | |
118 RenderDelayBuffer::Create(3)); | |
98 for (size_t k = 0; k < 100; ++k) { | 119 for (size_t k = 0; k < 100; ++k) { |
99 RandomizeSampleVector(&random_generator, render); | 120 RandomizeSampleVector(&random_generator, render[0]); |
100 for (auto& render_k : render) { | 121 for (auto& render_k : render[0]) { |
101 render_k *= 100.f / 32767.f; | 122 render_k *= 100.f / 32767.f; |
102 } | 123 } |
103 std::copy(render.begin(), render.end(), capture.begin()); | 124 std::copy(render[0].begin(), render[0].end(), capture.begin()); |
104 EXPECT_FALSE(estimator.EstimateDelay(render, capture)); | 125 render_delay_buffer->Insert(&render); |
126 render_delay_buffer->UpdateBuffers(); | |
127 EXPECT_FALSE(estimator.EstimateDelay( | |
128 render_delay_buffer->GetDownsampledRenderBuffer(), capture)); | |
105 } | 129 } |
106 } | 130 } |
107 | 131 |
108 // Verifies that the delay estimator does not produce delay estimates for | 132 // Verifies that the delay estimator does not produce delay estimates for |
109 // uncorrelated signals. | 133 // uncorrelated signals. |
110 TEST(EchoPathDelayEstimator, NoDelayEstimatesForUncorrelatedSignals) { | 134 TEST(EchoPathDelayEstimator, NoDelayEstimatesForUncorrelatedSignals) { |
111 Random random_generator(42U); | 135 Random random_generator(42U); |
112 std::vector<float> render(kBlockSize, 0.f); | 136 std::vector<std::vector<float>> render(3, |
137 std::vector<float>(kBlockSize, 0.f)); | |
113 std::vector<float> capture(kBlockSize, 0.f); | 138 std::vector<float> capture(kBlockSize, 0.f); |
114 ApmDataDumper data_dumper(0); | 139 ApmDataDumper data_dumper(0); |
115 EchoPathDelayEstimator estimator(&data_dumper); | 140 EchoPathDelayEstimator estimator(&data_dumper); |
141 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( | |
142 RenderDelayBuffer::Create(3)); | |
116 for (size_t k = 0; k < 100; ++k) { | 143 for (size_t k = 0; k < 100; ++k) { |
117 RandomizeSampleVector(&random_generator, render); | 144 RandomizeSampleVector(&random_generator, render[0]); |
118 RandomizeSampleVector(&random_generator, capture); | 145 RandomizeSampleVector(&random_generator, capture); |
119 EXPECT_FALSE(estimator.EstimateDelay(render, capture)); | 146 render_delay_buffer->Insert(&render); |
147 render_delay_buffer->UpdateBuffers(); | |
148 EXPECT_FALSE(estimator.EstimateDelay( | |
149 render_delay_buffer->GetDownsampledRenderBuffer(), capture)); | |
120 } | 150 } |
121 } | 151 } |
122 | 152 |
123 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 153 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
124 | 154 |
125 // Verifies the check for the render blocksize. | 155 // Verifies the check for the render blocksize. |
126 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH | 156 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH |
127 // tests on test bots has been fixed. | 157 // tests on test bots has been fixed. |
128 TEST(EchoPathDelayEstimator, DISABLED_WrongRenderBlockSize) { | 158 TEST(EchoPathDelayEstimator, DISABLED_WrongRenderBlockSize) { |
129 ApmDataDumper data_dumper(0); | 159 ApmDataDumper data_dumper(0); |
130 EchoPathDelayEstimator estimator(&data_dumper); | 160 EchoPathDelayEstimator estimator(&data_dumper); |
131 std::vector<float> render(std::vector<float>(kBlockSize - 1, 0.f)); | 161 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( |
162 RenderDelayBuffer::Create(3)); | |
132 std::vector<float> capture(std::vector<float>(kBlockSize, 0.f)); | 163 std::vector<float> capture(std::vector<float>(kBlockSize, 0.f)); |
133 EXPECT_DEATH(estimator.EstimateDelay(render, capture), ""); | 164 EXPECT_DEATH(estimator.EstimateDelay( |
165 render_delay_buffer->GetDownsampledRenderBuffer(), capture), | |
166 ""); | |
134 } | 167 } |
135 | 168 |
136 // Verifies the check for the capture blocksize. | 169 // Verifies the check for the capture blocksize. |
137 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH | 170 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH |
138 // tests on test bots has been fixed. | 171 // tests on test bots has been fixed. |
139 TEST(EchoPathDelayEstimator, WrongCaptureBlockSize) { | 172 TEST(EchoPathDelayEstimator, WrongCaptureBlockSize) { |
140 ApmDataDumper data_dumper(0); | 173 ApmDataDumper data_dumper(0); |
141 EchoPathDelayEstimator estimator(&data_dumper); | 174 EchoPathDelayEstimator estimator(&data_dumper); |
142 std::vector<float> render(std::vector<float>(kBlockSize, 0.f)); | 175 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( |
176 RenderDelayBuffer::Create(3)); | |
143 std::vector<float> capture(std::vector<float>(kBlockSize - 1, 0.f)); | 177 std::vector<float> capture(std::vector<float>(kBlockSize - 1, 0.f)); |
144 EXPECT_DEATH(estimator.EstimateDelay(render, capture), ""); | 178 EXPECT_DEATH(estimator.EstimateDelay( |
179 render_delay_buffer->GetDownsampledRenderBuffer(), capture), | |
180 ""); | |
145 } | 181 } |
146 | 182 |
147 // Verifies the check for non-null data dumper. | 183 // Verifies the check for non-null data dumper. |
148 TEST(EchoPathDelayEstimator, NullDataDumper) { | 184 TEST(EchoPathDelayEstimator, NullDataDumper) { |
149 EXPECT_DEATH(EchoPathDelayEstimator(nullptr), ""); | 185 EXPECT_DEATH(EchoPathDelayEstimator(nullptr), ""); |
150 } | 186 } |
151 | 187 |
152 #endif | 188 #endif |
153 | 189 |
154 } // namespace webrtc | 190 } // namespace webrtc |
OLD | NEW |