blob: 1fc39bb6b964829d955bab3c60fcc024c79ecad3 [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
Per Åhgren6ee75fd2019-04-26 11:33:37 +020011#include "modules/audio_processing/test/audioproc_float_impl.h"
12
Ivo Creusen2cb41052018-03-15 12:22:52 +010013#include <string.h>
14
aluebsb0ad43b2015-11-20 00:11:53 -080015#include <iostream>
kwiberg62eaacf2016-02-17 06:39:05 -080016#include <memory>
Ivo Creusen2cb41052018-03-15 12:22:52 +010017#include <string>
18#include <utility>
Alessio Bazzica68170382018-11-20 12:27:20 +010019#include <vector>
andrew@webrtc.org08df9b22014-12-16 20:57:15 +000020
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020021#include "absl/flags/flag.h"
22#include "absl/flags/parse.h"
Alessio Bazzica68170382018-11-20 12:27:20 +010023#include "absl/strings/string_view.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "modules/audio_processing/include/audio_processing.h"
25#include "modules/audio_processing/test/aec_dump_based_simulator.h"
26#include "modules/audio_processing/test/audio_processing_simulator.h"
27#include "modules/audio_processing/test/wav_based_simulator.h"
Alessio Bazzica68170382018-11-20 12:27:20 +010028#include "rtc_base/checks.h"
Alessio Bazzica68170382018-11-20 12:27:20 +010029#include "rtc_base/strings/string_builder.h"
saza0cf99ce2020-04-01 17:42:01 +020030#include "system_wrappers/include/field_trial.h"
andrew@webrtc.org08df9b22014-12-16 20:57:15 +000031
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020032constexpr int kParameterNotSpecifiedValue = -10000;
33
34ABSL_FLAG(std::string, dump_input, "", "Aec dump input filename");
35ABSL_FLAG(std::string, dump_output, "", "Aec dump output filename");
36ABSL_FLAG(std::string, i, "", "Forward stream input wav filename");
37ABSL_FLAG(std::string, o, "", "Forward stream output wav filename");
38ABSL_FLAG(std::string, ri, "", "Reverse stream input wav filename");
39ABSL_FLAG(std::string, ro, "", "Reverse stream output wav filename");
40ABSL_FLAG(std::string,
41 artificial_nearend,
42 "",
43 "Artificial nearend wav filename");
Per Åhgrenc20a19c2019-11-13 11:12:29 +010044ABSL_FLAG(std::string, linear_aec_output, "", "Linear AEC output wav filename");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020045ABSL_FLAG(int,
46 output_num_channels,
47 kParameterNotSpecifiedValue,
48 "Number of forward stream output channels");
49ABSL_FLAG(int,
50 reverse_output_num_channels,
51 kParameterNotSpecifiedValue,
52 "Number of Reverse stream output channels");
53ABSL_FLAG(int,
54 output_sample_rate_hz,
55 kParameterNotSpecifiedValue,
56 "Forward stream output sample rate in Hz");
57ABSL_FLAG(int,
58 reverse_output_sample_rate_hz,
59 kParameterNotSpecifiedValue,
60 "Reverse stream output sample rate in Hz");
61ABSL_FLAG(bool,
62 fixed_interface,
63 false,
64 "Use the fixed interface when operating on wav files");
65ABSL_FLAG(int,
66 aec,
67 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +010068 "Activate (1) or deactivate (0) the echo canceller");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020069ABSL_FLAG(int,
70 aecm,
71 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +010072 "Activate (1) or deactivate (0) the mobile echo controller");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020073ABSL_FLAG(int,
74 ed,
75 kParameterNotSpecifiedValue,
76 "Activate (1) or deactivate (0) the residual echo detector");
77ABSL_FLAG(std::string,
78 ed_graph,
79 "",
80 "Output filename for graph of echo likelihood");
81ABSL_FLAG(int,
82 agc,
83 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +010084 "Activate (1) or deactivate (0) the AGC");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020085ABSL_FLAG(int,
86 agc2,
87 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +010088 "Activate (1) or deactivate (0) the AGC2");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020089ABSL_FLAG(int,
90 pre_amplifier,
91 kParameterNotSpecifiedValue,
Per Åhgrendb5d7282021-03-15 16:31:04 +000092 "Activate (1) or deactivate(0) the pre amplifier");
93ABSL_FLAG(
94 int,
95 capture_level_adjustment,
96 kParameterNotSpecifiedValue,
97 "Activate (1) or deactivate(0) the capture level adjustment functionality");
98ABSL_FLAG(int,
99 analog_mic_gain_emulation,
100 kParameterNotSpecifiedValue,
101 "Activate (1) or deactivate(0) the analog mic gain emulation in the "
102 "production (non-test) code.");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200103ABSL_FLAG(int,
104 hpf,
105 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100106 "Activate (1) or deactivate (0) the high-pass filter");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200107ABSL_FLAG(int,
108 ns,
109 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100110 "Activate (1) or deactivate (0) the noise suppressor");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200111ABSL_FLAG(int,
112 ts,
113 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100114 "Activate (1), deactivate (0) or activate the transient suppressor "
115 "with continuous key events (2)");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200116ABSL_FLAG(int,
Per Åhgren0695df12020-01-13 14:43:13 +0100117 analog_agc,
118 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100119 "Activate (1) or deactivate (0) the analog AGC");
Per Åhgren0695df12020-01-13 14:43:13 +0100120ABSL_FLAG(int,
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200121 vad,
122 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100123 "Activate (1) or deactivate (0) the voice activity detector");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200124ABSL_FLAG(int,
125 le,
126 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100127 "Activate (1) or deactivate (0) the level estimator");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200128ABSL_FLAG(bool,
129 all_default,
130 false,
131 "Activate all of the default components (will be overridden by any "
132 "other settings)");
133ABSL_FLAG(int,
Per Åhgren0695df12020-01-13 14:43:13 +0100134 analog_agc_disable_digital_adaptive,
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200135 kParameterNotSpecifiedValue,
136 "Force-deactivate (1) digital adaptation in "
137 "experimental AGC. Digital adaptation is active by default (0).");
138ABSL_FLAG(int,
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200139 agc_mode,
140 kParameterNotSpecifiedValue,
141 "Specify the AGC mode (0-2)");
142ABSL_FLAG(int,
143 agc_target_level,
144 kParameterNotSpecifiedValue,
145 "Specify the AGC target level (0-31)");
146ABSL_FLAG(int,
147 agc_limiter,
148 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100149 "Activate (1) or deactivate (0) the level estimator");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200150ABSL_FLAG(int,
151 agc_compression_gain,
152 kParameterNotSpecifiedValue,
153 "Specify the AGC compression gain (0-90)");
154ABSL_FLAG(int,
155 agc2_enable_adaptive_gain,
156 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100157 "Activate (1) or deactivate (0) the AGC2 adaptive gain");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200158ABSL_FLAG(float,
159 agc2_fixed_gain_db,
160 kParameterNotSpecifiedValue,
161 "AGC2 fixed gain (dB) to apply");
162ABSL_FLAG(std::string,
163 agc2_adaptive_level_estimator,
164 "RMS",
165 "AGC2 adaptive digital level estimator to use [RMS, peak]");
166ABSL_FLAG(float,
167 pre_amplifier_gain_factor,
168 kParameterNotSpecifiedValue,
169 "Pre-amplifier gain factor (linear) to apply");
Per Åhgrendb5d7282021-03-15 16:31:04 +0000170ABSL_FLAG(float,
171 pre_gain_factor,
172 kParameterNotSpecifiedValue,
173 "Pre-gain factor (linear) to apply in the capture level adjustment");
174ABSL_FLAG(float,
175 post_gain_factor,
176 kParameterNotSpecifiedValue,
177 "Post-gain factor (linear) to apply in the capture level adjustment");
178ABSL_FLAG(float,
179 analog_mic_gain_emulation_initial_level,
180 kParameterNotSpecifiedValue,
181 "Emulated analog mic level to apply initially in the production "
182 "(non-test) code.");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200183ABSL_FLAG(int,
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200184 ns_level,
185 kParameterNotSpecifiedValue,
186 "Specify the NS level (0-3)");
187ABSL_FLAG(int,
Per Åhgren2e8e1c62019-12-20 00:42:22 +0100188 ns_analysis_on_linear_aec_output,
189 kParameterNotSpecifiedValue,
190 "Specifies whether the noise suppression analysis is done on the "
191 "linear AEC output");
192ABSL_FLAG(int,
Per Åhgrenfcbe4072019-09-15 00:27:58 +0200193 maximum_internal_processing_rate,
194 kParameterNotSpecifiedValue,
195 "Set a maximum internal processing rate (32000 or 48000) to override "
196 "the default rate");
197ABSL_FLAG(int,
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200198 stream_delay,
199 kParameterNotSpecifiedValue,
200 "Specify the stream delay in ms to use");
201ABSL_FLAG(int,
202 use_stream_delay,
203 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100204 "Activate (1) or deactivate (0) reporting the stream delay");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200205ABSL_FLAG(int,
206 stream_drift_samples,
207 kParameterNotSpecifiedValue,
208 "Specify the number of stream drift samples to use");
Per Åhgrendb5d7282021-03-15 16:31:04 +0000209ABSL_FLAG(int,
210 initial_mic_level,
211 100,
212 "Initial mic level (0-255) for the analog mic gain simulation in the "
213 "test code");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200214ABSL_FLAG(int,
215 simulate_mic_gain,
216 0,
Per Åhgrendb5d7282021-03-15 16:31:04 +0000217 "Activate (1) or deactivate(0) the analog mic gain simulation in the "
218 "test code");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200219ABSL_FLAG(int,
Per Åhgrene14cb992019-11-27 09:34:22 +0100220 multi_channel_render,
Sam Zackrissonfeee1e42019-09-20 07:50:35 +0200221 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100222 "Activate (1) or deactivate (0) multi-channel render processing in "
Per Åhgrene14cb992019-11-27 09:34:22 +0100223 "APM pipeline");
224ABSL_FLAG(int,
225 multi_channel_capture,
226 kParameterNotSpecifiedValue,
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100227 "Activate (1) or deactivate (0) multi-channel capture processing in "
Per Åhgrene14cb992019-11-27 09:34:22 +0100228 "APM pipeline");
Sam Zackrissonfeee1e42019-09-20 07:50:35 +0200229ABSL_FLAG(int,
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200230 simulated_mic_kind,
231 kParameterNotSpecifiedValue,
232 "Specify which microphone kind to use for microphone simulation");
Per Åhgren34fdc922021-03-10 09:51:52 +0000233ABSL_FLAG(int,
234 frame_for_sending_capture_output_used_false,
235 kParameterNotSpecifiedValue,
236 "Capture frame index for sending a runtime setting for that the "
237 "capture output is not used.");
238ABSL_FLAG(int,
239 frame_for_sending_capture_output_used_true,
240 kParameterNotSpecifiedValue,
241 "Capture frame index for sending a runtime setting for that the "
242 "capture output is used.");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200243ABSL_FLAG(bool, performance_report, false, "Report the APM performance ");
244ABSL_FLAG(std::string,
245 performance_report_output_file,
246 "",
247 "Generate a CSV file with the API call durations");
248ABSL_FLAG(bool, verbose, false, "Produce verbose output");
249ABSL_FLAG(bool,
250 quiet,
251 false,
252 "Avoid producing information about the progress.");
253ABSL_FLAG(bool,
254 bitexactness_report,
255 false,
256 "Report bitexactness for aec dump result reproduction");
257ABSL_FLAG(bool,
258 discard_settings_in_aecdump,
259 false,
260 "Discard any config settings specified in the aec dump");
261ABSL_FLAG(bool,
262 store_intermediate_output,
263 false,
264 "Creates new output files after each init");
265ABSL_FLAG(std::string,
266 custom_call_order_file,
267 "",
268 "Custom process API call order file");
269ABSL_FLAG(std::string,
270 output_custom_call_order_file,
271 "",
272 "Generate custom process API call order file from AEC dump");
273ABSL_FLAG(bool,
274 print_aec_parameter_values,
275 false,
276 "Print parameter values used in AEC in JSON-format");
277ABSL_FLAG(std::string,
278 aec_settings,
279 "",
280 "File in JSON-format with custom AEC settings");
281ABSL_FLAG(bool,
282 dump_data,
283 false,
284 "Dump internal data during the call (requires build flag)");
285ABSL_FLAG(std::string,
286 dump_data_output_dir,
287 "",
288 "Internal data dump output directory");
Per Åhgrenc2ae4c82021-01-20 15:42:13 +0100289ABSL_FLAG(int,
290 dump_set_to_use,
291 kParameterNotSpecifiedValue,
292 "Specifies the dump set to use (if not all the dump sets will "
293 "be used");
Per Åhgren5dca3f12020-01-28 09:08:11 +0100294ABSL_FLAG(bool,
Per Åhgren879d33b2021-01-21 10:08:15 +0100295 analyze,
296 false,
297 "Only analyze the call setup behavior (no processing)");
298ABSL_FLAG(float,
299 dump_start_seconds,
300 kParameterNotSpecifiedValue,
301 "Start of when to dump data (seconds).");
302ABSL_FLAG(float,
303 dump_end_seconds,
304 kParameterNotSpecifiedValue,
305 "End of when to dump data (seconds).");
306ABSL_FLAG(int,
307 dump_start_frame,
308 kParameterNotSpecifiedValue,
309 "Start of when to dump data (frames).");
310ABSL_FLAG(int,
311 dump_end_frame,
312 kParameterNotSpecifiedValue,
313 "End of when to dump data (frames).");
314ABSL_FLAG(int,
315 init_to_process,
316 kParameterNotSpecifiedValue,
317 "Init index to process.");
318
319ABSL_FLAG(bool,
Per Åhgren5dca3f12020-01-28 09:08:11 +0100320 float_wav_output,
321 false,
322 "Produce floating point wav output files.");
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200323
saza0cf99ce2020-04-01 17:42:01 +0200324ABSL_FLAG(std::string,
325 force_fieldtrials,
326 "",
327 "Field trials control experimental feature code which can be forced. "
328 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
329 " will assign the group Enable to field trial WebRTC-FooFeature.");
330
peah60a189f2016-05-24 20:54:40 -0700331namespace webrtc {
332namespace test {
Peter Kasting69558702016-01-12 16:26:35 -0800333namespace {
334
peah60a189f2016-05-24 20:54:40 -0700335const char kUsageDescription[] =
336 "Usage: audioproc_f [options] -i <input.wav>\n"
337 " or\n"
338 " audioproc_f [options] -dump_input <aec_dump>\n"
339 "\n\n"
340 "Command-line tool to simulate a call using the audio "
341 "processing module, either based on wav files or "
oprypin6e09d872017-08-31 03:21:39 -0700342 "protobuf debug dump recordings.\n";
peah60a189f2016-05-24 20:54:40 -0700343
Alessio Bazzica68170382018-11-20 12:27:20 +0100344std::vector<std::string> GetAgc2AdaptiveLevelEstimatorNames() {
345 return {"RMS", "peak"};
346}
peah60a189f2016-05-24 20:54:40 -0700347
Alex Loiko890988c2017-08-31 10:25:48 +0200348void SetSettingIfSpecified(const std::string& value,
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200349 absl::optional<std::string>* parameter) {
peah60a189f2016-05-24 20:54:40 -0700350 if (value.compare("") != 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100351 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700352 }
353}
354
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200355void SetSettingIfSpecified(int value, absl::optional<int>* parameter) {
peah60a189f2016-05-24 20:54:40 -0700356 if (value != kParameterNotSpecifiedValue) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100357 *parameter = value;
peah60a189f2016-05-24 20:54:40 -0700358 }
359}
360
Per Åhgrenef349602019-04-12 16:26:34 +0200361void SetSettingIfSpecified(float value, absl::optional<float>* parameter) {
362 constexpr float kFloatParameterNotSpecifiedValue =
363 kParameterNotSpecifiedValue;
364 if (value != kFloatParameterNotSpecifiedValue) {
365 *parameter = value;
366 }
367}
368
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200369void SetSettingIfFlagSet(int32_t flag, absl::optional<bool>* parameter) {
peah60a189f2016-05-24 20:54:40 -0700370 if (flag == 0) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100371 *parameter = false;
peah60a189f2016-05-24 20:54:40 -0700372 } else if (flag == 1) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100373 *parameter = true;
peah60a189f2016-05-24 20:54:40 -0700374 }
375}
376
Alessio Bazzica68170382018-11-20 12:27:20 +0100377AudioProcessing::Config::GainController2::LevelEstimator
378MapAgc2AdaptiveLevelEstimator(absl::string_view name) {
379 if (name.compare("RMS") == 0) {
380 return AudioProcessing::Config::GainController2::LevelEstimator::kRms;
381 }
382 if (name.compare("peak") == 0) {
383 return AudioProcessing::Config::GainController2::LevelEstimator::kPeak;
384 }
385 auto concat_strings =
386 [](const std::vector<std::string>& strings) -> std::string {
387 rtc::StringBuilder ss;
388 for (const auto& s : strings) {
389 ss << " " << s;
390 }
391 return ss.Release();
392 };
393 RTC_CHECK(false)
394 << "Invalid value for agc2_adaptive_level_estimator, valid options:"
395 << concat_strings(GetAgc2AdaptiveLevelEstimatorNames()) << ".";
396}
397
peah60a189f2016-05-24 20:54:40 -0700398SimulationSettings CreateSettings() {
399 SimulationSettings settings;
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200400 if (absl::GetFlag(FLAGS_all_default)) {
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100401 settings.use_le = true;
402 settings.use_vad = true;
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100403 settings.use_ts = true;
Per Åhgren0695df12020-01-13 14:43:13 +0100404 settings.use_analog_agc = true;
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100405 settings.use_ns = true;
406 settings.use_hpf = true;
407 settings.use_agc = true;
408 settings.use_agc2 = false;
Alex Loiko5feb30e2018-04-16 13:52:32 +0200409 settings.use_pre_amplifier = false;
Oskar Sundbomaa8b67d2017-11-17 14:34:48 +0100410 settings.use_aec = true;
411 settings.use_aecm = false;
412 settings.use_ed = false;
peah60a189f2016-05-24 20:54:40 -0700413 }
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200414 SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_input),
415 &settings.aec_dump_input_filename);
416 SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_output),
417 &settings.aec_dump_output_filename);
418 SetSettingIfSpecified(absl::GetFlag(FLAGS_i), &settings.input_filename);
419 SetSettingIfSpecified(absl::GetFlag(FLAGS_o), &settings.output_filename);
420 SetSettingIfSpecified(absl::GetFlag(FLAGS_ri),
421 &settings.reverse_input_filename);
422 SetSettingIfSpecified(absl::GetFlag(FLAGS_ro),
423 &settings.reverse_output_filename);
424 SetSettingIfSpecified(absl::GetFlag(FLAGS_artificial_nearend),
peahdf80fd12016-12-09 02:43:40 -0800425 &settings.artificial_nearend_filename);
Per Åhgrenc20a19c2019-11-13 11:12:29 +0100426 SetSettingIfSpecified(absl::GetFlag(FLAGS_linear_aec_output),
427 &settings.linear_aec_output_filename);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200428 SetSettingIfSpecified(absl::GetFlag(FLAGS_output_num_channels),
peah60a189f2016-05-24 20:54:40 -0700429 &settings.output_num_channels);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200430 SetSettingIfSpecified(absl::GetFlag(FLAGS_reverse_output_num_channels),
peah60a189f2016-05-24 20:54:40 -0700431 &settings.reverse_output_num_channels);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200432 SetSettingIfSpecified(absl::GetFlag(FLAGS_output_sample_rate_hz),
peah60a189f2016-05-24 20:54:40 -0700433 &settings.output_sample_rate_hz);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200434 SetSettingIfSpecified(absl::GetFlag(FLAGS_reverse_output_sample_rate_hz),
peah60a189f2016-05-24 20:54:40 -0700435 &settings.reverse_output_sample_rate_hz);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200436 SetSettingIfFlagSet(absl::GetFlag(FLAGS_aec), &settings.use_aec);
437 SetSettingIfFlagSet(absl::GetFlag(FLAGS_aecm), &settings.use_aecm);
438 SetSettingIfFlagSet(absl::GetFlag(FLAGS_ed), &settings.use_ed);
439 SetSettingIfSpecified(absl::GetFlag(FLAGS_ed_graph),
440 &settings.ed_graph_output_filename);
441 SetSettingIfFlagSet(absl::GetFlag(FLAGS_agc), &settings.use_agc);
442 SetSettingIfFlagSet(absl::GetFlag(FLAGS_agc2), &settings.use_agc2);
443 SetSettingIfFlagSet(absl::GetFlag(FLAGS_pre_amplifier),
444 &settings.use_pre_amplifier);
Per Åhgrendb5d7282021-03-15 16:31:04 +0000445 SetSettingIfFlagSet(absl::GetFlag(FLAGS_capture_level_adjustment),
446 &settings.use_capture_level_adjustment);
447 SetSettingIfFlagSet(absl::GetFlag(FLAGS_analog_mic_gain_emulation),
448 &settings.use_analog_mic_gain_emulation);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200449 SetSettingIfFlagSet(absl::GetFlag(FLAGS_hpf), &settings.use_hpf);
450 SetSettingIfFlagSet(absl::GetFlag(FLAGS_ns), &settings.use_ns);
Gustaf Ullbergfdd60992021-03-15 14:26:40 +0100451 SetSettingIfSpecified(absl::GetFlag(FLAGS_ts), &settings.use_ts);
Per Åhgren0695df12020-01-13 14:43:13 +0100452 SetSettingIfFlagSet(absl::GetFlag(FLAGS_analog_agc),
453 &settings.use_analog_agc);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200454 SetSettingIfFlagSet(absl::GetFlag(FLAGS_vad), &settings.use_vad);
455 SetSettingIfFlagSet(absl::GetFlag(FLAGS_le), &settings.use_le);
Per Åhgren0695df12020-01-13 14:43:13 +0100456 SetSettingIfFlagSet(absl::GetFlag(FLAGS_analog_agc_disable_digital_adaptive),
457 &settings.analog_agc_disable_digital_adaptive);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200458 SetSettingIfSpecified(absl::GetFlag(FLAGS_agc_mode), &settings.agc_mode);
459 SetSettingIfSpecified(absl::GetFlag(FLAGS_agc_target_level),
460 &settings.agc_target_level);
461 SetSettingIfFlagSet(absl::GetFlag(FLAGS_agc_limiter),
462 &settings.use_agc_limiter);
463 SetSettingIfSpecified(absl::GetFlag(FLAGS_agc_compression_gain),
peah60a189f2016-05-24 20:54:40 -0700464 &settings.agc_compression_gain);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200465 SetSettingIfFlagSet(absl::GetFlag(FLAGS_agc2_enable_adaptive_gain),
Per Åhgrene4d23b12018-10-02 23:40:07 +0200466 &settings.agc2_use_adaptive_gain);
Per Åhgren879d33b2021-01-21 10:08:15 +0100467
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200468 SetSettingIfSpecified(absl::GetFlag(FLAGS_agc2_fixed_gain_db),
469 &settings.agc2_fixed_gain_db);
470 settings.agc2_adaptive_level_estimator = MapAgc2AdaptiveLevelEstimator(
471 absl::GetFlag(FLAGS_agc2_adaptive_level_estimator));
472 SetSettingIfSpecified(absl::GetFlag(FLAGS_pre_amplifier_gain_factor),
Per Åhgrenef349602019-04-12 16:26:34 +0200473 &settings.pre_amplifier_gain_factor);
Per Åhgrendb5d7282021-03-15 16:31:04 +0000474 SetSettingIfSpecified(absl::GetFlag(FLAGS_pre_gain_factor),
475 &settings.pre_gain_factor);
476 SetSettingIfSpecified(absl::GetFlag(FLAGS_post_gain_factor),
477 &settings.post_gain_factor);
478 SetSettingIfSpecified(
479 absl::GetFlag(FLAGS_analog_mic_gain_emulation_initial_level),
480 &settings.analog_mic_gain_emulation_initial_level);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200481 SetSettingIfSpecified(absl::GetFlag(FLAGS_ns_level), &settings.ns_level);
Per Åhgren2e8e1c62019-12-20 00:42:22 +0100482 SetSettingIfFlagSet(absl::GetFlag(FLAGS_ns_analysis_on_linear_aec_output),
483 &settings.ns_analysis_on_linear_aec_output);
Per Åhgrenfcbe4072019-09-15 00:27:58 +0200484 SetSettingIfSpecified(absl::GetFlag(FLAGS_maximum_internal_processing_rate),
485 &settings.maximum_internal_processing_rate);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200486 SetSettingIfSpecified(absl::GetFlag(FLAGS_stream_delay),
487 &settings.stream_delay);
488 SetSettingIfFlagSet(absl::GetFlag(FLAGS_use_stream_delay),
489 &settings.use_stream_delay);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200490 SetSettingIfSpecified(absl::GetFlag(FLAGS_custom_call_order_file),
Ivo Creusen9a66d5e2019-03-13 13:55:12 +0100491 &settings.call_order_input_filename);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200492 SetSettingIfSpecified(absl::GetFlag(FLAGS_output_custom_call_order_file),
Ivo Creusen9a66d5e2019-03-13 13:55:12 +0100493 &settings.call_order_output_filename);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200494 SetSettingIfSpecified(absl::GetFlag(FLAGS_aec_settings),
495 &settings.aec_settings_filename);
496 settings.initial_mic_level = absl::GetFlag(FLAGS_initial_mic_level);
Per Åhgrene14cb992019-11-27 09:34:22 +0100497 SetSettingIfFlagSet(absl::GetFlag(FLAGS_multi_channel_render),
498 &settings.multi_channel_render);
499 SetSettingIfFlagSet(absl::GetFlag(FLAGS_multi_channel_capture),
500 &settings.multi_channel_capture);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200501 settings.simulate_mic_gain = absl::GetFlag(FLAGS_simulate_mic_gain);
502 SetSettingIfSpecified(absl::GetFlag(FLAGS_simulated_mic_kind),
503 &settings.simulated_mic_kind);
Per Åhgren34fdc922021-03-10 09:51:52 +0000504 SetSettingIfSpecified(
505 absl::GetFlag(FLAGS_frame_for_sending_capture_output_used_false),
506 &settings.frame_for_sending_capture_output_used_false);
507 SetSettingIfSpecified(
508 absl::GetFlag(FLAGS_frame_for_sending_capture_output_used_true),
509 &settings.frame_for_sending_capture_output_used_true);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200510 settings.report_performance = absl::GetFlag(FLAGS_performance_report);
511 SetSettingIfSpecified(absl::GetFlag(FLAGS_performance_report_output_file),
Per Åhgrenada9b892019-04-03 16:06:42 +0200512 &settings.performance_report_output_filename);
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200513 settings.use_verbose_logging = absl::GetFlag(FLAGS_verbose);
514 settings.use_quiet_output = absl::GetFlag(FLAGS_quiet);
515 settings.report_bitexactness = absl::GetFlag(FLAGS_bitexactness_report);
516 settings.discard_all_settings_in_aecdump =
517 absl::GetFlag(FLAGS_discard_settings_in_aecdump);
518 settings.fixed_interface = absl::GetFlag(FLAGS_fixed_interface);
519 settings.store_intermediate_output =
520 absl::GetFlag(FLAGS_store_intermediate_output);
521 settings.print_aec_parameter_values =
522 absl::GetFlag(FLAGS_print_aec_parameter_values);
523 settings.dump_internal_data = absl::GetFlag(FLAGS_dump_data);
524 SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_data_output_dir),
Alessio Bazzica4bc60452018-11-20 12:44:15 +0100525 &settings.dump_internal_data_output_dir);
Per Åhgrenc2ae4c82021-01-20 15:42:13 +0100526 SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_set_to_use),
527 &settings.dump_set_to_use);
Per Åhgren5dca3f12020-01-28 09:08:11 +0100528 settings.wav_output_format = absl::GetFlag(FLAGS_float_wav_output)
529 ? WavFile::SampleFormat::kFloat
530 : WavFile::SampleFormat::kInt16;
peah60a189f2016-05-24 20:54:40 -0700531
Per Åhgren879d33b2021-01-21 10:08:15 +0100532 settings.analysis_only = absl::GetFlag(FLAGS_analyze);
533
534 SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_start_frame),
535 &settings.dump_start_frame);
536 SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_end_frame),
537 &settings.dump_end_frame);
538
539 constexpr int kFramesPerSecond = 100;
540 absl::optional<float> start_seconds;
541 SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_start_seconds),
542 &start_seconds);
543 if (start_seconds) {
544 settings.dump_start_frame = *start_seconds * kFramesPerSecond;
545 }
546
547 absl::optional<float> end_seconds;
548 SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_end_seconds), &end_seconds);
549 if (end_seconds) {
550 settings.dump_end_frame = *end_seconds * kFramesPerSecond;
551 }
552
553 SetSettingIfSpecified(absl::GetFlag(FLAGS_init_to_process),
554 &settings.init_to_process);
555
peah60a189f2016-05-24 20:54:40 -0700556 return settings;
557}
558
Alex Loiko890988c2017-08-31 10:25:48 +0200559void ReportConditionalErrorAndExit(bool condition, const std::string& message) {
peah60a189f2016-05-24 20:54:40 -0700560 if (condition) {
561 std::cerr << message << std::endl;
562 exit(1);
563 }
564}
565
Per Åhgrene9cd6172020-05-19 12:52:08 +0200566void PerformBasicParameterSanityChecks(
567 const SimulationSettings& settings,
568 bool pre_constructed_ap_provided,
569 bool pre_constructed_ap_builder_provided) {
peah60a189f2016-05-24 20:54:40 -0700570 if (settings.input_filename || settings.reverse_input_filename) {
Sonia-Florina Horchidanb75d14c2019-08-12 09:57:01 +0200571 ReportConditionalErrorAndExit(
572 !!settings.aec_dump_input_filename,
573 "Error: The aec dump file cannot be specified "
574 "together with input wav files!\n");
575
576 ReportConditionalErrorAndExit(
577 !!settings.aec_dump_input_string,
578 "Error: The aec dump input string cannot be specified "
579 "together with input wav files!\n");
peah60a189f2016-05-24 20:54:40 -0700580
peahdf80fd12016-12-09 02:43:40 -0800581 ReportConditionalErrorAndExit(!!settings.artificial_nearend_filename,
582 "Error: The artificial nearend cannot be "
583 "specified together with input wav files!\n");
584
peah60a189f2016-05-24 20:54:40 -0700585 ReportConditionalErrorAndExit(!settings.input_filename,
586 "Error: When operating at wav files, the "
587 "input wav filename must be "
588 "specified!\n");
589
590 ReportConditionalErrorAndExit(
591 settings.reverse_output_filename && !settings.reverse_input_filename,
592 "Error: When operating at wav files, the reverse input wav filename "
593 "must be specified if the reverse output wav filename is specified!\n");
594 } else {
Sonia-Florina Horchidanb75d14c2019-08-12 09:57:01 +0200595 ReportConditionalErrorAndExit(
596 !settings.aec_dump_input_filename && !settings.aec_dump_input_string,
597 "Error: Either the aec dump input file, the wav "
598 "input file or the aec dump input string must be specified!\n");
599 ReportConditionalErrorAndExit(
600 settings.aec_dump_input_filename && settings.aec_dump_input_string,
601 "Error: The aec dump input file cannot be specified together with the "
602 "aec dump input string!\n");
peah60a189f2016-05-24 20:54:40 -0700603 }
604
Per Åhgrenc20a19c2019-11-13 11:12:29 +0100605 ReportConditionalErrorAndExit(settings.use_aec && !(*settings.use_aec) &&
606 settings.linear_aec_output_filename,
607 "Error: The linear AEC ouput filename cannot "
608 "be specified without the AEC being active");
609
610 ReportConditionalErrorAndExit(
peah60a189f2016-05-24 20:54:40 -0700611 settings.use_aec && *settings.use_aec && settings.use_aecm &&
612 *settings.use_aecm,
613 "Error: The AEC and the AECM cannot be activated at the same time!\n");
614
615 ReportConditionalErrorAndExit(
616 settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0,
617 "Error: --output_sample_rate_hz must be positive!\n");
618
619 ReportConditionalErrorAndExit(
620 settings.reverse_output_sample_rate_hz &&
621 settings.output_sample_rate_hz &&
622 *settings.output_sample_rate_hz <= 0,
623 "Error: --reverse_output_sample_rate_hz must be positive!\n");
624
625 ReportConditionalErrorAndExit(
626 settings.output_num_channels && *settings.output_num_channels <= 0,
627 "Error: --output_num_channels must be positive!\n");
628
629 ReportConditionalErrorAndExit(
630 settings.reverse_output_num_channels &&
631 *settings.reverse_output_num_channels <= 0,
632 "Error: --reverse_output_num_channels must be positive!\n");
633
peah60a189f2016-05-24 20:54:40 -0700634 ReportConditionalErrorAndExit(
peah60a189f2016-05-24 20:54:40 -0700635 settings.agc_target_level && ((*settings.agc_target_level) < 0 ||
636 (*settings.agc_target_level) > 31),
637 "Error: --agc_target_level must be specified between 0 and 31.\n");
638
639 ReportConditionalErrorAndExit(
640 settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 ||
641 (*settings.agc_compression_gain) > 90),
642 "Error: --agc_compression_gain must be specified between 0 and 90.\n");
643
644 ReportConditionalErrorAndExit(
Per Åhgren6ee75fd2019-04-26 11:33:37 +0200645 settings.agc2_fixed_gain_db && ((*settings.agc2_fixed_gain_db) < 0 ||
646 (*settings.agc2_fixed_gain_db) > 90),
Alessio Bazzica270f7b52017-10-13 11:05:17 +0200647 "Error: --agc2_fixed_gain_db must be specified between 0 and 90.\n");
648
649 ReportConditionalErrorAndExit(
peah60a189f2016-05-24 20:54:40 -0700650 settings.ns_level &&
651 ((*settings.ns_level) < 0 || (*settings.ns_level) > 3),
652 "Error: --ns_level must be specified between 0 and 3.\n");
653
654 ReportConditionalErrorAndExit(
655 settings.report_bitexactness && !settings.aec_dump_input_filename,
656 "Error: --bitexactness_report can only be used when operating on an "
657 "aecdump\n");
658
peah5ad5de32016-12-09 03:18:22 -0800659 ReportConditionalErrorAndExit(
Ivo Creusen9a66d5e2019-03-13 13:55:12 +0100660 settings.call_order_input_filename && settings.aec_dump_input_filename,
peah5ad5de32016-12-09 03:18:22 -0800661 "Error: --custom_call_order_file cannot be used when operating on an "
662 "aecdump\n");
663
Alessio Bazzicaca90a552017-09-27 11:51:10 +0200664 ReportConditionalErrorAndExit(
665 (settings.initial_mic_level < 0 || settings.initial_mic_level > 255),
666 "Error: --initial_mic_level must be specified between 0 and 255.\n");
667
668 ReportConditionalErrorAndExit(
669 settings.simulated_mic_kind && !settings.simulate_mic_gain,
670 "Error: --simulated_mic_kind cannot be specified when mic simulation is "
671 "disabled\n");
672
673 ReportConditionalErrorAndExit(
674 !settings.simulated_mic_kind && settings.simulate_mic_gain,
675 "Error: --simulated_mic_kind must be specified when mic simulation is "
676 "enabled\n");
677
peah60a189f2016-05-24 20:54:40 -0700678 auto valid_wav_name = [](const std::string& wav_file_name) {
679 if (wav_file_name.size() < 5) {
680 return false;
681 }
682 if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) ||
683 (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) {
684 return true;
685 }
686 return false;
687 };
688
689 ReportConditionalErrorAndExit(
690 settings.input_filename && (!valid_wav_name(*settings.input_filename)),
691 "Error: --i must be a valid .wav file name.\n");
692
693 ReportConditionalErrorAndExit(
694 settings.output_filename && (!valid_wav_name(*settings.output_filename)),
695 "Error: --o must be a valid .wav file name.\n");
696
697 ReportConditionalErrorAndExit(
698 settings.reverse_input_filename &&
699 (!valid_wav_name(*settings.reverse_input_filename)),
700 "Error: --ri must be a valid .wav file name.\n");
701
702 ReportConditionalErrorAndExit(
703 settings.reverse_output_filename &&
704 (!valid_wav_name(*settings.reverse_output_filename)),
705 "Error: --ro must be a valid .wav file name.\n");
peahdf80fd12016-12-09 02:43:40 -0800706
707 ReportConditionalErrorAndExit(
708 settings.artificial_nearend_filename &&
709 !valid_wav_name(*settings.artificial_nearend_filename),
710 "Error: --artifical_nearend must be a valid .wav file name.\n");
Per Åhgren7a95e0f2018-10-25 09:56:49 +0200711
712 ReportConditionalErrorAndExit(
Per Åhgrenc20a19c2019-11-13 11:12:29 +0100713 settings.linear_aec_output_filename &&
714 (!valid_wav_name(*settings.linear_aec_output_filename)),
715 "Error: --linear_aec_output must be a valid .wav file name.\n");
716
717 ReportConditionalErrorAndExit(
Per Åhgren7a95e0f2018-10-25 09:56:49 +0200718 WEBRTC_APM_DEBUG_DUMP == 0 && settings.dump_internal_data,
719 "Error: --dump_data cannot be set without proper build support.\n");
Alessio Bazzica4bc60452018-11-20 12:44:15 +0100720
Per Åhgren879d33b2021-01-21 10:08:15 +0100721 ReportConditionalErrorAndExit(settings.init_to_process &&
722 *settings.init_to_process != 1 &&
723 !settings.aec_dump_input_filename,
724 "Error: --init_to_process must be set to 1 for "
725 "wav-file based simulations.\n");
726
727 ReportConditionalErrorAndExit(
728 !settings.init_to_process &&
729 (settings.dump_start_frame || settings.dump_end_frame),
730 "Error: --init_to_process must be set when specifying a start and/or end "
731 "frame for when to dump internal data.\n");
732
Alessio Bazzica4bc60452018-11-20 12:44:15 +0100733 ReportConditionalErrorAndExit(
734 !settings.dump_internal_data &&
735 settings.dump_internal_data_output_dir.has_value(),
736 "Error: --dump_data_output_dir cannot be set without --dump_data.\n");
Ivo Creusen9a66d5e2019-03-13 13:55:12 +0100737
738 ReportConditionalErrorAndExit(
739 !settings.aec_dump_input_filename &&
740 settings.call_order_output_filename.has_value(),
741 "Error: --output_custom_call_order_file needs an AEC dump input file.\n");
Per Åhgrenef349602019-04-12 16:26:34 +0200742
743 ReportConditionalErrorAndExit(
744 (!settings.use_pre_amplifier || !(*settings.use_pre_amplifier)) &&
745 settings.pre_amplifier_gain_factor.has_value(),
746 "Error: --pre_amplifier_gain_factor needs --pre_amplifier to be "
747 "specified and set.\n");
Per Åhgrene9cd6172020-05-19 12:52:08 +0200748
749 ReportConditionalErrorAndExit(
750 pre_constructed_ap_provided && pre_constructed_ap_builder_provided,
751 "Error: The AudioProcessing and the AudioProcessingBuilder cannot both "
752 "be specified at the same time.\n");
753
754 ReportConditionalErrorAndExit(
755 settings.aec_settings_filename && pre_constructed_ap_provided,
756 "Error: The aec_settings_filename cannot be specified when a "
757 "pre-constructed audio processing object is provided.\n");
758
759 ReportConditionalErrorAndExit(
760 settings.aec_settings_filename && pre_constructed_ap_provided,
761 "Error: The print_aec_parameter_values cannot be set when a "
762 "pre-constructed audio processing object is provided.\n");
763
764 if (settings.linear_aec_output_filename && pre_constructed_ap_provided) {
765 std::cout << "Warning: For the linear AEC output to be stored, this must "
766 "be configured in the AEC that is part of the provided "
767 "AudioProcessing object."
768 << std::endl;
769 }
Peter Kasting69558702016-01-12 16:26:35 -0800770}
771
Per Åhgrene9cd6172020-05-19 12:52:08 +0200772int RunSimulation(rtc::scoped_refptr<AudioProcessing> audio_processing,
773 std::unique_ptr<AudioProcessingBuilder> ap_builder,
774 int argc,
775 char* argv[],
776 absl::string_view input_aecdump,
777 std::vector<float>* processed_capture_samples) {
Mirko Bonadei2ab97f62019-07-18 13:44:12 +0200778 std::vector<char*> args = absl::ParseCommandLine(argc, argv);
779 if (args.size() != 1) {
oprypin6e09d872017-08-31 03:21:39 -0700780 printf("%s", kUsageDescription);
oprypin6e09d872017-08-31 03:21:39 -0700781 return 1;
782 }
saza0cf99ce2020-04-01 17:42:01 +0200783 // InitFieldTrialsFromString stores the char*, so the char array must
784 // outlive the application.
785 const std::string field_trials = absl::GetFlag(FLAGS_force_fieldtrials);
786 webrtc::field_trial::InitFieldTrialsFromString(field_trials.c_str());
787
peah60a189f2016-05-24 20:54:40 -0700788 SimulationSettings settings = CreateSettings();
Sonia-Florina Horchidanb75d14c2019-08-12 09:57:01 +0200789 if (!input_aecdump.empty()) {
790 settings.aec_dump_input_string = input_aecdump;
791 settings.processed_capture_samples = processed_capture_samples;
792 RTC_CHECK(settings.processed_capture_samples);
793 }
Per Åhgrene9cd6172020-05-19 12:52:08 +0200794 PerformBasicParameterSanityChecks(settings, !!audio_processing, !!ap_builder);
peah60a189f2016-05-24 20:54:40 -0700795 std::unique_ptr<AudioProcessingSimulator> processor;
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000796
Sonia-Florina Horchidanb75d14c2019-08-12 09:57:01 +0200797 if (settings.aec_dump_input_filename || settings.aec_dump_input_string) {
Per Åhgrene9cd6172020-05-19 12:52:08 +0200798 processor.reset(new AecDumpBasedSimulator(
799 settings, std::move(audio_processing), std::move(ap_builder)));
aluebsb0ad43b2015-11-20 00:11:53 -0800800 } else {
Per Åhgrene9cd6172020-05-19 12:52:08 +0200801 processor.reset(new WavBasedSimulator(settings, std::move(audio_processing),
802 std::move(ap_builder)));
andrewbdafe312015-10-29 23:42:54 -0700803 }
804
Per Åhgren879d33b2021-01-21 10:08:15 +0100805 if (settings.analysis_only) {
806 processor->Analyze();
807 } else {
808 processor->Process();
809 }
aluebsb0ad43b2015-11-20 00:11:53 -0800810
peah60a189f2016-05-24 20:54:40 -0700811 if (settings.report_performance) {
Per Åhgrenada9b892019-04-03 16:06:42 +0200812 processor->GetApiCallStatistics().PrintReport();
813 }
814 if (settings.performance_report_output_filename) {
815 processor->GetApiCallStatistics().WriteReportToFile(
816 *settings.performance_report_output_filename);
peah60a189f2016-05-24 20:54:40 -0700817 }
818
819 if (settings.report_bitexactness && settings.aec_dump_input_filename) {
820 if (processor->OutputWasBitexact()) {
821 std::cout << "The processing was bitexact.";
822 } else {
823 std::cout << "The processing was not bitexact.";
824 }
Alejandro Luebs5d22c002015-04-15 11:26:40 -0700825 }
aluebsb0ad43b2015-11-20 00:11:53 -0800826
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000827 return 0;
828}
829
Per Åhgrene9cd6172020-05-19 12:52:08 +0200830} // namespace
831
832int AudioprocFloatImpl(rtc::scoped_refptr<AudioProcessing> audio_processing,
833 int argc,
834 char* argv[]) {
835 return RunSimulation(
836 std::move(audio_processing), /*ap_builder=*/nullptr, argc, argv,
837 /*input_aecdump=*/"", /*processed_capture_samples=*/nullptr);
838}
839
840int AudioprocFloatImpl(std::unique_ptr<AudioProcessingBuilder> ap_builder,
841 int argc,
842 char* argv[],
843 absl::string_view input_aecdump,
844 std::vector<float>* processed_capture_samples) {
845 return RunSimulation(/*audio_processing=*/nullptr, std::move(ap_builder),
846 argc, argv, input_aecdump, processed_capture_samples);
847}
848
peah60a189f2016-05-24 20:54:40 -0700849} // namespace test
andrew@webrtc.org08df9b22014-12-16 20:57:15 +0000850} // namespace webrtc