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

Side by Side Diff: webrtc/modules/audio_processing/aec/system_delay_unittest.cc

Issue 1187943005: Reland "Revert "audio_processing/aec: make delay estimator aware of starving farend buffer"" (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adjusted device buffer mapping w.r.t. extended_filter Created 5 years, 6 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
« no previous file with comments | « webrtc/modules/audio_processing/aec/echo_cancellation.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webrtc/base/checks.h"
13 extern "C" { 12 extern "C" {
14 #include "webrtc/modules/audio_processing/aec/aec_core.h" 13 #include "webrtc/modules/audio_processing/aec/aec_core.h"
15 } 14 }
16 #include "webrtc/modules/audio_processing/aec/echo_cancellation_internal.h" 15 #include "webrtc/modules/audio_processing/aec/echo_cancellation_internal.h"
17 #include "webrtc/modules/audio_processing/aec/include/echo_cancellation.h" 16 #include "webrtc/modules/audio_processing/aec/include/echo_cancellation.h"
18 #include "webrtc/test/testsupport/gtest_disable.h" 17 #include "webrtc/test/testsupport/gtest_disable.h"
19 #include "webrtc/typedefs.h" 18 #include "webrtc/typedefs.h"
20 19
21 namespace { 20 namespace {
22 21
(...skipping 11 matching lines...) Expand all
34 void RenderAndCapture(int device_buffer_ms); 33 void RenderAndCapture(int device_buffer_ms);
35 34
36 // Fills up the far-end buffer with respect to the default device buffer size. 35 // Fills up the far-end buffer with respect to the default device buffer size.
37 int BufferFillUp(); 36 int BufferFillUp();
38 37
39 // Runs and verifies the behavior in a stable startup procedure. 38 // Runs and verifies the behavior in a stable startup procedure.
40 void RunStableStartup(); 39 void RunStableStartup();
41 40
42 // Maps buffer size in ms into samples, taking the unprocessed frame into 41 // Maps buffer size in ms into samples, taking the unprocessed frame into
43 // account. 42 // account.
44 int MapBufferSizeToSamples(int size_in_ms); 43 int MapBufferSizeToSamples(int size_in_ms, bool extended_filter);
45 44
46 void* handle_; 45 void* handle_;
47 Aec* self_; 46 Aec* self_;
48 int samples_per_frame_; 47 int samples_per_frame_;
49 // Dummy input/output speech data. 48 // Dummy input/output speech data.
50 static const int kSamplesPerChunk = 160; 49 static const int kSamplesPerChunk = 160;
51 float far_[kSamplesPerChunk]; 50 float far_[kSamplesPerChunk];
52 float near_[kSamplesPerChunk]; 51 float near_[kSamplesPerChunk];
53 float out_[kSamplesPerChunk]; 52 float out_[kSamplesPerChunk];
54 const float* near_ptr_; 53 const float* near_ptr_;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 static const int kStableConvergenceMs = 100; 92 static const int kStableConvergenceMs = 100;
94 93
95 // Maximum convergence time in ms. This means that we should leave the startup 94 // Maximum convergence time in ms. This means that we should leave the startup
96 // phase after |kMaxConvergenceMs| independent of device buffer stability 95 // phase after |kMaxConvergenceMs| independent of device buffer stability
97 // conditions. 96 // conditions.
98 static const int kMaxConvergenceMs = 500; 97 static const int kMaxConvergenceMs = 500;
99 98
100 void SystemDelayTest::Init(int sample_rate_hz) { 99 void SystemDelayTest::Init(int sample_rate_hz) {
101 // Initialize AEC 100 // Initialize AEC
102 EXPECT_EQ(0, WebRtcAec_Init(handle_, sample_rate_hz, 48000)); 101 EXPECT_EQ(0, WebRtcAec_Init(handle_, sample_rate_hz, 48000));
102 EXPECT_EQ(0, WebRtcAec_system_delay(self_->aec));
103 103
104 // One frame equals 10 ms of data. 104 // One frame equals 10 ms of data.
105 samples_per_frame_ = sample_rate_hz / 100; 105 samples_per_frame_ = sample_rate_hz / 100;
106 } 106 }
107 107
108 void SystemDelayTest::RenderAndCapture(int device_buffer_ms) { 108 void SystemDelayTest::RenderAndCapture(int device_buffer_ms) {
109 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); 109 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_));
110 EXPECT_EQ(0, 110 EXPECT_EQ(0,
111 WebRtcAec_Process(handle_, 111 WebRtcAec_Process(handle_,
112 &near_ptr_, 112 &near_ptr_,
(...skipping 15 matching lines...) Expand all
128 EXPECT_EQ(buffer_size, WebRtcAec_system_delay(self_->aec)); 128 EXPECT_EQ(buffer_size, WebRtcAec_system_delay(self_->aec));
129 } 129 }
130 return buffer_size; 130 return buffer_size;
131 } 131 }
132 132
133 void SystemDelayTest::RunStableStartup() { 133 void SystemDelayTest::RunStableStartup() {
134 // To make sure we have a full buffer when we verify stability we first fill 134 // To make sure we have a full buffer when we verify stability we first fill
135 // up the far-end buffer with the same amount as we will report in through 135 // up the far-end buffer with the same amount as we will report in through
136 // Process(). 136 // Process().
137 int buffer_size = BufferFillUp(); 137 int buffer_size = BufferFillUp();
138 // A stable device should be accepted and put in a regular process mode within 138
139 // |kStableConvergenceMs|. 139 if (WebRtcAec_reported_delay_enabled(self_->aec) == 0) {
140 int process_time_ms = 0; 140 // In extended_filter mode we set the buffer size after the first processed
141 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) { 141 // 10 ms chunk. Hence, we don't need to wait for the reported system delay
142 // values to become stable.
142 RenderAndCapture(kDeviceBufMs); 143 RenderAndCapture(kDeviceBufMs);
143 buffer_size += samples_per_frame_; 144 buffer_size += samples_per_frame_;
144 if (self_->startup_phase == 0) { 145 EXPECT_EQ(0, self_->startup_phase);
145 // We have left the startup phase. 146 } else {
146 break; 147 // A stable device should be accepted and put in a regular process mode
148 // within |kStableConvergenceMs|.
149 int process_time_ms = 0;
150 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) {
151 RenderAndCapture(kDeviceBufMs);
152 buffer_size += samples_per_frame_;
153 if (self_->startup_phase == 0) {
154 // We have left the startup phase.
155 break;
156 }
147 } 157 }
158 // Verify convergence time.
159 EXPECT_GT(kStableConvergenceMs, process_time_ms);
148 } 160 }
149 // Verify convergence time.
150 EXPECT_GT(kStableConvergenceMs, process_time_ms);
151 // Verify that the buffer has been flushed. 161 // Verify that the buffer has been flushed.
152 EXPECT_GE(buffer_size, WebRtcAec_system_delay(self_->aec)); 162 EXPECT_GE(buffer_size, WebRtcAec_system_delay(self_->aec));
153 } 163 }
154 164
155 int SystemDelayTest::MapBufferSizeToSamples(int size_in_ms) { 165 int SystemDelayTest::MapBufferSizeToSamples(int size_in_ms,
156 // The extra 10 ms corresponds to the unprocessed frame. 166 bool extended_filter) {
157 return (size_in_ms + 10) * samples_per_frame_ / 10; 167 // If extended_filter is disabled we add an extra 10 ms for the unprocessed
168 // frame. That is simply how the algorithm is constructed.
169 return (size_in_ms + (extended_filter ? 0 : 10)) * samples_per_frame_ / 10;
158 } 170 }
159 171
160 // The tests should meet basic requirements and not be adjusted to what is 172 // The tests should meet basic requirements and not be adjusted to what is
161 // actually implemented. If we don't get good code coverage this way we either 173 // actually implemented. If we don't get good code coverage this way we either
162 // lack in tests or have unnecessary code. 174 // lack in tests or have unnecessary code.
163 // General requirements: 175 // General requirements:
164 // 1) If we add far-end data the system delay should be increased with the same 176 // 1) If we add far-end data the system delay should be increased with the same
165 // amount we add. 177 // amount we add.
166 // 2) If the far-end buffer is full we should flush the oldest data to make room 178 // 2) If the far-end buffer is full we should flush the oldest data to make room
167 // for the new. In this case the system delay is unaffected. 179 // for the new. In this case the system delay is unaffected.
168 // 3) There should exist a startup phase in which the buffer size is to be 180 // 3) There should exist a startup phase in which the buffer size is to be
169 // determined. In this phase no cancellation should be performed. 181 // determined. In this phase no cancellation should be performed.
170 // 4) Under stable conditions (small variations in device buffer sizes) the AEC 182 // 4) Under stable conditions (small variations in device buffer sizes) the AEC
171 // should determine an appropriate local buffer size within 183 // should determine an appropriate local buffer size within
172 // |kStableConvergenceMs| ms. 184 // |kStableConvergenceMs| ms.
173 // 5) Under unstable conditions the AEC should make a decision within 185 // 5) Under unstable conditions the AEC should make a decision within
174 // |kMaxConvergenceMs| ms. 186 // |kMaxConvergenceMs| ms.
175 // 6) If the local buffer runs out of data we should stuff the buffer with older 187 // 6) If the local buffer runs out of data we should stuff the buffer with older
176 // frames. 188 // frames.
177 // 7) The system delay should within |kMaxConvergenceMs| ms heal from 189 // 7) The system delay should within |kMaxConvergenceMs| ms heal from
178 // disturbances like drift, data glitches, toggling events and outliers. 190 // disturbances like drift, data glitches, toggling events and outliers.
179 // 8) The system delay should never become negative. 191 // 8) The system delay should never become negative.
180 192
181 TEST_F(SystemDelayTest, CorrectIncreaseWhenBufferFarend) { 193 TEST_F(SystemDelayTest, CorrectIncreaseWhenBufferFarend) {
182 // When we add data to the AEC buffer the internal system delay should be 194 // When we add data to the AEC buffer the internal system delay should be
183 // incremented with the same amount as the size of data. 195 // incremented with the same amount as the size of data.
184 for (size_t i = 0; i < kNumSampleRates; i++) { 196 // This process should be independent of DA-AEC and extended_filter mode.
185 Init(kSampleRateHz[i]); 197 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
186 198 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
187 // Loop through a couple of calls to make sure the system delay increments 199 EXPECT_EQ(extended_filter, WebRtcAec_extended_filter_enabled(self_->aec));
188 // correctly. 200 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
189 for (int j = 1; j <= 5; j++) { 201 WebRtcAec_enable_reported_delay(self_->aec, 1 - da_aec);
190 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); 202 EXPECT_EQ(1 - da_aec, WebRtcAec_reported_delay_enabled(self_->aec));
191 EXPECT_EQ(j * samples_per_frame_, WebRtcAec_system_delay(self_->aec)); 203 for (size_t i = 0; i < kNumSampleRates; i++) {
204 Init(kSampleRateHz[i]);
205 // Loop through a couple of calls to make sure the system delay
206 // increments correctly.
207 for (int j = 1; j <= 5; j++) {
208 EXPECT_EQ(0,
209 WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_));
210 EXPECT_EQ(j * samples_per_frame_, WebRtcAec_system_delay(self_->aec));
211 }
212 }
192 } 213 }
193 } 214 }
194 } 215 }
195 216
196 // TODO(bjornv): Add a test to verify behavior if the far-end buffer is full 217 // TODO(bjornv): Add a test to verify behavior if the far-end buffer is full
197 // when adding new data. 218 // when adding new data.
198 219
199 TEST_F(SystemDelayTest, CorrectDelayAfterStableStartup) { 220 TEST_F(SystemDelayTest, CorrectDelayAfterStableStartup) {
200 // We run the system in a stable startup. After that we verify that the system 221 // We run the system in a stable startup. After that we verify that the system
201 // delay meets the requirements. 222 // delay meets the requirements.
202 for (size_t i = 0; i < kNumSampleRates; i++) { 223 // This process should be independent of DA-AEC and extended_filter mode.
203 Init(kSampleRateHz[i]); 224 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
204 RunStableStartup(); 225 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
226 EXPECT_EQ(extended_filter, WebRtcAec_extended_filter_enabled(self_->aec));
227 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
228 WebRtcAec_enable_reported_delay(self_->aec, 1 - da_aec);
229 EXPECT_EQ(1 - da_aec, WebRtcAec_reported_delay_enabled(self_->aec));
230 for (size_t i = 0; i < kNumSampleRates; i++) {
231 Init(kSampleRateHz[i]);
232 RunStableStartup();
205 233
206 // Verify system delay with respect to requirements, i.e., the 234 // Verify system delay with respect to requirements, i.e., the
207 // |system_delay| is in the interval [75%, 100%] of what's reported on the 235 // |system_delay| is in the interval [75%, 100%] of what's reported on
208 // average. 236 // the average.
209 int average_reported_delay = kDeviceBufMs * samples_per_frame_ / 10; 237 // In extended_filter mode we target 50% and measure after one processed
210 EXPECT_GE(average_reported_delay, WebRtcAec_system_delay(self_->aec)); 238 // 10 ms chunk.
211 EXPECT_LE(average_reported_delay * 3 / 4, 239 int average_reported_delay = kDeviceBufMs * samples_per_frame_ / 10;
212 WebRtcAec_system_delay(self_->aec)); 240 EXPECT_GE(average_reported_delay, WebRtcAec_system_delay(self_->aec));
241 int lower_bound = WebRtcAec_extended_filter_enabled(self_->aec)
242 ? average_reported_delay / 2 - samples_per_frame_
243 : average_reported_delay * 3 / 4;
244 EXPECT_LE(lower_bound, WebRtcAec_system_delay(self_->aec));
245 }
246 }
213 } 247 }
214 } 248 }
215 249
216 TEST_F(SystemDelayTest, CorrectDelayAfterUnstableStartup) { 250 TEST_F(SystemDelayTest, CorrectDelayAfterUnstableStartup) {
251 // This test does not apply in extended_filter mode, since we only use the
252 // the first 10 ms chunk to determine a reasonable buffer size. Neither does
253 // it apply if DA-AEC is on because that overrides the startup procedure.
254 WebRtcAec_enable_extended_filter(self_->aec, 0);
255 EXPECT_EQ(0, WebRtcAec_extended_filter_enabled(self_->aec));
256 WebRtcAec_enable_reported_delay(self_->aec, 1);
257 EXPECT_EQ(1, WebRtcAec_reported_delay_enabled(self_->aec));
258
217 // In an unstable system we would start processing after |kMaxConvergenceMs|. 259 // In an unstable system we would start processing after |kMaxConvergenceMs|.
218 // On the last frame the AEC buffer is adjusted to 60% of the last reported 260 // On the last frame the AEC buffer is adjusted to 60% of the last reported
219 // device buffer size. 261 // device buffer size.
220 // We construct an unstable system by altering the device buffer size between 262 // We construct an unstable system by altering the device buffer size between
221 // two values |kDeviceBufMs| +- 25 ms. 263 // two values |kDeviceBufMs| +- 25 ms.
222 for (size_t i = 0; i < kNumSampleRates; i++) { 264 for (size_t i = 0; i < kNumSampleRates; i++) {
223 Init(kSampleRateHz[i]); 265 Init(kSampleRateHz[i]);
224 266
225 // To make sure we have a full buffer when we verify stability we first fill 267 // To make sure we have a full buffer when we verify stability we first fill
226 // up the far-end buffer with the same amount as we will report in on the 268 // up the far-end buffer with the same amount as we will report in on the
(...skipping 20 matching lines...) Expand all
247 289
248 // Verify system delay with respect to requirements, i.e., the 290 // Verify system delay with respect to requirements, i.e., the
249 // |system_delay| is in the interval [60%, 100%] of what's last reported. 291 // |system_delay| is in the interval [60%, 100%] of what's last reported.
250 EXPECT_GE(reported_delay_ms * samples_per_frame_ / 10, 292 EXPECT_GE(reported_delay_ms * samples_per_frame_ / 10,
251 WebRtcAec_system_delay(self_->aec)); 293 WebRtcAec_system_delay(self_->aec));
252 EXPECT_LE(reported_delay_ms * samples_per_frame_ / 10 * 3 / 5, 294 EXPECT_LE(reported_delay_ms * samples_per_frame_ / 10 * 3 / 5,
253 WebRtcAec_system_delay(self_->aec)); 295 WebRtcAec_system_delay(self_->aec));
254 } 296 }
255 } 297 }
256 298
257 TEST_F(SystemDelayTest, 299 TEST_F(SystemDelayTest, CorrectDelayAfterStableBufferBuildUp) {
258 DISABLED_ON_ANDROID(CorrectDelayAfterStableBufferBuildUp)) { 300 // This test does not apply in extended_filter mode, since we only use the
301 // the first 10 ms chunk to determine a reasonable buffer size. Neither does
302 // it apply if DA-AEC is on because that overrides the startup procedure.
303 WebRtcAec_enable_extended_filter(self_->aec, 0);
304 EXPECT_EQ(0, WebRtcAec_extended_filter_enabled(self_->aec));
305 WebRtcAec_enable_reported_delay(self_->aec, 1);
306 EXPECT_EQ(1, WebRtcAec_reported_delay_enabled(self_->aec));
307
259 // In this test we start by establishing the device buffer size during stable 308 // In this test we start by establishing the device buffer size during stable
260 // conditions, but with an empty internal far-end buffer. Once that is done we 309 // conditions, but with an empty internal far-end buffer. Once that is done we
261 // verify that the system delay is increased correctly until we have reach an 310 // verify that the system delay is increased correctly until we have reach an
262 // internal buffer size of 75% of what's been reported. 311 // internal buffer size of 75% of what's been reported.
263
264 // This test assumes the reported delays are used.
265 WebRtcAec_enable_reported_delay(WebRtcAec_aec_core(handle_), 1);
266 for (size_t i = 0; i < kNumSampleRates; i++) { 312 for (size_t i = 0; i < kNumSampleRates; i++) {
267 Init(kSampleRateHz[i]); 313 Init(kSampleRateHz[i]);
268 314
269 // We assume that running |kStableConvergenceMs| calls will put the 315 // We assume that running |kStableConvergenceMs| calls will put the
270 // algorithm in a state where the device buffer size has been determined. We 316 // algorithm in a state where the device buffer size has been determined. We
271 // can make that assumption since we have a separate stability test. 317 // can make that assumption since we have a separate stability test.
272 int process_time_ms = 0; 318 int process_time_ms = 0;
273 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) { 319 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) {
274 EXPECT_EQ(0, 320 EXPECT_EQ(0,
275 WebRtcAec_Process(handle_, 321 WebRtcAec_Process(handle_,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 EXPECT_EQ(system_delay_before_calls, WebRtcAec_system_delay(self_->aec)); 355 EXPECT_EQ(system_delay_before_calls, WebRtcAec_system_delay(self_->aec));
310 } 356 }
311 } 357 }
312 } 358 }
313 359
314 TEST_F(SystemDelayTest, CorrectDelayWhenBufferUnderrun) { 360 TEST_F(SystemDelayTest, CorrectDelayWhenBufferUnderrun) {
315 // Here we test a buffer under run scenario. If we keep on calling 361 // Here we test a buffer under run scenario. If we keep on calling
316 // WebRtcAec_Process() we will finally run out of data, but should 362 // WebRtcAec_Process() we will finally run out of data, but should
317 // automatically stuff the buffer. We verify this behavior by checking if the 363 // automatically stuff the buffer. We verify this behavior by checking if the
318 // system delay goes negative. 364 // system delay goes negative.
319 for (size_t i = 0; i < kNumSampleRates; i++) { 365 // This process should be independent of DA-AEC and extended_filter mode.
320 Init(kSampleRateHz[i]); 366 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
321 RunStableStartup(); 367 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
368 EXPECT_EQ(extended_filter, WebRtcAec_extended_filter_enabled(self_->aec));
369 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
370 WebRtcAec_enable_reported_delay(self_->aec, 1 - da_aec);
371 EXPECT_EQ(1 - da_aec, WebRtcAec_reported_delay_enabled(self_->aec));
372 for (size_t i = 0; i < kNumSampleRates; i++) {
373 Init(kSampleRateHz[i]);
374 RunStableStartup();
322 375
323 // The AEC has now left the Startup phase. We now have at most 376 // The AEC has now left the Startup phase. We now have at most
324 // |kStableConvergenceMs| in the buffer. Keep on calling Process() until 377 // |kStableConvergenceMs| in the buffer. Keep on calling Process() until
325 // we run out of data and verify that the system delay is non-negative. 378 // we run out of data and verify that the system delay is non-negative.
326 for (int j = 0; j <= kStableConvergenceMs; j += 10) { 379 for (int j = 0; j <= kStableConvergenceMs; j += 10) {
327 EXPECT_EQ(0, 380 EXPECT_EQ(0, WebRtcAec_Process(handle_, &near_ptr_, 1, &out_ptr_,
328 WebRtcAec_Process(handle_, 381 samples_per_frame_, kDeviceBufMs, 0));
329 &near_ptr_, 382 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
330 1, 383 }
331 &out_ptr_, 384 }
332 samples_per_frame_,
333 kDeviceBufMs,
334 0));
335 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
336 } 385 }
337 } 386 }
338 } 387 }
339 388
340 TEST_F(SystemDelayTest, DISABLED_ON_ANDROID(CorrectDelayDuringDrift)) { 389 TEST_F(SystemDelayTest, CorrectDelayDuringDrift) {
341 // This drift test should verify that the system delay is never exceeding the 390 // This drift test should verify that the system delay is never exceeding the
342 // device buffer. The drift is simulated by decreasing the reported device 391 // device buffer. The drift is simulated by decreasing the reported device
343 // buffer size by 1 ms every 100 ms. If the device buffer size goes below 30 392 // buffer size by 1 ms every 100 ms. If the device buffer size goes below 30
344 // ms we jump (add) 10 ms to give a repeated pattern. 393 // ms we jump (add) 10 ms to give a repeated pattern.
345 394
346 // This test assumes the reported delays are used. 395 // This process should be independent of DA-AEC and extended_filter mode.
347 WebRtcAec_enable_reported_delay(WebRtcAec_aec_core(handle_), 1); 396 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
348 for (size_t i = 0; i < kNumSampleRates; i++) { 397 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
349 Init(kSampleRateHz[i]); 398 EXPECT_EQ(extended_filter, WebRtcAec_extended_filter_enabled(self_->aec));
350 RunStableStartup(); 399 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
400 WebRtcAec_enable_reported_delay(self_->aec, 1 - da_aec);
401 EXPECT_EQ(1 - da_aec, WebRtcAec_reported_delay_enabled(self_->aec));
402 for (size_t i = 0; i < kNumSampleRates; i++) {
403 Init(kSampleRateHz[i]);
404 RunStableStartup();
351 405
352 // We have now left the startup phase and proceed with normal processing. 406 // We have left the startup phase and proceed with normal processing.
353 int jump = 0; 407 int jump = 0;
354 for (int j = 0; j < 1000; j++) { 408 for (int j = 0; j < 1000; j++) {
355 // Drift = -1 ms per 100 ms of data. 409 // Drift = -1 ms per 100 ms of data.
356 int device_buf_ms = kDeviceBufMs - (j / 10) + jump; 410 int device_buf_ms = kDeviceBufMs - (j / 10) + jump;
357 int device_buf = MapBufferSizeToSamples(device_buf_ms); 411 int device_buf = MapBufferSizeToSamples(device_buf_ms,
412 extended_filter == 1);
358 413
359 if (device_buf_ms < 30) { 414 if (device_buf_ms < 30) {
360 // Add 10 ms data, taking affect next frame. 415 // Add 10 ms data, taking affect next frame.
361 jump += 10; 416 jump += 10;
417 }
418 RenderAndCapture(device_buf_ms);
419
420 // Verify that the system delay does not exceed the device buffer.
421 EXPECT_GE(device_buf, WebRtcAec_system_delay(self_->aec));
422
423 // Verify that the system delay is non-negative.
424 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
425 }
362 } 426 }
363 RenderAndCapture(device_buf_ms);
364
365 // Verify that the system delay does not exceed the device buffer.
366 EXPECT_GE(device_buf, WebRtcAec_system_delay(self_->aec));
367
368 // Verify that the system delay is non-negative.
369 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
370 } 427 }
371 } 428 }
372 } 429 }
373 430
374 TEST_F(SystemDelayTest, DISABLED_ON_ANDROID(ShouldRecoverAfterGlitch)) { 431 TEST_F(SystemDelayTest, ShouldRecoverAfterGlitch) {
375 // This glitch test should verify that the system delay recovers if there is 432 // This glitch test should verify that the system delay recovers if there is
376 // a glitch in data. The data glitch is constructed as 200 ms of buffering 433 // a glitch in data. The data glitch is constructed as 200 ms of buffering
377 // after which the stable procedure continues. The glitch is never reported by 434 // after which the stable procedure continues. The glitch is never reported by
378 // the device. 435 // the device.
379 // The system is said to be in a non-causal state if the difference between 436 // The system is said to be in a non-causal state if the difference between
380 // the device buffer and system delay is less than a block (64 samples). 437 // the device buffer and system delay is less than a block (64 samples).
381 438
382 // This test assumes the reported delays are used. 439 // This process should be independent of DA-AEC and extended_filter mode.
383 WebRtcAec_enable_reported_delay(WebRtcAec_aec_core(handle_), 1); 440 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
384 for (size_t i = 0; i < kNumSampleRates; i++) { 441 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
385 Init(kSampleRateHz[i]); 442 EXPECT_EQ(extended_filter, WebRtcAec_extended_filter_enabled(self_->aec));
386 RunStableStartup(); 443 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
387 int device_buf = MapBufferSizeToSamples(kDeviceBufMs); 444 WebRtcAec_enable_reported_delay(self_->aec, 1 - da_aec);
388 // Glitch state. 445 EXPECT_EQ(1 - da_aec, WebRtcAec_reported_delay_enabled(self_->aec));
389 for (int j = 0; j < 20; j++) { 446 for (size_t i = 0; i < kNumSampleRates; i++) {
390 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); 447 Init(kSampleRateHz[i]);
391 // No need to verify system delay, since that is done in a separate test. 448 RunStableStartup();
449 int device_buf = MapBufferSizeToSamples(kDeviceBufMs,
450 extended_filter == 1);
451 // Glitch state.
452 for (int j = 0; j < 20; j++) {
453 EXPECT_EQ(0,
454 WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_));
455 // No need to verify system delay, since that is done in a separate
456 // test.
457 }
458 // Verify that we are in a non-causal state, i.e.,
459 // |system_delay| > |device_buf|.
460 EXPECT_LT(device_buf, WebRtcAec_system_delay(self_->aec));
461
462 // Recover state. Should recover at least 4 ms of data per 10 ms, hence
463 // a glitch of 200 ms will take at most 200 * 10 / 4 = 500 ms to recover
464 // from.
465 bool non_causal = true; // We are currently in a non-causal state.
466 for (int j = 0; j < 50; j++) {
467 int system_delay_before = WebRtcAec_system_delay(self_->aec);
468 RenderAndCapture(kDeviceBufMs);
469 int system_delay_after = WebRtcAec_system_delay(self_->aec);
470 // We have recovered if
471 // |device_buf| - |system_delay_after| >= PART_LEN (1 block).
472 // During recovery, |system_delay_after| < |system_delay_before|,
473 // otherwise they are equal.
474 if (non_causal) {
475 EXPECT_LT(system_delay_after, system_delay_before);
476 if (device_buf - system_delay_after >= PART_LEN) {
477 non_causal = false;
478 }
479 } else {
480 EXPECT_EQ(system_delay_before, system_delay_after);
481 }
482 // Verify that the system delay is non-negative.
483 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
484 }
485 // Check that we have recovered.
486 EXPECT_FALSE(non_causal);
487 }
392 } 488 }
393 // Verify that we are in a non-causal state, i.e.,
394 // |system_delay| > |device_buf|.
395 EXPECT_LT(device_buf, WebRtcAec_system_delay(self_->aec));
396
397 // Recover state. Should recover at least 4 ms of data per 10 ms, hence a
398 // glitch of 200 ms will take at most 200 * 10 / 4 = 500 ms to recover from.
399 bool non_causal = true; // We are currently in a non-causal state.
400 for (int j = 0; j < 50; j++) {
401 int system_delay_before = WebRtcAec_system_delay(self_->aec);
402 RenderAndCapture(kDeviceBufMs);
403 int system_delay_after = WebRtcAec_system_delay(self_->aec);
404
405 // We have recovered if |device_buf| - |system_delay_after| >= 64 (one
406 // block). During recovery |system_delay_after| < |system_delay_before|,
407 // otherwise they are equal.
408 if (non_causal) {
409 EXPECT_LT(system_delay_after, system_delay_before);
410 if (device_buf - system_delay_after >= 64) {
411 non_causal = false;
412 }
413 } else {
414 EXPECT_EQ(system_delay_before, system_delay_after);
415 }
416 // Verify that the system delay is non-negative.
417 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
418 }
419 // Check that we have recovered.
420 EXPECT_FALSE(non_causal);
421 } 489 }
422 } 490 }
423 491
424 TEST_F(SystemDelayTest, UnaffectedWhenSpuriousDeviceBufferValues) { 492 TEST_F(SystemDelayTest, UnaffectedWhenSpuriousDeviceBufferValues) {
425 // This spurious device buffer data test aims at verifying that the system 493 // This test does not apply in extended_filter mode, since we only use the
426 // delay is unaffected by large outliers. 494 // the first 10 ms chunk to determine a reasonable buffer size.
427 // The system is said to be in a non-causal state if the difference between 495 const int extended_filter = 0;
428 // the device buffer and system delay is less than a block (64 samples). 496 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
429 for (size_t i = 0; i < kNumSampleRates; i++) { 497 EXPECT_EQ(extended_filter, WebRtcAec_extended_filter_enabled(self_->aec));
430 Init(kSampleRateHz[i]);
431 RunStableStartup();
432 int device_buf = MapBufferSizeToSamples(kDeviceBufMs);
433 498
434 // Normal state. We are currently not in a non-causal state. 499 // Should be DA-AEC independent.
435 bool non_causal = false; 500 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
501 WebRtcAec_enable_reported_delay(self_->aec, 1 - da_aec);
502 EXPECT_EQ(1 - da_aec, WebRtcAec_reported_delay_enabled(self_->aec));
503 // This spurious device buffer data test aims at verifying that the system
504 // delay is unaffected by large outliers.
505 // The system is said to be in a non-causal state if the difference between
506 // the device buffer and system delay is less than a block (64 samples).
507 for (size_t i = 0; i < kNumSampleRates; i++) {
508 Init(kSampleRateHz[i]);
509 RunStableStartup();
510 int device_buf = MapBufferSizeToSamples(kDeviceBufMs,
511 extended_filter == 1);
436 512
437 // Run 1 s and replace device buffer size with 500 ms every 100 ms. 513 // Normal state. We are currently not in a non-causal state.
438 for (int j = 0; j < 100; j++) { 514 bool non_causal = false;
439 int system_delay_before_calls = WebRtcAec_system_delay(self_->aec); 515
440 int device_buf_ms = kDeviceBufMs; 516 // Run 1 s and replace device buffer size with 500 ms every 100 ms.
441 if (j % 10 == 0) { 517 for (int j = 0; j < 100; j++) {
442 device_buf_ms = 500; 518 int system_delay_before_calls = WebRtcAec_system_delay(self_->aec);
519 int device_buf_ms = j % 10 == 0 ? 500 : kDeviceBufMs;
520 RenderAndCapture(device_buf_ms);
521
522 // Check for non-causality.
523 if (device_buf - WebRtcAec_system_delay(self_->aec) < PART_LEN) {
524 non_causal = true;
525 }
526 EXPECT_FALSE(non_causal);
527 EXPECT_EQ(system_delay_before_calls,
528 WebRtcAec_system_delay(self_->aec));
529
530 // Verify that the system delay is non-negative.
531 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
443 } 532 }
444 RenderAndCapture(device_buf_ms);
445
446 // Check for non-causality.
447 if (device_buf - WebRtcAec_system_delay(self_->aec) < 64) {
448 non_causal = true;
449 }
450 EXPECT_FALSE(non_causal);
451 EXPECT_EQ(system_delay_before_calls, WebRtcAec_system_delay(self_->aec));
452
453 // Verify that the system delay is non-negative.
454 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
455 } 533 }
456 } 534 }
457 } 535 }
458 536
459 TEST_F(SystemDelayTest, CorrectImpactWhenTogglingDeviceBufferValues) { 537 TEST_F(SystemDelayTest, CorrectImpactWhenTogglingDeviceBufferValues) {
460 // This test aims at verifying that the system delay is "unaffected" by 538 // This test aims at verifying that the system delay is "unaffected" by
461 // toggling values reported by the device. 539 // toggling values reported by the device.
462 // The test is constructed such that every other device buffer value is zero 540 // The test is constructed such that every other device buffer value is zero
463 // and then 2 * |kDeviceBufMs|, hence the size is constant on the average. The 541 // and then 2 * |kDeviceBufMs|, hence the size is constant on the average. The
464 // zero values will force us into a non-causal state and thereby lowering the 542 // zero values will force us into a non-causal state and thereby lowering the
465 // system delay until we basically runs out of data. Once that happens the 543 // system delay until we basically run out of data. Once that happens the
466 // buffer will be stuffed. 544 // buffer will be stuffed.
467 // TODO(bjornv): This test will have a better impact if we verified that the 545 // TODO(bjornv): This test will have a better impact if we verified that the
468 // delay estimate goes up when the system delay goes done to meet the average 546 // delay estimate goes up when the system delay goes down to meet the average
469 // device buffer size. 547 // device buffer size.
470 for (size_t i = 0; i < kNumSampleRates; i++) {
471 Init(kSampleRateHz[i]);
472 RunStableStartup();
473 int device_buf = MapBufferSizeToSamples(kDeviceBufMs);
474 548
475 // Normal state. We are currently not in a non-causal state. 549 // This test does not apply if DA-AEC is enabled and extended_filter mode
476 bool non_causal = false; 550 // disabled.
551 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
552 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
553 EXPECT_EQ(extended_filter, WebRtcAec_extended_filter_enabled(self_->aec));
554 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
555 WebRtcAec_enable_reported_delay(self_->aec, 1 - da_aec);
556 EXPECT_EQ(1 - da_aec, WebRtcAec_reported_delay_enabled(self_->aec));
557 if (extended_filter == 0 && da_aec == 1) {
558 continue;
559 }
560 for (size_t i = 0; i < kNumSampleRates; i++) {
561 Init(kSampleRateHz[i]);
562 RunStableStartup();
563 const int device_buf = MapBufferSizeToSamples(kDeviceBufMs,
564 extended_filter == 1);
477 565
478 // Loop through 100 frames (both render and capture), which equals 1 s of 566 // Normal state. We are currently not in a non-causal state.
479 // data. Every odd frame we set the device buffer size to 2 * |kDeviceBufMs| 567 bool non_causal = false;
480 // and even frames we set the device buffer size to zero.
481 for (int j = 0; j < 100; j++) {
482 int system_delay_before_calls = WebRtcAec_system_delay(self_->aec);
483 int device_buf_ms = 2 * (j % 2) * kDeviceBufMs;
484 RenderAndCapture(device_buf_ms);
485 568
486 // Check for non-causality, compared with the average device buffer size. 569 // Loop through 100 frames (both render and capture), which equals 1 s
487 non_causal |= (device_buf - WebRtcAec_system_delay(self_->aec) < 64); 570 // of data. Every odd frame we set the device buffer size to
488 EXPECT_GE(system_delay_before_calls, WebRtcAec_system_delay(self_->aec)); 571 // 2 * |kDeviceBufMs| and even frames we set the device buffer size to
572 // zero.
573 for (int j = 0; j < 100; j++) {
574 int system_delay_before_calls = WebRtcAec_system_delay(self_->aec);
575 int device_buf_ms = 2 * (j % 2) * kDeviceBufMs;
576 RenderAndCapture(device_buf_ms);
489 577
490 // Verify that the system delay is non-negative. 578 // Check for non-causality, compared with the average device buffer
491 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); 579 // size.
580 non_causal |= (device_buf - WebRtcAec_system_delay(self_->aec) < 64);
581 EXPECT_GE(system_delay_before_calls,
582 WebRtcAec_system_delay(self_->aec));
583
584 // Verify that the system delay is non-negative.
585 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
586 }
587 // Verify we are not in a non-causal state.
588 EXPECT_FALSE(non_causal);
589 }
492 } 590 }
493 // Verify we are not in a non-causal state.
494 EXPECT_FALSE(non_causal);
495 } 591 }
496 } 592 }
497 593
498 } // namespace 594 } // namespace
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/aec/echo_cancellation.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698