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>
impl<T: Smoothable> Smoother<T>
sourcepub fn new(style: SmoothingStyle) -> Self
pub fn new(style: SmoothingStyle) -> Self
Use the specified style for the smoothing.
sourcepub fn none() -> Self
pub fn none() -> Self
Convenience function for not applying any smoothing at all. Same as Smoother::default
.
sourcepub fn steps_left(&self) -> i32
pub fn steps_left(&self) -> i32
The number of steps left until calling next()
will stop yielding new
values.
sourcepub fn is_smoothing(&self) -> bool
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.
sourcepub fn iter(&self) -> SmootherIter<'_, T> ⓘ
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.
sourcepub fn set_target(&self, sample_rate: f32, target: T)
pub fn set_target(&self, sample_rate: f32, target: T)
Set the target value.
sourcepub fn next(&self) -> T
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.
sourcepub fn previous_value(&self) -> T
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.
sourcepub fn next_block(&self, block_values: &mut [T], block_len: usize)
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()
.
sourcepub fn next_block_exact(&self, block_values: &mut [T])
pub fn next_block_exact(&self, block_values: &mut [T])
The same as next_block()
, but filling the entire slice.
sourcepub fn next_block_mapped(
&self,
block_values: &mut [T],
block_len: usize,
f: impl FnMut(usize, f32) -> T
)
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.
sourcepub fn next_block_exact_mapped(
&self,
block_values: &mut [T],
f: impl FnMut(usize, f32) -> T
)
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.