| 1 |
/* |
| 2 |
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license |
| 5 |
* that can be found in the LICENSE file in the root of the source |
| 6 |
* tree. An additional intellectual property rights grant can be found |
| 7 |
* in the file PATENTS. All contributing project authors may |
| 8 |
* be found in the AUTHORS file in the root of the source tree. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "modules/audio_processing/include/audio_processing.h" |
| 12 |
|
| 13 |
#include "rtc_base/strings/string_builder.h" |
| 14 |
#include "rtc_base/system/arch.h" |
| 15 |
|
| 16 |
namespace webrtc { |
| 17 |
namespace { |
| 18 |
|
| 19 |
using Agc1Config = AudioProcessing::Config::GainController1; |
| 20 |
using Agc2Config = AudioProcessing::Config::GainController2; |
| 21 |
|
| 22 |
std::string NoiseSuppressionLevelToString( |
| 23 |
const AudioProcessing::Config::NoiseSuppression::Level& level) { |
| 24 |
switch (level) { |
| 25 |
case AudioProcessing::Config::NoiseSuppression::Level::kLow: |
| 26 |
return "Low"; |
| 27 |
case AudioProcessing::Config::NoiseSuppression::Level::kModerate: |
| 28 |
return "Moderate"; |
| 29 |
case AudioProcessing::Config::NoiseSuppression::Level::kHigh: |
| 30 |
return "High"; |
| 31 |
case AudioProcessing::Config::NoiseSuppression::Level::kVeryHigh: |
| 32 |
return "VeryHigh"; |
| 33 |
} |
| 34 |
RTC_CHECK_NOTREACHED(); |
| 35 |
} |
| 36 |
|
| 37 |
std::string GainController1ModeToString(const Agc1Config::Mode& mode) { |
| 38 |
switch (mode) { |
| 39 |
case Agc1Config::Mode::kAdaptiveAnalog: |
| 40 |
return "AdaptiveAnalog"; |
| 41 |
case Agc1Config::Mode::kAdaptiveDigital: |
| 42 |
return "AdaptiveDigital"; |
| 43 |
case Agc1Config::Mode::kFixedDigital: |
| 44 |
return "FixedDigital"; |
| 45 |
} |
| 46 |
RTC_CHECK_NOTREACHED(); |
| 47 |
} |
| 48 |
|
| 49 |
std::string GainController2NoiseEstimatorToString( |
| 50 |
const Agc2Config::NoiseEstimator& type) { |
| 51 |
switch (type) { |
| 52 |
case Agc2Config::NoiseEstimator::kStationaryNoise: |
| 53 |
return "StationaryNoise"; |
| 54 |
case Agc2Config::NoiseEstimator::kNoiseFloor: |
| 55 |
return "NoiseFloor"; |
| 56 |
} |
| 57 |
RTC_CHECK_NOTREACHED(); |
| 58 |
} |
| 59 |
|
| 60 |
} // namespace |
| 61 |
|
| 62 |
constexpr int AudioProcessing::kNativeSampleRatesHz[]; |
| 63 |
|
| 64 |
void CustomProcessing::SetRuntimeSetting( |
| 65 |
AudioProcessing::RuntimeSetting setting) {} |
| 66 |
|
| 67 |
bool Agc1Config::operator==(const Agc1Config& rhs) const { |
| 68 |
const auto& analog_lhs = analog_gain_controller; |
| 69 |
const auto& analog_rhs = rhs.analog_gain_controller; |
| 70 |
return enabled == rhs.enabled && mode == rhs.mode && |
| 71 |
target_level_dbfs == rhs.target_level_dbfs && |
| 72 |
compression_gain_db == rhs.compression_gain_db && |
| 73 |
enable_limiter == rhs.enable_limiter && |
| 74 |
analog_level_minimum == rhs.analog_level_minimum && |
| 75 |
analog_level_maximum == rhs.analog_level_maximum && |
| 76 |
analog_lhs.enabled == analog_rhs.enabled && |
| 77 |
analog_lhs.startup_min_volume == analog_rhs.startup_min_volume && |
| 78 |
analog_lhs.clipped_level_min == analog_rhs.clipped_level_min && |
| 79 |
analog_lhs.enable_digital_adaptive == |
| 80 |
analog_rhs.enable_digital_adaptive; |
| 81 |
} |
| 82 |
|
| 83 |
bool Agc2Config::operator==(const Agc2Config& rhs) const { |
| 84 |
const auto& adaptive_lhs = adaptive_digital; |
| 85 |
const auto& adaptive_rhs = rhs.adaptive_digital; |
| 86 |
|
| 87 |
return enabled == rhs.enabled && |
| 88 |
fixed_digital.gain_db == rhs.fixed_digital.gain_db && |
| 89 |
adaptive_lhs.enabled == adaptive_rhs.enabled && |
| 90 |
adaptive_lhs.vad_probability_attack == |
| 91 |
adaptive_rhs.vad_probability_attack && |
| 92 |
adaptive_lhs.level_estimator == adaptive_rhs.level_estimator && |
| 93 |
adaptive_lhs.level_estimator_adjacent_speech_frames_threshold == |
| 94 |
adaptive_rhs.level_estimator_adjacent_speech_frames_threshold && |
| 95 |
adaptive_lhs.use_saturation_protector == |
| 96 |
adaptive_rhs.use_saturation_protector && |
| 97 |
adaptive_lhs.initial_saturation_margin_db == |
| 98 |
adaptive_rhs.initial_saturation_margin_db && |
| 99 |
adaptive_lhs.extra_saturation_margin_db == |
| 100 |
adaptive_rhs.extra_saturation_margin_db && |
| 101 |
adaptive_lhs.gain_applier_adjacent_speech_frames_threshold == |
| 102 |
adaptive_rhs.gain_applier_adjacent_speech_frames_threshold && |
| 103 |
adaptive_lhs.max_gain_change_db_per_second == |
| 104 |
adaptive_rhs.max_gain_change_db_per_second && |
| 105 |
adaptive_lhs.max_output_noise_level_dbfs == |
| 106 |
adaptive_rhs.max_output_noise_level_dbfs; |
| 107 |
} |
| 108 |
|
| 109 |
bool AudioProcessing::Config::CaptureLevelAdjustment::operator==( |
| 110 |
const AudioProcessing::Config::CaptureLevelAdjustment& rhs) const { |
| 111 |
return enabled == rhs.enabled && pre_gain_factor == rhs.pre_gain_factor && |
| 112 |
post_gain_factor && rhs.post_gain_factor && |
| 113 |
analog_mic_gain_emulation == rhs.analog_mic_gain_emulation; |
| 114 |
} |
| 115 |
|
| 116 |
bool AudioProcessing::Config::CaptureLevelAdjustment::AnalogMicGainEmulation:: |
| 117 |
operator==(const AudioProcessing::Config::CaptureLevelAdjustment:: |
| 118 |
AnalogMicGainEmulation& rhs) const { |
| 119 |
return enabled == rhs.enabled && initial_level == rhs.initial_level; |
| 120 |
} |
| 121 |
|
| 122 |
std::string AudioProcessing::Config::ToString() const { |
| 123 |
char buf[2048]; |
| 124 |
rtc::SimpleStringBuilder builder(buf); |
| 125 |
builder |
| 126 |
<< "AudioProcessing::Config{ " |
| 127 |
"pipeline: { " |
| 128 |
"maximum_internal_processing_rate: " |
| 129 |
<< pipeline.maximum_internal_processing_rate |
| 130 |
<< ", multi_channel_render: " << pipeline.multi_channel_render |
| 131 |
<< ", multi_channel_capture: " << pipeline.multi_channel_capture |
| 132 |
<< " }, pre_amplifier: { enabled: " << pre_amplifier.enabled |
| 133 |
<< ", fixed_gain_factor: " << pre_amplifier.fixed_gain_factor |
| 134 |
<< " },capture_level_adjustment: { enabled: " |
| 135 |
<< capture_level_adjustment.enabled |
| 136 |
<< ", pre_gain_factor: " << capture_level_adjustment.pre_gain_factor |
| 137 |
<< ", post_gain_factor: " << capture_level_adjustment.post_gain_factor |
| 138 |
<< ", analog_mic_gain_emulation: { enabled: " |
| 139 |
<< capture_level_adjustment.analog_mic_gain_emulation.enabled |
| 140 |
<< ", initial_level: " |
| 141 |
<< capture_level_adjustment.analog_mic_gain_emulation.initial_level |
| 142 |
<< " }}, high_pass_filter: { enabled: " << high_pass_filter.enabled |
| 143 |
<< " }, echo_canceller: { enabled: " << echo_canceller.enabled |
| 144 |
<< ", mobile_mode: " << echo_canceller.mobile_mode |
| 145 |
<< ", enforce_high_pass_filtering: " |
| 146 |
<< echo_canceller.enforce_high_pass_filtering |
| 147 |
<< " }, noise_suppression: { enabled: " << noise_suppression.enabled |
| 148 |
<< ", level: " << NoiseSuppressionLevelToString(noise_suppression.level) |
| 149 |
<< " }, transient_suppression: { enabled: " |
| 150 |
<< transient_suppression.enabled |
| 151 |
<< " }, voice_detection: { enabled: " << voice_detection.enabled |
| 152 |
<< " }, gain_controller1: { enabled: " << gain_controller1.enabled |
| 153 |
<< ", mode: " << GainController1ModeToString(gain_controller1.mode) |
| 154 |
<< ", target_level_dbfs: " << gain_controller1.target_level_dbfs |
| 155 |
<< ", compression_gain_db: " << gain_controller1.compression_gain_db |
| 156 |
<< ", enable_limiter: " << gain_controller1.enable_limiter |
| 157 |
<< ", analog_level_minimum: " << gain_controller1.analog_level_minimum |
| 158 |
<< ", analog_level_maximum: " << gain_controller1.analog_level_maximum |
| 159 |
<< " }, gain_controller2: { enabled: " << gain_controller2.enabled |
| 160 |
<< ", fixed_digital: { gain_db: " |
| 161 |
<< gain_controller2.fixed_digital.gain_db |
| 162 |
<< " }, adaptive_digital: { enabled: " |
| 163 |
<< gain_controller2.adaptive_digital.enabled << ", noise_estimator: " |
| 164 |
<< GainController2NoiseEstimatorToString( |
| 165 |
gain_controller2.adaptive_digital.noise_estimator) |
| 166 |
<< ", vad_reset_period_ms: " |
| 167 |
<< gain_controller2.adaptive_digital.vad_reset_period_ms |
| 168 |
<< ", adjacent_speech_frames_threshold: " |
| 169 |
<< gain_controller2.adaptive_digital.adjacent_speech_frames_threshold |
| 170 |
<< ", max_gain_change_db_per_second: " |
| 171 |
<< gain_controller2.adaptive_digital.max_gain_change_db_per_second |
| 172 |
<< ", max_output_noise_level_dbfs: " |
| 173 |
<< gain_controller2.adaptive_digital.max_output_noise_level_dbfs |
| 174 |
<< ", sse2_allowed: " << gain_controller2.adaptive_digital.sse2_allowed |
| 175 |
<< ", avx2_allowed: " << gain_controller2.adaptive_digital.avx2_allowed |
| 176 |
<< ", neon_allowed: " << gain_controller2.adaptive_digital.neon_allowed |
| 177 |
<< "}}, residual_echo_detector: { enabled: " |
| 178 |
<< residual_echo_detector.enabled |
| 179 |
<< " }, level_estimation: { enabled: " << level_estimation.enabled |
| 180 |
<< " }}"; |
| 181 |
return builder.str(); |
| 182 |
} |
| 183 |
|
| 184 |
} // namespace webrtc |