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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_BLOCK_MEAN_CALCULATOR_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_BLOCK_MEAN_CALCULATOR_H_ |
| 13 |
| 14 #include <stddef.h> |
| 15 |
| 16 #include "webrtc/base/constructormagic.h" |
| 17 |
| 18 namespace webrtc { |
| 19 |
| 20 // BlockMeanCalculator calculates the mean of a block of values. Values are |
| 21 // added one after another, and the mean is updated at the end of every block. |
| 22 class BlockMeanCalculator { |
| 23 public: |
| 24 explicit BlockMeanCalculator(size_t block_length); |
| 25 |
| 26 // Reset. |
| 27 void Reset(); |
| 28 |
| 29 // Add one value to the sequence. |
| 30 void AddValue(float value); |
| 31 |
| 32 // Return whether the latest added value was at the end of a block. |
| 33 bool EndOfBlock() const; |
| 34 |
| 35 // Return the latest mean. |
| 36 float GetLatestMean() const; |
| 37 |
| 38 private: |
| 39 // Clear all values added. |
| 40 void Clear(); |
| 41 |
| 42 const size_t block_length_; |
| 43 size_t count_; |
| 44 float sum_; |
| 45 float mean_; |
| 46 |
| 47 RTC_DISALLOW_COPY_AND_ASSIGN(BlockMeanCalculator); |
| 48 }; |
| 49 |
| 50 } // namespace webrtc |
| 51 |
| 52 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_BLOCK_MEAN_CALCULATOR_H_ |
OLD | NEW |