pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 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 WEBRTC_MODULES_AUDIO_PROCESSING_AGC_AGC_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AGC_AGC_H_ |
| 13 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 14 | #include "webrtc/base/scoped_ptr.h" |
aluebs | ecf6b81 | 2015-06-25 12:28:48 -0700 | [diff] [blame] | 15 | #include "webrtc/modules/audio_processing/vad/voice_activity_detector.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 16 | #include "webrtc/typedefs.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | class AudioFrame; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 21 | class Histogram; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 22 | |
| 23 | class Agc { |
| 24 | public: |
| 25 | Agc(); |
| 26 | virtual ~Agc(); |
| 27 | |
| 28 | // Returns the proportion of samples in the buffer which are at full-scale |
| 29 | // (and presumably clipped). |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 30 | virtual float AnalyzePreproc(const int16_t* audio, size_t length); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 31 | // |audio| must be mono; in a multi-channel stream, provide the first (usually |
| 32 | // left) channel. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 33 | virtual int Process(const int16_t* audio, size_t length, int sample_rate_hz); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 34 | |
| 35 | // Retrieves the difference between the target RMS level and the current |
| 36 | // signal RMS level in dB. Returns true if an update is available and false |
| 37 | // otherwise, in which case |error| should be ignored and no action taken. |
| 38 | virtual bool GetRmsErrorDb(int* error); |
| 39 | virtual void Reset(); |
| 40 | |
| 41 | virtual int set_target_level_dbfs(int level); |
| 42 | virtual int target_level_dbfs() const { return target_level_dbfs_; } |
| 43 | |
aluebs | ecf6b81 | 2015-06-25 12:28:48 -0700 | [diff] [blame] | 44 | virtual float voice_probability() const { |
| 45 | return vad_.last_voice_probability(); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 46 | } |
| 47 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 48 | private: |
| 49 | double target_level_loudness_; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 50 | int target_level_dbfs_; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 51 | rtc::scoped_ptr<Histogram> histogram_; |
| 52 | rtc::scoped_ptr<Histogram> inactive_histogram_; |
aluebs | ecf6b81 | 2015-06-25 12:28:48 -0700 | [diff] [blame] | 53 | VoiceActivityDetector vad_; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | } // namespace webrtc |
| 57 | |
| 58 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_AGC_H_ |