vad_with_level.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2018 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_AGC2_VAD_WITH_LEVEL_H_
  11. #define MODULES_AUDIO_PROCESSING_AGC2_VAD_WITH_LEVEL_H_
  12. #include <memory>
  13. #include "modules/audio_processing/include/audio_frame_view.h"
  14. namespace webrtc {
  15. // Class to analyze voice activity and audio levels.
  16. class VadLevelAnalyzer {
  17. public:
  18. struct Result {
  19. float speech_probability; // Range: [0, 1].
  20. float rms_dbfs; // Root mean square power (dBFS).
  21. float peak_dbfs; // Peak power (dBFS).
  22. };
  23. // Voice Activity Detector (VAD) interface.
  24. class VoiceActivityDetector {
  25. public:
  26. virtual ~VoiceActivityDetector() = default;
  27. // Analyzes an audio frame and returns the speech probability.
  28. virtual float ComputeProbability(AudioFrameView<const float> frame) = 0;
  29. };
  30. // Ctor. Uses the default VAD.
  31. VadLevelAnalyzer();
  32. explicit VadLevelAnalyzer(float vad_probability_attack);
  33. // Ctor. Uses a custom `vad`.
  34. VadLevelAnalyzer(float vad_probability_attack,
  35. std::unique_ptr<VoiceActivityDetector> vad);
  36. VadLevelAnalyzer(const VadLevelAnalyzer&) = delete;
  37. VadLevelAnalyzer& operator=(const VadLevelAnalyzer&) = delete;
  38. ~VadLevelAnalyzer();
  39. // Computes the speech probability and the level for `frame`.
  40. Result AnalyzeFrame(AudioFrameView<const float> frame);
  41. private:
  42. std::unique_ptr<VoiceActivityDetector> vad_;
  43. const float vad_probability_attack_;
  44. float vad_probability_ = 0.f;
  45. };
  46. } // namespace webrtc
  47. #endif // MODULES_AUDIO_PROCESSING_AGC2_VAD_WITH_LEVEL_H_