From 66d248110678d732646935ce846ff1d581782168 Mon Sep 17 00:00:00 2001 From: Alejandro Luebs Date: Thu, 11 Feb 2016 10:37:12 -0800 Subject: [PATCH] Fix division by zero errors in IntelligibilityEnhancer BUG=webrtc:5509 R=henrik.lundin@webrtc.org Review URL: https://codereview.webrtc.org/1686333002 . Cr-Commit-Position: refs/heads/master@{#11584} --- .../intelligibility/intelligibility_enhancer.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc index 9ed2d07584..877e437fe7 100644 --- a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc +++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "webrtc/base/checks.h" @@ -225,7 +226,8 @@ void IntelligibilityEnhancer::SolveForLambda(float power_target, const float kConvergeThresh = 0.001f; // TODO(ekmeyerson): Find best values const int kMaxIters = 100; // for these, based on experiments. - const float reciprocal_power_target = 1.f / power_target; + const float reciprocal_power_target = + 1.f / (power_target + std::numeric_limits::epsilon()); float lambda_bot = kLambdaBot; float lambda_top = kLambdaTop; float power_ratio = 2.0f; // Ratio of achieved power to target power. @@ -307,13 +309,13 @@ std::vector> IntelligibilityEnhancer::CreateErbBank( float step, element; - step = 1.0f / (ll - lll); + step = ll == lll ? 0.f : 1.f / (ll - lll); element = 0.0f; for (size_t j = lll; j <= ll; ++j) { filter_bank[i - 1][j] = element; element += step; } - step = 1.0f / (rrr - rr); + step = rr == rrr ? 0.f : 1.f / (rrr - rr); element = 1.0f; for (size_t j = rr; j <= rrr; ++j) { filter_bank[i - 1][j] = element; @@ -357,7 +359,8 @@ void IntelligibilityEnhancer::SolveForGainsGivenLambda(float lambda, if (quadratic) { alpha0 = lambda * var_x0[n] * (1 - rho_[n]) * var_x0[n] * var_x0[n]; sols[n] = - (-beta0 - sqrtf(beta0 * beta0 - 4 * alpha0 * gamma0)) / (2 * alpha0); + (-beta0 - sqrtf(beta0 * beta0 - 4 * alpha0 * gamma0)) / + (2 * alpha0 + std::numeric_limits::epsilon()); } else { sols[n] = -gamma0 / beta0; }