blob: 0c384f1fa0b161b0ae7f691d42deed4414649bdc [file] [log] [blame]
Alex Loiko1e48e802018-03-28 09:45:29 +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_SATURATION_PROTECTOR_H_
12#define MODULES_AUDIO_PROCESSING_AGC2_SATURATION_PROTECTOR_H_
13
Alessio Bazzica980c4602021-04-14 19:09:17 +020014#include <memory>
Alex Loiko1e48e802018-03-28 09:45:29 +020015
16namespace webrtc {
Alessio Bazzica980c4602021-04-14 19:09:17 +020017class ApmDataDumper;
Alex Loiko1e48e802018-03-28 09:45:29 +020018
Alessio Bazzica980c4602021-04-14 19:09:17 +020019// Saturation protector. Analyzes peak levels and recommends a headroom to
20// reduce the chances of clipping.
21class SaturationProtector {
Alex Loiko1e48e802018-03-28 09:45:29 +020022 public:
Alessio Bazzica980c4602021-04-14 19:09:17 +020023 virtual ~SaturationProtector() = default;
Alessio Bazzica56f63c32020-09-29 11:56:38 +020024
Alessio Bazzica980c4602021-04-14 19:09:17 +020025 // Returns the recommended headroom in dB.
26 virtual float HeadroomDb() = 0;
Alex Loiko5e784612018-11-01 14:51:56 +010027
Alessio Bazzica980c4602021-04-14 19:09:17 +020028 // 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 Loiko9917c4a2018-04-04 14:16:10 +020033
Alessio Bazzica980c4602021-04-14 19:09:17 +020034 // Resets the internal state.
35 virtual void Reset() = 0;
Alex Loiko1e48e802018-03-28 09:45:29 +020036};
37
Alessio Bazzica980c4602021-04-14 19:09:17 +020038// Creates a saturation protector that starts at `initial_headroom_db`.
39std::unique_ptr<SaturationProtector> CreateSaturationProtector(
40 float initial_headroom_db,
41 float extra_headroom_db,
42 int adjacent_speech_frames_threshold,
43 ApmDataDumper* apm_data_dumper);
Alessio Bazzica56f63c32020-09-29 11:56:38 +020044
Alex Loiko1e48e802018-03-28 09:45:29 +020045} // namespace webrtc
46
47#endif // MODULES_AUDIO_PROCESSING_AGC2_SATURATION_PROTECTOR_H_