chromium/third_party/webrtc/modules/audio_processing/agc2/input_volume_controller.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/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 {

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

constexpr int kMaxInputVolume =;
static_assert;

// Maximum absolute RMS error.
constexpr int KMaxAbsRmsErrorDbfs =;
static_assert;

Agc1ClippingPredictorConfig;

// TODO(webrtc:7494): Hardcode clipping predictor parameters and remove this
// function after no longer needed in the ctor.
Agc1ClippingPredictorConfig CreateClippingPredictorConfig(bool enabled) {}

// Returns an input volume in the [`min_input_volume`, `kMaxInputVolume`] range
// that reduces `gain_error_db`, which is a gain error estimated when
// `input_volume` was applied, according to a fixed gain map.
int ComputeVolumeUpdate(int gain_error_db,
                        int input_volume,
                        int min_input_volume) {}

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

// Compares `speech_level_dbfs` to the [`target_range_min_dbfs`,
// `target_range_max_dbfs`] range and returns the error to be compensated via
// input volume adjustment. Returns a positive value when the level is below
// the range, a negative value when the level is above the range, zero
// otherwise.
int GetSpeechLevelRmsErrorDb(float speech_level_dbfs,
                             int target_range_min_dbfs,
                             int target_range_max_dbfs) {}

}  // namespace

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

// A speeh segment is considered active if at least
// `update_input_volume_wait_frames_` new frames have been processed since the
// previous update and the ratio of non-silence frames (i.e., frames with a
// `speech_probability` higher than `speech_probability_threshold_`) is at least
// `speech_ratio_threshold_`.
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() {}

}  // namespace webrtc