Fix MovingMoments::CalculateMoments.

Protect from negative second moments, which are unexpected in TransientDetector::Detect
and may lead to invalid results.

Bug: chromium:866925
Change-Id: Id1d5b2ebb51e54d9d332b869c6f63dcd03cc461c
Reviewed-on: https://webrtc-review.googlesource.com/91164
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24153}
This commit is contained in:
Alessio Bazzica
2018-07-31 15:08:53 +02:00
committed by Commit Bot
parent 52233a3f28
commit 2a99c0bf67

View File

@ -10,8 +10,7 @@
#include "modules/audio_processing/transient/moving_moments.h"
#include <math.h>
#include <string.h>
#include <cmath>
#include "rtc_base/checks.h"
@ -44,7 +43,7 @@ void MovingMoments::CalculateMoments(const float* in,
sum_ += in[i] - old_value;
sum_of_squares_ += in[i] * in[i] - old_value * old_value;
first[i] = sum_ / length_;
second[i] = sum_of_squares_ / length_;
second[i] = std::max(0.f, sum_of_squares_ / length_);
}
}