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

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

Issue 1812433002: Added a bitexactness test for the gain controller in the audio processing module. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@AecmBitExactness_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/gain_control_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 ProcessOneFrame(int sample_rate_hz,
25 AudioBuffer* render_audio_buffer,
26 AudioBuffer* capture_audio_buffer,
27 GainControlImpl* gain_controller) {
28 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
29 render_audio_buffer->SplitIntoFrequencyBands();
30 capture_audio_buffer->SplitIntoFrequencyBands();
31 }
32
33 gain_controller->ProcessRenderAudio(render_audio_buffer);
34 gain_controller->AnalyzeCaptureAudio(capture_audio_buffer);
35 gain_controller->ProcessCaptureAudio(capture_audio_buffer, false);
36
37 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
38 capture_audio_buffer->MergeFrequencyBands();
39 }
40 }
41
42 void SetupComponent(int sample_rate_hz,
43 GainControl::Mode mode,
44 int target_level_dbfs,
45 int stream_analog_level,
46 int compression_gain_db,
47 bool enable_limiter,
48 int analog_level_min,
49 int analog_level_max,
50 GainControlImpl* gain_controller) {
51 gain_controller->Initialize(1, sample_rate_hz);
52 static_cast<GainControl*>(gain_controller)->Enable(true);
hlundin-webrtc 2016/03/18 08:32:31 GainControl* gc = static_cast<GainControl*>(gain_c
peah-webrtc 2016/03/21 06:12:19 Done.
53 static_cast<GainControl*>(gain_controller)->set_mode(mode);
54
55 static_cast<GainControl*>(gain_controller)
56 ->set_stream_analog_level(stream_analog_level);
57 static_cast<GainControl*>(gain_controller)
58 ->set_target_level_dbfs(target_level_dbfs);
59 static_cast<GainControl*>(gain_controller)
60 ->set_compression_gain_db(compression_gain_db);
61 static_cast<GainControl*>(gain_controller)->enable_limiter(enable_limiter);
62 static_cast<GainControl*>(gain_controller)
63 ->set_analog_level_limits(analog_level_min, analog_level_max);
64 }
65
66 void RunBitExactnessTest(int sample_rate_hz,
67 size_t num_channels,
68 GainControl::Mode mode,
69 int target_level_dbfs,
70 int stream_analog_level,
71 int compression_gain_db,
72 bool enable_limiter,
73 int analog_level_min,
74 int analog_level_max,
75 int achieved_stream_analog_level_reference,
76 rtc::ArrayView<const float> output_reference) {
77 rtc::CriticalSection crit_render;
78 rtc::CriticalSection crit_capture;
79 GainControlImpl gain_controller(&crit_render, &crit_capture);
80 SetupComponent(sample_rate_hz, mode, target_level_dbfs, stream_analog_level,
81 compression_gain_db, enable_limiter, analog_level_min,
82 analog_level_max, &gain_controller);
83
84 int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100);
hlundin-webrtc 2016/03/18 08:32:31 const
peah-webrtc 2016/03/21 06:12:19 Done.
85 const StreamConfig render_config(sample_rate_hz, num_channels, false);
86 AudioBuffer render_buffer(
87 render_config.num_frames(), render_config.num_channels(),
88 render_config.num_frames(), 1, render_config.num_frames());
89 test::InputAudioFile render_file(
90 test::GetApmRenderTestVectorFileName(sample_rate_hz));
91 std::vector<float> render_input(samples_per_channel * num_channels);
92
93 const StreamConfig capture_config(sample_rate_hz, num_channels, false);
94 AudioBuffer capture_buffer(
95 capture_config.num_frames(), capture_config.num_channels(),
96 capture_config.num_frames(), 1, capture_config.num_frames());
97 test::InputAudioFile capture_file(
98 test::GetApmCaptureTestVectorFileName(sample_rate_hz));
99 std::vector<float> capture_input(samples_per_channel * num_channels);
100
101 for (int frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) {
102 ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels,
103 &render_file, render_input);
104 ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels,
105 &capture_file, capture_input);
106
107 test::CopyVectorToAudioBuffer(render_config, render_input, &render_buffer);
108 test::CopyVectorToAudioBuffer(capture_config, capture_input,
109 &capture_buffer);
110
111 ProcessOneFrame(sample_rate_hz, &render_buffer, &capture_buffer,
112 &gain_controller);
113 }
114
115 // Extract and verify the test results.
116 int achieved_stream_analog_level = gain_controller.stream_analog_level();
117
118 std::vector<float> capture_output;
119 test::ExtractVectorFromAudioBuffer(capture_config, &capture_buffer,
120 &capture_output);
121
122 const float kTolerance = 1.0f / 32768.0f;
hlundin-webrtc 2016/03/18 08:32:31 Move tolerance down.
peah-webrtc 2016/03/21 06:12:19 Done.
123 EXPECT_EQ(achieved_stream_analog_level_reference,
hlundin-webrtc 2016/03/18 08:32:30 EXPECT_EQ(achieved_stream_analog_level_reference,
peah-webrtc 2016/03/21 06:12:19 Done.
124 achieved_stream_analog_level);
125
126 // Compare the output with the reference. Only the first values of the output
127 // from last frame processed are compared in order not having to specify all
128 // preceeding frames as testvectors. As the algorithm being tested has a
129 // memory, testing only the last frame implicitly also tests the preceeding
130 // frames.
131 EXPECT_TRUE(test::BitExactFrame(
132 capture_config.num_frames(), capture_config.num_channels(),
133 output_reference, capture_output, kTolerance));
134 }
135
136 } // namespace
137
138 TEST(GainControlBitExactnessTest,
139 Mono8kHz_AdaptiveAnalog_Tl10_SL50_CG5_Lim_AL0_100) {
140 const int kStreamAnalogLevelReference = 50;
141 const float kOutputReference[] = {-0.004578f, -0.003998f, -0.002991f};
142 RunBitExactnessTest(8000, 1, GainControl::Mode::kAdaptiveAnalog, 10, 50, 5,
143 true, 0, 100, kStreamAnalogLevelReference,
144 kOutputReference);
145 }
146
147 TEST(GainControlBitExactnessTest,
148 Mono16kHz_AdaptiveAnalog_Tl10_SL50_CG5_Lim_AL0_100) {
149 const int kStreamAnalogLevelReference = 50;
150 const float kOutputReference[] = {-0.004303f, -0.004150f, -0.004089f};
151 RunBitExactnessTest(16000, 1, GainControl::Mode::kAdaptiveAnalog, 10, 50, 5,
152 true, 0, 100, kStreamAnalogLevelReference,
153 kOutputReference);
154 }
155
156 TEST(GainControlBitExactnessTest,
157 Stereo16kHz_AdaptiveAnalog_Tl10_SL50_CG5_Lim_AL0_100) {
158 const int kStreamAnalogLevelReference = 50;
159 const float kOutputReference[] = {-0.010254f, -0.004761f, -0.009918f,
160 -0.010254f, -0.004761f, -0.009918f};
161 RunBitExactnessTest(16000, 2, GainControl::Mode::kAdaptiveAnalog, 10, 50, 5,
162 true, 0, 100, kStreamAnalogLevelReference,
163 kOutputReference);
164 }
165
166 TEST(GainControlBitExactnessTest,
167 Mono32kHz_AdaptiveAnalog_Tl10_SL50_CG5_Lim_AL0_100) {
168 const int kStreamAnalogLevelReference = 50;
169 const float kOutputReference[] = {-0.005554f, -0.005066f, -0.004242f};
170 RunBitExactnessTest(32000, 1, GainControl::Mode::kAdaptiveAnalog, 10, 50, 5,
171 true, 0, 100, kStreamAnalogLevelReference,
172 kOutputReference);
173 }
174
175 TEST(GainControlBitExactnessTest,
176 Mono48kHz_AdaptiveAnalog_Tl10_SL50_CG5_Lim_AL0_100) {
177 const int kStreamAnalogLevelReference = 50;
178 const float kOutputReference[] = {-0.005554f, -0.005066f, -0.004242f};
179 RunBitExactnessTest(32000, 1, GainControl::Mode::kAdaptiveAnalog, 10, 50, 5,
180 true, 0, 100, kStreamAnalogLevelReference,
181 kOutputReference);
182 }
183
184 TEST(GainControlBitExactnessTest,
185 Mono8kHz_AdaptiveDigital_Tl10_SL50_CG5_Lim_AL0_100) {
186 const int kStreamAnalogLevelReference = 50;
187 const float kOutputReference[] = {-0.014221f, -0.012421f, -0.009308f};
188 RunBitExactnessTest(8000, 1, GainControl::Mode::kAdaptiveDigital, 10, 50, 5,
189 true, 0, 100, kStreamAnalogLevelReference,
190 kOutputReference);
191 }
192
193 TEST(GainControlBitExactnessTest,
194 Mono16kHz_AdaptiveDigital_Tl10_SL50_CG5_Lim_AL0_100) {
195 const int kStreamAnalogLevelReference = 50;
196 const float kOutputReference[] = {-0.014923f, -0.014404f, -0.014191f};
197 RunBitExactnessTest(16000, 1, GainControl::Mode::kAdaptiveDigital, 10, 50, 5,
198 true, 0, 100, kStreamAnalogLevelReference,
199 kOutputReference);
200 }
201
202 TEST(GainControlBitExactnessTest,
203 Stereo16kHz_AdaptiveDigital_Tl10_SL50_CG5_Lim_AL0_100) {
204 const int kStreamAnalogLevelReference = 50;
205 const float kOutputReference[] = {-0.009796f, -0.004547f, -0.009460f,
206 -0.009796f, -0.004547f, -0.009460f};
207 RunBitExactnessTest(16000, 2, GainControl::Mode::kAdaptiveDigital, 10, 50, 5,
208 true, 0, 100, kStreamAnalogLevelReference,
209 kOutputReference);
210 }
211
212 TEST(GainControlBitExactnessTest,
213 Mono32kHz_AdaptiveDigital_Tl10_SL50_CG5_Lim_AL0_100) {
214 const int kStreamAnalogLevelReference = 50;
215 const float kOutputReference[] = {-0.019287f, -0.017578f, -0.014709f};
216 RunBitExactnessTest(32000, 1, GainControl::Mode::kAdaptiveDigital, 10, 50, 5,
217 true, 0, 100, kStreamAnalogLevelReference,
218 kOutputReference);
219 }
220
221 TEST(GainControlBitExactnessTest,
222 Mono48kHz_AdaptiveDigital_Tl10_SL50_CG5_Lim_AL0_100) {
223 const int kStreamAnalogLevelReference = 50;
224 const float kOutputReference[] = {-0.019287f, -0.017578f, -0.014709f};
225 RunBitExactnessTest(32000, 1, GainControl::Mode::kAdaptiveDigital, 10, 50, 5,
226 true, 0, 100, kStreamAnalogLevelReference,
227 kOutputReference);
228 }
229
230 TEST(GainControlBitExactnessTest,
231 Mono8kHz_FixedDigital_Tl10_SL50_CG5_Lim_AL0_100) {
232 const int kStreamAnalogLevelReference = 50;
233 const float kOutputReference[] = {-0.008209f, -0.007172f, -0.005371f};
234 RunBitExactnessTest(8000, 1, GainControl::Mode::kFixedDigital, 10, 50, 5,
235 true, 0, 100, kStreamAnalogLevelReference,
236 kOutputReference);
237 }
238
239 TEST(GainControlBitExactnessTest,
240 Mono16kHz_FixedDigital_Tl10_SL50_CG5_Lim_AL0_100) {
241 const int kStreamAnalogLevelReference = 50;
242 const float kOutputReference[] = {-0.007721f, -0.007446f, -0.007355f};
243 RunBitExactnessTest(16000, 1, GainControl::Mode::kFixedDigital, 10, 50, 5,
244 true, 0, 100, kStreamAnalogLevelReference,
245 kOutputReference);
246 }
247
248 TEST(GainControlBitExactnessTest,
249 Stereo16kHz_FixedDigital_Tl10_SL50_CG5_Lim_AL0_100) {
250 const int kStreamAnalogLevelReference = 50;
251 const float kOutputReference[] = {-0.018402f, -0.008545f, -0.017792f,
252 -0.018402f, -0.008545f, -0.017792f};
253 RunBitExactnessTest(16000, 2, GainControl::Mode::kFixedDigital, 10, 50, 5,
254 true, 0, 100, kStreamAnalogLevelReference,
255 kOutputReference);
256 }
257
258 TEST(GainControlBitExactnessTest,
259 Mono32kHz_FixedDigital_Tl10_SL50_CG5_Lim_AL0_100) {
260 const int kStreamAnalogLevelReference = 50;
261 const float kOutputReference[] = {-0.009979f, -0.009064f, -0.007629f};
262 RunBitExactnessTest(32000, 1, GainControl::Mode::kFixedDigital, 10, 50, 5,
263 true, 0, 100, kStreamAnalogLevelReference,
264 kOutputReference);
265 }
266
267 TEST(GainControlBitExactnessTest,
268 Mono48kHz_FixedDigital_Tl10_SL50_CG5_Lim_AL0_100) {
269 const int kStreamAnalogLevelReference = 50;
270 const float kOutputReference[] = {-0.009979f, -0.009064f, -0.007629f};
271 RunBitExactnessTest(32000, 1, GainControl::Mode::kFixedDigital, 10, 50, 5,
272 true, 0, 100, kStreamAnalogLevelReference,
273 kOutputReference);
274 }
275
276 TEST(GainControlBitExactnessTest,
277 Mono16kHz_AdaptiveAnalog_Tl10_SL10_CG5_Lim_AL0_100) {
278 const int kStreamAnalogLevelReference = 12;
279 const float kOutputReference[] = {-0.004303f, -0.004150f, -0.004089f};
280 RunBitExactnessTest(16000, 1, GainControl::Mode::kAdaptiveAnalog, 10, 10, 5,
281 true, 0, 100, kStreamAnalogLevelReference,
282 kOutputReference);
283 }
284
285 TEST(GainControlBitExactnessTest,
286 Mono16kHz_AdaptiveAnalog_Tl10_SL100_CG5_Lim_AL70_80) {
287 const int kStreamAnalogLevelReference = 100;
288 const float kOutputReference[] = {-0.004303f, -0.004150f, -0.004089f};
289 RunBitExactnessTest(16000, 1, GainControl::Mode::kAdaptiveAnalog, 10, 100, 5,
290 true, 70, 80, kStreamAnalogLevelReference,
291 kOutputReference);
292 }
293
294 TEST(GainControlBitExactnessTest,
295 Mono16kHz_AdaptiveDigital_Tl10_SL100_CG5_NoLim_AL0_100) {
296 const int kStreamAnalogLevelReference = 100;
297 const float kOutputReference[] = {-0.014923f, -0.014404f, -0.014191f};
298 RunBitExactnessTest(16000, 1, GainControl::Mode::kAdaptiveDigital, 10, 100, 5,
299 false, 0, 100, kStreamAnalogLevelReference,
300 kOutputReference);
301 }
302
303 TEST(GainControlBitExactnessTest,
304 Mono16kHz_AdaptiveDigital_Tl40_SL100_CG5_Lim_AL0_100) {
305 const int kStreamAnalogLevelReference = 100;
306 const float kOutputReference[] = {-0.020721f, -0.019989f, -0.019714f};
307 RunBitExactnessTest(16000, 1, GainControl::Mode::kAdaptiveDigital, 40, 100, 5,
308 true, 0, 100, kStreamAnalogLevelReference,
309 kOutputReference);
310 }
311
312 TEST(GainControlBitExactnessTest,
313 Mono16kHz_AdaptiveDigital_Tl10_SL100_CG30_Lim_AL0_100) {
314 const int kStreamAnalogLevelReference = 100;
315 const float kOutputReference[] = {-0.020416f, -0.019714f, -0.019409f};
316 RunBitExactnessTest(16000, 1, GainControl::Mode::kAdaptiveDigital, 10, 100,
317 30, true, 0, 100, kStreamAnalogLevelReference,
318 kOutputReference);
319 }
320
321 } // 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