OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_RMS_LEVEL_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_RMS_LEVEL_H_ |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_RMS_LEVEL_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_RMS_LEVEL_H_ |
13 | 13 |
14 #include <cstddef> | 14 #include "webrtc/base/array_view.h" |
15 | |
16 #include "webrtc/typedefs.h" | 15 #include "webrtc/typedefs.h" |
17 | 16 |
18 namespace webrtc { | 17 namespace webrtc { |
19 | 18 |
20 // Computes the root mean square (RMS) level in dBFs (decibels from digital | 19 // Computes the root mean square (RMS) level in dBFs (decibels from digital |
21 // full-scale) of audio data. The computation follows RFC 6465: | 20 // full-scale) of audio data. The computation follows RFC 6465: |
22 // https://tools.ietf.org/html/rfc6465 | 21 // https://tools.ietf.org/html/rfc6465 |
23 // with the intent that it can provide the RTP audio level indication. | 22 // with the intent that it can provide the RTP audio level indication. |
24 // | 23 // |
25 // The expected approach is to provide constant-sized chunks of audio to | 24 // The expected approach is to provide constant-sized chunks of audio to |
26 // Process(). When enough chunks have been accumulated to form a packet, call | 25 // Process(). When enough chunks have been accumulated to form a packet, call |
27 // RMS() to get the audio level indicator for the RTP header. | 26 // RMS() to get the audio level indicator for the RTP header. |
28 class RMSLevel { | 27 class RMSLevel { |
29 public: | 28 public: |
30 static const int kMinLevel = 127; | 29 struct Levels { |
30 int average; | |
31 int peak; | |
32 }; | |
31 | 33 |
32 RMSLevel(); | 34 RMSLevel(); |
33 ~RMSLevel(); | 35 ~RMSLevel(); |
34 | 36 |
35 // Can be called to reset internal states, but is not required during normal | 37 // Can be called to reset internal states, but is not required during normal |
36 // operation. | 38 // operation. |
37 void Reset(); | 39 void Reset(); |
38 | 40 |
39 // Pass each chunk of audio to Process() to accumulate the level. | 41 // Pass each chunk of audio to Process() to accumulate the level. |
40 void Process(const int16_t* data, size_t length); | 42 void Process(rtc::ArrayView<const int16_t> data); |
peah-webrtc
2016/11/29 08:57:13
While you are anyway changing this: Would it make
hlundin-webrtc
2016/11/29 10:24:55
Done.
| |
41 | 43 |
42 // If all samples with the given |length| have a magnitude of zero, this is | 44 // If all samples with the given |length| have a magnitude of zero, this is |
43 // a shortcut to avoid some computation. | 45 // a shortcut to avoid some computation. |
44 void ProcessMuted(size_t length); | 46 void ProcessMuted(size_t length); |
45 | 47 |
46 // Computes the RMS level over all data passed to Process() since the last | 48 // Computes the RMS level over all data passed to Process() since the last |
47 // call to RMS(). The returned value is positive but should be interpreted as | 49 // call to RMS(). The returned value is positive but should be interpreted as |
48 // negative as per the RFC. It is constrained to [0, 127]. | 50 // negative as per the RFC. It is constrained to [0, 127]. Resets the internal |
51 // state to start a new measurement period. | |
49 int RMS(); | 52 int RMS(); |
peah-webrtc
2016/11/29 08:57:13
Suggestion: I think it would make sense to rename
hlundin-webrtc
2016/11/29 10:24:55
Done.
| |
50 | 53 |
54 // Like RMS() above, but also returns the RMS peak value. Resets the internal | |
55 // state to start a new measurement period. | |
56 Levels AverageAndPeak(); | |
57 | |
51 private: | 58 private: |
52 float sum_square_; | 59 float sum_square_; |
53 size_t sample_count_; | 60 size_t sample_count_; |
61 float max_mean_square_; | |
54 }; | 62 }; |
55 | 63 |
56 } // namespace webrtc | 64 } // namespace webrtc |
57 | 65 |
58 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_RMS_LEVEL_H_ | 66 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_RMS_LEVEL_H_ |
59 | 67 |
OLD | NEW |