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..041cdab86f1a22b195ff5b11bdde8d29722e2dd6 |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/utility/mean_calculator.h |
@@ -0,0 +1,57 @@ |
+/* |
+ * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
peah-webrtc
2016/03/14 09:12:53
The year should be 2016.
minyue-webrtc
2016/03/14 14:51:42
yes, thanks
peah-webrtc
2016/03/15 09:18:41
Acknowledged.
|
+ * |
+ * 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_ |
+ |
peah-webrtc
2016/03/14 09:12:53
Until there are more uses of this class, I think i
minyue-webrtc
2016/03/14 14:51:42
As mentioned in an earlier reply, the reason of wr
peah-webrtc
2016/03/15 09:18:41
I think that it then is better to delay the introd
minyue-webrtc
2016/04/03 21:42:05
Ok, sure. I will remove it
|
+#include <memory> |
+#include <stddef.h> |
+ |
+#include "webrtc/base/criticalsection.h" |
+#include "webrtc/base/constructormagic.h" |
+#include "webrtc/base/optional.h" |
+ |
+namespace webrtc { |
+ |
+// MeanCalculator calculates the mean of a sample sequence of a certain length. |
+class MeanCalculator { |
peah-webrtc
2016/03/14 09:12:53
In the code, this class is currently only used to
minyue-webrtc
2016/03/14 14:51:42
replied in earlier comments
peah-webrtc
2016/03/15 09:18:40
Acknowledged.
|
+ public: |
+ explicit MeanCalculator(size_t window_length); |
peah-webrtc
2016/03/14 09:12:53
The name of this class is a bit too vague I think.
minyue-webrtc
2016/03/14 14:51:42
I am very bad at naming, do you have any suggestio
peah-webrtc
2016/03/15 09:18:41
What about SlidingWindowAverage?
|
+ ~MeanCalculator(); |
+ |
+ // Add one sample to the sequence. |
+ void AddSample(float sample); |
+ |
+ // Get the mean of the latest samples. Returns the mean if it is available, |
+ // otherwise null, which happens when the added samples have not fully filled |
+ // the window. |
+ rtc::Optional<float> GetMean(); |
+ |
+ // Flush all samples added. |
+ void Flush(); |
peah-webrtc
2016/03/14 09:12:53
What about Clear() ?
minyue-webrtc
2016/03/14 14:51:42
I'd buy it.
peah-webrtc
2016/03/15 09:18:41
Acknowledged.
|
+ |
+ // Determines if the window is full. This is a quick way of checking if the |
+ // mean is ready. |
+ bool IsWindowFull(); |
peah-webrtc
2016/03/14 09:12:53
The return of an optional and this function provid
peah-webrtc
2016/03/14 09:12:53
Should be declared const
minyue-webrtc
2016/03/14 14:51:42
I think that using GetMean() to determine IsWindow
minyue-webrtc
2016/03/14 14:51:42
Yes, thanks.
peah-webrtc
2016/03/15 09:18:40
It totally depends on how it is to be used. Since
|
+ |
+ private: |
+ rtc::CriticalSection crit_; |
peah-webrtc
2016/03/14 09:12:53
Why is a lock required in this class? It is not cu
minyue-webrtc
2016/03/14 14:51:42
There is no trouble on the current use case of it.
peah-webrtc
2016/03/15 09:18:40
The problem with a lock is that it adds a cost and
|
+ size_t window_length_ GUARDED_BY(crit_); |
peah-webrtc
2016/03/14 09:12:53
This variable can be removed if you use a vector (
minyue-webrtc
2016/03/14 14:51:42
Doesn't size() give the actual number of values ad
peah-webrtc
2016/03/15 09:18:41
The vector should be preallocated to the size of t
|
+ std::unique_ptr<float[]> buffer_ GUARDED_BY(crit_); |
peah-webrtc
2016/03/14 09:12:53
Please use a vector instead of a dynamically alloc
minyue-webrtc
2016/03/14 14:51:42
ok.
peah-webrtc
2016/03/15 09:18:41
Acknowledged.
|
+ size_t head_ GUARDED_BY(crit_); |
+ bool full_ GUARDED_BY(crit_); |
+ float sum_ GUARDED_BY(crit_); |
+ |
+ RTC_DISALLOW_COPY_AND_ASSIGN(MeanCalculator); |
+}; |
+ |
+} // namespace webrtc |
+ |
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_MEAN_CALCULATOR_H |