Skip to content

Commit

Permalink
Fix MovingMoments::CalculateMoments.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Sam Zackrisson <[email protected]>
Cr-Commit-Position: refs/heads/master@{#24153}
  • Loading branch information
alebzk authored and Commit Bot committed Jul 31, 2018
1 parent 52233a3 commit 2a99c0b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions modules/audio_processing/transient/moving_moments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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_);
}
}

Expand Down

0 comments on commit 2a99c0b

Please sign in to comment.