InputVolumeController: Rename variables
Rename MonoInputVolumeController member input_volume_ to reflect its use to store the most recent input volume recommendation. Rename the remaining variables named as manager in the unit tests. Bug: webrtc:7494 Change-Id: I31ffdc131c98061ef2b36f98b685c5182b3c6861 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287123 Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Commit-Queue: Hanna Silen <silen@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38854}
This commit is contained in:
parent
248b9105fd
commit
6ebf5e3379
@ -237,16 +237,17 @@ void MonoInputVolumeController::HandleClipping(int clipped_level_step) {
|
|||||||
SetMaxLevel(std::max(min_input_volume_after_clipping_,
|
SetMaxLevel(std::max(min_input_volume_after_clipping_,
|
||||||
max_input_volume_ - clipped_level_step));
|
max_input_volume_ - clipped_level_step));
|
||||||
if (log_to_histograms_) {
|
if (log_to_histograms_) {
|
||||||
RTC_HISTOGRAM_BOOLEAN(
|
RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.AgcClippingAdjustmentAllowed",
|
||||||
"WebRTC.Audio.AgcClippingAdjustmentAllowed",
|
last_recommended_input_volume_ - clipped_level_step >=
|
||||||
input_volume_ - clipped_level_step >= min_input_volume_after_clipping_);
|
min_input_volume_after_clipping_);
|
||||||
}
|
}
|
||||||
if (input_volume_ > min_input_volume_after_clipping_) {
|
if (last_recommended_input_volume_ > min_input_volume_after_clipping_) {
|
||||||
// Don't try to adjust the input volume if we're already below the limit. As
|
// Don't try to adjust the input volume if we're already below the limit. As
|
||||||
// a consequence, if the user has brought the input volume above the limit,
|
// a consequence, if the user has brought the input volume above the limit,
|
||||||
// we will still not react until the postproc updates the input volume.
|
// we will still not react until the postproc updates the input volume.
|
||||||
SetInputVolume(std::max(min_input_volume_after_clipping_,
|
SetInputVolume(
|
||||||
input_volume_ - clipped_level_step));
|
std::max(min_input_volume_after_clipping_,
|
||||||
|
last_recommended_input_volume_ - clipped_level_step));
|
||||||
frames_since_update_input_volume_ = 0;
|
frames_since_update_input_volume_ = 0;
|
||||||
speech_frames_since_update_input_volume_ = 0;
|
speech_frames_since_update_input_volume_ = 0;
|
||||||
is_first_frame_ = false;
|
is_first_frame_ = false;
|
||||||
@ -267,18 +268,21 @@ void MonoInputVolumeController::SetInputVolume(int new_volume) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Detect manual input volume adjustments by checking if the
|
// Detect manual input volume adjustments by checking if the
|
||||||
// `applied_input_volume` is outside of the `[input_volume_ -
|
// `applied_input_volume` is outside of the `[last_recommended_input_volume_ -
|
||||||
// kVolumeQuantizationSlack, input_volume_ + kVolumeQuantizationSlack]` range.
|
// kVolumeQuantizationSlack, last_recommended_input_volume_ +
|
||||||
if (applied_input_volume > input_volume_ + kVolumeQuantizationSlack ||
|
// kVolumeQuantizationSlack]` range.
|
||||||
applied_input_volume < input_volume_ - kVolumeQuantizationSlack) {
|
if (applied_input_volume >
|
||||||
|
last_recommended_input_volume_ + kVolumeQuantizationSlack ||
|
||||||
|
applied_input_volume <
|
||||||
|
last_recommended_input_volume_ - kVolumeQuantizationSlack) {
|
||||||
RTC_DLOG(LS_INFO)
|
RTC_DLOG(LS_INFO)
|
||||||
<< "[AGC2] The input volume was manually adjusted. Updating "
|
<< "[AGC2] The input volume was manually adjusted. Updating "
|
||||||
"stored input volume from "
|
"stored input volume from "
|
||||||
<< input_volume_ << " to " << applied_input_volume;
|
<< last_recommended_input_volume_ << " to " << applied_input_volume;
|
||||||
input_volume_ = applied_input_volume;
|
last_recommended_input_volume_ = applied_input_volume;
|
||||||
// Always allow the user to increase the volume.
|
// Always allow the user to increase the volume.
|
||||||
if (input_volume_ > max_input_volume_) {
|
if (last_recommended_input_volume_ > max_input_volume_) {
|
||||||
SetMaxLevel(input_volume_);
|
SetMaxLevel(last_recommended_input_volume_);
|
||||||
}
|
}
|
||||||
// Take no action in this case, since we can't be sure when the volume
|
// Take no action in this case, since we can't be sure when the volume
|
||||||
// was manually adjusted.
|
// was manually adjusted.
|
||||||
@ -289,15 +293,16 @@ void MonoInputVolumeController::SetInputVolume(int new_volume) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_volume = std::min(new_volume, max_input_volume_);
|
new_volume = std::min(new_volume, max_input_volume_);
|
||||||
if (new_volume == input_volume_) {
|
if (new_volume == last_recommended_input_volume_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
recommended_input_volume_ = new_volume;
|
recommended_input_volume_ = new_volume;
|
||||||
RTC_DLOG(LS_INFO) << "[AGC2] Applied input volume: " << applied_input_volume
|
RTC_DLOG(LS_INFO) << "[AGC2] Applied input volume: " << applied_input_volume
|
||||||
<< " | last recommended input volume: " << input_volume_
|
<< " | last recommended input volume: "
|
||||||
|
<< last_recommended_input_volume_
|
||||||
<< " | newly recommended input volume: " << new_volume;
|
<< " | newly recommended input volume: " << new_volume;
|
||||||
input_volume_ = new_volume;
|
last_recommended_input_volume_ = new_volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonoInputVolumeController::SetMaxLevel(int input_volume) {
|
void MonoInputVolumeController::SetMaxLevel(int input_volume) {
|
||||||
@ -346,7 +351,7 @@ int MonoInputVolumeController::CheckVolumeAndReset() {
|
|||||||
recommended_input_volume_ = input_volume;
|
recommended_input_volume_ = input_volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_volume_ = input_volume;
|
last_recommended_input_volume_ = input_volume;
|
||||||
startup_ = false;
|
startup_ = false;
|
||||||
frames_since_update_input_volume_ = 0;
|
frames_since_update_input_volume_ = 0;
|
||||||
speech_frames_since_update_input_volume_ = 0;
|
speech_frames_since_update_input_volume_ = 0;
|
||||||
@ -364,8 +369,8 @@ void MonoInputVolumeController::UpdateInputVolume(int rms_error_db) {
|
|||||||
if (rms_error_db == 0) {
|
if (rms_error_db == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SetInputVolume(
|
SetInputVolume(ComputeVolumeUpdate(
|
||||||
ComputeVolumeUpdate(rms_error_db, input_volume_, min_input_volume_));
|
rms_error_db, last_recommended_input_volume_, min_input_volume_));
|
||||||
}
|
}
|
||||||
|
|
||||||
InputVolumeController::InputVolumeController(int num_capture_channels,
|
InputVolumeController::InputVolumeController(int num_capture_channels,
|
||||||
|
|||||||
@ -244,8 +244,7 @@ class MonoInputVolumeController {
|
|||||||
const int min_input_volume_after_clipping_;
|
const int min_input_volume_after_clipping_;
|
||||||
int max_input_volume_;
|
int max_input_volume_;
|
||||||
|
|
||||||
// Last recommended input volume.
|
int last_recommended_input_volume_ = 0;
|
||||||
int input_volume_ = 0;
|
|
||||||
|
|
||||||
bool capture_output_used_ = true;
|
bool capture_output_used_ = true;
|
||||||
bool check_volume_on_next_process_ = true;
|
bool check_volume_on_next_process_ = true;
|
||||||
|
|||||||
@ -801,11 +801,11 @@ TEST(InputVolumeControllerTest, MinInputVolumeCheckMinLevelWithClipping) {
|
|||||||
return controller;
|
return controller;
|
||||||
};
|
};
|
||||||
std::unique_ptr<InputVolumeController> controller = factory();
|
std::unique_ptr<InputVolumeController> controller = factory();
|
||||||
std::unique_ptr<InputVolumeController> manager_with_override;
|
std::unique_ptr<InputVolumeController> controller_with_override;
|
||||||
{
|
{
|
||||||
test::ScopedFieldTrials field_trial(
|
test::ScopedFieldTrials field_trial(
|
||||||
GetAgcMinInputVolumeFieldTrialEnabled(kMinInputVolume));
|
GetAgcMinInputVolumeFieldTrialEnabled(kMinInputVolume));
|
||||||
manager_with_override = factory();
|
controller_with_override = factory();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a test input signal which containts 80% of clipped samples.
|
// Create a test input signal which containts 80% of clipped samples.
|
||||||
@ -822,18 +822,19 @@ TEST(InputVolumeControllerTest, MinInputVolumeCheckMinLevelWithClipping) {
|
|||||||
*controller);
|
*controller);
|
||||||
CallPreProcessAndProcess(/*num_calls=*/400, audio_buffer,
|
CallPreProcessAndProcess(/*num_calls=*/400, audio_buffer,
|
||||||
kLowSpeechProbability, /*speech_level_dbfs=*/-42.0f,
|
kLowSpeechProbability, /*speech_level_dbfs=*/-42.0f,
|
||||||
*manager_with_override);
|
*controller_with_override);
|
||||||
|
|
||||||
// Make sure that an adaptation occurred.
|
// Make sure that an adaptation occurred.
|
||||||
ASSERT_GT(controller->recommended_analog_level(), 0);
|
ASSERT_GT(controller->recommended_analog_level(), 0);
|
||||||
|
|
||||||
// Check that the test signal triggers a larger downward adaptation for
|
// Check that the test signal triggers a larger downward adaptation for
|
||||||
// `controller`, which is allowed to reach a lower gain.
|
// `controller`, which is allowed to reach a lower gain.
|
||||||
EXPECT_GT(manager_with_override->recommended_analog_level(),
|
EXPECT_GT(controller_with_override->recommended_analog_level(),
|
||||||
controller->recommended_analog_level());
|
controller->recommended_analog_level());
|
||||||
// Check that the gain selected by `manager_with_override` equals the
|
// Check that the gain selected by `controller_with_override` equals the
|
||||||
// minimum value overridden via field trial.
|
// minimum value overridden via field trial.
|
||||||
EXPECT_EQ(manager_with_override->recommended_analog_level(), kMinInputVolume);
|
EXPECT_EQ(controller_with_override->recommended_analog_level(),
|
||||||
|
kMinInputVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that, when the "WebRTC-Audio-Agc2-MinInputVolume" field trial is
|
// Checks that, when the "WebRTC-Audio-Agc2-MinInputVolume" field trial is
|
||||||
@ -857,11 +858,11 @@ TEST(InputVolumeControllerTest,
|
|||||||
return controller;
|
return controller;
|
||||||
};
|
};
|
||||||
std::unique_ptr<InputVolumeController> controller = factory();
|
std::unique_ptr<InputVolumeController> controller = factory();
|
||||||
std::unique_ptr<InputVolumeController> manager_with_override;
|
std::unique_ptr<InputVolumeController> controller_with_override;
|
||||||
{
|
{
|
||||||
test::ScopedFieldTrials field_trial(
|
test::ScopedFieldTrials field_trial(
|
||||||
GetAgcMinInputVolumeFieldTrialEnabled(kMinInputVolume));
|
GetAgcMinInputVolumeFieldTrialEnabled(kMinInputVolume));
|
||||||
manager_with_override = factory();
|
controller_with_override = factory();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a test input signal which containts 80% of clipped samples.
|
// Create a test input signal which containts 80% of clipped samples.
|
||||||
@ -877,18 +878,19 @@ TEST(InputVolumeControllerTest,
|
|||||||
/*speech_level_dbfs=*/-18.0f, *controller);
|
/*speech_level_dbfs=*/-18.0f, *controller);
|
||||||
CallPreProcessAndProcess(
|
CallPreProcessAndProcess(
|
||||||
/*num_calls=*/400, audio_buffer, kHighSpeechProbability,
|
/*num_calls=*/400, audio_buffer, kHighSpeechProbability,
|
||||||
/*speech_level_dbfs=*/-18.0f, *manager_with_override);
|
/*speech_level_dbfs=*/-18.0f, *controller_with_override);
|
||||||
|
|
||||||
// Make sure that an adaptation occurred.
|
// Make sure that an adaptation occurred.
|
||||||
ASSERT_GT(controller->recommended_analog_level(), 0);
|
ASSERT_GT(controller->recommended_analog_level(), 0);
|
||||||
|
|
||||||
// Check that the test signal triggers a larger downward adaptation for
|
// Check that the test signal triggers a larger downward adaptation for
|
||||||
// `controller`, which is allowed to reach a lower gain.
|
// `controller`, which is allowed to reach a lower gain.
|
||||||
EXPECT_GT(manager_with_override->recommended_analog_level(),
|
EXPECT_GT(controller_with_override->recommended_analog_level(),
|
||||||
controller->recommended_analog_level());
|
controller->recommended_analog_level());
|
||||||
// Check that the gain selected by `manager_with_override` equals the minimum
|
// Check that the gain selected by `controller_with_override` equals the
|
||||||
// value overridden via field trial.
|
// minimum value overridden via field trial.
|
||||||
EXPECT_EQ(manager_with_override->recommended_analog_level(), kMinInputVolume);
|
EXPECT_EQ(controller_with_override->recommended_analog_level(),
|
||||||
|
kMinInputVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that, when the "WebRTC-Audio-Agc2-MinInputVolume" field trial is
|
// Checks that, when the "WebRTC-Audio-Agc2-MinInputVolume" field trial is
|
||||||
@ -912,7 +914,7 @@ TEST(InputVolumeControllerTest, MinInputVolumeCompareMicLevelWithClipping) {
|
|||||||
return controller;
|
return controller;
|
||||||
};
|
};
|
||||||
std::unique_ptr<InputVolumeController> controller = factory();
|
std::unique_ptr<InputVolumeController> controller = factory();
|
||||||
std::unique_ptr<InputVolumeController> manager_with_override;
|
std::unique_ptr<InputVolumeController> controller_with_override;
|
||||||
{
|
{
|
||||||
constexpr int kMinInputVolume = 20;
|
constexpr int kMinInputVolume = 20;
|
||||||
static_assert(kDefaultInputVolumeControllerConfig.clipped_level_min >=
|
static_assert(kDefaultInputVolumeControllerConfig.clipped_level_min >=
|
||||||
@ -920,7 +922,7 @@ TEST(InputVolumeControllerTest, MinInputVolumeCompareMicLevelWithClipping) {
|
|||||||
"Use a lower override value.");
|
"Use a lower override value.");
|
||||||
test::ScopedFieldTrials field_trial(
|
test::ScopedFieldTrials field_trial(
|
||||||
GetAgcMinInputVolumeFieldTrialEnabled(kMinInputVolume));
|
GetAgcMinInputVolumeFieldTrialEnabled(kMinInputVolume));
|
||||||
manager_with_override = factory();
|
controller_with_override = factory();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a test input signal which containts 80% of clipped samples.
|
// Create a test input signal which containts 80% of clipped samples.
|
||||||
@ -937,7 +939,7 @@ TEST(InputVolumeControllerTest, MinInputVolumeCompareMicLevelWithClipping) {
|
|||||||
*controller);
|
*controller);
|
||||||
CallPreProcessAndProcess(/*num_calls=*/400, audio_buffer,
|
CallPreProcessAndProcess(/*num_calls=*/400, audio_buffer,
|
||||||
kLowSpeechProbability, /*speech_level_dbfs=*/-18,
|
kLowSpeechProbability, /*speech_level_dbfs=*/-18,
|
||||||
*manager_with_override);
|
*controller_with_override);
|
||||||
|
|
||||||
// Make sure that an adaptation occurred.
|
// Make sure that an adaptation occurred.
|
||||||
ASSERT_GT(controller->recommended_analog_level(), 0);
|
ASSERT_GT(controller->recommended_analog_level(), 0);
|
||||||
@ -947,8 +949,8 @@ TEST(InputVolumeControllerTest, MinInputVolumeCompareMicLevelWithClipping) {
|
|||||||
// expected because the minimum microphone level override is less than the
|
// expected because the minimum microphone level override is less than the
|
||||||
// minimum level used when clipping is detected.
|
// minimum level used when clipping is detected.
|
||||||
EXPECT_EQ(controller->recommended_analog_level(),
|
EXPECT_EQ(controller->recommended_analog_level(),
|
||||||
manager_with_override->recommended_analog_level());
|
controller_with_override->recommended_analog_level());
|
||||||
EXPECT_EQ(manager_with_override->recommended_analog_level(),
|
EXPECT_EQ(controller_with_override->recommended_analog_level(),
|
||||||
kDefaultInputVolumeControllerConfig.clipped_level_min);
|
kDefaultInputVolumeControllerConfig.clipped_level_min);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -977,7 +979,7 @@ TEST(InputVolumeControllerTest,
|
|||||||
return controller;
|
return controller;
|
||||||
};
|
};
|
||||||
std::unique_ptr<InputVolumeController> controller = factory();
|
std::unique_ptr<InputVolumeController> controller = factory();
|
||||||
std::unique_ptr<InputVolumeController> manager_with_override;
|
std::unique_ptr<InputVolumeController> controller_with_override;
|
||||||
{
|
{
|
||||||
constexpr int kMinInputVolume = 20;
|
constexpr int kMinInputVolume = 20;
|
||||||
static_assert(kDefaultInputVolumeControllerConfig.clipped_level_min >=
|
static_assert(kDefaultInputVolumeControllerConfig.clipped_level_min >=
|
||||||
@ -985,7 +987,7 @@ TEST(InputVolumeControllerTest,
|
|||||||
"Use a lower override value.");
|
"Use a lower override value.");
|
||||||
test::ScopedFieldTrials field_trial(
|
test::ScopedFieldTrials field_trial(
|
||||||
GetAgcMinInputVolumeFieldTrialEnabled(kMinInputVolume));
|
GetAgcMinInputVolumeFieldTrialEnabled(kMinInputVolume));
|
||||||
manager_with_override = factory();
|
controller_with_override = factory();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a test input signal which containts 80% of clipped samples.
|
// Create a test input signal which containts 80% of clipped samples.
|
||||||
@ -1001,7 +1003,7 @@ TEST(InputVolumeControllerTest,
|
|||||||
CallPreProcessAndProcess(
|
CallPreProcessAndProcess(
|
||||||
/*num_calls=*/400, audio_buffer,
|
/*num_calls=*/400, audio_buffer,
|
||||||
/*speech_probability=*/0.7f,
|
/*speech_probability=*/0.7f,
|
||||||
/*speech_level_dbfs=*/-18.0f, *manager_with_override);
|
/*speech_level_dbfs=*/-18.0f, *controller_with_override);
|
||||||
|
|
||||||
// Make sure that an adaptation occurred.
|
// Make sure that an adaptation occurred.
|
||||||
ASSERT_GT(controller->recommended_analog_level(), 0);
|
ASSERT_GT(controller->recommended_analog_level(), 0);
|
||||||
@ -1011,8 +1013,8 @@ TEST(InputVolumeControllerTest,
|
|||||||
// expected because the minimum microphone level override is less than the
|
// expected because the minimum microphone level override is less than the
|
||||||
// minimum level used when clipping is detected.
|
// minimum level used when clipping is detected.
|
||||||
EXPECT_EQ(controller->recommended_analog_level(),
|
EXPECT_EQ(controller->recommended_analog_level(),
|
||||||
manager_with_override->recommended_analog_level());
|
controller_with_override->recommended_analog_level());
|
||||||
EXPECT_EQ(manager_with_override->recommended_analog_level(),
|
EXPECT_EQ(controller_with_override->recommended_analog_level(),
|
||||||
kDefaultInputVolumeControllerConfig.clipped_level_min);
|
kDefaultInputVolumeControllerConfig.clipped_level_min);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1028,14 +1030,14 @@ TEST_P(InputVolumeControllerParametrizedTest, ClippingParametersVerified) {
|
|||||||
EXPECT_EQ(controller->clipped_level_step_, kClippedLevelStep);
|
EXPECT_EQ(controller->clipped_level_step_, kClippedLevelStep);
|
||||||
EXPECT_EQ(controller->clipped_ratio_threshold_, kClippedRatioThreshold);
|
EXPECT_EQ(controller->clipped_ratio_threshold_, kClippedRatioThreshold);
|
||||||
EXPECT_EQ(controller->clipped_wait_frames_, kClippedWaitFrames);
|
EXPECT_EQ(controller->clipped_wait_frames_, kClippedWaitFrames);
|
||||||
std::unique_ptr<InputVolumeController> manager_custom =
|
std::unique_ptr<InputVolumeController> controller_custom =
|
||||||
CreateInputVolumeController(/*clipped_level_step=*/10,
|
CreateInputVolumeController(/*clipped_level_step=*/10,
|
||||||
/*clipped_ratio_threshold=*/0.2f,
|
/*clipped_ratio_threshold=*/0.2f,
|
||||||
/*clipped_wait_frames=*/50);
|
/*clipped_wait_frames=*/50);
|
||||||
manager_custom->Initialize();
|
controller_custom->Initialize();
|
||||||
EXPECT_EQ(manager_custom->clipped_level_step_, 10);
|
EXPECT_EQ(controller_custom->clipped_level_step_, 10);
|
||||||
EXPECT_EQ(manager_custom->clipped_ratio_threshold_, 0.2f);
|
EXPECT_EQ(controller_custom->clipped_ratio_threshold_, 0.2f);
|
||||||
EXPECT_EQ(manager_custom->clipped_wait_frames_, 50);
|
EXPECT_EQ(controller_custom->clipped_wait_frames_, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(InputVolumeControllerParametrizedTest,
|
TEST_P(InputVolumeControllerParametrizedTest,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user