From 56b3a00d52c7adaa7ff987bdb07709e35357d2aa Mon Sep 17 00:00:00 2001 From: Hanna Silen Date: Fri, 30 Sep 2022 19:06:04 +0200 Subject: [PATCH] MonoAgc: Move error computation outside UpdateGain Bug: webrtc:7494 Change-Id: If95f44bf404316b8fadf28e3fd01a25f87c96a5b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/277625 Reviewed-by: Alessio Bazzica Commit-Queue: Hanna Silen Cr-Commit-Position: refs/heads/main@{#38282} --- .../agc/agc_manager_direct.cc | 23 ++++++++++--------- .../audio_processing/agc/agc_manager_direct.h | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/modules/audio_processing/agc/agc_manager_direct.cc b/modules/audio_processing/agc/agc_manager_direct.cc index 6633dccde6..8203bc6646 100644 --- a/modules/audio_processing/agc/agc_manager_direct.cc +++ b/modules/audio_processing/agc/agc_manager_direct.cc @@ -215,7 +215,12 @@ void MonoAgc::Process(rtc::ArrayView audio) { agc_->Process(audio); - UpdateGain(); + // Update gain if `agc_` has an RMS error estimate ready. + int rms_error = 0; + if (agc_->GetRmsErrorDb(&rms_error)) { + UpdateGain(rms_error); + } + if (!disable_digital_adaptive_) { UpdateCompressor(); } @@ -342,19 +347,15 @@ int MonoAgc::CheckVolumeAndReset() { return 0; } -// Requests the RMS error from AGC and distributes the required gain change -// between the digital compression stage and volume slider. We use the -// compressor first, providing a slack region around the current slider -// position to reduce movement. +// Distributes the required gain change between the digital compression stage +// and volume slider. We use the compressor first, providing a slack region +// around the current slider position to reduce movement. // // If the slider needs to be moved, we check first if the user has adjusted // it, in which case we take no action and cache the updated level. -void MonoAgc::UpdateGain() { - int rms_error = 0; - if (!agc_->GetRmsErrorDb(&rms_error)) { - // No error update ready. - return; - } +void MonoAgc::UpdateGain(int rms_error_db) { + int rms_error = rms_error_db; + // The compressor will always add at least kMinCompressionGain. In effect, // this adjusts our target gain upward by the same amount and rms_error // needs to reflect that. diff --git a/modules/audio_processing/agc/agc_manager_direct.h b/modules/audio_processing/agc/agc_manager_direct.h index 498e486bf1..5c29ddf204 100644 --- a/modules/audio_processing/agc/agc_manager_direct.h +++ b/modules/audio_processing/agc/agc_manager_direct.h @@ -228,7 +228,7 @@ class MonoAgc { void SetMaxLevel(int level); int CheckVolumeAndReset(); - void UpdateGain(); + void UpdateGain(int rms_error_db); void UpdateCompressor(); const int min_mic_level_;