Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * 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.
| |
| 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_MEAN_CALCULATOR_H_ | |
| 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_MEAN_CALCULATOR_H_ | |
| 13 | |
|
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
| |
| 14 #include <memory> | |
| 15 #include <stddef.h> | |
| 16 | |
| 17 #include "webrtc/base/criticalsection.h" | |
| 18 #include "webrtc/base/constructormagic.h" | |
| 19 #include "webrtc/base/optional.h" | |
| 20 | |
| 21 namespace webrtc { | |
| 22 | |
| 23 // MeanCalculator calculates the mean of a sample sequence of a certain length. | |
| 24 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.
| |
| 25 public: | |
| 26 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?
| |
| 27 ~MeanCalculator(); | |
| 28 | |
| 29 // Add one sample to the sequence. | |
| 30 void AddSample(float sample); | |
| 31 | |
| 32 // Get the mean of the latest samples. Returns the mean if it is available, | |
| 33 // otherwise null, which happens when the added samples have not fully filled | |
| 34 // the window. | |
| 35 rtc::Optional<float> GetMean(); | |
| 36 | |
| 37 // Flush all samples added. | |
| 38 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.
| |
| 39 | |
| 40 // Determines if the window is full. This is a quick way of checking if the | |
| 41 // mean is ready. | |
| 42 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
| |
| 43 | |
| 44 private: | |
| 45 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
| |
| 46 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
| |
| 47 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.
| |
| 48 size_t head_ GUARDED_BY(crit_); | |
| 49 bool full_ GUARDED_BY(crit_); | |
| 50 float sum_ GUARDED_BY(crit_); | |
| 51 | |
| 52 RTC_DISALLOW_COPY_AND_ASSIGN(MeanCalculator); | |
| 53 }; | |
| 54 | |
| 55 } // namespace webrtc | |
| 56 | |
| 57 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_MEAN_CALCULATOR_H | |
| OLD | NEW |