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 |
(...skipping 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 DEFINE_string(dump, "", "Name of the aecdump debug file to read from."); | 39 DEFINE_string(dump, "", "Name of the aecdump debug file to read from."); |
40 DEFINE_string(i, "", "Name of the capture input stream file to read from."); | 40 DEFINE_string(i, "", "Name of the capture input stream file to read from."); |
41 DEFINE_string( | 41 DEFINE_string( |
42 o, | 42 o, |
43 "out.wav", | 43 "out.wav", |
44 "Name of the output file to write the processed capture stream to."); | 44 "Name of the output file to write the processed capture stream to."); |
45 DEFINE_string(ri, "", "Name of the render input stream file to read from."); | |
46 DEFINE_string( | |
47 ro, | |
48 "out_reverse.wav", | |
49 "Name of the output file to write the processed render stream to."); | |
50 DEFINE_int32(out_channels, 1, "Number of output channels."); | 45 DEFINE_int32(out_channels, 1, "Number of output channels."); |
51 const bool out_channels_dummy = | 46 const bool out_channels_dummy = |
52 google::RegisterFlagValidator(&FLAGS_out_channels, &ValidateOutChannels); | 47 google::RegisterFlagValidator(&FLAGS_out_channels, &ValidateOutChannels); |
53 DEFINE_int32(rev_out_channels, 1, "Number of reverse output channels."); | |
54 const bool rev_out_channels_dummy = | |
55 google::RegisterFlagValidator(&FLAGS_rev_out_channels, | |
56 &ValidateOutChannels); | |
57 DEFINE_int32(out_sample_rate, 48000, "Output sample rate in Hz."); | 48 DEFINE_int32(out_sample_rate, 48000, "Output sample rate in Hz."); |
58 DEFINE_int32(rev_out_sample_rate, 48000, "Reverse output sample rate in Hz."); | |
59 DEFINE_string(mic_positions, "", | 49 DEFINE_string(mic_positions, "", |
60 "Space delimited cartesian coordinates of microphones in meters. " | 50 "Space delimited cartesian coordinates of microphones in meters. " |
61 "The coordinates of each point are contiguous. " | 51 "The coordinates of each point are contiguous. " |
62 "For a two element array: \"x1 y1 z1 x2 y2 z2\""); | 52 "For a two element array: \"x1 y1 z1 x2 y2 z2\""); |
63 DEFINE_double( | 53 DEFINE_double( |
64 target_angle_degrees, | 54 target_angle_degrees, |
65 90, | 55 90, |
66 "The azimuth of the target in degrees. Only applies to beamforming."); | 56 "The azimuth of the target in degrees. Only applies to beamforming."); |
67 | 57 |
68 DEFINE_bool(aec, false, "Enable echo cancellation."); | 58 DEFINE_bool(aec, false, "Enable echo cancellation."); |
(...skipping 11 matching lines...) Expand all Loading... |
80 | 70 |
81 namespace webrtc { | 71 namespace webrtc { |
82 namespace { | 72 namespace { |
83 | 73 |
84 const int kChunksPerSecond = 100; | 74 const int kChunksPerSecond = 100; |
85 const char kUsage[] = | 75 const char kUsage[] = |
86 "Command-line tool to run audio processing on WAV files. Accepts either\n" | 76 "Command-line tool to run audio processing on WAV files. Accepts either\n" |
87 "an input capture WAV file or protobuf debug dump and writes to an output\n" | 77 "an input capture WAV file or protobuf debug dump and writes to an output\n" |
88 "WAV file.\n" | 78 "WAV file.\n" |
89 "\n" | 79 "\n" |
90 "All components are disabled by default."; | 80 "All components are disabled by default. If any bi-directional components\n" |
| 81 "are enabled, only debug dump files are permitted."; |
91 | 82 |
92 } // namespace | 83 } // namespace |
93 | 84 |
94 int main(int argc, char* argv[]) { | 85 int main(int argc, char* argv[]) { |
95 google::SetUsageMessage(kUsage); | 86 google::SetUsageMessage(kUsage); |
96 google::ParseCommandLineFlags(&argc, &argv, true); | 87 google::ParseCommandLineFlags(&argc, &argv, true); |
97 | 88 |
98 if (!((FLAGS_i.empty()) ^ (FLAGS_dump.empty()))) { | 89 if (!((FLAGS_i.empty()) ^ (FLAGS_dump.empty()))) { |
99 fprintf(stderr, | 90 fprintf(stderr, |
100 "An input file must be specified with either -i or -dump.\n"); | 91 "An input file must be specified with either -i or -dump.\n"); |
101 return 1; | 92 return 1; |
102 } | 93 } |
| 94 if (FLAGS_dump.empty() && (FLAGS_aec || FLAGS_ie)) { |
| 95 fprintf(stderr, "-aec and -ie require a -dump file.\n"); |
| 96 return 1; |
| 97 } |
| 98 if (FLAGS_ie) { |
| 99 fprintf(stderr, |
| 100 "FIXME(ajm): The intelligibility enhancer output is not dumped.\n"); |
| 101 return 1; |
| 102 } |
103 | 103 |
104 test::TraceToStderr trace_to_stderr(true); | 104 test::TraceToStderr trace_to_stderr(true); |
105 Config config; | 105 Config config; |
106 if (FLAGS_bf || FLAGS_all) { | 106 if (FLAGS_bf || FLAGS_all) { |
107 if (FLAGS_mic_positions.empty()) { | 107 if (FLAGS_mic_positions.empty()) { |
108 fprintf(stderr, "-mic_positions must be specified when -bf is used.\n"); | 108 fprintf(stderr, "-mic_positions must be specified when -bf is used.\n"); |
109 return 1; | 109 return 1; |
110 } | 110 } |
111 config.Set<Beamforming>(new Beamforming( | 111 config.Set<Beamforming>(new Beamforming( |
112 true, ParseArrayGeometry(FLAGS_mic_positions), | 112 true, ParseArrayGeometry(FLAGS_mic_positions), |
(...skipping 15 matching lines...) Expand all Loading... |
128 } | 128 } |
129 ap->set_stream_key_pressed(FLAGS_ts); | 129 ap->set_stream_key_pressed(FLAGS_ts); |
130 | 130 |
131 std::unique_ptr<AudioFileProcessor> processor; | 131 std::unique_ptr<AudioFileProcessor> processor; |
132 auto out_file = std::unique_ptr<WavWriter>(new WavWriter( | 132 auto out_file = std::unique_ptr<WavWriter>(new WavWriter( |
133 FLAGS_o, FLAGS_out_sample_rate, static_cast<size_t>(FLAGS_out_channels))); | 133 FLAGS_o, FLAGS_out_sample_rate, static_cast<size_t>(FLAGS_out_channels))); |
134 std::cout << FLAGS_o << ": " << out_file->FormatAsString() << std::endl; | 134 std::cout << FLAGS_o << ": " << out_file->FormatAsString() << std::endl; |
135 if (FLAGS_dump.empty()) { | 135 if (FLAGS_dump.empty()) { |
136 auto in_file = std::unique_ptr<WavReader>(new WavReader(FLAGS_i)); | 136 auto in_file = std::unique_ptr<WavReader>(new WavReader(FLAGS_i)); |
137 std::cout << FLAGS_i << ": " << in_file->FormatAsString() << std::endl; | 137 std::cout << FLAGS_i << ": " << in_file->FormatAsString() << std::endl; |
138 std::unique_ptr<WavReader> reverse_in_file; | 138 processor.reset(new WavFileProcessor(std::move(ap), std::move(in_file), |
139 std::unique_ptr<WavWriter> reverse_out_file; | 139 std::move(out_file))); |
140 if (!FLAGS_ri.empty()) { | |
141 reverse_in_file.reset(new WavReader(FLAGS_ri)); | |
142 reverse_out_file.reset(new WavWriter( | |
143 FLAGS_ro, | |
144 FLAGS_rev_out_sample_rate, | |
145 static_cast<size_t>(FLAGS_rev_out_channels))); | |
146 std::cout << FLAGS_ri << ": " | |
147 << reverse_in_file->FormatAsString() << std::endl; | |
148 std::cout << FLAGS_ro << ": " | |
149 << reverse_out_file->FormatAsString() << std::endl; | |
150 } | |
151 processor.reset(new WavFileProcessor(std::move(ap), | |
152 std::move(in_file), | |
153 std::move(out_file), | |
154 std::move(reverse_in_file), | |
155 std::move(reverse_out_file))); | |
156 | 140 |
157 } else { | 141 } else { |
158 processor.reset(new AecDumpFileProcessor( | 142 processor.reset(new AecDumpFileProcessor( |
159 std::move(ap), fopen(FLAGS_dump.c_str(), "rb"), std::move(out_file))); | 143 std::move(ap), fopen(FLAGS_dump.c_str(), "rb"), std::move(out_file))); |
160 } | 144 } |
161 | 145 |
162 int num_chunks = 0; | 146 int num_chunks = 0; |
163 while (processor->ProcessChunk()) { | 147 while (processor->ProcessChunk()) { |
164 trace_to_stderr.SetTimeSeconds(num_chunks * 1.f / kChunksPerSecond); | 148 trace_to_stderr.SetTimeSeconds(num_chunks * 1.f / kChunksPerSecond); |
165 ++num_chunks; | 149 ++num_chunks; |
(...skipping 11 matching lines...) Expand all Loading... |
177 } | 161 } |
178 | 162 |
179 return 0; | 163 return 0; |
180 } | 164 } |
181 | 165 |
182 } // namespace webrtc | 166 } // namespace webrtc |
183 | 167 |
184 int main(int argc, char* argv[]) { | 168 int main(int argc, char* argv[]) { |
185 return webrtc::main(argc, argv); | 169 return webrtc::main(argc, argv); |
186 } | 170 } |
OLD | NEW |