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 13 matching lines...) Expand all Loading... |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "webrtc/base/checks.h" | 25 #include "webrtc/base/checks.h" |
26 #include "webrtc/common_audio/real_fourier.h" | 26 #include "webrtc/common_audio/real_fourier.h" |
27 #include "webrtc/common_audio/wav_file.h" | 27 #include "webrtc/common_audio/wav_file.h" |
28 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc
er.h" | 28 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc
er.h" |
29 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_utils.
h" | 29 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_utils.
h" |
30 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 30 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
31 #include "webrtc/test/testsupport/fileutils.h" | 31 #include "webrtc/test/testsupport/fileutils.h" |
32 | 32 |
33 using std::complex; | 33 using std::complex; |
| 34 using webrtc::intelligibility::VarianceArray; |
34 | 35 |
35 namespace webrtc { | 36 namespace webrtc { |
36 namespace { | 37 namespace { |
37 | 38 |
38 bool ValidateClearWindow(const char* flagname, int32_t value) { | 39 bool ValidateClearWindow(const char* flagname, int32_t value) { |
39 return value > 0; | 40 return value > 0; |
40 } | 41 } |
41 | 42 |
42 DEFINE_int32(clear_type, | 43 DEFINE_int32(clear_type, |
43 webrtc::intelligibility::VarianceArray::kStepInfinite, | 44 webrtc::intelligibility::VarianceArray::kStepDecaying, |
44 "Variance algorithm for clear data."); | 45 "Variance algorithm for clear data."); |
45 DEFINE_double(clear_alpha, 0.9, "Variance decay factor for clear data."); | 46 DEFINE_double(clear_alpha, 0.9, "Variance decay factor for clear data."); |
46 DEFINE_int32(clear_window, | 47 DEFINE_int32(clear_window, |
47 475, | 48 475, |
48 "Window size for windowed variance for clear data."); | 49 "Window size for windowed variance for clear data."); |
49 const bool clear_window_dummy = | 50 const bool clear_window_dummy = |
50 google::RegisterFlagValidator(&FLAGS_clear_window, &ValidateClearWindow); | 51 google::RegisterFlagValidator(&FLAGS_clear_window, &ValidateClearWindow); |
51 DEFINE_int32(sample_rate, | 52 DEFINE_int32(sample_rate, |
52 16000, | 53 16000, |
53 "Audio sample rate used in the input and output files."); | 54 "Audio sample rate used in the input and output files."); |
54 DEFINE_int32(ana_rate, | 55 DEFINE_int32(ana_rate, |
55 800, | 56 800, |
56 "Analysis rate; gains recalculated every N blocks."); | 57 "Analysis rate; gains recalculated every N blocks."); |
57 DEFINE_int32( | 58 DEFINE_int32( |
58 var_rate, | 59 var_rate, |
59 2, | 60 2, |
60 "Variance clear rate; history is forgotten every N gain recalculations."); | 61 "Variance clear rate; history is forgotten every N gain recalculations."); |
61 DEFINE_double(gain_limit, 1000.0, "Maximum gain change in one block."); | 62 DEFINE_double(gain_limit, 1000.0, "Maximum gain change in one block."); |
62 | 63 |
63 DEFINE_string(clear_file, "speech.wav", "Input file with clear speech."); | 64 DEFINE_string(clear_file, "speech.wav", "Input file with clear speech."); |
64 DEFINE_string(noise_file, "noise.wav", "Input file with noise data."); | 65 DEFINE_string(noise_file, "noise.wav", "Input file with noise data."); |
65 DEFINE_string(out_file, | 66 DEFINE_string(out_file, |
66 "proc_enhanced.wav", | 67 "proc_enhanced.wav", |
67 "Enhanced output. Use '-' to " | 68 "Enhanced output. Use '-' to " |
68 "play through aplay immediately."); | 69 "play through aplay immediately."); |
69 | 70 |
70 // Constant IntelligibilityEnhancer constructor parameters. | |
71 const int kErbResolution = 2; | |
72 const int kNumChannels = 1; | 71 const int kNumChannels = 1; |
73 | 72 |
74 // void function for gtest | 73 // void function for gtest |
75 void void_main(int argc, char* argv[]) { | 74 void void_main(int argc, char* argv[]) { |
76 google::SetUsageMessage( | 75 google::SetUsageMessage( |
77 "\n\nVariance algorithm types are:\n" | 76 "\n\nVariance algorithm types are:\n" |
78 " 0 - infinite/normal,\n" | 77 " 0 - infinite/normal,\n" |
79 " 1 - exponentially decaying,\n" | 78 " 1 - exponentially decaying,\n" |
80 " 2 - rolling window.\n" | 79 " 2 - rolling window.\n" |
81 "\nInput files must be little-endian 16-bit signed raw PCM.\n"); | 80 "\nInput files must be little-endian 16-bit signed raw PCM.\n"); |
(...skipping 19 matching lines...) Expand all Loading... |
101 | 100 |
102 WavReader in_file(FLAGS_clear_file); | 101 WavReader in_file(FLAGS_clear_file); |
103 std::vector<float> in_fpcm(samples); | 102 std::vector<float> in_fpcm(samples); |
104 in_file.ReadSamples(samples, &in_fpcm[0]); | 103 in_file.ReadSamples(samples, &in_fpcm[0]); |
105 | 104 |
106 WavReader noise_file(FLAGS_noise_file); | 105 WavReader noise_file(FLAGS_noise_file); |
107 std::vector<float> noise_fpcm(samples); | 106 std::vector<float> noise_fpcm(samples); |
108 noise_file.ReadSamples(samples, &noise_fpcm[0]); | 107 noise_file.ReadSamples(samples, &noise_fpcm[0]); |
109 | 108 |
110 // Run intelligibility enhancement. | 109 // Run intelligibility enhancement. |
111 | 110 IntelligibilityEnhancer::Config config; |
112 IntelligibilityEnhancer enh( | 111 config.sample_rate_hz = FLAGS_sample_rate; |
113 kErbResolution, FLAGS_sample_rate, kNumChannels, FLAGS_clear_type, | 112 config.var_type = static_cast<VarianceArray::StepType>(FLAGS_clear_type); |
114 static_cast<float>(FLAGS_clear_alpha), FLAGS_clear_window, FLAGS_ana_rate, | 113 config.var_decay_rate = static_cast<float>(FLAGS_clear_alpha); |
115 FLAGS_var_rate, FLAGS_gain_limit); | 114 config.var_window_size = FLAGS_clear_window; |
| 115 config.analysis_rate = FLAGS_ana_rate; |
| 116 config.gain_change_limit = FLAGS_gain_limit; |
| 117 IntelligibilityEnhancer enh(config); |
116 | 118 |
117 // Slice the input into smaller chunks, as the APM would do, and feed them | 119 // Slice the input into smaller chunks, as the APM would do, and feed them |
118 // through the enhancer. | 120 // through the enhancer. |
119 float* clear_cursor = &in_fpcm[0]; | 121 float* clear_cursor = &in_fpcm[0]; |
120 float* noise_cursor = &noise_fpcm[0]; | 122 float* noise_cursor = &noise_fpcm[0]; |
121 | 123 |
122 for (size_t i = 0; i < samples; i += fragment_size) { | 124 for (size_t i = 0; i < samples; i += fragment_size) { |
123 enh.ProcessCaptureAudio(&noise_cursor); | 125 enh.AnalyzeCaptureAudio(&noise_cursor, FLAGS_sample_rate, kNumChannels); |
124 enh.ProcessRenderAudio(&clear_cursor); | 126 enh.ProcessRenderAudio(&clear_cursor, FLAGS_sample_rate, kNumChannels); |
125 clear_cursor += fragment_size; | 127 clear_cursor += fragment_size; |
126 noise_cursor += fragment_size; | 128 noise_cursor += fragment_size; |
127 } | 129 } |
128 | 130 |
129 if (FLAGS_out_file.compare("-") == 0) { | 131 if (FLAGS_out_file.compare("-") == 0) { |
130 const std::string temp_out_filename = | 132 const std::string temp_out_filename = |
131 test::TempFilename(test::WorkingDir(), "temp_wav_file"); | 133 test::TempFilename(test::WorkingDir(), "temp_wav_file"); |
132 { | 134 { |
133 WavWriter out_file(temp_out_filename, FLAGS_sample_rate, kNumChannels); | 135 WavWriter out_file(temp_out_filename, FLAGS_sample_rate, kNumChannels); |
134 out_file.WriteSamples(&in_fpcm[0], samples); | 136 out_file.WriteSamples(&in_fpcm[0], samples); |
135 } | 137 } |
136 system(("aplay " + temp_out_filename).c_str()); | 138 system(("aplay " + temp_out_filename).c_str()); |
137 system(("rm " + temp_out_filename).c_str()); | 139 system(("rm " + temp_out_filename).c_str()); |
138 } else { | 140 } else { |
139 WavWriter out_file(FLAGS_out_file, FLAGS_sample_rate, kNumChannels); | 141 WavWriter out_file(FLAGS_out_file, FLAGS_sample_rate, kNumChannels); |
140 out_file.WriteSamples(&in_fpcm[0], samples); | 142 out_file.WriteSamples(&in_fpcm[0], samples); |
141 } | 143 } |
142 } | 144 } |
143 | 145 |
144 } // namespace | 146 } // namespace |
145 } // namespace webrtc | 147 } // namespace webrtc |
146 | 148 |
147 int main(int argc, char* argv[]) { | 149 int main(int argc, char* argv[]) { |
148 webrtc::void_main(argc, argv); | 150 webrtc::void_main(argc, argv); |
149 return 0; | 151 return 0; |
150 } | 152 } |
OLD | NEW |