summaryrefslogtreecommitdiff
path: root/webrtc/modules/audio_processing/level_estimator.h
blob: 1d8a0712b58df5ff55da2ef0fa8fc232f53ba99c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 *  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
 *
 *  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 MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_H_
#define MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_H_

#include "modules/audio_processing/audio_buffer.h"
#include "modules/audio_processing/rms_level.h"

namespace webrtc {

// An estimation component used to retrieve level metrics.
class LevelEstimator {
 public:
  LevelEstimator();
  ~LevelEstimator();

  LevelEstimator(LevelEstimator&) = delete;
  LevelEstimator& operator=(LevelEstimator&) = delete;

  void ProcessStream(const AudioBuffer& audio);

  // Returns the root mean square (RMS) level in dBFs (decibels from digital
  // full-scale), or alternately dBov. It is computed over all primary stream
  // frames since the last call to RMS(). The returned value is positive but
  // should be interpreted as negative. It is constrained to [0, 127].
  //
  // The computation follows: https://tools.ietf.org/html/rfc6465
  // with the intent that it can provide the RTP audio level indication.
  //
  // Frames passed to ProcessStream() with an |_energy| of zero are considered
  // to have been muted. The RMS of the frame will be interpreted as -127.
  int RMS() { return rms_.Average(); }

 private:
  RmsLevel rms_;
};
}  // namespace webrtc

#endif  // MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_H_