aleloi | 5f09980 | 2016-08-25 00:45:31 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/include/audio_processing.h" |
aleloi | 5f09980 | 2016-08-25 00:45:31 -0700 | [diff] [blame] | 12 | |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 13 | #include "rtc_base/strings/string_builder.h" |
Per Åhgren | fcbe407 | 2019-09-15 00:27:58 +0200 | [diff] [blame] | 14 | #include "rtc_base/system/arch.h" |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 15 | |
aleloi | 5f09980 | 2016-08-25 00:45:31 -0700 | [diff] [blame] | 16 | namespace webrtc { |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 17 | namespace { |
| 18 | |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 19 | using Agc1Config = AudioProcessing::Config::GainController1; |
| 20 | using Agc2Config = AudioProcessing::Config::GainController2; |
| 21 | |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 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 | } |
Karl Wiberg | c95b939 | 2020-11-08 00:49:37 +0100 | [diff] [blame^] | 34 | RTC_CHECK_NOTREACHED(); |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 37 | std::string GainController1ModeToString(const Agc1Config::Mode& mode) { |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 38 | switch (mode) { |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 39 | case Agc1Config::Mode::kAdaptiveAnalog: |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 40 | return "AdaptiveAnalog"; |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 41 | case Agc1Config::Mode::kAdaptiveDigital: |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 42 | return "AdaptiveDigital"; |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 43 | case Agc1Config::Mode::kFixedDigital: |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 44 | return "FixedDigital"; |
| 45 | } |
Karl Wiberg | c95b939 | 2020-11-08 00:49:37 +0100 | [diff] [blame^] | 46 | RTC_CHECK_NOTREACHED(); |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | std::string GainController2LevelEstimatorToString( |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 50 | const Agc2Config::LevelEstimator& level) { |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 51 | switch (level) { |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 52 | case Agc2Config::LevelEstimator::kRms: |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 53 | return "Rms"; |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 54 | case Agc2Config::LevelEstimator::kPeak: |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 55 | return "Peak"; |
| 56 | } |
Karl Wiberg | c95b939 | 2020-11-08 00:49:37 +0100 | [diff] [blame^] | 57 | RTC_CHECK_NOTREACHED(); |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 58 | } |
| 59 | |
Per Åhgren | fcbe407 | 2019-09-15 00:27:58 +0200 | [diff] [blame] | 60 | int GetDefaultMaxInternalRate() { |
| 61 | #ifdef WEBRTC_ARCH_ARM_FAMILY |
| 62 | return 32000; |
| 63 | #else |
| 64 | return 48000; |
| 65 | #endif |
| 66 | } |
| 67 | |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 68 | } // namespace |
aleloi | 5f09980 | 2016-08-25 00:45:31 -0700 | [diff] [blame] | 69 | |
Sam Zackrisson | 4b6ba7c | 2020-03-12 12:45:21 +0100 | [diff] [blame] | 70 | constexpr int AudioProcessing::kNativeSampleRatesHz[]; |
| 71 | |
Alex Loiko | 73ec019 | 2018-05-15 10:52:28 +0200 | [diff] [blame] | 72 | void CustomProcessing::SetRuntimeSetting( |
| 73 | AudioProcessing::RuntimeSetting setting) {} |
| 74 | |
Per Åhgren | fcbe407 | 2019-09-15 00:27:58 +0200 | [diff] [blame] | 75 | AudioProcessing::Config::Pipeline::Pipeline() |
| 76 | : maximum_internal_processing_rate(GetDefaultMaxInternalRate()) {} |
| 77 | |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 78 | bool Agc1Config::operator==(const Agc1Config& rhs) const { |
| 79 | const auto& analog_lhs = analog_gain_controller; |
| 80 | const auto& analog_rhs = rhs.analog_gain_controller; |
| 81 | return enabled == rhs.enabled && mode == rhs.mode && |
| 82 | target_level_dbfs == rhs.target_level_dbfs && |
| 83 | compression_gain_db == rhs.compression_gain_db && |
| 84 | enable_limiter == rhs.enable_limiter && |
| 85 | analog_level_minimum == rhs.analog_level_minimum && |
| 86 | analog_level_maximum == rhs.analog_level_maximum && |
| 87 | analog_lhs.enabled == analog_rhs.enabled && |
| 88 | analog_lhs.startup_min_volume == analog_rhs.startup_min_volume && |
| 89 | analog_lhs.clipped_level_min == analog_rhs.clipped_level_min && |
| 90 | analog_lhs.enable_agc2_level_estimator == |
| 91 | analog_rhs.enable_agc2_level_estimator && |
| 92 | analog_lhs.enable_digital_adaptive == |
| 93 | analog_rhs.enable_digital_adaptive; |
| 94 | } |
| 95 | |
| 96 | bool Agc2Config::operator==(const Agc2Config& rhs) const { |
| 97 | const auto& adaptive_lhs = adaptive_digital; |
| 98 | const auto& adaptive_rhs = rhs.adaptive_digital; |
| 99 | |
| 100 | return enabled == rhs.enabled && |
| 101 | fixed_digital.gain_db == rhs.fixed_digital.gain_db && |
| 102 | adaptive_lhs.enabled == adaptive_rhs.enabled && |
| 103 | adaptive_lhs.vad_probability_attack == |
| 104 | adaptive_rhs.vad_probability_attack && |
| 105 | adaptive_lhs.level_estimator == adaptive_rhs.level_estimator && |
| 106 | adaptive_lhs.level_estimator_adjacent_speech_frames_threshold == |
| 107 | adaptive_rhs.level_estimator_adjacent_speech_frames_threshold && |
| 108 | adaptive_lhs.use_saturation_protector == |
| 109 | adaptive_rhs.use_saturation_protector && |
| 110 | adaptive_lhs.initial_saturation_margin_db == |
| 111 | adaptive_rhs.initial_saturation_margin_db && |
| 112 | adaptive_lhs.extra_saturation_margin_db == |
| 113 | adaptive_rhs.extra_saturation_margin_db && |
| 114 | adaptive_lhs.gain_applier_adjacent_speech_frames_threshold == |
| 115 | adaptive_rhs.gain_applier_adjacent_speech_frames_threshold && |
| 116 | adaptive_lhs.max_gain_change_db_per_second == |
| 117 | adaptive_rhs.max_gain_change_db_per_second && |
| 118 | adaptive_lhs.max_output_noise_level_dbfs == |
| 119 | adaptive_rhs.max_output_noise_level_dbfs; |
| 120 | } |
| 121 | |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 122 | std::string AudioProcessing::Config::ToString() const { |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 123 | char buf[2048]; |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 124 | rtc::SimpleStringBuilder builder(buf); |
| 125 | builder << "AudioProcessing::Config{ " |
Jonas Olsson | b2b2031 | 2020-01-14 12:11:31 +0100 | [diff] [blame] | 126 | "pipeline: {" |
| 127 | "maximum_internal_processing_rate: " |
Sam Zackrisson | 72cc71c | 2019-10-21 12:54:02 +0200 | [diff] [blame] | 128 | << pipeline.maximum_internal_processing_rate |
Jonas Olsson | b2b2031 | 2020-01-14 12:11:31 +0100 | [diff] [blame] | 129 | << ", multi_channel_render: " << pipeline.multi_channel_render |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 130 | << ", multi_channel_capture: " << pipeline.multi_channel_capture |
| 131 | << "}, pre_amplifier: { enabled: " << pre_amplifier.enabled |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 132 | << ", fixed_gain_factor: " << pre_amplifier.fixed_gain_factor |
| 133 | << " }, high_pass_filter: { enabled: " << high_pass_filter.enabled |
| 134 | << " }, echo_canceller: { enabled: " << echo_canceller.enabled |
| 135 | << ", mobile_mode: " << echo_canceller.mobile_mode |
Per Åhgren | ded86c1 | 2019-12-09 20:47:39 +0100 | [diff] [blame] | 136 | << ", enforce_high_pass_filtering: " |
| 137 | << echo_canceller.enforce_high_pass_filtering |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 138 | << " }, noise_suppression: { enabled: " << noise_suppression.enabled |
| 139 | << ", level: " |
| 140 | << NoiseSuppressionLevelToString(noise_suppression.level) |
Per Åhgren | c073471 | 2020-01-02 15:15:36 +0100 | [diff] [blame] | 141 | << " }, transient_suppression: { enabled: " |
| 142 | << transient_suppression.enabled |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 143 | << " }, voice_detection: { enabled: " << voice_detection.enabled |
| 144 | << " }, gain_controller1: { enabled: " << gain_controller1.enabled |
| 145 | << ", mode: " << GainController1ModeToString(gain_controller1.mode) |
| 146 | << ", target_level_dbfs: " << gain_controller1.target_level_dbfs |
| 147 | << ", compression_gain_db: " << gain_controller1.compression_gain_db |
| 148 | << ", enable_limiter: " << gain_controller1.enable_limiter |
| 149 | << ", analog_level_minimum: " << gain_controller1.analog_level_minimum |
| 150 | << ", analog_level_maximum: " << gain_controller1.analog_level_maximum |
| 151 | << " }, gain_controller2: { enabled: " << gain_controller2.enabled |
| 152 | << ", fixed_digital: { gain_db: " |
| 153 | << gain_controller2.fixed_digital.gain_db |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 154 | << "}, adaptive_digital: { enabled: " |
| 155 | << gain_controller2.adaptive_digital.enabled |
| 156 | << ", level_estimator: { type: " |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 157 | << GainController2LevelEstimatorToString( |
| 158 | gain_controller2.adaptive_digital.level_estimator) |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 159 | << ", adjacent_speech_frames_threshold: " |
| 160 | << gain_controller2.adaptive_digital |
| 161 | .level_estimator_adjacent_speech_frames_threshold |
| 162 | << ", initial_saturation_margin_db: " |
| 163 | << gain_controller2.adaptive_digital.initial_saturation_margin_db |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 164 | << ", extra_saturation_margin_db: " |
| 165 | << gain_controller2.adaptive_digital.extra_saturation_margin_db |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 166 | << "}, gain_applier: { adjacent_speech_frames_threshold: " |
| 167 | << gain_controller2.adaptive_digital |
| 168 | .gain_applier_adjacent_speech_frames_threshold |
| 169 | << ", max_gain_change_db_per_second: " |
| 170 | << gain_controller2.adaptive_digital.max_gain_change_db_per_second |
| 171 | << ", max_output_noise_level_dbfs: " |
| 172 | << gain_controller2.adaptive_digital.max_output_noise_level_dbfs |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 173 | << " } }, residual_echo_detector: { enabled: " |
| 174 | << residual_echo_detector.enabled |
| 175 | << " }, level_estimation: { enabled: " << level_estimation.enabled |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 176 | << " }}}"; |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 177 | return builder.str(); |
| 178 | } |
| 179 | |
aleloi | 5f09980 | 2016-08-25 00:45:31 -0700 | [diff] [blame] | 180 | } // namespace webrtc |