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" |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 30 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 31 | constexpr int kParameterNotSpecifiedValue = -10000; |
| 32 | |
| 33 | ABSL_FLAG(std::string, dump_input, "", "Aec dump input filename"); |
| 34 | ABSL_FLAG(std::string, dump_output, "", "Aec dump output filename"); |
| 35 | ABSL_FLAG(std::string, i, "", "Forward stream input wav filename"); |
| 36 | ABSL_FLAG(std::string, o, "", "Forward stream output wav filename"); |
| 37 | ABSL_FLAG(std::string, ri, "", "Reverse stream input wav filename"); |
| 38 | ABSL_FLAG(std::string, ro, "", "Reverse stream output wav filename"); |
| 39 | ABSL_FLAG(std::string, |
| 40 | artificial_nearend, |
| 41 | "", |
| 42 | "Artificial nearend wav filename"); |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame^] | 43 | ABSL_FLAG(std::string, linear_aec_output, "", "Linear AEC output wav filename"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 44 | ABSL_FLAG(int, |
| 45 | output_num_channels, |
| 46 | kParameterNotSpecifiedValue, |
| 47 | "Number of forward stream output channels"); |
| 48 | ABSL_FLAG(int, |
| 49 | reverse_output_num_channels, |
| 50 | kParameterNotSpecifiedValue, |
| 51 | "Number of Reverse stream output channels"); |
| 52 | ABSL_FLAG(int, |
| 53 | output_sample_rate_hz, |
| 54 | kParameterNotSpecifiedValue, |
| 55 | "Forward stream output sample rate in Hz"); |
| 56 | ABSL_FLAG(int, |
| 57 | reverse_output_sample_rate_hz, |
| 58 | kParameterNotSpecifiedValue, |
| 59 | "Reverse stream output sample rate in Hz"); |
| 60 | ABSL_FLAG(bool, |
| 61 | fixed_interface, |
| 62 | false, |
| 63 | "Use the fixed interface when operating on wav files"); |
| 64 | ABSL_FLAG(int, |
| 65 | aec, |
| 66 | kParameterNotSpecifiedValue, |
| 67 | "Activate (1) or deactivate(0) the echo canceller"); |
| 68 | ABSL_FLAG(int, |
| 69 | aecm, |
| 70 | kParameterNotSpecifiedValue, |
| 71 | "Activate (1) or deactivate(0) the mobile echo controller"); |
| 72 | ABSL_FLAG(int, |
| 73 | ed, |
| 74 | kParameterNotSpecifiedValue, |
| 75 | "Activate (1) or deactivate (0) the residual echo detector"); |
| 76 | ABSL_FLAG(std::string, |
| 77 | ed_graph, |
| 78 | "", |
| 79 | "Output filename for graph of echo likelihood"); |
| 80 | ABSL_FLAG(int, |
| 81 | agc, |
| 82 | kParameterNotSpecifiedValue, |
| 83 | "Activate (1) or deactivate(0) the AGC"); |
| 84 | ABSL_FLAG(int, |
| 85 | agc2, |
| 86 | kParameterNotSpecifiedValue, |
| 87 | "Activate (1) or deactivate(0) the AGC2"); |
| 88 | ABSL_FLAG(int, |
| 89 | pre_amplifier, |
| 90 | kParameterNotSpecifiedValue, |
| 91 | "Activate (1) or deactivate(0) the pre amplifier"); |
| 92 | ABSL_FLAG(int, |
| 93 | hpf, |
| 94 | kParameterNotSpecifiedValue, |
| 95 | "Activate (1) or deactivate(0) the high-pass filter"); |
| 96 | ABSL_FLAG(int, |
| 97 | ns, |
| 98 | kParameterNotSpecifiedValue, |
| 99 | "Activate (1) or deactivate(0) the noise suppressor"); |
| 100 | ABSL_FLAG(int, |
| 101 | ts, |
| 102 | kParameterNotSpecifiedValue, |
| 103 | "Activate (1) or deactivate(0) the transient suppressor"); |
| 104 | ABSL_FLAG(int, |
| 105 | vad, |
| 106 | kParameterNotSpecifiedValue, |
| 107 | "Activate (1) or deactivate(0) the voice activity detector"); |
| 108 | ABSL_FLAG(int, |
| 109 | le, |
| 110 | kParameterNotSpecifiedValue, |
| 111 | "Activate (1) or deactivate(0) the level estimator"); |
| 112 | ABSL_FLAG(bool, |
| 113 | all_default, |
| 114 | false, |
| 115 | "Activate all of the default components (will be overridden by any " |
| 116 | "other settings)"); |
| 117 | ABSL_FLAG(int, |
| 118 | aec_suppression_level, |
| 119 | kParameterNotSpecifiedValue, |
| 120 | "Set the aec suppression level (0-2)"); |
| 121 | ABSL_FLAG(int, |
| 122 | delay_agnostic, |
| 123 | kParameterNotSpecifiedValue, |
| 124 | "Activate (1) or deactivate(0) the AEC delay agnostic mode"); |
| 125 | ABSL_FLAG(int, |
| 126 | extended_filter, |
| 127 | kParameterNotSpecifiedValue, |
| 128 | "Activate (1) or deactivate(0) the AEC extended filter mode"); |
| 129 | ABSL_FLAG(int, |
| 130 | use_legacy_aec, |
| 131 | kParameterNotSpecifiedValue, |
| 132 | "Activate (1) or deactivate(0) the legacy AEC"); |
| 133 | ABSL_FLAG(int, |
Per Åhgren | 0cbb58e | 2019-10-29 22:59:44 +0100 | [diff] [blame] | 134 | use_legacy_ns, |
| 135 | kParameterNotSpecifiedValue, |
| 136 | "Activate (1) or deactivate(0) the legacy AEC"); |
| 137 | ABSL_FLAG(int, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 138 | experimental_agc, |
| 139 | kParameterNotSpecifiedValue, |
| 140 | "Activate (1) or deactivate(0) the experimental AGC"); |
| 141 | ABSL_FLAG(int, |
| 142 | experimental_agc_disable_digital_adaptive, |
| 143 | kParameterNotSpecifiedValue, |
| 144 | "Force-deactivate (1) digital adaptation in " |
| 145 | "experimental AGC. Digital adaptation is active by default (0)."); |
| 146 | ABSL_FLAG(int, |
| 147 | experimental_agc_analyze_before_aec, |
| 148 | kParameterNotSpecifiedValue, |
| 149 | "Make level estimation happen before AEC" |
| 150 | " in the experimental AGC. After AEC is the default (0)"); |
| 151 | ABSL_FLAG(int, |
| 152 | experimental_agc_agc2_level_estimator, |
| 153 | kParameterNotSpecifiedValue, |
| 154 | "AGC2 level estimation" |
| 155 | " in the experimental AGC. AGC1 level estimation is the default (0)"); |
| 156 | ABSL_FLAG( |
| 157 | int, |
| 158 | refined_adaptive_filter, |
| 159 | kParameterNotSpecifiedValue, |
| 160 | "Activate (1) or deactivate(0) the refined adaptive filter functionality"); |
| 161 | ABSL_FLAG(int, |
| 162 | agc_mode, |
| 163 | kParameterNotSpecifiedValue, |
| 164 | "Specify the AGC mode (0-2)"); |
| 165 | ABSL_FLAG(int, |
| 166 | agc_target_level, |
| 167 | kParameterNotSpecifiedValue, |
| 168 | "Specify the AGC target level (0-31)"); |
| 169 | ABSL_FLAG(int, |
| 170 | agc_limiter, |
| 171 | kParameterNotSpecifiedValue, |
| 172 | "Activate (1) or deactivate(0) the level estimator"); |
| 173 | ABSL_FLAG(int, |
| 174 | agc_compression_gain, |
| 175 | kParameterNotSpecifiedValue, |
| 176 | "Specify the AGC compression gain (0-90)"); |
| 177 | ABSL_FLAG(int, |
| 178 | agc2_enable_adaptive_gain, |
| 179 | kParameterNotSpecifiedValue, |
| 180 | "Activate (1) or deactivate(0) the AGC2 adaptive gain"); |
| 181 | ABSL_FLAG(float, |
| 182 | agc2_fixed_gain_db, |
| 183 | kParameterNotSpecifiedValue, |
| 184 | "AGC2 fixed gain (dB) to apply"); |
| 185 | ABSL_FLAG(std::string, |
| 186 | agc2_adaptive_level_estimator, |
| 187 | "RMS", |
| 188 | "AGC2 adaptive digital level estimator to use [RMS, peak]"); |
| 189 | ABSL_FLAG(float, |
| 190 | pre_amplifier_gain_factor, |
| 191 | kParameterNotSpecifiedValue, |
| 192 | "Pre-amplifier gain factor (linear) to apply"); |
| 193 | ABSL_FLAG(int, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 194 | ns_level, |
| 195 | kParameterNotSpecifiedValue, |
| 196 | "Specify the NS level (0-3)"); |
| 197 | ABSL_FLAG(int, |
Per Åhgren | fcbe407 | 2019-09-15 00:27:58 +0200 | [diff] [blame] | 198 | maximum_internal_processing_rate, |
| 199 | kParameterNotSpecifiedValue, |
| 200 | "Set a maximum internal processing rate (32000 or 48000) to override " |
| 201 | "the default rate"); |
| 202 | ABSL_FLAG(int, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 203 | stream_delay, |
| 204 | kParameterNotSpecifiedValue, |
| 205 | "Specify the stream delay in ms to use"); |
| 206 | ABSL_FLAG(int, |
| 207 | use_stream_delay, |
| 208 | kParameterNotSpecifiedValue, |
| 209 | "Activate (1) or deactivate(0) reporting the stream delay"); |
| 210 | ABSL_FLAG(int, |
| 211 | stream_drift_samples, |
| 212 | kParameterNotSpecifiedValue, |
| 213 | "Specify the number of stream drift samples to use"); |
| 214 | ABSL_FLAG(int, initial_mic_level, 100, "Initial mic level (0-255)"); |
| 215 | ABSL_FLAG(int, |
| 216 | simulate_mic_gain, |
| 217 | 0, |
| 218 | "Activate (1) or deactivate(0) the analog mic gain simulation"); |
| 219 | ABSL_FLAG(int, |
Sam Zackrisson | feee1e4 | 2019-09-20 07:50:35 +0200 | [diff] [blame] | 220 | experimental_multi_channel, |
| 221 | kParameterNotSpecifiedValue, |
| 222 | "Activate (1) or deactivate(0) multi-channel audio in APM pipeline"); |
| 223 | ABSL_FLAG(int, |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 224 | simulated_mic_kind, |
| 225 | kParameterNotSpecifiedValue, |
| 226 | "Specify which microphone kind to use for microphone simulation"); |
| 227 | ABSL_FLAG(bool, performance_report, false, "Report the APM performance "); |
| 228 | ABSL_FLAG(std::string, |
| 229 | performance_report_output_file, |
| 230 | "", |
| 231 | "Generate a CSV file with the API call durations"); |
| 232 | ABSL_FLAG(bool, verbose, false, "Produce verbose output"); |
| 233 | ABSL_FLAG(bool, |
| 234 | quiet, |
| 235 | false, |
| 236 | "Avoid producing information about the progress."); |
| 237 | ABSL_FLAG(bool, |
| 238 | bitexactness_report, |
| 239 | false, |
| 240 | "Report bitexactness for aec dump result reproduction"); |
| 241 | ABSL_FLAG(bool, |
| 242 | discard_settings_in_aecdump, |
| 243 | false, |
| 244 | "Discard any config settings specified in the aec dump"); |
| 245 | ABSL_FLAG(bool, |
| 246 | store_intermediate_output, |
| 247 | false, |
| 248 | "Creates new output files after each init"); |
| 249 | ABSL_FLAG(std::string, |
| 250 | custom_call_order_file, |
| 251 | "", |
| 252 | "Custom process API call order file"); |
| 253 | ABSL_FLAG(std::string, |
| 254 | output_custom_call_order_file, |
| 255 | "", |
| 256 | "Generate custom process API call order file from AEC dump"); |
| 257 | ABSL_FLAG(bool, |
| 258 | print_aec_parameter_values, |
| 259 | false, |
| 260 | "Print parameter values used in AEC in JSON-format"); |
| 261 | ABSL_FLAG(std::string, |
| 262 | aec_settings, |
| 263 | "", |
| 264 | "File in JSON-format with custom AEC settings"); |
| 265 | ABSL_FLAG(bool, |
| 266 | dump_data, |
| 267 | false, |
| 268 | "Dump internal data during the call (requires build flag)"); |
| 269 | ABSL_FLAG(std::string, |
| 270 | dump_data_output_dir, |
| 271 | "", |
| 272 | "Internal data dump output directory"); |
| 273 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 274 | namespace webrtc { |
| 275 | namespace test { |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 276 | namespace { |
| 277 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 278 | const char kUsageDescription[] = |
| 279 | "Usage: audioproc_f [options] -i <input.wav>\n" |
| 280 | " or\n" |
| 281 | " audioproc_f [options] -dump_input <aec_dump>\n" |
| 282 | "\n\n" |
| 283 | "Command-line tool to simulate a call using the audio " |
| 284 | "processing module, either based on wav files or " |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 285 | "protobuf debug dump recordings.\n"; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 286 | |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 287 | std::vector<std::string> GetAgc2AdaptiveLevelEstimatorNames() { |
| 288 | return {"RMS", "peak"}; |
| 289 | } |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 290 | |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 291 | void SetSettingIfSpecified(const std::string& value, |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 292 | absl::optional<std::string>* parameter) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 293 | if (value.compare("") != 0) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 294 | *parameter = value; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 298 | void SetSettingIfSpecified(int value, absl::optional<int>* parameter) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 299 | if (value != kParameterNotSpecifiedValue) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 300 | *parameter = value; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Per Åhgren | ef34960 | 2019-04-12 16:26:34 +0200 | [diff] [blame] | 304 | void SetSettingIfSpecified(float value, absl::optional<float>* parameter) { |
| 305 | constexpr float kFloatParameterNotSpecifiedValue = |
| 306 | kParameterNotSpecifiedValue; |
| 307 | if (value != kFloatParameterNotSpecifiedValue) { |
| 308 | *parameter = value; |
| 309 | } |
| 310 | } |
| 311 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 312 | void SetSettingIfFlagSet(int32_t flag, absl::optional<bool>* parameter) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 313 | if (flag == 0) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 314 | *parameter = false; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 315 | } else if (flag == 1) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 316 | *parameter = true; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 320 | AudioProcessing::Config::GainController2::LevelEstimator |
| 321 | MapAgc2AdaptiveLevelEstimator(absl::string_view name) { |
| 322 | if (name.compare("RMS") == 0) { |
| 323 | return AudioProcessing::Config::GainController2::LevelEstimator::kRms; |
| 324 | } |
| 325 | if (name.compare("peak") == 0) { |
| 326 | return AudioProcessing::Config::GainController2::LevelEstimator::kPeak; |
| 327 | } |
| 328 | auto concat_strings = |
| 329 | [](const std::vector<std::string>& strings) -> std::string { |
| 330 | rtc::StringBuilder ss; |
| 331 | for (const auto& s : strings) { |
| 332 | ss << " " << s; |
| 333 | } |
| 334 | return ss.Release(); |
| 335 | }; |
| 336 | RTC_CHECK(false) |
| 337 | << "Invalid value for agc2_adaptive_level_estimator, valid options:" |
| 338 | << concat_strings(GetAgc2AdaptiveLevelEstimatorNames()) << "."; |
| 339 | } |
| 340 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 341 | SimulationSettings CreateSettings() { |
| 342 | SimulationSettings settings; |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 343 | if (absl::GetFlag(FLAGS_all_default)) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 344 | settings.use_le = true; |
| 345 | settings.use_vad = true; |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 346 | settings.use_ts = true; |
| 347 | settings.use_ns = true; |
| 348 | settings.use_hpf = true; |
| 349 | settings.use_agc = true; |
| 350 | settings.use_agc2 = false; |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 351 | settings.use_pre_amplifier = false; |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 352 | settings.use_aec = true; |
| 353 | settings.use_aecm = false; |
| 354 | settings.use_ed = false; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 355 | } |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 356 | SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_input), |
| 357 | &settings.aec_dump_input_filename); |
| 358 | SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_output), |
| 359 | &settings.aec_dump_output_filename); |
| 360 | SetSettingIfSpecified(absl::GetFlag(FLAGS_i), &settings.input_filename); |
| 361 | SetSettingIfSpecified(absl::GetFlag(FLAGS_o), &settings.output_filename); |
| 362 | SetSettingIfSpecified(absl::GetFlag(FLAGS_ri), |
| 363 | &settings.reverse_input_filename); |
| 364 | SetSettingIfSpecified(absl::GetFlag(FLAGS_ro), |
| 365 | &settings.reverse_output_filename); |
| 366 | SetSettingIfSpecified(absl::GetFlag(FLAGS_artificial_nearend), |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame] | 367 | &settings.artificial_nearend_filename); |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame^] | 368 | SetSettingIfSpecified(absl::GetFlag(FLAGS_linear_aec_output), |
| 369 | &settings.linear_aec_output_filename); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 370 | SetSettingIfSpecified(absl::GetFlag(FLAGS_output_num_channels), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 371 | &settings.output_num_channels); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 372 | SetSettingIfSpecified(absl::GetFlag(FLAGS_reverse_output_num_channels), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 373 | &settings.reverse_output_num_channels); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 374 | SetSettingIfSpecified(absl::GetFlag(FLAGS_output_sample_rate_hz), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 375 | &settings.output_sample_rate_hz); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 376 | SetSettingIfSpecified(absl::GetFlag(FLAGS_reverse_output_sample_rate_hz), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 377 | &settings.reverse_output_sample_rate_hz); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 378 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_aec), &settings.use_aec); |
| 379 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_aecm), &settings.use_aecm); |
| 380 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_ed), &settings.use_ed); |
| 381 | SetSettingIfSpecified(absl::GetFlag(FLAGS_ed_graph), |
| 382 | &settings.ed_graph_output_filename); |
| 383 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_agc), &settings.use_agc); |
| 384 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_agc2), &settings.use_agc2); |
| 385 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_pre_amplifier), |
| 386 | &settings.use_pre_amplifier); |
| 387 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_hpf), &settings.use_hpf); |
| 388 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_ns), &settings.use_ns); |
| 389 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_ts), &settings.use_ts); |
| 390 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_vad), &settings.use_vad); |
| 391 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_le), &settings.use_le); |
| 392 | SetSettingIfSpecified(absl::GetFlag(FLAGS_aec_suppression_level), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 393 | &settings.aec_suppression_level); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 394 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_delay_agnostic), |
| 395 | &settings.use_delay_agnostic); |
| 396 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_extended_filter), |
| 397 | &settings.use_extended_filter); |
| 398 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_refined_adaptive_filter), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 399 | &settings.use_refined_adaptive_filter); |
| 400 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 401 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_use_legacy_aec), |
| 402 | &settings.use_legacy_aec); |
Per Åhgren | 0cbb58e | 2019-10-29 22:59:44 +0100 | [diff] [blame] | 403 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_use_legacy_ns), |
| 404 | &settings.use_legacy_ns); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 405 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_experimental_agc), |
| 406 | &settings.use_experimental_agc); |
| 407 | SetSettingIfFlagSet( |
| 408 | absl::GetFlag(FLAGS_experimental_agc_disable_digital_adaptive), |
| 409 | &settings.experimental_agc_disable_digital_adaptive); |
| 410 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_experimental_agc_analyze_before_aec), |
Alex Loiko | d934244 | 2018-09-10 13:59:41 +0200 | [diff] [blame] | 411 | &settings.experimental_agc_analyze_before_aec); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 412 | SetSettingIfFlagSet( |
| 413 | absl::GetFlag(FLAGS_experimental_agc_agc2_level_estimator), |
| 414 | &settings.use_experimental_agc_agc2_level_estimator); |
| 415 | SetSettingIfSpecified(absl::GetFlag(FLAGS_agc_mode), &settings.agc_mode); |
| 416 | SetSettingIfSpecified(absl::GetFlag(FLAGS_agc_target_level), |
| 417 | &settings.agc_target_level); |
| 418 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_agc_limiter), |
| 419 | &settings.use_agc_limiter); |
| 420 | SetSettingIfSpecified(absl::GetFlag(FLAGS_agc_compression_gain), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 421 | &settings.agc_compression_gain); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 422 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_agc2_enable_adaptive_gain), |
Per Åhgren | e4d23b1 | 2018-10-02 23:40:07 +0200 | [diff] [blame] | 423 | &settings.agc2_use_adaptive_gain); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 424 | SetSettingIfSpecified(absl::GetFlag(FLAGS_agc2_fixed_gain_db), |
| 425 | &settings.agc2_fixed_gain_db); |
| 426 | settings.agc2_adaptive_level_estimator = MapAgc2AdaptiveLevelEstimator( |
| 427 | absl::GetFlag(FLAGS_agc2_adaptive_level_estimator)); |
| 428 | SetSettingIfSpecified(absl::GetFlag(FLAGS_pre_amplifier_gain_factor), |
Per Åhgren | ef34960 | 2019-04-12 16:26:34 +0200 | [diff] [blame] | 429 | &settings.pre_amplifier_gain_factor); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 430 | SetSettingIfSpecified(absl::GetFlag(FLAGS_ns_level), &settings.ns_level); |
Per Åhgren | fcbe407 | 2019-09-15 00:27:58 +0200 | [diff] [blame] | 431 | SetSettingIfSpecified(absl::GetFlag(FLAGS_maximum_internal_processing_rate), |
| 432 | &settings.maximum_internal_processing_rate); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 433 | SetSettingIfSpecified(absl::GetFlag(FLAGS_stream_delay), |
| 434 | &settings.stream_delay); |
| 435 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_use_stream_delay), |
| 436 | &settings.use_stream_delay); |
| 437 | SetSettingIfSpecified(absl::GetFlag(FLAGS_stream_drift_samples), |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 438 | &settings.stream_drift_samples); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 439 | SetSettingIfSpecified(absl::GetFlag(FLAGS_custom_call_order_file), |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 440 | &settings.call_order_input_filename); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 441 | SetSettingIfSpecified(absl::GetFlag(FLAGS_output_custom_call_order_file), |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 442 | &settings.call_order_output_filename); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 443 | SetSettingIfSpecified(absl::GetFlag(FLAGS_aec_settings), |
| 444 | &settings.aec_settings_filename); |
| 445 | settings.initial_mic_level = absl::GetFlag(FLAGS_initial_mic_level); |
Sam Zackrisson | feee1e4 | 2019-09-20 07:50:35 +0200 | [diff] [blame] | 446 | SetSettingIfFlagSet(absl::GetFlag(FLAGS_experimental_multi_channel), |
| 447 | &settings.experimental_multi_channel); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 448 | settings.simulate_mic_gain = absl::GetFlag(FLAGS_simulate_mic_gain); |
| 449 | SetSettingIfSpecified(absl::GetFlag(FLAGS_simulated_mic_kind), |
| 450 | &settings.simulated_mic_kind); |
| 451 | settings.report_performance = absl::GetFlag(FLAGS_performance_report); |
| 452 | SetSettingIfSpecified(absl::GetFlag(FLAGS_performance_report_output_file), |
Per Åhgren | ada9b89 | 2019-04-03 16:06:42 +0200 | [diff] [blame] | 453 | &settings.performance_report_output_filename); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 454 | settings.use_verbose_logging = absl::GetFlag(FLAGS_verbose); |
| 455 | settings.use_quiet_output = absl::GetFlag(FLAGS_quiet); |
| 456 | settings.report_bitexactness = absl::GetFlag(FLAGS_bitexactness_report); |
| 457 | settings.discard_all_settings_in_aecdump = |
| 458 | absl::GetFlag(FLAGS_discard_settings_in_aecdump); |
| 459 | settings.fixed_interface = absl::GetFlag(FLAGS_fixed_interface); |
| 460 | settings.store_intermediate_output = |
| 461 | absl::GetFlag(FLAGS_store_intermediate_output); |
| 462 | settings.print_aec_parameter_values = |
| 463 | absl::GetFlag(FLAGS_print_aec_parameter_values); |
| 464 | settings.dump_internal_data = absl::GetFlag(FLAGS_dump_data); |
| 465 | SetSettingIfSpecified(absl::GetFlag(FLAGS_dump_data_output_dir), |
Alessio Bazzica | 4bc6045 | 2018-11-20 12:44:15 +0100 | [diff] [blame] | 466 | &settings.dump_internal_data_output_dir); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 467 | |
| 468 | return settings; |
| 469 | } |
| 470 | |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 471 | void ReportConditionalErrorAndExit(bool condition, const std::string& message) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 472 | if (condition) { |
| 473 | std::cerr << message << std::endl; |
| 474 | exit(1); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | void PerformBasicParameterSanityChecks(const SimulationSettings& settings) { |
| 479 | if (settings.input_filename || settings.reverse_input_filename) { |
Sonia-Florina Horchidan | b75d14c | 2019-08-12 09:57:01 +0200 | [diff] [blame] | 480 | ReportConditionalErrorAndExit( |
| 481 | !!settings.aec_dump_input_filename, |
| 482 | "Error: The aec dump file cannot be specified " |
| 483 | "together with input wav files!\n"); |
| 484 | |
| 485 | ReportConditionalErrorAndExit( |
| 486 | !!settings.aec_dump_input_string, |
| 487 | "Error: The aec dump input string cannot be specified " |
| 488 | "together with input wav files!\n"); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 489 | |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame] | 490 | ReportConditionalErrorAndExit(!!settings.artificial_nearend_filename, |
| 491 | "Error: The artificial nearend cannot be " |
| 492 | "specified together with input wav files!\n"); |
| 493 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 494 | ReportConditionalErrorAndExit(!settings.input_filename, |
| 495 | "Error: When operating at wav files, the " |
| 496 | "input wav filename must be " |
| 497 | "specified!\n"); |
| 498 | |
| 499 | ReportConditionalErrorAndExit( |
| 500 | settings.reverse_output_filename && !settings.reverse_input_filename, |
| 501 | "Error: When operating at wav files, the reverse input wav filename " |
| 502 | "must be specified if the reverse output wav filename is specified!\n"); |
| 503 | } else { |
Sonia-Florina Horchidan | b75d14c | 2019-08-12 09:57:01 +0200 | [diff] [blame] | 504 | ReportConditionalErrorAndExit( |
| 505 | !settings.aec_dump_input_filename && !settings.aec_dump_input_string, |
| 506 | "Error: Either the aec dump input file, the wav " |
| 507 | "input file or the aec dump input string must be specified!\n"); |
| 508 | ReportConditionalErrorAndExit( |
| 509 | settings.aec_dump_input_filename && settings.aec_dump_input_string, |
| 510 | "Error: The aec dump input file cannot be specified together with the " |
| 511 | "aec dump input string!\n"); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame^] | 514 | ReportConditionalErrorAndExit(settings.use_aec && !(*settings.use_aec) && |
| 515 | settings.linear_aec_output_filename, |
| 516 | "Error: The linear AEC ouput filename cannot " |
| 517 | "be specified without the AEC being active"); |
| 518 | |
| 519 | ReportConditionalErrorAndExit( |
| 520 | ((settings.use_aec && *settings.use_aec && settings.use_legacy_aec && |
| 521 | *settings.use_legacy_aec) || |
| 522 | (settings.use_aecm && *settings.use_aecm)) && |
| 523 | !!settings.linear_aec_output_filename, |
| 524 | "Error: The linear AEC ouput filename cannot be specified when the " |
| 525 | "legacy AEC or the AECm are used"); |
| 526 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 527 | ReportConditionalErrorAndExit( |
| 528 | settings.use_aec && *settings.use_aec && settings.use_aecm && |
| 529 | *settings.use_aecm, |
| 530 | "Error: The AEC and the AECM cannot be activated at the same time!\n"); |
| 531 | |
| 532 | ReportConditionalErrorAndExit( |
| 533 | settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0, |
| 534 | "Error: --output_sample_rate_hz must be positive!\n"); |
| 535 | |
| 536 | ReportConditionalErrorAndExit( |
| 537 | settings.reverse_output_sample_rate_hz && |
| 538 | settings.output_sample_rate_hz && |
| 539 | *settings.output_sample_rate_hz <= 0, |
| 540 | "Error: --reverse_output_sample_rate_hz must be positive!\n"); |
| 541 | |
| 542 | ReportConditionalErrorAndExit( |
| 543 | settings.output_num_channels && *settings.output_num_channels <= 0, |
| 544 | "Error: --output_num_channels must be positive!\n"); |
| 545 | |
| 546 | ReportConditionalErrorAndExit( |
| 547 | settings.reverse_output_num_channels && |
| 548 | *settings.reverse_output_num_channels <= 0, |
| 549 | "Error: --reverse_output_num_channels must be positive!\n"); |
| 550 | |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 551 | ReportConditionalErrorAndExit(settings.aec_suppression_level && |
| 552 | ((*settings.aec_suppression_level) < 1 || |
| 553 | (*settings.aec_suppression_level) > 2), |
| 554 | "Error: --aec_suppression_level must be " |
| 555 | "specified between 1 and 2. 0 is " |
| 556 | "deprecated.\n"); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 557 | |
| 558 | ReportConditionalErrorAndExit( |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 559 | settings.agc_target_level && ((*settings.agc_target_level) < 0 || |
| 560 | (*settings.agc_target_level) > 31), |
| 561 | "Error: --agc_target_level must be specified between 0 and 31.\n"); |
| 562 | |
| 563 | ReportConditionalErrorAndExit( |
| 564 | settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 || |
| 565 | (*settings.agc_compression_gain) > 90), |
| 566 | "Error: --agc_compression_gain must be specified between 0 and 90.\n"); |
| 567 | |
| 568 | ReportConditionalErrorAndExit( |
Per Åhgren | 6ee75fd | 2019-04-26 11:33:37 +0200 | [diff] [blame] | 569 | settings.agc2_fixed_gain_db && ((*settings.agc2_fixed_gain_db) < 0 || |
| 570 | (*settings.agc2_fixed_gain_db) > 90), |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 571 | "Error: --agc2_fixed_gain_db must be specified between 0 and 90.\n"); |
| 572 | |
| 573 | ReportConditionalErrorAndExit( |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 574 | settings.ns_level && |
| 575 | ((*settings.ns_level) < 0 || (*settings.ns_level) > 3), |
| 576 | "Error: --ns_level must be specified between 0 and 3.\n"); |
| 577 | |
| 578 | ReportConditionalErrorAndExit( |
| 579 | settings.report_bitexactness && !settings.aec_dump_input_filename, |
| 580 | "Error: --bitexactness_report can only be used when operating on an " |
| 581 | "aecdump\n"); |
| 582 | |
peah | 5ad5de3 | 2016-12-09 03:18:22 -0800 | [diff] [blame] | 583 | ReportConditionalErrorAndExit( |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 584 | settings.call_order_input_filename && settings.aec_dump_input_filename, |
peah | 5ad5de3 | 2016-12-09 03:18:22 -0800 | [diff] [blame] | 585 | "Error: --custom_call_order_file cannot be used when operating on an " |
| 586 | "aecdump\n"); |
| 587 | |
Alessio Bazzica | ca90a55 | 2017-09-27 11:51:10 +0200 | [diff] [blame] | 588 | ReportConditionalErrorAndExit( |
| 589 | (settings.initial_mic_level < 0 || settings.initial_mic_level > 255), |
| 590 | "Error: --initial_mic_level must be specified between 0 and 255.\n"); |
| 591 | |
| 592 | ReportConditionalErrorAndExit( |
| 593 | settings.simulated_mic_kind && !settings.simulate_mic_gain, |
| 594 | "Error: --simulated_mic_kind cannot be specified when mic simulation is " |
| 595 | "disabled\n"); |
| 596 | |
| 597 | ReportConditionalErrorAndExit( |
| 598 | !settings.simulated_mic_kind && settings.simulate_mic_gain, |
| 599 | "Error: --simulated_mic_kind must be specified when mic simulation is " |
| 600 | "enabled\n"); |
| 601 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 602 | auto valid_wav_name = [](const std::string& wav_file_name) { |
| 603 | if (wav_file_name.size() < 5) { |
| 604 | return false; |
| 605 | } |
| 606 | if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) || |
| 607 | (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) { |
| 608 | return true; |
| 609 | } |
| 610 | return false; |
| 611 | }; |
| 612 | |
| 613 | ReportConditionalErrorAndExit( |
| 614 | settings.input_filename && (!valid_wav_name(*settings.input_filename)), |
| 615 | "Error: --i must be a valid .wav file name.\n"); |
| 616 | |
| 617 | ReportConditionalErrorAndExit( |
| 618 | settings.output_filename && (!valid_wav_name(*settings.output_filename)), |
| 619 | "Error: --o must be a valid .wav file name.\n"); |
| 620 | |
| 621 | ReportConditionalErrorAndExit( |
| 622 | settings.reverse_input_filename && |
| 623 | (!valid_wav_name(*settings.reverse_input_filename)), |
| 624 | "Error: --ri must be a valid .wav file name.\n"); |
| 625 | |
| 626 | ReportConditionalErrorAndExit( |
| 627 | settings.reverse_output_filename && |
| 628 | (!valid_wav_name(*settings.reverse_output_filename)), |
| 629 | "Error: --ro must be a valid .wav file name.\n"); |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame] | 630 | |
| 631 | ReportConditionalErrorAndExit( |
| 632 | settings.artificial_nearend_filename && |
| 633 | !valid_wav_name(*settings.artificial_nearend_filename), |
| 634 | "Error: --artifical_nearend must be a valid .wav file name.\n"); |
Per Åhgren | 7a95e0f | 2018-10-25 09:56:49 +0200 | [diff] [blame] | 635 | |
| 636 | ReportConditionalErrorAndExit( |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame^] | 637 | settings.linear_aec_output_filename && |
| 638 | (!valid_wav_name(*settings.linear_aec_output_filename)), |
| 639 | "Error: --linear_aec_output must be a valid .wav file name.\n"); |
| 640 | |
| 641 | ReportConditionalErrorAndExit( |
Per Åhgren | 7a95e0f | 2018-10-25 09:56:49 +0200 | [diff] [blame] | 642 | WEBRTC_APM_DEBUG_DUMP == 0 && settings.dump_internal_data, |
| 643 | "Error: --dump_data cannot be set without proper build support.\n"); |
Alessio Bazzica | 4bc6045 | 2018-11-20 12:44:15 +0100 | [diff] [blame] | 644 | |
| 645 | ReportConditionalErrorAndExit( |
| 646 | !settings.dump_internal_data && |
| 647 | settings.dump_internal_data_output_dir.has_value(), |
| 648 | "Error: --dump_data_output_dir cannot be set without --dump_data.\n"); |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 649 | |
| 650 | ReportConditionalErrorAndExit( |
| 651 | !settings.aec_dump_input_filename && |
| 652 | settings.call_order_output_filename.has_value(), |
| 653 | "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] | 654 | |
| 655 | ReportConditionalErrorAndExit( |
| 656 | (!settings.use_pre_amplifier || !(*settings.use_pre_amplifier)) && |
| 657 | settings.pre_amplifier_gain_factor.has_value(), |
| 658 | "Error: --pre_amplifier_gain_factor needs --pre_amplifier to be " |
| 659 | "specified and set.\n"); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | } // namespace |
| 663 | |
Ivo Creusen | 2cb4105 | 2018-03-15 12:22:52 +0100 | [diff] [blame] | 664 | int AudioprocFloatImpl(std::unique_ptr<AudioProcessingBuilder> ap_builder, |
| 665 | int argc, |
Sonia-Florina Horchidan | b75d14c | 2019-08-12 09:57:01 +0200 | [diff] [blame] | 666 | char* argv[], |
| 667 | absl::string_view input_aecdump, |
| 668 | std::vector<float>* processed_capture_samples) { |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 669 | std::vector<char*> args = absl::ParseCommandLine(argc, argv); |
| 670 | if (args.size() != 1) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 671 | printf("%s", kUsageDescription); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 672 | return 1; |
| 673 | } |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 674 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 675 | SimulationSettings settings = CreateSettings(); |
Sonia-Florina Horchidan | b75d14c | 2019-08-12 09:57:01 +0200 | [diff] [blame] | 676 | if (!input_aecdump.empty()) { |
| 677 | settings.aec_dump_input_string = input_aecdump; |
| 678 | settings.processed_capture_samples = processed_capture_samples; |
| 679 | RTC_CHECK(settings.processed_capture_samples); |
| 680 | } |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 681 | PerformBasicParameterSanityChecks(settings); |
| 682 | std::unique_ptr<AudioProcessingSimulator> processor; |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 683 | |
Sonia-Florina Horchidan | b75d14c | 2019-08-12 09:57:01 +0200 | [diff] [blame] | 684 | if (settings.aec_dump_input_filename || settings.aec_dump_input_string) { |
Ivo Creusen | 8c812f3 | 2018-03-09 17:33:04 +0100 | [diff] [blame] | 685 | processor.reset(new AecDumpBasedSimulator(settings, std::move(ap_builder))); |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 686 | } else { |
Ivo Creusen | 8c812f3 | 2018-03-09 17:33:04 +0100 | [diff] [blame] | 687 | processor.reset(new WavBasedSimulator(settings, std::move(ap_builder))); |
andrew | bdafe31 | 2015-10-29 23:42:54 -0700 | [diff] [blame] | 688 | } |
| 689 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 690 | processor->Process(); |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 691 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 692 | if (settings.report_performance) { |
Per Åhgren | ada9b89 | 2019-04-03 16:06:42 +0200 | [diff] [blame] | 693 | processor->GetApiCallStatistics().PrintReport(); |
| 694 | } |
| 695 | if (settings.performance_report_output_filename) { |
| 696 | processor->GetApiCallStatistics().WriteReportToFile( |
| 697 | *settings.performance_report_output_filename); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | if (settings.report_bitexactness && settings.aec_dump_input_filename) { |
| 701 | if (processor->OutputWasBitexact()) { |
| 702 | std::cout << "The processing was bitexact."; |
| 703 | } else { |
| 704 | std::cout << "The processing was not bitexact."; |
| 705 | } |
Alejandro Luebs | 5d22c00 | 2015-04-15 11:26:40 -0700 | [diff] [blame] | 706 | } |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 707 | |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 708 | return 0; |
| 709 | } |
| 710 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 711 | } // namespace test |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 712 | } // namespace webrtc |