Skip to main content

Tween

Struct Tween 

Source
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

Source

pub const IMMEDIATE: Tween

Jump to the target immediately (no ramp).

Source

pub const fn frames(n: u32) -> Self

Ramp over an explicit number of frames.

Source

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§

Source§

impl Clone for Tween

Source§

fn clone(&self) -> Tween

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Tween

Source§

impl Debug for Tween

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tween

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more