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 | 37 |
37 using webrtc::RealFourier; | 38 using webrtc::RealFourier; |
38 using webrtc::IntelligibilityEnhancer; | 39 using webrtc::IntelligibilityEnhancer; |
39 | 40 |
40 DEFINE_int32(clear_type, | 41 DEFINE_int32(clear_type, |
41 webrtc::intelligibility::VarianceArray::kStepInfinite, | 42 webrtc::intelligibility::VarianceArray::kStepDecaying, |
42 "Variance algorithm for clear data."); | 43 "Variance algorithm for clear data."); |
43 DEFINE_double(clear_alpha, 0.9, "Variance decay factor for clear data."); | 44 DEFINE_double(clear_alpha, 0.9, "Variance decay factor for clear data."); |
44 DEFINE_int32(clear_window, | 45 DEFINE_int32(clear_window, |
45 475, | 46 475, |
46 "Window size for windowed variance for clear data."); | 47 "Window size for windowed variance for clear data."); |
47 DEFINE_int32(sample_rate, | 48 DEFINE_int32(sample_rate, |
48 16000, | 49 16000, |
49 "Audio sample rate used in the input and output files."); | 50 "Audio sample rate used in the input and output files."); |
50 DEFINE_int32(ana_rate, | 51 DEFINE_int32(ana_rate, |
51 800, | 52 800, |
52 "Analysis rate; gains recalculated every N blocks."); | 53 "Analysis rate; gains recalculated every N blocks."); |
53 DEFINE_int32( | 54 DEFINE_int32( |
54 var_rate, | 55 var_rate, |
55 2, | 56 2, |
56 "Variance clear rate; history is forgotten every N gain recalculations."); | 57 "Variance clear rate; history is forgotten every N gain recalculations."); |
57 DEFINE_double(gain_limit, 1000.0, "Maximum gain change in one block."); | 58 DEFINE_double(gain_limit, 1000.0, "Maximum gain change in one block."); |
58 | 59 |
59 DEFINE_string(clear_file, "speech.wav", "Input file with clear speech."); | 60 DEFINE_string(clear_file, "speech.wav", "Input file with clear speech."); |
60 DEFINE_string(noise_file, "noise.wav", "Input file with noise data."); | 61 DEFINE_string(noise_file, "noise.wav", "Input file with noise data."); |
61 DEFINE_string(out_file, | 62 DEFINE_string(out_file, |
62 "proc_enhanced.wav", | 63 "proc_enhanced.wav", |
63 "Enhanced output. Use '-' to " | 64 "Enhanced output. Use '-' to " |
64 "play through aplay immediately."); | 65 "play through aplay immediately."); |
65 | 66 |
66 // Constant IntelligibilityEnhancer constructor parameters. | |
67 const int kErbResolution = 2; | |
68 const int kNumChannels = 1; | 67 const int kNumChannels = 1; |
69 | 68 |
70 // void function for gtest | 69 // void function for gtest |
71 void void_main(int argc, char* argv[]) { | 70 void void_main(int argc, char* argv[]) { |
72 google::SetUsageMessage( | 71 google::SetUsageMessage( |
73 "\n\nVariance algorithm types are:\n" | 72 "\n\nVariance algorithm types are:\n" |
74 " 0 - infinite/normal,\n" | 73 " 0 - infinite/normal,\n" |
75 " 1 - exponentially decaying,\n" | 74 " 1 - exponentially decaying,\n" |
76 " 2 - rolling window.\n" | 75 " 2 - rolling window.\n" |
77 "\nInput files must be little-endian 16-bit signed raw PCM.\n"); | 76 "\nInput files must be little-endian 16-bit signed raw PCM.\n"); |
(...skipping 19 matching lines...) Expand all Loading... |
97 | 96 |
98 WavReader in_file(FLAGS_clear_file); | 97 WavReader in_file(FLAGS_clear_file); |
99 std::vector<float> in_fpcm(samples); | 98 std::vector<float> in_fpcm(samples); |
100 in_file.ReadSamples(samples, &in_fpcm[0]); | 99 in_file.ReadSamples(samples, &in_fpcm[0]); |
101 | 100 |
102 WavReader noise_file(FLAGS_noise_file); | 101 WavReader noise_file(FLAGS_noise_file); |
103 std::vector<float> noise_fpcm(samples); | 102 std::vector<float> noise_fpcm(samples); |
104 noise_file.ReadSamples(samples, &noise_fpcm[0]); | 103 noise_file.ReadSamples(samples, &noise_fpcm[0]); |
105 | 104 |
106 // Run intelligibility enhancement. | 105 // Run intelligibility enhancement. |
107 | 106 IntelligibilityEnhancer::Config config; |
108 IntelligibilityEnhancer enh( | 107 config.sample_rate_hz = FLAGS_sample_rate; |
109 kErbResolution, FLAGS_sample_rate, kNumChannels, FLAGS_clear_type, | 108 config.var_type = static_cast<VarianceArray::StepType>(FLAGS_clear_type); |
110 static_cast<float>(FLAGS_clear_alpha), FLAGS_clear_window, FLAGS_ana_rate, | 109 config.var_decay_rate = static_cast<float>(FLAGS_clear_alpha); |
111 FLAGS_var_rate, FLAGS_gain_limit); | 110 config.var_window_size = FLAGS_clear_window; |
| 111 config.analysis_rate = FLAGS_ana_rate; |
| 112 config.gain_change_limit = FLAGS_gain_limit; |
| 113 IntelligibilityEnhancer enh(config); |
112 | 114 |
113 // Slice the input into smaller chunks, as the APM would do, and feed them | 115 // Slice the input into smaller chunks, as the APM would do, and feed them |
114 // through the enhancer. | 116 // through the enhancer. |
115 float* clear_cursor = &in_fpcm[0]; | 117 float* clear_cursor = &in_fpcm[0]; |
116 float* noise_cursor = &noise_fpcm[0]; | 118 float* noise_cursor = &noise_fpcm[0]; |
117 | 119 |
118 for (size_t i = 0; i < samples; i += fragment_size) { | 120 for (size_t i = 0; i < samples; i += fragment_size) { |
119 enh.ProcessCaptureAudio(&noise_cursor); | 121 enh.ProcessCaptureAudio(&noise_cursor); |
120 enh.ProcessRenderAudio(&clear_cursor); | 122 enh.ProcessRenderAudio(&clear_cursor); |
121 clear_cursor += fragment_size; | 123 clear_cursor += fragment_size; |
(...skipping 14 matching lines...) Expand all Loading... |
136 out_file.WriteSamples(&in_fpcm[0], samples); | 138 out_file.WriteSamples(&in_fpcm[0], samples); |
137 } | 139 } |
138 } | 140 } |
139 | 141 |
140 } // namespace webrtc | 142 } // namespace webrtc |
141 | 143 |
142 int main(int argc, char* argv[]) { | 144 int main(int argc, char* argv[]) { |
143 webrtc::void_main(argc, argv); | 145 webrtc::void_main(argc, argv); |
144 return 0; | 146 return 0; |
145 } | 147 } |
OLD | NEW |