| 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 // | 11 // |
| 12 // Command line tool for speech intelligibility enhancement. Provides for | 12 // Command line tool for speech intelligibility enhancement. Provides for |
| 13 // running and testing intelligibility_enhancer as an independent process. | 13 // running and testing intelligibility_enhancer as an independent process. |
| 14 // Use --help for options. | 14 // Use --help for options. |
| 15 // | 15 // |
| 16 | 16 |
| 17 #include <stdint.h> | 17 #include <stdint.h> |
| 18 #include <stdlib.h> | 18 #include <stdlib.h> |
| 19 #include <sys/stat.h> | 19 #include <sys/stat.h> |
| 20 #include <sys/types.h> | 20 #include <sys/types.h> |
| 21 #include <string> | 21 #include <string> |
| 22 | 22 |
| 23 #include "gflags/gflags.h" | 23 #include "gflags/gflags.h" |
| 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/base/criticalsection.h" |
| 26 #include "webrtc/common_audio/real_fourier.h" | 27 #include "webrtc/common_audio/real_fourier.h" |
| 27 #include "webrtc/common_audio/wav_file.h" | 28 #include "webrtc/common_audio/wav_file.h" |
| 29 #include "webrtc/modules/audio_processing/audio_buffer.h" |
| 30 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 28 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc
er.h" | 31 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc
er.h" |
| 29 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_utils.
h" | 32 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_utils.
h" |
| 33 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" |
| 30 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 34 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 31 #include "webrtc/test/testsupport/fileutils.h" | 35 #include "webrtc/test/testsupport/fileutils.h" |
| 32 | 36 |
| 33 using std::complex; | 37 using std::complex; |
| 34 using webrtc::intelligibility::VarianceArray; | 38 using webrtc::intelligibility::VarianceArray; |
| 35 | 39 |
| 36 namespace webrtc { | 40 namespace webrtc { |
| 37 namespace { | 41 namespace { |
| 38 | 42 |
| 39 bool ValidateClearWindow(const char* flagname, int32_t value) { | 43 bool ValidateClearWindow(const char* flagname, int32_t value) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 112 |
| 109 // Run intelligibility enhancement. | 113 // Run intelligibility enhancement. |
| 110 IntelligibilityEnhancer::Config config; | 114 IntelligibilityEnhancer::Config config; |
| 111 config.sample_rate_hz = FLAGS_sample_rate; | 115 config.sample_rate_hz = FLAGS_sample_rate; |
| 112 config.var_type = static_cast<VarianceArray::StepType>(FLAGS_clear_type); | 116 config.var_type = static_cast<VarianceArray::StepType>(FLAGS_clear_type); |
| 113 config.var_decay_rate = static_cast<float>(FLAGS_clear_alpha); | 117 config.var_decay_rate = static_cast<float>(FLAGS_clear_alpha); |
| 114 config.var_window_size = static_cast<size_t>(FLAGS_clear_window); | 118 config.var_window_size = static_cast<size_t>(FLAGS_clear_window); |
| 115 config.analysis_rate = FLAGS_ana_rate; | 119 config.analysis_rate = FLAGS_ana_rate; |
| 116 config.gain_change_limit = FLAGS_gain_limit; | 120 config.gain_change_limit = FLAGS_gain_limit; |
| 117 IntelligibilityEnhancer enh(config); | 121 IntelligibilityEnhancer enh(config); |
| 122 rtc::CriticalSection crit; |
| 123 NoiseSuppressionImpl ns(&crit); |
| 124 ns.Initialize(kNumChannels, FLAGS_sample_rate); |
| 125 ns.Enable(true); |
| 126 |
| 127 AudioBuffer capture_audio(fragment_size, |
| 128 kNumChannels, |
| 129 fragment_size, |
| 130 kNumChannels, |
| 131 fragment_size); |
| 132 StreamConfig stream_config(FLAGS_sample_rate, kNumChannels); |
| 118 | 133 |
| 119 // Slice the input into smaller chunks, as the APM would do, and feed them | 134 // Slice the input into smaller chunks, as the APM would do, and feed them |
| 120 // through the enhancer. | 135 // through the enhancer. |
| 121 float* clear_cursor = &in_fpcm[0]; | 136 float* clear_cursor = &in_fpcm[0]; |
| 122 float* noise_cursor = &noise_fpcm[0]; | 137 float* noise_cursor = &noise_fpcm[0]; |
| 123 | 138 |
| 124 for (size_t i = 0; i < samples; i += fragment_size) { | 139 for (size_t i = 0; i < samples; i += fragment_size) { |
| 125 enh.AnalyzeCaptureAudio(&noise_cursor, FLAGS_sample_rate, kNumChannels); | 140 capture_audio.CopyFrom(&noise_cursor, stream_config); |
| 141 ns.AnalyzeCaptureAudio(&capture_audio); |
| 142 ns.ProcessCaptureAudio(&capture_audio); |
| 143 enh.SetCaptureNoiseEstimate(ns.noise_estimate()); |
| 126 enh.ProcessRenderAudio(&clear_cursor, FLAGS_sample_rate, kNumChannels); | 144 enh.ProcessRenderAudio(&clear_cursor, FLAGS_sample_rate, kNumChannels); |
| 127 clear_cursor += fragment_size; | 145 clear_cursor += fragment_size; |
| 128 noise_cursor += fragment_size; | 146 noise_cursor += fragment_size; |
| 129 } | 147 } |
| 130 | 148 |
| 131 if (FLAGS_out_file.compare("-") == 0) { | 149 if (FLAGS_out_file.compare("-") == 0) { |
| 132 const std::string temp_out_filename = | 150 const std::string temp_out_filename = |
| 133 test::TempFilename(test::WorkingDir(), "temp_wav_file"); | 151 test::TempFilename(test::WorkingDir(), "temp_wav_file"); |
| 134 { | 152 { |
| 135 WavWriter out_file(temp_out_filename, FLAGS_sample_rate, kNumChannels); | 153 WavWriter out_file(temp_out_filename, FLAGS_sample_rate, kNumChannels); |
| 136 out_file.WriteSamples(&in_fpcm[0], samples); | 154 out_file.WriteSamples(&in_fpcm[0], samples); |
| 137 } | 155 } |
| 138 system(("aplay " + temp_out_filename).c_str()); | 156 system(("aplay " + temp_out_filename).c_str()); |
| 139 system(("rm " + temp_out_filename).c_str()); | 157 system(("rm " + temp_out_filename).c_str()); |
| 140 } else { | 158 } else { |
| 141 WavWriter out_file(FLAGS_out_file, FLAGS_sample_rate, kNumChannels); | 159 WavWriter out_file(FLAGS_out_file, FLAGS_sample_rate, kNumChannels); |
| 142 out_file.WriteSamples(&in_fpcm[0], samples); | 160 out_file.WriteSamples(&in_fpcm[0], samples); |
| 143 } | 161 } |
| 144 } | 162 } |
| 145 | 163 |
| 146 } // namespace | 164 } // namespace |
| 147 } // namespace webrtc | 165 } // namespace webrtc |
| 148 | 166 |
| 149 int main(int argc, char* argv[]) { | 167 int main(int argc, char* argv[]) { |
| 150 webrtc::void_main(argc, argv); | 168 webrtc::void_main(argc, argv); |
| 151 return 0; | 169 return 0; |
| 152 } | 170 } |
| OLD | NEW |