pub struct Tween { /* private fields */ }Expand description
Control-rate linear smoothing over a fixed duration. Tween::default() /
Tween::IMMEDIATE jumps instantly; Tween::ms ramps over a wall-clock time.
Implementations§
Source§impl Tween
impl Tween
Sourcepub fn ms(ms: f32, sample_rate: u32) -> Self
pub fn ms(ms: f32, sample_rate: u32) -> Self
Ramp over ms milliseconds at sample_rate.
Examples found in repository?
examples/runtime_mixer.rs (line 31)
21fn main() {
22 let sr = 48_000;
23
24 // --- Direct (single-threaded) use -------------------------------------
25 let mut engine = Engine::new(sr);
26 let patch = engine.load(&blip());
27
28 // One patch → several independent instances, each controlled by handle.
29 let a = engine.play_looping(patch);
30 let b = engine.play_looping(patch);
31 engine.set_gain(b, 0.5, Tween::ms(20.0, sr));
32 engine.set_pan(a, -0.7, Tween::ms(20.0, sr));
33 engine.set_pan(b, 0.7, Tween::ms(20.0, sr));
34
35 let mut block = vec![0.0f32; 512 * 2];
36 let mut p = 0.0f32;
37 for _ in 0..20 {
38 engine.fill(&mut block);
39 p = p.max(peak(&block));
40 }
41 println!("direct mix: {} instances, peak {p:.3}", engine.active());
42
43 // --- Split (control thread + audio thread) ----------------------------
44 let mut engine = Engine::new(sr);
45 let patch = engine.load(&blip());
46 let (mut control, mut audio) = engine.split(2048);
47 control.play_looping(patch); // Deref → Engine::play_looping
48
49 control.pump(2048); // control thread: keep the ring fed
50 let mut out = vec![0.0f32; 512 * 2];
51 let frames = audio.fill(&mut out); // audio thread: drain in the callback
52 println!("split mix: pulled {frames} frames, peak {:.3}", peak(&out));
53}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Tween
impl RefUnwindSafe for Tween
impl Send for Tween
impl Sync for Tween
impl Unpin for Tween
impl UnsafeUnpin for Tween
impl UnwindSafe for Tween
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more