Alex Loiko | 1e48e80 | 2018-03-28 07:45:29 | [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_SATURATION_PROTECTOR_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AGC2_SATURATION_PROTECTOR_H_ |
| 13 | |
Alessio Bazzica | 980c460 | 2021-04-14 17:09:17 | [diff] [blame] | 14 | #include <memory> |
Alex Loiko | 1e48e80 | 2018-03-28 07:45:29 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
Alessio Bazzica | 980c460 | 2021-04-14 17:09:17 | [diff] [blame] | 17 | class ApmDataDumper; |
Alex Loiko | 1e48e80 | 2018-03-28 07:45:29 | [diff] [blame] | 18 | |
Alessio Bazzica | 980c460 | 2021-04-14 17:09:17 | [diff] [blame] | 19 | // Saturation protector. Analyzes peak levels and recommends a headroom to |
| 20 | // reduce the chances of clipping. |
| 21 | class SaturationProtector { |
Alex Loiko | 1e48e80 | 2018-03-28 07:45:29 | [diff] [blame] | 22 | public: |
Alessio Bazzica | 980c460 | 2021-04-14 17:09:17 | [diff] [blame] | 23 | virtual ~SaturationProtector() = default; |
Alessio Bazzica | 56f63c3 | 2020-09-29 09:56:38 | [diff] [blame] | 24 | |
Alessio Bazzica | 980c460 | 2021-04-14 17:09:17 | [diff] [blame] | 25 | // Returns the recommended headroom in dB. |
| 26 | virtual float HeadroomDb() = 0; |
Alex Loiko | 5e78461 | 2018-11-01 13:51:56 | [diff] [blame] | 27 | |
Alessio Bazzica | 980c460 | 2021-04-14 17:09:17 | [diff] [blame] | 28 | // Analyzes the peak level of a 10 ms frame along with its speech probability |
| 29 | // and the current speech level estimate to update the recommended headroom. |
| 30 | virtual void Analyze(float speech_probability, |
| 31 | float peak_dbfs, |
| 32 | float speech_level_dbfs) = 0; |
Alex Loiko | 9917c4a | 2018-04-04 12:16:10 | [diff] [blame] | 33 | |
Alessio Bazzica | 980c460 | 2021-04-14 17:09:17 | [diff] [blame] | 34 | // Resets the internal state. |
| 35 | virtual void Reset() = 0; |
Alex Loiko | 1e48e80 | 2018-03-28 07:45:29 | [diff] [blame] | 36 | }; |
| 37 | |
Alessio Bazzica | 980c460 | 2021-04-14 17:09:17 | [diff] [blame] | 38 | // Creates a saturation protector that starts at `initial_headroom_db`. |
| 39 | std::unique_ptr<SaturationProtector> CreateSaturationProtector( |
| 40 | float initial_headroom_db, |
Alessio Bazzica | 980c460 | 2021-04-14 17:09:17 | [diff] [blame] | 41 | int adjacent_speech_frames_threshold, |
| 42 | ApmDataDumper* apm_data_dumper); |
Alessio Bazzica | 56f63c3 | 2020-09-29 09:56:38 | [diff] [blame] | 43 | |
Alex Loiko | 1e48e80 | 2018-03-28 07:45:29 | [diff] [blame] | 44 | } // namespace webrtc |
| 45 | |
| 46 | #endif // MODULES_AUDIO_PROCESSING_AGC2_SATURATION_PROTECTOR_H_ |