Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/modules/audio_processing/utility/block_mean_calculator.h" | |
| 12 | |
| 13 namespace webrtc { | |
| 14 | |
| 15 BlockMeanCalculator::BlockMeanCalculator(size_t block_length) | |
| 16 : block_length_(block_length), | |
| 17 count_(0), | |
| 18 sum_(0.0), | |
| 19 mean_(0.0) { | |
|
peah-webrtc
2016/03/24 11:21:58
You should add a DCHECK on the block_length not be
minyue-webrtc
2016/03/24 11:43:33
Done.
| |
| 20 } | |
| 21 | |
| 22 void BlockMeanCalculator::Reset() { | |
| 23 Clear(); | |
| 24 mean_ = 0.0; | |
| 25 } | |
| 26 | |
| 27 void BlockMeanCalculator::AddValue(float value) { | |
| 28 sum_ += value; | |
| 29 ++count_; | |
| 30 if (count_ == block_length_) { | |
| 31 mean_ = sum_ / block_length_; | |
|
peah-webrtc
2016/03/24 11:21:58
You should add a DCHECK on the block_length not be
minyue-webrtc
2016/03/24 11:43:33
since block_length_ is qualified const, it is enou
| |
| 32 Clear(); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 bool BlockMeanCalculator::EndOfBlock() const { | |
|
peah-webrtc
2016/03/24 11:21:58
Another suggestion instead of "EndOfBlock" could b
minyue-webrtc
2016/03/24 11:43:33
I prefer EndOfBlock. Let's consider what people wo
| |
| 37 return count_ == 0; | |
| 38 } | |
| 39 | |
| 40 float BlockMeanCalculator::GetLatestMean() const { | |
| 41 return mean_; | |
| 42 } | |
| 43 | |
| 44 // Flush all samples added. | |
| 45 void BlockMeanCalculator::Clear() { | |
| 46 count_ = 0; | |
| 47 sum_ = 0.0; | |
| 48 } | |
| 49 | |
| 50 } // namespace webrtc | |
| OLD | NEW |