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 11 #ifndef MODULES_AUDIO_PROCESSING_AGC_AGC_H_ 12 #define MODULES_AUDIO_PROCESSING_AGC_AGC_H_ 13 14 #include <memory> 15 16 #include "api/array_view.h" 17 #include "modules/audio_processing/vad/voice_activity_detector.h" 18 19 namespace webrtc { 20 21 class LoudnessHistogram; 22 23 class Agc { 24 public: 25 Agc(); 26 virtual ~Agc(); 27 28 // `audio` must be mono; in a multi-channel stream, provide the first (usually 29 // left) channel. 30 virtual void Process(rtc::ArrayView<const int16_t> audio); 31 32 // Retrieves the difference between the target RMS level and the current 33 // signal RMS level in dB. Returns true if an update is available and false 34 // otherwise, in which case `error` should be ignored and no action taken. 35 virtual bool GetRmsErrorDb(int* error); 36 virtual void Reset(); 37 38 virtual int set_target_level_dbfs(int level); 39 virtual int target_level_dbfs() const; 40 virtual float voice_probability() const; 41 42 private: 43 double target_level_loudness_; 44 int target_level_dbfs_; 45 std::unique_ptr<LoudnessHistogram> histogram_; 46 std::unique_ptr<LoudnessHistogram> inactive_histogram_; 47 VoiceActivityDetector vad_; 48 }; 49 50 } // namespace webrtc 51 52 #endif // MODULES_AUDIO_PROCESSING_AGC_AGC_H_ 53