Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: webrtc/modules/audio_processing/aec3/render_delay_controller_unittest.cc

Issue 3007833002: Further utilizing the AEC3 config struct for constants (Closed)
Patch Set: Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } // namespace 43 } // namespace
44 44
45 // Verifies the output of GetDelay when there are no AnalyzeRender calls. 45 // Verifies the output of GetDelay when there are no AnalyzeRender calls.
46 TEST(RenderDelayController, NoRenderSignal) { 46 TEST(RenderDelayController, NoRenderSignal) {
47 std::vector<float> block(kBlockSize, 0.f); 47 std::vector<float> block(kBlockSize, 0.f);
48 for (auto rate : {8000, 16000, 32000, 48000}) { 48 for (auto rate : {8000, 16000, 32000, 48000}) {
49 SCOPED_TRACE(ProduceDebugText(rate)); 49 SCOPED_TRACE(ProduceDebugText(rate));
50 std::unique_ptr<RenderDelayBuffer> delay_buffer( 50 std::unique_ptr<RenderDelayBuffer> delay_buffer(
51 RenderDelayBuffer::Create(NumBandsForRate(rate))); 51 RenderDelayBuffer::Create(NumBandsForRate(rate)));
52 std::unique_ptr<RenderDelayController> delay_controller( 52 std::unique_ptr<RenderDelayController> delay_controller(
53 RenderDelayController::Create(rate)); 53 RenderDelayController::Create(AudioProcessing::Config::EchoCanceller3(),
54 rate));
54 for (size_t k = 0; k < 100; ++k) { 55 for (size_t k = 0; k < 100; ++k) {
55 EXPECT_EQ(0u, delay_controller->GetDelay( 56 EXPECT_EQ(0u, delay_controller->GetDelay(
56 delay_buffer->GetDownsampledRenderBuffer(), block)); 57 delay_buffer->GetDownsampledRenderBuffer(), block));
57 } 58 }
58 } 59 }
59 } 60 }
60 61
61 // Verifies the basic API call sequence. 62 // Verifies the basic API call sequence.
62 TEST(RenderDelayController, BasicApiCalls) { 63 TEST(RenderDelayController, BasicApiCalls) {
63 std::vector<float> capture_block(kBlockSize, 0.f); 64 std::vector<float> capture_block(kBlockSize, 0.f);
64 size_t delay_blocks = 0; 65 size_t delay_blocks = 0;
65 for (auto rate : {8000, 16000, 32000, 48000}) { 66 for (auto rate : {8000, 16000, 32000, 48000}) {
66 std::vector<std::vector<float>> render_block( 67 std::vector<std::vector<float>> render_block(
67 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); 68 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f));
68 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( 69 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
69 RenderDelayBuffer::Create(NumBandsForRate(rate))); 70 RenderDelayBuffer::Create(NumBandsForRate(rate)));
70 std::unique_ptr<RenderDelayController> delay_controller( 71 std::unique_ptr<RenderDelayController> delay_controller(
71 RenderDelayController::Create(rate)); 72 RenderDelayController::Create(AudioProcessing::Config::EchoCanceller3(),
73 rate));
72 for (size_t k = 0; k < 10; ++k) { 74 for (size_t k = 0; k < 10; ++k) {
73 render_delay_buffer->Insert(render_block); 75 render_delay_buffer->Insert(render_block);
74 render_delay_buffer->UpdateBuffers(); 76 render_delay_buffer->UpdateBuffers();
75 delay_blocks = delay_controller->GetDelay( 77 delay_blocks = delay_controller->GetDelay(
76 render_delay_buffer->GetDownsampledRenderBuffer(), capture_block); 78 render_delay_buffer->GetDownsampledRenderBuffer(), capture_block);
77 } 79 }
78 EXPECT_FALSE(delay_controller->AlignmentHeadroomSamples()); 80 EXPECT_FALSE(delay_controller->AlignmentHeadroomSamples());
79 EXPECT_EQ(0u, delay_blocks); 81 EXPECT_EQ(0u, delay_blocks);
80 } 82 }
81 } 83 }
82 84
83 // Verifies that the RenderDelayController is able to align the signals for 85 // Verifies that the RenderDelayController is able to align the signals for
84 // simple timeshifts between the signals. 86 // simple timeshifts between the signals.
85 TEST(RenderDelayController, Alignment) { 87 TEST(RenderDelayController, Alignment) {
86 Random random_generator(42U); 88 Random random_generator(42U);
87 std::vector<float> capture_block(kBlockSize, 0.f); 89 std::vector<float> capture_block(kBlockSize, 0.f);
88 size_t delay_blocks = 0; 90 size_t delay_blocks = 0;
89 for (auto rate : {8000, 16000, 32000, 48000}) { 91 for (auto rate : {8000, 16000, 32000, 48000}) {
90 std::vector<std::vector<float>> render_block( 92 std::vector<std::vector<float>> render_block(
91 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); 93 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f));
92 94
93 for (size_t delay_samples : {15, 50, 150, 200, 800, 4000}) { 95 for (size_t delay_samples : {15, 50, 150, 200, 800, 4000}) {
94 SCOPED_TRACE(ProduceDebugText(rate, delay_samples)); 96 SCOPED_TRACE(ProduceDebugText(rate, delay_samples));
95 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( 97 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
96 RenderDelayBuffer::Create(NumBandsForRate(rate))); 98 RenderDelayBuffer::Create(NumBandsForRate(rate)));
97 std::unique_ptr<RenderDelayController> delay_controller( 99 std::unique_ptr<RenderDelayController> delay_controller(
98 RenderDelayController::Create(rate)); 100 RenderDelayController::Create(
101 AudioProcessing::Config::EchoCanceller3(), rate));
99 DelayBuffer<float> signal_delay_buffer(delay_samples); 102 DelayBuffer<float> signal_delay_buffer(delay_samples);
100 for (size_t k = 0; k < (400 + delay_samples / kBlockSize); ++k) { 103 for (size_t k = 0; k < (400 + delay_samples / kBlockSize); ++k) {
101 RandomizeSampleVector(&random_generator, render_block[0]); 104 RandomizeSampleVector(&random_generator, render_block[0]);
102 signal_delay_buffer.Delay(render_block[0], capture_block); 105 signal_delay_buffer.Delay(render_block[0], capture_block);
103 render_delay_buffer->Insert(render_block); 106 render_delay_buffer->Insert(render_block);
104 render_delay_buffer->UpdateBuffers(); 107 render_delay_buffer->UpdateBuffers();
105 delay_blocks = delay_controller->GetDelay( 108 delay_blocks = delay_controller->GetDelay(
106 render_delay_buffer->GetDownsampledRenderBuffer(), capture_block); 109 render_delay_buffer->GetDownsampledRenderBuffer(), capture_block);
107 } 110 }
108 111
(...skipping 23 matching lines...) Expand all
132 std::vector<float> capture_block(kBlockSize, 0.f); 135 std::vector<float> capture_block(kBlockSize, 0.f);
133 for (auto rate : {8000, 16000, 32000, 48000}) { 136 for (auto rate : {8000, 16000, 32000, 48000}) {
134 std::vector<std::vector<float>> render_block( 137 std::vector<std::vector<float>> render_block(
135 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); 138 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f));
136 for (size_t delay_samples : {15, 50, 300, 800}) { 139 for (size_t delay_samples : {15, 50, 300, 800}) {
137 size_t delay_blocks = 0; 140 size_t delay_blocks = 0;
138 SCOPED_TRACE(ProduceDebugText(rate, delay_samples)); 141 SCOPED_TRACE(ProduceDebugText(rate, delay_samples));
139 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( 142 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
140 RenderDelayBuffer::Create(NumBandsForRate(rate))); 143 RenderDelayBuffer::Create(NumBandsForRate(rate)));
141 std::unique_ptr<RenderDelayController> delay_controller( 144 std::unique_ptr<RenderDelayController> delay_controller(
142 RenderDelayController::Create(rate)); 145 RenderDelayController::Create(
146 AudioProcessing::Config::EchoCanceller3(), rate));
143 DelayBuffer<float> signal_delay_buffer(delay_samples); 147 DelayBuffer<float> signal_delay_buffer(delay_samples);
144 for (size_t j = 0; 148 for (size_t j = 0;
145 j < 149 j <
146 (1000 + delay_samples / kBlockSize) / kMaxApiCallsJitterBlocks + 1; 150 (1000 + delay_samples / kBlockSize) / kMaxApiCallsJitterBlocks + 1;
147 ++j) { 151 ++j) {
148 std::vector<std::vector<float>> capture_block_buffer; 152 std::vector<std::vector<float>> capture_block_buffer;
149 for (size_t k = 0; k < (kMaxApiCallsJitterBlocks - 1); ++k) { 153 for (size_t k = 0; k < (kMaxApiCallsJitterBlocks - 1); ++k) {
150 RandomizeSampleVector(&random_generator, render_block[0]); 154 RandomizeSampleVector(&random_generator, render_block[0]);
151 signal_delay_buffer.Delay(render_block[0], capture_block); 155 signal_delay_buffer.Delay(render_block[0], capture_block);
152 capture_block_buffer.push_back(capture_block); 156 capture_block_buffer.push_back(capture_block);
(...skipping 28 matching lines...) Expand all
181 185
182 // Verifies the initial value for the AlignmentHeadroomSamples. 186 // Verifies the initial value for the AlignmentHeadroomSamples.
183 TEST(RenderDelayController, InitialHeadroom) { 187 TEST(RenderDelayController, InitialHeadroom) {
184 std::vector<float> render_block(kBlockSize, 0.f); 188 std::vector<float> render_block(kBlockSize, 0.f);
185 std::vector<float> capture_block(kBlockSize, 0.f); 189 std::vector<float> capture_block(kBlockSize, 0.f);
186 for (auto rate : {8000, 16000, 32000, 48000}) { 190 for (auto rate : {8000, 16000, 32000, 48000}) {
187 SCOPED_TRACE(ProduceDebugText(rate)); 191 SCOPED_TRACE(ProduceDebugText(rate));
188 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( 192 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
189 RenderDelayBuffer::Create(NumBandsForRate(rate))); 193 RenderDelayBuffer::Create(NumBandsForRate(rate)));
190 std::unique_ptr<RenderDelayController> delay_controller( 194 std::unique_ptr<RenderDelayController> delay_controller(
191 RenderDelayController::Create(rate)); 195 RenderDelayController::Create(AudioProcessing::Config::EchoCanceller3(),
196 rate));
192 EXPECT_FALSE(delay_controller->AlignmentHeadroomSamples()); 197 EXPECT_FALSE(delay_controller->AlignmentHeadroomSamples());
193 } 198 }
194 } 199 }
195 200
196 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 201 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
197 202
198 // Verifies the check for the capture signal block size. 203 // Verifies the check for the capture signal block size.
199 TEST(RenderDelayController, WrongCaptureSize) { 204 TEST(RenderDelayController, WrongCaptureSize) {
200 std::vector<float> block(kBlockSize - 1, 0.f); 205 std::vector<float> block(kBlockSize - 1, 0.f);
201 for (auto rate : {8000, 16000, 32000, 48000}) { 206 for (auto rate : {8000, 16000, 32000, 48000}) {
202 SCOPED_TRACE(ProduceDebugText(rate)); 207 SCOPED_TRACE(ProduceDebugText(rate));
203 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( 208 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
204 RenderDelayBuffer::Create(NumBandsForRate(rate))); 209 RenderDelayBuffer::Create(NumBandsForRate(rate)));
205 EXPECT_DEATH( 210 EXPECT_DEATH(
206 std::unique_ptr<RenderDelayController>( 211 std::unique_ptr<RenderDelayController>(
207 RenderDelayController::Create(rate)) 212 RenderDelayController::Create(
213 AudioProcessing::Config::EchoCanceller3(), rate))
208 ->GetDelay(render_delay_buffer->GetDownsampledRenderBuffer(), 214 ->GetDelay(render_delay_buffer->GetDownsampledRenderBuffer(),
209 block), 215 block),
210 ""); 216 "");
211 } 217 }
212 } 218 }
213 219
214 // Verifies the check for correct sample rate. 220 // Verifies the check for correct sample rate.
215 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH 221 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH
216 // tests on test bots has been fixed. 222 // tests on test bots has been fixed.
217 TEST(RenderDelayController, DISABLED_WrongSampleRate) { 223 TEST(RenderDelayController, DISABLED_WrongSampleRate) {
218 for (auto rate : {-1, 0, 8001, 16001}) { 224 for (auto rate : {-1, 0, 8001, 16001}) {
219 SCOPED_TRACE(ProduceDebugText(rate)); 225 SCOPED_TRACE(ProduceDebugText(rate));
220 std::unique_ptr<RenderDelayBuffer> render_delay_buffer( 226 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
221 RenderDelayBuffer::Create(NumBandsForRate(rate))); 227 RenderDelayBuffer::Create(NumBandsForRate(rate)));
222 EXPECT_DEATH(std::unique_ptr<RenderDelayController>( 228 EXPECT_DEATH(
223 RenderDelayController::Create(rate)), 229 std::unique_ptr<RenderDelayController>(RenderDelayController::Create(
224 ""); 230 AudioProcessing::Config::EchoCanceller3(), rate)),
231 "");
225 } 232 }
226 } 233 }
227 234
228 #endif 235 #endif
229 236
230 } // namespace webrtc 237 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698