blob: de6fb6551f9413e288b7354cca29e16e23c32344 [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
Ivo Creusen2cb41052018-03-15 12:22:52 +010011#include <string.h>
12
aluebsb0ad43b2015-11-20 00:11:53 -080013#include <iostream>
kwiberg62eaacf2016-02-17 06:39:05 -080014#include <memory>
Ivo Creusen2cb41052018-03-15 12:22:52 +010015#include <string>
16#include <utility>
andrew@webrtc.org08df9b22014-12-16 20:57:15 +000017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_processing/include/audio_processing.h"
19#include "modules/audio_processing/test/aec_dump_based_simulator.h"
20#include "modules/audio_processing/test/audio_processing_simulator.h"
Ivo Creusen2cb41052018-03-15 12:22:52 +010021#include "modules/audio_processing/test/audioproc_float_impl.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "modules/audio_processing/test/wav_based_simulator.h"
23#include "rtc_base/flags.h"
andrew@webrtc.org08df9b22014-12-16 20:57:15 +000024
peah60a189f2016-05-24 20:54:40 -070025namespace webrtc {
26namespace test {
Peter Kasting69558702016-01-12 16:26:35 -080027namespace {
28
peah60a189f2016-05-24 20:54:40 -070029const int kParameterNotSpecifiedValue = -10000;
30
31const char kUsageDescription[] =
32 "Usage: audioproc_f [options] -i <input.wav>\n"
33 " or\n"
34 " audioproc_f [options] -dump_input <aec_dump>\n"
35 "\n\n"
36 "Command-line tool to simulate a call using the audio "
37 "processing module, either based on wav files or "
oprypin6e09d872017-08-31 03:21:39 -070038 "protobuf debug dump recordings.\n";
peah60a189f2016-05-24 20:54:40 -070039
40DEFINE_string(dump_input, "", "Aec dump input filename");
41DEFINE_string(dump_output, "", "Aec dump output filename");
42DEFINE_string(i, "", "Forward stream input wav filename");
43DEFINE_string(o, "", "Forward stream output wav filename");
44DEFINE_string(ri, "", "Reverse stream input wav filename");
45DEFINE_string(ro, "", "Reverse stream output wav filename");
peahdf80fd12016-12-09 02:43:40 -080046DEFINE_string(artificial_nearend, "", "Artificial nearend wav filename");
oprypin6e09d872017-08-31 03:21:39 -070047DEFINE_int(output_num_channels,
48 kParameterNotSpecifiedValue,
49 "Number of forward stream output channels");
50DEFINE_int(reverse_output_num_channels,
51 kParameterNotSpecifiedValue,
52 "Number of Reverse stream output channels");
53DEFINE_int(output_sample_rate_hz,
54 kParameterNotSpecifiedValue,
55 "Forward stream output sample rate in Hz");
56DEFINE_int(reverse_output_sample_rate_hz,
57 kParameterNotSpecifiedValue,
58 "Reverse stream output sample rate in Hz");
peah60a189f2016-05-24 20:54:40 -070059DEFINE_string(mic_positions,
60 "",
61 "Space delimited cartesian coordinates of microphones in "
62 "meters. The coordinates of each point are contiguous. For a "
63 "two element array: \"x1 y1 z1 x2 y2 z2\"");
oprypin6e09d872017-08-31 03:21:39 -070064DEFINE_int(target_angle_degrees,
65 90,
66 "The azimuth of the target in degrees (0-359). Only applies to "
67 "beamforming.");
peah60a189f2016-05-24 20:54:40 -070068DEFINE_bool(fixed_interface,
69 false,
70 "Use the fixed interface when operating on wav files");
oprypin6e09d872017-08-31 03:21:39 -070071DEFINE_int(aec,
72 kParameterNotSpecifiedValue,
73 "Activate (1) or deactivate(0) the echo canceller");
74DEFINE_int(aecm,
75 kParameterNotSpecifiedValue,
76 "Activate (1) or deactivate(0) the mobile echo controller");
77DEFINE_int(ed,
78 kParameterNotSpecifiedValue,
79 "Activate (1) or deactivate (0) the residual echo detector");
ivoc0bff12a2016-11-17 00:55:43 -080080DEFINE_string(ed_graph, "", "Output filename for graph of echo likelihood");
oprypin6e09d872017-08-31 03:21:39 -070081DEFINE_int(agc,
82 kParameterNotSpecifiedValue,
83 "Activate (1) or deactivate(0) the AGC");
84DEFINE_int(agc2,
85 kParameterNotSpecifiedValue,
86 "Activate (1) or deactivate(0) the AGC2");
87DEFINE_int(hpf,
88 kParameterNotSpecifiedValue,
89 "Activate (1) or deactivate(0) the high-pass filter");
90DEFINE_int(ns,
91 kParameterNotSpecifiedValue,
92 "Activate (1) or deactivate(0) the noise suppressor");
93DEFINE_int(ts,
94 kParameterNotSpecifiedValue,
95 "Activate (1) or deactivate(0) the transient suppressor");
96DEFINE_int(bf,
97 kParameterNotSpecifiedValue,
98 "Activate (1) or deactivate(0) the beamformer");
99DEFINE_int(ie,
100 kParameterNotSpecifiedValue,
101 "Activate (1) or deactivate(0) the intelligibility enhancer");
102DEFINE_int(vad,
103 kParameterNotSpecifiedValue,
104 "Activate (1) or deactivate(0) the voice activity detector");
105DEFINE_int(le,
106 kParameterNotSpecifiedValue,
107 "Activate (1) or deactivate(0) the level estimator");
peah60a189f2016-05-24 20:54:40 -0700108DEFINE_bool(all_default,
109 false,
110 "Activate all of the default components (will be overridden by any "
111 "other settings)");
oprypin6e09d872017-08-31 03:21:39 -0700112DEFINE_int(aec_suppression_level,
113 kParameterNotSpecifiedValue,
114 "Set the aec suppression level (0-2)");
115DEFINE_int(delay_agnostic,
116 kParameterNotSpecifiedValue,
117 "Activate (1) or deactivate(0) the AEC delay agnostic mode");
118DEFINE_int(extended_filter,
119 kParameterNotSpecifiedValue,
120 "Activate (1) or deactivate(0) the AEC extended filter mode");
121DEFINE_int(drift_compensation,
122 kParameterNotSpecifiedValue,
123 "Activate (1) or deactivate(0) the drift compensation");
124DEFINE_int(aec3,
125 kParameterNotSpecifiedValue,
126 "Activate (1) or deactivate(0) the experimental AEC mode AEC3");
oprypin6e09d872017-08-31 03:21:39 -0700127DEFINE_int(experimental_agc,
128 kParameterNotSpecifiedValue,
129 "Activate (1) or deactivate(0) the experimental AGC");
130DEFINE_int(
peah60a189f2016-05-24 20:54:40 -0700131 refined_adaptive_filter,
132 kParameterNotSpecifiedValue,
133 "Activate (1) or deactivate(0) the refined adaptive filter functionality");
oprypin6e09d872017-08-31 03:21:39 -0700134DEFINE_int(aecm_routing_mode,
135 kParameterNotSpecifiedValue,
136 "Specify the AECM routing mode (0-4)");
137DEFINE_int(aecm_comfort_noise,
138 kParameterNotSpecifiedValue,
139 "Activate (1) or deactivate(0) the AECM comfort noise");
140DEFINE_int(agc_mode,
141 kParameterNotSpecifiedValue,
142 "Specify the AGC mode (0-2)");
143DEFINE_int(agc_target_level,
144 kParameterNotSpecifiedValue,
145 "Specify the AGC target level (0-31)");
146DEFINE_int(agc_limiter,
147 kParameterNotSpecifiedValue,
148 "Activate (1) or deactivate(0) the level estimator");
149DEFINE_int(agc_compression_gain,
150 kParameterNotSpecifiedValue,
151 "Specify the AGC compression gain (0-90)");
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200152DEFINE_float(agc2_fixed_gain_db, 0.f, "AGC2 fixed gain (dB) to apply");
oprypin6e09d872017-08-31 03:21:39 -0700153DEFINE_int(vad_likelihood,
154 kParameterNotSpecifiedValue,
155 "Specify the VAD likelihood (0-3)");
156DEFINE_int(ns_level,
157 kParameterNotSpecifiedValue,
158 "Specify the NS level (0-3)");
159DEFINE_int(stream_delay,
160 kParameterNotSpecifiedValue,
161 "Specify the stream delay in ms to use");
162DEFINE_int(stream_drift_samples,
163 kParameterNotSpecifiedValue,
164 "Specify the number of stream drift samples to use");
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200165DEFINE_int(initial_mic_level, 100, "Initial mic level (0-255)");
166DEFINE_int(simulate_mic_gain,
167 0,
168 "Activate (1) or deactivate(0) the analog mic gain simulation");
169DEFINE_int(simulated_mic_kind,
170 kParameterNotSpecifiedValue,
171 "Specify which microphone kind to use for microphone simulation");
peah60a189f2016-05-24 20:54:40 -0700172DEFINE_bool(performance_report, false, "Report the APM performance ");
173DEFINE_bool(verbose, false, "Produce verbose output");
174DEFINE_bool(bitexactness_report,
175 false,
176 "Report bitexactness for aec dump result reproduction");
177DEFINE_bool(discard_settings_in_aecdump,
178 false,
179 "Discard any config settings specified in the aec dump");
180DEFINE_bool(store_intermediate_output,
181 false,
182 "Creates new output files after each init");
peah5ad5de32016-12-09 03:18:22 -0800183DEFINE_string(custom_call_order_file, "", "Custom process API call order file");
Per Ã…hgrenad09d742018-03-08 07:47:14 +0100184DEFINE_string(aec3_settings,
185 "",
186 "File in JSON-format with custom AEC3 settings");
oprypin6e09d872017-08-31 03:21:39 -0700187DEFINE_bool(help, false, "Print this message");
peah60a189f2016-05-24 20:54:40 -0700188
Alex Loiko890988c2017-08-31 10:25:48 +0200189void SetSettingIfSpecified(const std::string& value,
peah60a189f2016-05-24 20:54:40 -0700190 rtc::Optional<std::string>* parameter) {
191 if (value.compare("") != 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100192 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700193 }
194}
195
196void SetSettingIfSpecified(int value, rtc::Optional<int>* parameter) {
197 if (value != kParameterNotSpecifiedValue) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100198 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700199 }
200}
201
202void SetSettingIfFlagSet(int32_t flag, rtc::Optional<bool>* parameter) {
203 if (flag == 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100204 *parameter = false;
peah60a189f2016-05-24 20:54:40 -0700205 } else if (flag == 1) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100206 *parameter = true;
peah60a189f2016-05-24 20:54:40 -0700207 }
208}
209
210SimulationSettings CreateSettings() {
211 SimulationSettings settings;
oprypin6e09d872017-08-31 03:21:39 -0700212 if (FLAG_all_default) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100213 settings.use_le = true;
214 settings.use_vad = true;
215 settings.use_ie = false;
216 settings.use_bf = false;
217 settings.use_ts = true;
218 settings.use_ns = true;
219 settings.use_hpf = true;
220 settings.use_agc = true;
221 settings.use_agc2 = false;
222 settings.use_aec = true;
223 settings.use_aecm = false;
224 settings.use_ed = false;
peah60a189f2016-05-24 20:54:40 -0700225 }
oprypin6e09d872017-08-31 03:21:39 -0700226 SetSettingIfSpecified(FLAG_dump_input, &settings.aec_dump_input_filename);
227 SetSettingIfSpecified(FLAG_dump_output, &settings.aec_dump_output_filename);
228 SetSettingIfSpecified(FLAG_i, &settings.input_filename);
229 SetSettingIfSpecified(FLAG_o, &settings.output_filename);
230 SetSettingIfSpecified(FLAG_ri, &settings.reverse_input_filename);
231 SetSettingIfSpecified(FLAG_ro, &settings.reverse_output_filename);
232 SetSettingIfSpecified(FLAG_artificial_nearend,
peahdf80fd12016-12-09 02:43:40 -0800233 &settings.artificial_nearend_filename);
oprypin6e09d872017-08-31 03:21:39 -0700234 SetSettingIfSpecified(FLAG_output_num_channels,
peah60a189f2016-05-24 20:54:40 -0700235 &settings.output_num_channels);
oprypin6e09d872017-08-31 03:21:39 -0700236 SetSettingIfSpecified(FLAG_reverse_output_num_channels,
peah60a189f2016-05-24 20:54:40 -0700237 &settings.reverse_output_num_channels);
oprypin6e09d872017-08-31 03:21:39 -0700238 SetSettingIfSpecified(FLAG_output_sample_rate_hz,
peah60a189f2016-05-24 20:54:40 -0700239 &settings.output_sample_rate_hz);
oprypin6e09d872017-08-31 03:21:39 -0700240 SetSettingIfSpecified(FLAG_reverse_output_sample_rate_hz,
peah60a189f2016-05-24 20:54:40 -0700241 &settings.reverse_output_sample_rate_hz);
oprypin6e09d872017-08-31 03:21:39 -0700242 SetSettingIfSpecified(FLAG_mic_positions, &settings.microphone_positions);
243 settings.target_angle_degrees = FLAG_target_angle_degrees;
244 SetSettingIfFlagSet(FLAG_aec, &settings.use_aec);
245 SetSettingIfFlagSet(FLAG_aecm, &settings.use_aecm);
246 SetSettingIfFlagSet(FLAG_ed, &settings.use_ed);
247 SetSettingIfSpecified(FLAG_ed_graph, &settings.ed_graph_output_filename);
248 SetSettingIfFlagSet(FLAG_agc, &settings.use_agc);
249 SetSettingIfFlagSet(FLAG_agc2, &settings.use_agc2);
250 SetSettingIfFlagSet(FLAG_hpf, &settings.use_hpf);
251 SetSettingIfFlagSet(FLAG_ns, &settings.use_ns);
252 SetSettingIfFlagSet(FLAG_ts, &settings.use_ts);
253 SetSettingIfFlagSet(FLAG_bf, &settings.use_bf);
254 SetSettingIfFlagSet(FLAG_ie, &settings.use_ie);
255 SetSettingIfFlagSet(FLAG_vad, &settings.use_vad);
256 SetSettingIfFlagSet(FLAG_le, &settings.use_le);
257 SetSettingIfSpecified(FLAG_aec_suppression_level,
peah60a189f2016-05-24 20:54:40 -0700258 &settings.aec_suppression_level);
oprypin6e09d872017-08-31 03:21:39 -0700259 SetSettingIfFlagSet(FLAG_delay_agnostic, &settings.use_delay_agnostic);
260 SetSettingIfFlagSet(FLAG_extended_filter, &settings.use_extended_filter);
261 SetSettingIfFlagSet(FLAG_drift_compensation,
peah60a189f2016-05-24 20:54:40 -0700262 &settings.use_drift_compensation);
oprypin6e09d872017-08-31 03:21:39 -0700263 SetSettingIfFlagSet(FLAG_refined_adaptive_filter,
peah60a189f2016-05-24 20:54:40 -0700264 &settings.use_refined_adaptive_filter);
265
oprypin6e09d872017-08-31 03:21:39 -0700266 SetSettingIfFlagSet(FLAG_aec3, &settings.use_aec3);
oprypin6e09d872017-08-31 03:21:39 -0700267 SetSettingIfFlagSet(FLAG_experimental_agc, &settings.use_experimental_agc);
268 SetSettingIfSpecified(FLAG_aecm_routing_mode, &settings.aecm_routing_mode);
269 SetSettingIfFlagSet(FLAG_aecm_comfort_noise,
peah60a189f2016-05-24 20:54:40 -0700270 &settings.use_aecm_comfort_noise);
oprypin6e09d872017-08-31 03:21:39 -0700271 SetSettingIfSpecified(FLAG_agc_mode, &settings.agc_mode);
272 SetSettingIfSpecified(FLAG_agc_target_level, &settings.agc_target_level);
273 SetSettingIfFlagSet(FLAG_agc_limiter, &settings.use_agc_limiter);
274 SetSettingIfSpecified(FLAG_agc_compression_gain,
peah60a189f2016-05-24 20:54:40 -0700275 &settings.agc_compression_gain);
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200276 settings.agc2_fixed_gain_db = FLAG_agc2_fixed_gain_db;
oprypin6e09d872017-08-31 03:21:39 -0700277 SetSettingIfSpecified(FLAG_vad_likelihood, &settings.vad_likelihood);
278 SetSettingIfSpecified(FLAG_ns_level, &settings.ns_level);
279 SetSettingIfSpecified(FLAG_stream_delay, &settings.stream_delay);
280 SetSettingIfSpecified(FLAG_stream_drift_samples,
peah60a189f2016-05-24 20:54:40 -0700281 &settings.stream_drift_samples);
oprypin6e09d872017-08-31 03:21:39 -0700282 SetSettingIfSpecified(FLAG_custom_call_order_file,
peah5ad5de32016-12-09 03:18:22 -0800283 &settings.custom_call_order_filename);
Per Ã…hgrenad09d742018-03-08 07:47:14 +0100284 SetSettingIfSpecified(FLAG_aec3_settings, &settings.aec3_settings_filename);
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200285 settings.initial_mic_level = FLAG_initial_mic_level;
286 settings.simulate_mic_gain = FLAG_simulate_mic_gain;
287 SetSettingIfSpecified(FLAG_simulated_mic_kind, &settings.simulated_mic_kind);
oprypin6e09d872017-08-31 03:21:39 -0700288 settings.report_performance = FLAG_performance_report;
289 settings.use_verbose_logging = FLAG_verbose;
290 settings.report_bitexactness = FLAG_bitexactness_report;
291 settings.discard_all_settings_in_aecdump = FLAG_discard_settings_in_aecdump;
292 settings.fixed_interface = FLAG_fixed_interface;
293 settings.store_intermediate_output = FLAG_store_intermediate_output;
peah60a189f2016-05-24 20:54:40 -0700294
295 return settings;
296}
297
Alex Loiko890988c2017-08-31 10:25:48 +0200298void ReportConditionalErrorAndExit(bool condition, const std::string& message) {
peah60a189f2016-05-24 20:54:40 -0700299 if (condition) {
300 std::cerr << message << std::endl;
301 exit(1);
302 }
303}
304
305void PerformBasicParameterSanityChecks(const SimulationSettings& settings) {
306 if (settings.input_filename || settings.reverse_input_filename) {
307 ReportConditionalErrorAndExit(!!settings.aec_dump_input_filename,
308 "Error: The aec dump cannot be specified "
309 "together with input wav files!\n");
310
peahdf80fd12016-12-09 02:43:40 -0800311 ReportConditionalErrorAndExit(!!settings.artificial_nearend_filename,
312 "Error: The artificial nearend cannot be "
313 "specified together with input wav files!\n");
314
peah60a189f2016-05-24 20:54:40 -0700315 ReportConditionalErrorAndExit(!settings.input_filename,
316 "Error: When operating at wav files, the "
317 "input wav filename must be "
318 "specified!\n");
319
320 ReportConditionalErrorAndExit(
321 settings.reverse_output_filename && !settings.reverse_input_filename,
322 "Error: When operating at wav files, the reverse input wav filename "
323 "must be specified if the reverse output wav filename is specified!\n");
324 } else {
325 ReportConditionalErrorAndExit(!settings.aec_dump_input_filename,
326 "Error: Either the aec dump or the wav "
327 "input files must be specified!\n");
328 }
329
330 ReportConditionalErrorAndExit(
331 settings.use_aec && *settings.use_aec && settings.use_aecm &&
332 *settings.use_aecm,
333 "Error: The AEC and the AECM cannot be activated at the same time!\n");
334
335 ReportConditionalErrorAndExit(
336 settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0,
337 "Error: --output_sample_rate_hz must be positive!\n");
338
339 ReportConditionalErrorAndExit(
340 settings.reverse_output_sample_rate_hz &&
341 settings.output_sample_rate_hz &&
342 *settings.output_sample_rate_hz <= 0,
343 "Error: --reverse_output_sample_rate_hz must be positive!\n");
344
345 ReportConditionalErrorAndExit(
346 settings.output_num_channels && *settings.output_num_channels <= 0,
347 "Error: --output_num_channels must be positive!\n");
348
349 ReportConditionalErrorAndExit(
350 settings.reverse_output_num_channels &&
351 *settings.reverse_output_num_channels <= 0,
352 "Error: --reverse_output_num_channels must be positive!\n");
353
354 ReportConditionalErrorAndExit(
355 settings.use_bf && *settings.use_bf && !settings.microphone_positions,
356 "Error: --mic_positions must be specified when the beamformer is "
357 "activated.\n");
358
359 ReportConditionalErrorAndExit(
360 settings.target_angle_degrees < 0 || settings.target_angle_degrees > 359,
361 "Error: -target_angle_degrees must be specified between 0 and 359.\n");
362
363 ReportConditionalErrorAndExit(
364 settings.aec_suppression_level &&
365 ((*settings.aec_suppression_level) < 0 ||
366 (*settings.aec_suppression_level) > 2),
367 "Error: --aec_suppression_level must be specified between 0 and 2.\n");
368
369 ReportConditionalErrorAndExit(
370 settings.aecm_routing_mode && ((*settings.aecm_routing_mode) < 0 ||
371 (*settings.aecm_routing_mode) > 4),
372 "Error: --aecm_routing_mode must be specified between 0 and 4.\n");
373
374 ReportConditionalErrorAndExit(
375 settings.agc_target_level && ((*settings.agc_target_level) < 0 ||
376 (*settings.agc_target_level) > 31),
377 "Error: --agc_target_level must be specified between 0 and 31.\n");
378
379 ReportConditionalErrorAndExit(
380 settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 ||
381 (*settings.agc_compression_gain) > 90),
382 "Error: --agc_compression_gain must be specified between 0 and 90.\n");
383
384 ReportConditionalErrorAndExit(
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200385 settings.use_agc && *settings.use_agc && settings.use_agc2 &&
386 *settings.use_agc2,
387 "Error: --agc and --agc2 cannot be both active.\n");
388
389 ReportConditionalErrorAndExit(
390 settings.use_agc2 && *settings.use_agc2 &&
391 ((settings.agc2_fixed_gain_db) < 0 ||
392 (settings.agc2_fixed_gain_db) > 90),
393 "Error: --agc2_fixed_gain_db must be specified between 0 and 90.\n");
394
395 ReportConditionalErrorAndExit(
peah60a189f2016-05-24 20:54:40 -0700396 settings.vad_likelihood &&
397 ((*settings.vad_likelihood) < 0 || (*settings.vad_likelihood) > 3),
398 "Error: --vad_likelihood must be specified between 0 and 3.\n");
399
400 ReportConditionalErrorAndExit(
401 settings.ns_level &&
402 ((*settings.ns_level) < 0 || (*settings.ns_level) > 3),
403 "Error: --ns_level must be specified between 0 and 3.\n");
404
405 ReportConditionalErrorAndExit(
406 settings.report_bitexactness && !settings.aec_dump_input_filename,
407 "Error: --bitexactness_report can only be used when operating on an "
408 "aecdump\n");
409
peah5ad5de32016-12-09 03:18:22 -0800410 ReportConditionalErrorAndExit(
411 settings.custom_call_order_filename && settings.aec_dump_input_filename,
412 "Error: --custom_call_order_file cannot be used when operating on an "
413 "aecdump\n");
414
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200415 ReportConditionalErrorAndExit(
416 (settings.initial_mic_level < 0 || settings.initial_mic_level > 255),
417 "Error: --initial_mic_level must be specified between 0 and 255.\n");
418
419 ReportConditionalErrorAndExit(
420 settings.simulated_mic_kind && !settings.simulate_mic_gain,
421 "Error: --simulated_mic_kind cannot be specified when mic simulation is "
422 "disabled\n");
423
424 ReportConditionalErrorAndExit(
425 !settings.simulated_mic_kind && settings.simulate_mic_gain,
426 "Error: --simulated_mic_kind must be specified when mic simulation is "
427 "enabled\n");
428
peah60a189f2016-05-24 20:54:40 -0700429 auto valid_wav_name = [](const std::string& wav_file_name) {
430 if (wav_file_name.size() < 5) {
431 return false;
432 }
433 if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) ||
434 (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) {
435 return true;
436 }
437 return false;
438 };
439
440 ReportConditionalErrorAndExit(
441 settings.input_filename && (!valid_wav_name(*settings.input_filename)),
442 "Error: --i must be a valid .wav file name.\n");
443
444 ReportConditionalErrorAndExit(
445 settings.output_filename && (!valid_wav_name(*settings.output_filename)),
446 "Error: --o must be a valid .wav file name.\n");
447
448 ReportConditionalErrorAndExit(
449 settings.reverse_input_filename &&
450 (!valid_wav_name(*settings.reverse_input_filename)),
451 "Error: --ri must be a valid .wav file name.\n");
452
453 ReportConditionalErrorAndExit(
454 settings.reverse_output_filename &&
455 (!valid_wav_name(*settings.reverse_output_filename)),
456 "Error: --ro must be a valid .wav file name.\n");
peahdf80fd12016-12-09 02:43:40 -0800457
458 ReportConditionalErrorAndExit(
459 settings.artificial_nearend_filename &&
460 !valid_wav_name(*settings.artificial_nearend_filename),
461 "Error: --artifical_nearend must be a valid .wav file name.\n");
Peter Kasting69558702016-01-12 16:26:35 -0800462}
463
464} // namespace
465
Ivo Creusen2cb41052018-03-15 12:22:52 +0100466int AudioprocFloatImpl(std::unique_ptr<AudioProcessingBuilder> ap_builder,
467 int argc,
468 char* argv[]) {
oprypin6e09d872017-08-31 03:21:39 -0700469 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) ||
470 FLAG_help || argc != 1) {
471 printf("%s", kUsageDescription);
472 if (FLAG_help) {
473 rtc::FlagList::Print(nullptr, false);
474 return 0;
475 }
476 return 1;
477 }
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000478
peah60a189f2016-05-24 20:54:40 -0700479 SimulationSettings settings = CreateSettings();
480 PerformBasicParameterSanityChecks(settings);
481 std::unique_ptr<AudioProcessingSimulator> processor;
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000482
peah60a189f2016-05-24 20:54:40 -0700483 if (settings.aec_dump_input_filename) {
Ivo Creusen8c812f32018-03-09 17:33:04 +0100484 processor.reset(new AecDumpBasedSimulator(settings, std::move(ap_builder)));
aluebsb0ad43b2015-11-20 00:11:53 -0800485 } else {
Ivo Creusen8c812f32018-03-09 17:33:04 +0100486 processor.reset(new WavBasedSimulator(settings, std::move(ap_builder)));
andrewbdafe312015-10-29 23:42:54 -0700487 }
488
peah60a189f2016-05-24 20:54:40 -0700489 processor->Process();
aluebsb0ad43b2015-11-20 00:11:53 -0800490
peah60a189f2016-05-24 20:54:40 -0700491 if (settings.report_performance) {
aluebsb0ad43b2015-11-20 00:11:53 -0800492 const auto& proc_time = processor->proc_time();
Niels Möllerd28db7f2016-05-10 16:31:47 +0200493 int64_t exec_time_us = proc_time.sum / rtc::kNumNanosecsPerMicrosec;
peah60a189f2016-05-24 20:54:40 -0700494 std::cout << std::endl
495 << "Execution time: " << exec_time_us * 1e-6 << " s, File time: "
496 << processor->get_num_process_stream_calls() * 1.f /
497 AudioProcessingSimulator::kChunksPerSecond
498 << std::endl
499 << "Time per fwd stream chunk (mean, max, min): " << std::endl
500 << exec_time_us * 1.f / processor->get_num_process_stream_calls()
501 << " us, " << 1.f * proc_time.max / rtc::kNumNanosecsPerMicrosec
502 << " us, " << 1.f * proc_time.min / rtc::kNumNanosecsPerMicrosec
503 << " us" << std::endl;
504 }
505
506 if (settings.report_bitexactness && settings.aec_dump_input_filename) {
507 if (processor->OutputWasBitexact()) {
508 std::cout << "The processing was bitexact.";
509 } else {
510 std::cout << "The processing was not bitexact.";
511 }
Alejandro Luebs5d22c002015-04-15 11:26:40 -0700512 }
aluebsb0ad43b2015-11-20 00:11:53 -0800513
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000514 return 0;
515}
516
peah60a189f2016-05-24 20:54:40 -0700517} // namespace test
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000518} // namespace webrtc