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