OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <stdio.h> | |
12 | |
13 #include <iostream> | 11 #include <iostream> |
14 #include <memory> | 12 #include <memory> |
15 #include <sstream> | 13 |
16 #include <string> | 14 #include <string.h> |
17 #include <utility> | |
18 | 15 |
19 #include "gflags/gflags.h" | 16 #include "gflags/gflags.h" |
20 #include "webrtc/base/checks.h" | |
21 #include "webrtc/base/format_macros.h" | |
22 #include "webrtc/common_audio/channel_buffer.h" | |
23 #include "webrtc/common_audio/wav_file.h" | |
24 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 17 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
25 #include "webrtc/modules/audio_processing/test/audio_file_processor.h" | 18 #include "webrtc/modules/audio_processing/test/aec_dump_based_simulator.h" |
26 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 19 #include "webrtc/modules/audio_processing/test/audio_processing_simulator.h" |
27 #include "webrtc/modules/audio_processing/test/test_utils.h" | 20 #include "webrtc/modules/audio_processing/test/wav_based_simulator.h" |
28 #include "webrtc/test/testsupport/trace_to_stderr.h" | 21 |
29 | 22 namespace webrtc { |
| 23 namespace test { |
30 namespace { | 24 namespace { |
31 | 25 |
32 bool ValidateOutChannels(const char* flagname, int32_t value) { | 26 const int kParameterNotSpecifiedValue = -10000; |
33 return value >= 0; | 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"); |
| 43 DEFINE_int32(output_num_channels, |
| 44 kParameterNotSpecifiedValue, |
| 45 "Number of forward stream output channels"); |
| 46 DEFINE_int32(reverse_output_num_channels, |
| 47 kParameterNotSpecifiedValue, |
| 48 "Number of Reverse stream output channels"); |
| 49 DEFINE_int32(output_sample_rate_hz, |
| 50 kParameterNotSpecifiedValue, |
| 51 "Forward stream output sample rate in Hz"); |
| 52 DEFINE_int32(reverse_output_sample_rate_hz, |
| 53 kParameterNotSpecifiedValue, |
| 54 "Reverse stream output sample rate in Hz"); |
| 55 DEFINE_string(mic_positions, |
| 56 "", |
| 57 "Space delimited cartesian coordinates of microphones in " |
| 58 "meters. The coordinates of each point are contiguous. For a " |
| 59 "two element array: \"x1 y1 z1 x2 y2 z2\""); |
| 60 DEFINE_int32(target_angle_degrees, |
| 61 90, |
| 62 "The azimuth of the target in degrees (0-359). Only applies to " |
| 63 "beamforming."); |
| 64 DEFINE_bool(fixed_interface, |
| 65 false, |
| 66 "Use the fixed interface when operating on wav files"); |
| 67 DEFINE_int32(aec, |
| 68 kParameterNotSpecifiedValue, |
| 69 "Activate (1) or deactivate(0) the echo canceller"); |
| 70 DEFINE_int32(aecm, |
| 71 kParameterNotSpecifiedValue, |
| 72 "Activate (1) or deactivate(0) the mobile echo controller"); |
| 73 DEFINE_int32(agc, |
| 74 kParameterNotSpecifiedValue, |
| 75 "Activate (1) or deactivate(0) the AGC"); |
| 76 DEFINE_int32(hpf, |
| 77 kParameterNotSpecifiedValue, |
| 78 "Activate (1) or deactivate(0) the high-pass filter"); |
| 79 DEFINE_int32(ns, |
| 80 kParameterNotSpecifiedValue, |
| 81 "Activate (1) or deactivate(0) the noise suppressor"); |
| 82 DEFINE_int32(ts, |
| 83 kParameterNotSpecifiedValue, |
| 84 "Activate (1) or deactivate(0) the transient suppressor"); |
| 85 DEFINE_int32(bf, |
| 86 kParameterNotSpecifiedValue, |
| 87 "Activate (1) or deactivate(0) the beamformer"); |
| 88 DEFINE_int32(ie, |
| 89 kParameterNotSpecifiedValue, |
| 90 "Activate (1) or deactivate(0) the intelligibility enhancer"); |
| 91 DEFINE_int32(vad, |
| 92 kParameterNotSpecifiedValue, |
| 93 "Activate (1) or deactivate(0) the voice activity detector"); |
| 94 DEFINE_int32(le, |
| 95 kParameterNotSpecifiedValue, |
| 96 "Activate (1) or deactivate(0) the level estimator"); |
| 97 DEFINE_bool(all_default, |
| 98 false, |
| 99 "Activate all of the default components (will be overridden by any " |
| 100 "other settings)"); |
| 101 DEFINE_int32(aec_suppression_level, |
| 102 kParameterNotSpecifiedValue, |
| 103 "Set the aec suppression level (0-2)"); |
| 104 DEFINE_int32(delay_agnostic, |
| 105 kParameterNotSpecifiedValue, |
| 106 "Activate (1) or deactivate(0) the AEC delay agnostic mode"); |
| 107 DEFINE_int32(extended_filter, |
| 108 kParameterNotSpecifiedValue, |
| 109 "Activate (1) or deactivate(0) the AEC extended filter mode"); |
| 110 DEFINE_int32(drift_compensation, |
| 111 kParameterNotSpecifiedValue, |
| 112 "Activate (1) or deactivate(0) the drift compensation"); |
| 113 DEFINE_int32(aec3, |
| 114 kParameterNotSpecifiedValue, |
| 115 "Activate (1) or deactivate(0) the experimental AEC mode AEC3"); |
| 116 DEFINE_int32( |
| 117 refined_adaptive_filter, |
| 118 kParameterNotSpecifiedValue, |
| 119 "Activate (1) or deactivate(0) the refined adaptive filter functionality"); |
| 120 DEFINE_int32(aecm_routing_mode, |
| 121 kParameterNotSpecifiedValue, |
| 122 "Specify the AECM routing mode (0-4)"); |
| 123 DEFINE_int32(aecm_comfort_noise, |
| 124 kParameterNotSpecifiedValue, |
| 125 "Activate (1) or deactivate(0) the AECM comfort noise"); |
| 126 DEFINE_int32(agc_mode, |
| 127 kParameterNotSpecifiedValue, |
| 128 "Specify the AGC mode (0-2)"); |
| 129 DEFINE_int32(agc_target_level, |
| 130 kParameterNotSpecifiedValue, |
| 131 "Specify the AGC target level (0-31)"); |
| 132 DEFINE_int32(agc_limiter, |
| 133 kParameterNotSpecifiedValue, |
| 134 "Activate (1) or deactivate(0) the level estimator"); |
| 135 DEFINE_int32(agc_compression_gain, |
| 136 kParameterNotSpecifiedValue, |
| 137 "Specify the AGC compression gain (0-90)"); |
| 138 DEFINE_int32(vad_likelihood, |
| 139 kParameterNotSpecifiedValue, |
| 140 "Specify the VAD likelihood (0-3)"); |
| 141 DEFINE_int32(ns_level, |
| 142 kParameterNotSpecifiedValue, |
| 143 "Specify the NS level (0-3)"); |
| 144 DEFINE_int32(stream_delay, |
| 145 kParameterNotSpecifiedValue, |
| 146 "Specify the stream delay in ms to use"); |
| 147 DEFINE_int32(stream_drift_samples, |
| 148 kParameterNotSpecifiedValue, |
| 149 "Specify the number of stream drift samples to use"); |
| 150 DEFINE_bool(performance_report, false, "Report the APM performance "); |
| 151 DEFINE_bool(verbose, false, "Produce verbose output"); |
| 152 DEFINE_bool(bitexactness_report, |
| 153 false, |
| 154 "Report bitexactness for aec dump result reproduction"); |
| 155 DEFINE_bool(discard_settings_in_aecdump, |
| 156 false, |
| 157 "Discard any config settings specified in the aec dump"); |
| 158 DEFINE_bool(store_intermediate_output, |
| 159 false, |
| 160 "Creates new output files after each init"); |
| 161 |
| 162 void SetSettingIfSpecified(const std::string value, |
| 163 rtc::Optional<std::string>* parameter) { |
| 164 if (value.compare("") != 0) { |
| 165 *parameter = rtc::Optional<std::string>(value); |
| 166 } |
| 167 } |
| 168 |
| 169 void SetSettingIfSpecified(int value, rtc::Optional<int>* parameter) { |
| 170 if (value != kParameterNotSpecifiedValue) { |
| 171 *parameter = rtc::Optional<int>(value); |
| 172 } |
| 173 } |
| 174 |
| 175 void SetSettingIfFlagSet(int32_t flag, rtc::Optional<bool>* parameter) { |
| 176 if (flag == 0) { |
| 177 *parameter = rtc::Optional<bool>(false); |
| 178 } else if (flag == 1) { |
| 179 *parameter = rtc::Optional<bool>(true); |
| 180 } |
| 181 } |
| 182 |
| 183 SimulationSettings CreateSettings() { |
| 184 SimulationSettings settings; |
| 185 if (FLAGS_all_default) { |
| 186 settings.use_le = rtc::Optional<bool>(true); |
| 187 settings.use_vad = rtc::Optional<bool>(true); |
| 188 settings.use_ie = rtc::Optional<bool>(false); |
| 189 settings.use_bf = rtc::Optional<bool>(false); |
| 190 settings.use_ts = rtc::Optional<bool>(true); |
| 191 settings.use_ns = rtc::Optional<bool>(true); |
| 192 settings.use_hpf = rtc::Optional<bool>(true); |
| 193 settings.use_agc = rtc::Optional<bool>(true); |
| 194 settings.use_aec = rtc::Optional<bool>(true); |
| 195 settings.use_aecm = rtc::Optional<bool>(false); |
| 196 } |
| 197 SetSettingIfSpecified(FLAGS_dump_input, &settings.aec_dump_input_filename); |
| 198 SetSettingIfSpecified(FLAGS_dump_output, &settings.aec_dump_output_filename); |
| 199 SetSettingIfSpecified(FLAGS_i, &settings.input_filename); |
| 200 SetSettingIfSpecified(FLAGS_o, &settings.output_filename); |
| 201 SetSettingIfSpecified(FLAGS_ri, &settings.reverse_input_filename); |
| 202 SetSettingIfSpecified(FLAGS_ro, &settings.reverse_output_filename); |
| 203 SetSettingIfSpecified(FLAGS_output_num_channels, |
| 204 &settings.output_num_channels); |
| 205 SetSettingIfSpecified(FLAGS_reverse_output_num_channels, |
| 206 &settings.reverse_output_num_channels); |
| 207 SetSettingIfSpecified(FLAGS_output_sample_rate_hz, |
| 208 &settings.output_sample_rate_hz); |
| 209 SetSettingIfSpecified(FLAGS_reverse_output_sample_rate_hz, |
| 210 &settings.reverse_output_sample_rate_hz); |
| 211 SetSettingIfSpecified(FLAGS_mic_positions, &settings.microphone_positions); |
| 212 settings.target_angle_degrees = FLAGS_target_angle_degrees; |
| 213 SetSettingIfFlagSet(FLAGS_aec, &settings.use_aec); |
| 214 SetSettingIfFlagSet(FLAGS_aecm, &settings.use_aecm); |
| 215 SetSettingIfFlagSet(FLAGS_agc, &settings.use_agc); |
| 216 SetSettingIfFlagSet(FLAGS_hpf, &settings.use_hpf); |
| 217 SetSettingIfFlagSet(FLAGS_ns, &settings.use_ns); |
| 218 SetSettingIfFlagSet(FLAGS_ts, &settings.use_ts); |
| 219 SetSettingIfFlagSet(FLAGS_bf, &settings.use_bf); |
| 220 SetSettingIfFlagSet(FLAGS_ie, &settings.use_ie); |
| 221 SetSettingIfFlagSet(FLAGS_vad, &settings.use_vad); |
| 222 SetSettingIfFlagSet(FLAGS_le, &settings.use_le); |
| 223 SetSettingIfSpecified(FLAGS_aec_suppression_level, |
| 224 &settings.aec_suppression_level); |
| 225 SetSettingIfFlagSet(FLAGS_delay_agnostic, &settings.use_delay_agnostic); |
| 226 SetSettingIfFlagSet(FLAGS_extended_filter, &settings.use_extended_filter); |
| 227 SetSettingIfFlagSet(FLAGS_drift_compensation, |
| 228 &settings.use_drift_compensation); |
| 229 SetSettingIfFlagSet(FLAGS_refined_adaptive_filter, |
| 230 &settings.use_refined_adaptive_filter); |
| 231 |
| 232 SetSettingIfFlagSet(FLAGS_aec3, &settings.use_aec3); |
| 233 SetSettingIfSpecified(FLAGS_aecm_routing_mode, &settings.aecm_routing_mode); |
| 234 SetSettingIfFlagSet(FLAGS_aecm_comfort_noise, |
| 235 &settings.use_aecm_comfort_noise); |
| 236 SetSettingIfSpecified(FLAGS_agc_mode, &settings.agc_mode); |
| 237 SetSettingIfSpecified(FLAGS_agc_target_level, &settings.agc_target_level); |
| 238 SetSettingIfFlagSet(FLAGS_agc_limiter, &settings.use_agc_limiter); |
| 239 SetSettingIfSpecified(FLAGS_agc_compression_gain, |
| 240 &settings.agc_compression_gain); |
| 241 SetSettingIfSpecified(FLAGS_vad_likelihood, &settings.vad_likelihood); |
| 242 SetSettingIfSpecified(FLAGS_ns_level, &settings.ns_level); |
| 243 SetSettingIfSpecified(FLAGS_stream_delay, &settings.stream_delay); |
| 244 SetSettingIfSpecified(FLAGS_stream_drift_samples, |
| 245 &settings.stream_drift_samples); |
| 246 settings.report_performance = FLAGS_performance_report; |
| 247 settings.use_verbose_logging = FLAGS_verbose; |
| 248 settings.report_bitexactness = FLAGS_bitexactness_report; |
| 249 settings.discard_all_settings_in_aecdump = FLAGS_discard_settings_in_aecdump; |
| 250 settings.fixed_interface = FLAGS_fixed_interface; |
| 251 settings.store_intermediate_output = FLAGS_store_intermediate_output; |
| 252 |
| 253 return settings; |
| 254 } |
| 255 |
| 256 void ReportConditionalErrorAndExit(bool condition, std::string message) { |
| 257 if (condition) { |
| 258 std::cerr << message << std::endl; |
| 259 exit(1); |
| 260 } |
| 261 } |
| 262 |
| 263 void PerformBasicParameterSanityChecks(const SimulationSettings& settings) { |
| 264 if (settings.input_filename || settings.reverse_input_filename) { |
| 265 ReportConditionalErrorAndExit(!!settings.aec_dump_input_filename, |
| 266 "Error: The aec dump cannot be specified " |
| 267 "together with input wav files!\n"); |
| 268 |
| 269 ReportConditionalErrorAndExit(!settings.input_filename, |
| 270 "Error: When operating at wav files, the " |
| 271 "input wav filename must be " |
| 272 "specified!\n"); |
| 273 |
| 274 ReportConditionalErrorAndExit( |
| 275 settings.reverse_output_filename && !settings.reverse_input_filename, |
| 276 "Error: When operating at wav files, the reverse input wav filename " |
| 277 "must be specified if the reverse output wav filename is specified!\n"); |
| 278 } else { |
| 279 ReportConditionalErrorAndExit(!settings.aec_dump_input_filename, |
| 280 "Error: Either the aec dump or the wav " |
| 281 "input files must be specified!\n"); |
| 282 } |
| 283 |
| 284 ReportConditionalErrorAndExit( |
| 285 settings.use_aec && *settings.use_aec && settings.use_aecm && |
| 286 *settings.use_aecm, |
| 287 "Error: The AEC and the AECM cannot be activated at the same time!\n"); |
| 288 |
| 289 ReportConditionalErrorAndExit( |
| 290 settings.output_sample_rate_hz && *settings.output_sample_rate_hz <= 0, |
| 291 "Error: --output_sample_rate_hz must be positive!\n"); |
| 292 |
| 293 ReportConditionalErrorAndExit( |
| 294 settings.reverse_output_sample_rate_hz && |
| 295 settings.output_sample_rate_hz && |
| 296 *settings.output_sample_rate_hz <= 0, |
| 297 "Error: --reverse_output_sample_rate_hz must be positive!\n"); |
| 298 |
| 299 ReportConditionalErrorAndExit( |
| 300 settings.output_num_channels && *settings.output_num_channels <= 0, |
| 301 "Error: --output_num_channels must be positive!\n"); |
| 302 |
| 303 ReportConditionalErrorAndExit( |
| 304 settings.reverse_output_num_channels && |
| 305 *settings.reverse_output_num_channels <= 0, |
| 306 "Error: --reverse_output_num_channels must be positive!\n"); |
| 307 |
| 308 ReportConditionalErrorAndExit( |
| 309 settings.use_bf && *settings.use_bf && !settings.microphone_positions, |
| 310 "Error: --mic_positions must be specified when the beamformer is " |
| 311 "activated.\n"); |
| 312 |
| 313 ReportConditionalErrorAndExit( |
| 314 settings.target_angle_degrees < 0 || settings.target_angle_degrees > 359, |
| 315 "Error: -target_angle_degrees must be specified between 0 and 359.\n"); |
| 316 |
| 317 ReportConditionalErrorAndExit( |
| 318 settings.aec_suppression_level && |
| 319 ((*settings.aec_suppression_level) < 0 || |
| 320 (*settings.aec_suppression_level) > 2), |
| 321 "Error: --aec_suppression_level must be specified between 0 and 2.\n"); |
| 322 |
| 323 ReportConditionalErrorAndExit( |
| 324 settings.aecm_routing_mode && ((*settings.aecm_routing_mode) < 0 || |
| 325 (*settings.aecm_routing_mode) > 4), |
| 326 "Error: --aecm_routing_mode must be specified between 0 and 4.\n"); |
| 327 |
| 328 ReportConditionalErrorAndExit( |
| 329 settings.agc_target_level && ((*settings.agc_target_level) < 0 || |
| 330 (*settings.agc_target_level) > 31), |
| 331 "Error: --agc_target_level must be specified between 0 and 31.\n"); |
| 332 |
| 333 ReportConditionalErrorAndExit( |
| 334 settings.agc_compression_gain && ((*settings.agc_compression_gain) < 0 || |
| 335 (*settings.agc_compression_gain) > 90), |
| 336 "Error: --agc_compression_gain must be specified between 0 and 90.\n"); |
| 337 |
| 338 ReportConditionalErrorAndExit( |
| 339 settings.vad_likelihood && |
| 340 ((*settings.vad_likelihood) < 0 || (*settings.vad_likelihood) > 3), |
| 341 "Error: --vad_likelihood must be specified between 0 and 3.\n"); |
| 342 |
| 343 ReportConditionalErrorAndExit( |
| 344 settings.ns_level && |
| 345 ((*settings.ns_level) < 0 || (*settings.ns_level) > 3), |
| 346 "Error: --ns_level must be specified between 0 and 3.\n"); |
| 347 |
| 348 ReportConditionalErrorAndExit( |
| 349 settings.report_bitexactness && !settings.aec_dump_input_filename, |
| 350 "Error: --bitexactness_report can only be used when operating on an " |
| 351 "aecdump\n"); |
| 352 |
| 353 auto valid_wav_name = [](const std::string& wav_file_name) { |
| 354 if (wav_file_name.size() < 5) { |
| 355 return false; |
| 356 } |
| 357 if ((wav_file_name.compare(wav_file_name.size() - 4, 4, ".wav") == 0) || |
| 358 (wav_file_name.compare(wav_file_name.size() - 4, 4, ".WAV") == 0)) { |
| 359 return true; |
| 360 } |
| 361 return false; |
| 362 }; |
| 363 |
| 364 ReportConditionalErrorAndExit( |
| 365 settings.input_filename && (!valid_wav_name(*settings.input_filename)), |
| 366 "Error: --i must be a valid .wav file name.\n"); |
| 367 |
| 368 ReportConditionalErrorAndExit( |
| 369 settings.output_filename && (!valid_wav_name(*settings.output_filename)), |
| 370 "Error: --o must be a valid .wav file name.\n"); |
| 371 |
| 372 ReportConditionalErrorAndExit( |
| 373 settings.reverse_input_filename && |
| 374 (!valid_wav_name(*settings.reverse_input_filename)), |
| 375 "Error: --ri must be a valid .wav file name.\n"); |
| 376 |
| 377 ReportConditionalErrorAndExit( |
| 378 settings.reverse_output_filename && |
| 379 (!valid_wav_name(*settings.reverse_output_filename)), |
| 380 "Error: --ro must be a valid .wav file name.\n"); |
34 } | 381 } |
35 | 382 |
36 } // namespace | 383 } // namespace |
37 | 384 |
38 DEFINE_string(dump, "", "Name of the aecdump debug file to read from."); | |
39 DEFINE_string(i, "", "Name of the capture input stream file to read from."); | |
40 DEFINE_string( | |
41 o, | |
42 "out.wav", | |
43 "Name of the output file to write the processed capture stream to."); | |
44 DEFINE_string(ri, "", "Name of the render input stream file to read from."); | |
45 DEFINE_string( | |
46 ro, | |
47 "out_reverse.wav", | |
48 "Name of the output file to write the processed render stream to."); | |
49 DEFINE_int32(out_channels, 1, "Number of output channels."); | |
50 const bool out_channels_dummy = | |
51 google::RegisterFlagValidator(&FLAGS_out_channels, &ValidateOutChannels); | |
52 DEFINE_int32(rev_out_channels, 1, "Number of reverse output channels."); | |
53 const bool rev_out_channels_dummy = | |
54 google::RegisterFlagValidator(&FLAGS_rev_out_channels, | |
55 &ValidateOutChannels); | |
56 DEFINE_int32(out_sample_rate, 48000, "Output sample rate in Hz."); | |
57 DEFINE_int32(rev_out_sample_rate, 48000, "Reverse output sample rate in Hz."); | |
58 DEFINE_string(mic_positions, "", | |
59 "Space delimited cartesian coordinates of microphones in meters. " | |
60 "The coordinates of each point are contiguous. " | |
61 "For a two element array: \"x1 y1 z1 x2 y2 z2\""); | |
62 DEFINE_double( | |
63 target_angle_degrees, | |
64 90, | |
65 "The azimuth of the target in degrees. Only applies to beamforming."); | |
66 | |
67 DEFINE_bool(aec, false, "Enable echo cancellation."); | |
68 DEFINE_bool(agc, false, "Enable automatic gain control."); | |
69 DEFINE_bool(hpf, false, "Enable high-pass filtering."); | |
70 DEFINE_bool(ns, false, "Enable noise suppression."); | |
71 DEFINE_bool(ts, false, "Enable transient suppression."); | |
72 DEFINE_bool(bf, false, "Enable beamforming."); | |
73 DEFINE_bool(ie, false, "Enable intelligibility enhancer."); | |
74 DEFINE_bool(all, false, "Enable all components."); | |
75 | |
76 DEFINE_int32(ns_level, -1, "Noise suppression level [0 - 3]."); | |
77 | |
78 DEFINE_bool(perf, false, "Enable performance tests."); | |
79 | |
80 namespace webrtc { | |
81 namespace { | |
82 | |
83 const int kChunksPerSecond = 100; | |
84 const char kUsage[] = | |
85 "Command-line tool to run audio processing on WAV files. Accepts either\n" | |
86 "an input capture WAV file or protobuf debug dump and writes to an output\n" | |
87 "WAV file.\n" | |
88 "\n" | |
89 "All components are disabled by default."; | |
90 | |
91 } // namespace | |
92 | |
93 int main(int argc, char* argv[]) { | 385 int main(int argc, char* argv[]) { |
94 google::SetUsageMessage(kUsage); | 386 google::SetUsageMessage(kUsageDescription); |
95 google::ParseCommandLineFlags(&argc, &argv, true); | 387 google::ParseCommandLineFlags(&argc, &argv, true); |
96 | 388 |
97 if (!((FLAGS_i.empty()) ^ (FLAGS_dump.empty()))) { | 389 SimulationSettings settings = CreateSettings(); |
98 fprintf(stderr, | 390 PerformBasicParameterSanityChecks(settings); |
99 "An input file must be specified with either -i or -dump.\n"); | 391 std::unique_ptr<AudioProcessingSimulator> processor; |
100 return 1; | 392 |
101 } | 393 if (settings.aec_dump_input_filename) { |
102 | 394 processor.reset(new AecDumpBasedSimulator(settings)); |
103 test::TraceToStderr trace_to_stderr(true); | |
104 Config config; | |
105 if (FLAGS_bf || FLAGS_all) { | |
106 if (FLAGS_mic_positions.empty()) { | |
107 fprintf(stderr, "-mic_positions must be specified when -bf is used.\n"); | |
108 return 1; | |
109 } | |
110 config.Set<Beamforming>(new Beamforming( | |
111 true, ParseArrayGeometry(FLAGS_mic_positions), | |
112 SphericalPointf(DegreesToRadians(FLAGS_target_angle_degrees), 0.f, | |
113 1.f))); | |
114 } | |
115 config.Set<ExperimentalNs>(new ExperimentalNs(FLAGS_ts || FLAGS_all)); | |
116 config.Set<Intelligibility>(new Intelligibility(FLAGS_ie || FLAGS_all)); | |
117 | |
118 std::unique_ptr<AudioProcessing> ap(AudioProcessing::Create(config)); | |
119 RTC_CHECK_EQ(kNoErr, ap->echo_cancellation()->Enable(FLAGS_aec || FLAGS_all)); | |
120 RTC_CHECK_EQ(kNoErr, ap->gain_control()->Enable(FLAGS_agc || FLAGS_all)); | |
121 RTC_CHECK_EQ(kNoErr, ap->high_pass_filter()->Enable(FLAGS_hpf || FLAGS_all)); | |
122 RTC_CHECK_EQ(kNoErr, ap->noise_suppression()->Enable(FLAGS_ns || FLAGS_all)); | |
123 if (FLAGS_ns_level != -1) { | |
124 RTC_CHECK_EQ(kNoErr, | |
125 ap->noise_suppression()->set_level( | |
126 static_cast<NoiseSuppression::Level>(FLAGS_ns_level))); | |
127 } | |
128 ap->set_stream_key_pressed(FLAGS_ts); | |
129 | |
130 std::unique_ptr<AudioFileProcessor> processor; | |
131 auto out_file = std::unique_ptr<WavWriter>(new WavWriter( | |
132 FLAGS_o, FLAGS_out_sample_rate, static_cast<size_t>(FLAGS_out_channels))); | |
133 std::cout << FLAGS_o << ": " << out_file->FormatAsString() << std::endl; | |
134 if (FLAGS_dump.empty()) { | |
135 auto in_file = std::unique_ptr<WavReader>(new WavReader(FLAGS_i)); | |
136 std::cout << FLAGS_i << ": " << in_file->FormatAsString() << std::endl; | |
137 std::unique_ptr<WavReader> reverse_in_file; | |
138 std::unique_ptr<WavWriter> reverse_out_file; | |
139 if (!FLAGS_ri.empty()) { | |
140 reverse_in_file.reset(new WavReader(FLAGS_ri)); | |
141 reverse_out_file.reset(new WavWriter( | |
142 FLAGS_ro, | |
143 FLAGS_rev_out_sample_rate, | |
144 static_cast<size_t>(FLAGS_rev_out_channels))); | |
145 std::cout << FLAGS_ri << ": " | |
146 << reverse_in_file->FormatAsString() << std::endl; | |
147 std::cout << FLAGS_ro << ": " | |
148 << reverse_out_file->FormatAsString() << std::endl; | |
149 } | |
150 processor.reset(new WavFileProcessor(std::move(ap), | |
151 std::move(in_file), | |
152 std::move(out_file), | |
153 std::move(reverse_in_file), | |
154 std::move(reverse_out_file))); | |
155 | |
156 } else { | 395 } else { |
157 processor.reset(new AecDumpFileProcessor( | 396 processor.reset(new WavBasedSimulator(settings)); |
158 std::move(ap), fopen(FLAGS_dump.c_str(), "rb"), std::move(out_file))); | 397 } |
159 } | 398 |
160 | 399 processor->Process(); |
161 int num_chunks = 0; | 400 |
162 while (processor->ProcessChunk()) { | 401 if (settings.report_performance) { |
163 trace_to_stderr.SetTimeSeconds(num_chunks * 1.f / kChunksPerSecond); | |
164 ++num_chunks; | |
165 } | |
166 | |
167 if (FLAGS_perf) { | |
168 const auto& proc_time = processor->proc_time(); | 402 const auto& proc_time = processor->proc_time(); |
169 int64_t exec_time_us = proc_time.sum / rtc::kNumNanosecsPerMicrosec; | 403 int64_t exec_time_us = proc_time.sum / rtc::kNumNanosecsPerMicrosec; |
170 printf( | 404 std::cout << std::endl |
171 "\nExecution time: %.3f s, File time: %.2f s\n" | 405 << "Execution time: " << exec_time_us * 1e-6 << " s, File time: " |
172 "Time per chunk (mean, max, min):\n%.0f us, %.0f us, %.0f us\n", | 406 << processor->get_num_process_stream_calls() * 1.f / |
173 exec_time_us * 1e-6, num_chunks * 1.f / kChunksPerSecond, | 407 AudioProcessingSimulator::kChunksPerSecond |
174 exec_time_us * 1.f / num_chunks, | 408 << std::endl |
175 1.f * proc_time.max / rtc::kNumNanosecsPerMicrosec, | 409 << "Time per fwd stream chunk (mean, max, min): " << std::endl |
176 1.f * proc_time.min / rtc::kNumNanosecsPerMicrosec); | 410 << exec_time_us * 1.f / processor->get_num_process_stream_calls() |
| 411 << " us, " << 1.f * proc_time.max / rtc::kNumNanosecsPerMicrosec |
| 412 << " us, " << 1.f * proc_time.min / rtc::kNumNanosecsPerMicrosec |
| 413 << " us" << std::endl; |
| 414 } |
| 415 |
| 416 if (settings.report_bitexactness && settings.aec_dump_input_filename) { |
| 417 if (processor->OutputWasBitexact()) { |
| 418 std::cout << "The processing was bitexact."; |
| 419 } else { |
| 420 std::cout << "The processing was not bitexact."; |
| 421 } |
177 } | 422 } |
178 | 423 |
179 return 0; | 424 return 0; |
180 } | 425 } |
181 | 426 |
| 427 } // namespace test |
182 } // namespace webrtc | 428 } // namespace webrtc |
183 | 429 |
184 int main(int argc, char* argv[]) { | 430 int main(int argc, char* argv[]) { |
185 return webrtc::main(argc, argv); | 431 return webrtc::test::main(argc, argv); |
186 } | 432 } |
OLD | NEW |