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 <vector> | 11 #include <vector> |
12 | 12 |
13 #include "gflags/gflags.h" | |
14 #include "webrtc/common_audio/channel_buffer.h" | 13 #include "webrtc/common_audio/channel_buffer.h" |
15 #include "webrtc/common_audio/wav_file.h" | 14 #include "webrtc/common_audio/wav_file.h" |
16 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" | 15 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" |
17 #include "webrtc/modules/audio_processing/test/test_utils.h" | 16 #include "webrtc/modules/audio_processing/test/test_utils.h" |
18 #include "webrtc/rtc_base/checks.h" | 17 #include "webrtc/rtc_base/checks.h" |
| 18 #include "webrtc/rtc_base/flags.h" |
19 #include "webrtc/rtc_base/format_macros.h" | 19 #include "webrtc/rtc_base/format_macros.h" |
20 | 20 |
21 DEFINE_string(i, "", "The name of the input file to read from."); | 21 DEFINE_string(i, "", "The name of the input file to read from."); |
22 DEFINE_string(o, "out.wav", "Name of the output file to write to."); | 22 DEFINE_string(o, "out.wav", "Name of the output file to write to."); |
23 DEFINE_string(mic_positions, "", | 23 DEFINE_string(mic_positions, "", |
24 "Space delimited cartesian coordinates of microphones in meters. " | 24 "Space delimited cartesian coordinates of microphones in meters. " |
25 "The coordinates of each point are contiguous. " | 25 "The coordinates of each point are contiguous. " |
26 "For a two element array: \"x1 y1 z1 x2 y2 z2\""); | 26 "For a two element array: \"x1 y1 z1 x2 y2 z2\""); |
| 27 DEFINE_bool(help, false, "Prints this message."); |
27 | 28 |
28 namespace webrtc { | 29 namespace webrtc { |
29 namespace { | 30 namespace { |
30 | 31 |
31 const int kChunksPerSecond = 100; | 32 const int kChunksPerSecond = 100; |
32 const int kChunkSizeMs = 1000 / kChunksPerSecond; | 33 const int kChunkSizeMs = 1000 / kChunksPerSecond; |
33 | 34 |
34 const char kUsage[] = | 35 const char kUsage[] = |
35 "Command-line tool to run beamforming on WAV files. The signal is passed\n" | 36 "Command-line tool to run beamforming on WAV files. The signal is passed\n" |
36 "in as a single band, unlike the audio processing interface which splits\n" | 37 "in as a single band, unlike the audio processing interface which splits\n" |
37 "signals into multiple bands."; | 38 "signals into multiple bands.\n"; |
38 | 39 |
39 } // namespace | 40 } // namespace |
40 | 41 |
41 int main(int argc, char* argv[]) { | 42 int main(int argc, char* argv[]) { |
42 google::SetUsageMessage(kUsage); | 43 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || |
43 google::ParseCommandLineFlags(&argc, &argv, true); | 44 FLAG_help || argc != 1) { |
| 45 printf("%s", kUsage); |
| 46 if (FLAG_help) { |
| 47 rtc::FlagList::Print(nullptr, false); |
| 48 return 0; |
| 49 } |
| 50 return 1; |
| 51 } |
44 | 52 |
45 WavReader in_file(FLAGS_i); | 53 WavReader in_file(FLAG_i); |
46 WavWriter out_file(FLAGS_o, in_file.sample_rate(), in_file.num_channels()); | 54 WavWriter out_file(FLAG_o, in_file.sample_rate(), in_file.num_channels()); |
47 | 55 |
48 const size_t num_mics = in_file.num_channels(); | 56 const size_t num_mics = in_file.num_channels(); |
49 const std::vector<Point> array_geometry = | 57 const std::vector<Point> array_geometry = |
50 ParseArrayGeometry(FLAGS_mic_positions, num_mics); | 58 ParseArrayGeometry(FLAG_mic_positions, num_mics); |
51 RTC_CHECK_EQ(array_geometry.size(), num_mics); | 59 RTC_CHECK_EQ(array_geometry.size(), num_mics); |
52 | 60 |
53 NonlinearBeamformer bf(array_geometry, array_geometry.size()); | 61 NonlinearBeamformer bf(array_geometry, array_geometry.size()); |
54 bf.Initialize(kChunkSizeMs, in_file.sample_rate()); | 62 bf.Initialize(kChunkSizeMs, in_file.sample_rate()); |
55 | 63 |
56 printf("Input file: %s\nChannels: %" PRIuS ", Sample rate: %d Hz\n\n", | 64 printf("Input file: %s\nChannels: %" PRIuS ", Sample rate: %d Hz\n\n", |
57 FLAGS_i.c_str(), in_file.num_channels(), in_file.sample_rate()); | 65 FLAG_i, in_file.num_channels(), in_file.sample_rate()); |
58 printf("Output file: %s\nChannels: %" PRIuS ", Sample rate: %d Hz\n\n", | 66 printf("Output file: %s\nChannels: %" PRIuS ", Sample rate: %d Hz\n\n", |
59 FLAGS_o.c_str(), out_file.num_channels(), out_file.sample_rate()); | 67 FLAG_o, out_file.num_channels(), out_file.sample_rate()); |
60 | 68 |
61 ChannelBuffer<float> buf( | 69 ChannelBuffer<float> buf( |
62 rtc::CheckedDivExact(in_file.sample_rate(), kChunksPerSecond), | 70 rtc::CheckedDivExact(in_file.sample_rate(), kChunksPerSecond), |
63 in_file.num_channels()); | 71 in_file.num_channels()); |
64 | 72 |
65 std::vector<float> interleaved(buf.size()); | 73 std::vector<float> interleaved(buf.size()); |
66 while (in_file.ReadSamples(interleaved.size(), | 74 while (in_file.ReadSamples(interleaved.size(), |
67 &interleaved[0]) == interleaved.size()) { | 75 &interleaved[0]) == interleaved.size()) { |
68 FloatS16ToFloat(&interleaved[0], interleaved.size(), &interleaved[0]); | 76 FloatS16ToFloat(&interleaved[0], interleaved.size(), &interleaved[0]); |
69 Deinterleave(&interleaved[0], buf.num_frames(), | 77 Deinterleave(&interleaved[0], buf.num_frames(), |
70 buf.num_channels(), buf.channels()); | 78 buf.num_channels(), buf.channels()); |
71 | 79 |
72 bf.AnalyzeChunk(buf); | 80 bf.AnalyzeChunk(buf); |
73 bf.PostFilter(&buf); | 81 bf.PostFilter(&buf); |
74 | 82 |
75 Interleave(buf.channels(), buf.num_frames(), | 83 Interleave(buf.channels(), buf.num_frames(), |
76 buf.num_channels(), &interleaved[0]); | 84 buf.num_channels(), &interleaved[0]); |
77 FloatToFloatS16(&interleaved[0], interleaved.size(), &interleaved[0]); | 85 FloatToFloatS16(&interleaved[0], interleaved.size(), &interleaved[0]); |
78 out_file.WriteSamples(&interleaved[0], interleaved.size()); | 86 out_file.WriteSamples(&interleaved[0], interleaved.size()); |
79 } | 87 } |
80 | 88 |
81 return 0; | 89 return 0; |
82 } | 90 } |
83 | 91 |
84 } // namespace webrtc | 92 } // namespace webrtc |
85 | 93 |
86 int main(int argc, char* argv[]) { | 94 int main(int argc, char* argv[]) { |
87 return webrtc::main(argc, argv); | 95 return webrtc::main(argc, argv); |
88 } | 96 } |
OLD | NEW |