blob: 57fcdfb9757aa573afeb6d676aaac9088f709b1b [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\"");
Alex Luebs24c220c2018-03-15 11:27:22 -070064DEFINE_float(target_angle_degrees,
65 90.f,
66 "The azimuth of the target in degrees (0-360). 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");
Alex Loiko5feb30e2018-04-16 13:52:32 +020087DEFINE_int(pre_amplifier,
88 kParameterNotSpecifiedValue,
89 "Activate (1) or deactivate(0) the pre amplifier");
oprypin6e09d872017-08-31 03:21:39 -070090DEFINE_int(hpf,
91 kParameterNotSpecifiedValue,
92 "Activate (1) or deactivate(0) the high-pass filter");
93DEFINE_int(ns,
94 kParameterNotSpecifiedValue,
95 "Activate (1) or deactivate(0) the noise suppressor");
96DEFINE_int(ts,
97 kParameterNotSpecifiedValue,
98 "Activate (1) or deactivate(0) the transient suppressor");
99DEFINE_int(bf,
100 kParameterNotSpecifiedValue,
101 "Activate (1) or deactivate(0) the beamformer");
102DEFINE_int(ie,
103 kParameterNotSpecifiedValue,
104 "Activate (1) or deactivate(0) the intelligibility enhancer");
105DEFINE_int(vad,
106 kParameterNotSpecifiedValue,
107 "Activate (1) or deactivate(0) the voice activity detector");
108DEFINE_int(le,
109 kParameterNotSpecifiedValue,
110 "Activate (1) or deactivate(0) the level estimator");
peah60a189f2016-05-24 20:54:40 -0700111DEFINE_bool(all_default,
112 false,
113 "Activate all of the default components (will be overridden by any "
114 "other settings)");
oprypin6e09d872017-08-31 03:21:39 -0700115DEFINE_int(aec_suppression_level,
116 kParameterNotSpecifiedValue,
117 "Set the aec suppression level (0-2)");
118DEFINE_int(delay_agnostic,
119 kParameterNotSpecifiedValue,
120 "Activate (1) or deactivate(0) the AEC delay agnostic mode");
121DEFINE_int(extended_filter,
122 kParameterNotSpecifiedValue,
123 "Activate (1) or deactivate(0) the AEC extended filter mode");
124DEFINE_int(drift_compensation,
125 kParameterNotSpecifiedValue,
126 "Activate (1) or deactivate(0) the drift compensation");
127DEFINE_int(aec3,
128 kParameterNotSpecifiedValue,
129 "Activate (1) or deactivate(0) the experimental AEC mode AEC3");
oprypin6e09d872017-08-31 03:21:39 -0700130DEFINE_int(experimental_agc,
131 kParameterNotSpecifiedValue,
132 "Activate (1) or deactivate(0) the experimental AGC");
133DEFINE_int(
peah60a189f2016-05-24 20:54:40 -0700134 refined_adaptive_filter,
135 kParameterNotSpecifiedValue,
136 "Activate (1) or deactivate(0) the refined adaptive filter functionality");
oprypin6e09d872017-08-31 03:21:39 -0700137DEFINE_int(aecm_routing_mode,
138 kParameterNotSpecifiedValue,
139 "Specify the AECM routing mode (0-4)");
140DEFINE_int(aecm_comfort_noise,
141 kParameterNotSpecifiedValue,
142 "Activate (1) or deactivate(0) the AECM comfort noise");
143DEFINE_int(agc_mode,
144 kParameterNotSpecifiedValue,
145 "Specify the AGC mode (0-2)");
146DEFINE_int(agc_target_level,
147 kParameterNotSpecifiedValue,
148 "Specify the AGC target level (0-31)");
149DEFINE_int(agc_limiter,
150 kParameterNotSpecifiedValue,
151 "Activate (1) or deactivate(0) the level estimator");
152DEFINE_int(agc_compression_gain,
153 kParameterNotSpecifiedValue,
154 "Specify the AGC compression gain (0-90)");
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200155DEFINE_float(agc2_fixed_gain_db, 0.f, "AGC2 fixed gain (dB) to apply");
Alex Loiko5feb30e2018-04-16 13:52:32 +0200156DEFINE_float(pre_amplifier_gain_factor,
157 1.f,
158 "Pre-amplifier gain factor (linear) to apply");
oprypin6e09d872017-08-31 03:21:39 -0700159DEFINE_int(vad_likelihood,
160 kParameterNotSpecifiedValue,
161 "Specify the VAD likelihood (0-3)");
162DEFINE_int(ns_level,
163 kParameterNotSpecifiedValue,
164 "Specify the NS level (0-3)");
165DEFINE_int(stream_delay,
166 kParameterNotSpecifiedValue,
167 "Specify the stream delay in ms to use");
Per Ã…hgrenc5efb0c2018-05-28 09:10:59 +0200168DEFINE_int(use_stream_delay,
169 kParameterNotSpecifiedValue,
170 "Activate (1) or deactivate(0) reporting the stream delay");
oprypin6e09d872017-08-31 03:21:39 -0700171DEFINE_int(stream_drift_samples,
172 kParameterNotSpecifiedValue,
173 "Specify the number of stream drift samples to use");
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200174DEFINE_int(initial_mic_level, 100, "Initial mic level (0-255)");
175DEFINE_int(simulate_mic_gain,
176 0,
177 "Activate (1) or deactivate(0) the analog mic gain simulation");
178DEFINE_int(simulated_mic_kind,
179 kParameterNotSpecifiedValue,
180 "Specify which microphone kind to use for microphone simulation");
peah60a189f2016-05-24 20:54:40 -0700181DEFINE_bool(performance_report, false, "Report the APM performance ");
182DEFINE_bool(verbose, false, "Produce verbose output");
183DEFINE_bool(bitexactness_report,
184 false,
185 "Report bitexactness for aec dump result reproduction");
186DEFINE_bool(discard_settings_in_aecdump,
187 false,
188 "Discard any config settings specified in the aec dump");
189DEFINE_bool(store_intermediate_output,
190 false,
191 "Creates new output files after each init");
peah5ad5de32016-12-09 03:18:22 -0800192DEFINE_string(custom_call_order_file, "", "Custom process API call order file");
Per Ã…hgrenad09d742018-03-08 07:47:14 +0100193DEFINE_string(aec3_settings,
194 "",
195 "File in JSON-format with custom AEC3 settings");
oprypin6e09d872017-08-31 03:21:39 -0700196DEFINE_bool(help, false, "Print this message");
peah60a189f2016-05-24 20:54:40 -0700197
Alex Loiko890988c2017-08-31 10:25:48 +0200198void SetSettingIfSpecified(const std::string& value,
peah60a189f2016-05-24 20:54:40 -0700199 rtc::Optional<std::string>* parameter) {
200 if (value.compare("") != 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100201 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700202 }
203}
204
205void SetSettingIfSpecified(int value, rtc::Optional<int>* parameter) {
206 if (value != kParameterNotSpecifiedValue) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100207 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700208 }
209}
210
211void SetSettingIfFlagSet(int32_t flag, rtc::Optional<bool>* parameter) {
212 if (flag == 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100213 *parameter = false;
peah60a189f2016-05-24 20:54:40 -0700214 } else if (flag == 1) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100215 *parameter = true;
peah60a189f2016-05-24 20:54:40 -0700216 }
217}
218
219SimulationSettings CreateSettings() {
220 SimulationSettings settings;
oprypin6e09d872017-08-31 03:21:39 -0700221 if (FLAG_all_default) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100222 settings.use_le = true;
223 settings.use_vad = true;
224 settings.use_ie = false;
225 settings.use_bf = false;
226 settings.use_ts = true;
227 settings.use_ns = true;
228 settings.use_hpf = true;
229 settings.use_agc = true;
230 settings.use_agc2 = false;
Alex Loiko5feb30e2018-04-16 13:52:32 +0200231 settings.use_pre_amplifier = false;
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100232 settings.use_aec = true;
233 settings.use_aecm = false;
234 settings.use_ed = false;
peah60a189f2016-05-24 20:54:40 -0700235 }
oprypin6e09d872017-08-31 03:21:39 -0700236 SetSettingIfSpecified(FLAG_dump_input, &settings.aec_dump_input_filename);
237 SetSettingIfSpecified(FLAG_dump_output, &settings.aec_dump_output_filename);
238 SetSettingIfSpecified(FLAG_i, &settings.input_filename);
239 SetSettingIfSpecified(FLAG_o, &settings.output_filename);
240 SetSettingIfSpecified(FLAG_ri, &settings.reverse_input_filename);
241 SetSettingIfSpecified(FLAG_ro, &settings.reverse_output_filename);
242 SetSettingIfSpecified(FLAG_artificial_nearend,
peahdf80fd12016-12-09 02:43:40 -0800243 &settings.artificial_nearend_filename);
oprypin6e09d872017-08-31 03:21:39 -0700244 SetSettingIfSpecified(FLAG_output_num_channels,
peah60a189f2016-05-24 20:54:40 -0700245 &settings.output_num_channels);
oprypin6e09d872017-08-31 03:21:39 -0700246 SetSettingIfSpecified(FLAG_reverse_output_num_channels,
peah60a189f2016-05-24 20:54:40 -0700247 &settings.reverse_output_num_channels);
oprypin6e09d872017-08-31 03:21:39 -0700248 SetSettingIfSpecified(FLAG_output_sample_rate_hz,
peah60a189f2016-05-24 20:54:40 -0700249 &settings.output_sample_rate_hz);
oprypin6e09d872017-08-31 03:21:39 -0700250 SetSettingIfSpecified(FLAG_reverse_output_sample_rate_hz,
peah60a189f2016-05-24 20:54:40 -0700251 &settings.reverse_output_sample_rate_hz);
oprypin6e09d872017-08-31 03:21:39 -0700252 SetSettingIfSpecified(FLAG_mic_positions, &settings.microphone_positions);
253 settings.target_angle_degrees = FLAG_target_angle_degrees;
254 SetSettingIfFlagSet(FLAG_aec, &settings.use_aec);
255 SetSettingIfFlagSet(FLAG_aecm, &settings.use_aecm);
256 SetSettingIfFlagSet(FLAG_ed, &settings.use_ed);
257 SetSettingIfSpecified(FLAG_ed_graph, &settings.ed_graph_output_filename);
258 SetSettingIfFlagSet(FLAG_agc, &settings.use_agc);
259 SetSettingIfFlagSet(FLAG_agc2, &settings.use_agc2);
Alex Loiko5feb30e2018-04-16 13:52:32 +0200260 SetSettingIfFlagSet(FLAG_pre_amplifier, &settings.use_pre_amplifier);
oprypin6e09d872017-08-31 03:21:39 -0700261 SetSettingIfFlagSet(FLAG_hpf, &settings.use_hpf);
262 SetSettingIfFlagSet(FLAG_ns, &settings.use_ns);
263 SetSettingIfFlagSet(FLAG_ts, &settings.use_ts);
264 SetSettingIfFlagSet(FLAG_bf, &settings.use_bf);
265 SetSettingIfFlagSet(FLAG_ie, &settings.use_ie);
266 SetSettingIfFlagSet(FLAG_vad, &settings.use_vad);
267 SetSettingIfFlagSet(FLAG_le, &settings.use_le);
268 SetSettingIfSpecified(FLAG_aec_suppression_level,
peah60a189f2016-05-24 20:54:40 -0700269 &settings.aec_suppression_level);
oprypin6e09d872017-08-31 03:21:39 -0700270 SetSettingIfFlagSet(FLAG_delay_agnostic, &settings.use_delay_agnostic);
271 SetSettingIfFlagSet(FLAG_extended_filter, &settings.use_extended_filter);
272 SetSettingIfFlagSet(FLAG_drift_compensation,
peah60a189f2016-05-24 20:54:40 -0700273 &settings.use_drift_compensation);
oprypin6e09d872017-08-31 03:21:39 -0700274 SetSettingIfFlagSet(FLAG_refined_adaptive_filter,
peah60a189f2016-05-24 20:54:40 -0700275 &settings.use_refined_adaptive_filter);
276
oprypin6e09d872017-08-31 03:21:39 -0700277 SetSettingIfFlagSet(FLAG_aec3, &settings.use_aec3);
oprypin6e09d872017-08-31 03:21:39 -0700278 SetSettingIfFlagSet(FLAG_experimental_agc, &settings.use_experimental_agc);
279 SetSettingIfSpecified(FLAG_aecm_routing_mode, &settings.aecm_routing_mode);
280 SetSettingIfFlagSet(FLAG_aecm_comfort_noise,
peah60a189f2016-05-24 20:54:40 -0700281 &settings.use_aecm_comfort_noise);
oprypin6e09d872017-08-31 03:21:39 -0700282 SetSettingIfSpecified(FLAG_agc_mode, &settings.agc_mode);
283 SetSettingIfSpecified(FLAG_agc_target_level, &settings.agc_target_level);
284 SetSettingIfFlagSet(FLAG_agc_limiter, &settings.use_agc_limiter);
285 SetSettingIfSpecified(FLAG_agc_compression_gain,
peah60a189f2016-05-24 20:54:40 -0700286 &settings.agc_compression_gain);
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200287 settings.agc2_fixed_gain_db = FLAG_agc2_fixed_gain_db;
Alex Loiko5feb30e2018-04-16 13:52:32 +0200288 settings.pre_amplifier_gain_factor = FLAG_pre_amplifier_gain_factor;
oprypin6e09d872017-08-31 03:21:39 -0700289 SetSettingIfSpecified(FLAG_vad_likelihood, &settings.vad_likelihood);
290 SetSettingIfSpecified(FLAG_ns_level, &settings.ns_level);
291 SetSettingIfSpecified(FLAG_stream_delay, &settings.stream_delay);
Per Ã…hgrenc5efb0c2018-05-28 09:10:59 +0200292 SetSettingIfFlagSet(FLAG_use_stream_delay, &settings.use_stream_delay);
oprypin6e09d872017-08-31 03:21:39 -0700293 SetSettingIfSpecified(FLAG_stream_drift_samples,
peah60a189f2016-05-24 20:54:40 -0700294 &settings.stream_drift_samples);
oprypin6e09d872017-08-31 03:21:39 -0700295 SetSettingIfSpecified(FLAG_custom_call_order_file,
peah5ad5de32016-12-09 03:18:22 -0800296 &settings.custom_call_order_filename);
Per Ã…hgrenad09d742018-03-08 07:47:14 +0100297 SetSettingIfSpecified(FLAG_aec3_settings, &settings.aec3_settings_filename);
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200298 settings.initial_mic_level = FLAG_initial_mic_level;
299 settings.simulate_mic_gain = FLAG_simulate_mic_gain;
300 SetSettingIfSpecified(FLAG_simulated_mic_kind, &settings.simulated_mic_kind);
oprypin6e09d872017-08-31 03:21:39 -0700301 settings.report_performance = FLAG_performance_report;
302 settings.use_verbose_logging = FLAG_verbose;
303 settings.report_bitexactness = FLAG_bitexactness_report;
304 settings.discard_all_settings_in_aecdump = FLAG_discard_settings_in_aecdump;
305 settings.fixed_interface = FLAG_fixed_interface;
306 settings.store_intermediate_output = FLAG_store_intermediate_output;
peah60a189f2016-05-24 20:54:40 -0700307
308 return settings;
309}
310
Alex Loiko890988c2017-08-31 10:25:48 +0200311void ReportConditionalErrorAndExit(bool condition, const std::string& message) {
peah60a189f2016-05-24 20:54:40 -0700312 if (condition) {
313 std::cerr << message << std::endl;
314 exit(1);
315 }
316}
317
318void PerformBasicParameterSanityChecks(const SimulationSettings& settings) {
319 if (settings.input_filename || settings.reverse_input_filename) {
320 ReportConditionalErrorAndExit(!!settings.aec_dump_input_filename,
321 "Error: The aec dump cannot be specified "
322 "together with input wav files!\n");
323
peahdf80fd12016-12-09 02:43:40 -0800324 ReportConditionalErrorAndExit(!!settings.artificial_nearend_filename,
325 "Error: The artificial nearend cannot be "
326 "specified together with input wav files!\n");
327
peah60a189f2016-05-24 20:54:40 -0700328 ReportConditionalErrorAndExit(!settings.input_filename,
329 "Error: When operating at wav files, the "
330 "input wav filename must be "
331 "specified!\n");
332
333 ReportConditionalErrorAndExit(
334 settings.reverse_output_filename && !settings.reverse_input_filename,
335 "Error: When operating at wav files, the reverse input wav filename "
336 "must be specified if the reverse output wav filename is specified!\n");
337 } else {
338 ReportConditionalErrorAndExit(!settings.aec_dump_input_filename,
339 "Error: Either the aec dump or the wav "
340 "input files must be specified!\n");
341 }
342
343 ReportConditionalErrorAndExit(
344 settings.use_aec && *settings.use_aec && settings.use_aecm &&
345 *settings.use_aecm,
346 "Error: The AEC and the AECM cannot be activated at the same time!\n");
347
348 ReportConditionalErrorAndExit(
349 settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0,
350 "Error: --output_sample_rate_hz must be positive!\n");
351
352 ReportConditionalErrorAndExit(
353 settings.reverse_output_sample_rate_hz &&
354 settings.output_sample_rate_hz &&
355 *settings.output_sample_rate_hz <= 0,
356 "Error: --reverse_output_sample_rate_hz must be positive!\n");
357
358 ReportConditionalErrorAndExit(
359 settings.output_num_channels && *settings.output_num_channels <= 0,
360 "Error: --output_num_channels must be positive!\n");
361
362 ReportConditionalErrorAndExit(
363 settings.reverse_output_num_channels &&
364 *settings.reverse_output_num_channels <= 0,
365 "Error: --reverse_output_num_channels must be positive!\n");
366
367 ReportConditionalErrorAndExit(
368 settings.use_bf && *settings.use_bf && !settings.microphone_positions,
369 "Error: --mic_positions must be specified when the beamformer is "
370 "activated.\n");
371
372 ReportConditionalErrorAndExit(
Alex Luebs24c220c2018-03-15 11:27:22 -0700373 settings.target_angle_degrees < 0.f ||
374 settings.target_angle_degrees >= 360.f,
375 "Error: -target_angle_degrees must be specified between 0 and 360.\n");
peah60a189f2016-05-24 20:54:40 -0700376
377 ReportConditionalErrorAndExit(
378 settings.aec_suppression_level &&
379 ((*settings.aec_suppression_level) < 0 ||
380 (*settings.aec_suppression_level) > 2),
381 "Error: --aec_suppression_level must be specified between 0 and 2.\n");
382
383 ReportConditionalErrorAndExit(
384 settings.aecm_routing_mode && ((*settings.aecm_routing_mode) < 0 ||
385 (*settings.aecm_routing_mode) > 4),
386 "Error: --aecm_routing_mode must be specified between 0 and 4.\n");
387
388 ReportConditionalErrorAndExit(
389 settings.agc_target_level && ((*settings.agc_target_level) < 0 ||
390 (*settings.agc_target_level) > 31),
391 "Error: --agc_target_level must be specified between 0 and 31.\n");
392
393 ReportConditionalErrorAndExit(
394 settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 ||
395 (*settings.agc_compression_gain) > 90),
396 "Error: --agc_compression_gain must be specified between 0 and 90.\n");
397
398 ReportConditionalErrorAndExit(
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200399 settings.use_agc && *settings.use_agc && settings.use_agc2 &&
400 *settings.use_agc2,
401 "Error: --agc and --agc2 cannot be both active.\n");
402
403 ReportConditionalErrorAndExit(
404 settings.use_agc2 && *settings.use_agc2 &&
405 ((settings.agc2_fixed_gain_db) < 0 ||
406 (settings.agc2_fixed_gain_db) > 90),
407 "Error: --agc2_fixed_gain_db must be specified between 0 and 90.\n");
408
409 ReportConditionalErrorAndExit(
peah60a189f2016-05-24 20:54:40 -0700410 settings.vad_likelihood &&
411 ((*settings.vad_likelihood) < 0 || (*settings.vad_likelihood) > 3),
412 "Error: --vad_likelihood must be specified between 0 and 3.\n");
413
414 ReportConditionalErrorAndExit(
415 settings.ns_level &&
416 ((*settings.ns_level) < 0 || (*settings.ns_level) > 3),
417 "Error: --ns_level must be specified between 0 and 3.\n");
418
419 ReportConditionalErrorAndExit(
420 settings.report_bitexactness && !settings.aec_dump_input_filename,
421 "Error: --bitexactness_report can only be used when operating on an "
422 "aecdump\n");
423
peah5ad5de32016-12-09 03:18:22 -0800424 ReportConditionalErrorAndExit(
425 settings.custom_call_order_filename && settings.aec_dump_input_filename,
426 "Error: --custom_call_order_file cannot be used when operating on an "
427 "aecdump\n");
428
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200429 ReportConditionalErrorAndExit(
430 (settings.initial_mic_level < 0 || settings.initial_mic_level > 255),
431 "Error: --initial_mic_level must be specified between 0 and 255.\n");
432
433 ReportConditionalErrorAndExit(
434 settings.simulated_mic_kind && !settings.simulate_mic_gain,
435 "Error: --simulated_mic_kind cannot be specified when mic simulation is "
436 "disabled\n");
437
438 ReportConditionalErrorAndExit(
439 !settings.simulated_mic_kind && settings.simulate_mic_gain,
440 "Error: --simulated_mic_kind must be specified when mic simulation is "
441 "enabled\n");
442
peah60a189f2016-05-24 20:54:40 -0700443 auto valid_wav_name = [](const std::string& wav_file_name) {
444 if (wav_file_name.size() < 5) {
445 return false;
446 }
447 if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) ||
448 (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) {
449 return true;
450 }
451 return false;
452 };
453
454 ReportConditionalErrorAndExit(
455 settings.input_filename && (!valid_wav_name(*settings.input_filename)),
456 "Error: --i must be a valid .wav file name.\n");
457
458 ReportConditionalErrorAndExit(
459 settings.output_filename && (!valid_wav_name(*settings.output_filename)),
460 "Error: --o must be a valid .wav file name.\n");
461
462 ReportConditionalErrorAndExit(
463 settings.reverse_input_filename &&
464 (!valid_wav_name(*settings.reverse_input_filename)),
465 "Error: --ri must be a valid .wav file name.\n");
466
467 ReportConditionalErrorAndExit(
468 settings.reverse_output_filename &&
469 (!valid_wav_name(*settings.reverse_output_filename)),
470 "Error: --ro must be a valid .wav file name.\n");
peahdf80fd12016-12-09 02:43:40 -0800471
472 ReportConditionalErrorAndExit(
473 settings.artificial_nearend_filename &&
474 !valid_wav_name(*settings.artificial_nearend_filename),
475 "Error: --artifical_nearend must be a valid .wav file name.\n");
Peter Kasting69558702016-01-12 16:26:35 -0800476}
477
478} // namespace
479
Ivo Creusen2cb41052018-03-15 12:22:52 +0100480int AudioprocFloatImpl(std::unique_ptr<AudioProcessingBuilder> ap_builder,
481 int argc,
482 char* argv[]) {
oprypin6e09d872017-08-31 03:21:39 -0700483 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) ||
484 FLAG_help || argc != 1) {
485 printf("%s", kUsageDescription);
486 if (FLAG_help) {
487 rtc::FlagList::Print(nullptr, false);
488 return 0;
489 }
490 return 1;
491 }
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000492
peah60a189f2016-05-24 20:54:40 -0700493 SimulationSettings settings = CreateSettings();
494 PerformBasicParameterSanityChecks(settings);
495 std::unique_ptr<AudioProcessingSimulator> processor;
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000496
peah60a189f2016-05-24 20:54:40 -0700497 if (settings.aec_dump_input_filename) {
Ivo Creusen8c812f32018-03-09 17:33:04 +0100498 processor.reset(new AecDumpBasedSimulator(settings, std::move(ap_builder)));
aluebsb0ad43b2015-11-20 00:11:53 -0800499 } else {
Ivo Creusen8c812f32018-03-09 17:33:04 +0100500 processor.reset(new WavBasedSimulator(settings, std::move(ap_builder)));
andrewbdafe312015-10-29 23:42:54 -0700501 }
502
peah60a189f2016-05-24 20:54:40 -0700503 processor->Process();
aluebsb0ad43b2015-11-20 00:11:53 -0800504
peah60a189f2016-05-24 20:54:40 -0700505 if (settings.report_performance) {
aluebsb0ad43b2015-11-20 00:11:53 -0800506 const auto& proc_time = processor->proc_time();
Niels Möllerd28db7f2016-05-10 16:31:47 +0200507 int64_t exec_time_us = proc_time.sum / rtc::kNumNanosecsPerMicrosec;
peah60a189f2016-05-24 20:54:40 -0700508 std::cout << std::endl
509 << "Execution time: " << exec_time_us * 1e-6 << " s, File time: "
510 << processor->get_num_process_stream_calls() * 1.f /
511 AudioProcessingSimulator::kChunksPerSecond
512 << std::endl
513 << "Time per fwd stream chunk (mean, max, min): " << std::endl
514 << exec_time_us * 1.f / processor->get_num_process_stream_calls()
515 << " us, " << 1.f * proc_time.max / rtc::kNumNanosecsPerMicrosec
516 << " us, " << 1.f * proc_time.min / rtc::kNumNanosecsPerMicrosec
517 << " us" << std::endl;
518 }
519
520 if (settings.report_bitexactness && settings.aec_dump_input_filename) {
521 if (processor->OutputWasBitexact()) {
522 std::cout << "The processing was bitexact.";
523 } else {
524 std::cout << "The processing was not bitexact.";
525 }
Alejandro Luebs5d22c002015-04-15 11:26:40 -0700526 }
aluebsb0ad43b2015-11-20 00:11:53 -0800527
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000528 return 0;
529}
530
peah60a189f2016-05-24 20:54:40 -0700531} // namespace test
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000532} // namespace webrtc