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