andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 1 | /* |
| 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 Åhgren | 6ee75fd | 2019-04-26 11:33:37 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/test/audioproc_float_impl.h" |
| 12 | |
Ivo Creusen | 2cb4105 | 2018-03-15 12:22:52 +0100 | [diff] [blame] | 13 | #include <string.h> |
| 14 | |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 15 | #include <iostream> |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 16 | #include <memory> |
Ivo Creusen | 2cb4105 | 2018-03-15 12:22:52 +0100 | [diff] [blame] | 17 | #include <string> |
| 18 | #include <utility> |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 19 | #include <vector> |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 20 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 21 | #include "absl/flags/flag.h" |
| 22 | #include "absl/flags/parse.h" |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 23 | #include "absl/strings/string_view.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #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 Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 28 | #include "rtc_base/checks.h" |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 29 | #include "rtc_base/strings/string_builder.h" |
saza | 0cf99ce | 2020-04-01 17:42:01 +0200 | [diff] [blame] | 30 | #include "system_wrappers/include/field_trial.h" |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 31 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 32 | constexpr int kParameterNotSpecifiedValue = -10000; |
| 33 | |
| 34 | ABSL_FLAG(std::string, dump_input, "", "Aec dump input filename"); |
| 35 | ABSL_FLAG(std::string, dump_output, "", "Aec dump output filename"); |
| 36 | ABSL_FLAG(std::string, i, "", "Forward stream input wav filename"); |
| 37 | ABSL_FLAG(std::string, o, "", "Forward stream output wav filename"); |
| 38 | ABSL_FLAG(std::string, ri, "", "Reverse stream input wav filename"); |
| 39 | ABSL_FLAG(std::string, ro, "", "Reverse stream output wav filename"); |
| 40 | ABSL_FLAG(std::string, |
| 41 | artificial_nearend, |
| 42 | "", |
| 43 | "Artificial nearend wav filename"); |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 44 | ABSL_FLAG(std::string, linear_aec_output, "", "Linear AEC output wav filename"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 45 | ABSL_FLAG(int, |
| 46 | output_num_channels, |
| 47 | kParameterNotSpecifiedValue, |
| 48 | "Number of forward stream output channels"); |
| 49 | ABSL_FLAG(int, |
| 50 | reverse_output_num_channels, |
| 51 | kParameterNotSpecifiedValue, |
| 52 | "Number of Reverse stream output channels"); |
| 53 | ABSL_FLAG(int, |
| 54 | output_sample_rate_hz, |
| 55 | kParameterNotSpecifiedValue, |
| 56 | "Forward stream output sample rate in Hz"); |
| 57 | ABSL_FLAG(int, |
| 58 | reverse_output_sample_rate_hz, |
| 59 | kParameterNotSpecifiedValue, |
| 60 | "Reverse stream output sample rate in Hz"); |
| 61 | ABSL_FLAG(bool, |
| 62 | fixed_interface, |
| 63 | false, |
| 64 | "Use the fixed interface when operating on wav files"); |
| 65 | ABSL_FLAG(int, |
| 66 | aec, |
| 67 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 68 | "Activate (1) or deactivate (0) the echo canceller"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 69 | ABSL_FLAG(int, |
| 70 | aecm, |
| 71 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 72 | "Activate (1) or deactivate (0) the mobile echo controller"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 73 | ABSL_FLAG(int, |
| 74 | ed, |
| 75 | kParameterNotSpecifiedValue, |
| 76 | "Activate (1) or deactivate (0) the residual echo detector"); |
| 77 | ABSL_FLAG(std::string, |
| 78 | ed_graph, |
| 79 | "", |
| 80 | "Output filename for graph of echo likelihood"); |
| 81 | ABSL_FLAG(int, |
| 82 | agc, |
| 83 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 84 | "Activate (1) or deactivate (0) the AGC"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 85 | ABSL_FLAG(int, |
| 86 | agc2, |
| 87 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 88 | "Activate (1) or deactivate (0) the AGC2"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 89 | ABSL_FLAG(int, |
| 90 | pre_amplifier, |
| 91 | kParameterNotSpecifiedValue, |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 92 | "Activate (1) or deactivate(0) the pre amplifier"); |
| 93 | ABSL_FLAG( |
| 94 | int, |
| 95 | capture_level_adjustment, |
| 96 | kParameterNotSpecifiedValue, |
| 97 | "Activate (1) or deactivate(0) the capture level adjustment functionality"); |
| 98 | ABSL_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 Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 103 | ABSL_FLAG(int, |
| 104 | hpf, |
| 105 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 106 | "Activate (1) or deactivate (0) the high-pass filter"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 107 | ABSL_FLAG(int, |
| 108 | ns, |
| 109 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 110 | "Activate (1) or deactivate (0) the noise suppressor"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 111 | ABSL_FLAG(int, |
| 112 | ts, |
| 113 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 114 | "Activate (1), deactivate (0) or activate the transient suppressor " |
| 115 | "with continuous key events (2)"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 116 | ABSL_FLAG(int, |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 117 | analog_agc, |
| 118 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 119 | "Activate (1) or deactivate (0) the analog AGC"); |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 120 | ABSL_FLAG(int, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 121 | vad, |
| 122 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 123 | "Activate (1) or deactivate (0) the voice activity detector"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 124 | ABSL_FLAG(int, |
| 125 | le, |
| 126 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 127 | "Activate (1) or deactivate (0) the level estimator"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 128 | ABSL_FLAG(bool, |
| 129 | all_default, |
| 130 | false, |
| 131 | "Activate all of the default components (will be overridden by any " |
| 132 | "other settings)"); |
| 133 | ABSL_FLAG(int, |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 134 | analog_agc_disable_digital_adaptive, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 135 | kParameterNotSpecifiedValue, |
| 136 | "Force-deactivate (1) digital adaptation in " |
| 137 | "experimental AGC. Digital adaptation is active by default (0)."); |
| 138 | ABSL_FLAG(int, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 139 | agc_mode, |
| 140 | kParameterNotSpecifiedValue, |
| 141 | "Specify the AGC mode (0-2)"); |
| 142 | ABSL_FLAG(int, |
| 143 | agc_target_level, |
| 144 | kParameterNotSpecifiedValue, |
| 145 | "Specify the AGC target level (0-31)"); |
| 146 | ABSL_FLAG(int, |
| 147 | agc_limiter, |
| 148 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 149 | "Activate (1) or deactivate (0) the level estimator"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 150 | ABSL_FLAG(int, |
| 151 | agc_compression_gain, |
| 152 | kParameterNotSpecifiedValue, |
| 153 | "Specify the AGC compression gain (0-90)"); |
| 154 | ABSL_FLAG(int, |
| 155 | agc2_enable_adaptive_gain, |
| 156 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 157 | "Activate (1) or deactivate (0) the AGC2 adaptive gain"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 158 | ABSL_FLAG(float, |
| 159 | agc2_fixed_gain_db, |
| 160 | kParameterNotSpecifiedValue, |
| 161 | "AGC2 fixed gain (dB) to apply"); |
| 162 | ABSL_FLAG(std::string, |
| 163 | agc2_adaptive_level_estimator, |
| 164 | "RMS", |
| 165 | "AGC2 adaptive digital level estimator to use [RMS, peak]"); |
| 166 | ABSL_FLAG(float, |
| 167 | pre_amplifier_gain_factor, |
| 168 | kParameterNotSpecifiedValue, |
| 169 | "Pre-amplifier gain factor (linear) to apply"); |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 170 | ABSL_FLAG(float, |
| 171 | pre_gain_factor, |
| 172 | kParameterNotSpecifiedValue, |
| 173 | "Pre-gain factor (linear) to apply in the capture level adjustment"); |
| 174 | ABSL_FLAG(float, |
| 175 | post_gain_factor, |
| 176 | kParameterNotSpecifiedValue, |
| 177 | "Post-gain factor (linear) to apply in the capture level adjustment"); |
| 178 | ABSL_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 Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 183 | ABSL_FLAG(int, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 184 | ns_level, |
| 185 | kParameterNotSpecifiedValue, |
| 186 | "Specify the NS level (0-3)"); |
| 187 | ABSL_FLAG(int, |
Per Åhgren | 2e8e1c6 | 2019-12-20 00:42:22 +0100 | [diff] [blame] | 188 | ns_analysis_on_linear_aec_output, |
| 189 | kParameterNotSpecifiedValue, |
| 190 | "Specifies whether the noise suppression analysis is done on the " |
| 191 | "linear AEC output"); |
| 192 | ABSL_FLAG(int, |
Per Åhgren | fcbe407 | 2019-09-15 00:27:58 +0200 | [diff] [blame] | 193 | maximum_internal_processing_rate, |
| 194 | kParameterNotSpecifiedValue, |
| 195 | "Set a maximum internal processing rate (32000 or 48000) to override " |
| 196 | "the default rate"); |
| 197 | ABSL_FLAG(int, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 198 | stream_delay, |
| 199 | kParameterNotSpecifiedValue, |
| 200 | "Specify the stream delay in ms to use"); |
| 201 | ABSL_FLAG(int, |
| 202 | use_stream_delay, |
| 203 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 204 | "Activate (1) or deactivate (0) reporting the stream delay"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 205 | ABSL_FLAG(int, |
| 206 | stream_drift_samples, |
| 207 | kParameterNotSpecifiedValue, |
| 208 | "Specify the number of stream drift samples to use"); |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 209 | ABSL_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 Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 214 | ABSL_FLAG(int, |
| 215 | simulate_mic_gain, |
| 216 | 0, |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 217 | "Activate (1) or deactivate(0) the analog mic gain simulation in the " |
| 218 | "test code"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 219 | ABSL_FLAG(int, |
Per Åhgren | e14cb99 | 2019-11-27 09:34:22 +0100 | [diff] [blame] | 220 | multi_channel_render, |
Sam Zackrisson | feee1e4 | 2019-09-20 07:50:35 +0200 | [diff] [blame] | 221 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 222 | "Activate (1) or deactivate (0) multi-channel render processing in " |
Per Åhgren | e14cb99 | 2019-11-27 09:34:22 +0100 | [diff] [blame] | 223 | "APM pipeline"); |
| 224 | ABSL_FLAG(int, |
| 225 | multi_channel_capture, |
| 226 | kParameterNotSpecifiedValue, |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 227 | "Activate (1) or deactivate (0) multi-channel capture processing in " |
Per Åhgren | e14cb99 | 2019-11-27 09:34:22 +0100 | [diff] [blame] | 228 | "APM pipeline"); |
Sam Zackrisson | feee1e4 | 2019-09-20 07:50:35 +0200 | [diff] [blame] | 229 | ABSL_FLAG(int, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 230 | simulated_mic_kind, |
| 231 | kParameterNotSpecifiedValue, |
| 232 | "Specify which microphone kind to use for microphone simulation"); |
Per Åhgren | 34fdc92 | 2021-03-10 09:51:52 +0000 | [diff] [blame] | 233 | ABSL_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."); |
| 238 | ABSL_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 Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 243 | ABSL_FLAG(bool, performance_report, false, "Report the APM performance "); |
| 244 | ABSL_FLAG(std::string, |
| 245 | performance_report_output_file, |
| 246 | "", |
| 247 | "Generate a CSV file with the API call durations"); |
| 248 | ABSL_FLAG(bool, verbose, false, "Produce verbose output"); |
| 249 | ABSL_FLAG(bool, |
| 250 | quiet, |
| 251 | false, |
| 252 | "Avoid producing information about the progress."); |
| 253 | ABSL_FLAG(bool, |
| 254 | bitexactness_report, |
| 255 | false, |
| 256 | "Report bitexactness for aec dump result reproduction"); |
| 257 | ABSL_FLAG(bool, |
| 258 | discard_settings_in_aecdump, |
| 259 | false, |
| 260 | "Discard any config settings specified in the aec dump"); |
| 261 | ABSL_FLAG(bool, |
| 262 | store_intermediate_output, |
| 263 | false, |
| 264 | "Creates new output files after each init"); |
| 265 | ABSL_FLAG(std::string, |
| 266 | custom_call_order_file, |
| 267 | "", |
| 268 | "Custom process API call order file"); |
| 269 | ABSL_FLAG(std::string, |
| 270 | output_custom_call_order_file, |
| 271 | "", |
| 272 | "Generate custom process API call order file from AEC dump"); |
| 273 | ABSL_FLAG(bool, |
| 274 | print_aec_parameter_values, |
| 275 | false, |
| 276 | "Print parameter values used in AEC in JSON-format"); |
| 277 | ABSL_FLAG(std::string, |
| 278 | aec_settings, |
| 279 | "", |
| 280 | "File in JSON-format with custom AEC settings"); |
| 281 | ABSL_FLAG(bool, |
| 282 | dump_data, |
| 283 | false, |
| 284 | "Dump internal data during the call (requires build flag)"); |
| 285 | ABSL_FLAG(std::string, |
| 286 | dump_data_output_dir, |
| 287 | "", |
| 288 | "Internal data dump output directory"); |
Per Åhgren | c2ae4c8 | 2021-01-20 15:42:13 +0100 | [diff] [blame] | 289 | ABSL_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 Åhgren | 5dca3f1 | 2020-01-28 09:08:11 +0100 | [diff] [blame] | 294 | ABSL_FLAG(bool, |
Per Åhgren | 879d33b | 2021-01-21 10:08:15 +0100 | [diff] [blame] | 295 | analyze, |
| 296 | false, |
| 297 | "Only analyze the call setup behavior (no processing)"); |
| 298 | ABSL_FLAG(float, |
| 299 | dump_start_seconds, |
| 300 | kParameterNotSpecifiedValue, |
| 301 | "Start of when to dump data (seconds)."); |
| 302 | ABSL_FLAG(float, |
| 303 | dump_end_seconds, |
| 304 | kParameterNotSpecifiedValue, |
| 305 | "End of when to dump data (seconds)."); |
| 306 | ABSL_FLAG(int, |
| 307 | dump_start_frame, |
| 308 | kParameterNotSpecifiedValue, |
| 309 | "Start of when to dump data (frames)."); |
| 310 | ABSL_FLAG(int, |
| 311 | dump_end_frame, |
| 312 | kParameterNotSpecifiedValue, |
| 313 | "End of when to dump data (frames)."); |
| 314 | ABSL_FLAG(int, |
| 315 | init_to_process, |
| 316 | kParameterNotSpecifiedValue, |
| 317 | "Init index to process."); |
| 318 | |
| 319 | ABSL_FLAG(bool, |
Per Åhgren | 5dca3f1 | 2020-01-28 09:08:11 +0100 | [diff] [blame] | 320 | float_wav_output, |
| 321 | false, |
| 322 | "Produce floating point wav output files."); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 323 | |
saza | 0cf99ce | 2020-04-01 17:42:01 +0200 | [diff] [blame] | 324 | ABSL_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 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 331 | namespace webrtc { |
| 332 | namespace test { |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 333 | namespace { |
| 334 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 335 | const 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 " |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 342 | "protobuf debug dump recordings.\n"; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 343 | |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 344 | std::vector<std::string> GetAgc2AdaptiveLevelEstimatorNames() { |
| 345 | return {"RMS", "peak"}; |
| 346 | } |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 347 | |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 348 | void SetSettingIfSpecified(const std::string& value, |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 349 | absl::optional<std::string>* parameter) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 350 | if (value.compare("") != 0) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 351 | *parameter = value; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 355 | void SetSettingIfSpecified(int value, absl::optional<int>* parameter) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 356 | if (value != kParameterNotSpecifiedValue) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 357 | *parameter = value; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
Per Åhgren | ef34960 | 2019-04-12 16:26:34 +0200 | [diff] [blame] | 361 | void SetSettingIfSpecified(float value, absl::optional<float>* parameter) { |
| 362 | constexpr float kFloatParameterNotSpecifiedValue = |
| 363 | kParameterNotSpecifiedValue; |
| 364 | if (value != kFloatParameterNotSpecifiedValue) { |
| 365 | *parameter = value; |
| 366 | } |
| 367 | } |
| 368 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 369 | void SetSettingIfFlagSet(int32_t flag, absl::optional<bool>* parameter) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 370 | if (flag == 0) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 371 | *parameter = false; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 372 | } else if (flag == 1) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 373 | *parameter = true; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 377 | AudioProcessing::Config::GainController2::LevelEstimator |
| 378 | MapAgc2AdaptiveLevelEstimator(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 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 398 | SimulationSettings CreateSettings() { |
| 399 | SimulationSettings settings; |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 400 | if (absl::GetFlag(FLAGS_all_default)) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 401 | settings.use_le = true; |
| 402 | settings.use_vad = true; |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 403 | settings.use_ts = true; |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 404 | settings.use_analog_agc = true; |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 405 | settings.use_ns = true; |
| 406 | settings.use_hpf = true; |
| 407 | settings.use_agc = true; |
| 408 | settings.use_agc2 = false; |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 409 | settings.use_pre_amplifier = false; |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 410 | settings.use_aec = true; |
| 411 | settings.use_aecm = false; |
| 412 | settings.use_ed = false; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 413 | } |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 414 | 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), |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame] | 425 | &settings.artificial_nearend_filename); |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 426 | SetSettingIfSpecified(absl::GetFlag(FLAGS_linear_aec_output), |
| 427 | &settings.linear_aec_output_filename); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 428 | SetSettingIfSpecified(absl::GetFlag(FLAGS_output_num_channels), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 429 | &settings.output_num_channels); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 430 | SetSettingIfSpecified(absl::GetFlag(FLAGS_reverse_output_num_channels), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 431 | &settings.reverse_output_num_channels); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 432 | SetSettingIfSpecified(absl::GetFlag(FLAGS_output_sample_rate_hz), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 433 | &settings.output_sample_rate_hz); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 434 | SetSettingIfSpecified(absl::GetFlag(FLAGS_reverse_output_sample_rate_hz), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 435 | &settings.reverse_output_sample_rate_hz); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 436 | 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 Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 445 | 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 Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 449 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_hpf), &settings.use_hpf); |
| 450 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_ns), &settings.use_ns); |
Gustaf Ullberg | fdd6099 | 2021-03-15 14:26:40 +0100 | [diff] [blame] | 451 | SetSettingIfSpecified(absl::GetFlag(FLAGS_ts), &settings.use_ts); |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 452 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_analog_agc), |
| 453 | &settings.use_analog_agc); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 454 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_vad), &settings.use_vad); |
| 455 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_le), &settings.use_le); |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 456 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_analog_agc_disable_digital_adaptive), |
| 457 | &settings.analog_agc_disable_digital_adaptive); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 458 | 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), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 464 | &settings.agc_compression_gain); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 465 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_agc2_enable_adaptive_gain), |
Per Åhgren | e4d23b1 | 2018-10-02 23:40:07 +0200 | [diff] [blame] | 466 | &settings.agc2_use_adaptive_gain); |
Per Åhgren | 879d33b | 2021-01-21 10:08:15 +0100 | [diff] [blame] | 467 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 468 | 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 Åhgren | ef34960 | 2019-04-12 16:26:34 +0200 | [diff] [blame] | 473 | &settings.pre_amplifier_gain_factor); |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 474 | 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 Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 481 | SetSettingIfSpecified(absl::GetFlag(FLAGS_ns_level), &settings.ns_level); |
Per Åhgren | 2e8e1c6 | 2019-12-20 00:42:22 +0100 | [diff] [blame] | 482 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_ns_analysis_on_linear_aec_output), |
| 483 | &settings.ns_analysis_on_linear_aec_output); |
Per Åhgren | fcbe407 | 2019-09-15 00:27:58 +0200 | [diff] [blame] | 484 | SetSettingIfSpecified(absl::GetFlag(FLAGS_maximum_internal_processing_rate), |
| 485 | &settings.maximum_internal_processing_rate); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 486 | SetSettingIfSpecified(absl::GetFlag(FLAGS_stream_delay), |
| 487 | &settings.stream_delay); |
| 488 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_use_stream_delay), |
| 489 | &settings.use_stream_delay); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 490 | SetSettingIfSpecified(absl::GetFlag(FLAGS_custom_call_order_file), |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 491 | &settings.call_order_input_filename); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 492 | SetSettingIfSpecified(absl::GetFlag(FLAGS_output_custom_call_order_file), |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 493 | &settings.call_order_output_filename); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 494 | SetSettingIfSpecified(absl::GetFlag(FLAGS_aec_settings), |
| 495 | &settings.aec_settings_filename); |
| 496 | settings.initial_mic_level = absl::GetFlag(FLAGS_initial_mic_level); |
Per Åhgren | e14cb99 | 2019-11-27 09:34:22 +0100 | [diff] [blame] | 497 | 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 Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 501 | settings.simulate_mic_gain = absl::GetFlag(FLAGS_simulate_mic_gain); |
| 502 | SetSettingIfSpecified(absl::GetFlag(FLAGS_simulated_mic_kind), |
| 503 | &settings.simulated_mic_kind); |
Per Åhgren | 34fdc92 | 2021-03-10 09:51:52 +0000 | [diff] [blame] | 504 | 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 Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 510 | settings.report_performance = absl::GetFlag(FLAGS_performance_report); |
| 511 | SetSettingIfSpecified(absl::GetFlag(FLAGS_performance_report_output_file), |
Per Åhgren | ada9b89 | 2019-04-03 16:06:42 +0200 | [diff] [blame] | 512 | &settings.performance_report_output_filename); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 513 | 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 Bazzica | 4bc6045 | 2018-11-20 12:44:15 +0100 | [diff] [blame] | 525 | &settings.dump_internal_data_output_dir); |
Per Åhgren | c2ae4c8 | 2021-01-20 15:42:13 +0100 | [diff] [blame] | 526 | SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_set_to_use), |
| 527 | &settings.dump_set_to_use); |
Per Åhgren | 5dca3f1 | 2020-01-28 09:08:11 +0100 | [diff] [blame] | 528 | settings.wav_output_format = absl::GetFlag(FLAGS_float_wav_output) |
| 529 | ? WavFile::SampleFormat::kFloat |
| 530 | : WavFile::SampleFormat::kInt16; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 531 | |
Per Åhgren | 879d33b | 2021-01-21 10:08:15 +0100 | [diff] [blame] | 532 | 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 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 556 | return settings; |
| 557 | } |
| 558 | |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 559 | void ReportConditionalErrorAndExit(bool condition, const std::string& message) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 560 | if (condition) { |
| 561 | std::cerr << message << std::endl; |
| 562 | exit(1); |
| 563 | } |
| 564 | } |
| 565 | |
Per Åhgren | e9cd617 | 2020-05-19 12:52:08 +0200 | [diff] [blame] | 566 | void PerformBasicParameterSanityChecks( |
| 567 | const SimulationSettings& settings, |
| 568 | bool pre_constructed_ap_provided, |
| 569 | bool pre_constructed_ap_builder_provided) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 570 | if (settings.input_filename || settings.reverse_input_filename) { |
Sonia-Florina Horchidan | b75d14c | 2019-08-12 09:57:01 +0200 | [diff] [blame] | 571 | 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"); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 580 | |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame] | 581 | ReportConditionalErrorAndExit(!!settings.artificial_nearend_filename, |
| 582 | "Error: The artificial nearend cannot be " |
| 583 | "specified together with input wav files!\n"); |
| 584 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 585 | 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 Horchidan | b75d14c | 2019-08-12 09:57:01 +0200 | [diff] [blame] | 595 | 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"); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 605 | 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( |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 611 | 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 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 634 | ReportConditionalErrorAndExit( |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 635 | 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 Åhgren | 6ee75fd | 2019-04-26 11:33:37 +0200 | [diff] [blame] | 645 | settings.agc2_fixed_gain_db && ((*settings.agc2_fixed_gain_db) < 0 || |
| 646 | (*settings.agc2_fixed_gain_db) > 90), |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 647 | "Error: --agc2_fixed_gain_db must be specified between 0 and 90.\n"); |
| 648 | |
| 649 | ReportConditionalErrorAndExit( |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 650 | 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 | |
peah | 5ad5de3 | 2016-12-09 03:18:22 -0800 | [diff] [blame] | 659 | ReportConditionalErrorAndExit( |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 660 | settings.call_order_input_filename && settings.aec_dump_input_filename, |
peah | 5ad5de3 | 2016-12-09 03:18:22 -0800 | [diff] [blame] | 661 | "Error: --custom_call_order_file cannot be used when operating on an " |
| 662 | "aecdump\n"); |
| 663 | |
Alessio Bazzica | ca90a55 | 2017-09-27 11:51:10 +0200 | [diff] [blame] | 664 | 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 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 678 | 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"); |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame] | 706 | |
| 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 Åhgren | 7a95e0f | 2018-10-25 09:56:49 +0200 | [diff] [blame] | 711 | |
| 712 | ReportConditionalErrorAndExit( |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 713 | 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 Åhgren | 7a95e0f | 2018-10-25 09:56:49 +0200 | [diff] [blame] | 718 | WEBRTC_APM_DEBUG_DUMP == 0 && settings.dump_internal_data, |
| 719 | "Error: --dump_data cannot be set without proper build support.\n"); |
Alessio Bazzica | 4bc6045 | 2018-11-20 12:44:15 +0100 | [diff] [blame] | 720 | |
Per Åhgren | 879d33b | 2021-01-21 10:08:15 +0100 | [diff] [blame] | 721 | 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 Bazzica | 4bc6045 | 2018-11-20 12:44:15 +0100 | [diff] [blame] | 733 | 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 Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 737 | |
| 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 Åhgren | ef34960 | 2019-04-12 16:26:34 +0200 | [diff] [blame] | 742 | |
| 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 Åhgren | e9cd617 | 2020-05-19 12:52:08 +0200 | [diff] [blame] | 748 | |
| 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 Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 770 | } |
| 771 | |
Per Åhgren | e9cd617 | 2020-05-19 12:52:08 +0200 | [diff] [blame] | 772 | int 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 Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 778 | std::vector<char*> args = absl::ParseCommandLine(argc, argv); |
| 779 | if (args.size() != 1) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 780 | printf("%s", kUsageDescription); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 781 | return 1; |
| 782 | } |
saza | 0cf99ce | 2020-04-01 17:42:01 +0200 | [diff] [blame] | 783 | // 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 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 788 | SimulationSettings settings = CreateSettings(); |
Sonia-Florina Horchidan | b75d14c | 2019-08-12 09:57:01 +0200 | [diff] [blame] | 789 | 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 Åhgren | e9cd617 | 2020-05-19 12:52:08 +0200 | [diff] [blame] | 794 | PerformBasicParameterSanityChecks(settings, !!audio_processing, !!ap_builder); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 795 | std::unique_ptr<AudioProcessingSimulator> processor; |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 796 | |
Sonia-Florina Horchidan | b75d14c | 2019-08-12 09:57:01 +0200 | [diff] [blame] | 797 | if (settings.aec_dump_input_filename || settings.aec_dump_input_string) { |
Per Åhgren | e9cd617 | 2020-05-19 12:52:08 +0200 | [diff] [blame] | 798 | processor.reset(new AecDumpBasedSimulator( |
| 799 | settings, std::move(audio_processing), std::move(ap_builder))); |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 800 | } else { |
Per Åhgren | e9cd617 | 2020-05-19 12:52:08 +0200 | [diff] [blame] | 801 | processor.reset(new WavBasedSimulator(settings, std::move(audio_processing), |
| 802 | std::move(ap_builder))); |
andrew | bdafe31 | 2015-10-29 23:42:54 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Per Åhgren | 879d33b | 2021-01-21 10:08:15 +0100 | [diff] [blame] | 805 | if (settings.analysis_only) { |
| 806 | processor->Analyze(); |
| 807 | } else { |
| 808 | processor->Process(); |
| 809 | } |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 810 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 811 | if (settings.report_performance) { |
Per Åhgren | ada9b89 | 2019-04-03 16:06:42 +0200 | [diff] [blame] | 812 | processor->GetApiCallStatistics().PrintReport(); |
| 813 | } |
| 814 | if (settings.performance_report_output_filename) { |
| 815 | processor->GetApiCallStatistics().WriteReportToFile( |
| 816 | *settings.performance_report_output_filename); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 817 | } |
| 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 Luebs | 5d22c00 | 2015-04-15 11:26:40 -0700 | [diff] [blame] | 825 | } |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 826 | |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 827 | return 0; |
| 828 | } |
| 829 | |
Per Åhgren | e9cd617 | 2020-05-19 12:52:08 +0200 | [diff] [blame] | 830 | } // namespace |
| 831 | |
| 832 | int 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 | |
| 840 | int 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 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 849 | } // namespace test |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 850 | } // namespace webrtc |