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 | |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 11 | #include <iostream> |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 12 | #include <memory> |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 13 | |
| 14 | #include <string.h> |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 15 | |
| 16 | #include "gflags/gflags.h" |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 18 | #include "webrtc/modules/audio_processing/test/aec_dump_based_simulator.h" |
| 19 | #include "webrtc/modules/audio_processing/test/audio_processing_simulator.h" |
| 20 | #include "webrtc/modules/audio_processing/test/wav_based_simulator.h" |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 21 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 22 | namespace webrtc { |
| 23 | namespace test { |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 24 | namespace { |
| 25 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 26 | const int kParameterNotSpecifiedValue = -10000; |
| 27 | |
| 28 | const char kUsageDescription[] = |
| 29 | "Usage: audioproc_f [options] -i <input.wav>\n" |
| 30 | " or\n" |
| 31 | " audioproc_f [options] -dump_input <aec_dump>\n" |
| 32 | "\n\n" |
| 33 | "Command-line tool to simulate a call using the audio " |
| 34 | "processing module, either based on wav files or " |
| 35 | "protobuf debug dump recordings."; |
| 36 | |
| 37 | DEFINE_string(dump_input, "", "Aec dump input filename"); |
| 38 | DEFINE_string(dump_output, "", "Aec dump output filename"); |
| 39 | DEFINE_string(i, "", "Forward stream input wav filename"); |
| 40 | DEFINE_string(o, "", "Forward stream output wav filename"); |
| 41 | DEFINE_string(ri, "", "Reverse stream input wav filename"); |
| 42 | DEFINE_string(ro, "", "Reverse stream output wav filename"); |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame^] | 43 | DEFINE_string(artificial_nearend, "", "Artificial nearend wav filename"); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 44 | DEFINE_int32(output_num_channels, |
| 45 | kParameterNotSpecifiedValue, |
| 46 | "Number of forward stream output channels"); |
| 47 | DEFINE_int32(reverse_output_num_channels, |
| 48 | kParameterNotSpecifiedValue, |
| 49 | "Number of Reverse stream output channels"); |
| 50 | DEFINE_int32(output_sample_rate_hz, |
| 51 | kParameterNotSpecifiedValue, |
| 52 | "Forward stream output sample rate in Hz"); |
| 53 | DEFINE_int32(reverse_output_sample_rate_hz, |
| 54 | kParameterNotSpecifiedValue, |
| 55 | "Reverse stream output sample rate in Hz"); |
| 56 | DEFINE_string(mic_positions, |
| 57 | "", |
| 58 | "Space delimited cartesian coordinates of microphones in " |
| 59 | "meters. The coordinates of each point are contiguous. For a " |
| 60 | "two element array: \"x1 y1 z1 x2 y2 z2\""); |
| 61 | DEFINE_int32(target_angle_degrees, |
| 62 | 90, |
| 63 | "The azimuth of the target in degrees (0-359). Only applies to " |
| 64 | "beamforming."); |
| 65 | DEFINE_bool(fixed_interface, |
| 66 | false, |
| 67 | "Use the fixed interface when operating on wav files"); |
| 68 | DEFINE_int32(aec, |
| 69 | kParameterNotSpecifiedValue, |
| 70 | "Activate (1) or deactivate(0) the echo canceller"); |
| 71 | DEFINE_int32(aecm, |
| 72 | kParameterNotSpecifiedValue, |
| 73 | "Activate (1) or deactivate(0) the mobile echo controller"); |
ivoc | 0bff12a | 2016-11-17 00:55:43 -0800 | [diff] [blame] | 74 | DEFINE_int32(ed, |
ivoc | 87d1a78 | 2016-11-14 07:55:03 -0800 | [diff] [blame] | 75 | kParameterNotSpecifiedValue, |
| 76 | "Activate (1) or deactivate (0) the residual echo detector"); |
ivoc | 0bff12a | 2016-11-17 00:55:43 -0800 | [diff] [blame] | 77 | DEFINE_string(ed_graph, "", "Output filename for graph of echo likelihood"); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 78 | DEFINE_int32(agc, |
| 79 | kParameterNotSpecifiedValue, |
| 80 | "Activate (1) or deactivate(0) the AGC"); |
| 81 | DEFINE_int32(hpf, |
| 82 | kParameterNotSpecifiedValue, |
| 83 | "Activate (1) or deactivate(0) the high-pass filter"); |
| 84 | DEFINE_int32(ns, |
| 85 | kParameterNotSpecifiedValue, |
| 86 | "Activate (1) or deactivate(0) the noise suppressor"); |
| 87 | DEFINE_int32(ts, |
| 88 | kParameterNotSpecifiedValue, |
| 89 | "Activate (1) or deactivate(0) the transient suppressor"); |
| 90 | DEFINE_int32(bf, |
| 91 | kParameterNotSpecifiedValue, |
| 92 | "Activate (1) or deactivate(0) the beamformer"); |
| 93 | DEFINE_int32(ie, |
| 94 | kParameterNotSpecifiedValue, |
| 95 | "Activate (1) or deactivate(0) the intelligibility enhancer"); |
| 96 | DEFINE_int32(vad, |
| 97 | kParameterNotSpecifiedValue, |
| 98 | "Activate (1) or deactivate(0) the voice activity detector"); |
| 99 | DEFINE_int32(le, |
| 100 | kParameterNotSpecifiedValue, |
| 101 | "Activate (1) or deactivate(0) the level estimator"); |
| 102 | DEFINE_bool(all_default, |
| 103 | false, |
| 104 | "Activate all of the default components (will be overridden by any " |
| 105 | "other settings)"); |
| 106 | DEFINE_int32(aec_suppression_level, |
| 107 | kParameterNotSpecifiedValue, |
| 108 | "Set the aec suppression level (0-2)"); |
| 109 | DEFINE_int32(delay_agnostic, |
| 110 | kParameterNotSpecifiedValue, |
| 111 | "Activate (1) or deactivate(0) the AEC delay agnostic mode"); |
| 112 | DEFINE_int32(extended_filter, |
| 113 | kParameterNotSpecifiedValue, |
| 114 | "Activate (1) or deactivate(0) the AEC extended filter mode"); |
| 115 | DEFINE_int32(drift_compensation, |
| 116 | kParameterNotSpecifiedValue, |
| 117 | "Activate (1) or deactivate(0) the drift compensation"); |
| 118 | DEFINE_int32(aec3, |
| 119 | kParameterNotSpecifiedValue, |
| 120 | "Activate (1) or deactivate(0) the experimental AEC mode AEC3"); |
peah | ca4cac7 | 2016-06-29 15:26:12 -0700 | [diff] [blame] | 121 | DEFINE_int32(lc, |
| 122 | kParameterNotSpecifiedValue, |
| 123 | "Activate (1) or deactivate(0) the level control"); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 124 | DEFINE_int32( |
| 125 | refined_adaptive_filter, |
| 126 | kParameterNotSpecifiedValue, |
| 127 | "Activate (1) or deactivate(0) the refined adaptive filter functionality"); |
| 128 | DEFINE_int32(aecm_routing_mode, |
| 129 | kParameterNotSpecifiedValue, |
| 130 | "Specify the AECM routing mode (0-4)"); |
| 131 | DEFINE_int32(aecm_comfort_noise, |
| 132 | kParameterNotSpecifiedValue, |
| 133 | "Activate (1) or deactivate(0) the AECM comfort noise"); |
| 134 | DEFINE_int32(agc_mode, |
| 135 | kParameterNotSpecifiedValue, |
| 136 | "Specify the AGC mode (0-2)"); |
| 137 | DEFINE_int32(agc_target_level, |
| 138 | kParameterNotSpecifiedValue, |
| 139 | "Specify the AGC target level (0-31)"); |
| 140 | DEFINE_int32(agc_limiter, |
| 141 | kParameterNotSpecifiedValue, |
| 142 | "Activate (1) or deactivate(0) the level estimator"); |
| 143 | DEFINE_int32(agc_compression_gain, |
| 144 | kParameterNotSpecifiedValue, |
| 145 | "Specify the AGC compression gain (0-90)"); |
| 146 | DEFINE_int32(vad_likelihood, |
| 147 | kParameterNotSpecifiedValue, |
| 148 | "Specify the VAD likelihood (0-3)"); |
| 149 | DEFINE_int32(ns_level, |
| 150 | kParameterNotSpecifiedValue, |
| 151 | "Specify the NS level (0-3)"); |
| 152 | DEFINE_int32(stream_delay, |
| 153 | kParameterNotSpecifiedValue, |
| 154 | "Specify the stream delay in ms to use"); |
| 155 | DEFINE_int32(stream_drift_samples, |
| 156 | kParameterNotSpecifiedValue, |
| 157 | "Specify the number of stream drift samples to use"); |
| 158 | DEFINE_bool(performance_report, false, "Report the APM performance "); |
| 159 | DEFINE_bool(verbose, false, "Produce verbose output"); |
| 160 | DEFINE_bool(bitexactness_report, |
| 161 | false, |
| 162 | "Report bitexactness for aec dump result reproduction"); |
| 163 | DEFINE_bool(discard_settings_in_aecdump, |
| 164 | false, |
| 165 | "Discard any config settings specified in the aec dump"); |
| 166 | DEFINE_bool(store_intermediate_output, |
| 167 | false, |
| 168 | "Creates new output files after each init"); |
| 169 | |
| 170 | void SetSettingIfSpecified(const std::string value, |
| 171 | rtc::Optional<std::string>* parameter) { |
| 172 | if (value.compare("") != 0) { |
| 173 | *parameter = rtc::Optional<std::string>(value); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void SetSettingIfSpecified(int value, rtc::Optional<int>* parameter) { |
| 178 | if (value != kParameterNotSpecifiedValue) { |
| 179 | *parameter = rtc::Optional<int>(value); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | void SetSettingIfFlagSet(int32_t flag, rtc::Optional<bool>* parameter) { |
| 184 | if (flag == 0) { |
| 185 | *parameter = rtc::Optional<bool>(false); |
| 186 | } else if (flag == 1) { |
| 187 | *parameter = rtc::Optional<bool>(true); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | SimulationSettings CreateSettings() { |
| 192 | SimulationSettings settings; |
| 193 | if (FLAGS_all_default) { |
| 194 | settings.use_le = rtc::Optional<bool>(true); |
| 195 | settings.use_vad = rtc::Optional<bool>(true); |
| 196 | settings.use_ie = rtc::Optional<bool>(false); |
| 197 | settings.use_bf = rtc::Optional<bool>(false); |
| 198 | settings.use_ts = rtc::Optional<bool>(true); |
| 199 | settings.use_ns = rtc::Optional<bool>(true); |
| 200 | settings.use_hpf = rtc::Optional<bool>(true); |
| 201 | settings.use_agc = rtc::Optional<bool>(true); |
| 202 | settings.use_aec = rtc::Optional<bool>(true); |
| 203 | settings.use_aecm = rtc::Optional<bool>(false); |
ivoc | 0bff12a | 2016-11-17 00:55:43 -0800 | [diff] [blame] | 204 | settings.use_ed = rtc::Optional<bool>(false); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 205 | } |
| 206 | SetSettingIfSpecified(FLAGS_dump_input, &settings.aec_dump_input_filename); |
| 207 | SetSettingIfSpecified(FLAGS_dump_output, &settings.aec_dump_output_filename); |
| 208 | SetSettingIfSpecified(FLAGS_i, &settings.input_filename); |
| 209 | SetSettingIfSpecified(FLAGS_o, &settings.output_filename); |
| 210 | SetSettingIfSpecified(FLAGS_ri, &settings.reverse_input_filename); |
| 211 | SetSettingIfSpecified(FLAGS_ro, &settings.reverse_output_filename); |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame^] | 212 | SetSettingIfSpecified(FLAGS_artificial_nearend, |
| 213 | &settings.artificial_nearend_filename); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 214 | SetSettingIfSpecified(FLAGS_output_num_channels, |
| 215 | &settings.output_num_channels); |
| 216 | SetSettingIfSpecified(FLAGS_reverse_output_num_channels, |
| 217 | &settings.reverse_output_num_channels); |
| 218 | SetSettingIfSpecified(FLAGS_output_sample_rate_hz, |
| 219 | &settings.output_sample_rate_hz); |
| 220 | SetSettingIfSpecified(FLAGS_reverse_output_sample_rate_hz, |
| 221 | &settings.reverse_output_sample_rate_hz); |
| 222 | SetSettingIfSpecified(FLAGS_mic_positions, &settings.microphone_positions); |
| 223 | settings.target_angle_degrees = FLAGS_target_angle_degrees; |
| 224 | SetSettingIfFlagSet(FLAGS_aec, &settings.use_aec); |
| 225 | SetSettingIfFlagSet(FLAGS_aecm, &settings.use_aecm); |
ivoc | 0bff12a | 2016-11-17 00:55:43 -0800 | [diff] [blame] | 226 | SetSettingIfFlagSet(FLAGS_ed, &settings.use_ed); |
| 227 | SetSettingIfSpecified(FLAGS_ed_graph, &settings.ed_graph_output_filename); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 228 | SetSettingIfFlagSet(FLAGS_agc, &settings.use_agc); |
| 229 | SetSettingIfFlagSet(FLAGS_hpf, &settings.use_hpf); |
| 230 | SetSettingIfFlagSet(FLAGS_ns, &settings.use_ns); |
| 231 | SetSettingIfFlagSet(FLAGS_ts, &settings.use_ts); |
| 232 | SetSettingIfFlagSet(FLAGS_bf, &settings.use_bf); |
| 233 | SetSettingIfFlagSet(FLAGS_ie, &settings.use_ie); |
| 234 | SetSettingIfFlagSet(FLAGS_vad, &settings.use_vad); |
| 235 | SetSettingIfFlagSet(FLAGS_le, &settings.use_le); |
| 236 | SetSettingIfSpecified(FLAGS_aec_suppression_level, |
| 237 | &settings.aec_suppression_level); |
| 238 | SetSettingIfFlagSet(FLAGS_delay_agnostic, &settings.use_delay_agnostic); |
| 239 | SetSettingIfFlagSet(FLAGS_extended_filter, &settings.use_extended_filter); |
| 240 | SetSettingIfFlagSet(FLAGS_drift_compensation, |
| 241 | &settings.use_drift_compensation); |
| 242 | SetSettingIfFlagSet(FLAGS_refined_adaptive_filter, |
| 243 | &settings.use_refined_adaptive_filter); |
| 244 | |
| 245 | SetSettingIfFlagSet(FLAGS_aec3, &settings.use_aec3); |
peah | ca4cac7 | 2016-06-29 15:26:12 -0700 | [diff] [blame] | 246 | SetSettingIfFlagSet(FLAGS_lc, &settings.use_lc); |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 247 | SetSettingIfSpecified(FLAGS_aecm_routing_mode, &settings.aecm_routing_mode); |
| 248 | SetSettingIfFlagSet(FLAGS_aecm_comfort_noise, |
| 249 | &settings.use_aecm_comfort_noise); |
| 250 | SetSettingIfSpecified(FLAGS_agc_mode, &settings.agc_mode); |
| 251 | SetSettingIfSpecified(FLAGS_agc_target_level, &settings.agc_target_level); |
| 252 | SetSettingIfFlagSet(FLAGS_agc_limiter, &settings.use_agc_limiter); |
| 253 | SetSettingIfSpecified(FLAGS_agc_compression_gain, |
| 254 | &settings.agc_compression_gain); |
| 255 | SetSettingIfSpecified(FLAGS_vad_likelihood, &settings.vad_likelihood); |
| 256 | SetSettingIfSpecified(FLAGS_ns_level, &settings.ns_level); |
| 257 | SetSettingIfSpecified(FLAGS_stream_delay, &settings.stream_delay); |
| 258 | SetSettingIfSpecified(FLAGS_stream_drift_samples, |
| 259 | &settings.stream_drift_samples); |
| 260 | settings.report_performance = FLAGS_performance_report; |
| 261 | settings.use_verbose_logging = FLAGS_verbose; |
| 262 | settings.report_bitexactness = FLAGS_bitexactness_report; |
| 263 | settings.discard_all_settings_in_aecdump = FLAGS_discard_settings_in_aecdump; |
| 264 | settings.fixed_interface = FLAGS_fixed_interface; |
| 265 | settings.store_intermediate_output = FLAGS_store_intermediate_output; |
| 266 | |
| 267 | return settings; |
| 268 | } |
| 269 | |
| 270 | void ReportConditionalErrorAndExit(bool condition, std::string message) { |
| 271 | if (condition) { |
| 272 | std::cerr << message << std::endl; |
| 273 | exit(1); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | void PerformBasicParameterSanityChecks(const SimulationSettings& settings) { |
| 278 | if (settings.input_filename || settings.reverse_input_filename) { |
| 279 | ReportConditionalErrorAndExit(!!settings.aec_dump_input_filename, |
| 280 | "Error: The aec dump cannot be specified " |
| 281 | "together with input wav files!\n"); |
| 282 | |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame^] | 283 | ReportConditionalErrorAndExit(!!settings.artificial_nearend_filename, |
| 284 | "Error: The artificial nearend cannot be " |
| 285 | "specified together with input wav files!\n"); |
| 286 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 287 | ReportConditionalErrorAndExit(!settings.input_filename, |
| 288 | "Error: When operating at wav files, the " |
| 289 | "input wav filename must be " |
| 290 | "specified!\n"); |
| 291 | |
| 292 | ReportConditionalErrorAndExit( |
| 293 | settings.reverse_output_filename && !settings.reverse_input_filename, |
| 294 | "Error: When operating at wav files, the reverse input wav filename " |
| 295 | "must be specified if the reverse output wav filename is specified!\n"); |
| 296 | } else { |
| 297 | ReportConditionalErrorAndExit(!settings.aec_dump_input_filename, |
| 298 | "Error: Either the aec dump or the wav " |
| 299 | "input files must be specified!\n"); |
| 300 | } |
| 301 | |
| 302 | ReportConditionalErrorAndExit( |
| 303 | settings.use_aec && *settings.use_aec && settings.use_aecm && |
| 304 | *settings.use_aecm, |
| 305 | "Error: The AEC and the AECM cannot be activated at the same time!\n"); |
| 306 | |
| 307 | ReportConditionalErrorAndExit( |
| 308 | settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0, |
| 309 | "Error: --output_sample_rate_hz must be positive!\n"); |
| 310 | |
| 311 | ReportConditionalErrorAndExit( |
| 312 | settings.reverse_output_sample_rate_hz && |
| 313 | settings.output_sample_rate_hz && |
| 314 | *settings.output_sample_rate_hz <= 0, |
| 315 | "Error: --reverse_output_sample_rate_hz must be positive!\n"); |
| 316 | |
| 317 | ReportConditionalErrorAndExit( |
| 318 | settings.output_num_channels && *settings.output_num_channels <= 0, |
| 319 | "Error: --output_num_channels must be positive!\n"); |
| 320 | |
| 321 | ReportConditionalErrorAndExit( |
| 322 | settings.reverse_output_num_channels && |
| 323 | *settings.reverse_output_num_channels <= 0, |
| 324 | "Error: --reverse_output_num_channels must be positive!\n"); |
| 325 | |
| 326 | ReportConditionalErrorAndExit( |
| 327 | settings.use_bf && *settings.use_bf && !settings.microphone_positions, |
| 328 | "Error: --mic_positions must be specified when the beamformer is " |
| 329 | "activated.\n"); |
| 330 | |
| 331 | ReportConditionalErrorAndExit( |
| 332 | settings.target_angle_degrees < 0 || settings.target_angle_degrees > 359, |
| 333 | "Error: -target_angle_degrees must be specified between 0 and 359.\n"); |
| 334 | |
| 335 | ReportConditionalErrorAndExit( |
| 336 | settings.aec_suppression_level && |
| 337 | ((*settings.aec_suppression_level) < 0 || |
| 338 | (*settings.aec_suppression_level) > 2), |
| 339 | "Error: --aec_suppression_level must be specified between 0 and 2.\n"); |
| 340 | |
| 341 | ReportConditionalErrorAndExit( |
| 342 | settings.aecm_routing_mode && ((*settings.aecm_routing_mode) < 0 || |
| 343 | (*settings.aecm_routing_mode) > 4), |
| 344 | "Error: --aecm_routing_mode must be specified between 0 and 4.\n"); |
| 345 | |
| 346 | ReportConditionalErrorAndExit( |
| 347 | settings.agc_target_level && ((*settings.agc_target_level) < 0 || |
| 348 | (*settings.agc_target_level) > 31), |
| 349 | "Error: --agc_target_level must be specified between 0 and 31.\n"); |
| 350 | |
| 351 | ReportConditionalErrorAndExit( |
| 352 | settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 || |
| 353 | (*settings.agc_compression_gain) > 90), |
| 354 | "Error: --agc_compression_gain must be specified between 0 and 90.\n"); |
| 355 | |
| 356 | ReportConditionalErrorAndExit( |
| 357 | settings.vad_likelihood && |
| 358 | ((*settings.vad_likelihood) < 0 || (*settings.vad_likelihood) > 3), |
| 359 | "Error: --vad_likelihood must be specified between 0 and 3.\n"); |
| 360 | |
| 361 | ReportConditionalErrorAndExit( |
| 362 | settings.ns_level && |
| 363 | ((*settings.ns_level) < 0 || (*settings.ns_level) > 3), |
| 364 | "Error: --ns_level must be specified between 0 and 3.\n"); |
| 365 | |
| 366 | ReportConditionalErrorAndExit( |
| 367 | settings.report_bitexactness && !settings.aec_dump_input_filename, |
| 368 | "Error: --bitexactness_report can only be used when operating on an " |
| 369 | "aecdump\n"); |
| 370 | |
| 371 | auto valid_wav_name = [](const std::string& wav_file_name) { |
| 372 | if (wav_file_name.size() < 5) { |
| 373 | return false; |
| 374 | } |
| 375 | if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) || |
| 376 | (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) { |
| 377 | return true; |
| 378 | } |
| 379 | return false; |
| 380 | }; |
| 381 | |
| 382 | ReportConditionalErrorAndExit( |
| 383 | settings.input_filename && (!valid_wav_name(*settings.input_filename)), |
| 384 | "Error: --i must be a valid .wav file name.\n"); |
| 385 | |
| 386 | ReportConditionalErrorAndExit( |
| 387 | settings.output_filename && (!valid_wav_name(*settings.output_filename)), |
| 388 | "Error: --o must be a valid .wav file name.\n"); |
| 389 | |
| 390 | ReportConditionalErrorAndExit( |
| 391 | settings.reverse_input_filename && |
| 392 | (!valid_wav_name(*settings.reverse_input_filename)), |
| 393 | "Error: --ri must be a valid .wav file name.\n"); |
| 394 | |
| 395 | ReportConditionalErrorAndExit( |
| 396 | settings.reverse_output_filename && |
| 397 | (!valid_wav_name(*settings.reverse_output_filename)), |
| 398 | "Error: --ro must be a valid .wav file name.\n"); |
peah | df80fd1 | 2016-12-09 02:43:40 -0800 | [diff] [blame^] | 399 | |
| 400 | ReportConditionalErrorAndExit( |
| 401 | settings.artificial_nearend_filename && |
| 402 | !valid_wav_name(*settings.artificial_nearend_filename), |
| 403 | "Error: --artifical_nearend must be a valid .wav file name.\n"); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | } // namespace |
| 407 | |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 408 | int main(int argc, char* argv[]) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 409 | google::SetUsageMessage(kUsageDescription); |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 410 | google::ParseCommandLineFlags(&argc, &argv, true); |
| 411 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 412 | SimulationSettings settings = CreateSettings(); |
| 413 | PerformBasicParameterSanityChecks(settings); |
| 414 | std::unique_ptr<AudioProcessingSimulator> processor; |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 415 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 416 | if (settings.aec_dump_input_filename) { |
| 417 | processor.reset(new AecDumpBasedSimulator(settings)); |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 418 | } else { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 419 | processor.reset(new WavBasedSimulator(settings)); |
andrew | bdafe31 | 2015-10-29 23:42:54 -0700 | [diff] [blame] | 420 | } |
| 421 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 422 | processor->Process(); |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 423 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 424 | if (settings.report_performance) { |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 425 | const auto& proc_time = processor->proc_time(); |
Niels Möller | d28db7f | 2016-05-10 16:31:47 +0200 | [diff] [blame] | 426 | int64_t exec_time_us = proc_time.sum / rtc::kNumNanosecsPerMicrosec; |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 427 | std::cout << std::endl |
| 428 | << "Execution time: " << exec_time_us * 1e-6 << " s, File time: " |
| 429 | << processor->get_num_process_stream_calls() * 1.f / |
| 430 | AudioProcessingSimulator::kChunksPerSecond |
| 431 | << std::endl |
| 432 | << "Time per fwd stream chunk (mean, max, min): " << std::endl |
| 433 | << exec_time_us * 1.f / processor->get_num_process_stream_calls() |
| 434 | << " us, " << 1.f * proc_time.max / rtc::kNumNanosecsPerMicrosec |
| 435 | << " us, " << 1.f * proc_time.min / rtc::kNumNanosecsPerMicrosec |
| 436 | << " us" << std::endl; |
| 437 | } |
| 438 | |
| 439 | if (settings.report_bitexactness && settings.aec_dump_input_filename) { |
| 440 | if (processor->OutputWasBitexact()) { |
| 441 | std::cout << "The processing was bitexact."; |
| 442 | } else { |
| 443 | std::cout << "The processing was not bitexact."; |
| 444 | } |
Alejandro Luebs | 5d22c00 | 2015-04-15 11:26:40 -0700 | [diff] [blame] | 445 | } |
aluebs | b0ad43b | 2015-11-20 00:11:53 -0800 | [diff] [blame] | 446 | |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 450 | } // namespace test |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 451 | } // namespace webrtc |
| 452 | |
| 453 | int main(int argc, char* argv[]) { |
peah | 60a189f | 2016-05-24 20:54:40 -0700 | [diff] [blame] | 454 | return webrtc::test::main(argc, argv); |
andrew@webrtc.org | 08df9b2 | 2014-12-16 20:57:15 +0000 | [diff] [blame] | 455 | } |