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

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

Issue 2644123002: Adding full initial version of delay estimation functionality in echo canceller 3 (Closed)
Patch Set: Rebase Created 3 years, 10 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
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 <sstream> 14 #include <sstream>
14 #include <string> 15 #include <string>
15 16
17 #include "webrtc/base/random.h"
16 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" 18 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h"
17 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" 19 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
20 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h"
18 #include "webrtc/test/gtest.h" 21 #include "webrtc/test/gtest.h"
19 22
20 namespace webrtc { 23 namespace webrtc {
21 namespace { 24 namespace {
22 25
23 std::string ProduceDebugText(int sample_rate_hz) { 26 std::string ProduceDebugText(size_t delay) {
24 std::ostringstream ss; 27 std::ostringstream ss;
25 ss << "Sample rate: " << sample_rate_hz; 28 ss << "Delay: " << delay;
26 return ss.str(); 29 return ss.str();
27 } 30 }
28 31
29 } // namespace 32 } // namespace
30 33
31 // Verifies that the basic API calls work. 34 // Verifies that the basic API calls work.
32 TEST(EchoPathDelayEstimator, BasicApiCalls) { 35 TEST(EchoPathDelayEstimator, BasicApiCalls) {
33 for (auto rate : {8000, 16000, 32000, 48000}) { 36 ApmDataDumper data_dumper(0);
34 ProduceDebugText(rate); 37 EchoPathDelayEstimator estimator(&data_dumper);
35 ApmDataDumper data_dumper(0); 38 std::vector<float> render(kBlockSize, 0.f);
36 EchoPathDelayEstimator estimator(&data_dumper, rate); 39 std::vector<float> capture(kBlockSize, 0.f);
37 std::vector<float> render(kBlockSize, 0.f); 40 for (size_t k = 0; k < 100; ++k) {
38 std::vector<float> capture(kBlockSize, 0.f); 41 estimator.EstimateDelay(render, capture);
39 for (size_t k = 0; k < 100; ++k) { 42 }
40 estimator.EstimateDelay(render, capture); 43 }
44
45 // Verifies that the delay estimator produces correct delay for artificially
46 // delayed signals.
47 TEST(EchoPathDelayEstimator, DelayEstimation) {
48 Random random_generator(42U);
49 std::vector<float> render(kBlockSize, 0.f);
50 std::vector<float> capture(kBlockSize, 0.f);
51 ApmDataDumper data_dumper(0);
52 for (size_t delay_samples : {0, 64, 150, 200, 800, 4000}) {
53 SCOPED_TRACE(ProduceDebugText(delay_samples));
54 DelayBuffer<float> signal_delay_buffer(delay_samples);
55 EchoPathDelayEstimator estimator(&data_dumper);
56
57 rtc::Optional<size_t> estimated_delay_samples;
58 for (size_t k = 0; k < (100 + delay_samples / kBlockSize); ++k) {
59 RandomizeSampleVector(&random_generator, render);
60 signal_delay_buffer.Delay(render, capture);
61 estimated_delay_samples = estimator.EstimateDelay(render, capture);
41 } 62 }
63 if (estimated_delay_samples) {
64 // 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
66 // the true delay.
67 EXPECT_NEAR(delay_samples, *estimated_delay_samples, 4);
68 } else {
69 ADD_FAILURE();
70 }
71 }
72 }
73
74 // Verifies that the delay estimator does not produce delay estimates too
75 // quickly.
76 TEST(EchoPathDelayEstimator, NoInitialDelayestimates) {
77 Random random_generator(42U);
78 std::vector<float> render(kBlockSize, 0.f);
79 std::vector<float> capture(kBlockSize, 0.f);
80 ApmDataDumper data_dumper(0);
81
82 EchoPathDelayEstimator estimator(&data_dumper);
83 for (size_t k = 0; k < 19; ++k) {
84 RandomizeSampleVector(&random_generator, render);
85 std::copy(render.begin(), render.end(), capture.begin());
86 EXPECT_FALSE(estimator.EstimateDelay(render, capture));
87 }
88 }
89
90 // Verifies that the delay estimator does not produce delay estimates for render
91 // signals of low level.
92 TEST(EchoPathDelayEstimator, NoDelayEstimatesForLowLevelRenderSignals) {
93 Random random_generator(42U);
94 std::vector<float> render(kBlockSize, 0.f);
95 std::vector<float> capture(kBlockSize, 0.f);
96 ApmDataDumper data_dumper(0);
97 EchoPathDelayEstimator estimator(&data_dumper);
98 for (size_t k = 0; k < 100; ++k) {
99 RandomizeSampleVector(&random_generator, render);
100 for (auto& render_k : render) {
101 render_k *= 100.f / 32767.f;
102 }
103 std::copy(render.begin(), render.end(), capture.begin());
104 EXPECT_FALSE(estimator.EstimateDelay(render, capture));
105 }
106 }
107
108 // Verifies that the delay estimator does not produce delay estimates for
109 // uncorrelated signals.
110 TEST(EchoPathDelayEstimator, NoDelayEstimatesForUncorrelatedSignals) {
111 Random random_generator(42U);
112 std::vector<float> render(kBlockSize, 0.f);
113 std::vector<float> capture(kBlockSize, 0.f);
114 ApmDataDumper data_dumper(0);
115 EchoPathDelayEstimator estimator(&data_dumper);
116 for (size_t k = 0; k < 100; ++k) {
117 RandomizeSampleVector(&random_generator, render);
118 RandomizeSampleVector(&random_generator, capture);
119 EXPECT_FALSE(estimator.EstimateDelay(render, capture));
42 } 120 }
43 } 121 }
44 122
45 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 123 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
46 124
47 // Verifies the check for correct sample rate.
48 TEST(EchoPathDelayEstimator, WrongSampleRate) {
49 ApmDataDumper data_dumper(0);
50 EXPECT_DEATH(EchoPathDelayEstimator remover(&data_dumper, 8001), "");
51 }
52
53 // Verifies the check for the render blocksize. 125 // Verifies the check for the render blocksize.
54 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH 126 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH
55 // tests on test bots has been fixed. 127 // tests on test bots has been fixed.
56 TEST(EchoPathDelayEstimator, DISABLED_WrongRenderBlockSize) { 128 TEST(EchoPathDelayEstimator, DISABLED_WrongRenderBlockSize) {
57 for (auto rate : {8000, 16000, 32000, 48000}) { 129 ApmDataDumper data_dumper(0);
58 ProduceDebugText(rate); 130 EchoPathDelayEstimator estimator(&data_dumper);
59 ApmDataDumper data_dumper(0); 131 std::vector<float> render(std::vector<float>(kBlockSize - 1, 0.f));
60 EchoPathDelayEstimator estimator(&data_dumper, rate); 132 std::vector<float> capture(std::vector<float>(kBlockSize, 0.f));
61 std::vector<float> render(kBlockSize - 1, 0.f); 133 EXPECT_DEATH(estimator.EstimateDelay(render, capture), "");
62 std::vector<float> capture(kBlockSize, 0.f);
63 EXPECT_DEATH(estimator.EstimateDelay(render, capture), "");
64 }
65 } 134 }
66 135
67 // Verifies the check for the capture blocksize. 136 // Verifies the check for the capture blocksize.
68 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH 137 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH
69 // tests on test bots has been fixed. 138 // tests on test bots has been fixed.
70 TEST(EchoPathDelayEstimator, DISABLED_WrongCaptureBlockSize) { 139 TEST(EchoPathDelayEstimator, WrongCaptureBlockSize) {
71 for (auto rate : {8000, 16000, 32000, 48000}) { 140 ApmDataDumper data_dumper(0);
72 ProduceDebugText(rate); 141 EchoPathDelayEstimator estimator(&data_dumper);
73 ApmDataDumper data_dumper(0); 142 std::vector<float> render(std::vector<float>(kBlockSize, 0.f));
74 EchoPathDelayEstimator estimator(&data_dumper, rate); 143 std::vector<float> capture(std::vector<float>(kBlockSize - 1, 0.f));
75 std::vector<float> render(kBlockSize, 0.f); 144 EXPECT_DEATH(estimator.EstimateDelay(render, capture), "");
76 std::vector<float> capture(kBlockSize - 1, 0.f);
77 EXPECT_DEATH(estimator.EstimateDelay(render, capture), "");
78 }
79 } 145 }
80 146
81 // Verifies the check for non-null data dumper. 147 // Verifies the check for non-null data dumper.
82 TEST(EchoPathDelayEstimator, NullDataDumper) { 148 TEST(EchoPathDelayEstimator, NullDataDumper) {
83 EXPECT_DEATH(EchoPathDelayEstimator(nullptr, 8000), ""); 149 EXPECT_DEATH(EchoPathDelayEstimator(nullptr), "");
84 } 150 }
85 151
86 #endif 152 #endif
87 153
88 } // namespace webrtc 154 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698