blob: b49b8d0992b2c16d8685cdb2454ada2664f080f0 [file] [log] [blame]
alessiob3ec96df2017-05-22 06:57:06 -07001/*
2 * Copyright (c) 2017 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
Alex Loikoe36e8bb2018-02-16 11:54:07 +010011#ifndef MODULES_AUDIO_PROCESSING_GAIN_CONTROLLER2_H_
12#define MODULES_AUDIO_PROCESSING_GAIN_CONTROLLER2_H_
alessiob3ec96df2017-05-22 06:57:06 -070013
14#include <memory>
15#include <string>
16
Alex Loiko9d2788f2018-03-29 11:02:43 +020017#include "modules/audio_processing/agc2/adaptive_agc.h"
Alex Loikoe36e8bb2018-02-16 11:54:07 +010018#include "modules/audio_processing/agc2/fixed_gain_controller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/audio_processing/include/audio_processing.h"
20#include "rtc_base/constructormagic.h"
alessiob3ec96df2017-05-22 06:57:06 -070021
22namespace webrtc {
23
24class ApmDataDumper;
25class AudioBuffer;
26
27// Gain Controller 2 aims to automatically adjust levels by acting on the
28// microphone gain and/or applying digital gain.
alessiob3ec96df2017-05-22 06:57:06 -070029class GainController2 {
30 public:
Alessio Bazzica270f7b52017-10-13 11:05:17 +020031 GainController2();
alessiob3ec96df2017-05-22 06:57:06 -070032 ~GainController2();
33
Alessio Bazzica270f7b52017-10-13 11:05:17 +020034 void Initialize(int sample_rate_hz);
alessiob3ec96df2017-05-22 06:57:06 -070035 void Process(AudioBuffer* audio);
Alex Loikoa837dd72018-08-06 16:32:12 +020036 void NotifyAnalogLevel(int level);
alessiob3ec96df2017-05-22 06:57:06 -070037
Alessio Bazzica270f7b52017-10-13 11:05:17 +020038 void ApplyConfig(const AudioProcessing::Config::GainController2& config);
alessiob3ec96df2017-05-22 06:57:06 -070039 static bool Validate(const AudioProcessing::Config::GainController2& config);
40 static std::string ToString(
41 const AudioProcessing::Config::GainController2& config);
42
43 private:
alessiob3ec96df2017-05-22 06:57:06 -070044 static int instance_count_;
Alessio Bazzica270f7b52017-10-13 11:05:17 +020045 std::unique_ptr<ApmDataDumper> data_dumper_;
Alex Loiko9d2788f2018-03-29 11:02:43 +020046 FixedGainController fixed_gain_controller_;
Alex Loikoe36e8bb2018-02-16 11:54:07 +010047 AudioProcessing::Config::GainController2 config_;
Alex Loiko5e784612018-11-01 14:51:56 +010048 std::unique_ptr<AdaptiveAgc> adaptive_agc_;
Alex Loikoa837dd72018-08-06 16:32:12 +020049 int analog_level_ = -1;
Alex Loikoe5831742018-08-24 11:28:36 +020050 bool adaptive_digital_mode_ = true;
Alessio Bazzica270f7b52017-10-13 11:05:17 +020051
alessiob3ec96df2017-05-22 06:57:06 -070052 RTC_DISALLOW_COPY_AND_ASSIGN(GainController2);
53};
54
55} // namespace webrtc
56
Alex Loikoe36e8bb2018-02-16 11:54:07 +010057#endif // MODULES_AUDIO_PROCESSING_GAIN_CONTROLLER2_H_