blob: 60c46f349fad2835d710610997f26607e5b29735 [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_bool(fixed_interface,
60 false,
61 "Use the fixed interface when operating on wav files");
oprypin6e09d872017-08-31 03:21:39 -070062DEFINE_int(aec,
63 kParameterNotSpecifiedValue,
64 "Activate (1) or deactivate(0) the echo canceller");
65DEFINE_int(aecm,
66 kParameterNotSpecifiedValue,
67 "Activate (1) or deactivate(0) the mobile echo controller");
68DEFINE_int(ed,
69 kParameterNotSpecifiedValue,
70 "Activate (1) or deactivate (0) the residual echo detector");
ivoc0bff12a2016-11-17 00:55:43 -080071DEFINE_string(ed_graph, "", "Output filename for graph of echo likelihood");
oprypin6e09d872017-08-31 03:21:39 -070072DEFINE_int(agc,
73 kParameterNotSpecifiedValue,
74 "Activate (1) or deactivate(0) the AGC");
75DEFINE_int(agc2,
76 kParameterNotSpecifiedValue,
77 "Activate (1) or deactivate(0) the AGC2");
Alex Loiko5feb30e2018-04-16 13:52:32 +020078DEFINE_int(pre_amplifier,
79 kParameterNotSpecifiedValue,
80 "Activate (1) or deactivate(0) the pre amplifier");
oprypin6e09d872017-08-31 03:21:39 -070081DEFINE_int(hpf,
82 kParameterNotSpecifiedValue,
83 "Activate (1) or deactivate(0) the high-pass filter");
84DEFINE_int(ns,
85 kParameterNotSpecifiedValue,
86 "Activate (1) or deactivate(0) the noise suppressor");
87DEFINE_int(ts,
88 kParameterNotSpecifiedValue,
89 "Activate (1) or deactivate(0) the transient suppressor");
oprypin6e09d872017-08-31 03:21:39 -070090DEFINE_int(vad,
91 kParameterNotSpecifiedValue,
92 "Activate (1) or deactivate(0) the voice activity detector");
93DEFINE_int(le,
94 kParameterNotSpecifiedValue,
95 "Activate (1) or deactivate(0) the level estimator");
peah60a189f2016-05-24 20:54:40 -070096DEFINE_bool(all_default,
97 false,
98 "Activate all of the default components (will be overridden by any "
99 "other settings)");
oprypin6e09d872017-08-31 03:21:39 -0700100DEFINE_int(aec_suppression_level,
101 kParameterNotSpecifiedValue,
102 "Set the aec suppression level (0-2)");
103DEFINE_int(delay_agnostic,
104 kParameterNotSpecifiedValue,
105 "Activate (1) or deactivate(0) the AEC delay agnostic mode");
106DEFINE_int(extended_filter,
107 kParameterNotSpecifiedValue,
108 "Activate (1) or deactivate(0) the AEC extended filter mode");
oprypin6e09d872017-08-31 03:21:39 -0700109DEFINE_int(aec3,
110 kParameterNotSpecifiedValue,
111 "Activate (1) or deactivate(0) the experimental AEC mode AEC3");
oprypin6e09d872017-08-31 03:21:39 -0700112DEFINE_int(experimental_agc,
113 kParameterNotSpecifiedValue,
114 "Activate (1) or deactivate(0) the experimental AGC");
Alex Loiko9489c3a2018-08-09 15:04:24 +0200115DEFINE_int(experimental_agc_disable_digital_adaptive,
Alex Loiko64cb83b2018-07-02 13:38:19 +0200116 kParameterNotSpecifiedValue,
Alex Loiko9489c3a2018-08-09 15:04:24 +0200117 "Force-deactivate (1) digital adaptation in "
118 "experimental AGC. Digital adaptation is active by default (0).");
Alex Loikod9342442018-09-10 13:59:41 +0200119DEFINE_int(experimental_agc_analyze_before_aec,
120 kParameterNotSpecifiedValue,
121 "Make level estimation happen before AEC"
122 " in the experimental AGC. After AEC is the default (0)");
123DEFINE_int(
124 experimental_agc_agc2_level_estimator,
125 kParameterNotSpecifiedValue,
126 "AGC2 level estimation"
127 " in the experimental AGC. AGC1 level estimation is the default (0)");
Alex Loiko64cb83b2018-07-02 13:38:19 +0200128DEFINE_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");
Yves Gerey665174f2018-06-19 15:03:05 +0200138DEFINE_int(agc_mode, kParameterNotSpecifiedValue, "Specify the AGC mode (0-2)");
oprypin6e09d872017-08-31 03:21:39 -0700139DEFINE_int(agc_target_level,
140 kParameterNotSpecifiedValue,
141 "Specify the AGC target level (0-31)");
142DEFINE_int(agc_limiter,
143 kParameterNotSpecifiedValue,
144 "Activate (1) or deactivate(0) the level estimator");
145DEFINE_int(agc_compression_gain,
146 kParameterNotSpecifiedValue,
147 "Specify the AGC compression gain (0-90)");
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200148DEFINE_float(agc2_fixed_gain_db, 0.f, "AGC2 fixed gain (dB) to apply");
Alex Loiko5feb30e2018-04-16 13:52:32 +0200149DEFINE_float(pre_amplifier_gain_factor,
150 1.f,
151 "Pre-amplifier gain factor (linear) to apply");
oprypin6e09d872017-08-31 03:21:39 -0700152DEFINE_int(vad_likelihood,
153 kParameterNotSpecifiedValue,
154 "Specify the VAD likelihood (0-3)");
Yves Gerey665174f2018-06-19 15:03:05 +0200155DEFINE_int(ns_level, kParameterNotSpecifiedValue, "Specify the NS level (0-3)");
oprypin6e09d872017-08-31 03:21:39 -0700156DEFINE_int(stream_delay,
157 kParameterNotSpecifiedValue,
158 "Specify the stream delay in ms to use");
Per Ã…hgrenc5efb0c2018-05-28 09:10:59 +0200159DEFINE_int(use_stream_delay,
160 kParameterNotSpecifiedValue,
161 "Activate (1) or deactivate(0) reporting the stream delay");
oprypin6e09d872017-08-31 03:21:39 -0700162DEFINE_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");
Per Ã…hgren5a72a5e2018-08-24 07:18:24 +0200174DEFINE_bool(quiet, false, "Avoid producing information about the progress.");
peah60a189f2016-05-24 20:54:40 -0700175DEFINE_bool(bitexactness_report,
176 false,
177 "Report bitexactness for aec dump result reproduction");
178DEFINE_bool(discard_settings_in_aecdump,
179 false,
180 "Discard any config settings specified in the aec dump");
181DEFINE_bool(store_intermediate_output,
182 false,
183 "Creates new output files after each init");
peah5ad5de32016-12-09 03:18:22 -0800184DEFINE_string(custom_call_order_file, "", "Custom process API call order file");
Per Ã…hgrenad09d742018-03-08 07:47:14 +0100185DEFINE_string(aec3_settings,
186 "",
187 "File in JSON-format with custom AEC3 settings");
oprypin6e09d872017-08-31 03:21:39 -0700188DEFINE_bool(help, false, "Print this message");
peah60a189f2016-05-24 20:54:40 -0700189
Alex Loiko890988c2017-08-31 10:25:48 +0200190void SetSettingIfSpecified(const std::string& value,
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200191 absl::optional<std::string>* parameter) {
peah60a189f2016-05-24 20:54:40 -0700192 if (value.compare("") != 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100193 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700194 }
195}
196
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200197void SetSettingIfSpecified(int value, absl::optional<int>* parameter) {
peah60a189f2016-05-24 20:54:40 -0700198 if (value != kParameterNotSpecifiedValue) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100199 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700200 }
201}
202
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200203void SetSettingIfFlagSet(int32_t flag, absl::optional<bool>* parameter) {
peah60a189f2016-05-24 20:54:40 -0700204 if (flag == 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100205 *parameter = false;
peah60a189f2016-05-24 20:54:40 -0700206 } else if (flag == 1) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100207 *parameter = true;
peah60a189f2016-05-24 20:54:40 -0700208 }
209}
210
211SimulationSettings CreateSettings() {
212 SimulationSettings settings;
oprypin6e09d872017-08-31 03:21:39 -0700213 if (FLAG_all_default) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100214 settings.use_le = true;
215 settings.use_vad = true;
216 settings.use_ie = false;
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100217 settings.use_ts = true;
218 settings.use_ns = true;
219 settings.use_hpf = true;
220 settings.use_agc = true;
221 settings.use_agc2 = false;
Alex Loiko5feb30e2018-04-16 13:52:32 +0200222 settings.use_pre_amplifier = false;
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100223 settings.use_aec = true;
224 settings.use_aecm = false;
225 settings.use_ed = false;
peah60a189f2016-05-24 20:54:40 -0700226 }
oprypin6e09d872017-08-31 03:21:39 -0700227 SetSettingIfSpecified(FLAG_dump_input, &settings.aec_dump_input_filename);
228 SetSettingIfSpecified(FLAG_dump_output, &settings.aec_dump_output_filename);
229 SetSettingIfSpecified(FLAG_i, &settings.input_filename);
230 SetSettingIfSpecified(FLAG_o, &settings.output_filename);
231 SetSettingIfSpecified(FLAG_ri, &settings.reverse_input_filename);
232 SetSettingIfSpecified(FLAG_ro, &settings.reverse_output_filename);
233 SetSettingIfSpecified(FLAG_artificial_nearend,
peahdf80fd12016-12-09 02:43:40 -0800234 &settings.artificial_nearend_filename);
oprypin6e09d872017-08-31 03:21:39 -0700235 SetSettingIfSpecified(FLAG_output_num_channels,
peah60a189f2016-05-24 20:54:40 -0700236 &settings.output_num_channels);
oprypin6e09d872017-08-31 03:21:39 -0700237 SetSettingIfSpecified(FLAG_reverse_output_num_channels,
peah60a189f2016-05-24 20:54:40 -0700238 &settings.reverse_output_num_channels);
oprypin6e09d872017-08-31 03:21:39 -0700239 SetSettingIfSpecified(FLAG_output_sample_rate_hz,
peah60a189f2016-05-24 20:54:40 -0700240 &settings.output_sample_rate_hz);
oprypin6e09d872017-08-31 03:21:39 -0700241 SetSettingIfSpecified(FLAG_reverse_output_sample_rate_hz,
peah60a189f2016-05-24 20:54:40 -0700242 &settings.reverse_output_sample_rate_hz);
oprypin6e09d872017-08-31 03:21:39 -0700243 SetSettingIfFlagSet(FLAG_aec, &settings.use_aec);
244 SetSettingIfFlagSet(FLAG_aecm, &settings.use_aecm);
245 SetSettingIfFlagSet(FLAG_ed, &settings.use_ed);
246 SetSettingIfSpecified(FLAG_ed_graph, &settings.ed_graph_output_filename);
247 SetSettingIfFlagSet(FLAG_agc, &settings.use_agc);
248 SetSettingIfFlagSet(FLAG_agc2, &settings.use_agc2);
Alex Loiko5feb30e2018-04-16 13:52:32 +0200249 SetSettingIfFlagSet(FLAG_pre_amplifier, &settings.use_pre_amplifier);
oprypin6e09d872017-08-31 03:21:39 -0700250 SetSettingIfFlagSet(FLAG_hpf, &settings.use_hpf);
251 SetSettingIfFlagSet(FLAG_ns, &settings.use_ns);
252 SetSettingIfFlagSet(FLAG_ts, &settings.use_ts);
oprypin6e09d872017-08-31 03:21:39 -0700253 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);
oprypin6e09d872017-08-31 03:21:39 -0700259 SetSettingIfFlagSet(FLAG_refined_adaptive_filter,
peah60a189f2016-05-24 20:54:40 -0700260 &settings.use_refined_adaptive_filter);
261
oprypin6e09d872017-08-31 03:21:39 -0700262 SetSettingIfFlagSet(FLAG_aec3, &settings.use_aec3);
oprypin6e09d872017-08-31 03:21:39 -0700263 SetSettingIfFlagSet(FLAG_experimental_agc, &settings.use_experimental_agc);
Alex Loiko9489c3a2018-08-09 15:04:24 +0200264 SetSettingIfFlagSet(FLAG_experimental_agc_disable_digital_adaptive,
265 &settings.experimental_agc_disable_digital_adaptive);
Alex Loikod9342442018-09-10 13:59:41 +0200266 SetSettingIfFlagSet(FLAG_experimental_agc_analyze_before_aec,
267 &settings.experimental_agc_analyze_before_aec);
268 SetSettingIfFlagSet(FLAG_experimental_agc_agc2_level_estimator,
269 &settings.use_experimental_agc_agc2_level_estimator);
oprypin6e09d872017-08-31 03:21:39 -0700270 SetSettingIfSpecified(FLAG_aecm_routing_mode, &settings.aecm_routing_mode);
271 SetSettingIfFlagSet(FLAG_aecm_comfort_noise,
peah60a189f2016-05-24 20:54:40 -0700272 &settings.use_aecm_comfort_noise);
oprypin6e09d872017-08-31 03:21:39 -0700273 SetSettingIfSpecified(FLAG_agc_mode, &settings.agc_mode);
274 SetSettingIfSpecified(FLAG_agc_target_level, &settings.agc_target_level);
275 SetSettingIfFlagSet(FLAG_agc_limiter, &settings.use_agc_limiter);
276 SetSettingIfSpecified(FLAG_agc_compression_gain,
peah60a189f2016-05-24 20:54:40 -0700277 &settings.agc_compression_gain);
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200278 settings.agc2_fixed_gain_db = FLAG_agc2_fixed_gain_db;
Alex Loiko5feb30e2018-04-16 13:52:32 +0200279 settings.pre_amplifier_gain_factor = FLAG_pre_amplifier_gain_factor;
oprypin6e09d872017-08-31 03:21:39 -0700280 SetSettingIfSpecified(FLAG_vad_likelihood, &settings.vad_likelihood);
281 SetSettingIfSpecified(FLAG_ns_level, &settings.ns_level);
282 SetSettingIfSpecified(FLAG_stream_delay, &settings.stream_delay);
Per Ã…hgrenc5efb0c2018-05-28 09:10:59 +0200283 SetSettingIfFlagSet(FLAG_use_stream_delay, &settings.use_stream_delay);
oprypin6e09d872017-08-31 03:21:39 -0700284 SetSettingIfSpecified(FLAG_stream_drift_samples,
peah60a189f2016-05-24 20:54:40 -0700285 &settings.stream_drift_samples);
oprypin6e09d872017-08-31 03:21:39 -0700286 SetSettingIfSpecified(FLAG_custom_call_order_file,
peah5ad5de32016-12-09 03:18:22 -0800287 &settings.custom_call_order_filename);
Per Ã…hgrenad09d742018-03-08 07:47:14 +0100288 SetSettingIfSpecified(FLAG_aec3_settings, &settings.aec3_settings_filename);
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200289 settings.initial_mic_level = FLAG_initial_mic_level;
290 settings.simulate_mic_gain = FLAG_simulate_mic_gain;
291 SetSettingIfSpecified(FLAG_simulated_mic_kind, &settings.simulated_mic_kind);
oprypin6e09d872017-08-31 03:21:39 -0700292 settings.report_performance = FLAG_performance_report;
293 settings.use_verbose_logging = FLAG_verbose;
Per Ã…hgren5a72a5e2018-08-24 07:18:24 +0200294 settings.use_quiet_output = FLAG_quiet;
oprypin6e09d872017-08-31 03:21:39 -0700295 settings.report_bitexactness = FLAG_bitexactness_report;
296 settings.discard_all_settings_in_aecdump = FLAG_discard_settings_in_aecdump;
297 settings.fixed_interface = FLAG_fixed_interface;
298 settings.store_intermediate_output = FLAG_store_intermediate_output;
peah60a189f2016-05-24 20:54:40 -0700299
300 return settings;
301}
302
Alex Loiko890988c2017-08-31 10:25:48 +0200303void ReportConditionalErrorAndExit(bool condition, const std::string& message) {
peah60a189f2016-05-24 20:54:40 -0700304 if (condition) {
305 std::cerr << message << std::endl;
306 exit(1);
307 }
308}
309
310void PerformBasicParameterSanityChecks(const SimulationSettings& settings) {
311 if (settings.input_filename || settings.reverse_input_filename) {
312 ReportConditionalErrorAndExit(!!settings.aec_dump_input_filename,
313 "Error: The aec dump cannot be specified "
314 "together with input wav files!\n");
315
peahdf80fd12016-12-09 02:43:40 -0800316 ReportConditionalErrorAndExit(!!settings.artificial_nearend_filename,
317 "Error: The artificial nearend cannot be "
318 "specified together with input wav files!\n");
319
peah60a189f2016-05-24 20:54:40 -0700320 ReportConditionalErrorAndExit(!settings.input_filename,
321 "Error: When operating at wav files, the "
322 "input wav filename must be "
323 "specified!\n");
324
325 ReportConditionalErrorAndExit(
326 settings.reverse_output_filename && !settings.reverse_input_filename,
327 "Error: When operating at wav files, the reverse input wav filename "
328 "must be specified if the reverse output wav filename is specified!\n");
329 } else {
330 ReportConditionalErrorAndExit(!settings.aec_dump_input_filename,
331 "Error: Either the aec dump or the wav "
332 "input files must be specified!\n");
333 }
334
335 ReportConditionalErrorAndExit(
336 settings.use_aec && *settings.use_aec && settings.use_aecm &&
337 *settings.use_aecm,
338 "Error: The AEC and the AECM cannot be activated at the same time!\n");
339
340 ReportConditionalErrorAndExit(
341 settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0,
342 "Error: --output_sample_rate_hz must be positive!\n");
343
344 ReportConditionalErrorAndExit(
345 settings.reverse_output_sample_rate_hz &&
346 settings.output_sample_rate_hz &&
347 *settings.output_sample_rate_hz <= 0,
348 "Error: --reverse_output_sample_rate_hz must be positive!\n");
349
350 ReportConditionalErrorAndExit(
351 settings.output_num_channels && *settings.output_num_channels <= 0,
352 "Error: --output_num_channels must be positive!\n");
353
354 ReportConditionalErrorAndExit(
355 settings.reverse_output_num_channels &&
356 *settings.reverse_output_num_channels <= 0,
357 "Error: --reverse_output_num_channels must be positive!\n");
358
Sam Zackrisson1a039602018-09-13 13:37:48 +0200359 ReportConditionalErrorAndExit(settings.aec_suppression_level &&
360 ((*settings.aec_suppression_level) < 1 ||
361 (*settings.aec_suppression_level) > 2),
362 "Error: --aec_suppression_level must be "
363 "specified between 1 and 2. 0 is "
364 "deprecated.\n");
peah60a189f2016-05-24 20:54:40 -0700365
366 ReportConditionalErrorAndExit(
367 settings.aecm_routing_mode && ((*settings.aecm_routing_mode) < 0 ||
368 (*settings.aecm_routing_mode) > 4),
369 "Error: --aecm_routing_mode must be specified between 0 and 4.\n");
370
371 ReportConditionalErrorAndExit(
372 settings.agc_target_level && ((*settings.agc_target_level) < 0 ||
373 (*settings.agc_target_level) > 31),
374 "Error: --agc_target_level must be specified between 0 and 31.\n");
375
376 ReportConditionalErrorAndExit(
377 settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 ||
378 (*settings.agc_compression_gain) > 90),
379 "Error: --agc_compression_gain must be specified between 0 and 90.\n");
380
381 ReportConditionalErrorAndExit(
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200382 settings.use_agc2 && *settings.use_agc2 &&
383 ((settings.agc2_fixed_gain_db) < 0 ||
384 (settings.agc2_fixed_gain_db) > 90),
385 "Error: --agc2_fixed_gain_db must be specified between 0 and 90.\n");
386
387 ReportConditionalErrorAndExit(
peah60a189f2016-05-24 20:54:40 -0700388 settings.vad_likelihood &&
389 ((*settings.vad_likelihood) < 0 || (*settings.vad_likelihood) > 3),
390 "Error: --vad_likelihood must be specified between 0 and 3.\n");
391
392 ReportConditionalErrorAndExit(
393 settings.ns_level &&
394 ((*settings.ns_level) < 0 || (*settings.ns_level) > 3),
395 "Error: --ns_level must be specified between 0 and 3.\n");
396
397 ReportConditionalErrorAndExit(
398 settings.report_bitexactness && !settings.aec_dump_input_filename,
399 "Error: --bitexactness_report can only be used when operating on an "
400 "aecdump\n");
401
peah5ad5de32016-12-09 03:18:22 -0800402 ReportConditionalErrorAndExit(
403 settings.custom_call_order_filename && settings.aec_dump_input_filename,
404 "Error: --custom_call_order_file cannot be used when operating on an "
405 "aecdump\n");
406
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200407 ReportConditionalErrorAndExit(
408 (settings.initial_mic_level < 0 || settings.initial_mic_level > 255),
409 "Error: --initial_mic_level must be specified between 0 and 255.\n");
410
411 ReportConditionalErrorAndExit(
412 settings.simulated_mic_kind && !settings.simulate_mic_gain,
413 "Error: --simulated_mic_kind cannot be specified when mic simulation is "
414 "disabled\n");
415
416 ReportConditionalErrorAndExit(
417 !settings.simulated_mic_kind && settings.simulate_mic_gain,
418 "Error: --simulated_mic_kind must be specified when mic simulation is "
419 "enabled\n");
420
peah60a189f2016-05-24 20:54:40 -0700421 auto valid_wav_name = [](const std::string& wav_file_name) {
422 if (wav_file_name.size() < 5) {
423 return false;
424 }
425 if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) ||
426 (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) {
427 return true;
428 }
429 return false;
430 };
431
432 ReportConditionalErrorAndExit(
433 settings.input_filename && (!valid_wav_name(*settings.input_filename)),
434 "Error: --i must be a valid .wav file name.\n");
435
436 ReportConditionalErrorAndExit(
437 settings.output_filename && (!valid_wav_name(*settings.output_filename)),
438 "Error: --o must be a valid .wav file name.\n");
439
440 ReportConditionalErrorAndExit(
441 settings.reverse_input_filename &&
442 (!valid_wav_name(*settings.reverse_input_filename)),
443 "Error: --ri must be a valid .wav file name.\n");
444
445 ReportConditionalErrorAndExit(
446 settings.reverse_output_filename &&
447 (!valid_wav_name(*settings.reverse_output_filename)),
448 "Error: --ro must be a valid .wav file name.\n");
peahdf80fd12016-12-09 02:43:40 -0800449
450 ReportConditionalErrorAndExit(
451 settings.artificial_nearend_filename &&
452 !valid_wav_name(*settings.artificial_nearend_filename),
453 "Error: --artifical_nearend must be a valid .wav file name.\n");
Peter Kasting69558702016-01-12 16:26:35 -0800454}
455
456} // namespace
457
Ivo Creusen2cb41052018-03-15 12:22:52 +0100458int AudioprocFloatImpl(std::unique_ptr<AudioProcessingBuilder> ap_builder,
459 int argc,
460 char* argv[]) {
Yves Gerey665174f2018-06-19 15:03:05 +0200461 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help ||
462 argc != 1) {
oprypin6e09d872017-08-31 03:21:39 -0700463 printf("%s", kUsageDescription);
464 if (FLAG_help) {
465 rtc::FlagList::Print(nullptr, false);
466 return 0;
467 }
468 return 1;
469 }
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000470
peah60a189f2016-05-24 20:54:40 -0700471 SimulationSettings settings = CreateSettings();
472 PerformBasicParameterSanityChecks(settings);
473 std::unique_ptr<AudioProcessingSimulator> processor;
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000474
peah60a189f2016-05-24 20:54:40 -0700475 if (settings.aec_dump_input_filename) {
Ivo Creusen8c812f32018-03-09 17:33:04 +0100476 processor.reset(new AecDumpBasedSimulator(settings, std::move(ap_builder)));
aluebsb0ad43b2015-11-20 00:11:53 -0800477 } else {
Ivo Creusen8c812f32018-03-09 17:33:04 +0100478 processor.reset(new WavBasedSimulator(settings, std::move(ap_builder)));
andrewbdafe312015-10-29 23:42:54 -0700479 }
480
peah60a189f2016-05-24 20:54:40 -0700481 processor->Process();
aluebsb0ad43b2015-11-20 00:11:53 -0800482
peah60a189f2016-05-24 20:54:40 -0700483 if (settings.report_performance) {
aluebsb0ad43b2015-11-20 00:11:53 -0800484 const auto& proc_time = processor->proc_time();
Niels Möllerd28db7f2016-05-10 16:31:47 +0200485 int64_t exec_time_us = proc_time.sum / rtc::kNumNanosecsPerMicrosec;
peah60a189f2016-05-24 20:54:40 -0700486 std::cout << std::endl
487 << "Execution time: " << exec_time_us * 1e-6 << " s, File time: "
488 << processor->get_num_process_stream_calls() * 1.f /
489 AudioProcessingSimulator::kChunksPerSecond
490 << std::endl
491 << "Time per fwd stream chunk (mean, max, min): " << std::endl
492 << exec_time_us * 1.f / processor->get_num_process_stream_calls()
493 << " us, " << 1.f * proc_time.max / rtc::kNumNanosecsPerMicrosec
494 << " us, " << 1.f * proc_time.min / rtc::kNumNanosecsPerMicrosec
495 << " us" << std::endl;
496 }
497
498 if (settings.report_bitexactness && settings.aec_dump_input_filename) {
499 if (processor->OutputWasBitexact()) {
500 std::cout << "The processing was bitexact.";
501 } else {
502 std::cout << "The processing was not bitexact.";
503 }
Alejandro Luebs5d22c002015-04-15 11:26:40 -0700504 }
aluebsb0ad43b2015-11-20 00:11:53 -0800505
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000506 return 0;
507}
508
peah60a189f2016-05-24 20:54:40 -0700509} // namespace test
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000510} // namespace webrtc