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

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: Changes in response to reviewer comments 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(int sample_rate_hz) {
24 std::ostringstream ss; 27 std::ostringstream ss;
25 ss << "Sample rate: " << sample_rate_hz; 28 ss << "Sample rate: " << sample_rate_hz;
26 return ss.str(); 29 return ss.str();
27 } 30 }
28 31
32 std::string ProduceDebugText(int sample_rate_hz, size_t delay) {
33 std::ostringstream ss(ProduceDebugText(sample_rate_hz));
34 ss << ", Delay: " << delay;
35 return ss.str();
36 }
37
29 } // namespace 38 } // namespace
30 39
31 // Verifies that the basic API calls work. 40 // Verifies that the basic API calls work.
32 TEST(EchoPathDelayEstimator, BasicApiCalls) { 41 TEST(EchoPathDelayEstimator, BasicApiCalls) {
33 for (auto rate : {8000, 16000, 32000, 48000}) { 42 for (auto rate : {8000, 16000, 32000, 48000}) {
34 ProduceDebugText(rate); 43 ProduceDebugText(rate);
35 ApmDataDumper data_dumper(0); 44 ApmDataDumper data_dumper(0);
36 EchoPathDelayEstimator estimator(&data_dumper, rate); 45 EchoPathDelayEstimator estimator(&data_dumper, rate);
37 std::vector<float> render(std::vector<float>(kBlockSize, 0.f)); 46 std::vector<float> render(std::vector<float>(kBlockSize, 0.f));
38 std::vector<float> capture(std::vector<float>(kBlockSize, 0.f)); 47 std::vector<float> capture(std::vector<float>(kBlockSize, 0.f));
39 for (size_t k = 0; k < 100; ++k) { 48 for (size_t k = 0; k < 100; ++k) {
40 estimator.EstimateDelay(render, capture); 49 estimator.EstimateDelay(render, capture);
41 } 50 }
42 } 51 }
43 } 52 }
44 53
54 // Verifies that the delay estimator produces correct delay for artificially
55 // delayed signals.
56 TEST(EchoPathDelayEstimator, DelayEstimation) {
57 Random random_generator(42U);
58 std::vector<float> render(kBlockSize, 0.f);
59 std::vector<float> capture(kBlockSize, 0.f);
60 ApmDataDumper data_dumper(0);
61 for (auto rate : {8000, 16000, 32000, 48000}) {
62 for (size_t delay_samples : {0, 64, 150, 200, 800, 4000}) {
63 SCOPED_TRACE(ProduceDebugText(rate, delay_samples));
64 DelayBuffer<float> signal_delay_buffer(delay_samples);
65 EchoPathDelayEstimator estimator(&data_dumper, rate);
66
67 rtc::Optional<size_t> estimated_delay_samples;
68 for (size_t k = 0; k < (100 + delay_samples / kBlockSize); ++k) {
69 RandomizeSampleVector(&random_generator, render);
70 signal_delay_buffer.Delay(render, capture);
71 estimated_delay_samples = estimator.EstimateDelay(render, capture);
72 }
73 if (estimated_delay_samples) {
74 EXPECT_NEAR(delay_samples, *estimated_delay_samples, 4);
aleloi 2017/02/03 15:46:48 Is the 4 here because of the down sampling factor?
peah-webrtc 2017/02/06 11:25:39 Yes, that is the reason. I added a comment to cla
75 } else {
76 ADD_FAILURE();
77 }
78 }
79 }
80 }
81
82 // Verifies that the delay estimator does not produce delay estimates too
83 // quickly.
84 TEST(EchoPathDelayEstimator, NoInitialDelayestimates) {
85 Random random_generator(42U);
86 std::vector<float> render(kBlockSize, 0.f);
87 std::vector<float> capture(kBlockSize, 0.f);
88 ApmDataDumper data_dumper(0);
89 for (auto rate : {8000, 16000, 32000, 48000}) {
90 SCOPED_TRACE(ProduceDebugText(rate));
91 EchoPathDelayEstimator estimator(&data_dumper, rate);
92 for (size_t k = 0; k < 19; ++k) {
93 RandomizeSampleVector(&random_generator, render);
94 std::copy(render.begin(), render.end(), capture.begin());
95 EXPECT_FALSE(estimator.EstimateDelay(render, capture));
96 }
97 }
98 }
99
100 // Verifies that the delay estimator does not produce delay estimates for render
101 // signals of low level.
102 TEST(EchoPathDelayEstimator, NoDelayEstimatesForLowLevelRenderSignals) {
103 Random random_generator(42U);
104 std::vector<float> render(kBlockSize, 0.f);
105 std::vector<float> capture(kBlockSize, 0.f);
106 ApmDataDumper data_dumper(0);
107 for (auto rate : {8000, 16000, 32000, 48000}) {
108 SCOPED_TRACE(ProduceDebugText(rate));
109 EchoPathDelayEstimator estimator(&data_dumper, rate);
110 for (size_t k = 0; k < 100; ++k) {
111 RandomizeSampleVector(&random_generator, render);
112 for (auto& render_k : render) {
113 render_k *= 100.f / 32767.f;
114 }
115 std::copy(render.begin(), render.end(), capture.begin());
116 EXPECT_FALSE(estimator.EstimateDelay(render, capture));
117 }
118 }
119 }
120
121 // Verifies that the delay estimator does not produce delay estimates for
122 // uncorrelated signals.
123 TEST(EchoPathDelayEstimator, NoDelayEstimatesForUncorrelatedSignals) {
124 Random random_generator(42U);
125 std::vector<float> render(kBlockSize, 0.f);
126 std::vector<float> capture(kBlockSize, 0.f);
127 ApmDataDumper data_dumper(0);
128 for (auto rate : {8000, 16000, 32000, 48000}) {
129 SCOPED_TRACE(ProduceDebugText(rate));
130 EchoPathDelayEstimator estimator(&data_dumper, rate);
131 for (size_t k = 0; k < 100; ++k) {
132 RandomizeSampleVector(&random_generator, render);
133 RandomizeSampleVector(&random_generator, capture);
134 EXPECT_FALSE(estimator.EstimateDelay(render, capture));
135 }
136 }
137 }
138
45 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 139 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
46 140
47 // Verifies the check for correct sample rate. 141 // Verifies the check for correct sample rate.
48 TEST(EchoPathDelayEstimator, WrongSampleRate) { 142 TEST(EchoPathDelayEstimator, WrongSampleRate) {
49 ApmDataDumper data_dumper(0); 143 ApmDataDumper data_dumper(0);
50 EXPECT_DEATH(EchoPathDelayEstimator remover(&data_dumper, 8001), ""); 144 EXPECT_DEATH(EchoPathDelayEstimator(&data_dumper, 8001), "");
51 } 145 }
52 146
53 // Verifies the check for the render blocksize. 147 // Verifies the check for the render blocksize.
54 TEST(EchoPathDelayEstimator, WrongRenderBlockSize) { 148 TEST(EchoPathDelayEstimator, WrongRenderBlockSize) {
55 for (auto rate : {8000, 16000, 32000, 48000}) { 149 for (auto rate : {8000, 16000, 32000, 48000}) {
56 ProduceDebugText(rate); 150 ProduceDebugText(rate);
57 ApmDataDumper data_dumper(0); 151 ApmDataDumper data_dumper(0);
58 EchoPathDelayEstimator estimator(&data_dumper, rate); 152 EchoPathDelayEstimator estimator(&data_dumper, rate);
59 std::vector<float> render(std::vector<float>(kBlockSize - 1, 0.f)); 153 std::vector<float> render(std::vector<float>(kBlockSize - 1, 0.f));
60 std::vector<float> capture(std::vector<float>(kBlockSize, 0.f)); 154 std::vector<float> capture(std::vector<float>(kBlockSize, 0.f));
(...skipping 14 matching lines...) Expand all
75 } 169 }
76 170
77 // Verifies the check for non-null data dumper. 171 // Verifies the check for non-null data dumper.
78 TEST(EchoPathDelayEstimator, NullDataDumper) { 172 TEST(EchoPathDelayEstimator, NullDataDumper) {
79 EXPECT_DEATH(EchoPathDelayEstimator(nullptr, 8000), ""); 173 EXPECT_DEATH(EchoPathDelayEstimator(nullptr, 8000), "");
80 } 174 }
81 175
82 #endif 176 #endif
83 177
84 } // namespace webrtc 178 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698