Add refined handling of the internal scaling of the audio in APM
This CL adds functionality that allows adjusting the audio levels
internally in APM. The main purpose of the functionality is to allow
APM to optionally be moved to an integration that does not provide an
analog gain to control, and the implementation of this has been
tailored specifically to meet the requirements for that.
More specifically, this CL does
-Add a new variant of the pre-amplifier gain that is intended to replace
the pre-amplifier gain (but at the moment can coexist with that). The
main differences with the pre-amplifier gain is that an attenuating
gain is allowed, the gain is applied jointly with any emulated analog
gain, and that its packaging fits better with the post gain.
-Add an emulation of an analog microphone gain. The emulation is
designed to match the analog mic gain functionality in Chrome OS (which
is digital) but should be usable also on other platforms.
-Add a post-gain which is applied after all processing has been applied.
The purpose of this gain is for it to work well with the integration
in ChromeOS, and be used to compensate for the offset that there is
applied on some USB audio devices.
Bug: b/177830918
Change-Id: I0f312996e4088c9bd242a713a703eaaeb17f188a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/209707
Commit-Queue: Per Åhgren <peah@webrtc.org>
Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33466}
diff --git a/modules/audio_processing/include/audio_processing.h b/modules/audio_processing/include/audio_processing.h
index 36d8256..bb24a48 100644
--- a/modules/audio_processing/include/audio_processing.h
+++ b/modules/audio_processing/include/audio_processing.h
@@ -206,11 +206,37 @@
// Enabled the pre-amplifier. It amplifies the capture signal
// before any other processing is done.
+ // TODO(webrtc:5298): Deprecate and use the pre-gain functionality in
+ // capture_level_adjustment instead.
struct PreAmplifier {
bool enabled = false;
float fixed_gain_factor = 1.f;
} pre_amplifier;
+ // Functionality for general level adjustment in the capture pipeline. This
+ // should not be used together with the legacy PreAmplifier functionality.
+ struct CaptureLevelAdjustment {
+ bool operator==(const CaptureLevelAdjustment& rhs) const;
+ bool operator!=(const CaptureLevelAdjustment& rhs) const {
+ return !(*this == rhs);
+ }
+ bool enabled = false;
+ // The `pre_gain_factor` scales the signal before any processing is done.
+ float pre_gain_factor = 1.f;
+ // The `post_gain_factor` scales the signal after all processing is done.
+ float post_gain_factor = 1.f;
+ struct AnalogMicGainEmulation {
+ bool operator==(const AnalogMicGainEmulation& rhs) const;
+ bool operator!=(const AnalogMicGainEmulation& rhs) const {
+ return !(*this == rhs);
+ }
+ bool enabled = false;
+ // Initial analog gain level to use for the emulated analog gain. Must
+ // be in the range [0...255].
+ int initial_level = 255;
+ } analog_mic_gain_emulation;
+ } capture_level_adjustment;
+
struct HighPassFilter {
bool enabled = false;
bool apply_in_full_band = true;
@@ -381,6 +407,7 @@
kPlayoutVolumeChange,
kCustomRenderProcessingRuntimeSetting,
kPlayoutAudioDeviceChange,
+ kCapturePostGain,
kCaptureOutputUsed
};
@@ -394,10 +421,13 @@
~RuntimeSetting() = default;
static RuntimeSetting CreateCapturePreGain(float gain) {
- RTC_DCHECK_GE(gain, 1.f) << "Attenuation is not allowed.";
return {Type::kCapturePreGain, gain};
}
+ static RuntimeSetting CreateCapturePostGain(float gain) {
+ return {Type::kCapturePostGain, gain};
+ }
+
// Corresponds to Config::GainController1::compression_gain_db, but for
// runtime configuration.
static RuntimeSetting CreateCompressionGainDb(int gain_db) {