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

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

Issue 2678423005: Finalization of the first version of EchoCanceller 3 (Closed)
Patch Set: 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
(Empty)
1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_processing/aec3/subtractor.h"
12
13 #include <algorithm>
14 #include <numeric>
15 #include <string>
16
17 #include "webrtc/base/random.h"
18 #include "webrtc/modules/audio_processing/aec3/delay_handler.h"
19 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h"
20 #include "webrtc/test/gtest.h"
21
22 namespace webrtc {
23 namespace {
24
25 void RunSubtractorTest(int num_blocks_to_process,
aleloi 2017/02/13 16:44:51 I can't find a reason for why echo_to_nearend_powe
peah-webrtc 2017/02/20 07:37:19 Done.
26 int delay_samples,
27 bool uncorrelated_inputs,
28 const std::vector<int>& blocks_with_echo_path_changes,
29 float* echo_to_nearend_power) {
30 ApmDataDumper data_dumper(42);
31 Subtractor subtractor(&data_dumper);
32 std::vector<float> x(kBlockSize, 0.f);
33 std::vector<float> y(kBlockSize, 0.f);
34 std::array<float, kBlockSize> x_old;
35 SubtractorOutput output;
36 FftBuffer X_buffer(
37 subtractor.MinFarendBufferLength(),
38 std::vector<size_t>(1, subtractor.MinFarendBufferLength()));
39 RenderSignalAnalyzer render_signal_analyzer;
40 Random random_generator(42U);
41 Aec3Fft fft;
42 FftData X;
43 DelayHandler delay_handler;
44 x_old.fill(0.f);
45
46 DelayBuffer<float> delay_buffer(delay_samples);
47 for (int k = 0; k < num_blocks_to_process; ++k) {
48 RandomizeSampleVector(&random_generator, x);
49 if (uncorrelated_inputs) {
50 RandomizeSampleVector(&random_generator, y);
51 } else {
52 delay_buffer.Delay(x, y);
53 }
54 fft.PaddedFft(x, x_old, &X);
55 X_buffer.Insert(X);
56 render_signal_analyzer.Update(X_buffer, delay_handler.FilterDelay());
57
58 // Handle echo path changes.
59 if (std::find(blocks_with_echo_path_changes.begin(),
60 blocks_with_echo_path_changes.end(),
61 k) != blocks_with_echo_path_changes.end()) {
62 subtractor.HandleEchoPathChange(EchoPathVariability(true, true));
63 }
64 subtractor.Process(X_buffer, y, render_signal_analyzer, false, &output);
65
66 delay_handler.UpdateDelays(
67 subtractor.FilterFrequencyResponse(),
68 rtc::Optional<size_t>(delay_samples / kBlockSize));
69 }
70
71 float output_power = std::inner_product(
72 output.e_main.begin(), output.e_main.end(), output.e_main.begin(), 0.f);
73 float y_power = std::inner_product(y.begin(), y.end(), y.begin(), 0.f);
aleloi 2017/02/13 16:44:51 const float *_power
peah-webrtc 2017/02/20 07:37:19 Done.
74 ASSERT_LT(0.f, y_power);
75 *echo_to_nearend_power = output_power / y_power;
76 }
77
78 std::string ProduceDebugText(size_t delay) {
79 std::ostringstream ss;
80 ss << "Delay: " << delay;
81 return ss.str();
82 }
83
84 } // namespace
85
86 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
87
88 // Verifies that the check for non data dumper works.
89 TEST(Subtractor, NullDataDumper) {
90 EXPECT_DEATH(Subtractor(nullptr), "");
91 }
92
93 // Verifies the check for null subtractor output.
94 TEST(Subtractor, NullOutput) {
95 ApmDataDumper data_dumper(42);
96 Subtractor subtractor(&data_dumper);
97 FftBuffer X_buffer(
98 subtractor.MinFarendBufferLength(),
99 std::vector<size_t>(1, subtractor.MinFarendBufferLength()));
100 RenderSignalAnalyzer render_signal_analyzer;
101 std::vector<float> y(kBlockSize, 0.f);
102
103 EXPECT_DEATH(
104 subtractor.Process(X_buffer, y, render_signal_analyzer, false, nullptr),
105 "");
106 }
107
108 // Verifies the check for the capture signal size.
109 TEST(Subtractor, WrongCaptureSize) {
110 ApmDataDumper data_dumper(42);
111 Subtractor subtractor(&data_dumper);
112 FftBuffer X_buffer(
113 subtractor.MinFarendBufferLength(),
114 std::vector<size_t>(1, subtractor.MinFarendBufferLength()));
115 RenderSignalAnalyzer render_signal_analyzer;
116 std::vector<float> y(kBlockSize - 1, 0.f);
117 SubtractorOutput output;
118
119 EXPECT_DEATH(
120 subtractor.Process(X_buffer, y, render_signal_analyzer, false, &output),
121 "");
122 }
123
124 #endif
125
126 // Verifies that the subtractor is able to converge on correlated data.
127 TEST(Subtractor, Convergence) {
128 std::vector<int> blocks_with_echo_path_changes;
129 // blocks_with_echo_path_changes.push_back(99);
aleloi 2017/02/13 16:44:51 remove comment
peah-webrtc 2017/02/20 07:37:19 Done.
130 for (size_t delay_samples : {0, 64, 150, 200, 301}) {
131 SCOPED_TRACE(ProduceDebugText(delay_samples));
132
133 float echo_to_nearend_power;
134 RunSubtractorTest(100, delay_samples, false, blocks_with_echo_path_changes,
135 &echo_to_nearend_power);
136 EXPECT_GT(0.1f, echo_to_nearend_power);
137 }
138 }
139
140 // Verifies that the subtractor does not converge on uncorrelated signals.
141 TEST(Subtractor, NonConvergenceOnUncorrelatedSignals) {
142 std::vector<int> blocks_with_echo_path_changes;
143 // blocks_with_echo_path_changes.push_back(99);
aleloi 2017/02/13 16:44:51 remove comment
peah-webrtc 2017/02/20 07:37:19 Done.
144 for (size_t delay_samples : {0, 64, 150, 200, 301}) {
145 SCOPED_TRACE(ProduceDebugText(delay_samples));
146
147 float echo_to_nearend_power;
148 RunSubtractorTest(100, delay_samples, true, blocks_with_echo_path_changes,
149 &echo_to_nearend_power);
150 EXPECT_LT(0.95f, echo_to_nearend_power);
151 EXPECT_GT(1.05f, echo_to_nearend_power);
aleloi 2017/02/13 16:44:51 I think EXPECT_NEAR(a, b, 0.05f) can be used here.
peah-webrtc 2017/02/20 07:37:19 Done.
152 }
153 }
154
155 // Verifies that the subtractor is properly reset when there is an echo path
156 // change.
157 TEST(Subtractor, EchoPathChangeReset) {
158 std::vector<int> blocks_with_echo_path_changes;
159 blocks_with_echo_path_changes.push_back(99);
160 for (size_t delay_samples : {0, 64, 150, 200, 301}) {
161 SCOPED_TRACE(ProduceDebugText(delay_samples));
162
163 float echo_to_nearend_power;
164 RunSubtractorTest(100, delay_samples, false, blocks_with_echo_path_changes,
165 &echo_to_nearend_power);
166 EXPECT_EQ(1.f, echo_to_nearend_power);
aleloi 2017/02/13 16:44:51 Does EXPECT_EQ use exact comparison for floats? Ma
peah-webrtc 2017/02/21 23:00:39 Done.
167 }
168 }
169
170 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698