Index: webrtc/modules/audio_processing/utility/block_fraction_calculator.h |
diff --git a/webrtc/modules/audio_processing/utility/block_fraction_calculator.h b/webrtc/modules/audio_processing/utility/block_fraction_calculator.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..27f2717398558f00bab0293cf23dedaaa282a15a |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/utility/block_fraction_calculator.h |
@@ -0,0 +1,50 @@ |
+/* |
+ * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_BLOCK_FRACTION_CALCULATOR_H_ |
+#define WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_BLOCK_FRACTION_CALCULATOR_H_ |
+ |
+#include <stddef.h> |
+ |
+#include "webrtc/base/constructormagic.h" |
+ |
+namespace webrtc { |
+ |
+// BlockFractionCalculator calculates the fraction of the occurrence of an event |
+// in a block. The fraction is updated at the end of every block. |
+class BlockFractionCalculator { |
peah-webrtc
2016/04/06 11:01:10
Please make this local toaec_core.cc instead.
peah-webrtc
2016/04/06 11:01:10
I think it is better if you name the class in a mo
minyue-webrtc
2016/04/06 13:35:37
ok
|
+ public: |
+ explicit BlockFractionCalculator(size_t block_length); |
+ |
+ // Reset. |
+ void Reset(); |
+ |
+ // Add one observation. |occurred| is true if the event of interest happened, |
+ // false otherwise. |
+ void AddObservation(bool occurred); |
+ |
+ // Return the latest fraction. |
+ float GetLatestFraction() const; |
+ |
+ private: |
+ // Clear all values added. |
+ void Clear(); |
+ |
+ const size_t block_length_; |
+ size_t count_; |
+ size_t occurrence_; |
+ float fraction_; |
+ |
+ RTC_DISALLOW_COPY_AND_ASSIGN(BlockFractionCalculator); |
+}; |
+ |
+} // namespace webrtc |
+ |
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_BLOCK_FRACTION_CALCULATOR_H_ |