From 347038bdb81e99038eeadca9eb35d629f2d3c7f0 Mon Sep 17 00:00:00 2001 From: Hanna Silen Date: Mon, 7 Nov 2022 11:08:58 +0100 Subject: [PATCH] InputVolumeController: Clean up the class definition Remove function declarations, members, and friend tests that are no longer used. Reorder the member variables. Bug: webrtc:7494 Change-Id: I8c24e2f4b9d9846e6d3fef4e2c998aa26f49f8c9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/282180 Reviewed-by: Alessio Bazzica Commit-Queue: Hanna Silen Cr-Commit-Position: refs/heads/main@{#38570} --- .../agc2/input_volume_controller.cc | 12 ++-- .../agc2/input_volume_controller.h | 66 +++++++------------ 2 files changed, 29 insertions(+), 49 deletions(-) diff --git a/modules/audio_processing/agc2/input_volume_controller.cc b/modules/audio_processing/agc2/input_volume_controller.cc index a547d6fe12..db85db696a 100644 --- a/modules/audio_processing/agc2/input_volume_controller.cc +++ b/modules/audio_processing/agc2/input_volume_controller.cc @@ -349,20 +349,16 @@ void MonoInputVolumeController::UpdateInputVolume(int rms_error_dbfs) { SetLevel(LevelFromGainError(residual_gain, level_, min_mic_level_)); } -std::atomic InputVolumeController::instance_counter_(0); - InputVolumeController::InputVolumeController(int num_capture_channels, const Config& config) : analog_controller_enabled_(config.enabled), + num_capture_channels_(num_capture_channels), min_mic_level_override_(GetMinMicLevelOverride()), use_min_channel_level_(!UseMaxAnalogChannelLevel()), - num_capture_channels_(num_capture_channels), - frames_since_clipped_(config.clipped_wait_frames), capture_output_used_(true), clipped_level_step_(config.clipped_level_step), clipped_ratio_threshold_(config.clipped_ratio_threshold), clipped_wait_frames_(config.clipped_wait_frames), - channel_controllers_(num_capture_channels), clipping_predictor_(CreateClippingPredictor( num_capture_channels, CreateClippingPredictorConfig(config.enable_clipping_predictor))), @@ -370,10 +366,12 @@ InputVolumeController::InputVolumeController(int num_capture_channels, !!clipping_predictor_ && CreateClippingPredictorConfig(config.enable_clipping_predictor) .use_predicted_step), - clipping_rate_log_(0.0f), + frames_since_clipped_(config.clipped_wait_frames), clipping_rate_log_counter_(0), + clipping_rate_log_(0.0f), target_range_max_dbfs_(config.target_range_max_dbfs), - target_range_min_dbfs_(config.target_range_min_dbfs) { + target_range_min_dbfs_(config.target_range_min_dbfs), + channel_controllers_(num_capture_channels) { RTC_LOG(LS_INFO) << "[agc] analog controller enabled: " << (analog_controller_enabled_ ? "yes" : "no"); const int min_mic_level = min_mic_level_override_.value_or(kMinMicLevel); diff --git a/modules/audio_processing/agc2/input_volume_controller.h b/modules/audio_processing/agc2/input_volume_controller.h index 41553cfd7e..73ded59e7a 100644 --- a/modules/audio_processing/agc2/input_volume_controller.h +++ b/modules/audio_processing/agc2/input_volume_controller.h @@ -11,7 +11,6 @@ #ifndef MODULES_AUDIO_PROCESSING_AGC2_INPUT_VOLUME_CONTROLLER_H_ #define MODULES_AUDIO_PROCESSING_AGC2_INPUT_VOLUME_CONTROLLER_H_ -#include #include #include @@ -26,11 +25,10 @@ namespace webrtc { class MonoInputVolumeController; -// Input volume controller that controls the input volume. The input volume -// controller recommends what volume to use, handles volume changes and -// clipping. In particular, it handles changes triggered by the user (e.g., -// volume set to zero by a HW mute button). The digital controller chooses and -// applies the digital compression gain. This class is not thread-safe. +// The input volume controller recommends what volume to use, handles volume +// changes and clipping detection and prediction. In particular, it handles +// changes triggered by the user (e.g., volume set to zero by a HW mute button). +// This class is not thread-safe. // TODO(bugs.webrtc.org/7494): Use applied/recommended input volume naming // convention. class InputVolumeController final { @@ -76,8 +74,7 @@ class InputVolumeController final { InputVolumeController(const InputVolumeController&) = delete; InputVolumeController& operator=(const InputVolumeController&) = delete; - // TODO(webrtc:7494): Integrate initialization into ctor and remove this - // method. + // TODO(webrtc:7494): Integrate initialization into ctor and remove. void Initialize(); // Sets the applied input volume. @@ -106,22 +103,17 @@ class InputVolumeController final { // `AnalyzePreProcess()` and `Process()`. int recommended_analog_level() const { return recommended_input_volume_; } - // Call when the capture stream output has been flagged to be used/not-used. - // If unused, the manager disregards all incoming audio. + // Stores whether the capture output will be used or not. Call when the + // capture stream output has been flagged to be used/not-used. If unused, the + // controller disregards all incoming audio. void HandleCaptureOutputUsedChange(bool capture_output_used); - float voice_probability() const; - - int num_channels() const { return num_capture_channels_; } - - // If available, returns the latest digital compression gain that has been - // chosen. - absl::optional GetDigitalComressionGain(); - // Returns true if clipping prediction is enabled. + // TODO(bugs.webrtc.org/7494): Deprecate this method. bool clipping_predictor_enabled() const { return !!clipping_predictor_; } // Returns true if clipping prediction is used to adjust the input volume. + // TODO(bugs.webrtc.org/7494): Deprecate this method. bool use_clipping_predictor_step() const { return use_clipping_predictor_step_; } @@ -129,8 +121,6 @@ class InputVolumeController final { private: friend class InputVolumeControllerTestHelper; - FRIEND_TEST_ALL_PREFIXES(InputVolumeControllerTest, - DisableDigitalDisablesDigital); FRIEND_TEST_ALL_PREFIXES(InputVolumeControllerTest, AgcMinMicLevelExperimentDefault); FRIEND_TEST_ALL_PREFIXES(InputVolumeControllerTest, @@ -141,29 +131,19 @@ class InputVolumeController final { AgcMinMicLevelExperimentOutOfRangeBelow); FRIEND_TEST_ALL_PREFIXES(InputVolumeControllerTest, AgcMinMicLevelExperimentEnabled50); - FRIEND_TEST_ALL_PREFIXES(InputVolumeControllerTest, - AgcMinMicLevelExperimentEnabledAboveStartupLevel); FRIEND_TEST_ALL_PREFIXES(InputVolumeControllerParametrizedTest, ClippingParametersVerified); - FRIEND_TEST_ALL_PREFIXES(InputVolumeControllerParametrizedTest, - DisableClippingPredictorDoesNotLowerVolume); - FRIEND_TEST_ALL_PREFIXES(InputVolumeControllerParametrizedTest, - UsedClippingPredictionsProduceLowerAnalogLevels); - FRIEND_TEST_ALL_PREFIXES(InputVolumeControllerParametrizedTest, - UnusedClippingPredictionsProduceEqualAnalogLevels); - FRIEND_TEST_ALL_PREFIXES(InputVolumeControllerParametrizedTest, - EmptyRmsErrorHasNoEffect); void AggregateChannelLevels(); const bool analog_controller_enabled_; - const absl::optional min_mic_level_override_; - static std::atomic instance_counter_; - const bool use_min_channel_level_; const int num_capture_channels_; - int frames_since_clipped_; + // If not empty, the value is used to override the minimum input volume. + const absl::optional min_mic_level_override_; + + const bool use_min_channel_level_; // TODO(bugs.webrtc.org/7494): Create a separate member for the applied input // volume. @@ -176,18 +156,16 @@ class InputVolumeController final { int recommended_input_volume_ = 0; bool capture_output_used_; - int channel_controlling_gain_ = 0; + // Clipping detection and prediction. const int clipped_level_step_; const float clipped_ratio_threshold_; const int clipped_wait_frames_; - - std::vector> channel_controllers_; - const std::unique_ptr clipping_predictor_; const bool use_clipping_predictor_step_; - float clipping_rate_log_; + int frames_since_clipped_; int clipping_rate_log_counter_; + float clipping_rate_log_; // Target range minimum and maximum. If the seech level is in the range // [`target_range_min_dbfs`, `target_range_max_dbfs`], no volume adjustments @@ -195,6 +173,10 @@ class InputVolumeController final { // compensate for the speech level RMS error. const int target_range_max_dbfs_; const int target_range_min_dbfs_; + + // Channel controllers updating the gain upwards/downwards. + std::vector> channel_controllers_; + int channel_controlling_gain_ = 0; }; // TODO(bugs.webrtc.org/7494): Use applied/recommended input volume naming @@ -239,8 +221,8 @@ class MonoInputVolumeController { // by the user, in which case no action is taken. void SetLevel(int new_level); - // Set the maximum input volume the input volume controller is allowed to - // apply. The volume must be at least `kClippedLevelMin`. + // Sets the maximum input volume that the input volume controller is allowed + // to apply. The volume must be at least `kClippedLevelMin`. void SetMaxLevel(int level); int CheckVolumeAndReset(); @@ -272,7 +254,7 @@ class MonoInputVolumeController { const int clipped_level_min_; - // Frames since the last `UpdateGain()` call. + // Frames since the last `UpdateInputVolume()` call. int frames_since_update_gain_ = 0; bool is_first_frame_ = true; };