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 | |
Ivo Creusen | 2cb4105 | 2018-03-15 12:22:52 +0100 | [diff] [blame] | 11 | #include <string.h> |
| 12 | |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 13 | #include <iostream> |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 14 | #include <memory> |
Ivo Creusen | 2cb4105 | 2018-03-15 12:22:52 +0100 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <utility> |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 17 | #include <vector> |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 18 | |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 19 | #include "absl/strings/string_view.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/audio_processing/include/audio_processing.h" |
| 21 | #include "modules/audio_processing/test/aec_dump_based_simulator.h" |
| 22 | #include "modules/audio_processing/test/audio_processing_simulator.h" |
Ivo Creusen | 2cb4105 | 2018-03-15 12:22:52 +0100 | [diff] [blame] | 23 | #include "modules/audio_processing/test/audioproc_float_impl.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "modules/audio_processing/test/wav_based_simulator.h" |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 25 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "rtc_base/flags.h" |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 27 | #include "rtc_base/strings/string_builder.h" |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 28 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 29 | namespace webrtc { |
| 30 | namespace test { |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 31 | namespace { |
| 32 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 33 | const int kParameterNotSpecifiedValue = -10000; |
| 34 | |
| 35 | const char kUsageDescription[] = |
| 36 | "Usage: audioproc_f [options] -i <input.wav>\n" |
| 37 | " or\n" |
| 38 | " audioproc_f [options] -dump_input <aec_dump>\n" |
| 39 | "\n\n" |
| 40 | "Command-line tool to simulate a call using the audio " |
| 41 | "processing module, either based on wav files or " |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 42 | "protobuf debug dump recordings.\n"; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 43 | |
Mirko Bonadei | 2dfa998 | 2018-10-18 11:35:32 +0200 | [diff] [blame] | 44 | WEBRTC_DEFINE_string(dump_input, "", "Aec dump input filename"); |
| 45 | WEBRTC_DEFINE_string(dump_output, "", "Aec dump output filename"); |
| 46 | WEBRTC_DEFINE_string(i, "", "Forward stream input wav filename"); |
| 47 | WEBRTC_DEFINE_string(o, "", "Forward stream output wav filename"); |
| 48 | WEBRTC_DEFINE_string(ri, "", "Reverse stream input wav filename"); |
| 49 | WEBRTC_DEFINE_string(ro, "", "Reverse stream output wav filename"); |
| 50 | WEBRTC_DEFINE_string(artificial_nearend, "", "Artificial nearend wav filename"); |
| 51 | WEBRTC_DEFINE_int(output_num_channels, |
| 52 | kParameterNotSpecifiedValue, |
| 53 | "Number of forward stream output channels"); |
| 54 | WEBRTC_DEFINE_int(reverse_output_num_channels, |
| 55 | kParameterNotSpecifiedValue, |
| 56 | "Number of Reverse stream output channels"); |
| 57 | WEBRTC_DEFINE_int(output_sample_rate_hz, |
| 58 | kParameterNotSpecifiedValue, |
| 59 | "Forward stream output sample rate in Hz"); |
| 60 | WEBRTC_DEFINE_int(reverse_output_sample_rate_hz, |
| 61 | kParameterNotSpecifiedValue, |
| 62 | "Reverse stream output sample rate in Hz"); |
| 63 | WEBRTC_DEFINE_bool(fixed_interface, |
| 64 | false, |
| 65 | "Use the fixed interface when operating on wav files"); |
| 66 | WEBRTC_DEFINE_int(aec, |
| 67 | kParameterNotSpecifiedValue, |
| 68 | "Activate (1) or deactivate(0) the echo canceller"); |
| 69 | WEBRTC_DEFINE_int(aecm, |
| 70 | kParameterNotSpecifiedValue, |
| 71 | "Activate (1) or deactivate(0) the mobile echo controller"); |
| 72 | WEBRTC_DEFINE_int(ed, |
| 73 | kParameterNotSpecifiedValue, |
| 74 | "Activate (1) or deactivate (0) the residual echo detector"); |
| 75 | WEBRTC_DEFINE_string(ed_graph, |
| 76 | "", |
| 77 | "Output filename for graph of echo likelihood"); |
| 78 | WEBRTC_DEFINE_int(agc, |
| 79 | kParameterNotSpecifiedValue, |
| 80 | "Activate (1) or deactivate(0) the AGC"); |
| 81 | WEBRTC_DEFINE_int(agc2, |
| 82 | kParameterNotSpecifiedValue, |
| 83 | "Activate (1) or deactivate(0) the AGC2"); |
| 84 | WEBRTC_DEFINE_int(pre_amplifier, |
| 85 | kParameterNotSpecifiedValue, |
| 86 | "Activate (1) or deactivate(0) the pre amplifier"); |
| 87 | WEBRTC_DEFINE_int(hpf, |
| 88 | kParameterNotSpecifiedValue, |
| 89 | "Activate (1) or deactivate(0) the high-pass filter"); |
| 90 | WEBRTC_DEFINE_int(ns, |
| 91 | kParameterNotSpecifiedValue, |
| 92 | "Activate (1) or deactivate(0) the noise suppressor"); |
| 93 | WEBRTC_DEFINE_int(ts, |
| 94 | kParameterNotSpecifiedValue, |
| 95 | "Activate (1) or deactivate(0) the transient suppressor"); |
| 96 | WEBRTC_DEFINE_int(vad, |
| 97 | kParameterNotSpecifiedValue, |
| 98 | "Activate (1) or deactivate(0) the voice activity detector"); |
| 99 | WEBRTC_DEFINE_int(le, |
| 100 | kParameterNotSpecifiedValue, |
| 101 | "Activate (1) or deactivate(0) the level estimator"); |
| 102 | WEBRTC_DEFINE_bool( |
| 103 | all_default, |
| 104 | false, |
| 105 | "Activate all of the default components (will be overridden by any " |
| 106 | "other settings)"); |
| 107 | WEBRTC_DEFINE_int(aec_suppression_level, |
| 108 | kParameterNotSpecifiedValue, |
| 109 | "Set the aec suppression level (0-2)"); |
| 110 | WEBRTC_DEFINE_int(delay_agnostic, |
| 111 | kParameterNotSpecifiedValue, |
| 112 | "Activate (1) or deactivate(0) the AEC delay agnostic mode"); |
| 113 | WEBRTC_DEFINE_int(extended_filter, |
| 114 | kParameterNotSpecifiedValue, |
| 115 | "Activate (1) or deactivate(0) the AEC extended filter mode"); |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 116 | WEBRTC_DEFINE_int(use_legacy_aec, |
| 117 | kParameterNotSpecifiedValue, |
| 118 | "Activate (1) or deactivate(0) the legacy AEC"); |
Mirko Bonadei | 2dfa998 | 2018-10-18 11:35:32 +0200 | [diff] [blame] | 119 | WEBRTC_DEFINE_int(experimental_agc, |
| 120 | kParameterNotSpecifiedValue, |
| 121 | "Activate (1) or deactivate(0) the experimental AGC"); |
| 122 | WEBRTC_DEFINE_int( |
| 123 | experimental_agc_disable_digital_adaptive, |
| 124 | kParameterNotSpecifiedValue, |
| 125 | "Force-deactivate (1) digital adaptation in " |
| 126 | "experimental AGC. Digital adaptation is active by default (0)."); |
| 127 | WEBRTC_DEFINE_int(experimental_agc_analyze_before_aec, |
| 128 | kParameterNotSpecifiedValue, |
| 129 | "Make level estimation happen before AEC" |
| 130 | " in the experimental AGC. After AEC is the default (0)"); |
| 131 | WEBRTC_DEFINE_int( |
Alex Loiko | d934244 | 2018-09-10 13:59:41 +0200 | [diff] [blame] | 132 | experimental_agc_agc2_level_estimator, |
| 133 | kParameterNotSpecifiedValue, |
| 134 | "AGC2 level estimation" |
| 135 | " in the experimental AGC. AGC1 level estimation is the default (0)"); |
Mirko Bonadei | 2dfa998 | 2018-10-18 11:35:32 +0200 | [diff] [blame] | 136 | WEBRTC_DEFINE_int( |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 137 | refined_adaptive_filter, |
| 138 | kParameterNotSpecifiedValue, |
| 139 | "Activate (1) or deactivate(0) the refined adaptive filter functionality"); |
Mirko Bonadei | 2dfa998 | 2018-10-18 11:35:32 +0200 | [diff] [blame] | 140 | WEBRTC_DEFINE_int(agc_mode, |
| 141 | kParameterNotSpecifiedValue, |
| 142 | "Specify the AGC mode (0-2)"); |
| 143 | WEBRTC_DEFINE_int(agc_target_level, |
| 144 | kParameterNotSpecifiedValue, |
| 145 | "Specify the AGC target level (0-31)"); |
| 146 | WEBRTC_DEFINE_int(agc_limiter, |
| 147 | kParameterNotSpecifiedValue, |
| 148 | "Activate (1) or deactivate(0) the level estimator"); |
| 149 | WEBRTC_DEFINE_int(agc_compression_gain, |
| 150 | kParameterNotSpecifiedValue, |
| 151 | "Specify the AGC compression gain (0-90)"); |
| 152 | WEBRTC_DEFINE_float(agc2_enable_adaptive_gain, |
| 153 | kParameterNotSpecifiedValue, |
| 154 | "Activate (1) or deactivate(0) the AGC2 adaptive gain"); |
| 155 | WEBRTC_DEFINE_float(agc2_fixed_gain_db, 0.f, "AGC2 fixed gain (dB) to apply"); |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 156 | |
| 157 | std::vector<std::string> GetAgc2AdaptiveLevelEstimatorNames() { |
| 158 | return {"RMS", "peak"}; |
| 159 | } |
| 160 | WEBRTC_DEFINE_string( |
| 161 | agc2_adaptive_level_estimator, |
| 162 | "RMS", |
| 163 | "AGC2 adaptive digital level estimator to use [RMS, peak]"); |
| 164 | |
Mirko Bonadei | 2dfa998 | 2018-10-18 11:35:32 +0200 | [diff] [blame] | 165 | WEBRTC_DEFINE_float(pre_amplifier_gain_factor, |
| 166 | 1.f, |
| 167 | "Pre-amplifier gain factor (linear) to apply"); |
| 168 | WEBRTC_DEFINE_int(vad_likelihood, |
| 169 | kParameterNotSpecifiedValue, |
| 170 | "Specify the VAD likelihood (0-3)"); |
| 171 | WEBRTC_DEFINE_int(ns_level, |
| 172 | kParameterNotSpecifiedValue, |
| 173 | "Specify the NS level (0-3)"); |
| 174 | WEBRTC_DEFINE_int(stream_delay, |
| 175 | kParameterNotSpecifiedValue, |
| 176 | "Specify the stream delay in ms to use"); |
| 177 | WEBRTC_DEFINE_int(use_stream_delay, |
| 178 | kParameterNotSpecifiedValue, |
| 179 | "Activate (1) or deactivate(0) reporting the stream delay"); |
| 180 | WEBRTC_DEFINE_int(stream_drift_samples, |
| 181 | kParameterNotSpecifiedValue, |
| 182 | "Specify the number of stream drift samples to use"); |
| 183 | WEBRTC_DEFINE_int(initial_mic_level, 100, "Initial mic level (0-255)"); |
| 184 | WEBRTC_DEFINE_int( |
| 185 | simulate_mic_gain, |
| 186 | 0, |
| 187 | "Activate (1) or deactivate(0) the analog mic gain simulation"); |
| 188 | WEBRTC_DEFINE_int( |
| 189 | simulated_mic_kind, |
| 190 | kParameterNotSpecifiedValue, |
| 191 | "Specify which microphone kind to use for microphone simulation"); |
| 192 | WEBRTC_DEFINE_bool(performance_report, false, "Report the APM performance "); |
Per Åhgren | ada9b89 | 2019-04-03 16:06:42 +0200 | [diff] [blame] | 193 | WEBRTC_DEFINE_string(performance_report_output_file, |
| 194 | "", |
| 195 | "Generate a CSV file with the API call durations"); |
| 196 | |
Mirko Bonadei | 2dfa998 | 2018-10-18 11:35:32 +0200 | [diff] [blame] | 197 | WEBRTC_DEFINE_bool(verbose, false, "Produce verbose output"); |
| 198 | WEBRTC_DEFINE_bool(quiet, |
| 199 | false, |
| 200 | "Avoid producing information about the progress."); |
| 201 | WEBRTC_DEFINE_bool(bitexactness_report, |
| 202 | false, |
| 203 | "Report bitexactness for aec dump result reproduction"); |
| 204 | WEBRTC_DEFINE_bool(discard_settings_in_aecdump, |
| 205 | false, |
| 206 | "Discard any config settings specified in the aec dump"); |
| 207 | WEBRTC_DEFINE_bool(store_intermediate_output, |
| 208 | false, |
| 209 | "Creates new output files after each init"); |
| 210 | WEBRTC_DEFINE_string(custom_call_order_file, |
| 211 | "", |
| 212 | "Custom process API call order file"); |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 213 | WEBRTC_DEFINE_string( |
| 214 | output_custom_call_order_file, |
| 215 | "", |
| 216 | "Generate custom process API call order file from AEC dump"); |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 217 | WEBRTC_DEFINE_bool(print_aec_parameter_values, |
Mirko Bonadei | 2dfa998 | 2018-10-18 11:35:32 +0200 | [diff] [blame] | 218 | false, |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 219 | "Print parameter values used in AEC in JSON-format"); |
| 220 | WEBRTC_DEFINE_string(aec_settings, |
Mirko Bonadei | 2dfa998 | 2018-10-18 11:35:32 +0200 | [diff] [blame] | 221 | "", |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 222 | "File in JSON-format with custom AEC settings"); |
Per Åhgren | 7a95e0f | 2018-10-25 09:56:49 +0200 | [diff] [blame] | 223 | WEBRTC_DEFINE_bool(dump_data, |
| 224 | false, |
| 225 | "Dump internal data during the call (requires build flag)"); |
Alessio Bazzica | 4bc6045 | 2018-11-20 12:44:15 +0100 | [diff] [blame] | 226 | WEBRTC_DEFINE_string(dump_data_output_dir, |
| 227 | "", |
| 228 | "Internal data dump output directory"); |
Mirko Bonadei | 2dfa998 | 2018-10-18 11:35:32 +0200 | [diff] [blame] | 229 | WEBRTC_DEFINE_bool(help, false, "Print this message"); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 230 | |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 231 | void SetSettingIfSpecified(const std::string& value, |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 232 | absl::optional<std::string>* parameter) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 233 | if (value.compare("") != 0) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 234 | *parameter = value; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 238 | void SetSettingIfSpecified(int value, absl::optional<int>* parameter) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 239 | if (value != kParameterNotSpecifiedValue) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 240 | *parameter = value; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 244 | void SetSettingIfFlagSet(int32_t flag, absl::optional<bool>* parameter) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 245 | if (flag == 0) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 246 | *parameter = false; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 247 | } else if (flag == 1) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 248 | *parameter = true; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 252 | AudioProcessing::Config::GainController2::LevelEstimator |
| 253 | MapAgc2AdaptiveLevelEstimator(absl::string_view name) { |
| 254 | if (name.compare("RMS") == 0) { |
| 255 | return AudioProcessing::Config::GainController2::LevelEstimator::kRms; |
| 256 | } |
| 257 | if (name.compare("peak") == 0) { |
| 258 | return AudioProcessing::Config::GainController2::LevelEstimator::kPeak; |
| 259 | } |
| 260 | auto concat_strings = |
| 261 | [](const std::vector<std::string>& strings) -> std::string { |
| 262 | rtc::StringBuilder ss; |
| 263 | for (const auto& s : strings) { |
| 264 | ss << " " << s; |
| 265 | } |
| 266 | return ss.Release(); |
| 267 | }; |
| 268 | RTC_CHECK(false) |
| 269 | << "Invalid value for agc2_adaptive_level_estimator, valid options:" |
| 270 | << concat_strings(GetAgc2AdaptiveLevelEstimatorNames()) << "."; |
| 271 | } |
| 272 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 273 | SimulationSettings CreateSettings() { |
| 274 | SimulationSettings settings; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 275 | if (FLAG_all_default) { |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 276 | settings.use_le = true; |
| 277 | settings.use_vad = true; |
| 278 | settings.use_ie = false; |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 279 | settings.use_ts = true; |
| 280 | settings.use_ns = true; |
| 281 | settings.use_hpf = true; |
| 282 | settings.use_agc = true; |
| 283 | settings.use_agc2 = false; |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 284 | settings.use_pre_amplifier = false; |
Oskar Sundbom | aa8b67d | 2017-11-17 14:34:48 +0100 | [diff] [blame] | 285 | settings.use_aec = true; |
| 286 | settings.use_aecm = false; |
| 287 | settings.use_ed = false; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 288 | } |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 289 | SetSettingIfSpecified(FLAG_dump_input, &settings.aec_dump_input_filename); |
| 290 | SetSettingIfSpecified(FLAG_dump_output, &settings.aec_dump_output_filename); |
| 291 | SetSettingIfSpecified(FLAG_i, &settings.input_filename); |
| 292 | SetSettingIfSpecified(FLAG_o, &settings.output_filename); |
| 293 | SetSettingIfSpecified(FLAG_ri, &settings.reverse_input_filename); |
| 294 | SetSettingIfSpecified(FLAG_ro, &settings.reverse_output_filename); |
| 295 | SetSettingIfSpecified(FLAG_artificial_nearend, |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame] | 296 | &settings.artificial_nearend_filename); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 297 | SetSettingIfSpecified(FLAG_output_num_channels, |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 298 | &settings.output_num_channels); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 299 | SetSettingIfSpecified(FLAG_reverse_output_num_channels, |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 300 | &settings.reverse_output_num_channels); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 301 | SetSettingIfSpecified(FLAG_output_sample_rate_hz, |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 302 | &settings.output_sample_rate_hz); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 303 | SetSettingIfSpecified(FLAG_reverse_output_sample_rate_hz, |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 304 | &settings.reverse_output_sample_rate_hz); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 305 | SetSettingIfFlagSet(FLAG_aec, &settings.use_aec); |
| 306 | SetSettingIfFlagSet(FLAG_aecm, &settings.use_aecm); |
| 307 | SetSettingIfFlagSet(FLAG_ed, &settings.use_ed); |
| 308 | SetSettingIfSpecified(FLAG_ed_graph, &settings.ed_graph_output_filename); |
| 309 | SetSettingIfFlagSet(FLAG_agc, &settings.use_agc); |
| 310 | SetSettingIfFlagSet(FLAG_agc2, &settings.use_agc2); |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 311 | SetSettingIfFlagSet(FLAG_pre_amplifier, &settings.use_pre_amplifier); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 312 | SetSettingIfFlagSet(FLAG_hpf, &settings.use_hpf); |
| 313 | SetSettingIfFlagSet(FLAG_ns, &settings.use_ns); |
| 314 | SetSettingIfFlagSet(FLAG_ts, &settings.use_ts); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 315 | SetSettingIfFlagSet(FLAG_vad, &settings.use_vad); |
| 316 | SetSettingIfFlagSet(FLAG_le, &settings.use_le); |
| 317 | SetSettingIfSpecified(FLAG_aec_suppression_level, |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 318 | &settings.aec_suppression_level); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 319 | SetSettingIfFlagSet(FLAG_delay_agnostic, &settings.use_delay_agnostic); |
| 320 | SetSettingIfFlagSet(FLAG_extended_filter, &settings.use_extended_filter); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 321 | SetSettingIfFlagSet(FLAG_refined_adaptive_filter, |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 322 | &settings.use_refined_adaptive_filter); |
| 323 | |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 324 | SetSettingIfFlagSet(FLAG_use_legacy_aec, &settings.use_legacy_aec); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 325 | SetSettingIfFlagSet(FLAG_experimental_agc, &settings.use_experimental_agc); |
Alex Loiko | 9489c3a | 2018-08-09 15:04:24 +0200 | [diff] [blame] | 326 | SetSettingIfFlagSet(FLAG_experimental_agc_disable_digital_adaptive, |
| 327 | &settings.experimental_agc_disable_digital_adaptive); |
Alex Loiko | d934244 | 2018-09-10 13:59:41 +0200 | [diff] [blame] | 328 | SetSettingIfFlagSet(FLAG_experimental_agc_analyze_before_aec, |
| 329 | &settings.experimental_agc_analyze_before_aec); |
| 330 | SetSettingIfFlagSet(FLAG_experimental_agc_agc2_level_estimator, |
| 331 | &settings.use_experimental_agc_agc2_level_estimator); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 332 | SetSettingIfSpecified(FLAG_agc_mode, &settings.agc_mode); |
| 333 | SetSettingIfSpecified(FLAG_agc_target_level, &settings.agc_target_level); |
| 334 | SetSettingIfFlagSet(FLAG_agc_limiter, &settings.use_agc_limiter); |
| 335 | SetSettingIfSpecified(FLAG_agc_compression_gain, |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 336 | &settings.agc_compression_gain); |
Per Åhgren | e4d23b1 | 2018-10-02 23:40:07 +0200 | [diff] [blame] | 337 | SetSettingIfFlagSet(FLAG_agc2_enable_adaptive_gain, |
| 338 | &settings.agc2_use_adaptive_gain); |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 339 | settings.agc2_fixed_gain_db = FLAG_agc2_fixed_gain_db; |
Alessio Bazzica | 6817038 | 2018-11-20 12:27:20 +0100 | [diff] [blame] | 340 | settings.agc2_adaptive_level_estimator = |
| 341 | MapAgc2AdaptiveLevelEstimator(FLAG_agc2_adaptive_level_estimator); |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 342 | settings.pre_amplifier_gain_factor = FLAG_pre_amplifier_gain_factor; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 343 | SetSettingIfSpecified(FLAG_vad_likelihood, &settings.vad_likelihood); |
| 344 | SetSettingIfSpecified(FLAG_ns_level, &settings.ns_level); |
| 345 | SetSettingIfSpecified(FLAG_stream_delay, &settings.stream_delay); |
Per Åhgren | c5efb0c | 2018-05-28 09:10:59 +0200 | [diff] [blame] | 346 | SetSettingIfFlagSet(FLAG_use_stream_delay, &settings.use_stream_delay); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 347 | SetSettingIfSpecified(FLAG_stream_drift_samples, |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 348 | &settings.stream_drift_samples); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 349 | SetSettingIfSpecified(FLAG_custom_call_order_file, |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 350 | &settings.call_order_input_filename); |
| 351 | SetSettingIfSpecified(FLAG_output_custom_call_order_file, |
| 352 | &settings.call_order_output_filename); |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 353 | SetSettingIfSpecified(FLAG_aec_settings, &settings.aec_settings_filename); |
Alessio Bazzica | ca90a55 | 2017-09-27 11:51:10 +0200 | [diff] [blame] | 354 | settings.initial_mic_level = FLAG_initial_mic_level; |
| 355 | settings.simulate_mic_gain = FLAG_simulate_mic_gain; |
| 356 | SetSettingIfSpecified(FLAG_simulated_mic_kind, &settings.simulated_mic_kind); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 357 | settings.report_performance = FLAG_performance_report; |
Per Åhgren | ada9b89 | 2019-04-03 16:06:42 +0200 | [diff] [blame] | 358 | SetSettingIfSpecified(FLAG_performance_report_output_file, |
| 359 | &settings.performance_report_output_filename); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 360 | settings.use_verbose_logging = FLAG_verbose; |
Per Åhgren | 5a72a5e | 2018-08-24 07:18:24 +0200 | [diff] [blame] | 361 | settings.use_quiet_output = FLAG_quiet; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 362 | settings.report_bitexactness = FLAG_bitexactness_report; |
| 363 | settings.discard_all_settings_in_aecdump = FLAG_discard_settings_in_aecdump; |
| 364 | settings.fixed_interface = FLAG_fixed_interface; |
| 365 | settings.store_intermediate_output = FLAG_store_intermediate_output; |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 366 | settings.print_aec_parameter_values = FLAG_print_aec_parameter_values; |
Per Åhgren | 7a95e0f | 2018-10-25 09:56:49 +0200 | [diff] [blame] | 367 | settings.dump_internal_data = FLAG_dump_data; |
Alessio Bazzica | 4bc6045 | 2018-11-20 12:44:15 +0100 | [diff] [blame] | 368 | SetSettingIfSpecified(FLAG_dump_data_output_dir, |
| 369 | &settings.dump_internal_data_output_dir); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 370 | |
| 371 | return settings; |
| 372 | } |
| 373 | |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 374 | void ReportConditionalErrorAndExit(bool condition, const std::string& message) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 375 | if (condition) { |
| 376 | std::cerr << message << std::endl; |
| 377 | exit(1); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | void PerformBasicParameterSanityChecks(const SimulationSettings& settings) { |
| 382 | if (settings.input_filename || settings.reverse_input_filename) { |
| 383 | ReportConditionalErrorAndExit(!!settings.aec_dump_input_filename, |
| 384 | "Error: The aec dump cannot be specified " |
| 385 | "together with input wav files!\n"); |
| 386 | |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame] | 387 | ReportConditionalErrorAndExit(!!settings.artificial_nearend_filename, |
| 388 | "Error: The artificial nearend cannot be " |
| 389 | "specified together with input wav files!\n"); |
| 390 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 391 | ReportConditionalErrorAndExit(!settings.input_filename, |
| 392 | "Error: When operating at wav files, the " |
| 393 | "input wav filename must be " |
| 394 | "specified!\n"); |
| 395 | |
| 396 | ReportConditionalErrorAndExit( |
| 397 | settings.reverse_output_filename && !settings.reverse_input_filename, |
| 398 | "Error: When operating at wav files, the reverse input wav filename " |
| 399 | "must be specified if the reverse output wav filename is specified!\n"); |
| 400 | } else { |
| 401 | ReportConditionalErrorAndExit(!settings.aec_dump_input_filename, |
| 402 | "Error: Either the aec dump or the wav " |
| 403 | "input files must be specified!\n"); |
| 404 | } |
| 405 | |
| 406 | ReportConditionalErrorAndExit( |
| 407 | settings.use_aec && *settings.use_aec && settings.use_aecm && |
| 408 | *settings.use_aecm, |
| 409 | "Error: The AEC and the AECM cannot be activated at the same time!\n"); |
| 410 | |
| 411 | ReportConditionalErrorAndExit( |
| 412 | settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0, |
| 413 | "Error: --output_sample_rate_hz must be positive!\n"); |
| 414 | |
| 415 | ReportConditionalErrorAndExit( |
| 416 | settings.reverse_output_sample_rate_hz && |
| 417 | settings.output_sample_rate_hz && |
| 418 | *settings.output_sample_rate_hz <= 0, |
| 419 | "Error: --reverse_output_sample_rate_hz must be positive!\n"); |
| 420 | |
| 421 | ReportConditionalErrorAndExit( |
| 422 | settings.output_num_channels && *settings.output_num_channels <= 0, |
| 423 | "Error: --output_num_channels must be positive!\n"); |
| 424 | |
| 425 | ReportConditionalErrorAndExit( |
| 426 | settings.reverse_output_num_channels && |
| 427 | *settings.reverse_output_num_channels <= 0, |
| 428 | "Error: --reverse_output_num_channels must be positive!\n"); |
| 429 | |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 430 | ReportConditionalErrorAndExit(settings.aec_suppression_level && |
| 431 | ((*settings.aec_suppression_level) < 1 || |
| 432 | (*settings.aec_suppression_level) > 2), |
| 433 | "Error: --aec_suppression_level must be " |
| 434 | "specified between 1 and 2. 0 is " |
| 435 | "deprecated.\n"); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 436 | |
| 437 | ReportConditionalErrorAndExit( |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 438 | settings.agc_target_level && ((*settings.agc_target_level) < 0 || |
| 439 | (*settings.agc_target_level) > 31), |
| 440 | "Error: --agc_target_level must be specified between 0 and 31.\n"); |
| 441 | |
| 442 | ReportConditionalErrorAndExit( |
| 443 | settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 || |
| 444 | (*settings.agc_compression_gain) > 90), |
| 445 | "Error: --agc_compression_gain must be specified between 0 and 90.\n"); |
| 446 | |
| 447 | ReportConditionalErrorAndExit( |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 448 | settings.use_agc2 && *settings.use_agc2 && |
| 449 | ((settings.agc2_fixed_gain_db) < 0 || |
| 450 | (settings.agc2_fixed_gain_db) > 90), |
| 451 | "Error: --agc2_fixed_gain_db must be specified between 0 and 90.\n"); |
| 452 | |
| 453 | ReportConditionalErrorAndExit( |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 454 | settings.vad_likelihood && |
| 455 | ((*settings.vad_likelihood) < 0 || (*settings.vad_likelihood) > 3), |
| 456 | "Error: --vad_likelihood must be specified between 0 and 3.\n"); |
| 457 | |
| 458 | ReportConditionalErrorAndExit( |
| 459 | settings.ns_level && |
| 460 | ((*settings.ns_level) < 0 || (*settings.ns_level) > 3), |
| 461 | "Error: --ns_level must be specified between 0 and 3.\n"); |
| 462 | |
| 463 | ReportConditionalErrorAndExit( |
| 464 | settings.report_bitexactness && !settings.aec_dump_input_filename, |
| 465 | "Error: --bitexactness_report can only be used when operating on an " |
| 466 | "aecdump\n"); |
| 467 | |
peah | 5ad5de3 | 2016-12-09 03:18:22 -0800 | [diff] [blame] | 468 | ReportConditionalErrorAndExit( |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 469 | settings.call_order_input_filename && settings.aec_dump_input_filename, |
peah | 5ad5de3 | 2016-12-09 03:18:22 -0800 | [diff] [blame] | 470 | "Error: --custom_call_order_file cannot be used when operating on an " |
| 471 | "aecdump\n"); |
| 472 | |
Alessio Bazzica | ca90a55 | 2017-09-27 11:51:10 +0200 | [diff] [blame] | 473 | ReportConditionalErrorAndExit( |
| 474 | (settings.initial_mic_level < 0 || settings.initial_mic_level > 255), |
| 475 | "Error: --initial_mic_level must be specified between 0 and 255.\n"); |
| 476 | |
| 477 | ReportConditionalErrorAndExit( |
| 478 | settings.simulated_mic_kind && !settings.simulate_mic_gain, |
| 479 | "Error: --simulated_mic_kind cannot be specified when mic simulation is " |
| 480 | "disabled\n"); |
| 481 | |
| 482 | ReportConditionalErrorAndExit( |
| 483 | !settings.simulated_mic_kind && settings.simulate_mic_gain, |
| 484 | "Error: --simulated_mic_kind must be specified when mic simulation is " |
| 485 | "enabled\n"); |
| 486 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 487 | auto valid_wav_name = [](const std::string& wav_file_name) { |
| 488 | if (wav_file_name.size() < 5) { |
| 489 | return false; |
| 490 | } |
| 491 | if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) || |
| 492 | (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) { |
| 493 | return true; |
| 494 | } |
| 495 | return false; |
| 496 | }; |
| 497 | |
| 498 | ReportConditionalErrorAndExit( |
| 499 | settings.input_filename && (!valid_wav_name(*settings.input_filename)), |
| 500 | "Error: --i must be a valid .wav file name.\n"); |
| 501 | |
| 502 | ReportConditionalErrorAndExit( |
| 503 | settings.output_filename && (!valid_wav_name(*settings.output_filename)), |
| 504 | "Error: --o must be a valid .wav file name.\n"); |
| 505 | |
| 506 | ReportConditionalErrorAndExit( |
| 507 | settings.reverse_input_filename && |
| 508 | (!valid_wav_name(*settings.reverse_input_filename)), |
| 509 | "Error: --ri must be a valid .wav file name.\n"); |
| 510 | |
| 511 | ReportConditionalErrorAndExit( |
| 512 | settings.reverse_output_filename && |
| 513 | (!valid_wav_name(*settings.reverse_output_filename)), |
| 514 | "Error: --ro must be a valid .wav file name.\n"); |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame] | 515 | |
| 516 | ReportConditionalErrorAndExit( |
| 517 | settings.artificial_nearend_filename && |
| 518 | !valid_wav_name(*settings.artificial_nearend_filename), |
| 519 | "Error: --artifical_nearend must be a valid .wav file name.\n"); |
Per Åhgren | 7a95e0f | 2018-10-25 09:56:49 +0200 | [diff] [blame] | 520 | |
| 521 | ReportConditionalErrorAndExit( |
| 522 | WEBRTC_APM_DEBUG_DUMP == 0 && settings.dump_internal_data, |
| 523 | "Error: --dump_data cannot be set without proper build support.\n"); |
Alessio Bazzica | 4bc6045 | 2018-11-20 12:44:15 +0100 | [diff] [blame] | 524 | |
| 525 | ReportConditionalErrorAndExit( |
| 526 | !settings.dump_internal_data && |
| 527 | settings.dump_internal_data_output_dir.has_value(), |
| 528 | "Error: --dump_data_output_dir cannot be set without --dump_data.\n"); |
Ivo Creusen | 9a66d5e | 2019-03-13 13:55:12 +0100 | [diff] [blame] | 529 | |
| 530 | ReportConditionalErrorAndExit( |
| 531 | !settings.aec_dump_input_filename && |
| 532 | settings.call_order_output_filename.has_value(), |
| 533 | "Error: --output_custom_call_order_file needs an AEC dump input file.\n"); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | } // namespace |
| 537 | |
Ivo Creusen | 2cb4105 | 2018-03-15 12:22:52 +0100 | [diff] [blame] | 538 | int AudioprocFloatImpl(std::unique_ptr<AudioProcessingBuilder> ap_builder, |
| 539 | int argc, |
| 540 | char* argv[]) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 541 | if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help || |
| 542 | argc != 1) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 543 | printf("%s", kUsageDescription); |
| 544 | if (FLAG_help) { |
| 545 | rtc::FlagList::Print(nullptr, false); |
| 546 | return 0; |
| 547 | } |
| 548 | return 1; |
| 549 | } |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 550 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 551 | SimulationSettings settings = CreateSettings(); |
| 552 | PerformBasicParameterSanityChecks(settings); |
| 553 | std::unique_ptr<AudioProcessingSimulator> processor; |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 554 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 555 | if (settings.aec_dump_input_filename) { |
Ivo Creusen | 8c812f3 | 2018-03-09 17:33:04 +0100 | [diff] [blame] | 556 | processor.reset(new AecDumpBasedSimulator(settings, std::move(ap_builder))); |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 557 | } else { |
Ivo Creusen | 8c812f3 | 2018-03-09 17:33:04 +0100 | [diff] [blame] | 558 | processor.reset(new WavBasedSimulator(settings, std::move(ap_builder))); |
andrew | bdafe31 | 2015-10-29 23:42:54 -0700 | [diff] [blame] | 559 | } |
| 560 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 561 | processor->Process(); |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 562 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 563 | if (settings.report_performance) { |
Per Åhgren | ada9b89 | 2019-04-03 16:06:42 +0200 | [diff] [blame] | 564 | processor->GetApiCallStatistics().PrintReport(); |
| 565 | } |
| 566 | if (settings.performance_report_output_filename) { |
| 567 | processor->GetApiCallStatistics().WriteReportToFile( |
| 568 | *settings.performance_report_output_filename); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | if (settings.report_bitexactness && settings.aec_dump_input_filename) { |
| 572 | if (processor->OutputWasBitexact()) { |
| 573 | std::cout << "The processing was bitexact."; |
| 574 | } else { |
| 575 | std::cout << "The processing was not bitexact."; |
| 576 | } |
Alejandro Luebs | 5d22c00 | 2015-04-15 11:26:40 -0700 | [diff] [blame] | 577 | } |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 578 | |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 579 | return 0; |
| 580 | } |
| 581 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 582 | } // namespace test |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 583 | } // namespace webrtc |