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

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

Issue 1809613002: 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: Removed unused merge of the bands on the render side 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 static_cast<EchoCancellation*>(echo_canceller)->Enable(true);
hlundin-webrtc 2016/03/18 08:17:47 Consider: EchoCancellation* ec = static_cast<EchoC
peah-webrtc 2016/03/20 21:23:16 Done.
30 static_cast<EchoCancellation*>(echo_canceller)
31 ->set_suppression_level(suppression_level);
32 static_cast<EchoCancellation*>(echo_canceller)
33 ->enable_drift_compensation(drift_compensation_enabled);
34
35 Config config;
36 config.Set<DelayAgnostic>(new DelayAgnostic(true));
37 config.Set<ExtendedFilter>(new ExtendedFilter(true));
38 echo_canceller->SetExtraOptions(config);
39 }
40
41 void ProcessOneFrame(int sample_rate_hz,
42 int stream_delay_ms,
43 bool drift_compensation_enabled,
44 int stream_drift_samples,
45 AudioBuffer* render_audio_buffer,
46 AudioBuffer* capture_audio_buffer,
47 EchoCancellationImpl* echo_canceller) {
48 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
49 render_audio_buffer->SplitIntoFrequencyBands();
50 capture_audio_buffer->SplitIntoFrequencyBands();
51 }
52
53 echo_canceller->ProcessRenderAudio(render_audio_buffer);
54
55 if (drift_compensation_enabled) {
56 static_cast<EchoCancellation*>(echo_canceller)
hlundin-webrtc 2016/03/18 08:17:47 Does this have to be set for every frame processed
peah-webrtc 2016/03/20 21:24:09 Yes, that is the case.
57 ->set_stream_drift_samples(stream_drift_samples);
58 }
59
60 echo_canceller->ProcessCaptureAudio(capture_audio_buffer, stream_delay_ms);
61
62 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
63 capture_audio_buffer->MergeFrequencyBands();
64 }
65 }
66
67 void RunBitexactnessTest(int sample_rate_hz,
68 size_t num_channels,
69 int stream_delay_ms,
70 bool drift_compensation_enabled,
71 int stream_drift_samples,
72 EchoCancellation::SuppressionLevel suppression_level,
73 bool stream_has_echo_reference,
74 const rtc::ArrayView<const float>& output_reference) {
75 rtc::CriticalSection crit_render;
76 rtc::CriticalSection crit_capture;
77 EchoCancellationImpl echo_canceller(&crit_render, &crit_capture);
78 SetupComponent(sample_rate_hz, suppression_level, drift_compensation_enabled,
79 &echo_canceller);
80
81 int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100);
hlundin-webrtc 2016/03/18 08:17:47 const
peah-webrtc 2016/03/20 21:24:10 Done.
82 const StreamConfig render_config(sample_rate_hz, num_channels, false);
83 AudioBuffer render_buffer(
84 render_config.num_frames(), render_config.num_channels(),
85 render_config.num_frames(), 1, render_config.num_frames());
86 test::InputAudioFile render_file(
87 test::GetApmRenderTestVectorFileName(sample_rate_hz));
88 std::vector<float> render_input(samples_per_channel * num_channels);
89
90 const StreamConfig capture_config(sample_rate_hz, num_channels, false);
91 AudioBuffer capture_buffer(
92 capture_config.num_frames(), capture_config.num_channels(),
93 capture_config.num_frames(), 1, capture_config.num_frames());
94 test::InputAudioFile capture_file(
95 test::GetApmCaptureTestVectorFileName(sample_rate_hz));
96 std::vector<float> capture_input(samples_per_channel * num_channels);
97
98 for (int frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) {
99 ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels,
100 &render_file, render_input);
101 ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels,
102 &capture_file, capture_input);
103
104 test::CopyVectorToAudioBuffer(render_config, render_input, &render_buffer);
105 test::CopyVectorToAudioBuffer(capture_config, capture_input,
106 &capture_buffer);
107
108 ProcessOneFrame(sample_rate_hz, stream_delay_ms, drift_compensation_enabled,
109 stream_drift_samples, &render_buffer, &capture_buffer,
110 &echo_canceller);
111 }
112
113 // Extract and verify the test results.
114 std::vector<float> capture_output;
115 test::ExtractVectorFromAudioBuffer(capture_config, &capture_buffer,
116 &capture_output);
117 bool stream_has_echo =
118 static_cast<EchoCancellation*>(&echo_canceller)->stream_has_echo();
119
120 const float kTolerance = 1.0f / 32768.0f;
hlundin-webrtc 2016/03/18 08:17:47 Move to just before the line where it is used.
peah-webrtc 2016/03/20 21:24:09 Done.
121 EXPECT_EQ(stream_has_echo_reference, stream_has_echo);
hlundin-webrtc 2016/03/18 08:17:47 EXPECT_EQ(stream_has_echo_reference, static_cast<E
peah-webrtc 2016/03/20 21:24:09 Done.
122
123 // Compare the output with the reference. Only the first values of the output
124 // from last frame processed are compared in order not having to specify all
125 // preceeding frames as testvectors. As the algorithm being tested has a
126 // memory, testing only the last frame implicitly also tests the preceeding
127 // frames.
128 EXPECT_TRUE(test::BitExactFrame(
129 capture_config.num_frames(), capture_config.num_channels(),
130 output_reference, capture_output, kTolerance));
131 }
132
133 } // namespace
134
135 TEST(EchoCancellationBitExactnessTest,
136 Mono8kHz_HighLevel_NoDrift_StreamDelay0) {
137 const bool kStreamHasEchoReference = false;
138 const float kOutputReference[] = {0.005739f, 0.009969f, 0.013096f};
139
140 RunBitexactnessTest(8000, 1, 0, false, 0,
141 EchoCancellation::SuppressionLevel::kHighSuppression,
142 kStreamHasEchoReference, kOutputReference);
143 }
144
145 TEST(EchoCancellationBitExactnessTest,
146 Mono16kHz_HighLevel_NoDrift_StreamDelay0) {
147 const bool kStreamHasEchoReference = false;
148 const float kOutputReference[] = {-0.017875f, -0.016454f, -0.014657f};
149
150 RunBitexactnessTest(16000, 1, 0, false, 0,
151 EchoCancellation::SuppressionLevel::kHighSuppression,
152 kStreamHasEchoReference, kOutputReference);
153 }
154
155 TEST(EchoCancellationBitExactnessTest,
156 Mono32kHz_HighLevel_NoDrift_StreamDelay0) {
157 const bool kStreamHasEchoReference = false;
158 const float kOutputReference[] = {-0.020294f, -0.020081f, -0.019135f};
159
160 RunBitexactnessTest(32000, 1, 0, false, 0,
161 EchoCancellation::SuppressionLevel::kHighSuppression,
162 kStreamHasEchoReference, kOutputReference);
163 }
164
165 TEST(EchoCancellationBitExactnessTest,
166 Mono48kHz_HighLevel_NoDrift_StreamDelay0) {
167 const bool kStreamHasEchoReference = false;
168 const float kOutputReference[] = {-0.016347f, -0.016763f, -0.017036f};
169
170 RunBitexactnessTest(48000, 1, 0, false, 0,
171 EchoCancellation::SuppressionLevel::kHighSuppression,
172 kStreamHasEchoReference, kOutputReference);
173 }
174
175 TEST(EchoCancellationBitExactnessTest,
176 Mono16kHz_LowLevel_NoDrift_StreamDelay0) {
177 const bool kStreamHasEchoReference = false;
178 const float kOutputReference[] = {-0.018289f, -0.016901f, -0.015122f};
179
180 RunBitexactnessTest(16000, 1, 0, false, 0,
181 EchoCancellation::SuppressionLevel::kLowSuppression,
182 kStreamHasEchoReference, kOutputReference);
183 }
184
185 TEST(EchoCancellationBitExactnessTest,
186 Mono16kHz_ModerateLevel_NoDrift_StreamDelay0) {
187 const bool kStreamHasEchoReference = false;
188 const float kOutputReference[] = {-0.018194f, -0.016788f, -0.014997f};
189
190 RunBitexactnessTest(16000, 1, 0, false, 0,
191 EchoCancellation::SuppressionLevel::kModerateSuppression,
192 kStreamHasEchoReference, kOutputReference);
193 }
194
195 TEST(EchoCancellationBitExactnessTest,
196 Mono16kHz_HighLevel_NoDrift_StreamDelay10) {
197 const bool kStreamHasEchoReference = false;
198 const float kOutputReference[] = {-0.017875f, -0.016454f, -0.014657f};
199
200 RunBitexactnessTest(16000, 1, 10, false, 0,
201 EchoCancellation::SuppressionLevel::kHighSuppression,
202 kStreamHasEchoReference, kOutputReference);
203 }
204
205 TEST(EchoCancellationBitExactnessTest,
206 Mono16kHz_HighLevel_NoDrift_StreamDelay20) {
207 const bool kStreamHasEchoReference = false;
208 const float kOutputReference[] = {-0.017875f, -0.016454f, -0.014657f};
209
210 RunBitexactnessTest(16000, 1, 20, false, 0,
211 EchoCancellation::SuppressionLevel::kHighSuppression,
212 kStreamHasEchoReference, kOutputReference);
213 }
214
215 TEST(EchoCancellationBitExactnessTest,
216 Mono16kHz_HighLevel_Drift0_StreamDelay0) {
217 const bool kStreamHasEchoReference = false;
218 const float kOutputReference[] = {-0.017875f, -0.016454f, -0.014657f};
219
220 RunBitexactnessTest(16000, 1, 0, true, 0,
221 EchoCancellation::SuppressionLevel::kHighSuppression,
222 kStreamHasEchoReference, kOutputReference);
223 }
224
225 TEST(EchoCancellationBitExactnessTest,
226 Mono16kHz_HighLevel_Drift5_StreamDelay0) {
227 const bool kStreamHasEchoReference = false;
228 const float kOutputReference[] = {-0.017875f, -0.016454f, -0.014657f};
229
230 RunBitexactnessTest(16000, 1, 0, true, 5,
231 EchoCancellation::SuppressionLevel::kHighSuppression,
232 kStreamHasEchoReference, kOutputReference);
233 }
234
235 TEST(EchoCancellationBitExactnessTest,
236 Stereo8kHz_HighLevel_NoDrift_StreamDelay0) {
237 const bool kStreamHasEchoReference = false;
238 const float kOutputReference[] = {0.011691f, 0.004257f, 0.010092f,
239 0.011691f, 0.004257f, 0.010092f};
240
241 RunBitexactnessTest(8000, 2, 0, false, 0,
242 EchoCancellation::SuppressionLevel::kHighSuppression,
243 kStreamHasEchoReference, kOutputReference);
244 }
245
246 TEST(EchoCancellationBitExactnessTest,
247 Stereo16kHz_HighLevel_NoDrift_StreamDelay0) {
248 const bool kStreamHasEchoReference = false;
249 const float kOutputReference[] = {0.000677f, 0.006431f, -0.000613f,
250 0.000677f, 0.006431f, -0.000613f};
251
252 RunBitexactnessTest(16000, 2, 0, false, 0,
253 EchoCancellation::SuppressionLevel::kHighSuppression,
254 kStreamHasEchoReference, kOutputReference);
255 }
256
257 TEST(EchoCancellationBitExactnessTest,
258 Stereo32kHz_HighLevel_NoDrift_StreamDelay0) {
259 const bool kStreamHasEchoReference = false;
260 const float kOutputReference[] = {0.001526f, 0.007630f, 0.001007f,
261 0.001526f, 0.007630f, 0.001007f};
262
263 RunBitexactnessTest(32000, 2, 0, false, 0,
264 EchoCancellation::SuppressionLevel::kHighSuppression,
265 kStreamHasEchoReference, kOutputReference);
266 }
267
268 TEST(EchoCancellationBitExactnessTest,
269 Stereo48kHz_HighLevel_NoDrift_StreamDelay0) {
270 const bool kStreamHasEchoReference = false;
271 const float kOutputReference[] = {0.004390f, 0.011286f, 0.004254f,
272 0.004390f, 0.011286f, 0.004254f};
273
274 RunBitexactnessTest(48000, 2, 0, false, 0,
275 EchoCancellation::SuppressionLevel::kHighSuppression,
276 kStreamHasEchoReference, kOutputReference);
277 }
278
279 } // 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