webrtc apm 参数设置 - housekeeper-software/soft GitHub Wiki

全部参数列表

/* Copyright 2018 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef APM_CONFIG_H_
#define APM_CONFIG_H_

/* Keys for AudioProcessing::Pipeline */
#define PIPELINE_MAXIMUM_INTERNAL_PROCESSING_RATE "apm:pipeline_maximum_internal_processing_rate"
#define PIPELINE_MAXIMUM_INTERNAL_PROCESSING_RATE_VALUE 48000
#define PIPELINE_MULTI_CHANNEL_RENDER "apm:pipeline_multi_channel_render"
#define PIPELINE_MULTI_CHANNEL_RENDER_VALUE 0
#define PIPELINE_MULTI_CHANNEL_CAPTURE "apm:pipeline_multi_channel_capture"
#define PIPELINE_MULTI_CHANNEL_CAPTURE_VALUE 0

/* Keys for AudioProcessing::PreAmplifier */
#define APM_PRE_AMPLIFIER_ENABLED "apm:pre_amplifier_enabled"
#define APM_PRE_AMPLIFIER_ENABLED_VALUE 0
#define APM_PRE_AMPLIFIER_FIXED_GAIN_FACTOR "apm:pre_amplifier_fixed_gain_factor"
#define APM_PRE_AMPLIFIER_FIXED_GAIN_FACTOR_VALUE 1.f

/* Keys for AudioProcessing::HighPassFilter */
#define APM_HIGH_PASS_FILTER_ENABLED "apm:high_pass_filter_enabled"
#define APM_HIGH_PASS_FILTER_ENABLED_VALUE 0
#define APM_HIGH_PASS_FILTER_APPLY_IN_FULL_BAND "apm:high_pass_filter_apply_in_full_band"
#define APM_HIGH_PASS_FILTER_APPLY_IN_FULL_BAND_VALUE 1

/* Keys for AudioProcessing::EchoCanceller */
#define APM_ECHO_CANCELLER_ENABLED "apm:echo_canceller_enabled"
#define APM_ECHO_CANCELLER_ENABLED_VALUE 0
#define APM_ECHO_CANCELLER_MOBILE_MODE "apm:echo_canceller_mobile_mode"
#define APM_ECHO_CANCELLER_MOBILE_MODE_VALUE 0
#define APM_ECHO_CANCELLER_EXPORT_LINEAR_AEC_OUTPUT \
	"apm:echo_canceller_export_linear_aec_output"
#define APM_ECHO_CANCELLER_EXPORT_LINEAR_AEC_OUTPUT_VALUE 0
#define APM_ECHO_CANCELLER_ENFORCE_HIGH_PASS_FILTERING \
	"apm:echo_canceller_enforce_high_pass_filtering"
#define APM_ECHO_CANCELLER_ENFORCE_HIGH_PASS_FILTERING_VALUE 1

/* Keys for AudioProcessing::NoiseSuppression */
#define APM_NOISE_SUPPRESSION_ENABLED "apm:noise_suppression_enabled"
#define APM_NOISE_SUPPRESSION_ENABLED_VALUE 0
/* 0: low, 1: moderate, 2: high, 3: very high*/
#define APM_NOISE_SUPPRESSION_LEVEL "apm:noise_suppression_level"
#define APM_NOISE_SUPPRESSION_LEVEL_VALUE 1
#define APM_NOISE_SUPPRESSION_ANALYZE_LINEAR_AEC_OUTPUT_WHEN_AVAILABLE \
	"apm:noise_suppression_analyze_linear_aec_output_when_available"
#define APM_NOISE_SUPPRESSION_ANALYZE_LINEAR_AEC_OUTPUT_WHEN_AVAILABLE_VALUE 0


/* Keys for AudioProcessing::TransientSuppression */
#define APM_TRANSIENT_SUPPRESSION_ENABLED "apm:transient_suppression_enabled"
#define APM_TRANSIENT_SUPPRESSION_ENABLED_VALUE 0


/* Keys for AudioProcessing::VoiceDetection */
#define APM_VOICE_DETECTION_ENABLED "apm:voice_detection_enabled"
#define APM_VOICE_DETECTION_ENABLED_VALUE 0


/* Keys for AudioProcessing::GainController1 */
/* 0: adaptive analog, 1: adaptive digital, 2: fixed digital */
#define APM_GAIN_CONTROL_ENABLED "apm:gain_control_enabled"
#define APM_GAIN_CONTROL_ENABLED_VALUE 0
/* 0: kAdaptiveAnalog, 1: kAdaptiveDigital, 2: kFixedDigital */
#define APM_GAIN_CONTROL_MODE "apm:gain_control_mode"
#define APM_GAIN_CONTROL_MODE_VALUE 0
#define APM_GAIN_CONTROL_TARGET_LEVEL_DBFS "apm:gain_control_target_level_dbfs"
#define APM_GAIN_CONTROL_TARGET_LEVEL_DBFS_VALUE 3
#define APM_GAIN_CONTROL_COMPRESSION_GAIN_DB \
	 "apm:gain_control_compression_gain_db"
#define APM_GAIN_CONTROL_COMPRESSION_GAIN_DB_VALUE 9
#define APM_GAIN_CONTROL_ENABLE_LIMITER "apm:gain_control_enable_limiter"
#define APM_GAIN_CONTROL_ENABLE_LIMITER_VALUE 1
#define APM_GAIN_CONTROL_ANALOG_LEVEL_MINIMUM \
	 "apm:gain_control_analog_level_minimum"
#define APM_GAIN_CONTROL_ANALOG_LEVEL_MINIMUM_VALUE 0
#define APM_GAIN_CONTROL_ANALOG_LEVEL_MAXIMUM \
	 "apm:gain_control_analog_level_maximum"
#define APM_GAIN_CONTROL_ANALOG_LEVEL_MAXIMUM_VALUE 255


/* Keys for AudioProcessing::GainController1::AnalogGainController */
#define APM_ANALOG_GAIN_CONTROLLER_ENABLED "apm:analog_gain_controller_enabled"
#define APM_ANALOG_GAIN_CONTROLLER_ENABLED_VALUE 1
#define APM_ANALOG_GAIN_CONTROLLER_STARTUP_MIN_VOLUME \
	"apm:analog_gain_controller_startup_min_volume"
#define APM_ANALOG_GAIN_CONTROLLER_STARTUP_MIN_VOLUME_VALUE 85
#define APM_ANALOG_GAIN_CONTROLLER_CLIPPED_LEVEL_MIN \
	"apm:analog_gain_controller_clipped_level_min"
#define APM_ANALOG_GAIN_CONTROLLER_CLIPPED_LEVEL_MIN_VALUE 70
#define APM_ANALOG_GAIN_CONTROLLER_ENABLE_DIGITAL_ADAPTIVE \
	"apm:analog_gain_controller_enable_digital_adaptive"
#define APM_ANALOG_GAIN_CONTROLLER_ENABLE_DIGITAL_ADAPTIVE_VALUE 1


/* Keys for AudioProcessing::GainController2 */
#define APM_GAIN_CONTROLLER2_ENABLED "apm:gain_controller2_enabled"
#define APM_GAIN_CONTROLLER2_ENABLED_VALUE 0
/* Keys for AudioProcessing::GainController2::FixedDigital */
#define APM_GAIN_CONTROLLER2_FIXED_DIGITAL_GAIN_DB \
	"apm:gain_controller2_fixed_digital_gain_db"
#define APM_GAIN_CONTROLLER2_FIXED_DIGITAL_GAIN_DB_VALUE 0.f
/* Keys for AudioProcessing::GainController2::AdaptiveDigital */
#define ADAPTIVE_DIGITAL_ENABLED "apm:adaptive_digital_enabled"
#define ADAPTIVE_DIGITAL_ENABLED_VALUE 0
#define ADAPTIVE_DIGITAL_VAD_PROBABILITY_ATTACK \
	"apm:adaptive_digital_vad_probability_attack"
#define ADAPTIVE_DIGITAL_VAD_PROBABILITY_ATTACK_VALUE 0.3f
/* 0: kRms, 1: kPeak */
#define ADAPTIVE_DIGITAL_LEVEL_ESTIMATOR \
	"apm:adaptive_digital_level_estimator"
#define ADAPTIVE_DIGITAL_LEVEL_ESTIMATOR_VALUE 0
#define ADAPTIVE_DIGITAL_LEVEL_ESTIMATOR_ADJACENT_SPEECH_FRAMES_THRESHOLD \
	"apm:adaptive_digital_level_estimator_adjacent_speech_frames_threshold"
#define ADAPTIVE_DIGITAL_LEVEL_ESTIMATOR_ADJACENT_SPEECH_FRAMES_THRESHOLD_VALUE 6
#define ADAPTIVE_DIGITAL_USE_SATURATION_PROTECTOR \
	"apm:adaptive_digital_use_saturation_protector"
#define ADAPTIVE_DIGITAL_USE_SATURATION_PROTECTOR_VALUE 1
#define ADAPTIVE_DIGITAL_INITIAL_SATURATION_MARGIN_DB \
	"apm:adaptive_digital_initial_saturation_margin_db"
#define ADAPTIVE_DIGITAL_INITIAL_SATURATION_MARGIN_DB_VALUE 20.f
#define ADAPTIVE_DIGITAL_EXTRA_SATURATION_MARGIN_DB \
	"apm:adaptive_digital_extra_saturation_margin_db"
#define ADAPTIVE_DIGITAL_EXTRA_SATURATION_MARGIN_DB_VALUE 5.f
#define ADAPTIVE_DIGITAL_GAIN_APPLIER_ADJACENT_SPEECH_FRAMES_THRESHOLD \
	"apm:adaptive_digital_gain_applier_adjacent_speech_frames_threshold"
#define ADAPTIVE_DIGITAL_GAIN_APPLIER_ADJACENT_SPEECH_FRAMES_THRESHOLD_VALUE 6
#define ADAPTIVE_DIGITAL_MAX_GAIN_CHANGE_DB_PER_SECOND \
	"apm:adaptive_digital_max_gain_change_db_per_second"
#define ADAPTIVE_DIGITAL_MAX_GAIN_CHANGE_DB_PER_SECOND_VALUE 3.f
#define ADAPTIVE_DIGITAL_MAX_OUTPUT_NOISE_LEVEL_DBFS \
	"apm:adaptive_digital_max_output_noise_level_dbfs"
#define ADAPTIVE_DIGITAL_MAX_OUTPUT_NOISE_LEVEL_DBFS_VALUE -55.f

/* Keys for AudioProcessing::ResidualEchoDetector */
#define APM_RESIDUAL_ECHO_DETECTOR_ENABLED "apm:residual_echo_detector_enabled"
#define APM_RESIDUAL_ECHO_DETECTOR_ENABLED_VALUE 1
/* Keys for AudioProcessing::LevelEstimation */
#define APM_LEVEL_ESTIMATION_ENABLED "apm:level_estimation_enabled"
#define APM_LEVEL_ESTIMATION_ENABLED_VALUE 0


#endif /* APM_CONFIG_H_ */

设置规则

上面define中最后是_VALUE的是默认值,如果不设置的话,就是这个值。  
举例,如果想设置AudioProcessing::PreAmplifier 和  AudioProcessing::HighPassFilter
则给出如下字符串: 
apm:pre_amplifier_enabled=1;apm:high_pass_filter_enabled=1;

参数说明

PreAmplifier:前置放大器,一般需要设置  
HighPassFilter:高通滤波,一般需要设置
EchoCanceller:回声消除,如果没有DSP消回声,需要设置  
NoiseSuppression:去噪,如果消回声打开,则需要开启
TransientSuppression:瞬态抑制,可消除一些非周期性的噪音,默认需要开启,如果回音消除使能  
VoiceDetection:人声检测,不必打开  
GainController1:第一代增益引擎,根据需要打开  
GainController1::AnalogGainController:自动增益  
GainController2:二代增益引擎,根据需要打开  
ResidualEchoDetector:残留回声检测,根据回音消除使能
LevelEstimation:使能。  

webrtc 参数结构和说明

 struct RTC_EXPORT Config {

    // Sets the properties of the audio processing pipeline.
    struct RTC_EXPORT Pipeline {
      Pipeline();

      // Maximum allowed processing rate used internally. May only be set to
      // 32000 or 48000 and any differing values will be treated as 48000. The
      // default rate is currently selected based on the CPU architecture, but
      // that logic may change.
      int maximum_internal_processing_rate;
      // Allow multi-channel processing of render audio.
      bool multi_channel_render = false;
      // Allow multi-channel processing of capture audio when AEC3 is active
      // or a custom AEC is injected..
      bool multi_channel_capture = false;
    } pipeline;

    // Enabled the pre-amplifier. It amplifies the capture signal
    // before any other processing is done.
    struct PreAmplifier {
      bool enabled = false;
      float fixed_gain_factor = 1.f;
    } pre_amplifier;

    struct HighPassFilter {
      bool enabled = false;
      bool apply_in_full_band = true;
    } high_pass_filter;

    struct EchoCanceller {
      bool enabled = false;
      bool mobile_mode = false;
      bool export_linear_aec_output = false;
      // Enforce the highpass filter to be on (has no effect for the mobile
      // mode).
      bool enforce_high_pass_filtering = true;
    } echo_canceller;

    // Enables background noise suppression.
    struct NoiseSuppression {
      bool enabled = false;
      enum Level { kLow, kModerate, kHigh, kVeryHigh };
      Level level = kModerate;
      bool analyze_linear_aec_output_when_available = false;
    } noise_suppression;

    // Enables transient suppression.
    struct TransientSuppression {
      bool enabled = false;
    } transient_suppression;

    // Enables reporting of |voice_detected| in webrtc::AudioProcessingStats.
    struct VoiceDetection {
      bool enabled = false;
    } voice_detection;

    // Enables automatic gain control (AGC) functionality.
    // The automatic gain control (AGC) component brings the signal to an
    // appropriate range. This is done by applying a digital gain directly and,
    // in the analog mode, prescribing an analog gain to be applied at the audio
    // HAL.
    // Recommended to be enabled on the client-side.
    struct GainController1 {
      bool enabled = false;
      enum Mode {
        // Adaptive mode intended for use if an analog volume control is
        // available on the capture device. It will require the user to provide
        // coupling between the OS mixer controls and AGC through the
        // stream_analog_level() functions.
        // It consists of an analog gain prescription for the audio device and a
        // digital compression stage.
        kAdaptiveAnalog,
        // Adaptive mode intended for situations in which an analog volume
        // control is unavailable. It operates in a similar fashion to the
        // adaptive analog mode, but with scaling instead applied in the digital
        // domain. As with the analog mode, it additionally uses a digital
        // compression stage.
        kAdaptiveDigital,
        // Fixed mode which enables only the digital compression stage also used
        // by the two adaptive modes.
        // It is distinguished from the adaptive modes by considering only a
        // short time-window of the input signal. It applies a fixed gain
        // through most of the input level range, and compresses (gradually
        // reduces gain with increasing level) the input signal at higher
        // levels. This mode is preferred on embedded devices where the capture
        // signal level is predictable, so that a known gain can be applied.
        kFixedDigital
      };
      Mode mode = kAdaptiveAnalog;
      // Sets the target peak level (or envelope) of the AGC in dBFs (decibels
      // from digital full-scale). The convention is to use positive values. For
      // instance, passing in a value of 3 corresponds to -3 dBFs, or a target
      // level 3 dB below full-scale. Limited to [0, 31].
      int target_level_dbfs = 3;
      // Sets the maximum gain the digital compression stage may apply, in dB. A
      // higher number corresponds to greater compression, while a value of 0
      // will leave the signal uncompressed. Limited to [0, 90].
      // For updates after APM setup, use a RuntimeSetting instead.
      int compression_gain_db = 9;
      // When enabled, the compression stage will hard limit the signal to the
      // target level. Otherwise, the signal will be compressed but not limited
      // above the target level.
      bool enable_limiter = true;
      // Sets the minimum and maximum analog levels of the audio capture device.
      // Must be set if an analog mode is used. Limited to [0, 65535].
      int analog_level_minimum = 0;
      int analog_level_maximum = 255;

      // Enables the analog gain controller functionality.
      struct AnalogGainController {
        bool enabled = true;
        int startup_min_volume = kAgcStartupMinVolume;
        // Lowest analog microphone level that will be applied in response to
        // clipping.
        int clipped_level_min = kClippedLevelMin;
        bool enable_agc2_level_estimator = false;
        bool enable_digital_adaptive = true;
      } analog_gain_controller;
    } gain_controller1;

    // Enables the next generation AGC functionality. This feature replaces the
    // standard methods of gain control in the previous AGC. Enabling this
    // submodule enables an adaptive digital AGC followed by a limiter. By
    // setting |fixed_gain_db|, the limiter can be turned into a compressor that
    // first applies a fixed gain. The adaptive digital AGC can be turned off by
    // setting |adaptive_digital_mode=false|.
    struct GainController2 {
      enum LevelEstimator { kRms, kPeak };
      bool enabled = false;
      struct {
        float gain_db = 0.f;
      } fixed_digital;
      struct {
        bool enabled = false;
        float vad_probability_attack = 1.f;
        LevelEstimator level_estimator = kRms;
        int level_estimator_adjacent_speech_frames_threshold = 1;
        // TODO(crbug.com/webrtc/7494): Remove `use_saturation_protector`.
        bool use_saturation_protector = true;
        float initial_saturation_margin_db = 20.f;
        float extra_saturation_margin_db = 2.f;
        int gain_applier_adjacent_speech_frames_threshold = 1;
        float max_gain_change_db_per_second = 3.f;
        float max_output_noise_level_dbfs = -50.f;
      } adaptive_digital;
    } gain_controller2;

    struct ResidualEchoDetector {
      bool enabled = true;
    } residual_echo_detector;

    // Enables reporting of |output_rms_dbfs| in webrtc::AudioProcessingStats.
    struct LevelEstimation {
      bool enabled = false;
    } level_estimation;

    std::string ToString() const;
  };