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 <alessiob@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38282}
This commit is contained in:
Hanna Silen 2022-09-30 19:06:04 +02:00 committed by WebRTC LUCI CQ
parent 4426c4709d
commit 56b3a00d52
2 changed files with 13 additions and 12 deletions

View File

@ -215,7 +215,12 @@ void MonoAgc::Process(rtc::ArrayView<const int16_t> 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.

View File

@ -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_;