Reset Agc2 on analog gain changes.
Agc2 applies a digital gain to the nearend signal.
When the analog level changes, the digital gain calculation is no
longer valid. Therefore Agc2 should be notified to analog gain
changes.
This CL also allow audioproc_f to chain AGC1 and AGC2. In a dependent
CL we will allow using AGC1 for analog gain and AGC2 for digital
gain.
Bug: webrtc:7494
Change-Id: Id75b3728fbf2de1d84b7fba005e4670c7a2985d9
Reviewed-on: https://webrtc-review.googlesource.com/89387
Commit-Queue: Alex Loiko <aleloi@webrtc.org>
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24231}
diff --git a/modules/audio_processing/agc2/adaptive_agc.cc b/modules/audio_processing/agc2/adaptive_agc.cc
index 7b24244..805be0c 100644
--- a/modules/audio_processing/agc2/adaptive_agc.cc
+++ b/modules/audio_processing/agc2/adaptive_agc.cc
@@ -30,14 +30,6 @@
AdaptiveAgc::~AdaptiveAgc() = default;
void AdaptiveAgc::Process(AudioFrameView<float> float_frame) {
- // TODO(webrtc:7494): Remove this loop. Remove the vectors from
- // VadWithData after we move to a VAD that outputs an estimate every
- // kFrameDurationMs ms.
- //
- // Some VADs are 'bursty'. They return several estimates for some
- // frames, and no estimates for other frames. We want to feed all to
- // the level estimator, but only care about the last level it
- // produces.
const VadWithLevel::LevelAndProbability vad_result =
vad_.AnalyzeFrame(float_frame);
apm_data_dumper_->DumpRaw("agc2_vad_probability",
@@ -58,4 +50,8 @@
float_frame);
}
+void AdaptiveAgc::Reset() {
+ speech_level_estimator_.Reset();
+}
+
} // namespace webrtc
diff --git a/modules/audio_processing/agc2/adaptive_agc.h b/modules/audio_processing/agc2/adaptive_agc.h
index dabe783..8f5efec 100644
--- a/modules/audio_processing/agc2/adaptive_agc.h
+++ b/modules/audio_processing/agc2/adaptive_agc.h
@@ -25,9 +25,11 @@
class AdaptiveAgc {
public:
explicit AdaptiveAgc(ApmDataDumper* apm_data_dumper);
- void Process(AudioFrameView<float> float_frame);
~AdaptiveAgc();
+ void Process(AudioFrameView<float> float_frame);
+ void Reset();
+
private:
AdaptiveModeLevelEstimator speech_level_estimator_;
VadWithLevel vad_;
diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc
index 04c1ba2..c2cb5c2 100644
--- a/modules/audio_processing/audio_processing_impl.cc
+++ b/modules/audio_processing/audio_processing_impl.cc
@@ -1334,6 +1334,8 @@
}
if (config_.gain_controller2.enabled) {
+ private_submodules_->gain_controller2->NotifyAnalogLevel(
+ gain_control()->stream_analog_level());
private_submodules_->gain_controller2->Process(capture_buffer);
}
diff --git a/modules/audio_processing/gain_control_for_experimental_agc.cc b/modules/audio_processing/gain_control_for_experimental_agc.cc
index d5d978c..6f1fc6a 100644
--- a/modules/audio_processing/gain_control_for_experimental_agc.cc
+++ b/modules/audio_processing/gain_control_for_experimental_agc.cc
@@ -43,14 +43,18 @@
rtc::CritScope cs_capture(crit_capture_);
data_dumper_->DumpRaw("experimental_gain_control_set_stream_analog_level", 1,
&level);
+ do_log_level_ = true;
volume_ = level;
return AudioProcessing::kNoError;
}
int GainControlForExperimentalAgc::stream_analog_level() {
rtc::CritScope cs_capture(crit_capture_);
- data_dumper_->DumpRaw("experimental_gain_control_stream_analog_level", 1,
- &volume_);
+ if (do_log_level_) {
+ data_dumper_->DumpRaw("experimental_gain_control_stream_analog_level", 1,
+ &volume_);
+ do_log_level_ = false;
+ }
return volume_;
}
diff --git a/modules/audio_processing/gain_control_for_experimental_agc.h b/modules/audio_processing/gain_control_for_experimental_agc.h
index 0894a0e..b20fbc9 100644
--- a/modules/audio_processing/gain_control_for_experimental_agc.h
+++ b/modules/audio_processing/gain_control_for_experimental_agc.h
@@ -68,6 +68,7 @@
GainControl* real_gain_control_;
int volume_;
rtc::CriticalSection* crit_capture_;
+ bool do_log_level_ = true;
static int instance_counter_;
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GainControlForExperimentalAgc);
};
diff --git a/modules/audio_processing/gain_controller2.cc b/modules/audio_processing/gain_controller2.cc
index 6c0149a..cdfcffa 100644
--- a/modules/audio_processing/gain_controller2.cc
+++ b/modules/audio_processing/gain_controller2.cc
@@ -45,6 +45,13 @@
fixed_gain_controller_.Process(float_frame);
}
+void GainController2::NotifyAnalogLevel(int level) {
+ if (analog_level_ != level) {
+ adaptive_agc_.Reset();
+ }
+ analog_level_ = level;
+}
+
void GainController2::ApplyConfig(
const AudioProcessing::Config::GainController2& config) {
RTC_DCHECK(Validate(config));
diff --git a/modules/audio_processing/gain_controller2.h b/modules/audio_processing/gain_controller2.h
index e2ca05e..41b7b69 100644
--- a/modules/audio_processing/gain_controller2.h
+++ b/modules/audio_processing/gain_controller2.h
@@ -33,6 +33,7 @@
void Initialize(int sample_rate_hz);
void Process(AudioBuffer* audio);
+ void NotifyAnalogLevel(int level);
void ApplyConfig(const AudioProcessing::Config::GainController2& config);
static bool Validate(const AudioProcessing::Config::GainController2& config);
@@ -45,6 +46,7 @@
FixedGainController fixed_gain_controller_;
AudioProcessing::Config::GainController2 config_;
AdaptiveAgc adaptive_agc_;
+ int analog_level_ = -1;
RTC_DISALLOW_COPY_AND_ASSIGN(GainController2);
};
diff --git a/modules/audio_processing/test/audioproc_float_impl.cc b/modules/audio_processing/test/audioproc_float_impl.cc
index 5d7b7e1..346a590 100644
--- a/modules/audio_processing/test/audioproc_float_impl.cc
+++ b/modules/audio_processing/test/audioproc_float_impl.cc
@@ -379,11 +379,6 @@
"Error: --agc_compression_gain must be specified between 0 and 90.\n");
ReportConditionalErrorAndExit(
- settings.use_agc && *settings.use_agc && settings.use_agc2 &&
- *settings.use_agc2,
- "Error: --agc and --agc2 cannot be both active.\n");
-
- ReportConditionalErrorAndExit(
settings.use_agc2 && *settings.use_agc2 &&
((settings.agc2_fixed_gain_db) < 0 ||
(settings.agc2_fixed_gain_db) > 90),