Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Unified Diff: webrtc/modules/audio_processing/utility/mean_calculator.h

Issue 1805633006: Adding BlockMeanCalculator for AEC. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/utility/mean_calculator.h
diff --git a/webrtc/modules/audio_processing/utility/mean_calculator.h b/webrtc/modules/audio_processing/utility/mean_calculator.h
new file mode 100644
index 0000000000000000000000000000000000000000..3cf281afda0323354bb58a4efb0ea55f6b5a0dad
--- /dev/null
+++ b/webrtc/modules/audio_processing/utility/mean_calculator.h
@@ -0,0 +1,58 @@
+/*
+ * 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_MEAN_CALCULATOR_H_
+#define WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_MEAN_CALCULATOR_H_
+
+#include <stddef.h>
+#include <vector>
+
+#include "webrtc/base/criticalsection.h"
peah-webrtc 2016/03/18 09:18:34 criticalsection.h should be after before construc
minyue-webrtc 2016/03/21 15:27:51 Done.
+#include "webrtc/base/constructormagic.h"
+#include "webrtc/base/optional.h"
+
+namespace webrtc {
+
+// MeanCalculator calculates the mean of a sample sequence of a certain length.
peah-webrtc 2016/03/18 09:18:34 I think it is better if this class is about the me
minyue-webrtc 2016/03/21 15:27:51 In statistics, sample has its own meaning, and sho
+class MeanCalculator {
peah-webrtc 2016/03/18 09:18:34 As I said in the previous review I think you shoul
+ public:
+ explicit MeanCalculator(size_t window_length);
+
+ // Reset.
+ void Reset();
+
+ // Add one sample to the sequence.
+ void AddSample(float sample);
+
+ // Return the number of newly added samples since latest update on mean value.
+ size_t GetNumberNewSamples() const;
peah-webrtc 2016/03/18 09:18:34 What about GetNumberOfNewSamples()?
minyue-webrtc 2016/03/21 15:27:51 Done.
+
+ // Return the latest mean value.
+ float GetLatestMean() const;
+
+ private:
+ // Clear all samples added.
+ void Clear();
+
+ // Update |sum_| and |compensation_| using Kahan algorithm.
+ void KahanSum(float sample);
+
+ const size_t window_length_;
+ size_t count_;
+ float sum_;
+ float compensation_;
+ float mean_;
+
+ RTC_DISALLOW_COPY_AND_ASSIGN(MeanCalculator);
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_MEAN_CALCULATOR_H_

Powered by Google App Engine
This is Rietveld 408576698