Index: webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc |
diff --git a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc |
index dc2dcdd2610542a69238a4317c24b7a18286f50e..d2d5edb223f87084f5a557f841b8cad755fc62d0 100644 |
--- a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc |
+++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc |
@@ -61,19 +61,21 @@ void MapToErbBands(const float* pow, |
} // namespace |
IntelligibilityEnhancer::IntelligibilityEnhancer(int sample_rate_hz, |
- size_t num_render_channels) |
+ size_t num_render_channels, |
+ size_t num_noise_bins) |
: freqs_(RealFourier::ComplexLength( |
RealFourier::FftOrder(sample_rate_hz * kWindowSizeMs / 1000))), |
+ num_noise_bins_(num_noise_bins), |
chunk_length_(static_cast<size_t>(sample_rate_hz * kChunkSizeMs / 1000)), |
bank_size_(GetBankSize(sample_rate_hz, kErbResolution)), |
sample_rate_hz_(sample_rate_hz), |
num_render_channels_(num_render_channels), |
clear_power_estimator_(freqs_, kDecayRate), |
- noise_power_estimator_( |
- new intelligibility::PowerEstimator<float>(freqs_, kDecayRate)), |
+ noise_power_estimator_(freqs_, kDecayRate), |
filtered_clear_pow_(bank_size_, 0.f), |
- filtered_noise_pow_(bank_size_, 0.f), |
+ filtered_noise_pow_(num_noise_bins, 0.f), |
turaj
2016/03/07 20:34:35
I suppose I'm missing a point, |filtered_noise_pow
aluebs-webrtc
2016/03/08 10:53:00
They can (and have) different sizes, since one is
turaj
2016/03/08 15:35:04
Thanks for the explanation.
|
center_freqs_(bank_size_), |
+ capture_filter_bank_(CreateErbBank(num_noise_bins)), |
render_filter_bank_(CreateErbBank(freqs_)), |
gains_eq_(bank_size_), |
gain_applier_(freqs_, kMaxRelativeGainChange), |
@@ -94,17 +96,19 @@ IntelligibilityEnhancer::IntelligibilityEnhancer(int sample_rate_hz, |
render_mangler_.reset(new LappedTransform( |
num_render_channels_, num_render_channels_, chunk_length_, |
kbd_window.data(), window_size, window_size / 2, this)); |
+ |
+ std::vector<float> template_queue_element(num_noise_bins); |
+ noise_estimation_queue_.reset( |
+ new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( |
+ kMaxNumFramesToBuffer, template_queue_element, |
+ RenderQueueItemVerifier<float>(num_noise_bins))); |
+ noise_estimation_buffer_.resize(num_noise_bins); |
turaj
2016/03/07 20:34:35
Any particular reason that |noise_estimation_buffe
aluebs-webrtc
2016/03/08 10:53:00
No really. Changed.
|
} |
void IntelligibilityEnhancer::SetCaptureNoiseEstimate( |
std::vector<float> noise) { |
- if (capture_filter_bank_.size() != bank_size_ || |
- capture_filter_bank_[0].size() != noise.size()) { |
- capture_filter_bank_ = CreateErbBank(noise.size()); |
- noise_power_estimator_.reset( |
- new intelligibility::PowerEstimator<float>(noise.size(), kDecayRate)); |
- } |
- noise_power_estimator_->Step(noise.data()); |
+ RTC_CHECK_EQ(noise.size(), num_noise_bins_); |
peah-webrtc
2016/03/08 07:02:38
Do we really want a CHECK here? I think a DCHECK s
hlundin-webrtc
2016/03/08 10:28:48
Acknowledged.
aluebs-webrtc
2016/03/08 10:53:00
Agreed. Done.
|
+ (void)noise_estimation_queue_->Insert(&noise); |
peah-webrtc
2016/03/08 07:02:38
Please add a comment on why buffer overflow is acc
aluebs-webrtc
2016/03/08 10:53:00
Done.
|
} |
void IntelligibilityEnhancer::ProcessRenderAudio(float* const* audio, |
@@ -112,6 +116,9 @@ void IntelligibilityEnhancer::ProcessRenderAudio(float* const* audio, |
size_t num_channels) { |
RTC_CHECK_EQ(sample_rate_hz_, sample_rate_hz); |
RTC_CHECK_EQ(num_render_channels_, num_channels); |
+ while (noise_estimation_queue_->Remove(&noise_estimation_buffer_)) { |
+ noise_power_estimator_.Step(noise_estimation_buffer_.data()); |
+ } |
is_speech_ = IsSpeech(audio[0]); |
render_mangler_->ProcessChunk(audio, audio); |
} |
@@ -127,7 +134,7 @@ void IntelligibilityEnhancer::ProcessAudioBlock( |
clear_power_estimator_.Step(in_block[0]); |
} |
const std::vector<float>& clear_power = clear_power_estimator_.power(); |
- const std::vector<float>& noise_power = noise_power_estimator_->power(); |
+ const std::vector<float>& noise_power = noise_power_estimator_.power(); |
MapToErbBands(clear_power.data(), render_filter_bank_, |
filtered_clear_pow_.data()); |
MapToErbBands(noise_power.data(), capture_filter_bank_, |