From 2a99c0bf6765d9c4615236ba4e00886678b2ef76 Mon Sep 17 00:00:00 2001 From: Alessio Bazzica Date: Tue, 31 Jul 2018 15:08:53 +0200 Subject: [PATCH] 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 Reviewed-by: Sam Zackrisson Cr-Commit-Position: refs/heads/master@{#24153} --- modules/audio_processing/transient/moving_moments.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/audio_processing/transient/moving_moments.cc b/modules/audio_processing/transient/moving_moments.cc index 4be4d6adcd..a199bb0c1b 100644 --- a/modules/audio_processing/transient/moving_moments.cc +++ b/modules/audio_processing/transient/moving_moments.cc @@ -10,8 +10,7 @@ #include "modules/audio_processing/transient/moving_moments.h" -#include -#include +#include #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_); } }