Enum nih_plug::params::smoothing::SmoothingStyle
source · pub enum SmoothingStyle {
OversamplingAware(Arc<AtomicF32>, &'static SmoothingStyle),
None,
Linear(f32),
Logarithmic(f32),
Exponential(f32),
}
Expand description
Controls if and how parameters gets smoothed.
Variants§
OversamplingAware(Arc<AtomicF32>, &'static SmoothingStyle)
Wraps another smoothing style to create a multi-rate oversampling-aware smoother for a
parameter that’s used in an oversampled part of the plugin. The Arc<AtomicF32>
indicates
the oversampling amount, where 1.0
means no oversampling. This value can change at
runtime, and it effectively scales the sample rate when computing new smoothing coefficients
when the parameter’s value changes.
None
No smoothing is applied. The parameter’s value
field contains the latest sample value
available for the parameters.
Linear(f32)
Smooth parameter changes so the current value approaches the target value at a constant rate. The target value will be reached in exactly this many milliseconds.
Logarithmic(f32)
Smooth parameter changes such that the rate matches the curve of a logarithmic function, starting out slow and then constantly increasing the slope until the value is reached. The target value will be reached in exactly this many milliseconds. This is useful for smoothing things like frequencies and decibel gain value. The caveat is that the value may never reach 0, or you will end up multiplying and dividing things by zero. Make sure your value ranges don’t include 0.
Exponential(f32)
Smooth parameter changes such that the rate matches the curve of an exponential function,
starting out fast and then tapering off until the end. This is a single-pole IIR filter
under the hood, while the other smoothing options are FIR filters. This means that the exact
value would never be reached. Instead, this reaches 99.99% of the value target value in the
specified number of milliseconds, and it then snaps to the target value in the last step.
This results in a smoother transition, with the caveat being that there will be a tiny jump
at the end. Unlike the Logarithmic
option, this does support crossing the zero value.
Implementations§
source§impl SmoothingStyle
impl SmoothingStyle
sourcepub fn num_steps(&self, sample_rate: f32) -> u32
pub fn num_steps(&self, sample_rate: f32) -> u32
Compute the number of steps to reach the target value based on the sample rate and this smoothing style’s duration.
sourcepub fn step_size(&self, start: f32, target: f32, num_steps: u32) -> f32
pub fn step_size(&self, start: f32, target: f32, num_steps: u32) -> f32
Compute the step size for this smoother. num_steps
can be obtained using
SmoothingStyle::num_steps()
. Check the source code of the SmoothingStyle::next()
and
SmoothingStyle::next_step()
functions for details on how these values should be used.
sourcepub fn next(&self, current: f32, target: f32, step_size: f32) -> f32
pub fn next(&self, current: f32, target: f32, step_size: f32) -> f32
Compute the next value from current
leading up to target
using the step_size
computed
using SmoothingStyle::step_size()
. Depending on the smoothing style this function may
never completely reach target
, so you will need to snap to target
yourself after
computing the target number of steps.
See the docstring on the SmoothingStyle::next_step()
function for the formulas used.
sourcepub fn next_step(
&self,
current: f32,
target: f32,
step_size: f32,
steps: u32
) -> f32
pub fn next_step( &self, current: f32, target: f32, step_size: f32, steps: u32 ) -> f32
The same as next()
, but with the option to take more than one step at a
time. Calling next_step()
with step count n
gives the same result as applying next()
n
times to a value, but is more efficient to compute. next_step()
with 1 step is
equivalent to step()
.
See the docstring on the SmoothingStyle::next_step()
function for the formulas used.
Trait Implementations§
source§impl Clone for SmoothingStyle
impl Clone for SmoothingStyle
source§fn clone(&self) -> SmoothingStyle
fn clone(&self) -> SmoothingStyle
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more