blob: cfe51c2241bc9b419406211ac0271f3abe00c158 [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"
Alessio Bazzica3e4c77f2018-11-01 21:31:38 +010018#include "modules/audio_processing/agc2/gain_applier.h"
19#include "modules/audio_processing/agc2/limiter.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_processing/include/audio_processing.h"
Alessio Bazzica8aaa6042021-03-31 15:16:05 +020021#include "modules/audio_processing/logging/apm_data_dumper.h"
alessiob3ec96df2017-05-22 06:57:06 -070022
23namespace webrtc {
24
alessiob3ec96df2017-05-22 06:57:06 -070025class 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 Bazzica38901042021-10-14 12:14:21 +020031 GainController2(const AudioProcessing::Config::GainController2& config,
32 int sample_rate_hz,
33 int num_channels);
Alessio Bazzica8aaa6042021-03-31 15:16:05 +020034 GainController2(const GainController2&) = delete;
35 GainController2& operator=(const GainController2&) = delete;
alessiob3ec96df2017-05-22 06:57:06 -070036 ~GainController2();
37
Alessio Bazzica38901042021-10-14 12:14:21 +020038 // Detects and handles changes of sample rate and/or number of channels.
Alessio Bazzicad66a6052021-04-29 16:13:25 +020039 void Initialize(int sample_rate_hz, int num_channels);
Alessio Bazzica38901042021-10-14 12:14:21 +020040
41 // Sets the fixed digital gain.
42 void SetFixedGainDb(float gain_db);
43
44 // Applies fixed and adaptive digital gains to `audio` and runs a limiter.
alessiob3ec96df2017-05-22 06:57:06 -070045 void Process(AudioBuffer* audio);
Alessio Bazzica38901042021-10-14 12:14:21 +020046
47 // Handles analog level changes.
Alex Loikoa837dd72018-08-06 16:32:12 +020048 void NotifyAnalogLevel(int level);
alessiob3ec96df2017-05-22 06:57:06 -070049
50 static bool Validate(const AudioProcessing::Config::GainController2& config);
alessiob3ec96df2017-05-22 06:57:06 -070051
52 private:
alessiob3ec96df2017-05-22 06:57:06 -070053 static int instance_count_;
Alessio Bazzica8aaa6042021-03-31 15:16:05 +020054 ApmDataDumper data_dumper_;
Alessio Bazzica82ea4ee2021-10-07 09:21:02 +020055 GainApplier fixed_gain_applier_;
56 std::unique_ptr<AdaptiveAgc> adaptive_digital_controller_;
Alessio Bazzica3e4c77f2018-11-01 21:31:38 +010057 Limiter limiter_;
Alessio Bazzica08d2a702020-11-20 16:26:24 +010058 int calls_since_last_limiter_log_;
Alessio Bazzica38901042021-10-14 12:14:21 +020059 int analog_level_;
alessiob3ec96df2017-05-22 06:57:06 -070060};
61
62} // namespace webrtc
63
Alex Loikoe36e8bb2018-02-16 11:54:07 +010064#endif // MODULES_AUDIO_PROCESSING_GAIN_CONTROLLER2_H_