From 4896aaa9e4e7d4e1322b301406e64777268965b9 Mon Sep 17 00:00:00 2001 From: aluebs Date: Thu, 28 Apr 2016 16:08:59 -0700 Subject: [PATCH] Limit the maximum and minimum gain the IntelligibilityEnhancer can apply Although the algorithm should generate the optimal gains, these limits are in place so that it doesn't go bananas in extreme noise situations or if there are some errors on the noise estimate. The limits were chosen as the extreme values from recordings with -3dB SNR, which is the minimum where the POLQA metric increases when processed. Review-Url: https://codereview.webrtc.org/1925933002 Cr-Commit-Position: refs/heads/master@{#12550} --- .../intelligibility/intelligibility_utils.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc b/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc index 3a9433b476..3675f66caf 100644 --- a/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc +++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc @@ -22,16 +22,15 @@ namespace intelligibility { namespace { +const float kMinFactor = 0.01f; +const float kMaxFactor = 1000.f; + // Return |current| changed towards |target|, with the relative change being at // most |limit|. float UpdateFactor(float target, float current, float limit) { float gain = target / (current + std::numeric_limits::epsilon()); - if (gain < 1.f - limit) { - gain = 1.f - limit; - } else if (gain > 1.f + limit) { - gain = 1.f + limit; - } - return current * gain + std::numeric_limits::epsilon(); + gain = std::min(std::max(gain, 1.f - limit), 1.f + limit); + return std::min(std::max(current * gain, kMinFactor), kMaxFactor);; } } // namespace