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

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: Fixed compilation error Created 3 years, 9 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/aec_state.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 float RunSubtractorTest(int num_blocks_to_process,
26 int delay_samples,
27 bool uncorrelated_inputs,
28 const std::vector<int>& blocks_with_echo_path_changes) {
29 ApmDataDumper data_dumper(42);
30 Subtractor subtractor(&data_dumper, DetectOptimization());
31 std::vector<float> x(kBlockSize, 0.f);
32 std::vector<float> y(kBlockSize, 0.f);
33 std::array<float, kBlockSize> x_old;
34 SubtractorOutput output;
35 FftBuffer X_buffer(
36 Aec3Optimization::kNone, subtractor.MinFarendBufferLength(),
37 std::vector<size_t>(1, subtractor.MinFarendBufferLength()));
38 RenderSignalAnalyzer render_signal_analyzer;
39 Random random_generator(42U);
40 Aec3Fft fft;
41 FftData X;
42 std::array<float, kFftLengthBy2Plus1> Y2;
43 std::array<float, kFftLengthBy2Plus1> E2_main;
44 std::array<float, kFftLengthBy2Plus1> E2_shadow;
45 AecState aec_state;
46 x_old.fill(0.f);
47 Y2.fill(0.f);
48 E2_main.fill(0.f);
49 E2_shadow.fill(0.f);
50
51 DelayBuffer<float> delay_buffer(delay_samples);
52 for (int k = 0; k < num_blocks_to_process; ++k) {
53 RandomizeSampleVector(&random_generator, x);
54 if (uncorrelated_inputs) {
55 RandomizeSampleVector(&random_generator, y);
56 } else {
57 delay_buffer.Delay(x, y);
58 }
59 fft.PaddedFft(x, x_old, &X);
60 X_buffer.Insert(X);
61 render_signal_analyzer.Update(X_buffer, aec_state.FilterDelay());
62
63 // Handle echo path changes.
64 if (std::find(blocks_with_echo_path_changes.begin(),
65 blocks_with_echo_path_changes.end(),
66 k) != blocks_with_echo_path_changes.end()) {
67 subtractor.HandleEchoPathChange(EchoPathVariability(true, true));
68 }
69 subtractor.Process(X_buffer, y, render_signal_analyzer, false, &output);
70
71 aec_state.Update(subtractor.FilterFrequencyResponse(),
72 rtc::Optional<size_t>(delay_samples / kBlockSize),
73 X_buffer, E2_main, E2_shadow, Y2, x,
74 EchoPathVariability(false, false), false);
75 }
76
77 const float output_power = std::inner_product(
78 output.e_main.begin(), output.e_main.end(), output.e_main.begin(), 0.f);
79 const float y_power = std::inner_product(y.begin(), y.end(), y.begin(), 0.f);
80 if (y_power == 0.f) {
81 ADD_FAILURE();
82 return -1.0;
83 }
84 return output_power / y_power;
85 }
86
87 std::string ProduceDebugText(size_t delay) {
88 std::ostringstream ss;
89 ss << "Delay: " << delay;
90 return ss.str();
91 }
92
93 } // namespace
94
95 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
96
97 // Verifies that the check for non data dumper works.
98 TEST(Subtractor, NullDataDumper) {
99 EXPECT_DEATH(Subtractor(nullptr, DetectOptimization()), "");
100 }
101
102 // Verifies the check for null subtractor output.
103 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH
104 // tests on test bots has been fixed.
105 TEST(Subtractor, DISABLED_NullOutput) {
106 ApmDataDumper data_dumper(42);
107 Subtractor subtractor(&data_dumper, DetectOptimization());
108 FftBuffer X_buffer(
109 Aec3Optimization::kNone, subtractor.MinFarendBufferLength(),
110 std::vector<size_t>(1, subtractor.MinFarendBufferLength()));
111 RenderSignalAnalyzer render_signal_analyzer;
112 std::vector<float> y(kBlockSize, 0.f);
113
114 EXPECT_DEATH(
115 subtractor.Process(X_buffer, y, render_signal_analyzer, false, nullptr),
116 "");
117 }
118
119 // Verifies the check for the capture signal size.
120 TEST(Subtractor, WrongCaptureSize) {
121 ApmDataDumper data_dumper(42);
122 Subtractor subtractor(&data_dumper, DetectOptimization());
123 FftBuffer X_buffer(
124 Aec3Optimization::kNone, subtractor.MinFarendBufferLength(),
125 std::vector<size_t>(1, subtractor.MinFarendBufferLength()));
126 RenderSignalAnalyzer render_signal_analyzer;
127 std::vector<float> y(kBlockSize - 1, 0.f);
128 SubtractorOutput output;
129
130 EXPECT_DEATH(
131 subtractor.Process(X_buffer, y, render_signal_analyzer, false, &output),
132 "");
133 }
134
135 #endif
136
137 // Verifies that the subtractor is able to converge on correlated data.
138 TEST(Subtractor, Convergence) {
139 std::vector<int> blocks_with_echo_path_changes;
140 for (size_t delay_samples : {0, 64, 150, 200, 301}) {
141 SCOPED_TRACE(ProduceDebugText(delay_samples));
142
143 float echo_to_nearend_power = RunSubtractorTest(
144 100, delay_samples, false, blocks_with_echo_path_changes);
145 EXPECT_GT(0.1f, echo_to_nearend_power);
146 }
147 }
148
149 // Verifies that the subtractor does not converge on uncorrelated signals.
150 TEST(Subtractor, NonConvergenceOnUncorrelatedSignals) {
151 std::vector<int> blocks_with_echo_path_changes;
152 for (size_t delay_samples : {0, 64, 150, 200, 301}) {
153 SCOPED_TRACE(ProduceDebugText(delay_samples));
154
155 float echo_to_nearend_power = RunSubtractorTest(
156 100, delay_samples, true, blocks_with_echo_path_changes);
157 EXPECT_NEAR(1.f, echo_to_nearend_power, 0.05);
158 }
159 }
160
161 // Verifies that the subtractor is properly reset when there is an echo path
162 // change.
163 TEST(Subtractor, EchoPathChangeReset) {
164 std::vector<int> blocks_with_echo_path_changes;
165 blocks_with_echo_path_changes.push_back(99);
166 for (size_t delay_samples : {0, 64, 150, 200, 301}) {
167 SCOPED_TRACE(ProduceDebugText(delay_samples));
168
169 float echo_to_nearend_power = RunSubtractorTest(
170 100, delay_samples, false, blocks_with_echo_path_changes);
171 EXPECT_NEAR(1.f, echo_to_nearend_power, 0.0000001f);
172 }
173 }
174
175 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698