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

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

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