pub struct Smoother<T: Smoothable> {
    pub style: SmoothingStyle,
    /* private fields */
}
Expand description

A smoother, providing a smoothed value for each sample.

Fields§

§style: SmoothingStyle

The kind of snoothing that needs to be applied, if any.

Implementations§

source§

impl<T: Smoothable> Smoother<T>

source

pub fn new(style: SmoothingStyle) -> Self

Use the specified style for the smoothing.

source

pub fn none() -> Self

Convenience function for not applying any smoothing at all. Same as Smoother::default.

source

pub fn steps_left(&self) -> i32

The number of steps left until calling next() will stop yielding new values.

source

pub fn is_smoothing(&self) -> bool

Whether calling next() will yield a new value or an old value. Useful if you need to recompute something whenever this parameter changes.

source

pub fn iter(&self) -> SmootherIter<'_, T>

Produce an iterator that yields smoothed values. These are not iterators already for the sole reason that this will always yield a value, and needing to unwrap all of those options is not going to be very fun.

source

pub fn reset(&self, value: T)

Reset the smoother the specified value.

source

pub fn set_target(&self, sample_rate: f32, target: T)

Set the target value.

source

pub fn next(&self) -> T

Get the next value from this smoother. The value will be equal to the previous value once the smoothing period is over. This should be called exactly once per sample.

source

pub fn next_step(&self, steps: u32) -> T

next(), but with the ability to skip forward in the smoother. next() is equivalent to calling this function with a steps value of 1. Calling this function with a steps value of n means will cause you to skip the next n - 1 values and return the nth value.

source

pub fn previous_value(&self) -> T

Get previous value returned by this smoother. This may be useful to save some boilerplate when is_smoothing() is used to determine whether an expensive calculation should take place, and next() gets called as part of that calculation.

source

pub fn next_block(&self, block_values: &mut [T], block_len: usize)

Produce smoothed values for an entire block of audio. This is useful when iterating the same block of audio multiple times. For instance when summing voices for a synthesizer. block_values[..block_len] will be filled with the smoothed values. This is simply a convenient function for next_block_exact() when iterating over variable length blocks with a known maximum size.

Panics

Panics if block_len > block_values.len().

source

pub fn next_block_exact(&self, block_values: &mut [T])

The same as next_block(), but filling the entire slice.

source

pub fn next_block_mapped( &self, block_values: &mut [T], block_len: usize, f: impl FnMut(usize, f32) -> T )

The same as next_block(), but with a function applied to each produced value. The mapping function takes an index in the block and a floating point representation of the smoother’s current value. This allows the modulation to be consistent during smoothing. Additionally, the mapping function is always called even if the smoothing is finished.

source

pub fn next_block_exact_mapped( &self, block_values: &mut [T], f: impl FnMut(usize, f32) -> T )

The same as next_block_exact(), but with a function applied to each produced value. Useful when applying modulation to a smoothed parameter.

Trait Implementations§

source§

impl<T: Smoothable> Clone for Smoother<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Smoothable> Debug for Smoother<T>where T::Atomic: Debug,

source§

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

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

impl<T: Smoothable> Default for Smoother<T>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Smoother<T>

§

impl<T> Send for Smoother<T>where <T as Smoothable>::Atomic: Send,

§

impl<T> Sync for Smoother<T>where <T as Smoothable>::Atomic: Sync,

§

impl<T> Unpin for Smoother<T>where <T as Smoothable>::Atomic: Unpin,

§

impl<T> !UnwindSafe for Smoother<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T, U> Into<U> for Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

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
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> Any for Twhere T: Any,

§

impl<T> CloneAny for Twhere T: Any + Clone,

§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,