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::SoftLimiter Class Reference

A soft-knee limiter: the input under a knee, a tanh bend under a ceiling above it. More...

Detailed Description

A soft-knee limiter: the input under a knee, a tanh bend under a ceiling above it.

Memoryless. A sample whose magnitude is at or under the knee passes unchanged, bit for bit. Above it the excess is bent by a tanh scaled to the room between the knee and the ceiling, so the curve leaves the knee at a slope of 1 and approaches the ceiling without reaching past it. A NaN comes out as 0. Below the signal transport (signal-transport section 5.6): the knee and the ceiling are in the signal's own scale, 0 < knee < ceiling, fixed at construction, and it declares no ports.

While a signal is above the knee the bend adds harmonics, which are not band-limited; set the knee above the level the signal has in normal use.

constexpr sbl::dsp::SoftLimiter limiter{0.92f, 0.98f};
out[i] = limiter.limit(in[i] * level);
A soft-knee limiter: the input under a knee, a tanh bend under a ceiling above it.
float limit(float x) const
One sample through the limiter.

Definition at line 36 of file soft_limiter.hpp.

#include <soft_limiter.hpp>

Public Member Functions

constexpr SoftLimiter (float knee, float ceiling)
 A limiter with a knee and a ceiling, 0 < knee < ceiling.
 
constexpr float knee () const
 The knee.
 
constexpr float ceiling () const
 The ceiling.
 
bool acts_on (float x) const
 Whether limit() changes x: its magnitude is above the knee, or it is not a number.
 
float limit (float x) const
 One sample through the limiter.
 
void process (const float *in, float *out, uint16_t frames) const
 A block through the limiter; out may be in.
 

Constructor & Destructor Documentation

◆ SoftLimiter()

constexpr sbl::dsp::SoftLimiter::SoftLimiter ( float  knee,
float  ceiling 
)
inlineconstexpr

A limiter with a knee and a ceiling, 0 < knee < ceiling.

Parameters
kneeThe magnitude up to which the input passes unchanged
ceilingThe magnitude the output does not exceed

Definition at line 44 of file soft_limiter.hpp.

Member Function Documentation

◆ knee()

constexpr float sbl::dsp::SoftLimiter::knee ( ) const
inlineconstexpr

The knee.

Definition at line 47 of file soft_limiter.hpp.

◆ ceiling()

constexpr float sbl::dsp::SoftLimiter::ceiling ( ) const
inlineconstexpr

The ceiling.

Definition at line 49 of file soft_limiter.hpp.

◆ acts_on()

bool sbl::dsp::SoftLimiter::acts_on ( float  x) const
inline

Whether limit() changes x: its magnitude is above the knee, or it is not a number.

Parameters
xInput sample
Returns
True when limit(x) differs from x

Definition at line 57 of file soft_limiter.hpp.

References sbl::math::magnitude_bits().

Referenced by limit().

◆ limit()

float sbl::dsp::SoftLimiter::limit ( float  x) const
inline

One sample through the limiter.

Parameters
xInput sample, any value
Returns
x at or under the knee; above it, a magnitude in (knee, ceiling]; 0 for a NaN
Context
Audio thread; real-time safe.

Definition at line 66 of file soft_limiter.hpp.

References acts_on(), and sbl::dsp::math::fast_tanhf().

Referenced by process().

◆ process()

void sbl::dsp::SoftLimiter::process ( const float *  in,
float *  out,
uint16_t  frames 
) const
inline

A block through the limiter; out may be in.

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

Definition at line 86 of file soft_limiter.hpp.

References limit().


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