1use webrtc_audio_processing_sys as ffi;
2
3pub use ffi::InitializationConfig;
4
5#[cfg(feature = "derive_serde")]
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Copy, Clone, PartialEq)]
10#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
11pub enum EchoCancellationSuppressionLevel {
12 Lowest,
15 Lower,
18 Low,
21 Moderate,
24 High,
27}
28
29impl From<EchoCancellationSuppressionLevel> for ffi::EchoCancellation_SuppressionLevel {
30 fn from(other: EchoCancellationSuppressionLevel) -> ffi::EchoCancellation_SuppressionLevel {
31 match other {
32 EchoCancellationSuppressionLevel::Lowest => {
33 ffi::EchoCancellation_SuppressionLevel::LOWEST
34 },
35 EchoCancellationSuppressionLevel::Lower => {
36 ffi::EchoCancellation_SuppressionLevel::LOWER
37 },
38 EchoCancellationSuppressionLevel::Low => ffi::EchoCancellation_SuppressionLevel::LOW,
39 EchoCancellationSuppressionLevel::Moderate => {
40 ffi::EchoCancellation_SuppressionLevel::MODERATE
41 },
42 EchoCancellationSuppressionLevel::High => ffi::EchoCancellation_SuppressionLevel::HIGH,
43 }
44 }
45}
46
47#[derive(Debug, Clone, PartialEq)]
49#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
50pub struct EchoCancellation {
51 pub suppression_level: EchoCancellationSuppressionLevel,
54
55 pub enable_extended_filter: bool,
60
61 pub enable_delay_agnostic: bool,
65
66 pub stream_delay_ms: Option<i32>,
72}
73
74impl From<EchoCancellation> for ffi::EchoCancellation {
75 fn from(other: EchoCancellation) -> ffi::EchoCancellation {
76 ffi::EchoCancellation {
77 enable: true,
78 suppression_level: other.suppression_level.into(),
79 enable_extended_filter: other.enable_extended_filter,
80 enable_delay_agnostic: other.enable_delay_agnostic,
81 stream_delay_ms: other.stream_delay_ms.into(),
82 }
83 }
84}
85
86#[derive(Debug, Copy, Clone, PartialEq)]
88#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
89pub enum GainControlMode {
90 AdaptiveDigital,
94
95 FixedDigital,
100}
101
102impl From<GainControlMode> for ffi::GainControl_Mode {
103 fn from(other: GainControlMode) -> ffi::GainControl_Mode {
104 match other {
105 GainControlMode::AdaptiveDigital => ffi::GainControl_Mode::ADAPTIVE_DIGITAL,
106 GainControlMode::FixedDigital => ffi::GainControl_Mode::FIXED_DIGITAL,
107 }
108 }
109}
110
111#[derive(Debug, Clone, PartialEq)]
113#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
114pub struct GainControl {
115 pub mode: GainControlMode,
117
118 pub target_level_dbfs: i32,
123
124 pub compression_gain_db: i32,
128
129 pub enable_limiter: bool,
133}
134
135impl From<GainControl> for ffi::GainControl {
136 fn from(other: GainControl) -> ffi::GainControl {
137 ffi::GainControl {
138 enable: true,
139 mode: other.mode.into(),
140 target_level_dbfs: other.target_level_dbfs,
141 compression_gain_db: other.compression_gain_db,
142 enable_limiter: other.enable_limiter,
143 }
144 }
145}
146
147#[derive(Debug, Copy, Clone, PartialEq)]
149#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
150pub enum NoiseSuppressionLevel {
151 Low,
153 Moderate,
155 High,
157 VeryHigh,
159}
160
161impl From<NoiseSuppressionLevel> for ffi::NoiseSuppression_SuppressionLevel {
162 fn from(other: NoiseSuppressionLevel) -> ffi::NoiseSuppression_SuppressionLevel {
163 match other {
164 NoiseSuppressionLevel::Low => ffi::NoiseSuppression_SuppressionLevel::LOW,
165 NoiseSuppressionLevel::Moderate => ffi::NoiseSuppression_SuppressionLevel::MODERATE,
166 NoiseSuppressionLevel::High => ffi::NoiseSuppression_SuppressionLevel::HIGH,
167 NoiseSuppressionLevel::VeryHigh => ffi::NoiseSuppression_SuppressionLevel::VERY_HIGH,
168 }
169 }
170}
171
172#[derive(Debug, Clone, PartialEq)]
174#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
175pub struct NoiseSuppression {
176 pub suppression_level: NoiseSuppressionLevel,
179}
180
181impl From<NoiseSuppression> for ffi::NoiseSuppression {
182 fn from(other: NoiseSuppression) -> ffi::NoiseSuppression {
183 ffi::NoiseSuppression { enable: true, suppression_level: other.suppression_level.into() }
184 }
185}
186
187#[derive(Debug, Copy, Clone, PartialEq)]
189#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
190pub enum VoiceDetectionLikelihood {
191 VeryLow,
193 Low,
195 Moderate,
197 High,
199}
200
201impl From<VoiceDetectionLikelihood> for ffi::VoiceDetection_DetectionLikelihood {
202 fn from(other: VoiceDetectionLikelihood) -> ffi::VoiceDetection_DetectionLikelihood {
203 match other {
204 VoiceDetectionLikelihood::VeryLow => ffi::VoiceDetection_DetectionLikelihood::VERY_LOW,
205 VoiceDetectionLikelihood::Low => ffi::VoiceDetection_DetectionLikelihood::LOW,
206 VoiceDetectionLikelihood::Moderate => ffi::VoiceDetection_DetectionLikelihood::MODERATE,
207 VoiceDetectionLikelihood::High => ffi::VoiceDetection_DetectionLikelihood::HIGH,
208 }
209 }
210}
211
212#[derive(Debug, Clone, PartialEq)]
214#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
215pub struct VoiceDetection {
216 pub detection_likelihood: VoiceDetectionLikelihood,
220}
221
222impl From<VoiceDetection> for ffi::VoiceDetection {
223 fn from(other: VoiceDetection) -> ffi::VoiceDetection {
224 ffi::VoiceDetection {
225 enable: true,
226 detection_likelihood: other.detection_likelihood.into(),
227 }
228 }
229}
230
231#[derive(Debug, Default, Clone, PartialEq)]
233#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
234pub struct Config {
235 pub echo_cancellation: Option<EchoCancellation>,
237
238 pub gain_control: Option<GainControl>,
240
241 pub noise_suppression: Option<NoiseSuppression>,
243
244 pub voice_detection: Option<VoiceDetection>,
246
247 #[cfg_attr(feature = "derive_serde", serde(default))]
249 pub enable_transient_suppressor: bool,
250
251 #[cfg_attr(feature = "derive_serde", serde(default))]
254 pub enable_high_pass_filter: bool,
255}
256
257impl From<Config> for ffi::Config {
258 fn from(other: Config) -> ffi::Config {
259 let echo_cancellation = if let Some(enabled_value) = other.echo_cancellation {
260 enabled_value.into()
261 } else {
262 ffi::EchoCancellation { enable: false, ..ffi::EchoCancellation::default() }
263 };
264
265 let gain_control = if let Some(enabled_value) = other.gain_control {
266 enabled_value.into()
267 } else {
268 ffi::GainControl { enable: false, ..ffi::GainControl::default() }
269 };
270
271 let noise_suppression = if let Some(enabled_value) = other.noise_suppression {
272 enabled_value.into()
273 } else {
274 ffi::NoiseSuppression { enable: false, ..ffi::NoiseSuppression::default() }
275 };
276
277 let voice_detection = if let Some(enabled_value) = other.voice_detection {
278 enabled_value.into()
279 } else {
280 ffi::VoiceDetection { enable: false, ..ffi::VoiceDetection::default() }
281 };
282
283 ffi::Config {
284 echo_cancellation,
285 gain_control,
286 noise_suppression,
287 voice_detection,
288 enable_transient_suppressor: other.enable_transient_suppressor,
289 enable_high_pass_filter: other.enable_high_pass_filter,
290 }
291 }
292}
293
294#[derive(Debug, Clone)]
296#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
297pub struct Stats {
298 pub has_voice: Option<bool>,
300
301 pub has_echo: Option<bool>,
304
305 pub rms_dbfs: Option<i32>,
310
311 pub speech_probability: Option<f64>,
314
315 pub residual_echo_return_loss: Option<f64>,
317
318 pub echo_return_loss: Option<f64>,
320
321 pub echo_return_loss_enhancement: Option<f64>,
323
324 pub a_nlp: Option<f64>,
326
327 pub delay_median_ms: Option<i32>,
331
332 pub delay_standard_deviation_ms: Option<i32>,
336
337 pub delay_fraction_poor_delays: Option<f64>,
340}
341
342impl From<ffi::Stats> for Stats {
343 fn from(other: ffi::Stats) -> Stats {
344 Stats {
345 has_voice: other.has_voice.into(),
346 has_echo: other.has_echo.into(),
347 rms_dbfs: other.rms_dbfs.into(),
348 speech_probability: other.speech_probability.into(),
349 residual_echo_return_loss: other.residual_echo_return_loss.into(),
350 echo_return_loss: other.echo_return_loss.into(),
351 echo_return_loss_enhancement: other.echo_return_loss_enhancement.into(),
352 a_nlp: other.a_nlp.into(),
353 delay_median_ms: other.delay_median_ms.into(),
354 delay_standard_deviation_ms: other.delay_standard_deviation_ms.into(),
355 delay_fraction_poor_delays: other.delay_fraction_poor_delays.into(),
356 }
357 }
358}