level_estimator.h 1.6 KB

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