blob: ef22145d5f109446d9446d07759cd48c17cc605e [file] [log] [blame]
Alex Loiko1e48e802018-03-28 07:45:291/*
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 17:09:1714#include <memory>
Alex Loiko1e48e802018-03-28 07:45:2915
16namespace webrtc {
Alessio Bazzica980c4602021-04-14 17:09:1717class ApmDataDumper;
Alex Loiko1e48e802018-03-28 07:45:2918
Alessio Bazzica980c4602021-04-14 17:09:1719// Saturation protector. Analyzes peak levels and recommends a headroom to
20// reduce the chances of clipping.
21class SaturationProtector {
Alex Loiko1e48e802018-03-28 07:45:2922 public:
Alessio Bazzica980c4602021-04-14 17:09:1723 virtual ~SaturationProtector() = default;
Alessio Bazzica56f63c32020-09-29 09:56:3824
Alessio Bazzica980c4602021-04-14 17:09:1725 // Returns the recommended headroom in dB.
26 virtual float HeadroomDb() = 0;
Alex Loiko5e784612018-11-01 13:51:5627
Alessio Bazzica980c4602021-04-14 17:09:1728 // 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 12:16:1033
Alessio Bazzica980c4602021-04-14 17:09:1734 // Resets the internal state.
35 virtual void Reset() = 0;
Alex Loiko1e48e802018-03-28 07:45:2936};
37
Alessio Bazzica980c4602021-04-14 17:09:1738// Creates a saturation protector that starts at `initial_headroom_db`.
39std::unique_ptr<SaturationProtector> CreateSaturationProtector(
40 float initial_headroom_db,
Alessio Bazzica980c4602021-04-14 17:09:1741 int adjacent_speech_frames_threshold,
42 ApmDataDumper* apm_data_dumper);
Alessio Bazzica56f63c32020-09-29 09:56:3843
Alex Loiko1e48e802018-03-28 07:45:2944} // namespace webrtc
45
46#endif // MODULES_AUDIO_PROCESSING_AGC2_SATURATION_PROTECTOR_H_