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 "gflags/gflags.h" | |
12 #include "webrtc/common_audio/channel_buffer.h" | 11 #include "webrtc/common_audio/channel_buffer.h" |
13 #include "webrtc/common_audio/include/audio_util.h" | 12 #include "webrtc/common_audio/include/audio_util.h" |
14 #include "webrtc/common_audio/wav_file.h" | 13 #include "webrtc/common_audio/wav_file.h" |
15 #include "webrtc/modules/audio_processing/audio_buffer.h" | 14 #include "webrtc/modules/audio_processing/audio_buffer.h" |
16 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc
er.h" | 15 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc
er.h" |
17 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" | 16 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" |
18 #include "webrtc/rtc_base/criticalsection.h" | 17 #include "webrtc/rtc_base/criticalsection.h" |
19 #include "webrtc/test/gtest.h" | 18 #include "webrtc/rtc_base/flags.h" |
20 | 19 |
21 using std::complex; | 20 using std::complex; |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 namespace { | 23 namespace { |
25 | 24 |
26 DEFINE_string(clear_file, "speech.wav", "Input file with clear speech."); | 25 DEFINE_string(clear_file, "speech.wav", "Input file with clear speech."); |
27 DEFINE_string(noise_file, "noise.wav", "Input file with noise data."); | 26 DEFINE_string(noise_file, "noise.wav", "Input file with noise data."); |
28 DEFINE_string(out_file, "proc_enhanced.wav", "Enhanced output file."); | 27 DEFINE_string(out_file, "proc_enhanced.wav", "Enhanced output file."); |
| 28 DEFINE_bool(help, false, "Print this message."); |
29 | 29 |
30 // void function for gtest | 30 int int_main(int argc, char* argv[]) { |
31 void void_main(int argc, char* argv[]) { | 31 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { |
32 google::SetUsageMessage( | 32 return 1; |
33 "\n\nInput files must be little-endian 16-bit signed raw PCM.\n"); | 33 } |
34 google::ParseCommandLineFlags(&argc, &argv, true); | 34 if (FLAG_help) { |
| 35 rtc::FlagList::Print(nullptr, false); |
| 36 return 0; |
| 37 } |
| 38 if (argc != 1) { |
| 39 printf("\n\nInput files must be little-endian 16-bit signed raw PCM.\n"); |
| 40 return 0; |
| 41 } |
35 | 42 |
36 WavReader in_file(FLAGS_clear_file); | 43 WavReader in_file(FLAG_clear_file); |
37 WavReader noise_file(FLAGS_noise_file); | 44 WavReader noise_file(FLAG_noise_file); |
38 WavWriter out_file(FLAGS_out_file, in_file.sample_rate(), | 45 WavWriter out_file(FLAG_out_file, in_file.sample_rate(), |
39 in_file.num_channels()); | 46 in_file.num_channels()); |
40 rtc::CriticalSection crit; | 47 rtc::CriticalSection crit; |
41 NoiseSuppressionImpl ns(&crit); | 48 NoiseSuppressionImpl ns(&crit); |
42 IntelligibilityEnhancer enh(in_file.sample_rate(), in_file.num_channels(), 1u, | 49 IntelligibilityEnhancer enh(in_file.sample_rate(), in_file.num_channels(), 1u, |
43 NoiseSuppressionImpl::num_noise_bins()); | 50 NoiseSuppressionImpl::num_noise_bins()); |
44 ns.Initialize(noise_file.num_channels(), noise_file.sample_rate()); | 51 ns.Initialize(noise_file.num_channels(), noise_file.sample_rate()); |
45 ns.Enable(true); | 52 ns.Enable(true); |
46 const size_t in_samples = noise_file.sample_rate() / 100; | 53 const size_t in_samples = noise_file.sample_rate() / 100; |
47 const size_t noise_samples = noise_file.sample_rate() / 100; | 54 const size_t noise_samples = noise_file.sample_rate() / 100; |
48 std::vector<float> in(in_samples * in_file.num_channels()); | 55 std::vector<float> in(in_samples * in_file.num_channels()); |
(...skipping 21 matching lines...) Expand all Loading... |
70 ns.AnalyzeCaptureAudio(&capture_audio); | 77 ns.AnalyzeCaptureAudio(&capture_audio); |
71 ns.ProcessCaptureAudio(&capture_audio); | 78 ns.ProcessCaptureAudio(&capture_audio); |
72 enh.SetCaptureNoiseEstimate(ns.NoiseEstimate(), 1); | 79 enh.SetCaptureNoiseEstimate(ns.NoiseEstimate(), 1); |
73 enh.ProcessRenderAudio(&render_audio); | 80 enh.ProcessRenderAudio(&render_audio); |
74 render_audio.CopyTo(in_config, in_buf.channels()); | 81 render_audio.CopyTo(in_config, in_buf.channels()); |
75 Interleave(in_buf.channels(), in_buf.num_frames(), in_buf.num_channels(), | 82 Interleave(in_buf.channels(), in_buf.num_frames(), in_buf.num_channels(), |
76 in.data()); | 83 in.data()); |
77 FloatToFloatS16(in.data(), in.size(), in.data()); | 84 FloatToFloatS16(in.data(), in.size(), in.data()); |
78 out_file.WriteSamples(in.data(), in.size()); | 85 out_file.WriteSamples(in.data(), in.size()); |
79 } | 86 } |
| 87 |
| 88 return 0; |
80 } | 89 } |
81 | 90 |
82 } // namespace | 91 } // namespace |
83 } // namespace webrtc | 92 } // namespace webrtc |
84 | 93 |
85 int main(int argc, char* argv[]) { | 94 int main(int argc, char* argv[]) { |
86 webrtc::void_main(argc, argv); | 95 return webrtc::int_main(argc, argv); |
87 return 0; | |
88 } | 96 } |
OLD | NEW |