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 | |
Alessio Bazzica | 61982a7 | 2021-04-14 16:17:09 +0200 | [diff] [blame] | 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 | |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 60 | } // namespace |
aleloi | 5f09980 | 2016-08-25 00:45:31 -0700 | [diff] [blame] | 61 | |
Sam Zackrisson | 4b6ba7c | 2020-03-12 12:45:21 +0100 | [diff] [blame] | 62 | constexpr int AudioProcessing::kNativeSampleRatesHz[]; |
| 63 | |
Alex Loiko | 73ec019 | 2018-05-15 10:52:28 +0200 | [diff] [blame] | 64 | void CustomProcessing::SetRuntimeSetting( |
| 65 | AudioProcessing::RuntimeSetting setting) {} |
| 66 | |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 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 && |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 79 | analog_lhs.enable_digital_adaptive == |
Hanna Silen | b8dc7fa | 2021-05-20 17:37:56 +0200 | [diff] [blame] | 80 | analog_rhs.enable_digital_adaptive && |
| 81 | analog_lhs.clipped_level_step == analog_rhs.clipped_level_step && |
| 82 | analog_lhs.clipped_ratio_threshold == |
| 83 | analog_rhs.clipped_ratio_threshold && |
Hanna Silen | a43953a | 2021-06-02 17:13:24 +0200 | [diff] [blame] | 84 | analog_lhs.clipped_wait_frames == analog_rhs.clipped_wait_frames && |
| 85 | analog_lhs.clipping_predictor.mode == |
| 86 | analog_rhs.clipping_predictor.mode && |
| 87 | analog_lhs.clipping_predictor.window_length == |
| 88 | analog_rhs.clipping_predictor.window_length && |
| 89 | analog_lhs.clipping_predictor.reference_window_length == |
| 90 | analog_rhs.clipping_predictor.reference_window_length && |
| 91 | analog_lhs.clipping_predictor.reference_window_delay == |
| 92 | analog_rhs.clipping_predictor.reference_window_delay && |
| 93 | analog_lhs.clipping_predictor.clipping_threshold == |
| 94 | analog_rhs.clipping_predictor.clipping_threshold && |
| 95 | analog_lhs.clipping_predictor.crest_factor_margin == |
| 96 | analog_rhs.clipping_predictor.crest_factor_margin; |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 97 | } |
| 98 | |
Alessio Bazzica | a2efd15 | 2021-04-29 16:17:49 +0200 | [diff] [blame] | 99 | bool Agc2Config::AdaptiveDigital::operator==( |
| 100 | const Agc2Config::AdaptiveDigital& rhs) const { |
| 101 | return enabled == rhs.enabled && dry_run == rhs.dry_run && |
| 102 | noise_estimator == rhs.noise_estimator && |
| 103 | vad_reset_period_ms == rhs.vad_reset_period_ms && |
| 104 | adjacent_speech_frames_threshold == |
| 105 | rhs.adjacent_speech_frames_threshold && |
| 106 | max_gain_change_db_per_second == rhs.max_gain_change_db_per_second && |
| 107 | max_output_noise_level_dbfs == rhs.max_output_noise_level_dbfs && |
| 108 | sse2_allowed == rhs.sse2_allowed && avx2_allowed == rhs.avx2_allowed && |
| 109 | neon_allowed == rhs.neon_allowed; |
| 110 | } |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 111 | |
Alessio Bazzica | a2efd15 | 2021-04-29 16:17:49 +0200 | [diff] [blame] | 112 | bool Agc2Config::operator==(const Agc2Config& rhs) const { |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 113 | return enabled == rhs.enabled && |
| 114 | fixed_digital.gain_db == rhs.fixed_digital.gain_db && |
Alessio Bazzica | a2efd15 | 2021-04-29 16:17:49 +0200 | [diff] [blame] | 115 | adaptive_digital == rhs.adaptive_digital; |
Alessio Bazzica | 3438a93 | 2020-10-14 12:47:50 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 118 | bool AudioProcessing::Config::CaptureLevelAdjustment::operator==( |
| 119 | const AudioProcessing::Config::CaptureLevelAdjustment& rhs) const { |
| 120 | return enabled == rhs.enabled && pre_gain_factor == rhs.pre_gain_factor && |
| 121 | post_gain_factor && rhs.post_gain_factor && |
| 122 | analog_mic_gain_emulation == rhs.analog_mic_gain_emulation; |
| 123 | } |
| 124 | |
| 125 | bool AudioProcessing::Config::CaptureLevelAdjustment::AnalogMicGainEmulation:: |
| 126 | operator==(const AudioProcessing::Config::CaptureLevelAdjustment:: |
| 127 | AnalogMicGainEmulation& rhs) const { |
| 128 | return enabled == rhs.enabled && initial_level == rhs.initial_level; |
| 129 | } |
| 130 | |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 131 | std::string AudioProcessing::Config::ToString() const { |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 132 | char buf[2048]; |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 133 | rtc::SimpleStringBuilder builder(buf); |
Alessio Bazzica | 6f75f6b | 2021-02-02 16:52:39 +0100 | [diff] [blame] | 134 | builder |
| 135 | << "AudioProcessing::Config{ " |
| 136 | "pipeline: { " |
| 137 | "maximum_internal_processing_rate: " |
| 138 | << pipeline.maximum_internal_processing_rate |
| 139 | << ", multi_channel_render: " << pipeline.multi_channel_render |
| 140 | << ", multi_channel_capture: " << pipeline.multi_channel_capture |
| 141 | << " }, pre_amplifier: { enabled: " << pre_amplifier.enabled |
| 142 | << ", fixed_gain_factor: " << pre_amplifier.fixed_gain_factor |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 143 | << " },capture_level_adjustment: { enabled: " |
| 144 | << capture_level_adjustment.enabled |
| 145 | << ", pre_gain_factor: " << capture_level_adjustment.pre_gain_factor |
| 146 | << ", post_gain_factor: " << capture_level_adjustment.post_gain_factor |
| 147 | << ", analog_mic_gain_emulation: { enabled: " |
| 148 | << capture_level_adjustment.analog_mic_gain_emulation.enabled |
| 149 | << ", initial_level: " |
| 150 | << capture_level_adjustment.analog_mic_gain_emulation.initial_level |
| 151 | << " }}, high_pass_filter: { enabled: " << high_pass_filter.enabled |
Alessio Bazzica | 6f75f6b | 2021-02-02 16:52:39 +0100 | [diff] [blame] | 152 | << " }, echo_canceller: { enabled: " << echo_canceller.enabled |
| 153 | << ", mobile_mode: " << echo_canceller.mobile_mode |
| 154 | << ", enforce_high_pass_filtering: " |
| 155 | << echo_canceller.enforce_high_pass_filtering |
| 156 | << " }, noise_suppression: { enabled: " << noise_suppression.enabled |
| 157 | << ", level: " << NoiseSuppressionLevelToString(noise_suppression.level) |
| 158 | << " }, transient_suppression: { enabled: " |
| 159 | << transient_suppression.enabled |
| 160 | << " }, voice_detection: { enabled: " << voice_detection.enabled |
| 161 | << " }, gain_controller1: { enabled: " << gain_controller1.enabled |
| 162 | << ", mode: " << GainController1ModeToString(gain_controller1.mode) |
| 163 | << ", target_level_dbfs: " << gain_controller1.target_level_dbfs |
| 164 | << ", compression_gain_db: " << gain_controller1.compression_gain_db |
| 165 | << ", enable_limiter: " << gain_controller1.enable_limiter |
| 166 | << ", analog_level_minimum: " << gain_controller1.analog_level_minimum |
| 167 | << ", analog_level_maximum: " << gain_controller1.analog_level_maximum |
Alessio Bazzica | 7ddadbc | 2021-05-17 16:17:32 +0200 | [diff] [blame] | 168 | << ", analog_gain_controller { enabled: " |
| 169 | << gain_controller1.analog_gain_controller.enabled |
| 170 | << ", startup_min_volume: " |
| 171 | << gain_controller1.analog_gain_controller.startup_min_volume |
| 172 | << ", clipped_level_min: " |
| 173 | << gain_controller1.analog_gain_controller.clipped_level_min |
| 174 | << ", enable_digital_adaptive: " |
| 175 | << gain_controller1.analog_gain_controller.enable_digital_adaptive |
Hanna Silen | b8dc7fa | 2021-05-20 17:37:56 +0200 | [diff] [blame] | 176 | << ", clipped_level_step: " |
| 177 | << gain_controller1.analog_gain_controller.clipped_level_step |
| 178 | << ", clipped_ratio_threshold: " |
| 179 | << gain_controller1.analog_gain_controller.clipped_ratio_threshold |
| 180 | << ", clipped_wait_frames: " |
| 181 | << gain_controller1.analog_gain_controller.clipped_wait_frames |
Hanna Silen | a43953a | 2021-06-02 17:13:24 +0200 | [diff] [blame] | 182 | << ", clipping_predictor: { enabled: " |
| 183 | << gain_controller1.analog_gain_controller.clipping_predictor.enabled |
| 184 | << ", mode: " |
| 185 | << gain_controller1.analog_gain_controller.clipping_predictor.mode |
| 186 | << ", window_length: " |
| 187 | << gain_controller1.analog_gain_controller.clipping_predictor |
| 188 | .window_length |
| 189 | << ", reference_window_length: " |
| 190 | << gain_controller1.analog_gain_controller.clipping_predictor |
| 191 | .reference_window_length |
| 192 | << ", reference_window_delay: " |
| 193 | << gain_controller1.analog_gain_controller.clipping_predictor |
| 194 | .reference_window_delay |
| 195 | << ", clipping_threshold: " |
| 196 | << gain_controller1.analog_gain_controller.clipping_predictor |
| 197 | .clipping_threshold |
| 198 | << ", crest_factor_margin: " |
| 199 | << gain_controller1.analog_gain_controller.clipping_predictor |
| 200 | .crest_factor_margin |
| 201 | << " }}}, gain_controller2: { enabled: " << gain_controller2.enabled |
Alessio Bazzica | 6f75f6b | 2021-02-02 16:52:39 +0100 | [diff] [blame] | 202 | << ", fixed_digital: { gain_db: " |
| 203 | << gain_controller2.fixed_digital.gain_db |
| 204 | << " }, adaptive_digital: { enabled: " |
Alessio Bazzica | a2efd15 | 2021-04-29 16:17:49 +0200 | [diff] [blame] | 205 | << gain_controller2.adaptive_digital.enabled |
| 206 | << ", dry_run: " << gain_controller2.adaptive_digital.dry_run |
| 207 | << ", noise_estimator: " |
Alessio Bazzica | 61982a7 | 2021-04-14 16:17:09 +0200 | [diff] [blame] | 208 | << GainController2NoiseEstimatorToString( |
| 209 | gain_controller2.adaptive_digital.noise_estimator) |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 210 | << ", vad_reset_period_ms: " |
| 211 | << gain_controller2.adaptive_digital.vad_reset_period_ms |
Alessio Bazzica | 6f75f6b | 2021-02-02 16:52:39 +0100 | [diff] [blame] | 212 | << ", adjacent_speech_frames_threshold: " |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 213 | << gain_controller2.adaptive_digital.adjacent_speech_frames_threshold |
Alessio Bazzica | 6f75f6b | 2021-02-02 16:52:39 +0100 | [diff] [blame] | 214 | << ", max_gain_change_db_per_second: " |
| 215 | << gain_controller2.adaptive_digital.max_gain_change_db_per_second |
| 216 | << ", max_output_noise_level_dbfs: " |
| 217 | << gain_controller2.adaptive_digital.max_output_noise_level_dbfs |
| 218 | << ", sse2_allowed: " << gain_controller2.adaptive_digital.sse2_allowed |
| 219 | << ", avx2_allowed: " << gain_controller2.adaptive_digital.avx2_allowed |
| 220 | << ", neon_allowed: " << gain_controller2.adaptive_digital.neon_allowed |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 221 | << "}}, residual_echo_detector: { enabled: " |
Alessio Bazzica | 6f75f6b | 2021-02-02 16:52:39 +0100 | [diff] [blame] | 222 | << residual_echo_detector.enabled |
| 223 | << " }, level_estimation: { enabled: " << level_estimation.enabled |
| 224 | << " }}"; |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 225 | return builder.str(); |
| 226 | } |
| 227 | |
aleloi | 5f09980 | 2016-08-25 00:45:31 -0700 | [diff] [blame] | 228 | } // namespace webrtc |