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 14 #include <memory> 15 16 namespace webrtc { 17 class ApmDataDumper; 18 19 // Saturation protector. Analyzes peak levels and recommends a headroom to 20 // reduce the chances of clipping. 21 class SaturationProtector { 22 public: 23 virtual ~SaturationProtector() = default; 24 25 // Returns the recommended headroom in dB. 26 virtual float HeadroomDb() = 0; 27 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; 33 34 // Resets the internal state. 35 virtual void Reset() = 0; 36 }; 37 38 // Creates a saturation protector that starts at `initial_headroom_db`. 39 std::unique_ptr<SaturationProtector> CreateSaturationProtector( 40 float initial_headroom_db, 41 int adjacent_speech_frames_threshold, 42 ApmDataDumper* apm_data_dumper); 43 44 } // namespace webrtc 45 46 #endif // MODULES_AUDIO_PROCESSING_AGC2_SATURATION_PROTECTOR_H_ 47