pub struct Smoothed<T> { /* private fields */ }
Expand description
Helper to linearly ramp a parameter towards a target value
Useful for implementing filters like Gain
which have dynamic parameters, where
applying changes to parameters directly would cause unpleasant artifacts such as popping.
Example
let mut value = oddio::Smoothed::new(0.0);
assert_eq!(value.get(), 0.0);
// Changes only take effect after time passes
value.set(1.0);
assert_eq!(value.get(), 0.0);
value.advance(0.5);
assert_eq!(value.get(), 0.5);
// A new value can be supplied mid-interpolation without causing a discontinuity
value.set(1.5);
value.advance(0.5);
assert_eq!(value.get(), 1.0);
value.advance(0.5);
assert_eq!(value.get(), 1.5);
// Interpolation halts once the target value is reached
value.advance(0.5);
assert_eq!(value.get(), 1.5);
Implementations§
source§impl<T> Smoothed<T>
impl<T> Smoothed<T>
sourcepub fn advance(&mut self, proportion: f32)
pub fn advance(&mut self, proportion: f32)
Advance interpolation by proportion
. For example, to advance at a fixed sample rate over a
particular smoothing period, pass sample_interval / smoothing_period
.
sourcepub fn set(&mut self, value: T)where
T: Interpolate,
pub fn set(&mut self, value: T)where
T: Interpolate,
Set the next value to x
sourcepub fn get(&self) -> Twhere
T: Interpolate,
pub fn get(&self) -> Twhere
T: Interpolate,
Get the current value
Trait Implementations§
impl<T: Copy> Copy for Smoothed<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for Smoothed<T>where
T: RefUnwindSafe,
impl<T> Send for Smoothed<T>where
T: Send,
impl<T> Sync for Smoothed<T>where
T: Sync,
impl<T> Unpin for Smoothed<T>where
T: Unpin,
impl<T> UnwindSafe for Smoothed<T>where
T: UnwindSafe,
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