From a43953a5180828dda982663ff0d962edc0d4ee6f Mon Sep 17 00:00:00 2001 From: Hanna Silen Date: Wed, 2 Jun 2021 17:13:24 +0200 Subject: [PATCH] Add ClippingPredictor config in AudioProcessing config Bug: webrtc:12774 Change-Id: Id8cdb6b5499a22cbca40d424cf936f81c1e7d8d7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/221104 Reviewed-by: Minyue Li Commit-Queue: Hanna Silen Cr-Commit-Position: refs/heads/master@{#34204} --- .../include/audio_processing.cc | 35 +++++++++++++++++-- .../include/audio_processing.h | 31 ++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/modules/audio_processing/include/audio_processing.cc b/modules/audio_processing/include/audio_processing.cc index 29dcd66040..44a90d6e76 100644 --- a/modules/audio_processing/include/audio_processing.cc +++ b/modules/audio_processing/include/audio_processing.cc @@ -81,7 +81,19 @@ bool Agc1Config::operator==(const Agc1Config& rhs) const { analog_lhs.clipped_level_step == analog_rhs.clipped_level_step && analog_lhs.clipped_ratio_threshold == analog_rhs.clipped_ratio_threshold && - analog_lhs.clipped_wait_frames == analog_rhs.clipped_wait_frames; + analog_lhs.clipped_wait_frames == analog_rhs.clipped_wait_frames && + analog_lhs.clipping_predictor.mode == + analog_rhs.clipping_predictor.mode && + analog_lhs.clipping_predictor.window_length == + analog_rhs.clipping_predictor.window_length && + analog_lhs.clipping_predictor.reference_window_length == + analog_rhs.clipping_predictor.reference_window_length && + analog_lhs.clipping_predictor.reference_window_delay == + analog_rhs.clipping_predictor.reference_window_delay && + analog_lhs.clipping_predictor.clipping_threshold == + analog_rhs.clipping_predictor.clipping_threshold && + analog_lhs.clipping_predictor.crest_factor_margin == + analog_rhs.clipping_predictor.crest_factor_margin; } bool Agc2Config::AdaptiveDigital::operator==( @@ -167,7 +179,26 @@ std::string AudioProcessing::Config::ToString() const { << gain_controller1.analog_gain_controller.clipped_ratio_threshold << ", clipped_wait_frames: " << gain_controller1.analog_gain_controller.clipped_wait_frames - << " }}, gain_controller2: { enabled: " << gain_controller2.enabled + << ", clipping_predictor: { enabled: " + << gain_controller1.analog_gain_controller.clipping_predictor.enabled + << ", mode: " + << gain_controller1.analog_gain_controller.clipping_predictor.mode + << ", window_length: " + << gain_controller1.analog_gain_controller.clipping_predictor + .window_length + << ", reference_window_length: " + << gain_controller1.analog_gain_controller.clipping_predictor + .reference_window_length + << ", reference_window_delay: " + << gain_controller1.analog_gain_controller.clipping_predictor + .reference_window_delay + << ", clipping_threshold: " + << gain_controller1.analog_gain_controller.clipping_predictor + .clipping_threshold + << ", crest_factor_margin: " + << gain_controller1.analog_gain_controller.clipping_predictor + .crest_factor_margin + << " }}}, gain_controller2: { enabled: " << gain_controller2.enabled << ", fixed_digital: { gain_db: " << gain_controller2.fixed_digital.gain_db << " }, adaptive_digital: { enabled: " diff --git a/modules/audio_processing/include/audio_processing.h b/modules/audio_processing/include/audio_processing.h index 66220979dd..1f3c19c464 100644 --- a/modules/audio_processing/include/audio_processing.h +++ b/modules/audio_processing/include/audio_processing.h @@ -343,6 +343,37 @@ class RTC_EXPORT AudioProcessing : public rtc::RefCountInterface { // Time in frames to wait after a clipping event before checking again. // Limited to values higher than 0. int clipped_wait_frames = 300; + + // Enables clipping prediction functionality. + struct ClippingPredictor { + bool enabled = false; + enum Mode { + // Sets clipping prediction for clipping event prediction with fixed + // step estimation. + kClippingEventPrediction, + // Sets clipping prediction for clipped peak estimation with + // adaptive step estimation. + kAdaptiveStepClippingPeakPrediction, + // Sets clipping prediction for clipped peak estimation with fixed + // step estimation. + kFixedStepClippingPeakPrediction, + }; + Mode mode = kClippingEventPrediction; + // Number of frames in the sliding analysis window. Limited to values + // higher than zero. + int window_length = 5; + // Number of frames in the sliding reference window. Limited to values + // higher than zero. + int reference_window_length = 5; + // Number of frames the reference window is delayed. Limited to values + // zero and higher. An additional requirement: + // |window_length < reference_window_length + reference_window_delay|. + int reference_window_delay = 5; + // Clipping predictor ste estimation threshold (dB). + float clipping_threshold = -1.0f; + // Crest factor drop threshold (dB). + float crest_factor_margin = 3.0f; + } clipping_predictor; } analog_gain_controller; } gain_controller1;