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

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

Issue 1686333002: Fix division by zero errors in IntelligibilityEnhancer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c42a1731b47266eb7e9b45d3e82796766db39baf..8aee3296d1248ae85390fea12e2d6c5dad9986ff 100644
--- a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc
+++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc
@@ -20,6 +20,7 @@
#include <math.h>
#include <stdlib.h>
#include <algorithm>
+#include <limits>
#include <numeric>
#include "webrtc/base/checks.h"
@@ -224,7 +225,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<float>::epsilon());
float lambda_bot = kLambdaBot;
float lambda_top = kLambdaTop;
float power_ratio = 2.0f; // Ratio of achieved power to target power.
@@ -306,13 +308,13 @@ std::vector<std::vector<float>> 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;
@@ -356,7 +358,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<float>::epsilon());
} else {
sols[n] = -gamma0 / beta0;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698