blob: 1d3f4273deb993c3d1424ff40ae6129f934aa7f5 [file] [log] [blame]
andrew@webrtc.org08df9b22014-12-16 20:57:15 +00001/*
2 * Copyright (c) 2014 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
aluebsb0ad43b2015-11-20 00:11:53 -080011#include <iostream>
kwiberg62eaacf2016-02-17 06:39:05 -080012#include <memory>
peah60a189f2016-05-24 20:54:40 -070013
14#include <string.h>
andrew@webrtc.org08df9b22014-12-16 20:57:15 +000015
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_processing/include/audio_processing.h"
17#include "modules/audio_processing/test/aec_dump_based_simulator.h"
18#include "modules/audio_processing/test/audio_processing_simulator.h"
Ivo Creusen8c812f32018-03-09 17:33:04 +010019#include "modules/audio_processing/test/audioproc_float.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_processing/test/wav_based_simulator.h"
21#include "rtc_base/flags.h"
andrew@webrtc.org08df9b22014-12-16 20:57:15 +000022
peah60a189f2016-05-24 20:54:40 -070023namespace webrtc {
24namespace test {
Peter Kasting69558702016-01-12 16:26:35 -080025namespace {
26
peah60a189f2016-05-24 20:54:40 -070027const int kParameterNotSpecifiedValue = -10000;
28
29const char kUsageDescription[] =
30 "Usage: audioproc_f [options] -i <input.wav>\n"
31 " or\n"
32 " audioproc_f [options] -dump_input <aec_dump>\n"
33 "\n\n"
34 "Command-line tool to simulate a call using the audio "
35 "processing module, either based on wav files or "
oprypin6e09d872017-08-31 03:21:39 -070036 "protobuf debug dump recordings.\n";
peah60a189f2016-05-24 20:54:40 -070037
38DEFINE_string(dump_input, "", "Aec dump input filename");
39DEFINE_string(dump_output, "", "Aec dump output filename");
40DEFINE_string(i, "", "Forward stream input wav filename");
41DEFINE_string(o, "", "Forward stream output wav filename");
42DEFINE_string(ri, "", "Reverse stream input wav filename");
43DEFINE_string(ro, "", "Reverse stream output wav filename");
peahdf80fd12016-12-09 02:43:40 -080044DEFINE_string(artificial_nearend, "", "Artificial nearend wav filename");
oprypin6e09d872017-08-31 03:21:39 -070045DEFINE_int(output_num_channels,
46 kParameterNotSpecifiedValue,
47 "Number of forward stream output channels");
48DEFINE_int(reverse_output_num_channels,
49 kParameterNotSpecifiedValue,
50 "Number of Reverse stream output channels");
51DEFINE_int(output_sample_rate_hz,
52 kParameterNotSpecifiedValue,
53 "Forward stream output sample rate in Hz");
54DEFINE_int(reverse_output_sample_rate_hz,
55 kParameterNotSpecifiedValue,
56 "Reverse stream output sample rate in Hz");
peah60a189f2016-05-24 20:54:40 -070057DEFINE_string(mic_positions,
58 "",
59 "Space delimited cartesian coordinates of microphones in "
60 "meters. The coordinates of each point are contiguous. For a "
61 "two element array: \"x1 y1 z1 x2 y2 z2\"");
oprypin6e09d872017-08-31 03:21:39 -070062DEFINE_int(target_angle_degrees,
63 90,
64 "The azimuth of the target in degrees (0-359). Only applies to "
65 "beamforming.");
peah60a189f2016-05-24 20:54:40 -070066DEFINE_bool(fixed_interface,
67 false,
68 "Use the fixed interface when operating on wav files");
oprypin6e09d872017-08-31 03:21:39 -070069DEFINE_int(aec,
70 kParameterNotSpecifiedValue,
71 "Activate (1) or deactivate(0) the echo canceller");
72DEFINE_int(aecm,
73 kParameterNotSpecifiedValue,
74 "Activate (1) or deactivate(0) the mobile echo controller");
75DEFINE_int(ed,
76 kParameterNotSpecifiedValue,
77 "Activate (1) or deactivate (0) the residual echo detector");
ivoc0bff12a2016-11-17 00:55:43 -080078DEFINE_string(ed_graph, "", "Output filename for graph of echo likelihood");
oprypin6e09d872017-08-31 03:21:39 -070079DEFINE_int(agc,
80 kParameterNotSpecifiedValue,
81 "Activate (1) or deactivate(0) the AGC");
82DEFINE_int(agc2,
83 kParameterNotSpecifiedValue,
84 "Activate (1) or deactivate(0) the AGC2");
85DEFINE_int(hpf,
86 kParameterNotSpecifiedValue,
87 "Activate (1) or deactivate(0) the high-pass filter");
88DEFINE_int(ns,
89 kParameterNotSpecifiedValue,
90 "Activate (1) or deactivate(0) the noise suppressor");
91DEFINE_int(ts,
92 kParameterNotSpecifiedValue,
93 "Activate (1) or deactivate(0) the transient suppressor");
94DEFINE_int(bf,
95 kParameterNotSpecifiedValue,
96 "Activate (1) or deactivate(0) the beamformer");
97DEFINE_int(ie,
98 kParameterNotSpecifiedValue,
99 "Activate (1) or deactivate(0) the intelligibility enhancer");
100DEFINE_int(vad,
101 kParameterNotSpecifiedValue,
102 "Activate (1) or deactivate(0) the voice activity detector");
103DEFINE_int(le,
104 kParameterNotSpecifiedValue,
105 "Activate (1) or deactivate(0) the level estimator");
peah60a189f2016-05-24 20:54:40 -0700106DEFINE_bool(all_default,
107 false,
108 "Activate all of the default components (will be overridden by any "
109 "other settings)");
oprypin6e09d872017-08-31 03:21:39 -0700110DEFINE_int(aec_suppression_level,
111 kParameterNotSpecifiedValue,
112 "Set the aec suppression level (0-2)");
113DEFINE_int(delay_agnostic,
114 kParameterNotSpecifiedValue,
115 "Activate (1) or deactivate(0) the AEC delay agnostic mode");
116DEFINE_int(extended_filter,
117 kParameterNotSpecifiedValue,
118 "Activate (1) or deactivate(0) the AEC extended filter mode");
119DEFINE_int(drift_compensation,
120 kParameterNotSpecifiedValue,
121 "Activate (1) or deactivate(0) the drift compensation");
122DEFINE_int(aec3,
123 kParameterNotSpecifiedValue,
124 "Activate (1) or deactivate(0) the experimental AEC mode AEC3");
oprypin6e09d872017-08-31 03:21:39 -0700125DEFINE_int(experimental_agc,
126 kParameterNotSpecifiedValue,
127 "Activate (1) or deactivate(0) the experimental AGC");
128DEFINE_int(
peah60a189f2016-05-24 20:54:40 -0700129 refined_adaptive_filter,
130 kParameterNotSpecifiedValue,
131 "Activate (1) or deactivate(0) the refined adaptive filter functionality");
oprypin6e09d872017-08-31 03:21:39 -0700132DEFINE_int(aecm_routing_mode,
133 kParameterNotSpecifiedValue,
134 "Specify the AECM routing mode (0-4)");
135DEFINE_int(aecm_comfort_noise,
136 kParameterNotSpecifiedValue,
137 "Activate (1) or deactivate(0) the AECM comfort noise");
138DEFINE_int(agc_mode,
139 kParameterNotSpecifiedValue,
140 "Specify the AGC mode (0-2)");
141DEFINE_int(agc_target_level,
142 kParameterNotSpecifiedValue,
143 "Specify the AGC target level (0-31)");
144DEFINE_int(agc_limiter,
145 kParameterNotSpecifiedValue,
146 "Activate (1) or deactivate(0) the level estimator");
147DEFINE_int(agc_compression_gain,
148 kParameterNotSpecifiedValue,
149 "Specify the AGC compression gain (0-90)");
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200150DEFINE_float(agc2_fixed_gain_db, 0.f, "AGC2 fixed gain (dB) to apply");
oprypin6e09d872017-08-31 03:21:39 -0700151DEFINE_int(vad_likelihood,
152 kParameterNotSpecifiedValue,
153 "Specify the VAD likelihood (0-3)");
154DEFINE_int(ns_level,
155 kParameterNotSpecifiedValue,
156 "Specify the NS level (0-3)");
157DEFINE_int(stream_delay,
158 kParameterNotSpecifiedValue,
159 "Specify the stream delay in ms to use");
160DEFINE_int(stream_drift_samples,
161 kParameterNotSpecifiedValue,
162 "Specify the number of stream drift samples to use");
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200163DEFINE_int(initial_mic_level, 100, "Initial mic level (0-255)");
164DEFINE_int(simulate_mic_gain,
165 0,
166 "Activate (1) or deactivate(0) the analog mic gain simulation");
167DEFINE_int(simulated_mic_kind,
168 kParameterNotSpecifiedValue,
169 "Specify which microphone kind to use for microphone simulation");
peah60a189f2016-05-24 20:54:40 -0700170DEFINE_bool(performance_report, false, "Report the APM performance ");
171DEFINE_bool(verbose, false, "Produce verbose output");
172DEFINE_bool(bitexactness_report,
173 false,
174 "Report bitexactness for aec dump result reproduction");
175DEFINE_bool(discard_settings_in_aecdump,
176 false,
177 "Discard any config settings specified in the aec dump");
178DEFINE_bool(store_intermediate_output,
179 false,
180 "Creates new output files after each init");
peah5ad5de32016-12-09 03:18:22 -0800181DEFINE_string(custom_call_order_file, "", "Custom process API call order file");
Per Ã…hgrenad09d742018-03-08 07:47:14 +0100182DEFINE_string(aec3_settings,
183 "",
184 "File in JSON-format with custom AEC3 settings");
oprypin6e09d872017-08-31 03:21:39 -0700185DEFINE_bool(help, false, "Print this message");
peah60a189f2016-05-24 20:54:40 -0700186
Alex Loiko890988c2017-08-31 10:25:48 +0200187void SetSettingIfSpecified(const std::string& value,
peah60a189f2016-05-24 20:54:40 -0700188 rtc::Optional<std::string>* parameter) {
189 if (value.compare("") != 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100190 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700191 }
192}
193
194void SetSettingIfSpecified(int value, rtc::Optional<int>* parameter) {
195 if (value != kParameterNotSpecifiedValue) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100196 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700197 }
198}
199
200void SetSettingIfFlagSet(int32_t flag, rtc::Optional<bool>* parameter) {
201 if (flag == 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100202 *parameter = false;
peah60a189f2016-05-24 20:54:40 -0700203 } else if (flag == 1) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100204 *parameter = true;
peah60a189f2016-05-24 20:54:40 -0700205 }
206}
207
208SimulationSettings CreateSettings() {
209 SimulationSettings settings;
oprypin6e09d872017-08-31 03:21:39 -0700210 if (FLAG_all_default) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100211 settings.use_le = true;
212 settings.use_vad = true;
213 settings.use_ie = false;
214 settings.use_bf = false;
215 settings.use_ts = true;
216 settings.use_ns = true;
217 settings.use_hpf = true;
218 settings.use_agc = true;
219 settings.use_agc2 = false;
220 settings.use_aec = true;
221 settings.use_aecm = false;
222 settings.use_ed = false;
peah60a189f2016-05-24 20:54:40 -0700223 }
oprypin6e09d872017-08-31 03:21:39 -0700224 SetSettingIfSpecified(FLAG_dump_input, &settings.aec_dump_input_filename);
225 SetSettingIfSpecified(FLAG_dump_output, &settings.aec_dump_output_filename);
226 SetSettingIfSpecified(FLAG_i, &settings.input_filename);
227 SetSettingIfSpecified(FLAG_o, &settings.output_filename);
228 SetSettingIfSpecified(FLAG_ri, &settings.reverse_input_filename);
229 SetSettingIfSpecified(FLAG_ro, &settings.reverse_output_filename);
230 SetSettingIfSpecified(FLAG_artificial_nearend,
peahdf80fd12016-12-09 02:43:40 -0800231 &settings.artificial_nearend_filename);
oprypin6e09d872017-08-31 03:21:39 -0700232 SetSettingIfSpecified(FLAG_output_num_channels,
peah60a189f2016-05-24 20:54:40 -0700233 &settings.output_num_channels);
oprypin6e09d872017-08-31 03:21:39 -0700234 SetSettingIfSpecified(FLAG_reverse_output_num_channels,
peah60a189f2016-05-24 20:54:40 -0700235 &settings.reverse_output_num_channels);
oprypin6e09d872017-08-31 03:21:39 -0700236 SetSettingIfSpecified(FLAG_output_sample_rate_hz,
peah60a189f2016-05-24 20:54:40 -0700237 &settings.output_sample_rate_hz);
oprypin6e09d872017-08-31 03:21:39 -0700238 SetSettingIfSpecified(FLAG_reverse_output_sample_rate_hz,
peah60a189f2016-05-24 20:54:40 -0700239 &settings.reverse_output_sample_rate_hz);
oprypin6e09d872017-08-31 03:21:39 -0700240 SetSettingIfSpecified(FLAG_mic_positions, &settings.microphone_positions);
241 settings.target_angle_degrees = FLAG_target_angle_degrees;
242 SetSettingIfFlagSet(FLAG_aec, &settings.use_aec);
243 SetSettingIfFlagSet(FLAG_aecm, &settings.use_aecm);
244 SetSettingIfFlagSet(FLAG_ed, &settings.use_ed);
245 SetSettingIfSpecified(FLAG_ed_graph, &settings.ed_graph_output_filename);
246 SetSettingIfFlagSet(FLAG_agc, &settings.use_agc);
247 SetSettingIfFlagSet(FLAG_agc2, &settings.use_agc2);
248 SetSettingIfFlagSet(FLAG_hpf, &settings.use_hpf);
249 SetSettingIfFlagSet(FLAG_ns, &settings.use_ns);
250 SetSettingIfFlagSet(FLAG_ts, &settings.use_ts);
251 SetSettingIfFlagSet(FLAG_bf, &settings.use_bf);
252 SetSettingIfFlagSet(FLAG_ie, &settings.use_ie);
253 SetSettingIfFlagSet(FLAG_vad, &settings.use_vad);
254 SetSettingIfFlagSet(FLAG_le, &settings.use_le);
255 SetSettingIfSpecified(FLAG_aec_suppression_level,
peah60a189f2016-05-24 20:54:40 -0700256 &settings.aec_suppression_level);
oprypin6e09d872017-08-31 03:21:39 -0700257 SetSettingIfFlagSet(FLAG_delay_agnostic, &settings.use_delay_agnostic);
258 SetSettingIfFlagSet(FLAG_extended_filter, &settings.use_extended_filter);
259 SetSettingIfFlagSet(FLAG_drift_compensation,
peah60a189f2016-05-24 20:54:40 -0700260 &settings.use_drift_compensation);
oprypin6e09d872017-08-31 03:21:39 -0700261 SetSettingIfFlagSet(FLAG_refined_adaptive_filter,
peah60a189f2016-05-24 20:54:40 -0700262 &settings.use_refined_adaptive_filter);
263
oprypin6e09d872017-08-31 03:21:39 -0700264 SetSettingIfFlagSet(FLAG_aec3, &settings.use_aec3);
oprypin6e09d872017-08-31 03:21:39 -0700265 SetSettingIfFlagSet(FLAG_experimental_agc, &settings.use_experimental_agc);
266 SetSettingIfSpecified(FLAG_aecm_routing_mode, &settings.aecm_routing_mode);
267 SetSettingIfFlagSet(FLAG_aecm_comfort_noise,
peah60a189f2016-05-24 20:54:40 -0700268 &settings.use_aecm_comfort_noise);
oprypin6e09d872017-08-31 03:21:39 -0700269 SetSettingIfSpecified(FLAG_agc_mode, &settings.agc_mode);
270 SetSettingIfSpecified(FLAG_agc_target_level, &settings.agc_target_level);
271 SetSettingIfFlagSet(FLAG_agc_limiter, &settings.use_agc_limiter);
272 SetSettingIfSpecified(FLAG_agc_compression_gain,
peah60a189f2016-05-24 20:54:40 -0700273 &settings.agc_compression_gain);
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200274 settings.agc2_fixed_gain_db = FLAG_agc2_fixed_gain_db;
oprypin6e09d872017-08-31 03:21:39 -0700275 SetSettingIfSpecified(FLAG_vad_likelihood, &settings.vad_likelihood);
276 SetSettingIfSpecified(FLAG_ns_level, &settings.ns_level);
277 SetSettingIfSpecified(FLAG_stream_delay, &settings.stream_delay);
278 SetSettingIfSpecified(FLAG_stream_drift_samples,
peah60a189f2016-05-24 20:54:40 -0700279 &settings.stream_drift_samples);
oprypin6e09d872017-08-31 03:21:39 -0700280 SetSettingIfSpecified(FLAG_custom_call_order_file,
peah5ad5de32016-12-09 03:18:22 -0800281 &settings.custom_call_order_filename);
Per Ã…hgrenad09d742018-03-08 07:47:14 +0100282 SetSettingIfSpecified(FLAG_aec3_settings, &settings.aec3_settings_filename);
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200283 settings.initial_mic_level = FLAG_initial_mic_level;
284 settings.simulate_mic_gain = FLAG_simulate_mic_gain;
285 SetSettingIfSpecified(FLAG_simulated_mic_kind, &settings.simulated_mic_kind);
oprypin6e09d872017-08-31 03:21:39 -0700286 settings.report_performance = FLAG_performance_report;
287 settings.use_verbose_logging = FLAG_verbose;
288 settings.report_bitexactness = FLAG_bitexactness_report;
289 settings.discard_all_settings_in_aecdump = FLAG_discard_settings_in_aecdump;
290 settings.fixed_interface = FLAG_fixed_interface;
291 settings.store_intermediate_output = FLAG_store_intermediate_output;
peah60a189f2016-05-24 20:54:40 -0700292
293 return settings;
294}
295
Alex Loiko890988c2017-08-31 10:25:48 +0200296void ReportConditionalErrorAndExit(bool condition, const std::string& message) {
peah60a189f2016-05-24 20:54:40 -0700297 if (condition) {
298 std::cerr << message << std::endl;
299 exit(1);
300 }
301}
302
303void PerformBasicParameterSanityChecks(const SimulationSettings& settings) {
304 if (settings.input_filename || settings.reverse_input_filename) {
305 ReportConditionalErrorAndExit(!!settings.aec_dump_input_filename,
306 "Error: The aec dump cannot be specified "
307 "together with input wav files!\n");
308
peahdf80fd12016-12-09 02:43:40 -0800309 ReportConditionalErrorAndExit(!!settings.artificial_nearend_filename,
310 "Error: The artificial nearend cannot be "
311 "specified together with input wav files!\n");
312
peah60a189f2016-05-24 20:54:40 -0700313 ReportConditionalErrorAndExit(!settings.input_filename,
314 "Error: When operating at wav files, the "
315 "input wav filename must be "
316 "specified!\n");
317
318 ReportConditionalErrorAndExit(
319 settings.reverse_output_filename && !settings.reverse_input_filename,
320 "Error: When operating at wav files, the reverse input wav filename "
321 "must be specified if the reverse output wav filename is specified!\n");
322 } else {
323 ReportConditionalErrorAndExit(!settings.aec_dump_input_filename,
324 "Error: Either the aec dump or the wav "
325 "input files must be specified!\n");
326 }
327
328 ReportConditionalErrorAndExit(
329 settings.use_aec && *settings.use_aec && settings.use_aecm &&
330 *settings.use_aecm,
331 "Error: The AEC and the AECM cannot be activated at the same time!\n");
332
333 ReportConditionalErrorAndExit(
334 settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0,
335 "Error: --output_sample_rate_hz must be positive!\n");
336
337 ReportConditionalErrorAndExit(
338 settings.reverse_output_sample_rate_hz &&
339 settings.output_sample_rate_hz &&
340 *settings.output_sample_rate_hz <= 0,
341 "Error: --reverse_output_sample_rate_hz must be positive!\n");
342
343 ReportConditionalErrorAndExit(
344 settings.output_num_channels && *settings.output_num_channels <= 0,
345 "Error: --output_num_channels must be positive!\n");
346
347 ReportConditionalErrorAndExit(
348 settings.reverse_output_num_channels &&
349 *settings.reverse_output_num_channels <= 0,
350 "Error: --reverse_output_num_channels must be positive!\n");
351
352 ReportConditionalErrorAndExit(
353 settings.use_bf && *settings.use_bf && !settings.microphone_positions,
354 "Error: --mic_positions must be specified when the beamformer is "
355 "activated.\n");
356
357 ReportConditionalErrorAndExit(
358 settings.target_angle_degrees < 0 || settings.target_angle_degrees > 359,
359 "Error: -target_angle_degrees must be specified between 0 and 359.\n");
360
361 ReportConditionalErrorAndExit(
362 settings.aec_suppression_level &&
363 ((*settings.aec_suppression_level) < 0 ||
364 (*settings.aec_suppression_level) > 2),
365 "Error: --aec_suppression_level must be specified between 0 and 2.\n");
366
367 ReportConditionalErrorAndExit(
368 settings.aecm_routing_mode && ((*settings.aecm_routing_mode) < 0 ||
369 (*settings.aecm_routing_mode) > 4),
370 "Error: --aecm_routing_mode must be specified between 0 and 4.\n");
371
372 ReportConditionalErrorAndExit(
373 settings.agc_target_level && ((*settings.agc_target_level) < 0 ||
374 (*settings.agc_target_level) > 31),
375 "Error: --agc_target_level must be specified between 0 and 31.\n");
376
377 ReportConditionalErrorAndExit(
378 settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 ||
379 (*settings.agc_compression_gain) > 90),
380 "Error: --agc_compression_gain must be specified between 0 and 90.\n");
381
382 ReportConditionalErrorAndExit(
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200383 settings.use_agc && *settings.use_agc && settings.use_agc2 &&
384 *settings.use_agc2,
385 "Error: --agc and --agc2 cannot be both active.\n");
386
387 ReportConditionalErrorAndExit(
388 settings.use_agc2 && *settings.use_agc2 &&
389 ((settings.agc2_fixed_gain_db) < 0 ||
390 (settings.agc2_fixed_gain_db) > 90),
391 "Error: --agc2_fixed_gain_db must be specified between 0 and 90.\n");
392
393 ReportConditionalErrorAndExit(
peah60a189f2016-05-24 20:54:40 -0700394 settings.vad_likelihood &&
395 ((*settings.vad_likelihood) < 0 || (*settings.vad_likelihood) > 3),
396 "Error: --vad_likelihood must be specified between 0 and 3.\n");
397
398 ReportConditionalErrorAndExit(
399 settings.ns_level &&
400 ((*settings.ns_level) < 0 || (*settings.ns_level) > 3),
401 "Error: --ns_level must be specified between 0 and 3.\n");
402
403 ReportConditionalErrorAndExit(
404 settings.report_bitexactness && !settings.aec_dump_input_filename,
405 "Error: --bitexactness_report can only be used when operating on an "
406 "aecdump\n");
407
peah5ad5de32016-12-09 03:18:22 -0800408 ReportConditionalErrorAndExit(
409 settings.custom_call_order_filename && settings.aec_dump_input_filename,
410 "Error: --custom_call_order_file cannot be used when operating on an "
411 "aecdump\n");
412
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200413 ReportConditionalErrorAndExit(
414 (settings.initial_mic_level < 0 || settings.initial_mic_level > 255),
415 "Error: --initial_mic_level must be specified between 0 and 255.\n");
416
417 ReportConditionalErrorAndExit(
418 settings.simulated_mic_kind && !settings.simulate_mic_gain,
419 "Error: --simulated_mic_kind cannot be specified when mic simulation is "
420 "disabled\n");
421
422 ReportConditionalErrorAndExit(
423 !settings.simulated_mic_kind && settings.simulate_mic_gain,
424 "Error: --simulated_mic_kind must be specified when mic simulation is "
425 "enabled\n");
426
peah60a189f2016-05-24 20:54:40 -0700427 auto valid_wav_name = [](const std::string& wav_file_name) {
428 if (wav_file_name.size() < 5) {
429 return false;
430 }
431 if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) ||
432 (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) {
433 return true;
434 }
435 return false;
436 };
437
438 ReportConditionalErrorAndExit(
439 settings.input_filename && (!valid_wav_name(*settings.input_filename)),
440 "Error: --i must be a valid .wav file name.\n");
441
442 ReportConditionalErrorAndExit(
443 settings.output_filename && (!valid_wav_name(*settings.output_filename)),
444 "Error: --o must be a valid .wav file name.\n");
445
446 ReportConditionalErrorAndExit(
447 settings.reverse_input_filename &&
448 (!valid_wav_name(*settings.reverse_input_filename)),
449 "Error: --ri must be a valid .wav file name.\n");
450
451 ReportConditionalErrorAndExit(
452 settings.reverse_output_filename &&
453 (!valid_wav_name(*settings.reverse_output_filename)),
454 "Error: --ro must be a valid .wav file name.\n");
peahdf80fd12016-12-09 02:43:40 -0800455
456 ReportConditionalErrorAndExit(
457 settings.artificial_nearend_filename &&
458 !valid_wav_name(*settings.artificial_nearend_filename),
459 "Error: --artifical_nearend must be a valid .wav file name.\n");
Peter Kasting69558702016-01-12 16:26:35 -0800460}
461
462} // namespace
463
Ivo Creusen8c812f32018-03-09 17:33:04 +0100464int audioproc_f(std::unique_ptr<AudioProcessingBuilder> ap_builder,
465 int argc,
466 char* argv[]) {
oprypin6e09d872017-08-31 03:21:39 -0700467 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) ||
468 FLAG_help || argc != 1) {
469 printf("%s", kUsageDescription);
470 if (FLAG_help) {
471 rtc::FlagList::Print(nullptr, false);
472 return 0;
473 }
474 return 1;
475 }
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000476
peah60a189f2016-05-24 20:54:40 -0700477 SimulationSettings settings = CreateSettings();
478 PerformBasicParameterSanityChecks(settings);
479 std::unique_ptr<AudioProcessingSimulator> processor;
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000480
peah60a189f2016-05-24 20:54:40 -0700481 if (settings.aec_dump_input_filename) {
Ivo Creusen8c812f32018-03-09 17:33:04 +0100482 processor.reset(new AecDumpBasedSimulator(settings, std::move(ap_builder)));
aluebsb0ad43b2015-11-20 00:11:53 -0800483 } else {
Ivo Creusen8c812f32018-03-09 17:33:04 +0100484 processor.reset(new WavBasedSimulator(settings, std::move(ap_builder)));
andrewbdafe312015-10-29 23:42:54 -0700485 }
486
peah60a189f2016-05-24 20:54:40 -0700487 processor->Process();
aluebsb0ad43b2015-11-20 00:11:53 -0800488
peah60a189f2016-05-24 20:54:40 -0700489 if (settings.report_performance) {
aluebsb0ad43b2015-11-20 00:11:53 -0800490 const auto& proc_time = processor->proc_time();
Niels Möllerd28db7f2016-05-10 16:31:47 +0200491 int64_t exec_time_us = proc_time.sum / rtc::kNumNanosecsPerMicrosec;
peah60a189f2016-05-24 20:54:40 -0700492 std::cout << std::endl
493 << "Execution time: " << exec_time_us * 1e-6 << " s, File time: "
494 << processor->get_num_process_stream_calls() * 1.f /
495 AudioProcessingSimulator::kChunksPerSecond
496 << std::endl
497 << "Time per fwd stream chunk (mean, max, min): " << std::endl
498 << exec_time_us * 1.f / processor->get_num_process_stream_calls()
499 << " us, " << 1.f * proc_time.max / rtc::kNumNanosecsPerMicrosec
500 << " us, " << 1.f * proc_time.min / rtc::kNumNanosecsPerMicrosec
501 << " us" << std::endl;
502 }
503
504 if (settings.report_bitexactness && settings.aec_dump_input_filename) {
505 if (processor->OutputWasBitexact()) {
506 std::cout << "The processing was bitexact.";
507 } else {
508 std::cout << "The processing was not bitexact.";
509 }
Alejandro Luebs5d22c002015-04-15 11:26:40 -0700510 }
aluebsb0ad43b2015-11-20 00:11:53 -0800511
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000512 return 0;
513}
514
peah60a189f2016-05-24 20:54:40 -0700515} // namespace test
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000516} // namespace webrtc