| Index: webrtc/modules/audio_processing/utility/block_fraction_calculator.cc
|
| diff --git a/webrtc/modules/audio_processing/utility/block_mean_calculator.cc b/webrtc/modules/audio_processing/utility/block_fraction_calculator.cc
|
| similarity index 55%
|
| copy from webrtc/modules/audio_processing/utility/block_mean_calculator.cc
|
| copy to webrtc/modules/audio_processing/utility/block_fraction_calculator.cc
|
| index 7f4508ecc7058f80a3c71e0ff390275b4bc6a0af..8dbfac7bdb02983ddb24674caa2c966f29da5687 100644
|
| --- a/webrtc/modules/audio_processing/utility/block_mean_calculator.cc
|
| +++ b/webrtc/modules/audio_processing/utility/block_fraction_calculator.cc
|
| @@ -8,46 +8,43 @@
|
| * be found in the AUTHORS file in the root of the source tree.
|
| */
|
|
|
| -#include "webrtc/modules/audio_processing/utility/block_mean_calculator.h"
|
| +#include "webrtc/modules/audio_processing/utility/block_fraction_calculator.h"
|
|
|
| #include "webrtc/base/checks.h"
|
|
|
| namespace webrtc {
|
|
|
| -BlockMeanCalculator::BlockMeanCalculator(size_t block_length)
|
| +BlockFractionCalculator::BlockFractionCalculator(size_t block_length)
|
| : block_length_(block_length),
|
| count_(0),
|
| - sum_(0.0),
|
| - mean_(0.0) {
|
| + occurrence_(0),
|
| + fraction_(-1.0) {
|
| RTC_DCHECK(block_length_ != 0);
|
| }
|
|
|
| -void BlockMeanCalculator::Reset() {
|
| +void BlockFractionCalculator::Reset() {
|
| Clear();
|
| - mean_ = 0.0;
|
| + fraction_ = -1.0;
|
| }
|
|
|
| -void BlockMeanCalculator::AddValue(float value) {
|
| - sum_ += value;
|
| +void BlockFractionCalculator::AddObservation(bool occurred) {
|
| + if (occurred)
|
| + occurrence_++;
|
| ++count_;
|
| if (count_ == block_length_) {
|
| - mean_ = sum_ / block_length_;
|
| + fraction_ = static_cast<float>(occurrence_) / block_length_;
|
| Clear();
|
| }
|
| }
|
|
|
| -bool BlockMeanCalculator::EndOfBlock() const {
|
| - return count_ == 0;
|
| -}
|
| -
|
| -float BlockMeanCalculator::GetLatestMean() const {
|
| - return mean_;
|
| +float BlockFractionCalculator::GetLatestFraction() const {
|
| + return fraction_;
|
| }
|
|
|
| // Flush all samples added.
|
| -void BlockMeanCalculator::Clear() {
|
| +void BlockFractionCalculator::Clear() {
|
| count_ = 0;
|
| - sum_ = 0.0;
|
| + occurrence_ = 0;
|
| }
|
|
|
| } // namespace webrtc
|
|
|