#include "modules/audio_processing/agc2/input_volume_controller.h"
#include <algorithm>
#include <cmath>
#include "api/array_view.h"
#include "modules/audio_processing/agc2/gain_map_internal.h"
#include "modules/audio_processing/agc2/input_volume_stats_reporter.h"
#include "modules/audio_processing/include/audio_frame_view.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_minmax.h"
#include "system_wrappers/include/field_trial.h"
#include "system_wrappers/include/metrics.h"
namespace webrtc {
namespace {
constexpr int kVolumeQuantizationSlack = …;
constexpr int kMaxInputVolume = …;
static_assert …;
constexpr int KMaxAbsRmsErrorDbfs = …;
static_assert …;
Agc1ClippingPredictorConfig;
Agc1ClippingPredictorConfig CreateClippingPredictorConfig(bool enabled) { … }
int ComputeVolumeUpdate(int gain_error_db,
int input_volume,
int min_input_volume) { … }
float ComputeClippedRatio(const float* const* audio,
size_t num_channels,
size_t samples_per_channel) { … }
void LogClippingMetrics(int clipping_rate) { … }
int GetSpeechLevelRmsErrorDb(float speech_level_dbfs,
int target_range_min_dbfs,
int target_range_max_dbfs) { … }
}
MonoInputVolumeController::MonoInputVolumeController(
int min_input_volume_after_clipping,
int min_input_volume,
int update_input_volume_wait_frames,
float speech_probability_threshold,
float speech_ratio_threshold)
: … { … }
MonoInputVolumeController::~MonoInputVolumeController() = default;
void MonoInputVolumeController::Initialize() { … }
void MonoInputVolumeController::Process(absl::optional<int> rms_error_db,
float speech_probability) { … }
void MonoInputVolumeController::HandleClipping(int clipped_level_step) { … }
void MonoInputVolumeController::SetInputVolume(int new_volume) { … }
void MonoInputVolumeController::SetMaxLevel(int input_volume) { … }
void MonoInputVolumeController::HandleCaptureOutputUsedChange(
bool capture_output_used) { … }
int MonoInputVolumeController::CheckVolumeAndReset() { … }
void MonoInputVolumeController::UpdateInputVolume(int rms_error_db) { … }
InputVolumeController::InputVolumeController(int num_capture_channels,
const Config& config)
: … { … }
InputVolumeController::~InputVolumeController() { … }
void InputVolumeController::Initialize() { … }
void InputVolumeController::AnalyzeInputAudio(int applied_input_volume,
const AudioBuffer& audio_buffer) { … }
absl::optional<int> InputVolumeController::RecommendInputVolume(
float speech_probability,
absl::optional<float> speech_level_dbfs) { … }
void InputVolumeController::HandleCaptureOutputUsedChange(
bool capture_output_used) { … }
void InputVolumeController::SetAppliedInputVolume(int input_volume) { … }
void InputVolumeController::AggregateChannelLevels() { … }
}