blob: 5d34c212f3abff98ee6f3aafbdf5d801d97d2d84 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AGC_AGC_H_
12#define MODULES_AUDIO_PROCESSING_AGC_AGC_H_
pbos@webrtc.org788acd12014-12-15 09:41:24 +000013
kwiberg88788ad2016-02-19 07:04:49 -080014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_processing/vad/voice_activity_detector.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000017
18namespace webrtc {
19
20class AudioFrame;
peahbbe42332016-06-08 06:42:02 -070021class LoudnessHistogram;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000022
23class 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 Kastingdce40cf2015-08-24 14:52:23 -070030 virtual float AnalyzePreproc(const int16_t* audio, size_t length);
pbos@webrtc.org788acd12014-12-15 09:41:24 +000031 // |audio| must be mono; in a multi-channel stream, provide the first (usually
32 // left) channel.
Jonas Olsson645b0272018-02-15 15:16:27 +010033 virtual void Process(const int16_t* audio, size_t length, int sample_rate_hz);
pbos@webrtc.org788acd12014-12-15 09:41:24 +000034
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);
kwiberg8cf88982016-08-26 14:50:38 -070042 virtual int target_level_dbfs() const;
43 virtual float voice_probability() const;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000044
pbos@webrtc.org788acd12014-12-15 09:41:24 +000045 private:
46 double target_level_loudness_;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000047 int target_level_dbfs_;
peahbbe42332016-06-08 06:42:02 -070048 std::unique_ptr<LoudnessHistogram> histogram_;
49 std::unique_ptr<LoudnessHistogram> inactive_histogram_;
aluebsecf6b812015-06-25 12:28:48 -070050 VoiceActivityDetector vad_;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000051};
52
53} // namespace webrtc
54
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020055#endif // MODULES_AUDIO_PROCESSING_AGC_AGC_H_