blob: 43c7787e368d81d816c9cd6a2a3846a338631aa4 [file] [log] [blame]
Alex Loiko2bac8962018-03-27 13:38:36 +02001/*
2 * Copyright (c) 2018 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 MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_AGC_H_
12#define MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_AGC_H_
13
Alessio Bazzica11bd1432021-04-07 14:57:40 +020014#include <memory>
15
Alex Loiko2bac8962018-03-27 13:38:36 +020016#include "modules/audio_processing/agc2/adaptive_digital_gain_applier.h"
17#include "modules/audio_processing/agc2/adaptive_mode_level_estimator.h"
18#include "modules/audio_processing/agc2/noise_level_estimator.h"
Alessio Bazzica980c4602021-04-14 19:09:17 +020019#include "modules/audio_processing/agc2/saturation_protector.h"
Alex Loikodb6af362018-06-20 14:14:18 +020020#include "modules/audio_processing/agc2/vad_with_level.h"
Alex Loiko2bac8962018-03-27 13:38:36 +020021#include "modules/audio_processing/include/audio_frame_view.h"
Alessio Bazzica1e2542f2018-11-13 14:44:15 +010022#include "modules/audio_processing/include/audio_processing.h"
Alex Loiko2bac8962018-03-27 13:38:36 +020023
24namespace webrtc {
25class ApmDataDumper;
26
Alessio Bazzicad5e6f412020-09-30 13:07:57 +020027// Adaptive digital gain controller.
Alessio Bazzicad66a6052021-04-29 16:13:25 +020028// TODO(crbug.com/webrtc/7494): Rename to `AdaptiveDigitalGainController`.
Alex Loiko2bac8962018-03-27 13:38:36 +020029class AdaptiveAgc {
30 public:
Alessio Bazzica61982a72021-04-14 16:17:09 +020031 AdaptiveAgc(
32 ApmDataDumper* apm_data_dumper,
33 const AudioProcessing::Config::GainController2::AdaptiveDigital& config);
Alex Loiko2bac8962018-03-27 13:38:36 +020034 ~AdaptiveAgc();
35
Alessio Bazzicad66a6052021-04-29 16:13:25 +020036 void Initialize(int sample_rate_hz, int num_channels);
37
38 // TODO(crbug.com/webrtc/7494): Add `SetLimiterEnvelope()`.
39
Alessio Bazzicad5e6f412020-09-30 13:07:57 +020040 // Analyzes `frame` and applies a digital adaptive gain to it. Takes into
41 // account the envelope measured by the limiter.
Alessio Bazzicad66a6052021-04-29 16:13:25 +020042 // TODO(crbug.com/webrtc/7494): Remove `limiter_envelope`.
Alessio Bazzicad5e6f412020-09-30 13:07:57 +020043 void Process(AudioFrameView<float> frame, float limiter_envelope);
Alessio Bazzica980c4602021-04-14 19:09:17 +020044
45 // Handles a gain change applied to the input signal (e.g., analog gain).
46 void HandleInputGainChange();
Alex Loikoa837dd72018-08-06 16:32:12 +020047
Alex Loiko2bac8962018-03-27 13:38:36 +020048 private:
49 AdaptiveModeLevelEstimator speech_level_estimator_;
Alessio Bazzica530781d2020-09-25 13:24:36 +020050 VadLevelAnalyzer vad_;
Alessio Bazzica980c4602021-04-14 19:09:17 +020051 AdaptiveDigitalGainApplier gain_controller_;
Alex Loiko2bac8962018-03-27 13:38:36 +020052 ApmDataDumper* const apm_data_dumper_;
Alessio Bazzica11bd1432021-04-07 14:57:40 +020053 std::unique_ptr<NoiseLevelEstimator> noise_level_estimator_;
Alessio Bazzica980c4602021-04-14 19:09:17 +020054 std::unique_ptr<SaturationProtector> saturation_protector_;
Alex Loiko2bac8962018-03-27 13:38:36 +020055};
56
57} // namespace webrtc
58
59#endif // MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_AGC_H_