| 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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_ENHANCER
_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_ENHANCER
_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_ENHANCER
_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_ENHANCER
_H_ |
| 13 | 13 |
| 14 #include <complex> | 14 #include <complex> |
| 15 #include <memory> | 15 #include <memory> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "webrtc/common_audio/lapped_transform.h" | 18 #include "webrtc/common_audio/lapped_transform.h" |
| 19 #include "webrtc/common_audio/channel_buffer.h" | 19 #include "webrtc/common_audio/channel_buffer.h" |
| 20 #include "webrtc/common_audio/swap_queue.h" |
| 20 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_utils.
h" | 21 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_utils.
h" |
| 22 #include "webrtc/modules/audio_processing/processing_component.h" |
| 21 #include "webrtc/modules/audio_processing/vad/voice_activity_detector.h" | 23 #include "webrtc/modules/audio_processing/vad/voice_activity_detector.h" |
| 22 | 24 |
| 23 namespace webrtc { | 25 namespace webrtc { |
| 24 | 26 |
| 25 // Speech intelligibility enhancement module. Reads render and capture | 27 // Speech intelligibility enhancement module. Reads render and capture |
| 26 // audio streams and modifies the render stream with a set of gains per | 28 // audio streams and modifies the render stream with a set of gains per |
| 27 // frequency bin to enhance speech against the noise background. | 29 // frequency bin to enhance speech against the noise background. |
| 28 // Details of the model and algorithm can be found in the original paper: | 30 // Details of the model and algorithm can be found in the original paper: |
| 29 // http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6882788 | 31 // http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6882788 |
| 30 class IntelligibilityEnhancer : public LappedTransform::Callback { | 32 class IntelligibilityEnhancer : public LappedTransform::Callback { |
| 31 public: | 33 public: |
| 32 IntelligibilityEnhancer(int sample_rate_hz, size_t num_render_channels); | 34 IntelligibilityEnhancer(int sample_rate_hz, |
| 35 size_t num_render_channels, |
| 36 size_t num_noise_bins); |
| 33 | 37 |
| 34 // Sets the capture noise magnitude spectrum estimate. | 38 // Sets the capture noise magnitude spectrum estimate. |
| 35 void SetCaptureNoiseEstimate(std::vector<float> noise); | 39 void SetCaptureNoiseEstimate(std::vector<float> noise); |
| 36 | 40 |
| 37 // Reads chunk of speech in time domain and updates with modified signal. | 41 // Reads chunk of speech in time domain and updates with modified signal. |
| 38 void ProcessRenderAudio(float* const* audio, | 42 void ProcessRenderAudio(float* const* audio, |
| 39 int sample_rate_hz, | 43 int sample_rate_hz, |
| 40 size_t num_channels); | 44 size_t num_channels); |
| 41 bool active() const; | 45 bool active() const; |
| 42 | 46 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 65 // Initializes ERB filterbank. | 69 // Initializes ERB filterbank. |
| 66 std::vector<std::vector<float>> CreateErbBank(size_t num_freqs); | 70 std::vector<std::vector<float>> CreateErbBank(size_t num_freqs); |
| 67 | 71 |
| 68 // Analytically solves quadratic for optimal gains given |lambda|. | 72 // Analytically solves quadratic for optimal gains given |lambda|. |
| 69 // Negative gains are set to 0. Stores the results in |sols|. | 73 // Negative gains are set to 0. Stores the results in |sols|. |
| 70 void SolveForGainsGivenLambda(float lambda, size_t start_freq, float* sols); | 74 void SolveForGainsGivenLambda(float lambda, size_t start_freq, float* sols); |
| 71 | 75 |
| 72 // Returns true if the audio is speech. | 76 // Returns true if the audio is speech. |
| 73 bool IsSpeech(const float* audio); | 77 bool IsSpeech(const float* audio); |
| 74 | 78 |
| 79 static const size_t kMaxNumNoiseEstimatesToBuffer = 5; |
| 80 |
| 75 const size_t freqs_; // Num frequencies in frequency domain. | 81 const size_t freqs_; // Num frequencies in frequency domain. |
| 82 const size_t num_noise_bins_; |
| 76 const size_t chunk_length_; // Chunk size in samples. | 83 const size_t chunk_length_; // Chunk size in samples. |
| 77 const size_t bank_size_; // Num ERB filters. | 84 const size_t bank_size_; // Num ERB filters. |
| 78 const int sample_rate_hz_; | 85 const int sample_rate_hz_; |
| 79 const size_t num_render_channels_; | 86 const size_t num_render_channels_; |
| 80 | 87 |
| 81 intelligibility::PowerEstimator<std::complex<float>> clear_power_estimator_; | 88 intelligibility::PowerEstimator<std::complex<float>> clear_power_estimator_; |
| 82 std::unique_ptr<intelligibility::PowerEstimator<float>> | 89 intelligibility::PowerEstimator<float> noise_power_estimator_; |
| 83 noise_power_estimator_; | |
| 84 std::vector<float> filtered_clear_pow_; | 90 std::vector<float> filtered_clear_pow_; |
| 85 std::vector<float> filtered_noise_pow_; | 91 std::vector<float> filtered_noise_pow_; |
| 86 std::vector<float> center_freqs_; | 92 std::vector<float> center_freqs_; |
| 87 std::vector<std::vector<float>> capture_filter_bank_; | 93 std::vector<std::vector<float>> capture_filter_bank_; |
| 88 std::vector<std::vector<float>> render_filter_bank_; | 94 std::vector<std::vector<float>> render_filter_bank_; |
| 89 size_t start_freq_; | 95 size_t start_freq_; |
| 90 | 96 |
| 91 std::vector<float> gains_eq_; // Pre-filter modified gains. | 97 std::vector<float> gains_eq_; // Pre-filter modified gains. |
| 92 intelligibility::GainApplier gain_applier_; | 98 intelligibility::GainApplier gain_applier_; |
| 93 | 99 |
| 94 std::unique_ptr<LappedTransform> render_mangler_; | 100 std::unique_ptr<LappedTransform> render_mangler_; |
| 95 | 101 |
| 96 VoiceActivityDetector vad_; | 102 VoiceActivityDetector vad_; |
| 97 std::vector<int16_t> audio_s16_; | 103 std::vector<int16_t> audio_s16_; |
| 98 size_t chunks_since_voice_; | 104 size_t chunks_since_voice_; |
| 99 bool is_speech_; | 105 bool is_speech_; |
| 106 |
| 107 std::vector<float> noise_estimation_buffer_; |
| 108 SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>> |
| 109 noise_estimation_queue_; |
| 100 }; | 110 }; |
| 101 | 111 |
| 102 } // namespace webrtc | 112 } // namespace webrtc |
| 103 | 113 |
| 104 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_ENHAN
CER_H_ | 114 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_ENHAN
CER_H_ |
| OLD | NEW |