You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2012 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_AGC_AGC_H_
  11. #define MODULES_AUDIO_PROCESSING_AGC_AGC_H_
  12. #include <memory>
  13. #include "modules/audio_processing/vad/voice_activity_detector.h"
  14. namespace webrtc {
  15. class LoudnessHistogram;
  16. class Agc {
  17. public:
  18. Agc();
  19. virtual ~Agc();
  20. // Returns the proportion of samples in the buffer which are at full-scale
  21. // (and presumably clipped).
  22. virtual float AnalyzePreproc(const int16_t* audio, size_t length);
  23. // |audio| must be mono; in a multi-channel stream, provide the first (usually
  24. // left) channel.
  25. virtual void Process(const int16_t* audio, size_t length, int sample_rate_hz);
  26. // Retrieves the difference between the target RMS level and the current
  27. // signal RMS level in dB. Returns true if an update is available and false
  28. // otherwise, in which case |error| should be ignored and no action taken.
  29. virtual bool GetRmsErrorDb(int* error);
  30. virtual void Reset();
  31. virtual int set_target_level_dbfs(int level);
  32. virtual int target_level_dbfs() const;
  33. virtual float voice_probability() const;
  34. private:
  35. double target_level_loudness_;
  36. int target_level_dbfs_;
  37. std::unique_ptr<LoudnessHistogram> histogram_;
  38. std::unique_ptr<LoudnessHistogram> inactive_histogram_;
  39. VoiceActivityDetector vad_;
  40. };
  41. } // namespace webrtc
  42. #endif // MODULES_AUDIO_PROCESSING_AGC_AGC_H_