#include "modules/audio_processing/agc/agc_manager_direct.h"
#include <algorithm>
#include <cmath>
#include "api/array_view.h"
#include "common_audio/include/audio_util.h"
#include "modules/audio_processing/agc/gain_control.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 kLevelQuantizationSlack = …;
constexpr int kDefaultCompressionGain = …;
constexpr int kMaxCompressionGain = …;
constexpr int kMinCompressionGain = …;
constexpr float kCompressionGainStep = …;
constexpr int kMaxMicLevel = …;
static_assert …;
constexpr int kMinMicLevel = …;
constexpr int kMaxResidualGainChange = …;
constexpr int kSurplusCompressionGain = …;
constexpr float kOverrideTargetSpeechLevelDbfs = …;
constexpr float kOverrideSpeechProbabilitySilenceThreshold = …;
constexpr int kOverrideWaitFrames = …;
AnalogAgcConfig;
absl::optional<int> GetMinMicLevelOverride() { … }
int LevelFromGainError(int gain_error, int level, int min_mic_level) { … }
float ComputeClippedRatio(const float* const* audio,
size_t num_channels,
size_t samples_per_channel) { … }
void LogClippingMetrics(int clipping_rate) { … }
int GetSpeechLevelErrorDb(float speech_level_dbfs, float speech_probability) { … }
}
MonoAgc::MonoAgc(ApmDataDumper* data_dumper,
int clipped_level_min,
bool disable_digital_adaptive,
int min_mic_level)
: … { … }
MonoAgc::~MonoAgc() = default;
void MonoAgc::Initialize() { … }
void MonoAgc::Process(rtc::ArrayView<const int16_t> audio,
absl::optional<int> rms_error_override) { … }
void MonoAgc::HandleClipping(int clipped_level_step) { … }
void MonoAgc::SetLevel(int new_level) { … }
void MonoAgc::SetMaxLevel(int level) { … }
void MonoAgc::HandleCaptureOutputUsedChange(bool capture_output_used) { … }
int MonoAgc::CheckVolumeAndReset() { … }
void MonoAgc::UpdateGain(int rms_error_db) { … }
void MonoAgc::UpdateCompressor() { … }
std::atomic<int> AgcManagerDirect::instance_counter_(0);
AgcManagerDirect::AgcManagerDirect(
const AudioProcessing::Config::GainController1::AnalogGainController&
analog_config,
Agc* agc)
: … { … }
AgcManagerDirect::AgcManagerDirect(int num_capture_channels,
const AnalogAgcConfig& analog_config)
: … { … }
AgcManagerDirect::~AgcManagerDirect() { … }
void AgcManagerDirect::Initialize() { … }
void AgcManagerDirect::SetupDigitalGainControl(
GainControl& gain_control) const { … }
void AgcManagerDirect::AnalyzePreProcess(const AudioBuffer& audio_buffer) { … }
void AgcManagerDirect::Process(const AudioBuffer& audio_buffer) { … }
void AgcManagerDirect::Process(const AudioBuffer& audio_buffer,
absl::optional<float> speech_probability,
absl::optional<float> speech_level_dbfs) { … }
absl::optional<int> AgcManagerDirect::GetDigitalComressionGain() { … }
void AgcManagerDirect::HandleCaptureOutputUsedChange(bool capture_output_used) { … }
float AgcManagerDirect::voice_probability() const { … }
void AgcManagerDirect::set_stream_analog_level(int level) { … }
void AgcManagerDirect::AggregateChannelLevels() { … }
}