Skip to main content

rill_core_model/cavity/
params.rs

1use rill_core::Transcendental;
2
3/// Parameters for a single Helmholtz cavity resonator.
4#[derive(Debug, Clone)]
5pub struct HelmholtzParams<T: Transcendental> {
6    /// Cavity volume in m³ (e.g., 0.001 for 1 liter).
7    pub volume: T,
8    /// Neck cross-sectional area in m².
9    pub neck_area: T,
10    /// Neck length in m.
11    pub neck_length: T,
12    /// Speed of sound in m/s (343.0 default).
13    pub sound_speed: T,
14    /// Radiation loss coefficient (0.0–1.0).
15    pub radiation_loss: T,
16    /// Viscous loss coefficient (0.0–1.0).
17    pub viscous_loss: T,
18    /// Excitation type: 0 = filter (no self-oscillation), 1 = reed.
19    pub excitation: u8,
20    /// Mouth pressure for reed excitation (0.0–1.0).
21    pub pressure: T,
22}
23
24impl<T: Transcendental> Default for HelmholtzParams<T> {
25    fn default() -> Self {
26        Self {
27            volume: T::from_f64(0.001),
28            neck_area: T::from_f64(0.0001),
29            neck_length: T::from_f64(0.02),
30            sound_speed: T::from_f64(343.0),
31            radiation_loss: T::from_f64(0.01),
32            viscous_loss: T::from_f64(0.005),
33            excitation: 0,
34            pressure: T::ZERO,
35        }
36    }
37}
38
39/// Parameters for a 1D array of coupled Helmholtz cavities.
40#[derive(Debug, Clone)]
41pub struct CavityArrayParams<T: Transcendental> {
42    /// Number of active cavities (1–MAX_CAVITIES).
43    pub num_cavities: usize,
44    /// Per-cavity Helmholtz parameters.
45    pub cavity_params: HelmholtzParams<T>,
46    /// Nearest-neighbor coupling strength (0.0–1.0).
47    pub coupling: T,
48    /// Input position index (0 to N-1).
49    pub input_index: usize,
50    /// Output position index (0 to N-1).
51    pub output_index: usize,
52}
53
54impl<T: Transcendental> Default for CavityArrayParams<T> {
55    fn default() -> Self {
56        Self {
57            num_cavities: 4,
58            cavity_params: HelmholtzParams::default(),
59            coupling: T::from_f64(0.1),
60            input_index: 0,
61            output_index: 3,
62        }
63    }
64}