niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 648af74 | 2012-02-08 01:57:29 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | #ifndef MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_PROCESSING_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_PROCESSING_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Alejandro Luebs | cb3f9bd | 2015-10-29 18:21:34 -0700 | [diff] [blame] | 14 | // MSVC++ requires this to be set before any other includes to get M_PI. |
Patrik Höglund | 3ff90f1 | 2017-12-12 14:41:53 +0100 | [diff] [blame] | 15 | #ifndef _USE_MATH_DEFINES |
Alejandro Luebs | cb3f9bd | 2015-10-29 18:21:34 -0700 | [diff] [blame] | 16 | #define _USE_MATH_DEFINES |
Patrik Höglund | 3ff90f1 | 2017-12-12 14:41:53 +0100 | [diff] [blame] | 17 | #endif |
Alejandro Luebs | cb3f9bd | 2015-10-29 18:21:34 -0700 | [diff] [blame] | 18 | |
| 19 | #include <math.h> |
andrew@webrtc.org | d72b3d6 | 2012-11-15 21:46:06 +0000 | [diff] [blame] | 20 | #include <stddef.h> // size_t |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 21 | #include <stdio.h> // FILE |
peah | 8cee56f | 2017-08-24 22:36:53 -0700 | [diff] [blame] | 22 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 23 | |
aluebs@webrtc.org | fb7a039 | 2015-01-05 21:58:58 +0000 | [diff] [blame] | 24 | #include <vector> |
ajm@google.com | 22e6515 | 2011-07-18 18:03:01 +0000 | [diff] [blame] | 25 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 26 | #include "absl/types/optional.h" |
Sam Zackrisson | ab866a2 | 2020-05-07 13:07:49 +0200 | [diff] [blame] | 27 | #include "api/array_view.h" |
Gustaf Ullberg | bffa300 | 2018-02-14 15:12:00 +0100 | [diff] [blame] | 28 | #include "api/audio/echo_canceller3_config.h" |
Gustaf Ullberg | fd4ce50 | 2018-02-15 10:09:09 +0100 | [diff] [blame] | 29 | #include "api/audio/echo_control.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 30 | #include "api/scoped_refptr.h" |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 31 | #include "modules/audio_processing/include/audio_processing_statistics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 32 | #include "modules/audio_processing/include/config.h" |
| 33 | #include "rtc_base/arraysize.h" |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 34 | #include "rtc_base/deprecation.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 35 | #include "rtc_base/ref_count.h" |
Mirko Bonadei | 3d25530 | 2018-10-11 10:50:45 +0200 | [diff] [blame] | 36 | #include "rtc_base/system/rtc_export.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
| 38 | namespace webrtc { |
| 39 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 40 | class AecDump; |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 41 | class AudioBuffer; |
Michael Graczyk | dfa3605 | 2015-03-25 16:37:27 -0700 | [diff] [blame] | 42 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 43 | class StreamConfig; |
| 44 | class ProcessingConfig; |
| 45 | |
Ivo Creusen | 09fa4b0 | 2018-01-11 16:08:54 +0100 | [diff] [blame] | 46 | class EchoDetector; |
Valeriia Nemychnikova | f06eb57 | 2018-08-29 10:37:09 +0200 | [diff] [blame] | 47 | class CustomAudioAnalyzer; |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 48 | class CustomProcessing; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
Bjorn Volcker | adc46c4 | 2015-04-15 11:42:40 +0200 | [diff] [blame] | 50 | // Use to enable experimental gain control (AGC). At startup the experimental |
| 51 | // AGC moves the microphone volume up to |startup_min_volume| if the current |
| 52 | // microphone volume is set too low. The value is clamped to its operating range |
| 53 | // [12, 255]. Here, 255 maps to 100%. |
| 54 | // |
Ivo Creusen | 62337e5 | 2018-01-09 14:17:33 +0100 | [diff] [blame] | 55 | // Must be provided through AudioProcessingBuilder().Create(config). |
Bjorn Volcker | fb49451 | 2015-04-22 06:39:58 +0200 | [diff] [blame] | 56 | #if defined(WEBRTC_CHROMIUM_BUILD) |
Bjorn Volcker | adc46c4 | 2015-04-15 11:42:40 +0200 | [diff] [blame] | 57 | static const int kAgcStartupMinVolume = 85; |
Bjorn Volcker | fb49451 | 2015-04-22 06:39:58 +0200 | [diff] [blame] | 58 | #else |
| 59 | static const int kAgcStartupMinVolume = 0; |
| 60 | #endif // defined(WEBRTC_CHROMIUM_BUILD) |
Henrik Lundin | e3a4da9 | 2017-11-06 11:42:21 +0100 | [diff] [blame] | 61 | static constexpr int kClippedLevelMin = 70; |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 62 | |
| 63 | // To be deprecated: Please instead use the flag in the |
| 64 | // AudioProcessing::Config::AnalogGainController. |
| 65 | // TODO(webrtc:5298): Remove. |
andrew@webrtc.org | c7c7a53 | 2014-01-29 04:57:25 +0000 | [diff] [blame] | 66 | struct ExperimentalAgc { |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 67 | ExperimentalAgc() = default; |
| 68 | explicit ExperimentalAgc(bool enabled) : enabled(enabled) {} |
Alex Loiko | 64cb83b | 2018-07-02 13:38:19 +0200 | [diff] [blame] | 69 | ExperimentalAgc(bool enabled, |
| 70 | bool enabled_agc2_level_estimator, |
Per Åhgren | b8c1be5 | 2019-11-07 20:35:50 +0100 | [diff] [blame] | 71 | bool digital_adaptive_disabled) |
| 72 | : enabled(enabled), |
| 73 | enabled_agc2_level_estimator(enabled_agc2_level_estimator), |
| 74 | digital_adaptive_disabled(digital_adaptive_disabled) {} |
| 75 | // Deprecated constructor: will be removed. |
| 76 | ExperimentalAgc(bool enabled, |
| 77 | bool enabled_agc2_level_estimator, |
Alex Loiko | d934244 | 2018-09-10 13:59:41 +0200 | [diff] [blame] | 78 | bool digital_adaptive_disabled, |
| 79 | bool analyze_before_aec) |
Alex Loiko | 64cb83b | 2018-07-02 13:38:19 +0200 | [diff] [blame] | 80 | : enabled(enabled), |
| 81 | enabled_agc2_level_estimator(enabled_agc2_level_estimator), |
Per Åhgren | b8c1be5 | 2019-11-07 20:35:50 +0100 | [diff] [blame] | 82 | digital_adaptive_disabled(digital_adaptive_disabled) {} |
Bjorn Volcker | adc46c4 | 2015-04-15 11:42:40 +0200 | [diff] [blame] | 83 | ExperimentalAgc(bool enabled, int startup_min_volume) |
| 84 | : enabled(enabled), startup_min_volume(startup_min_volume) {} |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 85 | ExperimentalAgc(bool enabled, int startup_min_volume, int clipped_level_min) |
| 86 | : enabled(enabled), |
| 87 | startup_min_volume(startup_min_volume), |
| 88 | clipped_level_min(clipped_level_min) {} |
aluebs | 688e308 | 2016-01-14 04:32:46 -0800 | [diff] [blame] | 89 | static const ConfigOptionID identifier = ConfigOptionID::kExperimentalAgc; |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 90 | bool enabled = true; |
| 91 | int startup_min_volume = kAgcStartupMinVolume; |
| 92 | // Lowest microphone level that will be applied in response to clipping. |
| 93 | int clipped_level_min = kClippedLevelMin; |
Alex Loiko | 64cb83b | 2018-07-02 13:38:19 +0200 | [diff] [blame] | 94 | bool enabled_agc2_level_estimator = false; |
Alex Loiko | 9489c3a | 2018-08-09 15:04:24 +0200 | [diff] [blame] | 95 | bool digital_adaptive_disabled = false; |
andrew@webrtc.org | 6b1e219 | 2013-09-25 23:46:20 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
Per Åhgren | c073471 | 2020-01-02 15:15:36 +0100 | [diff] [blame] | 98 | // To be deprecated: Please instead use the flag in the |
| 99 | // AudioProcessing::Config::TransientSuppression. |
| 100 | // |
aluebs@webrtc.org | 9825afc | 2014-06-30 17:39:53 +0000 | [diff] [blame] | 101 | // Use to enable experimental noise suppression. It can be set in the |
| 102 | // constructor or using AudioProcessing::SetExtraOptions(). |
Per Åhgren | c073471 | 2020-01-02 15:15:36 +0100 | [diff] [blame] | 103 | // TODO(webrtc:5298): Remove. |
aluebs@webrtc.org | 9825afc | 2014-06-30 17:39:53 +0000 | [diff] [blame] | 104 | struct ExperimentalNs { |
| 105 | ExperimentalNs() : enabled(false) {} |
| 106 | explicit ExperimentalNs(bool enabled) : enabled(enabled) {} |
aluebs | 688e308 | 2016-01-14 04:32:46 -0800 | [diff] [blame] | 107 | static const ConfigOptionID identifier = ConfigOptionID::kExperimentalNs; |
aluebs@webrtc.org | 9825afc | 2014-06-30 17:39:53 +0000 | [diff] [blame] | 108 | bool enabled; |
| 109 | }; |
| 110 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | // The Audio Processing Module (APM) provides a collection of voice processing |
| 112 | // components designed for real-time communications software. |
| 113 | // |
| 114 | // APM operates on two audio streams on a frame-by-frame basis. Frames of the |
| 115 | // primary stream, on which all processing is applied, are passed to |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 116 | // |ProcessStream()|. Frames of the reverse direction stream are passed to |
| 117 | // |ProcessReverseStream()|. On the client-side, this will typically be the |
| 118 | // near-end (capture) and far-end (render) streams, respectively. APM should be |
| 119 | // placed in the signal chain as close to the audio hardware abstraction layer |
| 120 | // (HAL) as possible. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | // |
| 122 | // On the server-side, the reverse stream will normally not be used, with |
| 123 | // processing occurring on each incoming stream. |
| 124 | // |
| 125 | // Component interfaces follow a similar pattern and are accessed through |
| 126 | // corresponding getters in APM. All components are disabled at create-time, |
| 127 | // with default settings that are recommended for most situations. New settings |
| 128 | // can be applied without enabling a component. Enabling a component triggers |
| 129 | // memory allocation and initialization to allow it to start processing the |
| 130 | // streams. |
| 131 | // |
| 132 | // Thread safety is provided with the following assumptions to reduce locking |
| 133 | // overhead: |
| 134 | // 1. The stream getters and setters are called from the same thread as |
| 135 | // ProcessStream(). More precisely, stream functions are never called |
| 136 | // concurrently with ProcessStream(). |
| 137 | // 2. Parameter getters are never called concurrently with the corresponding |
| 138 | // setter. |
| 139 | // |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 140 | // APM accepts only linear PCM audio data in chunks of 10 ms. The int16 |
| 141 | // interfaces use interleaved data, while the float interfaces use deinterleaved |
| 142 | // data. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 143 | // |
| 144 | // Usage example, omitting error checking: |
Ivo Creusen | 62337e5 | 2018-01-09 14:17:33 +0100 | [diff] [blame] | 145 | // AudioProcessing* apm = AudioProcessingBuilder().Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | // |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 147 | // AudioProcessing::Config config; |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 148 | // config.echo_canceller.enabled = true; |
| 149 | // config.echo_canceller.mobile_mode = false; |
Sam Zackrisson | 41478c7 | 2019-10-15 10:10:26 +0200 | [diff] [blame] | 150 | // |
| 151 | // config.gain_controller1.enabled = true; |
| 152 | // config.gain_controller1.mode = |
| 153 | // AudioProcessing::Config::GainController1::kAdaptiveAnalog; |
| 154 | // config.gain_controller1.analog_level_minimum = 0; |
| 155 | // config.gain_controller1.analog_level_maximum = 255; |
| 156 | // |
Sam Zackrisson | ab1aee0 | 2018-03-05 15:59:06 +0100 | [diff] [blame] | 157 | // config.gain_controller2.enabled = true; |
Sam Zackrisson | 41478c7 | 2019-10-15 10:10:26 +0200 | [diff] [blame] | 158 | // |
| 159 | // config.high_pass_filter.enabled = true; |
| 160 | // |
| 161 | // config.voice_detection.enabled = true; |
| 162 | // |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 163 | // apm->ApplyConfig(config) |
| 164 | // |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 165 | // apm->noise_reduction()->set_level(kHighSuppression); |
| 166 | // apm->noise_reduction()->Enable(true); |
| 167 | // |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 168 | // // Start a voice call... |
| 169 | // |
| 170 | // // ... Render frame arrives bound for the audio HAL ... |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 171 | // apm->ProcessReverseStream(render_frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | // |
| 173 | // // ... Capture frame arrives from the audio HAL ... |
| 174 | // // Call required set_stream_ functions. |
| 175 | // apm->set_stream_delay_ms(delay_ms); |
Sam Zackrisson | 41478c7 | 2019-10-15 10:10:26 +0200 | [diff] [blame] | 176 | // apm->set_stream_analog_level(analog_level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 177 | // |
| 178 | // apm->ProcessStream(capture_frame); |
| 179 | // |
| 180 | // // Call required stream_ functions. |
Sam Zackrisson | 41478c7 | 2019-10-15 10:10:26 +0200 | [diff] [blame] | 181 | // analog_level = apm->recommended_stream_analog_level(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | // has_voice = apm->stream_has_voice(); |
| 183 | // |
| 184 | // // Repeate render and capture processing for the duration of the call... |
| 185 | // // Start a new call... |
| 186 | // apm->Initialize(); |
| 187 | // |
| 188 | // // Close the application... |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 189 | // delete apm; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | // |
Mirko Bonadei | 35214fc | 2019-09-23 14:54:28 +0200 | [diff] [blame] | 191 | class RTC_EXPORT AudioProcessing : public rtc::RefCountInterface { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | public: |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 193 | // The struct below constitutes the new parameter scheme for the audio |
| 194 | // processing. It is being introduced gradually and until it is fully |
| 195 | // introduced, it is prone to change. |
| 196 | // TODO(peah): Remove this comment once the new config scheme is fully rolled |
| 197 | // out. |
| 198 | // |
| 199 | // The parameters and behavior of the audio processing module are controlled |
| 200 | // by changing the default values in the AudioProcessing::Config struct. |
| 201 | // The config is applied by passing the struct to the ApplyConfig method. |
Sam Zackrisson | f0d1c03 | 2019-03-27 13:28:08 +0100 | [diff] [blame] | 202 | // |
| 203 | // This config is intended to be used during setup, and to enable/disable |
| 204 | // top-level processing effects. Use during processing may cause undesired |
| 205 | // submodule resets, affecting the audio quality. Use the RuntimeSetting |
| 206 | // construct for runtime configuration. |
Mirko Bonadei | d4002a7 | 2019-11-12 20:11:48 +0100 | [diff] [blame] | 207 | struct RTC_EXPORT Config { |
Per Åhgren | 2512604 | 2019-12-05 07:32:32 +0100 | [diff] [blame] | 208 | |
Per Åhgren | fcbe407 | 2019-09-15 00:27:58 +0200 | [diff] [blame] | 209 | // Sets the properties of the audio processing pipeline. |
Mirko Bonadei | d4002a7 | 2019-11-12 20:11:48 +0100 | [diff] [blame] | 210 | struct RTC_EXPORT Pipeline { |
Per Åhgren | fcbe407 | 2019-09-15 00:27:58 +0200 | [diff] [blame] | 211 | Pipeline(); |
| 212 | |
| 213 | // Maximum allowed processing rate used internally. May only be set to |
| 214 | // 32000 or 48000 and any differing values will be treated as 48000. The |
| 215 | // default rate is currently selected based on the CPU architecture, but |
| 216 | // that logic may change. |
| 217 | int maximum_internal_processing_rate; |
Per Åhgren | e14cb99 | 2019-11-27 09:34:22 +0100 | [diff] [blame] | 218 | // Allow multi-channel processing of render audio. |
| 219 | bool multi_channel_render = false; |
| 220 | // Allow multi-channel processing of capture audio when AEC3 is active |
| 221 | // or a custom AEC is injected.. |
| 222 | bool multi_channel_capture = false; |
Per Åhgren | fcbe407 | 2019-09-15 00:27:58 +0200 | [diff] [blame] | 223 | } pipeline; |
| 224 | |
Sam Zackrisson | 2351313 | 2019-01-11 15:10:32 +0100 | [diff] [blame] | 225 | // Enabled the pre-amplifier. It amplifies the capture signal |
| 226 | // before any other processing is done. |
| 227 | struct PreAmplifier { |
| 228 | bool enabled = false; |
| 229 | float fixed_gain_factor = 1.f; |
| 230 | } pre_amplifier; |
| 231 | |
| 232 | struct HighPassFilter { |
| 233 | bool enabled = false; |
Per Åhgren | c042425 | 2019-12-10 13:04:15 +0100 | [diff] [blame] | 234 | bool apply_in_full_band = true; |
Sam Zackrisson | 2351313 | 2019-01-11 15:10:32 +0100 | [diff] [blame] | 235 | } high_pass_filter; |
| 236 | |
Sam Zackrisson | 8b5d2cc | 2018-07-27 13:27:23 +0200 | [diff] [blame] | 237 | struct EchoCanceller { |
| 238 | bool enabled = false; |
| 239 | bool mobile_mode = false; |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 240 | bool export_linear_aec_output = false; |
Per Åhgren | b810646 | 2019-12-04 08:34:12 +0100 | [diff] [blame] | 241 | // Enforce the highpass filter to be on (has no effect for the mobile |
| 242 | // mode). |
Per Åhgren | bcce453 | 2019-12-03 13:52:40 +0100 | [diff] [blame] | 243 | bool enforce_high_pass_filtering = true; |
Sam Zackrisson | 8b5d2cc | 2018-07-27 13:27:23 +0200 | [diff] [blame] | 244 | } echo_canceller; |
| 245 | |
Sam Zackrisson | 2351313 | 2019-01-11 15:10:32 +0100 | [diff] [blame] | 246 | // Enables background noise suppression. |
| 247 | struct NoiseSuppression { |
peah | 8271d04 | 2016-11-22 07:24:52 -0800 | [diff] [blame] | 248 | bool enabled = false; |
Sam Zackrisson | 2351313 | 2019-01-11 15:10:32 +0100 | [diff] [blame] | 249 | enum Level { kLow, kModerate, kHigh, kVeryHigh }; |
| 250 | Level level = kModerate; |
Per Åhgren | 2e8e1c6 | 2019-12-20 00:42:22 +0100 | [diff] [blame] | 251 | bool analyze_linear_aec_output_when_available = false; |
Sam Zackrisson | 2351313 | 2019-01-11 15:10:32 +0100 | [diff] [blame] | 252 | } noise_suppression; |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 253 | |
Per Åhgren | c073471 | 2020-01-02 15:15:36 +0100 | [diff] [blame] | 254 | // Enables transient suppression. |
| 255 | struct TransientSuppression { |
| 256 | bool enabled = false; |
| 257 | } transient_suppression; |
| 258 | |
Sam Zackrisson | 0824c6f | 2019-10-07 14:03:56 +0200 | [diff] [blame] | 259 | // Enables reporting of |voice_detected| in webrtc::AudioProcessingStats. |
Sam Zackrisson | 2351313 | 2019-01-11 15:10:32 +0100 | [diff] [blame] | 260 | struct VoiceDetection { |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 261 | bool enabled = false; |
Sam Zackrisson | 2351313 | 2019-01-11 15:10:32 +0100 | [diff] [blame] | 262 | } voice_detection; |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 263 | |
Sam Zackrisson | f0d1c03 | 2019-03-27 13:28:08 +0100 | [diff] [blame] | 264 | // Enables automatic gain control (AGC) functionality. |
| 265 | // The automatic gain control (AGC) component brings the signal to an |
| 266 | // appropriate range. This is done by applying a digital gain directly and, |
| 267 | // in the analog mode, prescribing an analog gain to be applied at the audio |
| 268 | // HAL. |
| 269 | // Recommended to be enabled on the client-side. |
| 270 | struct GainController1 { |
| 271 | bool enabled = false; |
| 272 | enum Mode { |
| 273 | // Adaptive mode intended for use if an analog volume control is |
| 274 | // available on the capture device. It will require the user to provide |
| 275 | // coupling between the OS mixer controls and AGC through the |
| 276 | // stream_analog_level() functions. |
| 277 | // It consists of an analog gain prescription for the audio device and a |
| 278 | // digital compression stage. |
| 279 | kAdaptiveAnalog, |
| 280 | // Adaptive mode intended for situations in which an analog volume |
| 281 | // control is unavailable. It operates in a similar fashion to the |
| 282 | // adaptive analog mode, but with scaling instead applied in the digital |
| 283 | // domain. As with the analog mode, it additionally uses a digital |
| 284 | // compression stage. |
| 285 | kAdaptiveDigital, |
| 286 | // Fixed mode which enables only the digital compression stage also used |
| 287 | // by the two adaptive modes. |
| 288 | // It is distinguished from the adaptive modes by considering only a |
| 289 | // short time-window of the input signal. It applies a fixed gain |
| 290 | // through most of the input level range, and compresses (gradually |
| 291 | // reduces gain with increasing level) the input signal at higher |
| 292 | // levels. This mode is preferred on embedded devices where the capture |
| 293 | // signal level is predictable, so that a known gain can be applied. |
| 294 | kFixedDigital |
| 295 | }; |
| 296 | Mode mode = kAdaptiveAnalog; |
| 297 | // Sets the target peak level (or envelope) of the AGC in dBFs (decibels |
| 298 | // from digital full-scale). The convention is to use positive values. For |
| 299 | // instance, passing in a value of 3 corresponds to -3 dBFs, or a target |
| 300 | // level 3 dB below full-scale. Limited to [0, 31]. |
| 301 | int target_level_dbfs = 3; |
| 302 | // Sets the maximum gain the digital compression stage may apply, in dB. A |
| 303 | // higher number corresponds to greater compression, while a value of 0 |
| 304 | // will leave the signal uncompressed. Limited to [0, 90]. |
| 305 | // For updates after APM setup, use a RuntimeSetting instead. |
| 306 | int compression_gain_db = 9; |
| 307 | // When enabled, the compression stage will hard limit the signal to the |
| 308 | // target level. Otherwise, the signal will be compressed but not limited |
| 309 | // above the target level. |
| 310 | bool enable_limiter = true; |
| 311 | // Sets the minimum and maximum analog levels of the audio capture device. |
| 312 | // Must be set if an analog mode is used. Limited to [0, 65535]. |
| 313 | int analog_level_minimum = 0; |
| 314 | int analog_level_maximum = 255; |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 315 | |
| 316 | // Enables the analog gain controller functionality. |
| 317 | struct AnalogGainController { |
| 318 | bool enabled = true; |
| 319 | int startup_min_volume = kAgcStartupMinVolume; |
| 320 | // Lowest analog microphone level that will be applied in response to |
| 321 | // clipping. |
| 322 | int clipped_level_min = kClippedLevelMin; |
| 323 | bool enable_agc2_level_estimator = false; |
| 324 | bool enable_digital_adaptive = true; |
| 325 | } analog_gain_controller; |
Sam Zackrisson | f0d1c03 | 2019-03-27 13:28:08 +0100 | [diff] [blame] | 326 | } gain_controller1; |
| 327 | |
Alex Loiko | e583174 | 2018-08-24 11:28:36 +0200 | [diff] [blame] | 328 | // Enables the next generation AGC functionality. This feature replaces the |
| 329 | // standard methods of gain control in the previous AGC. Enabling this |
| 330 | // submodule enables an adaptive digital AGC followed by a limiter. By |
| 331 | // setting |fixed_gain_db|, the limiter can be turned into a compressor that |
| 332 | // first applies a fixed gain. The adaptive digital AGC can be turned off by |
| 333 | // setting |adaptive_digital_mode=false|. |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 334 | struct GainController2 { |
Alessio Bazzica | 1e2542f | 2018-11-13 14:44:15 +0100 | [diff] [blame] | 335 | enum LevelEstimator { kRms, kPeak }; |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 336 | bool enabled = false; |
Alessio Bazzica | 1e2542f | 2018-11-13 14:44:15 +0100 | [diff] [blame] | 337 | struct { |
| 338 | float gain_db = 0.f; |
| 339 | } fixed_digital; |
| 340 | struct { |
Alessio Bazzica | 8da7b35 | 2018-11-21 10:50:58 +0100 | [diff] [blame] | 341 | bool enabled = false; |
Alessio Bazzica | 1e2542f | 2018-11-13 14:44:15 +0100 | [diff] [blame] | 342 | LevelEstimator level_estimator = kRms; |
| 343 | bool use_saturation_protector = true; |
| 344 | float extra_saturation_margin_db = 2.f; |
| 345 | } adaptive_digital; |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 346 | } gain_controller2; |
peah | 8cee56f | 2017-08-24 22:36:53 -0700 | [diff] [blame] | 347 | |
Sam Zackrisson | 2351313 | 2019-01-11 15:10:32 +0100 | [diff] [blame] | 348 | struct ResidualEchoDetector { |
| 349 | bool enabled = true; |
| 350 | } residual_echo_detector; |
| 351 | |
Sam Zackrisson | b24c00f | 2018-11-26 16:18:25 +0100 | [diff] [blame] | 352 | // Enables reporting of |output_rms_dbfs| in webrtc::AudioProcessingStats. |
| 353 | struct LevelEstimation { |
| 354 | bool enabled = false; |
| 355 | } level_estimation; |
| 356 | |
Artem Titov | 59bbd65 | 2019-08-02 11:31:37 +0200 | [diff] [blame] | 357 | std::string ToString() const; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 358 | }; |
| 359 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 360 | // TODO(mgraczyk): Remove once all methods that use ChannelLayout are gone. |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 361 | enum ChannelLayout { |
| 362 | kMono, |
| 363 | // Left, right. |
| 364 | kStereo, |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 365 | // Mono, keyboard, and mic. |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 366 | kMonoAndKeyboard, |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 367 | // Left, right, keyboard, and mic. |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 368 | kStereoAndKeyboard |
| 369 | }; |
| 370 | |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 371 | // Specifies the properties of a setting to be passed to AudioProcessing at |
| 372 | // runtime. |
| 373 | class RuntimeSetting { |
| 374 | public: |
Alex Loiko | 73ec019 | 2018-05-15 10:52:28 +0200 | [diff] [blame] | 375 | enum class Type { |
| 376 | kNotSpecified, |
| 377 | kCapturePreGain, |
Sam Zackrisson | f0d1c03 | 2019-03-27 13:28:08 +0100 | [diff] [blame] | 378 | kCaptureCompressionGain, |
Per Åhgren | 6ee75fd | 2019-04-26 11:33:37 +0200 | [diff] [blame] | 379 | kCaptureFixedPostGain, |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 380 | kPlayoutVolumeChange, |
Alessio Bazzica | 7c19a70 | 2019-11-07 13:22:00 +0100 | [diff] [blame] | 381 | kCustomRenderProcessingRuntimeSetting, |
| 382 | kPlayoutAudioDeviceChange |
| 383 | }; |
| 384 | |
| 385 | // Play-out audio device properties. |
| 386 | struct PlayoutAudioDeviceInfo { |
| 387 | int id; // Identifies the audio device. |
| 388 | int max_volume; // Maximum play-out volume. |
Alex Loiko | 73ec019 | 2018-05-15 10:52:28 +0200 | [diff] [blame] | 389 | }; |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 390 | |
| 391 | RuntimeSetting() : type_(Type::kNotSpecified), value_(0.f) {} |
| 392 | ~RuntimeSetting() = default; |
| 393 | |
| 394 | static RuntimeSetting CreateCapturePreGain(float gain) { |
| 395 | RTC_DCHECK_GE(gain, 1.f) << "Attenuation is not allowed."; |
| 396 | return {Type::kCapturePreGain, gain}; |
| 397 | } |
| 398 | |
Sam Zackrisson | f0d1c03 | 2019-03-27 13:28:08 +0100 | [diff] [blame] | 399 | // Corresponds to Config::GainController1::compression_gain_db, but for |
| 400 | // runtime configuration. |
| 401 | static RuntimeSetting CreateCompressionGainDb(int gain_db) { |
| 402 | RTC_DCHECK_GE(gain_db, 0); |
| 403 | RTC_DCHECK_LE(gain_db, 90); |
| 404 | return {Type::kCaptureCompressionGain, static_cast<float>(gain_db)}; |
| 405 | } |
| 406 | |
Per Åhgren | 6ee75fd | 2019-04-26 11:33:37 +0200 | [diff] [blame] | 407 | // Corresponds to Config::GainController2::fixed_digital::gain_db, but for |
| 408 | // runtime configuration. |
| 409 | static RuntimeSetting CreateCaptureFixedPostGain(float gain_db) { |
| 410 | RTC_DCHECK_GE(gain_db, 0.f); |
| 411 | RTC_DCHECK_LE(gain_db, 90.f); |
| 412 | return {Type::kCaptureFixedPostGain, gain_db}; |
| 413 | } |
| 414 | |
Alessio Bazzica | 7c19a70 | 2019-11-07 13:22:00 +0100 | [diff] [blame] | 415 | // Creates a runtime setting to notify play-out (aka render) audio device |
| 416 | // changes. |
| 417 | static RuntimeSetting CreatePlayoutAudioDeviceChange( |
| 418 | PlayoutAudioDeviceInfo audio_device) { |
| 419 | return {Type::kPlayoutAudioDeviceChange, audio_device}; |
| 420 | } |
| 421 | |
| 422 | // Creates a runtime setting to notify play-out (aka render) volume changes. |
| 423 | // |volume| is the unnormalized volume, the maximum of which |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 424 | static RuntimeSetting CreatePlayoutVolumeChange(int volume) { |
| 425 | return {Type::kPlayoutVolumeChange, volume}; |
| 426 | } |
| 427 | |
Alex Loiko | 73ec019 | 2018-05-15 10:52:28 +0200 | [diff] [blame] | 428 | static RuntimeSetting CreateCustomRenderSetting(float payload) { |
| 429 | return {Type::kCustomRenderProcessingRuntimeSetting, payload}; |
| 430 | } |
| 431 | |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 432 | Type type() const { return type_; } |
Alessio Bazzica | 7c19a70 | 2019-11-07 13:22:00 +0100 | [diff] [blame] | 433 | // Getters do not return a value but instead modify the argument to protect |
| 434 | // from implicit casting. |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 435 | void GetFloat(float* value) const { |
| 436 | RTC_DCHECK(value); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 437 | *value = value_.float_value; |
| 438 | } |
| 439 | void GetInt(int* value) const { |
| 440 | RTC_DCHECK(value); |
| 441 | *value = value_.int_value; |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 442 | } |
Alessio Bazzica | 7c19a70 | 2019-11-07 13:22:00 +0100 | [diff] [blame] | 443 | void GetPlayoutAudioDeviceInfo(PlayoutAudioDeviceInfo* value) const { |
| 444 | RTC_DCHECK(value); |
| 445 | *value = value_.playout_audio_device_info; |
| 446 | } |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 447 | |
| 448 | private: |
| 449 | RuntimeSetting(Type id, float value) : type_(id), value_(value) {} |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 450 | RuntimeSetting(Type id, int value) : type_(id), value_(value) {} |
Alessio Bazzica | 7c19a70 | 2019-11-07 13:22:00 +0100 | [diff] [blame] | 451 | RuntimeSetting(Type id, PlayoutAudioDeviceInfo value) |
| 452 | : type_(id), value_(value) {} |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 453 | Type type_; |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 454 | union U { |
| 455 | U() {} |
| 456 | U(int value) : int_value(value) {} |
| 457 | U(float value) : float_value(value) {} |
Alessio Bazzica | 7c19a70 | 2019-11-07 13:22:00 +0100 | [diff] [blame] | 458 | U(PlayoutAudioDeviceInfo value) : playout_audio_device_info(value) {} |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 459 | float float_value; |
| 460 | int int_value; |
Alessio Bazzica | 7c19a70 | 2019-11-07 13:22:00 +0100 | [diff] [blame] | 461 | PlayoutAudioDeviceInfo playout_audio_device_info; |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 462 | } value_; |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 463 | }; |
| 464 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 465 | ~AudioProcessing() override {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 466 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 467 | // Initializes internal states, while retaining all user settings. This |
| 468 | // should be called before beginning to process a new audio stream. However, |
| 469 | // it is not necessary to call before processing the first stream after |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 470 | // creation. |
| 471 | // |
| 472 | // It is also not necessary to call if the audio parameters (sample |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 473 | // rate and number of channels) have changed. Passing updated parameters |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 474 | // directly to |ProcessStream()| and |ProcessReverseStream()| is permissible. |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 475 | // If the parameters are known at init-time though, they may be provided. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 476 | virtual int Initialize() = 0; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 477 | |
| 478 | // The int16 interfaces require: |
| 479 | // - only |NativeRate|s be used |
| 480 | // - that the input, output and reverse rates must match |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 481 | // - that |processing_config.output_stream()| matches |
| 482 | // |processing_config.input_stream()|. |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 483 | // |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 484 | // The float interfaces accept arbitrary rates and support differing input and |
| 485 | // output layouts, but the output must have either one channel or the same |
| 486 | // number of channels as the input. |
| 487 | virtual int Initialize(const ProcessingConfig& processing_config) = 0; |
| 488 | |
| 489 | // Initialize with unpacked parameters. See Initialize() above for details. |
| 490 | // |
| 491 | // TODO(mgraczyk): Remove once clients are updated to use the new interface. |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 492 | virtual int Initialize(int capture_input_sample_rate_hz, |
| 493 | int capture_output_sample_rate_hz, |
| 494 | int render_sample_rate_hz, |
| 495 | ChannelLayout capture_input_layout, |
| 496 | ChannelLayout capture_output_layout, |
| 497 | ChannelLayout render_input_layout) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 498 | |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 499 | // TODO(peah): This method is a temporary solution used to take control |
| 500 | // over the parameters in the audio processing module and is likely to change. |
| 501 | virtual void ApplyConfig(const Config& config) = 0; |
| 502 | |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 503 | // Pass down additional options which don't have explicit setters. This |
| 504 | // ensures the options are applied immediately. |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 505 | virtual void SetExtraOptions(const webrtc::Config& config) = 0; |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 506 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 507 | // TODO(ajm): Only intended for internal use. Make private and friend the |
| 508 | // necessary classes? |
| 509 | virtual int proc_sample_rate_hz() const = 0; |
| 510 | virtual int proc_split_sample_rate_hz() const = 0; |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 511 | virtual size_t num_input_channels() const = 0; |
| 512 | virtual size_t num_proc_channels() const = 0; |
| 513 | virtual size_t num_output_channels() const = 0; |
| 514 | virtual size_t num_reverse_channels() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 515 | |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 516 | // Set to true when the output of AudioProcessing will be muted or in some |
| 517 | // other way not used. Ideally, the captured audio would still be processed, |
| 518 | // but some components may change behavior based on this information. |
| 519 | // Default false. |
| 520 | virtual void set_output_will_be_muted(bool muted) = 0; |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 521 | |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 522 | // Enqueue a runtime setting. |
| 523 | virtual void SetRuntimeSetting(RuntimeSetting setting) = 0; |
| 524 | |
Per Åhgren | 645f24c | 2020-03-16 12:06:02 +0100 | [diff] [blame] | 525 | // Accepts and produces a 10 ms frame interleaved 16 bit integer audio as |
| 526 | // specified in |input_config| and |output_config|. |src| and |dest| may use |
| 527 | // the same memory, if desired. |
| 528 | virtual int ProcessStream(const int16_t* const src, |
| 529 | const StreamConfig& input_config, |
| 530 | const StreamConfig& output_config, |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 531 | int16_t* const dest) = 0; |
Per Åhgren | 645f24c | 2020-03-16 12:06:02 +0100 | [diff] [blame] | 532 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 533 | // Accepts deinterleaved float audio with the range [-1, 1]. Each element of |
| 534 | // |src| points to a channel buffer, arranged according to |input_stream|. At |
| 535 | // output, the channels will be arranged according to |output_stream| in |
| 536 | // |dest|. |
| 537 | // |
| 538 | // The output must have one channel or as many channels as the input. |src| |
| 539 | // and |dest| may use the same memory, if desired. |
| 540 | virtual int ProcessStream(const float* const* src, |
| 541 | const StreamConfig& input_config, |
| 542 | const StreamConfig& output_config, |
| 543 | float* const* dest) = 0; |
| 544 | |
Per Åhgren | 645f24c | 2020-03-16 12:06:02 +0100 | [diff] [blame] | 545 | // Accepts and produces a 10 ms frame of interleaved 16 bit integer audio for |
| 546 | // the reverse direction audio stream as specified in |input_config| and |
| 547 | // |output_config|. |src| and |dest| may use the same memory, if desired. |
| 548 | virtual int ProcessReverseStream(const int16_t* const src, |
| 549 | const StreamConfig& input_config, |
| 550 | const StreamConfig& output_config, |
| 551 | int16_t* const dest) = 0; |
| 552 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 553 | // Accepts deinterleaved float audio with the range [-1, 1]. Each element of |
| 554 | // |data| points to a channel buffer, arranged according to |reverse_config|. |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 555 | virtual int ProcessReverseStream(const float* const* src, |
peah | de65ddc | 2016-09-16 15:02:15 -0700 | [diff] [blame] | 556 | const StreamConfig& input_config, |
| 557 | const StreamConfig& output_config, |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 558 | float* const* dest) = 0; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 559 | |
Gustaf Ullberg | cb30726 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 560 | // Accepts deinterleaved float audio with the range [-1, 1]. Each element |
| 561 | // of |data| points to a channel buffer, arranged according to |
| 562 | // |reverse_config|. |
| 563 | virtual int AnalyzeReverseStream(const float* const* data, |
| 564 | const StreamConfig& reverse_config) = 0; |
| 565 | |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 566 | // Returns the most recently produced 10 ms of the linear AEC output at a rate |
| 567 | // of 16 kHz. If there is more than one capture channel, a mono representation |
| 568 | // of the input is returned. Returns true/false to indicate whether an output |
| 569 | // returned. |
| 570 | virtual bool GetLinearAecOutput( |
| 571 | rtc::ArrayView<std::array<float, 160>> linear_output) const = 0; |
| 572 | |
Sam Zackrisson | f0d1c03 | 2019-03-27 13:28:08 +0100 | [diff] [blame] | 573 | // This must be called prior to ProcessStream() if and only if adaptive analog |
| 574 | // gain control is enabled, to pass the current analog level from the audio |
| 575 | // HAL. Must be within the range provided in Config::GainController1. |
| 576 | virtual void set_stream_analog_level(int level) = 0; |
| 577 | |
| 578 | // When an analog mode is set, this should be called after ProcessStream() |
| 579 | // to obtain the recommended new analog level for the audio HAL. It is the |
| 580 | // user's responsibility to apply this level. |
| 581 | virtual int recommended_stream_analog_level() const = 0; |
| 582 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 583 | // This must be called if and only if echo processing is enabled. |
| 584 | // |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 585 | // Sets the |delay| in ms between ProcessReverseStream() receiving a far-end |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 586 | // frame and ProcessStream() receiving a near-end frame containing the |
| 587 | // corresponding echo. On the client-side this can be expressed as |
| 588 | // delay = (t_render - t_analyze) + (t_process - t_capture) |
| 589 | // where, |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 590 | // - t_analyze is the time a frame is passed to ProcessReverseStream() and |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 591 | // t_render is the time the first sample of the same frame is rendered by |
| 592 | // the audio hardware. |
| 593 | // - t_capture is the time the first sample of a frame is captured by the |
alessiob | 13fc180 | 2017-04-19 05:35:51 -0700 | [diff] [blame] | 594 | // audio hardware and t_process is the time the same frame is passed to |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 595 | // ProcessStream(). |
| 596 | virtual int set_stream_delay_ms(int delay) = 0; |
| 597 | virtual int stream_delay_ms() const = 0; |
| 598 | |
andrew@webrtc.org | 75dd288 | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 599 | // Call to signal that a key press occurred (true) or did not occur (false) |
| 600 | // with this chunk of audio. |
| 601 | virtual void set_stream_key_pressed(bool key_pressed) = 0; |
andrew@webrtc.org | 75dd288 | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 602 | |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 603 | // Attaches provided webrtc::AecDump for recording debugging |
| 604 | // information. Log file and maximum file size logic is supposed to |
| 605 | // be handled by implementing instance of AecDump. Calling this |
| 606 | // method when another AecDump is attached resets the active AecDump |
| 607 | // with a new one. This causes the d-tor of the earlier AecDump to |
| 608 | // be called. The d-tor call may block until all pending logging |
| 609 | // tasks are completed. |
Alex Loiko | be767e0 | 2017-06-08 09:45:03 +0200 | [diff] [blame] | 610 | virtual void AttachAecDump(std::unique_ptr<AecDump> aec_dump) = 0; |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 611 | |
| 612 | // If no AecDump is attached, this has no effect. If an AecDump is |
| 613 | // attached, it's destructor is called. The d-tor may block until |
| 614 | // all pending logging tasks are completed. |
Alex Loiko | be767e0 | 2017-06-08 09:45:03 +0200 | [diff] [blame] | 615 | virtual void DetachAecDump() = 0; |
aleloi | 868f32f | 2017-05-23 07:20:05 -0700 | [diff] [blame] | 616 | |
Per Åhgren | cf4c872 | 2019-12-30 14:32:14 +0100 | [diff] [blame] | 617 | // Get audio processing statistics. |
| 618 | virtual AudioProcessingStats GetStatistics() = 0; |
| 619 | // TODO(webrtc:5298) Deprecated variant. The |has_remote_tracks| argument |
| 620 | // should be set if there are active remote tracks (this would usually be true |
| 621 | // during a call). If there are no remote tracks some of the stats will not be |
| 622 | // set by AudioProcessing, because they only make sense if there is at least |
| 623 | // one remote track. |
| 624 | virtual AudioProcessingStats GetStatistics(bool has_remote_tracks) = 0; |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 625 | |
henrik.lundin | adf0635 | 2017-04-05 05:48:24 -0700 | [diff] [blame] | 626 | // Returns the last applied configuration. |
henrik.lundin | 7749286 | 2017-04-06 23:28:09 -0700 | [diff] [blame] | 627 | virtual AudioProcessing::Config GetConfig() const = 0; |
henrik.lundin | adf0635 | 2017-04-05 05:48:24 -0700 | [diff] [blame] | 628 | |
andrew@webrtc.org | 648af74 | 2012-02-08 01:57:29 +0000 | [diff] [blame] | 629 | enum Error { |
| 630 | // Fatal errors. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 631 | kNoError = 0, |
| 632 | kUnspecifiedError = -1, |
| 633 | kCreationFailedError = -2, |
| 634 | kUnsupportedComponentError = -3, |
| 635 | kUnsupportedFunctionError = -4, |
| 636 | kNullPointerError = -5, |
| 637 | kBadParameterError = -6, |
| 638 | kBadSampleRateError = -7, |
| 639 | kBadDataLengthError = -8, |
| 640 | kBadNumberChannelsError = -9, |
| 641 | kFileError = -10, |
| 642 | kStreamParameterNotSetError = -11, |
andrew@webrtc.org | 648af74 | 2012-02-08 01:57:29 +0000 | [diff] [blame] | 643 | kNotEnabledError = -12, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 644 | |
andrew@webrtc.org | 648af74 | 2012-02-08 01:57:29 +0000 | [diff] [blame] | 645 | // Warnings are non-fatal. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 646 | // This results when a set_stream_ parameter is out of range. Processing |
| 647 | // will continue, but the parameter may have been truncated. |
andrew@webrtc.org | 648af74 | 2012-02-08 01:57:29 +0000 | [diff] [blame] | 648 | kBadStreamParameterWarning = -13 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 649 | }; |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 650 | |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 651 | // Native rates supported by the integer interfaces. |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 652 | enum NativeRate { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 653 | kSampleRate8kHz = 8000, |
| 654 | kSampleRate16kHz = 16000, |
aluebs@webrtc.org | 087da13 | 2014-11-17 23:01:23 +0000 | [diff] [blame] | 655 | kSampleRate32kHz = 32000, |
| 656 | kSampleRate48kHz = 48000 |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 657 | }; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 658 | |
kwiberg | d59d3bb | 2016-09-13 07:49:33 -0700 | [diff] [blame] | 659 | // TODO(kwiberg): We currently need to support a compiler (Visual C++) that |
| 660 | // complains if we don't explicitly state the size of the array here. Remove |
| 661 | // the size when that's no longer the case. |
| 662 | static constexpr int kNativeSampleRatesHz[4] = { |
| 663 | kSampleRate8kHz, kSampleRate16kHz, kSampleRate32kHz, kSampleRate48kHz}; |
| 664 | static constexpr size_t kNumNativeSampleRates = |
| 665 | arraysize(kNativeSampleRatesHz); |
| 666 | static constexpr int kMaxNativeSampleRateHz = |
| 667 | kNativeSampleRatesHz[kNumNativeSampleRates - 1]; |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 668 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 669 | static const int kChunkSizeMs = 10; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 670 | }; |
| 671 | |
Mirko Bonadei | 3d25530 | 2018-10-11 10:50:45 +0200 | [diff] [blame] | 672 | class RTC_EXPORT AudioProcessingBuilder { |
Ivo Creusen | 5ec7e12 | 2017-12-22 11:35:59 +0100 | [diff] [blame] | 673 | public: |
| 674 | AudioProcessingBuilder(); |
| 675 | ~AudioProcessingBuilder(); |
| 676 | // The AudioProcessingBuilder takes ownership of the echo_control_factory. |
| 677 | AudioProcessingBuilder& SetEchoControlFactory( |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 678 | std::unique_ptr<EchoControlFactory> echo_control_factory) { |
| 679 | echo_control_factory_ = std::move(echo_control_factory); |
| 680 | return *this; |
| 681 | } |
Ivo Creusen | 5ec7e12 | 2017-12-22 11:35:59 +0100 | [diff] [blame] | 682 | // The AudioProcessingBuilder takes ownership of the capture_post_processing. |
| 683 | AudioProcessingBuilder& SetCapturePostProcessing( |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 684 | std::unique_ptr<CustomProcessing> capture_post_processing) { |
| 685 | capture_post_processing_ = std::move(capture_post_processing); |
| 686 | return *this; |
| 687 | } |
Ivo Creusen | 5ec7e12 | 2017-12-22 11:35:59 +0100 | [diff] [blame] | 688 | // The AudioProcessingBuilder takes ownership of the render_pre_processing. |
| 689 | AudioProcessingBuilder& SetRenderPreProcessing( |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 690 | std::unique_ptr<CustomProcessing> render_pre_processing) { |
| 691 | render_pre_processing_ = std::move(render_pre_processing); |
| 692 | return *this; |
| 693 | } |
Ivo Creusen | 09fa4b0 | 2018-01-11 16:08:54 +0100 | [diff] [blame] | 694 | // The AudioProcessingBuilder takes ownership of the echo_detector. |
| 695 | AudioProcessingBuilder& SetEchoDetector( |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 696 | rtc::scoped_refptr<EchoDetector> echo_detector) { |
| 697 | echo_detector_ = std::move(echo_detector); |
| 698 | return *this; |
| 699 | } |
Valeriia Nemychnikova | f06eb57 | 2018-08-29 10:37:09 +0200 | [diff] [blame] | 700 | // The AudioProcessingBuilder takes ownership of the capture_analyzer. |
| 701 | AudioProcessingBuilder& SetCaptureAnalyzer( |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 702 | std::unique_ptr<CustomAudioAnalyzer> capture_analyzer) { |
| 703 | capture_analyzer_ = std::move(capture_analyzer); |
| 704 | return *this; |
| 705 | } |
Ivo Creusen | 5ec7e12 | 2017-12-22 11:35:59 +0100 | [diff] [blame] | 706 | // This creates an APM instance using the previously set components. Calling |
| 707 | // the Create function resets the AudioProcessingBuilder to its initial state. |
| 708 | AudioProcessing* Create(); |
| 709 | AudioProcessing* Create(const webrtc::Config& config); |
| 710 | |
| 711 | private: |
| 712 | std::unique_ptr<EchoControlFactory> echo_control_factory_; |
| 713 | std::unique_ptr<CustomProcessing> capture_post_processing_; |
| 714 | std::unique_ptr<CustomProcessing> render_pre_processing_; |
Ivo Creusen | d1f970d | 2018-06-14 11:02:03 +0200 | [diff] [blame] | 715 | rtc::scoped_refptr<EchoDetector> echo_detector_; |
Valeriia Nemychnikova | f06eb57 | 2018-08-29 10:37:09 +0200 | [diff] [blame] | 716 | std::unique_ptr<CustomAudioAnalyzer> capture_analyzer_; |
Ivo Creusen | 5ec7e12 | 2017-12-22 11:35:59 +0100 | [diff] [blame] | 717 | RTC_DISALLOW_COPY_AND_ASSIGN(AudioProcessingBuilder); |
| 718 | }; |
| 719 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 720 | class StreamConfig { |
| 721 | public: |
| 722 | // sample_rate_hz: The sampling rate of the stream. |
| 723 | // |
| 724 | // num_channels: The number of audio channels in the stream, excluding the |
| 725 | // keyboard channel if it is present. When passing a |
| 726 | // StreamConfig with an array of arrays T*[N], |
| 727 | // |
| 728 | // N == {num_channels + 1 if has_keyboard |
| 729 | // {num_channels if !has_keyboard |
| 730 | // |
| 731 | // has_keyboard: True if the stream has a keyboard channel. When has_keyboard |
| 732 | // is true, the last channel in any corresponding list of |
| 733 | // channels is the keyboard channel. |
| 734 | StreamConfig(int sample_rate_hz = 0, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 735 | size_t num_channels = 0, |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 736 | bool has_keyboard = false) |
| 737 | : sample_rate_hz_(sample_rate_hz), |
| 738 | num_channels_(num_channels), |
| 739 | has_keyboard_(has_keyboard), |
| 740 | num_frames_(calculate_frames(sample_rate_hz)) {} |
| 741 | |
| 742 | void set_sample_rate_hz(int value) { |
| 743 | sample_rate_hz_ = value; |
| 744 | num_frames_ = calculate_frames(value); |
| 745 | } |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 746 | void set_num_channels(size_t value) { num_channels_ = value; } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 747 | void set_has_keyboard(bool value) { has_keyboard_ = value; } |
| 748 | |
| 749 | int sample_rate_hz() const { return sample_rate_hz_; } |
| 750 | |
| 751 | // The number of channels in the stream, not including the keyboard channel if |
| 752 | // present. |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 753 | size_t num_channels() const { return num_channels_; } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 754 | |
| 755 | bool has_keyboard() const { return has_keyboard_; } |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 756 | size_t num_frames() const { return num_frames_; } |
| 757 | size_t num_samples() const { return num_channels_ * num_frames_; } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 758 | |
| 759 | bool operator==(const StreamConfig& other) const { |
| 760 | return sample_rate_hz_ == other.sample_rate_hz_ && |
| 761 | num_channels_ == other.num_channels_ && |
| 762 | has_keyboard_ == other.has_keyboard_; |
| 763 | } |
| 764 | |
| 765 | bool operator!=(const StreamConfig& other) const { return !(*this == other); } |
| 766 | |
| 767 | private: |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 768 | static size_t calculate_frames(int sample_rate_hz) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 769 | return static_cast<size_t>(AudioProcessing::kChunkSizeMs * sample_rate_hz / |
| 770 | 1000); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | int sample_rate_hz_; |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 774 | size_t num_channels_; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 775 | bool has_keyboard_; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 776 | size_t num_frames_; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 777 | }; |
| 778 | |
| 779 | class ProcessingConfig { |
| 780 | public: |
| 781 | enum StreamName { |
| 782 | kInputStream, |
| 783 | kOutputStream, |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 784 | kReverseInputStream, |
| 785 | kReverseOutputStream, |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 786 | kNumStreamNames, |
| 787 | }; |
| 788 | |
| 789 | const StreamConfig& input_stream() const { |
| 790 | return streams[StreamName::kInputStream]; |
| 791 | } |
| 792 | const StreamConfig& output_stream() const { |
| 793 | return streams[StreamName::kOutputStream]; |
| 794 | } |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 795 | const StreamConfig& reverse_input_stream() const { |
| 796 | return streams[StreamName::kReverseInputStream]; |
| 797 | } |
| 798 | const StreamConfig& reverse_output_stream() const { |
| 799 | return streams[StreamName::kReverseOutputStream]; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | StreamConfig& input_stream() { return streams[StreamName::kInputStream]; } |
| 803 | StreamConfig& output_stream() { return streams[StreamName::kOutputStream]; } |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 804 | StreamConfig& reverse_input_stream() { |
| 805 | return streams[StreamName::kReverseInputStream]; |
| 806 | } |
| 807 | StreamConfig& reverse_output_stream() { |
| 808 | return streams[StreamName::kReverseOutputStream]; |
| 809 | } |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 810 | |
| 811 | bool operator==(const ProcessingConfig& other) const { |
| 812 | for (int i = 0; i < StreamName::kNumStreamNames; ++i) { |
| 813 | if (this->streams[i] != other.streams[i]) { |
| 814 | return false; |
| 815 | } |
| 816 | } |
| 817 | return true; |
| 818 | } |
| 819 | |
| 820 | bool operator!=(const ProcessingConfig& other) const { |
| 821 | return !(*this == other); |
| 822 | } |
| 823 | |
| 824 | StreamConfig streams[StreamName::kNumStreamNames]; |
| 825 | }; |
| 826 | |
Valeriia Nemychnikova | f06eb57 | 2018-08-29 10:37:09 +0200 | [diff] [blame] | 827 | // Experimental interface for a custom analysis submodule. |
| 828 | class CustomAudioAnalyzer { |
| 829 | public: |
| 830 | // (Re-) Initializes the submodule. |
| 831 | virtual void Initialize(int sample_rate_hz, int num_channels) = 0; |
| 832 | // Analyzes the given capture or render signal. |
| 833 | virtual void Analyze(const AudioBuffer* audio) = 0; |
| 834 | // Returns a string representation of the module state. |
| 835 | virtual std::string ToString() const = 0; |
| 836 | |
| 837 | virtual ~CustomAudioAnalyzer() {} |
| 838 | }; |
| 839 | |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 840 | // Interface for a custom processing submodule. |
| 841 | class CustomProcessing { |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 842 | public: |
| 843 | // (Re-)Initializes the submodule. |
| 844 | virtual void Initialize(int sample_rate_hz, int num_channels) = 0; |
| 845 | // Processes the given capture or render signal. |
| 846 | virtual void Process(AudioBuffer* audio) = 0; |
| 847 | // Returns a string representation of the module state. |
| 848 | virtual std::string ToString() const = 0; |
Alex Loiko | 73ec019 | 2018-05-15 10:52:28 +0200 | [diff] [blame] | 849 | // Handles RuntimeSettings. TODO(webrtc:9262): make pure virtual |
| 850 | // after updating dependencies. |
| 851 | virtual void SetRuntimeSetting(AudioProcessing::RuntimeSetting setting); |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 852 | |
Alex Loiko | 5825aa6 | 2017-12-18 16:02:40 +0100 | [diff] [blame] | 853 | virtual ~CustomProcessing() {} |
Sam Zackrisson | 0beac58 | 2017-09-25 12:04:02 +0200 | [diff] [blame] | 854 | }; |
| 855 | |
Ivo Creusen | 09fa4b0 | 2018-01-11 16:08:54 +0100 | [diff] [blame] | 856 | // Interface for an echo detector submodule. |
Ivo Creusen | d1f970d | 2018-06-14 11:02:03 +0200 | [diff] [blame] | 857 | class EchoDetector : public rtc::RefCountInterface { |
Ivo Creusen | 09fa4b0 | 2018-01-11 16:08:54 +0100 | [diff] [blame] | 858 | public: |
| 859 | // (Re-)Initializes the submodule. |
Ivo Creusen | 647ef09 | 2018-03-14 17:13:48 +0100 | [diff] [blame] | 860 | virtual void Initialize(int capture_sample_rate_hz, |
| 861 | int num_capture_channels, |
| 862 | int render_sample_rate_hz, |
| 863 | int num_render_channels) = 0; |
Ivo Creusen | 09fa4b0 | 2018-01-11 16:08:54 +0100 | [diff] [blame] | 864 | |
| 865 | // Analysis (not changing) of the render signal. |
| 866 | virtual void AnalyzeRenderAudio(rtc::ArrayView<const float> render_audio) = 0; |
| 867 | |
| 868 | // Analysis (not changing) of the capture signal. |
| 869 | virtual void AnalyzeCaptureAudio( |
| 870 | rtc::ArrayView<const float> capture_audio) = 0; |
| 871 | |
| 872 | // Pack an AudioBuffer into a vector<float>. |
| 873 | static void PackRenderAudioBuffer(AudioBuffer* audio, |
| 874 | std::vector<float>* packed_buffer); |
| 875 | |
| 876 | struct Metrics { |
Ivo Creusen | bb826c9 | 2020-04-29 14:34:48 +0200 | [diff] [blame] | 877 | absl::optional<double> echo_likelihood; |
| 878 | absl::optional<double> echo_likelihood_recent_max; |
Ivo Creusen | 09fa4b0 | 2018-01-11 16:08:54 +0100 | [diff] [blame] | 879 | }; |
| 880 | |
| 881 | // Collect current metrics from the echo detector. |
| 882 | virtual Metrics GetMetrics() const = 0; |
Ivo Creusen | 09fa4b0 | 2018-01-11 16:08:54 +0100 | [diff] [blame] | 883 | }; |
| 884 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 885 | } // namespace webrtc |
| 886 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 887 | #endif // MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_PROCESSING_H_ |