use std::ops::{Deref, DerefMut};
use webrtc_audio_processing_sys as ffi;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(default))]
pub struct EchoCanceller3Config(ffi::EchoCanceller3Config);
impl EchoCanceller3Config {
pub fn multichannel_default() -> Self {
Self(unsafe { ffi::create_multichannel_aec3_config() })
}
pub fn validate(&mut self) -> bool {
unsafe { ffi::validate_aec3_config(&raw mut self.0) }
}
}
impl Default for EchoCanceller3Config {
fn default() -> Self {
Self(unsafe { ffi::create_aec3_config() })
}
}
impl Deref for EchoCanceller3Config {
type Target = ffi::EchoCanceller3Config;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for EchoCanceller3Config {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
pub use ffi::{
EchoCanceller3Config_Buffering, EchoCanceller3Config_ComfortNoise, EchoCanceller3Config_Delay,
EchoCanceller3Config_Delay_AlignmentMixing,
EchoCanceller3Config_Delay_DelaySelectionThresholds, EchoCanceller3Config_EchoAudibility,
EchoCanceller3Config_EchoModel, EchoCanceller3Config_EchoRemovalControl,
EchoCanceller3Config_EpStrength, EchoCanceller3Config_Erle, EchoCanceller3Config_Filter,
EchoCanceller3Config_Filter_CoarseConfiguration,
EchoCanceller3Config_Filter_RefinedConfiguration, EchoCanceller3Config_MultiChannel,
EchoCanceller3Config_RenderLevels, EchoCanceller3Config_Suppressor,
EchoCanceller3Config_Suppressor_DominantNearendDetection,
EchoCanceller3Config_Suppressor_HighBandsSuppression,
EchoCanceller3Config_Suppressor_MaskingThresholds,
EchoCanceller3Config_Suppressor_SubbandNearendDetection,
EchoCanceller3Config_Suppressor_SubbandNearendDetection_SubbandRegion,
EchoCanceller3Config_Suppressor_Tuning,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn aec3_config_default() {
let default_aec3_config = EchoCanceller3Config::default();
assert_eq!(8, default_aec3_config.buffering.max_allowed_excess_render_blocks);
assert!(default_aec3_config.delay.detect_pre_echo);
assert_eq!(1.0, default_aec3_config.erle.min);
}
#[test]
fn test_aec3_config_validation() {
let mut aec3_config = EchoCanceller3Config::default();
assert!(aec3_config.validate(), "Default config should be valid");
aec3_config.erle.min = 5.0;
aec3_config.erle.max_l = 4.0;
assert!(!aec3_config.validate(), "Config with min ERLE > max ERLE should be invalid");
}
}