#[derive(Debug, Clone, Default)]
pub struct Config {
pub pipeline: Pipeline,
pub pre_amplifier: Option<PreAmplifier>,
pub capture_level_adjustment: Option<CaptureLevelAdjustment>,
pub high_pass_filter: Option<HighPassFilter>,
pub echo_canceller: Option<EchoCanceller>,
pub noise_suppression: Option<NoiseSuppression>,
pub gain_controller2: Option<GainController2>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MaxProcessingRate {
Rate32kHz,
Rate48kHz,
}
impl MaxProcessingRate {
pub fn as_hz(self) -> u32 {
match self {
Self::Rate32kHz => 32000,
Self::Rate48kHz => 48000,
}
}
}
#[derive(Debug, Clone)]
pub struct Pipeline {
pub maximum_internal_processing_rate: MaxProcessingRate,
pub multi_channel_render: bool,
pub multi_channel_capture: bool,
pub capture_downmix_method: DownmixMethod,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DownmixMethod {
AverageChannels,
UseFirstChannel,
}
impl Default for Pipeline {
fn default() -> Self {
Self {
maximum_internal_processing_rate: MaxProcessingRate::Rate32kHz,
multi_channel_render: false,
multi_channel_capture: false,
capture_downmix_method: DownmixMethod::AverageChannels,
}
}
}
#[derive(Debug, Clone)]
pub struct PreAmplifier {
pub fixed_gain_factor: f32,
}
impl Default for PreAmplifier {
fn default() -> Self {
Self {
fixed_gain_factor: 1.0,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct CaptureLevelAdjustment {
pub pre_gain_factor: f32,
pub post_gain_factor: f32,
pub analog_mic_gain_emulation: Option<AnalogMicGainEmulation>,
}
impl Default for CaptureLevelAdjustment {
fn default() -> Self {
Self {
pre_gain_factor: 1.0,
post_gain_factor: 1.0,
analog_mic_gain_emulation: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AnalogMicGainEmulation {
pub initial_level: u8,
}
impl Default for AnalogMicGainEmulation {
fn default() -> Self {
Self { initial_level: 255 }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HighPassFilter {
pub apply_in_full_band: bool,
}
impl Default for HighPassFilter {
fn default() -> Self {
Self {
apply_in_full_band: true,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EchoCanceller {
pub enforce_high_pass_filtering: bool,
pub transparent_mode: TransparentModeType,
}
impl Default for EchoCanceller {
fn default() -> Self {
Self {
enforce_high_pass_filtering: true,
transparent_mode: TransparentModeType::default(),
}
}
}
pub use sonora_aec3::config::TransparentModeType;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NoiseSuppression {
pub level: NoiseSuppressionLevel,
pub analyze_linear_aec_output_when_available: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NoiseSuppressionLevel {
Low,
Moderate,
High,
VeryHigh,
}
impl Default for NoiseSuppression {
fn default() -> Self {
Self {
level: NoiseSuppressionLevel::Moderate,
analyze_linear_aec_output_when_available: false,
}
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct GainController2 {
pub input_volume_controller: bool,
pub adaptive_digital: Option<AdaptiveDigital>,
pub fixed_digital: FixedDigital,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AdaptiveDigital {
pub headroom_db: f32,
pub max_gain_db: f32,
pub initial_gain_db: f32,
pub max_gain_change_db_per_second: f32,
pub max_output_noise_level_dbfs: f32,
}
impl Default for AdaptiveDigital {
fn default() -> Self {
Self {
headroom_db: 5.0,
max_gain_db: 50.0,
initial_gain_db: 15.0,
max_gain_change_db_per_second: 6.0,
max_output_noise_level_dbfs: -50.0,
}
}
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct FixedDigital {
pub gain_db: f32,
}
#[derive(Debug, Clone)]
pub(crate) enum RuntimeSetting {
CapturePreGain(f32),
CapturePostGain(f32),
CaptureFixedPostGain(f32),
PlayoutVolumeChange(i32),
PlayoutAudioDeviceChange(PlayoutAudioDeviceInfo),
CaptureOutputUsed(bool),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct PlayoutAudioDeviceInfo {
pub id: i32,
pub max_volume: i32,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn capture_level_adjustment_equality() {
let a = CaptureLevelAdjustment::default();
let mut b = a.clone();
assert_eq!(a, b);
b.pre_gain_factor = 2.0;
assert_ne!(a, b);
}
#[test]
fn max_processing_rate_as_hz() {
assert_eq!(MaxProcessingRate::Rate32kHz.as_hz(), 32000);
assert_eq!(MaxProcessingRate::Rate48kHz.as_hz(), 48000);
}
}