Alex Loiko | 2bac896 | 2018-03-27 13:38:36 +0200 | [diff] [blame] | 1 | /* |
| 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 Bazzica | 11bd143 | 2021-04-07 14:57:40 +0200 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Alex Loiko | 2bac896 | 2018-03-27 13:38:36 +0200 | [diff] [blame] | 16 | #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 Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 19 | #include "modules/audio_processing/agc2/saturation_protector.h" |
Alex Loiko | db6af36 | 2018-06-20 14:14:18 +0200 | [diff] [blame] | 20 | #include "modules/audio_processing/agc2/vad_with_level.h" |
Alex Loiko | 2bac896 | 2018-03-27 13:38:36 +0200 | [diff] [blame] | 21 | #include "modules/audio_processing/include/audio_frame_view.h" |
Alessio Bazzica | 1e2542f | 2018-11-13 14:44:15 +0100 | [diff] [blame] | 22 | #include "modules/audio_processing/include/audio_processing.h" |
Alex Loiko | 2bac896 | 2018-03-27 13:38:36 +0200 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | class ApmDataDumper; |
| 26 | |
Alessio Bazzica | d5e6f41 | 2020-09-30 13:07:57 +0200 | [diff] [blame] | 27 | // Adaptive digital gain controller. |
Alessio Bazzica | d66a605 | 2021-04-29 16:13:25 +0200 | [diff] [blame] | 28 | // TODO(crbug.com/webrtc/7494): Rename to `AdaptiveDigitalGainController`. |
Alex Loiko | 2bac896 | 2018-03-27 13:38:36 +0200 | [diff] [blame] | 29 | class AdaptiveAgc { |
| 30 | public: |
Alessio Bazzica | 61982a7 | 2021-04-14 16:17:09 +0200 | [diff] [blame] | 31 | AdaptiveAgc( |
| 32 | ApmDataDumper* apm_data_dumper, |
| 33 | const AudioProcessing::Config::GainController2::AdaptiveDigital& config); |
Alex Loiko | 2bac896 | 2018-03-27 13:38:36 +0200 | [diff] [blame] | 34 | ~AdaptiveAgc(); |
| 35 | |
Alessio Bazzica | d66a605 | 2021-04-29 16:13:25 +0200 | [diff] [blame] | 36 | void Initialize(int sample_rate_hz, int num_channels); |
| 37 | |
| 38 | // TODO(crbug.com/webrtc/7494): Add `SetLimiterEnvelope()`. |
| 39 | |
Alessio Bazzica | d5e6f41 | 2020-09-30 13:07:57 +0200 | [diff] [blame] | 40 | // Analyzes `frame` and applies a digital adaptive gain to it. Takes into |
| 41 | // account the envelope measured by the limiter. |
Alessio Bazzica | d66a605 | 2021-04-29 16:13:25 +0200 | [diff] [blame] | 42 | // TODO(crbug.com/webrtc/7494): Remove `limiter_envelope`. |
Alessio Bazzica | d5e6f41 | 2020-09-30 13:07:57 +0200 | [diff] [blame] | 43 | void Process(AudioFrameView<float> frame, float limiter_envelope); |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 44 | |
| 45 | // Handles a gain change applied to the input signal (e.g., analog gain). |
| 46 | void HandleInputGainChange(); |
Alex Loiko | a837dd7 | 2018-08-06 16:32:12 +0200 | [diff] [blame] | 47 | |
Alex Loiko | 2bac896 | 2018-03-27 13:38:36 +0200 | [diff] [blame] | 48 | private: |
| 49 | AdaptiveModeLevelEstimator speech_level_estimator_; |
Alessio Bazzica | 530781d | 2020-09-25 13:24:36 +0200 | [diff] [blame] | 50 | VadLevelAnalyzer vad_; |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 51 | AdaptiveDigitalGainApplier gain_controller_; |
Alex Loiko | 2bac896 | 2018-03-27 13:38:36 +0200 | [diff] [blame] | 52 | ApmDataDumper* const apm_data_dumper_; |
Alessio Bazzica | 11bd143 | 2021-04-07 14:57:40 +0200 | [diff] [blame] | 53 | std::unique_ptr<NoiseLevelEstimator> noise_level_estimator_; |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 54 | std::unique_ptr<SaturationProtector> saturation_protector_; |
Alex Loiko | 2bac896 | 2018-03-27 13:38:36 +0200 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // namespace webrtc |
| 58 | |
| 59 | #endif // MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_AGC_H_ |