chromium/third_party/webrtc/modules/audio_processing/agc/agc_manager_direct.cc

/*
 *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#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 {

// Amount of error we tolerate in the microphone level (presumably due to OS
// quantization) before we assume the user has manually adjusted the microphone.
constexpr int kLevelQuantizationSlack =;

constexpr int kDefaultCompressionGain =;
constexpr int kMaxCompressionGain =;
constexpr int kMinCompressionGain =;
// Controls the rate of compression changes towards the target.
constexpr float kCompressionGainStep =;

constexpr int kMaxMicLevel =;
static_assert;
constexpr int kMinMicLevel =;

// Prevent very large microphone level changes.
constexpr int kMaxResidualGainChange =;

// Maximum additional gain allowed to compensate for microphone level
// restrictions from clipping events.
constexpr int kSurplusCompressionGain =;

// Target speech level (dBFs) and speech probability threshold used to compute
// the RMS error override in `GetSpeechLevelErrorDb()`. These are only used for
// computing the error override and they are not passed to `agc_`.
// TODO(webrtc:7494): Move these to a config and pass in the ctor.
constexpr float kOverrideTargetSpeechLevelDbfs =;
constexpr float kOverrideSpeechProbabilitySilenceThreshold =;
// The minimum number of frames between `UpdateGain()` calls.
// TODO(webrtc:7494): Move this to a config and pass in the ctor with
// kOverrideWaitFrames = 100. Default value zero needed for the unit tests.
constexpr int kOverrideWaitFrames =;

AnalogAgcConfig;

// If the "WebRTC-Audio-2ndAgcMinMicLevelExperiment" field trial is specified,
// parses it and returns a value between 0 and 255 depending on the field-trial
// string. Returns an unspecified value if the field trial is not specified, if
// disabled or if it cannot be parsed. Example:
// 'WebRTC-Audio-2ndAgcMinMicLevelExperiment/Enabled-80' => returns 80.
absl::optional<int> GetMinMicLevelOverride() {}

int LevelFromGainError(int gain_error, int level, int min_mic_level) {}

// Returns the proportion of samples in the buffer which are at full-scale
// (and presumably clipped).
float ComputeClippedRatio(const float* const* audio,
                          size_t num_channels,
                          size_t samples_per_channel) {}

void LogClippingMetrics(int clipping_rate) {}

// Computes the speech level error in dB. `speech_level_dbfs` is required to be
// in the range [-90.0f, 30.0f] and `speech_probability` in the range
// [0.0f, 1.0f].
int GetSpeechLevelErrorDb(float speech_level_dbfs, float speech_probability) {}

}  // namespace

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() {}

// Distributes the required gain change between the digital compression stage
// and volume slider. We use the compressor first, providing a slack region
// around the current slider position to reduce movement.
//
// If the slider needs to be moved, we check first if the user has adjusted
// it, in which case we take no action and cache the updated level.
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() {}

}  // namespace webrtc