Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::dsp::Slew Class Reference

One-pole slew toward a target, with separate rise and fall time constants. More...

Detailed Description

One-pole slew toward a target, with separate rise and fall time constants.

y += k (target - y) per frame, k the rise coefficient when the target is above y and the fall coefficient when below. Below the signal transport: the time constants are in frames, set by the component or app that owns it. Until a time constant is set, its coefficient is 1 and the output jumps to the target.

Definition at line 23 of file slew.hpp.

#include <slew.hpp>

Public Member Functions

void set_rise (float time_constant_frames)
 Set the rise time constant.
 
void set_fall (float time_constant_frames)
 Set the fall time constant.
 
void set_target (float target)
 Set where the output heads.
 
float process ()
 One frame.
 
void process (float *out, uint16_t frames)
 A buffer of frames.
 
void reset (float value=0.0f)
 The output and the target jump to a value.
 
float value () const
 The current output.
 
float target () const
 The current target.
 

Static Public Member Functions

static float coefficient_for (float time_constant_frames)
 The coefficient for a time constant in frames: 1 - e^(-1 / tau).
 

Member Function Documentation

◆ coefficient_for()

static float sbl::dsp::Slew::coefficient_for ( float  time_constant_frames)
inlinestatic

The coefficient for a time constant in frames: 1 - e^(-1 / tau).

The step response reaches 1 - 1/e after tau frames.

Parameters
time_constant_framestau, in frames
Returns
k in [0, 1]: 1 (instant) for a tau of 0 or less, or NaN; 0 for +inf, where the output holds

Definition at line 33 of file slew.hpp.

Referenced by set_fall(), and set_rise().

◆ set_rise()

void sbl::dsp::Slew::set_rise ( float  time_constant_frames)
inline

Set the rise time constant.

Parameters
time_constant_framestau in frames, as coefficient_for() takes it
Context
Same thread as process(); real-time safe.

Definition at line 46 of file slew.hpp.

References coefficient_for().

◆ set_fall()

void sbl::dsp::Slew::set_fall ( float  time_constant_frames)
inline

Set the fall time constant.

Parameters
time_constant_framestau in frames, as coefficient_for() takes it
Context
Same thread as process(); real-time safe.

Definition at line 54 of file slew.hpp.

References coefficient_for().

◆ set_target()

void sbl::dsp::Slew::set_target ( float  target)
inline

Set where the output heads.

Parameters
targetThe target; a non-finite value counts as 0
Context
Same thread as process(); real-time safe.

Definition at line 62 of file slew.hpp.

References target().

◆ process() [1/2]

float sbl::dsp::Slew::process ( )
inline

One frame.

Returns
The output after the step
Context
Audio thread; real-time safe.

Definition at line 70 of file slew.hpp.

Referenced by process().

◆ process() [2/2]

void sbl::dsp::Slew::process ( float *  out,
uint16_t  frames 
)
inline

A buffer of frames.

Parameters
[out]outOutput buffer, frames long
framesFrame count
Context
Audio thread; real-time safe.

Definition at line 83 of file slew.hpp.

References process().

◆ reset()

void sbl::dsp::Slew::reset ( float  value = 0.0f)
inline

The output and the target jump to a value.

Parameters
valueNew output and target; a non-finite value gives 0

Definition at line 94 of file slew.hpp.

References value().

◆ value()

float sbl::dsp::Slew::value ( ) const
inline

The current output.

Definition at line 100 of file slew.hpp.

Referenced by reset().

◆ target()

float sbl::dsp::Slew::target ( ) const
inline

The current target.

Definition at line 102 of file slew.hpp.

Referenced by set_target().


The documentation for this class was generated from the following file: