vibe/animation/families/
acoustic.rs1use crate::animation::pga::Motor;
4use crate::animation::presets::AnimationSample;
5
6pub fn eval(preset: &str, t: f64) -> AnimationSample {
8 match preset {
9 "adsr_pulse" | "adsr" => {
10 let (a, d, s, r) = (0.1, 0.2, 0.6, 0.4);
11 let total = a + d + 0.5 + r;
12 let cycle = t % total;
13 let amp = if cycle < a {
14 cycle / a
15 } else if cycle < a + d {
16 1.0 - (1.0 - s) * ((cycle - a) / d)
17 } else if cycle < a + d + 0.5 {
18 s
19 } else {
20 s * (1.0 - (cycle - a - d - 0.5) / r)
21 };
22 AnimationSample {
23 scalar: amp,
24 vector: [amp, amp, amp],
25 motor: Motor::identity(),
26 secondary: cycle,
27 settled: false,
28 }
29 }
30 "binaural_sweep" => {
31 let pan = (t * 1.5).sin(); let left = ((1.0 - pan) * 0.5).sqrt();
33 let right = ((1.0 + pan) * 0.5).sqrt();
34 AnimationSample {
35 scalar: pan,
36 vector: [left, 0.0, right],
37 motor: Motor::from_translation(pan * 2.0, 0.0, 0.0),
38 secondary: pan.abs(),
39 settled: false,
40 }
41 }
42 "resonant_formant" => {
43 let f1 = 500.0 + (t * 2.0).sin() * 300.0;
44 let f2 = 1500.0 + (t * 3.0).cos() * 500.0;
45 AnimationSample {
46 scalar: f1,
47 vector: [f1 / 1000.0, f2 / 2000.0, 0.0],
48 motor: Motor::identity(),
49 secondary: f2,
50 settled: false,
51 }
52 }
53 _ => AnimationSample::default(),
54 }
55}