| 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> | 11 #include <stdio.h> |
| 12 #include <sstream> | 12 #include <sstream> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "gflags/gflags.h" | 15 #include "gflags/gflags.h" |
| 16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/format_macros.h" |
| 17 #include "webrtc/base/scoped_ptr.h" | 18 #include "webrtc/base/scoped_ptr.h" |
| 18 #include "webrtc/common_audio/channel_buffer.h" | 19 #include "webrtc/common_audio/channel_buffer.h" |
| 19 #include "webrtc/common_audio/wav_file.h" | 20 #include "webrtc/common_audio/wav_file.h" |
| 20 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 21 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 21 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 22 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
| 22 #include "webrtc/modules/audio_processing/test/test_utils.h" | 23 #include "webrtc/modules/audio_processing/test/test_utils.h" |
| 23 #include "webrtc/system_wrappers/interface/tick_util.h" | 24 #include "webrtc/system_wrappers/interface/tick_util.h" |
| 24 #include "webrtc/test/testsupport/trace_to_stderr.h" | 25 #include "webrtc/test/testsupport/trace_to_stderr.h" |
| 25 | 26 |
| 27 namespace { |
| 28 |
| 29 bool ValidateOutChannels(const char* flagname, int32_t value) { |
| 30 return value >= 0; |
| 31 } |
| 32 |
| 33 } // namespace |
| 34 |
| 26 DEFINE_string(dump, "", "The name of the debug dump file to read from."); | 35 DEFINE_string(dump, "", "The name of the debug dump file to read from."); |
| 27 DEFINE_string(i, "", "The name of the input file to read from."); | 36 DEFINE_string(i, "", "The name of the input file to read from."); |
| 28 DEFINE_string(o, "out.wav", "Name of the output file to write to."); | 37 DEFINE_string(o, "out.wav", "Name of the output file to write to."); |
| 29 DEFINE_int32(out_channels, 0, "Number of output channels. Defaults to input."); | 38 DEFINE_int32(out_channels, 0, "Number of output channels. Defaults to input."); |
| 39 const bool out_channels_dummy = |
| 40 google::RegisterFlagValidator(&FLAGS_out_channels, &ValidateOutChannels); |
| 30 DEFINE_int32(out_sample_rate, 0, | 41 DEFINE_int32(out_sample_rate, 0, |
| 31 "Output sample rate in Hz. Defaults to input."); | 42 "Output sample rate in Hz. Defaults to input."); |
| 32 DEFINE_string(mic_positions, "", | 43 DEFINE_string(mic_positions, "", |
| 33 "Space delimited cartesian coordinates of microphones in meters. " | 44 "Space delimited cartesian coordinates of microphones in meters. " |
| 34 "The coordinates of each point are contiguous. " | 45 "The coordinates of each point are contiguous. " |
| 35 "For a two element array: \"x1 y1 z1 x2 y2 z2\""); | 46 "For a two element array: \"x1 y1 z1 x2 y2 z2\""); |
| 36 | 47 |
| 37 DEFINE_bool(aec, false, "Enable echo cancellation."); | 48 DEFINE_bool(aec, false, "Enable echo cancellation."); |
| 38 DEFINE_bool(agc, false, "Enable automatic gain control."); | 49 DEFINE_bool(agc, false, "Enable automatic gain control."); |
| 39 DEFINE_bool(hpf, false, "Enable high-pass filtering."); | 50 DEFINE_bool(hpf, false, "Enable high-pass filtering."); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 70 return 1; | 81 return 1; |
| 71 } | 82 } |
| 72 if (!FLAGS_dump.empty()) { | 83 if (!FLAGS_dump.empty()) { |
| 73 fprintf(stderr, "FIXME: the -dump option is not yet implemented.\n"); | 84 fprintf(stderr, "FIXME: the -dump option is not yet implemented.\n"); |
| 74 return 1; | 85 return 1; |
| 75 } | 86 } |
| 76 | 87 |
| 77 test::TraceToStderr trace_to_stderr(true); | 88 test::TraceToStderr trace_to_stderr(true); |
| 78 WavReader in_file(FLAGS_i); | 89 WavReader in_file(FLAGS_i); |
| 79 // If the output format is uninitialized, use the input format. | 90 // If the output format is uninitialized, use the input format. |
| 80 const int out_channels = | 91 const size_t out_channels = FLAGS_out_channels ? |
| 81 FLAGS_out_channels ? FLAGS_out_channels : in_file.num_channels(); | 92 static_cast<size_t>(FLAGS_out_channels) : in_file.num_channels(); |
| 82 const int out_sample_rate = | 93 const int out_sample_rate = |
| 83 FLAGS_out_sample_rate ? FLAGS_out_sample_rate : in_file.sample_rate(); | 94 FLAGS_out_sample_rate ? FLAGS_out_sample_rate : in_file.sample_rate(); |
| 84 WavWriter out_file(FLAGS_o, out_sample_rate, out_channels); | 95 WavWriter out_file(FLAGS_o, out_sample_rate, out_channels); |
| 85 | 96 |
| 86 Config config; | 97 Config config; |
| 87 config.Set<ExperimentalNs>(new ExperimentalNs(FLAGS_ts || FLAGS_all)); | 98 config.Set<ExperimentalNs>(new ExperimentalNs(FLAGS_ts || FLAGS_all)); |
| 88 | 99 |
| 89 if (FLAGS_bf || FLAGS_all) { | 100 if (FLAGS_bf || FLAGS_all) { |
| 90 const size_t num_mics = in_file.num_channels(); | 101 const size_t num_mics = in_file.num_channels(); |
| 91 const std::vector<Point> array_geometry = | 102 const std::vector<Point> array_geometry = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 103 return -1; | 114 return -1; |
| 104 } | 115 } |
| 105 CHECK_EQ(kNoErr, ap->gain_control()->Enable(FLAGS_agc || FLAGS_all)); | 116 CHECK_EQ(kNoErr, ap->gain_control()->Enable(FLAGS_agc || FLAGS_all)); |
| 106 CHECK_EQ(kNoErr, ap->gain_control()->set_mode(GainControl::kFixedDigital)); | 117 CHECK_EQ(kNoErr, ap->gain_control()->set_mode(GainControl::kFixedDigital)); |
| 107 CHECK_EQ(kNoErr, ap->high_pass_filter()->Enable(FLAGS_hpf || FLAGS_all)); | 118 CHECK_EQ(kNoErr, ap->high_pass_filter()->Enable(FLAGS_hpf || FLAGS_all)); |
| 108 CHECK_EQ(kNoErr, ap->noise_suppression()->Enable(FLAGS_ns || FLAGS_all)); | 119 CHECK_EQ(kNoErr, ap->noise_suppression()->Enable(FLAGS_ns || FLAGS_all)); |
| 109 if (FLAGS_ns_level != -1) | 120 if (FLAGS_ns_level != -1) |
| 110 CHECK_EQ(kNoErr, ap->noise_suppression()->set_level( | 121 CHECK_EQ(kNoErr, ap->noise_suppression()->set_level( |
| 111 static_cast<NoiseSuppression::Level>(FLAGS_ns_level))); | 122 static_cast<NoiseSuppression::Level>(FLAGS_ns_level))); |
| 112 | 123 |
| 113 printf("Input file: %s\nChannels: %d, Sample rate: %d Hz\n\n", | 124 printf("Input file: %s\nChannels: %" PRIuS ", Sample rate: %d Hz\n\n", |
| 114 FLAGS_i.c_str(), in_file.num_channels(), in_file.sample_rate()); | 125 FLAGS_i.c_str(), in_file.num_channels(), in_file.sample_rate()); |
| 115 printf("Output file: %s\nChannels: %d, Sample rate: %d Hz\n\n", | 126 printf("Output file: %s\nChannels: %" PRIuS ", Sample rate: %d Hz\n\n", |
| 116 FLAGS_o.c_str(), out_file.num_channels(), out_file.sample_rate()); | 127 FLAGS_o.c_str(), out_file.num_channels(), out_file.sample_rate()); |
| 117 | 128 |
| 118 ChannelBuffer<float> in_buf( | 129 ChannelBuffer<float> in_buf( |
| 119 rtc::CheckedDivExact(in_file.sample_rate(), kChunksPerSecond), | 130 rtc::CheckedDivExact(in_file.sample_rate(), kChunksPerSecond), |
| 120 in_file.num_channels()); | 131 in_file.num_channels()); |
| 121 ChannelBuffer<float> out_buf( | 132 ChannelBuffer<float> out_buf( |
| 122 rtc::CheckedDivExact(out_file.sample_rate(), kChunksPerSecond), | 133 rtc::CheckedDivExact(out_file.sample_rate(), kChunksPerSecond), |
| 123 out_file.num_channels()); | 134 out_file.num_channels()); |
| 124 | 135 |
| 125 std::vector<float> in_interleaved(in_buf.size()); | 136 std::vector<float> in_interleaved(in_buf.size()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 execution_time_ms * 1.f / num_chunks); | 178 execution_time_ms * 1.f / num_chunks); |
| 168 } | 179 } |
| 169 return 0; | 180 return 0; |
| 170 } | 181 } |
| 171 | 182 |
| 172 } // namespace webrtc | 183 } // namespace webrtc |
| 173 | 184 |
| 174 int main(int argc, char* argv[]) { | 185 int main(int argc, char* argv[]) { |
| 175 return webrtc::main(argc, argv); | 186 return webrtc::main(argc, argv); |
| 176 } | 187 } |
| OLD | NEW |