sva_formula/modal/
string.rs1use crate::closed_form::Mode;
4use crate::modal::damping::Damping;
5use crate::modal::mode;
6
7pub struct StringGeom {
8 pub f0: f64,
9 pub inharmonicity: f64,
10 pub strike: f64,
11 pub damping: Damping,
12}
13
14pub fn inharmonicity(young: f64, diameter: f64, tension: f64, length: f64) -> f64 {
16 std::f64::consts::PI.powi(3) * young * diameter.powi(4) / (64.0 * tension * length * length)
17}
18
19pub fn modes(g: &StringGeom, count: usize) -> Vec<Mode> {
21 (1..=count)
22 .map(|n| {
23 let n = n as f64;
24 let hz = n * g.f0 * (1.0 + g.inharmonicity * n * n).sqrt();
25 let amp = (n * std::f64::consts::PI * g.strike).sin() / (n * n);
26 mode(hz, amp, g.damping)
27 })
28 .collect()
29}