From 60f675ff8d4fc17740972191042836b3b26af973 Mon Sep 17 00:00:00 2001 From: Alessio Bazzica Date: Fri, 15 Oct 2021 15:36:11 +0200 Subject: [PATCH] AGC2: fix fixed digital init, VAD before fixed digital MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL includes two changes that break bit-exactness, but that haven't changed the way AGC2 behaves - the new behavior has been verified with audioproc_f on a collection of AEC dumps and Wav files (42 recordings in total). 1) The fixed digital controller can directly be initialized in the `GainController2` ctor. Before, `SetGainFactor()` was called after the creation of the object and that caused an initial ramp up lasting one 10 ms frame from -inf to 0 dB. As an effect of the new initialization, the initial ramp up doesn't happen anymore. 2) In [1] the AGC2 VAD has been moved from the adaptive digital controller into `GainController2`. In order to not break bit-exactness, the VAD was placed after the fixed digital controller and before the adaptive digital one. However, to reduce the chance of incorrect estimation of the speech probability, the VAD should analyze the audio before any digital processing is applied inside AGC2. [1] https://webrtc-review.googlesource.com/c/src/+/234583 Bug: webrtc:7494 Change-Id: I9418229cbe537014fed8271c5550c3ce2bc88e26 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235240 Commit-Queue: Alessio Bazzica Reviewed-by: Hanna Silen Reviewed-by: Per Ã…hgren Cr-Commit-Position: refs/heads/main@{#35252} --- modules/audio_processing/gain_controller2.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/audio_processing/gain_controller2.cc b/modules/audio_processing/gain_controller2.cc index a21ef72734..8ca87c7ca1 100644 --- a/modules/audio_processing/gain_controller2.cc +++ b/modules/audio_processing/gain_controller2.cc @@ -76,8 +76,9 @@ GainController2::GainController2(const Agc2Config& config, int num_channels) : cpu_features_(GetAllowedCpuFeatures()), data_dumper_(rtc::AtomicOps::Increment(&instance_count_)), - fixed_gain_applier_(/*hard_clip_samples=*/false, - /*initial_gain_factor=*/0.0f), + fixed_gain_applier_( + /*hard_clip_samples=*/false, + /*initial_gain_factor=*/DbToRatio(config.fixed_digital.gain_db)), adaptive_digital_controller_( CreateAdaptiveDigitalController(config.adaptive_digital, sample_rate_hz, @@ -88,8 +89,6 @@ GainController2::GainController2(const Agc2Config& config, analog_level_(kUnspecifiedAnalogLevel) { RTC_DCHECK(Validate(config)); data_dumper_.InitiateNewSetOfRecordings(); - // TODO(bugs.webrtc.org/7494): Set gain when `fixed_gain_applier_` is init'd. - fixed_gain_applier_.SetGainFactor(DbToRatio(config.fixed_digital.gain_db)); const bool use_vad = config.adaptive_digital.enabled; if (use_vad) { // TODO(bugs.webrtc.org/7494): Move `vad_reset_period_ms` from adaptive @@ -135,12 +134,11 @@ void GainController2::Process(AudioBuffer* audio) { AudioFrameView float_frame(audio->channels(), audio->num_channels(), audio->num_frames()); absl::optional speech_probability; - // TODO(bugs.webrtc.org/7494): Apply fixed digital gain after VAD. - fixed_gain_applier_.ApplyGain(float_frame); if (vad_) { speech_probability = vad_->Analyze(float_frame); data_dumper_.DumpRaw("agc2_speech_probability", speech_probability.value()); } + fixed_gain_applier_.ApplyGain(float_frame); if (adaptive_digital_controller_) { RTC_DCHECK(speech_probability.has_value()); adaptive_digital_controller_->Process(