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