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

Side by Side Diff: webrtc/modules/audio_processing/rms_level.h

Issue 2535523002: Refactor RMSLevel and give it new functionality (Closed)
Patch Set: Rename to RmsLevel Created 4 years 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 unified diff | Download patch
OLDNEW
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 15 #include "webrtc/base/optional.h"
16 #include "webrtc/typedefs.h" 16 #include "webrtc/typedefs.h"
17 17
18 namespace webrtc { 18 namespace webrtc {
19 19
20 // Computes the root mean square (RMS) level in dBFs (decibels from digital 20 // Computes the root mean square (RMS) level in dBFs (decibels from digital
21 // full-scale) of audio data. The computation follows RFC 6465: 21 // full-scale) of audio data. The computation follows RFC 6465:
22 // https://tools.ietf.org/html/rfc6465 22 // https://tools.ietf.org/html/rfc6465
23 // with the intent that it can provide the RTP audio level indication. 23 // with the intent that it can provide the RTP audio level indication.
24 // 24 //
25 // The expected approach is to provide constant-sized chunks of audio to 25 // 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 26 // Analyze(). When enough chunks have been accumulated to form a packet, call
27 // RMS() to get the audio level indicator for the RTP header. 27 // Average() to get the audio level indicator for the RTP header.
28 class RMSLevel { 28 class RmsLevel {
29 public: 29 public:
30 static const int kMinLevel = 127; 30 struct Levels {
31 int average;
32 int peak;
33 };
31 34
32 RMSLevel(); 35 RmsLevel();
33 ~RMSLevel(); 36 ~RmsLevel();
34 37
35 // Can be called to reset internal states, but is not required during normal 38 // Can be called to reset internal states, but is not required during normal
36 // operation. 39 // operation.
37 void Reset(); 40 void Reset();
38 41
39 // Pass each chunk of audio to Process() to accumulate the level. 42 // Pass each chunk of audio to Analyze() to accumulate the level.
40 void Process(const int16_t* data, size_t length); 43 void Analyze(rtc::ArrayView<const int16_t> data);
41 44
42 // If all samples with the given |length| have a magnitude of zero, this is 45 // If all samples with the given |length| have a magnitude of zero, this is
43 // a shortcut to avoid some computation. 46 // a shortcut to avoid some computation.
44 void ProcessMuted(size_t length); 47 void AnalyzeMuted(size_t length);
45 48
46 // Computes the RMS level over all data passed to Process() since the last 49 // Computes the RMS level over all data passed to Analyze() since the last
47 // call to RMS(). The returned value is positive but should be interpreted as 50 // call to Average(). The returned value is positive but should be interpreted
48 // negative as per the RFC. It is constrained to [0, 127]. 51 // as negative as per the RFC. It is constrained to [0, 127]. Resets the
49 int RMS(); 52 // internal state to start a new measurement period.
53 int Average();
54
55 // Like Average() above, but also returns the RMS peak value. Resets the
56 // internal state to start a new measurement period.
57 Levels AverageAndPeak();
50 58
51 private: 59 private:
60 // Compares |block_size| with |block_size_|. If they are different, calls
61 // Reset() and stores the new size.
62 void CheckBlockSize(size_t block_size);
63
52 float sum_square_; 64 float sum_square_;
53 size_t sample_count_; 65 size_t sample_count_;
66 float max_sum_square_;
67 rtc::Optional<size_t> block_size_;
54 }; 68 };
55 69
56 } // namespace webrtc 70 } // namespace webrtc
57 71
58 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_RMS_LEVEL_H_ 72 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_RMS_LEVEL_H_
59 73
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/level_estimator_impl.cc ('k') | webrtc/modules/audio_processing/rms_level.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698