Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [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 | |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_LIMITER_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AGC2_LIMITER_H_ |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 13 | |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 14 | #include <string> |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
| 17 | #include "modules/audio_processing/agc2/fixed_digital_level_estimator.h" |
| 18 | #include "modules/audio_processing/agc2/interpolated_gain_curve.h" |
| 19 | #include "modules/audio_processing/include/audio_frame_view.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "rtc_base/constructor_magic.h" |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | class ApmDataDumper; |
| 24 | |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 25 | class Limiter { |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 26 | public: |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 27 | Limiter(size_t sample_rate_hz, |
| 28 | ApmDataDumper* apm_data_dumper, |
| 29 | std::string histogram_name_prefix); |
| 30 | Limiter(const Limiter& limiter) = delete; |
| 31 | Limiter& operator=(const Limiter& limiter) = delete; |
| 32 | ~Limiter(); |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 33 | |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 34 | // Applies limiter and hard-clipping to |signal|. |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 35 | void Process(AudioFrameView<float> signal); |
| 36 | InterpolatedGainCurve::Stats GetGainCurveStats() const; |
| 37 | |
| 38 | // Supported rates must be |
| 39 | // * supported by FixedDigitalLevelEstimator |
| 40 | // * below kMaximalNumberOfSamplesPerChannel*1000/kFrameDurationMs |
| 41 | // so that samples_per_channel fit in the |
| 42 | // per_sample_scaling_factors_ array. |
| 43 | void SetSampleRate(size_t sample_rate_hz); |
| 44 | |
Alessio Bazzica | 82ec0fa | 2018-08-27 14:24:16 +0200 | [diff] [blame] | 45 | // Resets the internal state. |
| 46 | void Reset(); |
| 47 | |
Alex Loiko | 93e5750 | 2018-10-01 16:28:47 +0200 | [diff] [blame] | 48 | float LastAudioLevel() const; |
| 49 | |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 50 | private: |
| 51 | const InterpolatedGainCurve interp_gain_curve_; |
| 52 | FixedDigitalLevelEstimator level_estimator_; |
| 53 | ApmDataDumper* const apm_data_dumper_ = nullptr; |
| 54 | |
| 55 | // Work array containing the sub-frame scaling factors to be interpolated. |
| 56 | std::array<float, kSubFramesInFrame + 1> scaling_factors_ = {}; |
| 57 | std::array<float, kMaximalNumberOfSamplesPerChannel> |
| 58 | per_sample_scaling_factors_ = {}; |
| 59 | float last_scaling_factor_ = 1.f; |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } // namespace webrtc |
| 63 | |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 64 | #endif // MODULES_AUDIO_PROCESSING_AGC2_LIMITER_H_ |