Fix APM AGC2 initialization: pass the correct number of channels

Pass the correct number of channels needed by the AGC2 input volume
controller. This change doesn't affect the adaptive digital
controller which reads the number of channel from the passed audio
buffer instance for each processed frame.

Note that the `AdaptiveDigitalGainController::Initialize()` impl
was removed in [1], but that CL didn't remove the declaration (done
in this CL).

[1] https://webrtc-review.googlesource.com/c/src/+/287222/5/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc#105

Bug: webrtc:7494
Change-Id: I07369ab4025a251b25c716cf618e4222fdb60fc8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287320
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38863}
This commit is contained in:
Alessio Bazzica 2022-12-09 14:16:30 +01:00 committed by WebRTC LUCI CQ
parent dfba28e30e
commit 2bfa767245
7 changed files with 18 additions and 34 deletions

View File

@ -105,9 +105,7 @@ float ComputeGainChangeThisFrameDb(float target_gain_db,
AdaptiveDigitalGainController::AdaptiveDigitalGainController(
ApmDataDumper* apm_data_dumper,
const AudioProcessing::Config::GainController2::AdaptiveDigital& config,
int adjacent_speech_frames_threshold,
int sample_rate_hz,
int num_channels)
int adjacent_speech_frames_threshold)
: apm_data_dumper_(apm_data_dumper),
gain_applier_(
/*hard_clip_samples=*/false,

View File

@ -39,15 +39,11 @@ class AdaptiveDigitalGainController {
AdaptiveDigitalGainController(
ApmDataDumper* apm_data_dumper,
const AudioProcessing::Config::GainController2::AdaptiveDigital& config,
int adjacent_speech_frames_threshold,
int sample_rate_hz,
int num_channels);
int adjacent_speech_frames_threshold);
AdaptiveDigitalGainController(const AdaptiveDigitalGainController&) = delete;
AdaptiveDigitalGainController& operator=(
const AdaptiveDigitalGainController&) = delete;
void Initialize(int sample_rate_hz, int num_channels);
// Analyzes `info`, updates the digital gain and applies it to a 10 ms
// `frame`. Supports any sample rate supported by APM.
void Process(const FrameInfo& info, AudioFrameView<float> frame);

View File

@ -51,16 +51,12 @@ constexpr AdaptiveDigitalConfig kDefaultConfig{};
// Helper to create initialized `AdaptiveDigitalGainController` objects.
struct GainApplierHelper {
GainApplierHelper(const AdaptiveDigitalConfig& config,
int adjacent_speech_frames_threshold,
int sample_rate_hz,
int num_channels)
int adjacent_speech_frames_threshold)
: apm_data_dumper(0),
gain_applier(std::make_unique<AdaptiveDigitalGainController>(
&apm_data_dumper,
config,
adjacent_speech_frames_threshold,
sample_rate_hz,
num_channels)) {}
adjacent_speech_frames_threshold)) {}
ApmDataDumper apm_data_dumper;
std::unique_ptr<AdaptiveDigitalGainController> gain_applier;
};
@ -83,8 +79,7 @@ AdaptiveDigitalGainController::FrameInfo GetFrameInfoToNotAdapt(
TEST(GainController2AdaptiveDigitalGainControllerTest,
GainApplierShouldNotCrash) {
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold,
/*sample_rate_hz=*/48000, kStereo);
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold);
// Make one call with reasonable audio level values and settings.
VectorFloatFrame fake_audio(kStereo, kFrameLen10ms48kHz, 10000.0f);
helper.gain_applier->Process(GetFrameInfoToNotAdapt(kDefaultConfig),
@ -99,8 +94,7 @@ TEST(GainController2AdaptiveDigitalGainControllerTest, MaxGainApplied) {
kDefaultConfig.max_gain_change_db_per_second)) +
kNumExtraFrames;
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold,
/*sample_rate_hz=*/8000, kMono);
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold);
AdaptiveDigitalGainController::FrameInfo info =
GetFrameInfoToNotAdapt(kDefaultConfig);
info.speech_level_dbfs = -60.0f;
@ -115,8 +109,7 @@ TEST(GainController2AdaptiveDigitalGainControllerTest, MaxGainApplied) {
}
TEST(GainController2AdaptiveDigitalGainControllerTest, GainDoesNotChangeFast) {
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold,
/*sample_rate_hz=*/8000, kMono);
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold);
constexpr float initial_level_dbfs = -25.0f;
constexpr float kMaxGainChangeDbPerFrame =
@ -157,8 +150,7 @@ TEST(GainController2AdaptiveDigitalGainControllerTest, GainDoesNotChangeFast) {
}
TEST(GainController2AdaptiveDigitalGainControllerTest, GainIsRampedInAFrame) {
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold,
/*sample_rate_hz=*/48000, kMono);
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold);
constexpr float initial_level_dbfs = -25.0f;
@ -184,8 +176,7 @@ TEST(GainController2AdaptiveDigitalGainControllerTest, GainIsRampedInAFrame) {
}
TEST(GainController2AdaptiveDigitalGainControllerTest, NoiseLimitsGain) {
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold,
/*sample_rate_hz=*/48000, kMono);
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold);
constexpr float initial_level_dbfs = -25.0f;
constexpr int num_initial_frames =
@ -217,8 +208,7 @@ TEST(GainController2AdaptiveDigitalGainControllerTest, NoiseLimitsGain) {
TEST(GainController2AdaptiveDigitalGainControllerTest,
CanHandlePositiveSpeechLevels) {
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold,
/*sample_rate_hz=*/48000, kStereo);
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold);
// Make one call with positive audio level values and settings.
VectorFloatFrame fake_audio(kStereo, kFrameLen10ms48kHz, 10000.0f);
@ -229,8 +219,7 @@ TEST(GainController2AdaptiveDigitalGainControllerTest,
}
TEST(GainController2AdaptiveDigitalGainControllerTest, AudioLevelLimitsGain) {
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold,
/*sample_rate_hz=*/48000, kMono);
GainApplierHelper helper(kDefaultConfig, kAdjacentSpeechFramesThreshold);
constexpr float initial_level_dbfs = -25.0f;
constexpr int num_initial_frames =
@ -269,8 +258,7 @@ class AdaptiveDigitalGainControllerParametrizedTest
TEST_P(AdaptiveDigitalGainControllerParametrizedTest,
DoNotIncreaseGainWithTooFewSpeechFrames) {
GainApplierHelper helper(kDefaultConfig, adjacent_speech_frames_threshold(),
/*sample_rate_hz=*/48000, kMono);
GainApplierHelper helper(kDefaultConfig, adjacent_speech_frames_threshold());
// Lower the speech level so that the target gain will be increased.
AdaptiveDigitalGainController::FrameInfo info =
@ -292,8 +280,7 @@ TEST_P(AdaptiveDigitalGainControllerParametrizedTest,
TEST_P(AdaptiveDigitalGainControllerParametrizedTest,
IncreaseGainWithEnoughSpeechFrames) {
GainApplierHelper helper(kDefaultConfig, adjacent_speech_frames_threshold(),
/*sample_rate_hz=*/48000, kMono);
GainApplierHelper helper(kDefaultConfig, adjacent_speech_frames_threshold());
// Lower the speech level so that the target gain will be increased.
AdaptiveDigitalGainController::FrameInfo info =

View File

@ -428,6 +428,7 @@ void InputVolumeController::Initialize() {
}
void InputVolumeController::AnalyzePreProcess(const AudioBuffer& audio_buffer) {
RTC_DCHECK_EQ(audio_buffer.num_channels(), channel_controllers_.size());
const float* const* audio = audio_buffer.channels_const();
size_t samples_per_channel = audio_buffer.num_frames();
RTC_DCHECK(audio);

View File

@ -2345,7 +2345,7 @@ void AudioProcessingImpl::InitializeGainController2(bool config_has_changed) {
gain_controller2_config_override_.has_value()
? gain_controller2_config_override_->input_volume_controller_config
: InputVolumeController::Config{},
proc_fullband_sample_rate_hz(), num_input_channels(), use_internal_vad);
proc_fullband_sample_rate_hz(), num_proc_channels(), use_internal_vad);
submodules_.gain_controller2->SetCaptureOutputUsed(
capture_.capture_output_used);
}

View File

@ -1007,6 +1007,8 @@ TEST(AudioProcessingImplTest,
EXPECT_FALSE(apm->GetConfig().transient_suppression.enabled);
}
// TODO(bugs.webrtc.org/7494): Test AGCs with different multi-channel configs.
// Tests that the minimum startup volume is applied at the startup.
TEST_P(InputVolumeStartupParameterizedTest,
VerifyStartupMinVolumeAppliedAtStartup) {

View File

@ -127,7 +127,7 @@ GainController2::GainController2(
adaptive_digital_controller_ =
std::make_unique<AdaptiveDigitalGainController>(
&data_dumper_, config.adaptive_digital,
kAdjacentSpeechFramesThreshold, sample_rate_hz, num_channels);
kAdjacentSpeechFramesThreshold);
}
}