• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
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 MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_H_
12 #define MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_H_
13 
14 #include "modules/audio_processing/audio_buffer.h"
15 #include "modules/audio_processing/rms_level.h"
16 
17 namespace webrtc {
18 
19 // An estimation component used to retrieve level metrics.
20 class LevelEstimator {
21  public:
22   LevelEstimator();
23   ~LevelEstimator();
24 
25   LevelEstimator(LevelEstimator&) = delete;
26   LevelEstimator& operator=(LevelEstimator&) = delete;
27 
28   void ProcessStream(const AudioBuffer& audio);
29 
30   // Returns the root mean square (RMS) level in dBFs (decibels from digital
31   // full-scale), or alternately dBov. It is computed over all primary stream
32   // frames since the last call to RMS(). The returned value is positive but
33   // should be interpreted as negative. It is constrained to [0, 127].
34   //
35   // The computation follows: https://tools.ietf.org/html/rfc6465
36   // with the intent that it can provide the RTP audio level indication.
37   //
38   // Frames passed to ProcessStream() with an |_energy| of zero are considered
39   // to have been muted. The RMS of the frame will be interpreted as -127.
RMS()40   int RMS() { return rms_.Average(); }
41 
42  private:
43   RmsLevel rms_;
44 };
45 }  // namespace webrtc
46 
47 #endif  // MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_H_
48