APM tests: check that the applied input volume is recommended

when volume emulation is used or when neither an input volume
controller nor volume emulation are used.

This CL adds 3 tests, 2 of which currently fail because APM
behaves in an undesired way. In [1] the behavior is fixed and
the tests are enabled.

A DCHECK in `AudioProcessingImpl::set_stream_analog_level` has
been removed since a more robust behavior can be obtained - namely,
that expected in the disabled unit tests added in this CL.

[1] https://webrtc-review.googlesource.com/c/src/+/281185

Bug: webrtc:14581
Change-Id: I29d2c000cd1baf90606487afd9a4042e6f487834
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/281184
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38696}
This commit is contained in:
Alessio Bazzica 2022-10-31 16:42:34 +01:00 committed by WebRTC LUCI CQ
parent 987ebe6b49
commit 79beaa7f38
2 changed files with 60 additions and 6 deletions

View File

@ -1746,12 +1746,6 @@ void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) {
}
void AudioProcessingImpl::set_stream_analog_level(int level) {
// Check that input volume emulation is disabled since, when enabled, there is
// no externally applied input volume to notify to APM.
RTC_DCHECK(
!submodules_.capture_levels_adjuster ||
!config_.capture_level_adjustment.analog_mic_gain_emulation.enabled);
MutexLock lock_capture(&mutex_capture_);
set_stream_analog_level_locked(level);
}

View File

@ -1035,4 +1035,64 @@ INSTANTIATE_TEST_SUITE_P(AudioProcessingImplTest,
::testing::Values(absl::nullopt,
20)));
// When the input volume is not emulated and no input volume controller is
// active, the recommended volume must always be the applied volume.
TEST(AudioProcessingImplTest,
RecommendAppliedInputVolumeWithNoAgcWithNoEmulation) {
auto apm = AudioProcessingBuilder()
.SetConfig({.capture_level_adjustment = {.enabled = false},
.gain_controller1 = {.enabled = false}})
.Create();
constexpr int kOneFrame = 1;
EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/123), 123);
EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/59), 59);
EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/135), 135);
}
// When the input volume is emulated, the recommended volume must always be the
// applied volume and at any time it must not be that set in the input volume
// emulator.
// TODO(bugs.webrtc.org/14581): Enable when APM fixed to let this test pass.
TEST(AudioProcessingImplTest,
DISABLED_RecommendAppliedInputVolumeWithNoAgcWithEmulation) {
auto apm =
AudioProcessingBuilder()
.SetConfig({.capture_level_adjustment = {.enabled = true,
.analog_mic_gain_emulation{
.enabled = true,
.initial_level = 255}},
.gain_controller1 = {.enabled = false}})
.Create();
constexpr int kOneFrame = 1;
EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/123), 123);
EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/59), 59);
EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/135), 135);
}
// Even if there is an enabled input volume controller, when the input volume is
// emulated, the recommended volume is always the applied volume because the
// active controller must only adjust the internally emulated volume and leave
// the externally applied volume unchanged.
// TODO(bugs.webrtc.org/14581): Enable when APM fixed to let this test pass.
TEST(AudioProcessingImplTest,
DISABLED_RecommendAppliedInputVolumeWithAgcWithEmulation) {
auto apm =
AudioProcessingBuilder()
.SetConfig({.capture_level_adjustment = {.enabled = true,
.analog_mic_gain_emulation{
.enabled = true}},
.gain_controller1 = {.enabled = true,
.analog_gain_controller{
.enabled = true,
}}})
.Create();
constexpr int kOneFrame = 1;
EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/123), 123);
EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/59), 59);
EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/135), 135);
}
} // namespace webrtc