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

Side by Side Diff: webrtc/modules/audio_processing/echo_cancellation_unittest.cc

Issue 1827833006: Reland of Added a bitexactness test for the echo canceller in the audio processing module. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Deactivated the tests on ARM64 Created 4 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
« no previous file with comments | « no previous file | webrtc/modules/modules.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 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 #include <vector>
11
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "webrtc/base/array_view.h"
14 #include "webrtc/modules/audio_processing/audio_buffer.h"
15 #include "webrtc/modules/audio_processing/echo_cancellation_impl.h"
16 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
17 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
18
19 #ifndef WEBRTC_ARCH_ARM64
20
21 namespace webrtc {
22 namespace {
23
24 const int kNumFramesToProcess = 1000;
25
26 void SetupComponent(int sample_rate_hz,
27 EchoCancellation::SuppressionLevel suppression_level,
28 bool drift_compensation_enabled,
29 EchoCancellationImpl* echo_canceller) {
30 echo_canceller->Initialize(sample_rate_hz, 1, 1, 1);
31 EchoCancellation* ec = static_cast<EchoCancellation*>(echo_canceller);
32 ec->Enable(true);
33 ec->set_suppression_level(suppression_level);
34 ec->enable_drift_compensation(drift_compensation_enabled);
35
36 Config config;
37 config.Set<DelayAgnostic>(new DelayAgnostic(true));
38 config.Set<ExtendedFilter>(new ExtendedFilter(true));
39 echo_canceller->SetExtraOptions(config);
40 }
41
42 void ProcessOneFrame(int sample_rate_hz,
43 int stream_delay_ms,
44 bool drift_compensation_enabled,
45 int stream_drift_samples,
46 AudioBuffer* render_audio_buffer,
47 AudioBuffer* capture_audio_buffer,
48 EchoCancellationImpl* echo_canceller) {
49 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
50 render_audio_buffer->SplitIntoFrequencyBands();
51 capture_audio_buffer->SplitIntoFrequencyBands();
52 }
53
54 echo_canceller->ProcessRenderAudio(render_audio_buffer);
55
56 if (drift_compensation_enabled) {
57 static_cast<EchoCancellation*>(echo_canceller)
58 ->set_stream_drift_samples(stream_drift_samples);
59 }
60
61 echo_canceller->ProcessCaptureAudio(capture_audio_buffer, stream_delay_ms);
62
63 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
64 capture_audio_buffer->MergeFrequencyBands();
65 }
66 }
67
68 void RunBitexactnessTest(int sample_rate_hz,
69 size_t num_channels,
70 int stream_delay_ms,
71 bool drift_compensation_enabled,
72 int stream_drift_samples,
73 EchoCancellation::SuppressionLevel suppression_level,
74 bool stream_has_echo_reference,
75 const rtc::ArrayView<const float>& output_reference) {
76 rtc::CriticalSection crit_render;
77 rtc::CriticalSection crit_capture;
78 EchoCancellationImpl echo_canceller(&crit_render, &crit_capture);
79 SetupComponent(sample_rate_hz, suppression_level, drift_compensation_enabled,
80 &echo_canceller);
81
82 const int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100);
83 const StreamConfig render_config(sample_rate_hz, num_channels, false);
84 AudioBuffer render_buffer(
85 render_config.num_frames(), render_config.num_channels(),
86 render_config.num_frames(), 1, render_config.num_frames());
87 test::InputAudioFile render_file(
88 test::GetApmRenderTestVectorFileName(sample_rate_hz));
89 std::vector<float> render_input(samples_per_channel * num_channels);
90
91 const StreamConfig capture_config(sample_rate_hz, num_channels, false);
92 AudioBuffer capture_buffer(
93 capture_config.num_frames(), capture_config.num_channels(),
94 capture_config.num_frames(), 1, capture_config.num_frames());
95 test::InputAudioFile capture_file(
96 test::GetApmCaptureTestVectorFileName(sample_rate_hz));
97 std::vector<float> capture_input(samples_per_channel * num_channels);
98
99 for (int frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) {
100 ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels,
101 &render_file, render_input);
102 ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels,
103 &capture_file, capture_input);
104
105 test::CopyVectorToAudioBuffer(render_config, render_input, &render_buffer);
106 test::CopyVectorToAudioBuffer(capture_config, capture_input,
107 &capture_buffer);
108
109 ProcessOneFrame(sample_rate_hz, stream_delay_ms, drift_compensation_enabled,
110 stream_drift_samples, &render_buffer, &capture_buffer,
111 &echo_canceller);
112 }
113
114 // Extract and verify the test results.
115 std::vector<float> capture_output;
116 test::ExtractVectorFromAudioBuffer(capture_config, &capture_buffer,
117 &capture_output);
118
119 EXPECT_EQ(stream_has_echo_reference,
120 static_cast<EchoCancellation*>(&echo_canceller)->stream_has_echo());
121
122 // Compare the output with the reference. Only the first values of the output
123 // from last frame processed are compared in order not having to specify all
124 // preceeding frames as testvectors. As the algorithm being tested has a
125 // memory, testing only the last frame implicitly also tests the preceeding
126 // frames.
127 const float kTolerance = 1.0f / 32768.0f;
128 EXPECT_TRUE(test::BitExactFrame(
129 capture_config.num_frames(), capture_config.num_channels(),
130 output_reference, capture_output, kTolerance));
131 }
132
133 const bool kStreamHasEchoReference = false;
134
135 } // namespace
136
137 // TODO(peah): Activate all these tests for ARM64 once the issue on the Chromium
138 // ARM64 boths have been identified.
139
140 TEST(EchoCancellationBitExactnessTest,
141 Mono8kHz_HighLevel_NoDrift_StreamDelay0) {
142 #ifdef WEBRTC_ARCH_ARM
143 const float kOutputReference[] = {0.005061f, 0.009174f, 0.012192f};
144 #else
145 const float kOutputReference[] = {0.005739f, 0.009969f, 0.013096f};
146 #endif
147
148 RunBitexactnessTest(8000, 1, 0, false, 0,
149 EchoCancellation::SuppressionLevel::kHighSuppression,
150 kStreamHasEchoReference, kOutputReference);
151 }
152
153 TEST(EchoCancellationBitExactnessTest,
154 Mono16kHz_HighLevel_NoDrift_StreamDelay0) {
155 #ifdef WEBRTC_ARCH_ARM
156 const float kOutputReference[] = {-0.017961f, -0.016535f, -0.014739f};
157 #else
158 const float kOutputReference[] = {-0.017875f, -0.016454f, -0.014657f};
159 #endif
160 RunBitexactnessTest(16000, 1, 0, false, 0,
161 EchoCancellation::SuppressionLevel::kHighSuppression,
162 kStreamHasEchoReference, kOutputReference);
163 }
164
165 TEST(EchoCancellationBitExactnessTest,
166 Mono32kHz_HighLevel_NoDrift_StreamDelay0) {
167 #ifdef WEBRTC_ARCH_ARM
168 const float kOutputReference[] = {-0.020325f, -0.020111f, -0.019165f};
169 #elif defined(WEBRTC_MAC)
170 const bool kStreamHasEchoReference = false;
171 const float kOutputReference[] = {-0.020111f, -0.019958f, -0.019012f};
172 #else
173 const bool kStreamHasEchoReference = false;
174 const float kOutputReference[] = {-0.020294f, -0.020081f, -0.019135f};
175 #endif
176
177 RunBitexactnessTest(32000, 1, 0, false, 0,
178 EchoCancellation::SuppressionLevel::kHighSuppression,
179 kStreamHasEchoReference, kOutputReference);
180 }
181
182 TEST(EchoCancellationBitExactnessTest,
183 Mono48kHz_HighLevel_NoDrift_StreamDelay0) {
184 #ifdef WEBRTC_ARCH_ARM
185 const float kOutputReference[] = {-0.016424f, -0.016843f, -0.017117f};
186 #else
187 const float kOutputReference[] = {-0.016347f, -0.016763f, -0.017036f};
188 #endif
189 RunBitexactnessTest(48000, 1, 0, false, 0,
190 EchoCancellation::SuppressionLevel::kHighSuppression,
191 kStreamHasEchoReference, kOutputReference);
192 }
193
194 TEST(EchoCancellationBitExactnessTest,
195 Mono16kHz_LowLevel_NoDrift_StreamDelay0) {
196 #ifdef WEBRTC_ARCH_ARM
197 const float kOutputReference[] = {-0.018348f, -0.016953f, -0.015167f};
198 #else
199 const float kOutputReference[] = {-0.018289f, -0.016901f, -0.015122f};
200 #endif
201 RunBitexactnessTest(16000, 1, 0, false, 0,
202 EchoCancellation::SuppressionLevel::kLowSuppression,
203 kStreamHasEchoReference, kOutputReference);
204 }
205
206 TEST(EchoCancellationBitExactnessTest,
207 Mono16kHz_ModerateLevel_NoDrift_StreamDelay0) {
208 #ifdef WEBRTC_ARCH_ARM
209 const float kOutputReference[] = {-0.018253f, -0.016845f, -0.015055f};
210 #else
211 const bool kStreamHasEchoReference = false;
212 const float kOutputReference[] = {-0.018194f, -0.016788f, -0.014997f};
213 #endif
214 RunBitexactnessTest(16000, 1, 0, false, 0,
215 EchoCancellation::SuppressionLevel::kModerateSuppression,
216 kStreamHasEchoReference, kOutputReference);
217 }
218
219 TEST(EchoCancellationBitExactnessTest,
220 Mono16kHz_HighLevel_NoDrift_StreamDelay10) {
221 #ifdef WEBRTC_ARCH_ARM
222 const float kOutputReference[] = {-0.017961f, -0.016535f, -0.014739f};
223 #else
224 const float kOutputReference[] = {-0.017875f, -0.016454f, -0.014657f};
225 #endif
226 RunBitexactnessTest(16000, 1, 10, false, 0,
227 EchoCancellation::SuppressionLevel::kHighSuppression,
228 kStreamHasEchoReference, kOutputReference);
229 }
230
231 TEST(EchoCancellationBitExactnessTest,
232 Mono16kHz_HighLevel_NoDrift_StreamDelay20) {
233 #ifdef WEBRTC_ARCH_ARM
234 const float kOutputReference[] = {-0.017961f, -0.016535f, -0.014739f};
235 #else
236 const float kOutputReference[] = {-0.017875f, -0.016454f, -0.014657f};
237 #endif
238 RunBitexactnessTest(16000, 1, 20, false, 0,
239 EchoCancellation::SuppressionLevel::kHighSuppression,
240 kStreamHasEchoReference, kOutputReference);
241 }
242
243 TEST(EchoCancellationBitExactnessTest,
244 Mono16kHz_HighLevel_Drift0_StreamDelay0) {
245 #ifdef WEBRTC_ARCH_ARM
246 const float kOutputReference[] = {-0.017961f, -0.016535f, -0.014739f};
247 #else
248 const float kOutputReference[] = {-0.017875f, -0.016454f, -0.014657f};
249 #endif
250 RunBitexactnessTest(16000, 1, 0, true, 0,
251 EchoCancellation::SuppressionLevel::kHighSuppression,
252 kStreamHasEchoReference, kOutputReference);
253 }
254
255 TEST(EchoCancellationBitExactnessTest,
256 Mono16kHz_HighLevel_Drift5_StreamDelay0) {
257 #ifdef WEBRTC_ARCH_ARM
258 const float kOutputReference[] = {-0.017961f, -0.016535f, -0.014739f};
259 #else
260 const float kOutputReference[] = {-0.017875f, -0.016454f, -0.014657f};
261 #endif
262
263 RunBitexactnessTest(16000, 1, 0, true, 5,
264 EchoCancellation::SuppressionLevel::kHighSuppression,
265 kStreamHasEchoReference, kOutputReference);
266 }
267
268 TEST(EchoCancellationBitExactnessTest,
269 Stereo8kHz_HighLevel_NoDrift_StreamDelay0) {
270 #ifdef WEBRTC_ARCH_ARM
271 const float kOutputReference[] = {0.011900f, 0.004306f, 0.010258f,
272 0.011900f, 0.004306f, 0.010258f};
273 #else
274 const float kOutputReference[] = {0.011691f, 0.004257f, 0.010092f,
275 0.011691f, 0.004257f, 0.010092f};
276 #endif
277 RunBitexactnessTest(8000, 2, 0, false, 0,
278 EchoCancellation::SuppressionLevel::kHighSuppression,
279 kStreamHasEchoReference, kOutputReference);
280 }
281
282 TEST(EchoCancellationBitExactnessTest,
283 Stereo16kHz_HighLevel_NoDrift_StreamDelay0) {
284 #ifdef WEBRTC_ARCH_ARM
285 const float kOutputReference[] = {0.000840f, 0.006285f, -0.000440f,
286 0.000840f, 0.006285f, -0.000440f};
287 #else
288 const float kOutputReference[] = {0.000677f, 0.006431f, -0.000613f,
289 0.000677f, 0.006431f, -0.000613f};
290 #endif
291 RunBitexactnessTest(16000, 2, 0, false, 0,
292 EchoCancellation::SuppressionLevel::kHighSuppression,
293 kStreamHasEchoReference, kOutputReference);
294 }
295
296 TEST(EchoCancellationBitExactnessTest,
297 Stereo32kHz_HighLevel_NoDrift_StreamDelay0) {
298 #ifdef WEBRTC_ARCH_ARM
299 const float kOutputReference[] = {0.001556f, 0.007599f, 0.001068f,
300 0.001556f, 0.007599f, 0.001068f};
301 #else
302 const float kOutputReference[] = {0.001526f, 0.007630f, 0.001007f,
303 0.001526f, 0.007630f, 0.001007f};
304 #endif
305 RunBitexactnessTest(32000, 2, 0, false, 0,
306 EchoCancellation::SuppressionLevel::kHighSuppression,
307 kStreamHasEchoReference, kOutputReference);
308 }
309
310 TEST(EchoCancellationBitExactnessTest,
311 Stereo48kHz_HighLevel_NoDrift_StreamDelay0) {
312 #ifdef WEBRTC_ARCH_ARM
313 const float kOutputReference[] = {0.004406f, 0.011327f, 0.004271f,
314 0.004406f, 0.011327f, 0.004271f};
315 #else
316 const float kOutputReference[] = {0.004390f, 0.011286f, 0.004254f,
317 0.004390f, 0.011286f, 0.004254f};
318 #endif
319 RunBitexactnessTest(48000, 2, 0, false, 0,
320 EchoCancellation::SuppressionLevel::kHighSuppression,
321 kStreamHasEchoReference, kOutputReference);
322 }
323
324 } // namespace webrtc
325
326 #endif
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/modules.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698