Remove C++11 calls from intelligibility_utils

The C++11 here was overkill. This replaces it with simpler logic that
covers all cases encountered so far in practice.

The problem was previously brought up here: https://codereview.webrtc.org/1250663007/

BUG=427718, 487341, webrtc:4866
R=andrew@webrtc.org

Review URL: https://codereview.webrtc.org/1242943008

Cr-Commit-Position: refs/heads/master@{#9627}
This commit is contained in:
ekmeyerson
2015-07-23 12:15:24 -07:00
committed by Commit bot
parent 86c6d33aec
commit 3ab2f14d56
3 changed files with 6 additions and 41 deletions

View File

@ -15,6 +15,7 @@
#include "webrtc/modules/audio_processing/intelligibility/intelligibility_utils.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
@ -31,28 +32,12 @@ float UpdateFactor(float target, float current, float limit) {
return current + sign * fminf(delta, limit);
}
bool cplxfinite(complex<float> c) {
return std::isfinite(c.real()) && std::isfinite(c.imag());
}
bool cplxnormal(complex<float> c) {
return std::isnormal(c.real()) && std::isnormal(c.imag());
float AddDitherIfZero(float value) {
return value == 0.f ? std::rand() * 0.01f / RAND_MAX : value;
}
complex<float> zerofudge(complex<float> c) {
const static complex<float> fudge[7] = {{0.001f, 0.002f},
{0.008f, 0.001f},
{0.003f, 0.008f},
{0.0006f, 0.0009f},
{0.001f, 0.004f},
{0.003f, 0.004f},
{0.002f, 0.009f}};
static int fudge_index = 0;
if (cplxfinite(c) && !cplxnormal(c)) {
fudge_index = (fudge_index + 1) % 7;
return c + fudge[fudge_index];
}
return c;
return complex<float>(AddDitherIfZero(c.real()), AddDitherIfZero(c.imag()));
}
complex<float> NewMean(complex<float> mean, complex<float> data, int count) {
@ -136,10 +121,7 @@ void VarianceArray::InfiniteStep(const complex<float>* data, bool skip_fudge) {
(old_sum + std::conj(sample - old_mean) * (sample - running_mean_[i]))
.real();
variance_[i] =
conj_sum_[i] / (count_ - 1); // + fudge[fudge_index].real();
// if (skip_fudge) {
// variance_[i] -= fudge[fudge_index].real();
// }
conj_sum_[i] / (count_ - 1);
}
array_mean_ += (variance_[i] - array_mean_) / (i + 1);
}
@ -164,9 +146,6 @@ void VarianceArray::DecayStep(const complex<float>* data, bool /*dummy*/) {
running_mean_[i] = decay_ * prev + (1.0f - decay_) * sample;
running_mean_sq_[i] =
decay_ * prev2 + (1.0f - decay_) * sample * std::conj(sample);
// variance_[i] = decay_ * variance_[i] + (1.0f - decay_) * (
// (sample - running_mean_[i]) * std::conj(sample -
// running_mean_[i])).real();
variance_[i] = (running_mean_sq_[i] -
running_mean_[i] * std::conj(running_mean_[i])).real();
}

View File

@ -27,12 +27,6 @@ namespace intelligibility {
// |limit|.
float UpdateFactor(float target, float current, float limit);
// std::isfinite for complex numbers.
bool cplxfinite(std::complex<float> c);
// std::isnormal for complex numbers.
bool cplxnormal(std::complex<float> c);
// Apply a small fudge to degenerate complex values. The numbers in the array
// were chosen randomly, so that even a series of all zeroes has some small
// variability.

View File

@ -48,20 +48,12 @@ TEST(IntelligibilityUtilsTest, TestUpdateFactor) {
EXPECT_EQ(3, intelligibility::UpdateFactor(2, 4, 1));
}
// Tests cplxfinite, cplxnormal, and zerofudge.
// Tests zerofudge.
TEST(IntelligibilityUtilsTest, TestCplx) {
complex<float> t0(1.f, 0.f);
EXPECT_TRUE(intelligibility::cplxfinite(t0));
EXPECT_FALSE(intelligibility::cplxnormal(t0));
t0 = intelligibility::zerofudge(t0);
EXPECT_NE(t0.imag(), 0.f);
EXPECT_NE(t0.real(), 0.f);
const complex<float> t1(1.f, std::sqrt(-1.f));
EXPECT_FALSE(intelligibility::cplxfinite(t1));
EXPECT_FALSE(intelligibility::cplxnormal(t1));
const complex<float> t2(1.f, 1.f);
EXPECT_TRUE(intelligibility::cplxfinite(t2));
EXPECT_TRUE(intelligibility::cplxnormal(t2));
}
// Tests NewMean and AddToMean.