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

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: Created 3 years, 11 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
74 EXPECT_TRUE(estimated_delay_samples);
hlundin-webrtc 2017/02/01 08:30:02 ASSERT_TRUE, or the below "dereferencing" will cra
peah-webrtc 2017/02/02 14:04:47 Great suggestion! Done.
75 EXPECT_NEAR(delay_samples, *estimated_delay_samples, 4);
76 }
77 }
78 }
79
80 // Verifies that the delay estimator does not produce delay estimates too
81 // quickly.
82 TEST(EchoPathDelayEstimator, NoInitialDelayestimates) {
83 Random random_generator(42U);
84 std::vector<float> render(kBlockSize, 0.f);
85 std::vector<float> capture(kBlockSize, 0.f);
86 ApmDataDumper data_dumper(0);
87 for (auto rate : {8000, 16000, 32000, 48000}) {
88 SCOPED_TRACE(ProduceDebugText(rate));
89 EchoPathDelayEstimator estimator(&data_dumper, rate);
90 for (size_t k = 0; k < 19; ++k) {
91 RandomizeSampleVector(&random_generator, render);
92 std::copy(render.begin(), render.end(), capture.begin());
93 EXPECT_FALSE(estimator.EstimateDelay(render, capture));
94 }
95 }
96 }
97
98 // Verifies that the delay estimator does not produce delay estimates for render
99 // signals of low level.
100 TEST(EchoPathDelayEstimator, NoDelayEstimatesForLowLevelRenderSignals) {
101 Random random_generator(42U);
102 std::vector<float> render(kBlockSize, 0.f);
103 std::vector<float> capture(kBlockSize, 0.f);
104 ApmDataDumper data_dumper(0);
105 for (auto rate : {8000, 16000, 32000, 48000}) {
106 SCOPED_TRACE(ProduceDebugText(rate));
107 EchoPathDelayEstimator estimator(&data_dumper, rate);
108 for (size_t k = 0; k < 100; ++k) {
109 RandomizeSampleVector(&random_generator, render);
110 for (auto& render_k : render) {
111 render_k *= 100.f / 32767.f;
112 }
113 std::copy(render.begin(), render.end(), capture.begin());
114 EXPECT_FALSE(estimator.EstimateDelay(render, capture));
115 }
116 }
117 }
118
119 // Verifies that the delay estimator does not produce delay estimates for
120 // uncorrelated signals.
121 TEST(EchoPathDelayEstimator, NoDelayEstimatesForUncorrelatedSignals) {
122 Random random_generator(42U);
123 std::vector<float> render(kBlockSize, 0.f);
124 std::vector<float> capture(kBlockSize, 0.f);
125 ApmDataDumper data_dumper(0);
126 for (auto rate : {8000, 16000, 32000, 48000}) {
127 SCOPED_TRACE(ProduceDebugText(rate));
128 EchoPathDelayEstimator estimator(&data_dumper, rate);
129 for (size_t k = 0; k < 100; ++k) {
130 RandomizeSampleVector(&random_generator, render);
131 RandomizeSampleVector(&random_generator, capture);
132 EXPECT_FALSE(estimator.EstimateDelay(render, capture));
133 }
134 }
135 }
136
45 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 137 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
46 138
47 // Verifies the check for correct sample rate. 139 // Verifies the check for correct sample rate.
48 TEST(EchoPathDelayEstimator, WrongSampleRate) { 140 TEST(EchoPathDelayEstimator, WrongSampleRate) {
49 ApmDataDumper data_dumper(0); 141 ApmDataDumper data_dumper(0);
50 EXPECT_DEATH(EchoPathDelayEstimator remover(&data_dumper, 8001), ""); 142 EXPECT_DEATH(EchoPathDelayEstimator(&data_dumper, 8001), "");
51 } 143 }
52 144
53 // Verifies the check for the render blocksize. 145 // Verifies the check for the render blocksize.
54 TEST(EchoPathDelayEstimator, WrongRenderBlockSize) { 146 TEST(EchoPathDelayEstimator, WrongRenderBlockSize) {
55 for (auto rate : {8000, 16000, 32000, 48000}) { 147 for (auto rate : {8000, 16000, 32000, 48000}) {
56 ProduceDebugText(rate); 148 ProduceDebugText(rate);
57 ApmDataDumper data_dumper(0); 149 ApmDataDumper data_dumper(0);
58 EchoPathDelayEstimator estimator(&data_dumper, rate); 150 EchoPathDelayEstimator estimator(&data_dumper, rate);
59 std::vector<float> render(std::vector<float>(kBlockSize - 1, 0.f)); 151 std::vector<float> render(std::vector<float>(kBlockSize - 1, 0.f));
60 std::vector<float> capture(std::vector<float>(kBlockSize, 0.f)); 152 std::vector<float> capture(std::vector<float>(kBlockSize, 0.f));
(...skipping 14 matching lines...) Expand all
75 } 167 }
76 168
77 // Verifies the check for non-null data dumper. 169 // Verifies the check for non-null data dumper.
78 TEST(EchoPathDelayEstimator, NullDataDumper) { 170 TEST(EchoPathDelayEstimator, NullDataDumper) {
79 EXPECT_DEATH(EchoPathDelayEstimator(nullptr, 8000), ""); 171 EXPECT_DEATH(EchoPathDelayEstimator(nullptr, 8000), "");
80 } 172 }
81 173
82 #endif 174 #endif
83 175
84 } // namespace webrtc 176 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698