Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Unified Diff: webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc

Issue 1766383002: Convert IntelligibilityEnhancer to multi-threaded mode (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Another way to suppress warning Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..40e6884e0ff8e8fc9b19e3a69cd25cc37211ce75 100644
--- a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc
+++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc
@@ -61,25 +61,28 @@ 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),
center_freqs_(bank_size_),
+ capture_filter_bank_(CreateErbBank(num_noise_bins)),
render_filter_bank_(CreateErbBank(freqs_)),
gains_eq_(bank_size_),
gain_applier_(freqs_, kMaxRelativeGainChange),
audio_s16_(chunk_length_),
chunks_since_voice_(kSpeechOffsetDelay),
- is_speech_(false) {
+ is_speech_(false),
+ noise_estimation_buffer_(num_noise_bins) {
RTC_DCHECK_LE(kRho, 1.f);
const size_t erb_index = static_cast<size_t>(
@@ -94,17 +97,20 @@ 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(
the sun 2016/03/09 09:02:55 Can you make to without the scoped_ptr, given this
aluebs-webrtc 2016/03/09 12:18:50 Good point. Done.
+ new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>(
+ kMaxNumNoiseEstimatesToBuffer, template_queue_element,
+ RenderQueueItemVerifier<float>(num_noise_bins)));
}
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_DCHECK_EQ(noise.size(), num_noise_bins_);
+ // Disregarding return value since buffer overflow is acceptable, because it
+ // is not critical to get each noise estimate.
+ if(noise_estimation_queue_->Insert(&noise)) {};
the sun 2016/03/09 09:02:55 Something missing here?
aluebs-webrtc 2016/03/09 12:18:50 No, that is a way of making all compilers happy an
the sun 2016/03/09 12:28:53 Ah, I need to learn how to read. :) nit: space be
aluebs-webrtc 2016/03/09 12:58:16 Done.
}
void IntelligibilityEnhancer::ProcessRenderAudio(float* const* audio,
@@ -112,6 +118,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 +136,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_,

Powered by Google App Engine
This is Rietveld 408576698