blob: cce153e3f986bc3523f075006a53f27d3f10534d [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>
Alessio Bazzica68170382018-11-20 12:27:20 +010017#include <vector>
andrew@webrtc.org08df9b22014-12-16 20:57:15 +000018
Alessio Bazzica68170382018-11-20 12:27:20 +010019#include "absl/strings/string_view.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_processing/include/audio_processing.h"
21#include "modules/audio_processing/test/aec_dump_based_simulator.h"
22#include "modules/audio_processing/test/audio_processing_simulator.h"
Ivo Creusen2cb41052018-03-15 12:22:52 +010023#include "modules/audio_processing/test/audioproc_float_impl.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "modules/audio_processing/test/wav_based_simulator.h"
Alessio Bazzica68170382018-11-20 12:27:20 +010025#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/flags.h"
Alessio Bazzica68170382018-11-20 12:27:20 +010027#include "rtc_base/strings/string_builder.h"
andrew@webrtc.org08df9b22014-12-16 20:57:15 +000028
peah60a189f2016-05-24 20:54:40 -070029namespace webrtc {
30namespace test {
Peter Kasting69558702016-01-12 16:26:35 -080031namespace {
32
peah60a189f2016-05-24 20:54:40 -070033const int kParameterNotSpecifiedValue = -10000;
34
35const char kUsageDescription[] =
36 "Usage: audioproc_f [options] -i <input.wav>\n"
37 " or\n"
38 " audioproc_f [options] -dump_input <aec_dump>\n"
39 "\n\n"
40 "Command-line tool to simulate a call using the audio "
41 "processing module, either based on wav files or "
oprypin6e09d872017-08-31 03:21:39 -070042 "protobuf debug dump recordings.\n";
peah60a189f2016-05-24 20:54:40 -070043
Mirko Bonadei2dfa9982018-10-18 11:35:32 +020044WEBRTC_DEFINE_string(dump_input, "", "Aec dump input filename");
45WEBRTC_DEFINE_string(dump_output, "", "Aec dump output filename");
46WEBRTC_DEFINE_string(i, "", "Forward stream input wav filename");
47WEBRTC_DEFINE_string(o, "", "Forward stream output wav filename");
48WEBRTC_DEFINE_string(ri, "", "Reverse stream input wav filename");
49WEBRTC_DEFINE_string(ro, "", "Reverse stream output wav filename");
50WEBRTC_DEFINE_string(artificial_nearend, "", "Artificial nearend wav filename");
51WEBRTC_DEFINE_int(output_num_channels,
52 kParameterNotSpecifiedValue,
53 "Number of forward stream output channels");
54WEBRTC_DEFINE_int(reverse_output_num_channels,
55 kParameterNotSpecifiedValue,
56 "Number of Reverse stream output channels");
57WEBRTC_DEFINE_int(output_sample_rate_hz,
58 kParameterNotSpecifiedValue,
59 "Forward stream output sample rate in Hz");
60WEBRTC_DEFINE_int(reverse_output_sample_rate_hz,
61 kParameterNotSpecifiedValue,
62 "Reverse stream output sample rate in Hz");
63WEBRTC_DEFINE_bool(fixed_interface,
64 false,
65 "Use the fixed interface when operating on wav files");
66WEBRTC_DEFINE_int(aec,
67 kParameterNotSpecifiedValue,
68 "Activate (1) or deactivate(0) the echo canceller");
69WEBRTC_DEFINE_int(aecm,
70 kParameterNotSpecifiedValue,
71 "Activate (1) or deactivate(0) the mobile echo controller");
72WEBRTC_DEFINE_int(ed,
73 kParameterNotSpecifiedValue,
74 "Activate (1) or deactivate (0) the residual echo detector");
75WEBRTC_DEFINE_string(ed_graph,
76 "",
77 "Output filename for graph of echo likelihood");
78WEBRTC_DEFINE_int(agc,
79 kParameterNotSpecifiedValue,
80 "Activate (1) or deactivate(0) the AGC");
81WEBRTC_DEFINE_int(agc2,
82 kParameterNotSpecifiedValue,
83 "Activate (1) or deactivate(0) the AGC2");
84WEBRTC_DEFINE_int(pre_amplifier,
85 kParameterNotSpecifiedValue,
86 "Activate (1) or deactivate(0) the pre amplifier");
87WEBRTC_DEFINE_int(hpf,
88 kParameterNotSpecifiedValue,
89 "Activate (1) or deactivate(0) the high-pass filter");
90WEBRTC_DEFINE_int(ns,
91 kParameterNotSpecifiedValue,
92 "Activate (1) or deactivate(0) the noise suppressor");
93WEBRTC_DEFINE_int(ts,
94 kParameterNotSpecifiedValue,
95 "Activate (1) or deactivate(0) the transient suppressor");
96WEBRTC_DEFINE_int(vad,
97 kParameterNotSpecifiedValue,
98 "Activate (1) or deactivate(0) the voice activity detector");
99WEBRTC_DEFINE_int(le,
100 kParameterNotSpecifiedValue,
101 "Activate (1) or deactivate(0) the level estimator");
102WEBRTC_DEFINE_bool(
103 all_default,
104 false,
105 "Activate all of the default components (will be overridden by any "
106 "other settings)");
107WEBRTC_DEFINE_int(aec_suppression_level,
108 kParameterNotSpecifiedValue,
109 "Set the aec suppression level (0-2)");
110WEBRTC_DEFINE_int(delay_agnostic,
111 kParameterNotSpecifiedValue,
112 "Activate (1) or deactivate(0) the AEC delay agnostic mode");
113WEBRTC_DEFINE_int(extended_filter,
114 kParameterNotSpecifiedValue,
115 "Activate (1) or deactivate(0) the AEC extended filter mode");
116WEBRTC_DEFINE_int(
117 aec3,
118 kParameterNotSpecifiedValue,
119 "Activate (1) or deactivate(0) the experimental AEC mode AEC3");
120WEBRTC_DEFINE_int(experimental_agc,
121 kParameterNotSpecifiedValue,
122 "Activate (1) or deactivate(0) the experimental AGC");
123WEBRTC_DEFINE_int(
124 experimental_agc_disable_digital_adaptive,
125 kParameterNotSpecifiedValue,
126 "Force-deactivate (1) digital adaptation in "
127 "experimental AGC. Digital adaptation is active by default (0).");
128WEBRTC_DEFINE_int(experimental_agc_analyze_before_aec,
129 kParameterNotSpecifiedValue,
130 "Make level estimation happen before AEC"
131 " in the experimental AGC. After AEC is the default (0)");
132WEBRTC_DEFINE_int(
Alex Loikod9342442018-09-10 13:59:41 +0200133 experimental_agc_agc2_level_estimator,
134 kParameterNotSpecifiedValue,
135 "AGC2 level estimation"
136 " in the experimental AGC. AGC1 level estimation is the default (0)");
Mirko Bonadei2dfa9982018-10-18 11:35:32 +0200137WEBRTC_DEFINE_int(
peah60a189f2016-05-24 20:54:40 -0700138 refined_adaptive_filter,
139 kParameterNotSpecifiedValue,
140 "Activate (1) or deactivate(0) the refined adaptive filter functionality");
Mirko Bonadei2dfa9982018-10-18 11:35:32 +0200141WEBRTC_DEFINE_int(agc_mode,
142 kParameterNotSpecifiedValue,
143 "Specify the AGC mode (0-2)");
144WEBRTC_DEFINE_int(agc_target_level,
145 kParameterNotSpecifiedValue,
146 "Specify the AGC target level (0-31)");
147WEBRTC_DEFINE_int(agc_limiter,
148 kParameterNotSpecifiedValue,
149 "Activate (1) or deactivate(0) the level estimator");
150WEBRTC_DEFINE_int(agc_compression_gain,
151 kParameterNotSpecifiedValue,
152 "Specify the AGC compression gain (0-90)");
153WEBRTC_DEFINE_float(agc2_enable_adaptive_gain,
154 kParameterNotSpecifiedValue,
155 "Activate (1) or deactivate(0) the AGC2 adaptive gain");
156WEBRTC_DEFINE_float(agc2_fixed_gain_db, 0.f, "AGC2 fixed gain (dB) to apply");
Alessio Bazzica68170382018-11-20 12:27:20 +0100157
158std::vector<std::string> GetAgc2AdaptiveLevelEstimatorNames() {
159 return {"RMS", "peak"};
160}
161WEBRTC_DEFINE_string(
162 agc2_adaptive_level_estimator,
163 "RMS",
164 "AGC2 adaptive digital level estimator to use [RMS, peak]");
165
Mirko Bonadei2dfa9982018-10-18 11:35:32 +0200166WEBRTC_DEFINE_float(pre_amplifier_gain_factor,
167 1.f,
168 "Pre-amplifier gain factor (linear) to apply");
169WEBRTC_DEFINE_int(vad_likelihood,
170 kParameterNotSpecifiedValue,
171 "Specify the VAD likelihood (0-3)");
172WEBRTC_DEFINE_int(ns_level,
173 kParameterNotSpecifiedValue,
174 "Specify the NS level (0-3)");
175WEBRTC_DEFINE_int(stream_delay,
176 kParameterNotSpecifiedValue,
177 "Specify the stream delay in ms to use");
178WEBRTC_DEFINE_int(use_stream_delay,
179 kParameterNotSpecifiedValue,
180 "Activate (1) or deactivate(0) reporting the stream delay");
181WEBRTC_DEFINE_int(stream_drift_samples,
182 kParameterNotSpecifiedValue,
183 "Specify the number of stream drift samples to use");
184WEBRTC_DEFINE_int(initial_mic_level, 100, "Initial mic level (0-255)");
185WEBRTC_DEFINE_int(
186 simulate_mic_gain,
187 0,
188 "Activate (1) or deactivate(0) the analog mic gain simulation");
189WEBRTC_DEFINE_int(
190 simulated_mic_kind,
191 kParameterNotSpecifiedValue,
192 "Specify which microphone kind to use for microphone simulation");
193WEBRTC_DEFINE_bool(performance_report, false, "Report the APM performance ");
194WEBRTC_DEFINE_bool(verbose, false, "Produce verbose output");
195WEBRTC_DEFINE_bool(quiet,
196 false,
197 "Avoid producing information about the progress.");
198WEBRTC_DEFINE_bool(bitexactness_report,
199 false,
200 "Report bitexactness for aec dump result reproduction");
201WEBRTC_DEFINE_bool(discard_settings_in_aecdump,
202 false,
203 "Discard any config settings specified in the aec dump");
204WEBRTC_DEFINE_bool(store_intermediate_output,
205 false,
206 "Creates new output files after each init");
207WEBRTC_DEFINE_string(custom_call_order_file,
208 "",
209 "Custom process API call order file");
210WEBRTC_DEFINE_bool(print_aec3_parameter_values,
211 false,
212 "Print parameter values used in AEC3 in JSON-format");
213WEBRTC_DEFINE_string(aec3_settings,
214 "",
215 "File in JSON-format with custom AEC3 settings");
Per Åhgren7a95e0f2018-10-25 09:56:49 +0200216WEBRTC_DEFINE_bool(dump_data,
217 false,
218 "Dump internal data during the call (requires build flag)");
Mirko Bonadei2dfa9982018-10-18 11:35:32 +0200219WEBRTC_DEFINE_bool(help, false, "Print this message");
peah60a189f2016-05-24 20:54:40 -0700220
Alex Loiko890988c2017-08-31 10:25:48 +0200221void SetSettingIfSpecified(const std::string& value,
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200222 absl::optional<std::string>* parameter) {
peah60a189f2016-05-24 20:54:40 -0700223 if (value.compare("") != 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100224 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700225 }
226}
227
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200228void SetSettingIfSpecified(int value, absl::optional<int>* parameter) {
peah60a189f2016-05-24 20:54:40 -0700229 if (value != kParameterNotSpecifiedValue) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100230 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700231 }
232}
233
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200234void SetSettingIfFlagSet(int32_t flag, absl::optional<bool>* parameter) {
peah60a189f2016-05-24 20:54:40 -0700235 if (flag == 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100236 *parameter = false;
peah60a189f2016-05-24 20:54:40 -0700237 } else if (flag == 1) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100238 *parameter = true;
peah60a189f2016-05-24 20:54:40 -0700239 }
240}
241
Alessio Bazzica68170382018-11-20 12:27:20 +0100242AudioProcessing::Config::GainController2::LevelEstimator
243MapAgc2AdaptiveLevelEstimator(absl::string_view name) {
244 if (name.compare("RMS") == 0) {
245 return AudioProcessing::Config::GainController2::LevelEstimator::kRms;
246 }
247 if (name.compare("peak") == 0) {
248 return AudioProcessing::Config::GainController2::LevelEstimator::kPeak;
249 }
250 auto concat_strings =
251 [](const std::vector<std::string>& strings) -> std::string {
252 rtc::StringBuilder ss;
253 for (const auto& s : strings) {
254 ss << " " << s;
255 }
256 return ss.Release();
257 };
258 RTC_CHECK(false)
259 << "Invalid value for agc2_adaptive_level_estimator, valid options:"
260 << concat_strings(GetAgc2AdaptiveLevelEstimatorNames()) << ".";
261}
262
peah60a189f2016-05-24 20:54:40 -0700263SimulationSettings CreateSettings() {
264 SimulationSettings settings;
oprypin6e09d872017-08-31 03:21:39 -0700265 if (FLAG_all_default) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100266 settings.use_le = true;
267 settings.use_vad = true;
268 settings.use_ie = false;
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100269 settings.use_ts = true;
270 settings.use_ns = true;
271 settings.use_hpf = true;
272 settings.use_agc = true;
273 settings.use_agc2 = false;
Alex Loiko5feb30e2018-04-16 13:52:32 +0200274 settings.use_pre_amplifier = false;
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100275 settings.use_aec = true;
276 settings.use_aecm = false;
277 settings.use_ed = false;
peah60a189f2016-05-24 20:54:40 -0700278 }
oprypin6e09d872017-08-31 03:21:39 -0700279 SetSettingIfSpecified(FLAG_dump_input, &settings.aec_dump_input_filename);
280 SetSettingIfSpecified(FLAG_dump_output, &settings.aec_dump_output_filename);
281 SetSettingIfSpecified(FLAG_i, &settings.input_filename);
282 SetSettingIfSpecified(FLAG_o, &settings.output_filename);
283 SetSettingIfSpecified(FLAG_ri, &settings.reverse_input_filename);
284 SetSettingIfSpecified(FLAG_ro, &settings.reverse_output_filename);
285 SetSettingIfSpecified(FLAG_artificial_nearend,
peahdf80fd12016-12-09 02:43:40 -0800286 &settings.artificial_nearend_filename);
oprypin6e09d872017-08-31 03:21:39 -0700287 SetSettingIfSpecified(FLAG_output_num_channels,
peah60a189f2016-05-24 20:54:40 -0700288 &settings.output_num_channels);
oprypin6e09d872017-08-31 03:21:39 -0700289 SetSettingIfSpecified(FLAG_reverse_output_num_channels,
peah60a189f2016-05-24 20:54:40 -0700290 &settings.reverse_output_num_channels);
oprypin6e09d872017-08-31 03:21:39 -0700291 SetSettingIfSpecified(FLAG_output_sample_rate_hz,
peah60a189f2016-05-24 20:54:40 -0700292 &settings.output_sample_rate_hz);
oprypin6e09d872017-08-31 03:21:39 -0700293 SetSettingIfSpecified(FLAG_reverse_output_sample_rate_hz,
peah60a189f2016-05-24 20:54:40 -0700294 &settings.reverse_output_sample_rate_hz);
oprypin6e09d872017-08-31 03:21:39 -0700295 SetSettingIfFlagSet(FLAG_aec, &settings.use_aec);
296 SetSettingIfFlagSet(FLAG_aecm, &settings.use_aecm);
297 SetSettingIfFlagSet(FLAG_ed, &settings.use_ed);
298 SetSettingIfSpecified(FLAG_ed_graph, &settings.ed_graph_output_filename);
299 SetSettingIfFlagSet(FLAG_agc, &settings.use_agc);
300 SetSettingIfFlagSet(FLAG_agc2, &settings.use_agc2);
Alex Loiko5feb30e2018-04-16 13:52:32 +0200301 SetSettingIfFlagSet(FLAG_pre_amplifier, &settings.use_pre_amplifier);
oprypin6e09d872017-08-31 03:21:39 -0700302 SetSettingIfFlagSet(FLAG_hpf, &settings.use_hpf);
303 SetSettingIfFlagSet(FLAG_ns, &settings.use_ns);
304 SetSettingIfFlagSet(FLAG_ts, &settings.use_ts);
oprypin6e09d872017-08-31 03:21:39 -0700305 SetSettingIfFlagSet(FLAG_vad, &settings.use_vad);
306 SetSettingIfFlagSet(FLAG_le, &settings.use_le);
307 SetSettingIfSpecified(FLAG_aec_suppression_level,
peah60a189f2016-05-24 20:54:40 -0700308 &settings.aec_suppression_level);
oprypin6e09d872017-08-31 03:21:39 -0700309 SetSettingIfFlagSet(FLAG_delay_agnostic, &settings.use_delay_agnostic);
310 SetSettingIfFlagSet(FLAG_extended_filter, &settings.use_extended_filter);
oprypin6e09d872017-08-31 03:21:39 -0700311 SetSettingIfFlagSet(FLAG_refined_adaptive_filter,
peah60a189f2016-05-24 20:54:40 -0700312 &settings.use_refined_adaptive_filter);
313
oprypin6e09d872017-08-31 03:21:39 -0700314 SetSettingIfFlagSet(FLAG_aec3, &settings.use_aec3);
oprypin6e09d872017-08-31 03:21:39 -0700315 SetSettingIfFlagSet(FLAG_experimental_agc, &settings.use_experimental_agc);
Alex Loiko9489c3a2018-08-09 15:04:24 +0200316 SetSettingIfFlagSet(FLAG_experimental_agc_disable_digital_adaptive,
317 &settings.experimental_agc_disable_digital_adaptive);
Alex Loikod9342442018-09-10 13:59:41 +0200318 SetSettingIfFlagSet(FLAG_experimental_agc_analyze_before_aec,
319 &settings.experimental_agc_analyze_before_aec);
320 SetSettingIfFlagSet(FLAG_experimental_agc_agc2_level_estimator,
321 &settings.use_experimental_agc_agc2_level_estimator);
oprypin6e09d872017-08-31 03:21:39 -0700322 SetSettingIfSpecified(FLAG_agc_mode, &settings.agc_mode);
323 SetSettingIfSpecified(FLAG_agc_target_level, &settings.agc_target_level);
324 SetSettingIfFlagSet(FLAG_agc_limiter, &settings.use_agc_limiter);
325 SetSettingIfSpecified(FLAG_agc_compression_gain,
peah60a189f2016-05-24 20:54:40 -0700326 &settings.agc_compression_gain);
Per Åhgrene4d23b12018-10-02 23:40:07 +0200327 SetSettingIfFlagSet(FLAG_agc2_enable_adaptive_gain,
328 &settings.agc2_use_adaptive_gain);
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200329 settings.agc2_fixed_gain_db = FLAG_agc2_fixed_gain_db;
Alessio Bazzica68170382018-11-20 12:27:20 +0100330 settings.agc2_adaptive_level_estimator =
331 MapAgc2AdaptiveLevelEstimator(FLAG_agc2_adaptive_level_estimator);
Alex Loiko5feb30e2018-04-16 13:52:32 +0200332 settings.pre_amplifier_gain_factor = FLAG_pre_amplifier_gain_factor;
oprypin6e09d872017-08-31 03:21:39 -0700333 SetSettingIfSpecified(FLAG_vad_likelihood, &settings.vad_likelihood);
334 SetSettingIfSpecified(FLAG_ns_level, &settings.ns_level);
335 SetSettingIfSpecified(FLAG_stream_delay, &settings.stream_delay);
Per Åhgrenc5efb0c2018-05-28 09:10:59 +0200336 SetSettingIfFlagSet(FLAG_use_stream_delay, &settings.use_stream_delay);
oprypin6e09d872017-08-31 03:21:39 -0700337 SetSettingIfSpecified(FLAG_stream_drift_samples,
peah60a189f2016-05-24 20:54:40 -0700338 &settings.stream_drift_samples);
oprypin6e09d872017-08-31 03:21:39 -0700339 SetSettingIfSpecified(FLAG_custom_call_order_file,
peah5ad5de32016-12-09 03:18:22 -0800340 &settings.custom_call_order_filename);
Per Åhgrenad09d742018-03-08 07:47:14 +0100341 SetSettingIfSpecified(FLAG_aec3_settings, &settings.aec3_settings_filename);
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200342 settings.initial_mic_level = FLAG_initial_mic_level;
343 settings.simulate_mic_gain = FLAG_simulate_mic_gain;
344 SetSettingIfSpecified(FLAG_simulated_mic_kind, &settings.simulated_mic_kind);
oprypin6e09d872017-08-31 03:21:39 -0700345 settings.report_performance = FLAG_performance_report;
346 settings.use_verbose_logging = FLAG_verbose;
Per Åhgren5a72a5e2018-08-24 07:18:24 +0200347 settings.use_quiet_output = FLAG_quiet;
oprypin6e09d872017-08-31 03:21:39 -0700348 settings.report_bitexactness = FLAG_bitexactness_report;
349 settings.discard_all_settings_in_aecdump = FLAG_discard_settings_in_aecdump;
350 settings.fixed_interface = FLAG_fixed_interface;
351 settings.store_intermediate_output = FLAG_store_intermediate_output;
Per Åhgren56b5a6c2018-09-14 06:49:36 +0200352 settings.print_aec3_parameter_values = FLAG_print_aec3_parameter_values;
Per Åhgren7a95e0f2018-10-25 09:56:49 +0200353 settings.dump_internal_data = FLAG_dump_data;
peah60a189f2016-05-24 20:54:40 -0700354
355 return settings;
356}
357
Alex Loiko890988c2017-08-31 10:25:48 +0200358void ReportConditionalErrorAndExit(bool condition, const std::string& message) {
peah60a189f2016-05-24 20:54:40 -0700359 if (condition) {
360 std::cerr << message << std::endl;
361 exit(1);
362 }
363}
364
365void PerformBasicParameterSanityChecks(const SimulationSettings& settings) {
366 if (settings.input_filename || settings.reverse_input_filename) {
367 ReportConditionalErrorAndExit(!!settings.aec_dump_input_filename,
368 "Error: The aec dump cannot be specified "
369 "together with input wav files!\n");
370
peahdf80fd12016-12-09 02:43:40 -0800371 ReportConditionalErrorAndExit(!!settings.artificial_nearend_filename,
372 "Error: The artificial nearend cannot be "
373 "specified together with input wav files!\n");
374
peah60a189f2016-05-24 20:54:40 -0700375 ReportConditionalErrorAndExit(!settings.input_filename,
376 "Error: When operating at wav files, the "
377 "input wav filename must be "
378 "specified!\n");
379
380 ReportConditionalErrorAndExit(
381 settings.reverse_output_filename && !settings.reverse_input_filename,
382 "Error: When operating at wav files, the reverse input wav filename "
383 "must be specified if the reverse output wav filename is specified!\n");
384 } else {
385 ReportConditionalErrorAndExit(!settings.aec_dump_input_filename,
386 "Error: Either the aec dump or the wav "
387 "input files must be specified!\n");
388 }
389
390 ReportConditionalErrorAndExit(
391 settings.use_aec && *settings.use_aec && settings.use_aecm &&
392 *settings.use_aecm,
393 "Error: The AEC and the AECM cannot be activated at the same time!\n");
394
395 ReportConditionalErrorAndExit(
396 settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0,
397 "Error: --output_sample_rate_hz must be positive!\n");
398
399 ReportConditionalErrorAndExit(
400 settings.reverse_output_sample_rate_hz &&
401 settings.output_sample_rate_hz &&
402 *settings.output_sample_rate_hz <= 0,
403 "Error: --reverse_output_sample_rate_hz must be positive!\n");
404
405 ReportConditionalErrorAndExit(
406 settings.output_num_channels && *settings.output_num_channels <= 0,
407 "Error: --output_num_channels must be positive!\n");
408
409 ReportConditionalErrorAndExit(
410 settings.reverse_output_num_channels &&
411 *settings.reverse_output_num_channels <= 0,
412 "Error: --reverse_output_num_channels must be positive!\n");
413
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200414 ReportConditionalErrorAndExit(settings.aec_suppression_level &&
415 ((*settings.aec_suppression_level) < 1 ||
416 (*settings.aec_suppression_level) > 2),
417 "Error: --aec_suppression_level must be "
418 "specified between 1 and 2. 0 is "
419 "deprecated.\n");
peah60a189f2016-05-24 20:54:40 -0700420
421 ReportConditionalErrorAndExit(
peah60a189f2016-05-24 20:54:40 -0700422 settings.agc_target_level && ((*settings.agc_target_level) < 0 ||
423 (*settings.agc_target_level) > 31),
424 "Error: --agc_target_level must be specified between 0 and 31.\n");
425
426 ReportConditionalErrorAndExit(
427 settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 ||
428 (*settings.agc_compression_gain) > 90),
429 "Error: --agc_compression_gain must be specified between 0 and 90.\n");
430
431 ReportConditionalErrorAndExit(
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200432 settings.use_agc2 && *settings.use_agc2 &&
433 ((settings.agc2_fixed_gain_db) < 0 ||
434 (settings.agc2_fixed_gain_db) > 90),
435 "Error: --agc2_fixed_gain_db must be specified between 0 and 90.\n");
436
437 ReportConditionalErrorAndExit(
peah60a189f2016-05-24 20:54:40 -0700438 settings.vad_likelihood &&
439 ((*settings.vad_likelihood) < 0 || (*settings.vad_likelihood) > 3),
440 "Error: --vad_likelihood must be specified between 0 and 3.\n");
441
442 ReportConditionalErrorAndExit(
443 settings.ns_level &&
444 ((*settings.ns_level) < 0 || (*settings.ns_level) > 3),
445 "Error: --ns_level must be specified between 0 and 3.\n");
446
447 ReportConditionalErrorAndExit(
448 settings.report_bitexactness && !settings.aec_dump_input_filename,
449 "Error: --bitexactness_report can only be used when operating on an "
450 "aecdump\n");
451
peah5ad5de32016-12-09 03:18:22 -0800452 ReportConditionalErrorAndExit(
453 settings.custom_call_order_filename && settings.aec_dump_input_filename,
454 "Error: --custom_call_order_file cannot be used when operating on an "
455 "aecdump\n");
456
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200457 ReportConditionalErrorAndExit(
458 (settings.initial_mic_level < 0 || settings.initial_mic_level > 255),
459 "Error: --initial_mic_level must be specified between 0 and 255.\n");
460
461 ReportConditionalErrorAndExit(
462 settings.simulated_mic_kind && !settings.simulate_mic_gain,
463 "Error: --simulated_mic_kind cannot be specified when mic simulation is "
464 "disabled\n");
465
466 ReportConditionalErrorAndExit(
467 !settings.simulated_mic_kind && settings.simulate_mic_gain,
468 "Error: --simulated_mic_kind must be specified when mic simulation is "
469 "enabled\n");
470
peah60a189f2016-05-24 20:54:40 -0700471 auto valid_wav_name = [](const std::string& wav_file_name) {
472 if (wav_file_name.size() < 5) {
473 return false;
474 }
475 if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) ||
476 (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) {
477 return true;
478 }
479 return false;
480 };
481
482 ReportConditionalErrorAndExit(
483 settings.input_filename && (!valid_wav_name(*settings.input_filename)),
484 "Error: --i must be a valid .wav file name.\n");
485
486 ReportConditionalErrorAndExit(
487 settings.output_filename && (!valid_wav_name(*settings.output_filename)),
488 "Error: --o must be a valid .wav file name.\n");
489
490 ReportConditionalErrorAndExit(
491 settings.reverse_input_filename &&
492 (!valid_wav_name(*settings.reverse_input_filename)),
493 "Error: --ri must be a valid .wav file name.\n");
494
495 ReportConditionalErrorAndExit(
496 settings.reverse_output_filename &&
497 (!valid_wav_name(*settings.reverse_output_filename)),
498 "Error: --ro must be a valid .wav file name.\n");
peahdf80fd12016-12-09 02:43:40 -0800499
500 ReportConditionalErrorAndExit(
501 settings.artificial_nearend_filename &&
502 !valid_wav_name(*settings.artificial_nearend_filename),
503 "Error: --artifical_nearend must be a valid .wav file name.\n");
Per Åhgren7a95e0f2018-10-25 09:56:49 +0200504
505 ReportConditionalErrorAndExit(
506 WEBRTC_APM_DEBUG_DUMP == 0 && settings.dump_internal_data,
507 "Error: --dump_data cannot be set without proper build support.\n");
Peter Kasting69558702016-01-12 16:26:35 -0800508}
509
510} // namespace
511
Ivo Creusen2cb41052018-03-15 12:22:52 +0100512int AudioprocFloatImpl(std::unique_ptr<AudioProcessingBuilder> ap_builder,
513 int argc,
514 char* argv[]) {
Yves Gerey665174f2018-06-19 15:03:05 +0200515 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help ||
516 argc != 1) {
oprypin6e09d872017-08-31 03:21:39 -0700517 printf("%s", kUsageDescription);
518 if (FLAG_help) {
519 rtc::FlagList::Print(nullptr, false);
520 return 0;
521 }
522 return 1;
523 }
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000524
peah60a189f2016-05-24 20:54:40 -0700525 SimulationSettings settings = CreateSettings();
526 PerformBasicParameterSanityChecks(settings);
527 std::unique_ptr<AudioProcessingSimulator> processor;
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000528
peah60a189f2016-05-24 20:54:40 -0700529 if (settings.aec_dump_input_filename) {
Ivo Creusen8c812f32018-03-09 17:33:04 +0100530 processor.reset(new AecDumpBasedSimulator(settings, std::move(ap_builder)));
aluebsb0ad43b2015-11-20 00:11:53 -0800531 } else {
Ivo Creusen8c812f32018-03-09 17:33:04 +0100532 processor.reset(new WavBasedSimulator(settings, std::move(ap_builder)));
andrewbdafe312015-10-29 23:42:54 -0700533 }
534
peah60a189f2016-05-24 20:54:40 -0700535 processor->Process();
aluebsb0ad43b2015-11-20 00:11:53 -0800536
peah60a189f2016-05-24 20:54:40 -0700537 if (settings.report_performance) {
aluebsb0ad43b2015-11-20 00:11:53 -0800538 const auto& proc_time = processor->proc_time();
Niels Möllerd28db7f2016-05-10 16:31:47 +0200539 int64_t exec_time_us = proc_time.sum / rtc::kNumNanosecsPerMicrosec;
peah60a189f2016-05-24 20:54:40 -0700540 std::cout << std::endl
541 << "Execution time: " << exec_time_us * 1e-6 << " s, File time: "
542 << processor->get_num_process_stream_calls() * 1.f /
543 AudioProcessingSimulator::kChunksPerSecond
544 << std::endl
545 << "Time per fwd stream chunk (mean, max, min): " << std::endl
546 << exec_time_us * 1.f / processor->get_num_process_stream_calls()
547 << " us, " << 1.f * proc_time.max / rtc::kNumNanosecsPerMicrosec
548 << " us, " << 1.f * proc_time.min / rtc::kNumNanosecsPerMicrosec
549 << " us" << std::endl;
550 }
551
552 if (settings.report_bitexactness && settings.aec_dump_input_filename) {
553 if (processor->OutputWasBitexact()) {
554 std::cout << "The processing was bitexact.";
555 } else {
556 std::cout << "The processing was not bitexact.";
557 }
Alejandro Luebs5d22c002015-04-15 11:26:40 -0700558 }
aluebsb0ad43b2015-11-20 00:11:53 -0800559
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000560 return 0;
561}
562
peah60a189f2016-05-24 20:54:40 -0700563} // namespace test
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000564} // namespace webrtc