blob: 1ecdab1166bf5b612af51540ee6d32a32bb6df96 [file] [log] [blame]
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001/*
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.org00b8f6b2015-02-26 14:34:55 +000014#include "webrtc/base/scoped_ptr.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000015#include "webrtc/typedefs.h"
16
17namespace webrtc {
18
19class AudioFrame;
Bjorn Volcker51c7cbb2015-06-25 08:46:02 +020020class AgcAudioProc;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000021class Histogram;
Bjorn Volcker51c7cbb2015-06-25 08:46:02 +020022class PitchBasedVad;
23class Resampler;
24class StandaloneVad;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000025
26class Agc {
27 public:
28 Agc();
29 virtual ~Agc();
30
31 // Returns the proportion of samples in the buffer which are at full-scale
32 // (and presumably clipped).
33 virtual float AnalyzePreproc(const int16_t* audio, int length);
34 // |audio| must be mono; in a multi-channel stream, provide the first (usually
35 // left) channel.
36 virtual int Process(const int16_t* audio, int length, int sample_rate_hz);
37
38 // Retrieves the difference between the target RMS level and the current
39 // signal RMS level in dB. Returns true if an update is available and false
40 // otherwise, in which case |error| should be ignored and no action taken.
41 virtual bool GetRmsErrorDb(int* error);
42 virtual void Reset();
43
44 virtual int set_target_level_dbfs(int level);
45 virtual int target_level_dbfs() const { return target_level_dbfs_; }
46
Bjorn Volcker51c7cbb2015-06-25 08:46:02 +020047 virtual void EnableStandaloneVad(bool enable);
48 virtual bool standalone_vad_enabled() const {
49 return standalone_vad_enabled_;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000050 }
51
Bjorn Volcker51c7cbb2015-06-25 08:46:02 +020052 virtual double voice_probability() const { return last_voice_probability_; }
53
pbos@webrtc.org788acd12014-12-15 09:41:24 +000054 private:
55 double target_level_loudness_;
Bjorn Volcker51c7cbb2015-06-25 08:46:02 +020056 double last_voice_probability_;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000057 int target_level_dbfs_;
Bjorn Volcker51c7cbb2015-06-25 08:46:02 +020058 bool standalone_vad_enabled_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000059 rtc::scoped_ptr<Histogram> histogram_;
60 rtc::scoped_ptr<Histogram> inactive_histogram_;
Bjorn Volcker51c7cbb2015-06-25 08:46:02 +020061 rtc::scoped_ptr<AgcAudioProc> audio_processing_;
62 rtc::scoped_ptr<PitchBasedVad> pitch_based_vad_;
63 rtc::scoped_ptr<StandaloneVad> standalone_vad_;
64 rtc::scoped_ptr<Resampler> resampler_;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000065};
66
67} // namespace webrtc
68
69#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_AGC_H_