roomeq-model 0.5.5

RoomEQ configuration, pipeline, and DSP-chain contracts
Documentation
use super::default::default_gd_ap_max_q;
use super::default::default_gd_ap_min_q;
use super::default::default_gd_ap_per_channel;
use super::default::default_gd_coherence_threshold;
use super::default::default_gd_max_delay_ms;
use super::default::default_gd_max_iter;
use super::default::default_gd_min_improvement_db;
use super::default::default_gd_popsize;
use super::default::default_gd_tol;
use super::default::default_true;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// Group-delay optimization configuration.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct GroupDelayOptimizationConfig {
    /// Enable GD optimization and apply the resulting phase-only DSP.
    #[serde(default)]
    pub enabled: bool,
    /// Maximum per-channel delay in ms.
    #[serde(default = "default_gd_max_delay_ms")]
    pub max_delay_ms: f64,
    /// Maximum all-pass filters per channel. Production may downgrade this to
    /// zero when bootstrap evidence is unavailable.
    #[serde(default = "default_gd_ap_per_channel")]
    pub ap_per_channel: usize,
    /// Minimum all-pass Q.
    #[serde(default = "default_gd_ap_min_q")]
    pub ap_min_q: f64,
    /// Maximum all-pass Q.
    #[serde(default = "default_gd_ap_max_q")]
    pub ap_max_q: f64,
    /// Whether polarity may be optimized when coherence is present.
    #[serde(default = "default_true")]
    pub optimize_polarity: bool,
    /// Minimum in-band mean coherence for polarity/AP optimization.
    #[serde(default = "default_gd_coherence_threshold")]
    pub coherence_threshold: f64,
    /// Minimum improvement required before applying GD DSP.
    #[serde(default = "default_gd_min_improvement_db")]
    pub min_improvement_db: f64,
    /// DE maximum iterations.
    #[serde(default = "default_gd_max_iter")]
    pub max_iter: usize,
    /// DE population size multiplier.
    #[serde(default = "default_gd_popsize")]
    pub popsize: usize,
    /// DE convergence tolerance.
    #[serde(default = "default_gd_tol")]
    pub tol: f64,
    /// Require adaptive AP bootstrap before emitting all-pass filters.
    #[serde(default = "default_true")]
    pub adaptive_allpass: bool,
}

impl Default for GroupDelayOptimizationConfig {
    fn default() -> Self {
        Self {
            enabled: false,
            max_delay_ms: default_gd_max_delay_ms(),
            ap_per_channel: default_gd_ap_per_channel(),
            ap_min_q: default_gd_ap_min_q(),
            ap_max_q: default_gd_ap_max_q(),
            optimize_polarity: true,
            coherence_threshold: default_gd_coherence_threshold(),
            min_improvement_db: default_gd_min_improvement_db(),
            max_iter: default_gd_max_iter(),
            popsize: default_gd_popsize(),
            tol: default_gd_tol(),
            adaptive_allpass: true,
        }
    }
}