OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <stdio.h> | |
12 | |
13 #include <iostream> | 11 #include <iostream> |
14 #include <memory> | 12 #include <memory> |
15 #include <sstream> | 13 |
16 #include <string> | 14 #include <string.h> |
17 #include <utility> | |
18 | 15 |
19 #include "gflags/gflags.h" | 16 #include "gflags/gflags.h" |
20 #include "webrtc/base/checks.h" | |
21 #include "webrtc/base/format_macros.h" | |
22 #include "webrtc/common_audio/channel_buffer.h" | |
23 #include "webrtc/common_audio/wav_file.h" | |
24 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 17 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
25 #include "webrtc/modules/audio_processing/test/audio_file_processor.h" | 18 #include "webrtc/modules/audio_processing/test/aec_dump_based_simulator.h" |
26 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 19 #include "webrtc/modules/audio_processing/test/audio_processing_simulator.h" |
27 #include "webrtc/modules/audio_processing/test/test_utils.h" | 20 #include "webrtc/modules/audio_processing/test/wav_based_simulator.h" |
28 #include "webrtc/system_wrappers/include/tick_util.h" | 21 |
29 #include "webrtc/test/testsupport/trace_to_stderr.h" | 22 namespace webrtc { |
30 | 23 namespace test { |
31 namespace { | 24 namespace { |
32 | 25 |
33 bool ValidateOutChannels(const char* flagname, int32_t value) { | 26 const int kParameterNotSpecifiedValue = -10000; |
34 return value >= 0; | 27 |
28 const char kUsageDescription[] = | |
29 "Usage: audioproc_f [options] -i <input.wav>\n" | |
30 " or\n" | |
31 " audioproc_f [options] -dump <aec_dump>\n" | |
32 "\n\n" | |
33 "Command-line tool to simulate a call using the audio " | |
34 "processing module, either based on wav files or " | |
35 "protobuf debug dump recordings and writes to an output"; | |
36 | |
37 DEFINE_string(dump_input, "", "Aec dump input filename"); | |
38 DEFINE_string(dump_output, "", "Aec dump output filename"); | |
39 DEFINE_string(i, "", "Forward stream input wav filename"); | |
40 DEFINE_string(o, "", "Forward stream output wav filename"); | |
41 DEFINE_string(ri, "", "Reverse stream input wav filename"); | |
42 DEFINE_string(ro, "", "Reverse stream output wav filename"); | |
43 DEFINE_int32(output_num_channels, | |
44 kParameterNotSpecifiedValue, | |
45 "Number of forward stream output channels"); | |
46 DEFINE_int32(reverse_output_num_channels, | |
47 kParameterNotSpecifiedValue, | |
48 "Number of Reverse stream output channels"); | |
49 DEFINE_int32(output_sample_rate_hz, | |
50 kParameterNotSpecifiedValue, | |
51 "Forward stream output sample rate in Hz"); | |
52 DEFINE_int32(reverse_output_sample_rate_hz, | |
53 kParameterNotSpecifiedValue, | |
54 "Reverse stream output sample rate in Hz"); | |
55 DEFINE_string(mic_positions, | |
56 "", | |
57 "Space delimited cartesian coordinates of microphones in " | |
58 "meters. The coordinates of each point are contiguous. For a " | |
59 "two element array: \"x1 y1 z1 x2 y2 z2\""); | |
60 DEFINE_int32(target_angle_degrees, | |
61 90, | |
62 "The azimuth of the target in degrees (0-359). Only applies to " | |
63 "beamforming."); | |
64 DEFINE_bool(fixed_interface, | |
65 false, | |
66 "Use the fixed interface when operating on wav files"); | |
67 DEFINE_bool(aec, false, "Activate the echo canceller"); | |
68 DEFINE_bool(no_aec, false, "Dectivate the echo canceller"); | |
69 DEFINE_bool(aecm, false, "Activate the mobile echo controller"); | |
70 DEFINE_bool(no_aecm, false, "Dectivate the mobile echo controller"); | |
71 DEFINE_bool(agc, false, "Activate the AGC"); | |
72 DEFINE_bool(no_agc, false, "Dectivate the AGC"); | |
73 DEFINE_bool(hpf, false, "Activate the high-pass filter"); | |
74 DEFINE_bool(no_hpf, false, "Dectivate the high-pass filter"); | |
75 DEFINE_bool(ns, false, "Activate the noise suppressor"); | |
76 DEFINE_bool(no_ns, false, "Dectivate the noise suppressor"); | |
77 DEFINE_bool(ts, false, "Activate the transient suppressor"); | |
78 DEFINE_bool(no_ts, false, "Dectivate the transient suppressor"); | |
79 DEFINE_bool(bf, false, "Activate the beamformer"); | |
80 DEFINE_bool(no_bf, false, "Dectivate the beamformer"); | |
81 DEFINE_bool(ie, false, "Activate the intelligibility enhancer"); | |
82 DEFINE_bool(no_ie, false, "Dectivate the intelligibility enhancer"); | |
83 DEFINE_bool(vad, false, "Activate the voice activity detector"); | |
84 DEFINE_bool(no_vad, false, "Dectivate the voice activity detector"); | |
85 DEFINE_bool(le, false, "Activate the level estimator"); | |
86 DEFINE_bool(no_le, false, "Dectivate the level estimator"); | |
87 DEFINE_bool(all_default, | |
88 false, | |
89 "Activate all of the default components (will be overridden by any " | |
90 "other settings)"); | |
91 DEFINE_int32(aec_suppression_level, | |
92 kParameterNotSpecifiedValue, | |
93 "Set the aec suppression level (0-2)"); | |
94 DEFINE_bool(delay_agnostic, false, "Activate the level estimator"); | |
95 DEFINE_bool(no_delay_agnostic, false, "Dectivate the level estimator"); | |
96 DEFINE_bool(extended_filter, false, "Activate the level estimator"); | |
97 DEFINE_bool(no_extended_filter, false, "Dectivate the level estimator"); | |
98 DEFINE_bool(drift_compensation, false, "Activate the level estimator"); | |
99 DEFINE_bool(no_drift_compensation, false, "Dectivate the level estimator"); | |
100 DEFINE_bool(aec3, false, "Activate the level estimator"); | |
101 DEFINE_bool(no_aec3, false, "Dectivate the level estimator"); | |
102 DEFINE_bool(refined_adaptive_filter, | |
103 false, | |
104 "Activate the refined adaptive filter functionality"); | |
105 DEFINE_bool(no_refined_adaptive_filter, | |
106 false, | |
107 "Deactivate the refined adaptive filter functionality"); | |
108 DEFINE_int32(aecm_routing_mode, | |
109 kParameterNotSpecifiedValue, | |
110 "Specify the AECM routing mode (0-4)"); | |
111 DEFINE_bool(aecm_comfort_noise, false, "Activate the AECM comfort noise"); | |
112 DEFINE_bool(no_aecm_comfort_noise, false, "Dectivate the AECM comfort noise"); | |
113 DEFINE_int32(agc_mode, | |
114 kParameterNotSpecifiedValue, | |
115 "Specify the AGC mode (0-2)"); | |
116 DEFINE_int32(agc_target_level, | |
117 kParameterNotSpecifiedValue, | |
118 "Specify the AGC target level (0-31)"); | |
119 DEFINE_bool(agc_limiter, false, "Activate the level estimator"); | |
120 DEFINE_bool(no_agc_limiter, false, "Dectivate the level estimator"); | |
121 DEFINE_int32(agc_compression_gain, | |
122 kParameterNotSpecifiedValue, | |
123 "Specify the AGC compression gain (0-90)"); | |
124 DEFINE_int32(vad_likelihood, | |
125 kParameterNotSpecifiedValue, | |
126 "Specify the VAD likelihood (0-3)"); | |
127 DEFINE_int32(ns_level, | |
128 kParameterNotSpecifiedValue, | |
129 "Specify the NS level (0-3)"); | |
130 DEFINE_int32(stream_delay, | |
131 kParameterNotSpecifiedValue, | |
132 "Specify the stream delay in ms to use"); | |
133 DEFINE_int32(stream_drift_samples, | |
134 kParameterNotSpecifiedValue, | |
135 "Specify the number of stream drift samples to use"); | |
136 DEFINE_bool(performance_report, false, "Report the APM performance "); | |
137 DEFINE_bool(verbose, false, "Produce verbose output"); | |
138 DEFINE_bool(bitexactness_report, | |
139 false, | |
140 "Report bitexactness for aec dump result reproduction"); | |
141 DEFINE_bool(discard_settings_in_aecdump, | |
142 false, | |
143 "Discard any config settings specified in the aec dump"); | |
144 DEFINE_bool(store_intermediate_output, | |
145 false, | |
146 "Creates new output files after each init"); | |
147 | |
148 void SetSettingIfSpecified(const std::string value, | |
149 rtc::Optional<std::string>* parameter) { | |
150 if (value.compare("") != 0) { | |
151 *parameter = rtc::Optional<std::string>(value); | |
152 } | |
153 } | |
154 | |
155 void SetSettingIfSpecified(int value, rtc::Optional<int>* parameter) { | |
156 if (value != kParameterNotSpecifiedValue) { | |
157 *parameter = rtc::Optional<int>(value); | |
158 } | |
159 } | |
160 | |
161 void SetSettingIfFlagSet(bool condition, | |
162 rtc::Optional<bool>* parameter, | |
163 bool value_to_set) { | |
164 if (condition) { | |
165 *parameter = rtc::Optional<bool>(value_to_set); | |
166 } | |
167 } | |
168 | |
169 SimulationSettings CreateSettings() { | |
170 SimulationSettings settings; | |
171 if (FLAGS_all_default) { | |
172 settings.use_le = rtc::Optional<bool>(true); | |
173 settings.use_vad = rtc::Optional<bool>(true); | |
174 settings.use_ie = rtc::Optional<bool>(false); | |
175 settings.use_bf = rtc::Optional<bool>(false); | |
176 settings.use_ts = rtc::Optional<bool>(true); | |
177 settings.use_ns = rtc::Optional<bool>(true); | |
178 settings.use_hpf = rtc::Optional<bool>(true); | |
179 settings.use_agc = rtc::Optional<bool>(true); | |
180 settings.use_aec = rtc::Optional<bool>(true); | |
181 settings.use_aecm = rtc::Optional<bool>(false); | |
182 } | |
183 SetSettingIfSpecified(FLAGS_dump_input, &settings.aec_dump_input_filename); | |
184 SetSettingIfSpecified(FLAGS_dump_output, &settings.aec_dump_output_filename); | |
185 SetSettingIfSpecified(FLAGS_i, &settings.input_filename); | |
186 SetSettingIfSpecified(FLAGS_o, &settings.output_filename); | |
187 SetSettingIfSpecified(FLAGS_ri, &settings.reverse_input_filename); | |
188 SetSettingIfSpecified(FLAGS_ro, &settings.reverse_output_filename); | |
189 SetSettingIfSpecified(FLAGS_output_num_channels, | |
190 &settings.output_num_channels); | |
191 SetSettingIfSpecified(FLAGS_reverse_output_num_channels, | |
192 &settings.reverse_output_num_channels); | |
193 SetSettingIfSpecified(FLAGS_output_sample_rate_hz, | |
194 &settings.output_sample_rate_hz); | |
195 SetSettingIfSpecified(FLAGS_reverse_output_sample_rate_hz, | |
196 &settings.reverse_output_sample_rate_hz); | |
197 SetSettingIfSpecified(FLAGS_mic_positions, &settings.microphone_positions); | |
198 settings.target_angle_degrees = FLAGS_target_angle_degrees; | |
199 SetSettingIfFlagSet(FLAGS_aec, &settings.use_aec, true); | |
200 SetSettingIfFlagSet(FLAGS_no_aec, &settings.use_aec, false); | |
201 SetSettingIfFlagSet(FLAGS_aecm, &settings.use_aecm, true); | |
202 SetSettingIfFlagSet(FLAGS_no_aecm, &settings.use_aecm, false); | |
203 SetSettingIfFlagSet(FLAGS_agc, &settings.use_agc, true); | |
204 SetSettingIfFlagSet(FLAGS_no_agc, &settings.use_agc, false); | |
205 SetSettingIfFlagSet(FLAGS_hpf, &settings.use_hpf, true); | |
206 SetSettingIfFlagSet(FLAGS_no_hpf, &settings.use_hpf, false); | |
207 SetSettingIfFlagSet(FLAGS_ns, &settings.use_ns, true); | |
208 SetSettingIfFlagSet(FLAGS_no_ns, &settings.use_ns, false); | |
209 SetSettingIfFlagSet(FLAGS_ts, &settings.use_ts, true); | |
210 SetSettingIfFlagSet(FLAGS_no_ts, &settings.use_ts, false); | |
211 SetSettingIfFlagSet(FLAGS_bf, &settings.use_bf, true); | |
212 SetSettingIfFlagSet(FLAGS_no_bf, &settings.use_bf, false); | |
213 SetSettingIfFlagSet(FLAGS_ie, &settings.use_ie, true); | |
214 SetSettingIfFlagSet(FLAGS_no_ie, &settings.use_ie, false); | |
215 SetSettingIfFlagSet(FLAGS_vad, &settings.use_vad, true); | |
216 SetSettingIfFlagSet(FLAGS_no_vad, &settings.use_vad, false); | |
217 SetSettingIfFlagSet(FLAGS_le, &settings.use_le, true); | |
218 SetSettingIfFlagSet(FLAGS_no_le, &settings.use_le, false); | |
219 SetSettingIfSpecified(FLAGS_aec_suppression_level, | |
220 &settings.aec_suppression_level); | |
221 SetSettingIfFlagSet(FLAGS_delay_agnostic, &settings.use_delay_agnostic, true); | |
222 SetSettingIfFlagSet(FLAGS_no_delay_agnostic, &settings.use_delay_agnostic, | |
223 false); | |
224 SetSettingIfFlagSet(FLAGS_extended_filter, &settings.use_extended_filter, | |
225 true); | |
226 SetSettingIfFlagSet(FLAGS_no_extended_filter, &settings.use_extended_filter, | |
227 false); | |
228 SetSettingIfFlagSet(FLAGS_drift_compensation, | |
229 &settings.use_drift_compensation, true); | |
230 SetSettingIfFlagSet(FLAGS_no_drift_compensation, | |
231 &settings.use_drift_compensation, false); | |
232 SetSettingIfFlagSet(FLAGS_refined_adaptive_filter, | |
233 &settings.use_refined_adaptive_filter, true); | |
234 SetSettingIfFlagSet(FLAGS_no_refined_adaptive_filter, | |
235 &settings.use_refined_adaptive_filter, false); | |
236 | |
237 SetSettingIfFlagSet(FLAGS_aec3, &settings.use_aec3, true); | |
238 SetSettingIfFlagSet(FLAGS_no_aec3, &settings.use_aec3, false); | |
239 SetSettingIfSpecified(FLAGS_aecm_routing_mode, &settings.aecm_routing_mode); | |
240 SetSettingIfFlagSet(FLAGS_aecm_comfort_noise, | |
241 &settings.use_aecm_comfort_noise, true); | |
242 SetSettingIfFlagSet(FLAGS_no_aecm_comfort_noise, | |
243 &settings.use_aecm_comfort_noise, false); | |
244 SetSettingIfSpecified(FLAGS_agc_mode, &settings.agc_mode); | |
245 SetSettingIfSpecified(FLAGS_agc_target_level, &settings.agc_target_level); | |
246 SetSettingIfFlagSet(FLAGS_agc_limiter, &settings.use_agc_limiter, true); | |
247 SetSettingIfFlagSet(FLAGS_no_agc_limiter, &settings.use_agc_limiter, false); | |
248 SetSettingIfSpecified(FLAGS_agc_compression_gain, | |
249 &settings.agc_compression_gain); | |
250 SetSettingIfSpecified(FLAGS_vad_likelihood, &settings.vad_likelihood); | |
251 SetSettingIfSpecified(FLAGS_ns_level, &settings.ns_level); | |
252 SetSettingIfSpecified(FLAGS_stream_delay, &settings.stream_delay); | |
253 SetSettingIfSpecified(FLAGS_stream_drift_samples, | |
254 &settings.stream_drift_samples); | |
255 settings.report_performance = FLAGS_performance_report; | |
256 settings.use_verbose_logging = FLAGS_verbose; | |
257 settings.report_bitexactness = FLAGS_bitexactness_report; | |
258 settings.discard_all_settings_in_aecdump = FLAGS_discard_settings_in_aecdump; | |
259 settings.fixed_interface = FLAGS_fixed_interface; | |
260 settings.store_intermediate_output = FLAGS_store_intermediate_output; | |
261 | |
262 return settings; | |
263 } | |
264 | |
265 void ReportConditionalErrorAndExit(bool condition, std::string message) { | |
266 if (condition) { | |
267 fprintf(stderr, "%s", message.c_str()); | |
aluebs-webrtc
2016/05/11 15:41:55
You can use cerr here.
peah-webrtc
2016/05/18 12:18:50
Thanks!
Done.
| |
268 exit(1); | |
269 } | |
270 } | |
271 | |
272 void PerformBasicParameterSanityChecks(const SimulationSettings& settings) { | |
273 if (settings.input_filename || settings.reverse_input_filename) { | |
274 ReportConditionalErrorAndExit(!!settings.aec_dump_input_filename, | |
275 "Error: The aec dump cannot be specified " | |
276 "together with input wav files!\n"); | |
277 | |
278 ReportConditionalErrorAndExit(!settings.input_filename, | |
279 "Error: When operating at wav files, the " | |
280 "input wav filename must be " | |
281 "specified!\n"); | |
282 | |
283 ReportConditionalErrorAndExit( | |
284 settings.reverse_output_filename && !settings.reverse_input_filename, | |
285 "Error: When operating at wav files, the reverse input wav filename " | |
286 "must be specified if the reverse output wav filename is specified!\n"); | |
287 } else { | |
288 ReportConditionalErrorAndExit(!settings.aec_dump_input_filename, | |
289 "Error: Either the aec dump or the wav " | |
290 "input files must be specified!\n"); | |
291 } | |
292 | |
293 ReportConditionalErrorAndExit( | |
294 settings.use_aec && *settings.use_aec && settings.use_aecm && | |
295 *settings.use_aecm, | |
296 "Error: The AEC and the AECM cannot be activated at the same time!\n"); | |
297 | |
298 ReportConditionalErrorAndExit( | |
299 settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0, | |
300 "Error: --output_sample_rate_hz must be positive!\n"); | |
301 | |
302 ReportConditionalErrorAndExit( | |
303 settings.reverse_output_sample_rate_hz && | |
304 settings.output_sample_rate_hz && | |
305 *settings.output_sample_rate_hz <= 0, | |
306 "Error: --reverse_output_sample_rate_hz must be positive!\n"); | |
307 | |
308 ReportConditionalErrorAndExit( | |
309 settings.output_num_channels && *settings.output_num_channels <= 0, | |
310 "Error: --output_num_channels must be positive!\n"); | |
311 | |
312 ReportConditionalErrorAndExit( | |
313 settings.reverse_output_num_channels && | |
314 *settings.reverse_output_num_channels <= 0, | |
315 "Error: --reverse_output_num_channels must be positive!\n"); | |
316 | |
317 ReportConditionalErrorAndExit( | |
318 settings.use_bf && *settings.use_bf && !settings.microphone_positions, | |
319 "Error: --mic_positions must be specified when the beamformer is " | |
320 "activated.\n"); | |
321 | |
322 ReportConditionalErrorAndExit( | |
323 settings.target_angle_degrees < 0 || settings.target_angle_degrees > 359, | |
324 "Error: -target_angle_degrees must be specified between 0 and 359.\n"); | |
325 | |
326 ReportConditionalErrorAndExit( | |
327 settings.aec_suppression_level && | |
328 ((*settings.aec_suppression_level) < 0 || | |
329 (*settings.aec_suppression_level) > 2), | |
330 "Error: --aec_suppression_level must be specified between 0 and 2.\n"); | |
331 | |
332 ReportConditionalErrorAndExit( | |
333 settings.aecm_routing_mode && ((*settings.aecm_routing_mode) < 0 || | |
334 (*settings.aecm_routing_mode) > 4), | |
335 "Error: --aecm_routing_mode must be specified between 0 and 4.\n"); | |
336 | |
337 ReportConditionalErrorAndExit( | |
338 settings.agc_target_level && ((*settings.agc_target_level) < 0 || | |
339 (*settings.agc_target_level) > 31), | |
340 "Error: --agc_target_level must be specified between 0 and 31.\n"); | |
341 | |
342 ReportConditionalErrorAndExit( | |
343 settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 || | |
344 (*settings.agc_compression_gain) > 90), | |
345 "Error: --agc_compression_gain must be specified between 0 and 90.\n"); | |
346 | |
347 ReportConditionalErrorAndExit( | |
348 settings.vad_likelihood && | |
349 ((*settings.vad_likelihood) < 0 || (*settings.vad_likelihood) > 3), | |
350 "Error: --vad_likelihood must be specified between 0 and 3.\n"); | |
351 | |
352 ReportConditionalErrorAndExit( | |
353 settings.ns_level && | |
354 ((*settings.ns_level) < 0 || (*settings.ns_level) > 3), | |
355 "Error: --ns_level must be specified between 0 and 3.\n"); | |
356 | |
357 ReportConditionalErrorAndExit( | |
358 settings.report_bitexactness && !settings.aec_dump_input_filename, | |
359 "Error: --bitexactness_report can only be used when operating on an " | |
360 "aecdump\n"); | |
361 | |
362 auto valid_wav_name = [](const std::string& wav_file_name) { | |
363 if (wav_file_name.size() < 5) { | |
364 return false; | |
365 } | |
366 if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) || | |
367 (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) { | |
368 return true; | |
369 } | |
370 return false; | |
371 }; | |
372 | |
373 ReportConditionalErrorAndExit( | |
374 settings.input_filename && (!valid_wav_name(*settings.input_filename)), | |
375 "Error: --i must be a valid .wav file name.\n"); | |
376 | |
377 ReportConditionalErrorAndExit( | |
378 settings.output_filename && (!valid_wav_name(*settings.output_filename)), | |
379 "Error: --o must be a valid .wav file name.\n"); | |
380 | |
381 ReportConditionalErrorAndExit( | |
382 settings.reverse_input_filename && | |
383 (!valid_wav_name(*settings.reverse_input_filename)), | |
384 "Error: --ri must be a valid .wav file name.\n"); | |
385 | |
386 ReportConditionalErrorAndExit( | |
387 settings.reverse_output_filename && | |
388 (!valid_wav_name(*settings.reverse_output_filename)), | |
389 "Error: --ro must be a valid .wav file name.\n"); | |
35 } | 390 } |
36 | 391 |
37 } // namespace | 392 } // namespace |
38 | 393 |
39 DEFINE_string(dump, "", "Name of the aecdump debug file to read from."); | |
40 DEFINE_string(i, "", "Name of the capture input stream file to read from."); | |
41 DEFINE_string( | |
42 o, | |
43 "out.wav", | |
44 "Name of the output file to write the processed capture stream to."); | |
45 DEFINE_string(ri, "", "Name of the render input stream file to read from."); | |
46 DEFINE_string( | |
47 ro, | |
48 "out_reverse.wav", | |
49 "Name of the output file to write the processed render stream to."); | |
50 DEFINE_int32(out_channels, 1, "Number of output channels."); | |
51 const bool out_channels_dummy = | |
52 google::RegisterFlagValidator(&FLAGS_out_channels, &ValidateOutChannels); | |
53 DEFINE_int32(rev_out_channels, 1, "Number of reverse output channels."); | |
54 const bool rev_out_channels_dummy = | |
55 google::RegisterFlagValidator(&FLAGS_rev_out_channels, | |
56 &ValidateOutChannels); | |
57 DEFINE_int32(out_sample_rate, 48000, "Output sample rate in Hz."); | |
58 DEFINE_int32(rev_out_sample_rate, 48000, "Reverse output sample rate in Hz."); | |
59 DEFINE_string(mic_positions, "", | |
60 "Space delimited cartesian coordinates of microphones in meters. " | |
61 "The coordinates of each point are contiguous. " | |
62 "For a two element array: \"x1 y1 z1 x2 y2 z2\""); | |
63 DEFINE_double( | |
64 target_angle_degrees, | |
65 90, | |
66 "The azimuth of the target in degrees. Only applies to beamforming."); | |
67 | |
68 DEFINE_bool(aec, false, "Enable echo cancellation."); | |
69 DEFINE_bool(agc, false, "Enable automatic gain control."); | |
70 DEFINE_bool(hpf, false, "Enable high-pass filtering."); | |
71 DEFINE_bool(ns, false, "Enable noise suppression."); | |
72 DEFINE_bool(ts, false, "Enable transient suppression."); | |
73 DEFINE_bool(bf, false, "Enable beamforming."); | |
74 DEFINE_bool(ie, false, "Enable intelligibility enhancer."); | |
75 DEFINE_bool(all, false, "Enable all components."); | |
76 | |
77 DEFINE_int32(ns_level, -1, "Noise suppression level [0 - 3]."); | |
78 | |
79 DEFINE_bool(perf, false, "Enable performance tests."); | |
80 | |
81 namespace webrtc { | |
82 namespace { | |
83 | |
84 const int kChunksPerSecond = 100; | |
85 const char kUsage[] = | |
86 "Command-line tool to run audio processing on WAV files. Accepts either\n" | |
87 "an input capture WAV file or protobuf debug dump and writes to an output\n" | |
88 "WAV file.\n" | |
89 "\n" | |
90 "All components are disabled by default."; | |
91 | |
92 } // namespace | |
93 | |
94 int main(int argc, char* argv[]) { | 394 int main(int argc, char* argv[]) { |
95 google::SetUsageMessage(kUsage); | 395 google::SetUsageMessage(kUsageDescription); |
96 google::ParseCommandLineFlags(&argc, &argv, true); | 396 google::ParseCommandLineFlags(&argc, &argv, true); |
97 | 397 |
98 if (!((FLAGS_i.empty()) ^ (FLAGS_dump.empty()))) { | 398 SimulationSettings settings = CreateSettings(); |
99 fprintf(stderr, | 399 PerformBasicParameterSanityChecks(settings); |
100 "An input file must be specified with either -i or -dump.\n"); | 400 std::unique_ptr<AudioProcessingSimulator> processor; |
101 return 1; | 401 |
102 } | 402 if (settings.aec_dump_input_filename) { |
103 | 403 processor.reset(new AecDumpBasedSimulator(settings)); |
104 test::TraceToStderr trace_to_stderr(true); | |
105 Config config; | |
106 if (FLAGS_bf || FLAGS_all) { | |
107 if (FLAGS_mic_positions.empty()) { | |
108 fprintf(stderr, "-mic_positions must be specified when -bf is used.\n"); | |
109 return 1; | |
110 } | |
111 config.Set<Beamforming>(new Beamforming( | |
112 true, ParseArrayGeometry(FLAGS_mic_positions), | |
113 SphericalPointf(DegreesToRadians(FLAGS_target_angle_degrees), 0.f, | |
114 1.f))); | |
115 } | |
116 config.Set<ExperimentalNs>(new ExperimentalNs(FLAGS_ts || FLAGS_all)); | |
117 config.Set<Intelligibility>(new Intelligibility(FLAGS_ie || FLAGS_all)); | |
118 | |
119 std::unique_ptr<AudioProcessing> ap(AudioProcessing::Create(config)); | |
120 RTC_CHECK_EQ(kNoErr, ap->echo_cancellation()->Enable(FLAGS_aec || FLAGS_all)); | |
121 RTC_CHECK_EQ(kNoErr, ap->gain_control()->Enable(FLAGS_agc || FLAGS_all)); | |
122 RTC_CHECK_EQ(kNoErr, ap->high_pass_filter()->Enable(FLAGS_hpf || FLAGS_all)); | |
123 RTC_CHECK_EQ(kNoErr, ap->noise_suppression()->Enable(FLAGS_ns || FLAGS_all)); | |
124 if (FLAGS_ns_level != -1) { | |
125 RTC_CHECK_EQ(kNoErr, | |
126 ap->noise_suppression()->set_level( | |
127 static_cast<NoiseSuppression::Level>(FLAGS_ns_level))); | |
128 } | |
129 ap->set_stream_key_pressed(FLAGS_ts); | |
130 | |
131 std::unique_ptr<AudioFileProcessor> processor; | |
132 auto out_file = std::unique_ptr<WavWriter>(new WavWriter( | |
133 FLAGS_o, FLAGS_out_sample_rate, static_cast<size_t>(FLAGS_out_channels))); | |
134 std::cout << FLAGS_o << ": " << out_file->FormatAsString() << std::endl; | |
135 if (FLAGS_dump.empty()) { | |
136 auto in_file = std::unique_ptr<WavReader>(new WavReader(FLAGS_i)); | |
137 std::cout << FLAGS_i << ": " << in_file->FormatAsString() << std::endl; | |
138 std::unique_ptr<WavReader> reverse_in_file; | |
139 std::unique_ptr<WavWriter> reverse_out_file; | |
140 if (!FLAGS_ri.empty()) { | |
141 reverse_in_file.reset(new WavReader(FLAGS_ri)); | |
142 reverse_out_file.reset(new WavWriter( | |
143 FLAGS_ro, | |
144 FLAGS_rev_out_sample_rate, | |
145 static_cast<size_t>(FLAGS_rev_out_channels))); | |
146 std::cout << FLAGS_ri << ": " | |
147 << reverse_in_file->FormatAsString() << std::endl; | |
148 std::cout << FLAGS_ro << ": " | |
149 << reverse_out_file->FormatAsString() << std::endl; | |
150 } | |
151 processor.reset(new WavFileProcessor(std::move(ap), | |
152 std::move(in_file), | |
153 std::move(out_file), | |
154 std::move(reverse_in_file), | |
155 std::move(reverse_out_file))); | |
156 | |
157 } else { | 404 } else { |
158 processor.reset(new AecDumpFileProcessor( | 405 processor.reset(new WavBasedSimulator(settings)); |
159 std::move(ap), fopen(FLAGS_dump.c_str(), "rb"), std::move(out_file))); | 406 } |
160 } | 407 |
161 | 408 processor->Process(); |
162 int num_chunks = 0; | 409 |
163 while (processor->ProcessChunk()) { | 410 if (settings.report_performance) { |
164 trace_to_stderr.SetTimeSeconds(num_chunks * 1.f / kChunksPerSecond); | |
165 ++num_chunks; | |
166 } | |
167 | |
168 if (FLAGS_perf) { | |
169 const auto& proc_time = processor->proc_time(); | 411 const auto& proc_time = processor->proc_time(); |
170 int64_t exec_time_us = proc_time.sum.Microseconds(); | 412 int64_t exec_time_us = proc_time.sum.Microseconds(); |
171 printf( | 413 std::cout << std::endl |
172 "\nExecution time: %.3f s, File time: %.2f s\n" | 414 << "Execution time: " << exec_time_us * 1e-6 << " s, File time: " |
173 "Time per chunk (mean, max, min):\n%.0f us, %.0f us, %.0f us\n", | 415 << processor->get_num_process_stream_calls() * 1.f / |
174 exec_time_us * 1e-6, num_chunks * 1.f / kChunksPerSecond, | 416 AudioProcessingSimulator::kChunksPerSecond |
175 exec_time_us * 1.f / num_chunks, 1.f * proc_time.max.Microseconds(), | 417 << std::endl |
176 1.f * proc_time.min.Microseconds()); | 418 << "Time per fwd stream chunk (mean, max, min): " << std::endl |
419 << exec_time_us * 1.f / processor->get_num_process_stream_calls() | |
420 << " us, " << 1.f * proc_time.max.Microseconds() << " us, " | |
421 << 1.f * proc_time.min.Microseconds() << " us" << std::endl; | |
422 } | |
423 | |
424 if (settings.report_bitexactness && settings.aec_dump_input_filename) { | |
425 if (processor->OutputWasBitexact()) { | |
426 std::cout << "The processing was bitexact."; | |
427 } else { | |
428 std::cout << "The processing was not bitexact."; | |
429 } | |
177 } | 430 } |
178 | 431 |
179 return 0; | 432 return 0; |
180 } | 433 } |
181 | 434 |
435 } // namespace test | |
182 } // namespace webrtc | 436 } // namespace webrtc |
183 | 437 |
184 int main(int argc, char* argv[]) { | 438 int main(int argc, char* argv[]) { |
185 return webrtc::main(argc, argv); | 439 return webrtc::test::main(argc, argv); |
186 } | 440 } |
OLD | NEW |