From 1aa821980d2f871336d2f323143934bb81affff6 Mon Sep 17 00:00:00 2001 From: Alejandro Luebs Date: Fri, 1 Jul 2016 17:16:01 -0700 Subject: [PATCH] Add logging to Intelligibility Enhancer It logs when the IE is activated and deactivated. R=ivoc@webrtc.org, turaj@webrtc.org Review URL: https://codereview.webrtc.org/2104273002 . Cr-Commit-Position: refs/heads/master@{#13370} --- .../intelligibility_enhancer.cc | 60 ++++++++++++------- .../intelligibility_enhancer.h | 5 +- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc index 63bb1b9b76..f3d023ec62 100644 --- a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc +++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc @@ -17,6 +17,7 @@ #include #include "webrtc/base/checks.h" +#include "webrtc/base/logging.h" #include "webrtc/common_audio/include/audio_util.h" #include "webrtc/common_audio/window_generator.h" @@ -90,6 +91,7 @@ IntelligibilityEnhancer::IntelligibilityEnhancer(int sample_rate_hz, snr_(kMaxActiveSNR), is_active_(false), num_chunks_(0u), + num_active_chunks_(0u), noise_estimation_buffer_(num_noise_bins), noise_estimation_queue_(kMaxNumNoiseEstimatesToBuffer, std::vector(num_noise_bins), @@ -110,6 +112,14 @@ IntelligibilityEnhancer::IntelligibilityEnhancer(int sample_rate_hz, kbd_window.data(), window_size, window_size / 2, this)); } +IntelligibilityEnhancer::~IntelligibilityEnhancer() { + // Don't rely on this log, since the destructor isn't called when the app/tab + // is killed. + LOG(LS_INFO) << "Intelligibility Enhancer was active for " + << static_cast(num_active_chunks_) / num_chunks_ + << "% of the call."; +} + void IntelligibilityEnhancer::SetCaptureNoiseEstimate( std::vector noise, float gain) { RTC_DCHECK_EQ(noise.size(), num_noise_bins_); @@ -145,25 +155,29 @@ void IntelligibilityEnhancer::ProcessAudioBlock( clear_power_estimator_.Step(in_block[0]); } SnrBasedEffectActivation(); - if (is_active_ && num_chunks_++ % kGainUpdatePeriod == 0) { - MapToErbBands(clear_power_estimator_.power().data(), render_filter_bank_, - filtered_clear_pow_.data()); - MapToErbBands(noise_power_estimator_.power().data(), capture_filter_bank_, - filtered_noise_pow_.data()); - SolveForGainsGivenLambda(kLambdaTop, start_freq_, gains_eq_.data()); - const float power_target = std::accumulate( - filtered_clear_pow_.data(), - filtered_clear_pow_.data() + bank_size_, - 0.f); - const float power_top = - DotProduct(gains_eq_.data(), filtered_clear_pow_.data(), bank_size_); - SolveForGainsGivenLambda(kLambdaBot, start_freq_, gains_eq_.data()); - const float power_bot = - DotProduct(gains_eq_.data(), filtered_clear_pow_.data(), bank_size_); - if (power_target >= power_bot && power_target <= power_top) { - SolveForLambda(power_target); - UpdateErbGains(); - } // Else experiencing power underflow, so do nothing. + ++num_chunks_; + if (is_active_) { + ++num_active_chunks_; + if (num_chunks_ % kGainUpdatePeriod == 0) { + MapToErbBands(clear_power_estimator_.power().data(), render_filter_bank_, + filtered_clear_pow_.data()); + MapToErbBands(noise_power_estimator_.power().data(), capture_filter_bank_, + filtered_noise_pow_.data()); + SolveForGainsGivenLambda(kLambdaTop, start_freq_, gains_eq_.data()); + const float power_target = std::accumulate( + filtered_clear_pow_.data(), + filtered_clear_pow_.data() + bank_size_, + 0.f); + const float power_top = + DotProduct(gains_eq_.data(), filtered_clear_pow_.data(), bank_size_); + SolveForGainsGivenLambda(kLambdaBot, start_freq_, gains_eq_.data()); + const float power_bot = + DotProduct(gains_eq_.data(), filtered_clear_pow_.data(), bank_size_); + if (power_target >= power_bot && power_target <= power_top) { + SolveForLambda(power_target); + UpdateErbGains(); + } // Else experiencing power underflow, so do nothing. + } } for (size_t i = 0; i < in_channels; ++i) { gain_applier_.Apply(in_block[i], out_block[i]); @@ -181,6 +195,8 @@ void IntelligibilityEnhancer::SnrBasedEffectActivation() { (noise_power + std::numeric_limits::epsilon()); if (is_active_) { if (snr_ > kMaxActiveSNR) { + LOG(LS_INFO) << "Intelligibility Enhancer was deactivated at chunk " + << num_chunks_; is_active_ = false; // Set the target gains to unity. float* gains = gain_applier_.target(); @@ -189,7 +205,11 @@ void IntelligibilityEnhancer::SnrBasedEffectActivation() { } } } else { - is_active_ = snr_ < kMinInactiveSNR; + if (snr_ < kMinInactiveSNR) { + LOG(LS_INFO) << "Intelligibility Enhancer was activated at chunk " + << num_chunks_; + is_active_ = true; + } } } diff --git a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.h b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.h index 5ad343f2fe..5cb8dbdde3 100644 --- a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.h +++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.h @@ -35,6 +35,8 @@ class IntelligibilityEnhancer : public LappedTransform::Callback { size_t num_render_channels, size_t num_noise_bins); + ~IntelligibilityEnhancer(); + // Sets the capture noise magnitude spectrum estimate. void SetCaptureNoiseEstimate(std::vector noise, float gain); @@ -112,7 +114,8 @@ class IntelligibilityEnhancer : public LappedTransform::Callback { float snr_; bool is_active_; - size_t num_chunks_; + unsigned long int num_chunks_; + unsigned long int num_active_chunks_; std::vector noise_estimation_buffer_; SwapQueue, RenderQueueItemVerifier>