AGC2: fix fixed digital init, VAD before fixed digital

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 <alessiob@webrtc.org>
Reviewed-by: Hanna Silen <silen@webrtc.org>
Reviewed-by: Per Ã…hgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35252}
diff --git a/modules/audio_processing/gain_controller2.cc b/modules/audio_processing/gain_controller2.cc
index a21ef72..8ca87c7 100644
--- a/modules/audio_processing/gain_controller2.cc
+++ b/modules/audio_processing/gain_controller2.cc
@@ -76,8 +76,9 @@
                                  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 @@
       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 @@
   AudioFrameView<float> float_frame(audio->channels(), audio->num_channels(),
                                     audio->num_frames());
   absl::optional<float> 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(