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