VCV Rack API v2
Loading...
Searching...
No Matches
rack::dsp Namespace Reference

Digital signal processing routines and classes. More...

Classes

struct  AppleRingBuffer
 A cyclic buffer which maintains a valid linear array of size S by sliding along a larger block of size N. More...
 
struct  BooleanTrigger
 Detects when a boolean changes from false to true. More...
 
struct  ClockDivider
 Counts calls to process(), returning true every division calls. More...
 
struct  ComplexFFT
 Complex-valued FFT context. More...
 
struct  Decimator
 Downsamples by an integer factor. More...
 
struct  DoubleRingBuffer
 A cyclic buffer which maintains a valid linear array of size S by keeping a copy of the buffer in adjacent memory. More...
 
struct  Frame
 Useful for storing arrays of samples in ring buffers and casting them to float* to be used by interleaved processors, like SampleRateConverter. More...
 
struct  IIRFilter
 Digital IIR filter processor. More...
 
struct  MidiGenerator
 Converts gates and CV to MIDI messages. More...
 
struct  MinBlepGenerator
 
struct  PulseGenerator
 When triggered, holds a high value for a specified time before going low again. More...
 
struct  RealFFT
 Real-valued FFT context. More...
 
struct  RealTimeConvolver
 
struct  RingBuffer
 Lock-free queue with fixed size and no allocations. More...
 
struct  SampleRateConverter
 Resamples by a fixed rational factor. More...
 
struct  TBiquadFilter
 
struct  TExponentialFilter
 Applies exponential smoothing to a signal with the ODE \( \frac{dy}{dt} = x \lambda \). More...
 
struct  TExponentialSlewLimiter
 Behaves like ExponentialFilter but with different lambas when the RHS of the ODE is positive or negative. More...
 
struct  TPeakFilter
 Like ExponentialFilter but jumps immediately to higher values. More...
 
struct  TRCFilter
 The simplest possible analog filter using an Euler solver. More...
 
struct  TSchmittTrigger
 Turns HIGH when value reaches a threshold (default 0.f), turns LOW when value reaches a threshold (default 1.f). More...
 
struct  TSchmittTrigger< float >
 
struct  TSlewLimiter
 Limits the derivative of the output by a rise and fall speed, in units/s. More...
 
struct  TTimer
 Accumulates a timer when process() is called. More...
 
struct  Upsampler
 Upsamples by an integer factor. More...
 
struct  VuMeter
 Deprecated. More...
 
struct  VuMeter2
 Models a VU meter with smoothing. More...
 

Typedefs

typedef TSchmittTrigger SchmittTrigger
 
typedef TTimer Timer
 
typedef TRCFilter RCFilter
 
typedef TExponentialFilter ExponentialFilter
 
typedef TPeakFilter PeakFilter
 
typedef TSlewLimiter SlewLimiter
 
typedef TExponentialSlewLimiter ExponentialSlewLimiter
 
typedef TBiquadFilter BiquadFilter
 

Functions

template<typename T , size_t N>
polyDirect (const T(&a)[N], T x)
 Evaluates a polynomial with coefficients a[n] at x.
 
template<typename T , size_t N>
polyHorner (const T(&a)[N], T x)
 Evaluates a polynomial with coefficients a[n] at x.
 
template<typename T , size_t N>
polyEstrin (const T(&a)[N], T x)
 Evaluates a polynomial with coefficients a[n] at x.
 
template<typename T >
exp2Floor (T x, T *xf)
 Returns 2^floor(x).
 
template<>
float exp2Floor (float x, float *xf)
 
template<>
simd::float_4 exp2Floor (simd::float_4 x, simd::float_4 *xf)
 
template<typename T >
approxExp2Floor (T x, T *xf)
 Deprecated alias of exp2Floor()
 
template<typename T >
exp2_taylor5 (T x)
 Returns 2^x with at most 6e-06 relative error.
 
template<typename T >
approxExp2_taylor5 (T x)
 Deprecated alias of exp2_taylor5()
 
float sinc (float x)
 The normalized sinc function See https://en.wikipedia.org/wiki/Sinc_function.
 
template<typename T >
sinc (T x)
 
template<typename T >
amplitudeToDb (T amp)
 
template<typename T >
dbToAmplitude (T db)
 
template<typename T >
quadraticBipolar (T x)
 
template<typename T >
cubic (T x)
 
template<typename T >
quarticBipolar (T x)
 
template<typename T >
quintic (T x)
 
template<typename T >
sqrtBipolar (T x)
 
template<typename T >
exponentialBipolar (T b, T x)
 This is pretty much a scaled sinh.
 
struct __attribute__ ((packed, aligned(1), gcc_struct)) Int24
 24-bit integer, using int32_t for conversions.
 
template<typename To , typename From >
To convert (From x)=delete
 Converts between normalized types.
 
template<>
float convert (float x)
 Trivial conversions.
 
template<>
float convert (int8_t x)
 Integer to float.
 
template<>
float convert (int16_t x)
 
template<>
float convert (Int24 x)
 
template<>
float convert (int32_t x)
 
template<>
float convert (int64_t x)
 
template<>
int8_t convert (float x)
 Float to integer.
 
template<>
int16_t convert (float x)
 
template<>
Int24 convert (float x)
 
template<>
int32_t convert (float x)
 
template<>
int64_t convert (float x)
 
template<typename To , typename From >
void convert (const From *in, To *out, size_t len)
 Buffer conversion.
 
float convolveNaive (const float *in, const float *kernel, int len)
 Performs a direct sum convolution.
 
void boxcarLowpassIR (float *out, int len, float cutoff=0.5f)
 Computes the impulse response of a boxcar lowpass filter.
 
void minBlepImpulse (int z, int o, float *output)
 Computes the minimum-phase bandlimited step (MinBLEP) z: number of zero-crossings o: oversample factor output: must be length 2 * z * o.
 
template<typename T , typename F >
void stepEuler (T t, T dt, T x[], int len, F f)
 The callback function f in each of these stepping functions must have the signature.
 
template<typename T , typename F >
void stepRK2 (T t, T dt, T x[], int len, F f)
 Solves an ODE system using the 2nd order Runge-Kutta method.
 
template<typename T , typename F >
void stepRK4 (T t, T dt, T x[], int len, F f)
 Solves an ODE system using the 4th order Runge-Kutta method.
 
template<typename T >
hann (T p)
 Hann window function.
 
void hannWindow (float *x, int len)
 Multiplies the Hann window by a signal x of length len in-place.
 
template<typename T >
blackman (T alpha, T p)
 Blackman window function.
 
void blackmanWindow (float alpha, float *x, int len)
 
template<typename T >
blackmanNuttall (T p)
 Blackman-Nuttall window function.
 
void blackmanNuttallWindow (float *x, int len)
 
template<typename T >
blackmanHarris (T p)
 Blackman-Harris window function.
 
void blackmanHarrisWindow (float *x, int len)
 

Variables

DEPRECATED typedef VuMeter VUMeter
 
static const float FREQ_C4 = 261.6256f
 
static const float FREQ_A4 = 440.0000f
 
static const float FREQ_SEMITONE = 1.0594630943592953f
 

Detailed Description

Digital signal processing routines and classes.

Typedef Documentation

◆ SchmittTrigger

◆ Timer

◆ RCFilter

◆ ExponentialFilter

◆ PeakFilter

◆ SlewLimiter

◆ ExponentialSlewLimiter

◆ BiquadFilter

Function Documentation

◆ polyDirect()

template<typename T , size_t N>
T rack::dsp::polyDirect ( const T(&)  a[N],
x 
)

Evaluates a polynomial with coefficients a[n] at x.

Uses naive direct evaluation.

◆ polyHorner()

template<typename T , size_t N>
T rack::dsp::polyHorner ( const T(&)  a[N],
x 
)

Evaluates a polynomial with coefficients a[n] at x.

Uses Horner's method. https://en.wikipedia.org/wiki/Horner%27s_method

◆ polyEstrin()

template<typename T , size_t N>
T rack::dsp::polyEstrin ( const T(&)  a[N],
x 
)

Evaluates a polynomial with coefficients a[n] at x.

Uses Estrin's method. https://en.wikipedia.org/wiki/Estrin%27s_scheme

◆ exp2Floor() [1/3]

template<typename T >
T rack::dsp::exp2Floor ( x,
T *  xf 
)

Returns 2^floor(x).

If xf is given, sets it to the fractional part of x. This is useful in the computation 2^x = 2^floor(x) * 2^frac(x).

◆ exp2Floor() [2/3]

template<>
float rack::dsp::exp2Floor ( float  x,
float *  xf 
)
inline

◆ exp2Floor() [3/3]

template<>
simd::float_4 rack::dsp::exp2Floor ( simd::float_4  x,
simd::float_4 xf 
)
inline

◆ approxExp2Floor()

template<typename T >
T rack::dsp::approxExp2Floor ( x,
T *  xf 
)

Deprecated alias of exp2Floor()

◆ exp2_taylor5()

template<typename T >
T rack::dsp::exp2_taylor5 ( x)

Returns 2^x with at most 6e-06 relative error.

Polynomial coefficients are chosen to minimize relative error while maintaining continuity and giving exact values at integer values of x. Thanks to Andy Simper for coefficients.

◆ approxExp2_taylor5()

template<typename T >
T rack::dsp::approxExp2_taylor5 ( x)

Deprecated alias of exp2_taylor5()

◆ sinc() [1/2]

float rack::dsp::sinc ( float  x)
inline

The normalized sinc function See https://en.wikipedia.org/wiki/Sinc_function.

◆ sinc() [2/2]

template<typename T >
T rack::dsp::sinc ( x)

◆ amplitudeToDb()

template<typename T >
T rack::dsp::amplitudeToDb ( amp)

◆ dbToAmplitude()

template<typename T >
T rack::dsp::dbToAmplitude ( db)

◆ quadraticBipolar()

template<typename T >
T rack::dsp::quadraticBipolar ( x)

◆ cubic()

template<typename T >
T rack::dsp::cubic ( x)

◆ quarticBipolar()

template<typename T >
T rack::dsp::quarticBipolar ( x)

◆ quintic()

template<typename T >
T rack::dsp::quintic ( x)

◆ sqrtBipolar()

template<typename T >
T rack::dsp::sqrtBipolar ( x)

◆ exponentialBipolar()

template<typename T >
T rack::dsp::exponentialBipolar ( b,
x 
)

This is pretty much a scaled sinh.

Slow. Not recommended for parameter scaling.

◆ __attribute__()

struct rack::dsp::__attribute__ ( (packed, aligned(1), gcc_struct)  )

24-bit integer, using int32_t for conversions.

◆ convert() [1/13]

template<typename To , typename From >
To rack::dsp::convert ( From  x)
delete

Converts between normalized types.

◆ convert() [2/13]

template<>
float rack::dsp::convert ( float  x)
inline

Trivial conversions.

◆ convert() [3/13]

template<>
float rack::dsp::convert ( int8_t  x)
inline

Integer to float.

◆ convert() [4/13]

template<>
float rack::dsp::convert ( int16_t  x)
inline

◆ convert() [5/13]

template<>
float rack::dsp::convert ( Int24  x)
inline

◆ convert() [6/13]

template<>
float rack::dsp::convert ( int32_t  x)
inline

◆ convert() [7/13]

template<>
float rack::dsp::convert ( int64_t  x)
inline

◆ convert() [8/13]

template<>
int8_t rack::dsp::convert ( float  x)
inline

Float to integer.

◆ convert() [9/13]

template<>
int16_t rack::dsp::convert ( float  x)
inline

◆ convert() [10/13]

template<>
Int24 rack::dsp::convert ( float  x)
inline

◆ convert() [11/13]

template<>
int32_t rack::dsp::convert ( float  x)
inline

◆ convert() [12/13]

template<>
int64_t rack::dsp::convert ( float  x)
inline

◆ convert() [13/13]

template<typename To , typename From >
void rack::dsp::convert ( const From *  in,
To *  out,
size_t  len 
)

Buffer conversion.

◆ convolveNaive()

float rack::dsp::convolveNaive ( const float *  in,
const float *  kernel,
int  len 
)
inline

Performs a direct sum convolution.

◆ boxcarLowpassIR()

void rack::dsp::boxcarLowpassIR ( float *  out,
int  len,
float  cutoff = 0.5f 
)
inline

Computes the impulse response of a boxcar lowpass filter.

◆ minBlepImpulse()

void rack::dsp::minBlepImpulse ( int  z,
int  o,
float *  output 
)

Computes the minimum-phase bandlimited step (MinBLEP) z: number of zero-crossings o: oversample factor output: must be length 2 * z * o.

https://www.cs.cmu.edu/~eli/papers/icmc01-hardsync.pdf

◆ stepEuler()

template<typename T , typename F >
void rack::dsp::stepEuler ( t,
dt,
x[],
int  len,
f 
)

The callback function f in each of these stepping functions must have the signature.

void f(T t, const T x[], T dxdt[])

A capturing lambda is ideal for this. For example, the following solves the system x''(t) = -x(t) using a fixed timestep of 0.01 and initial conditions x(0) = 1, x'(0) = 0.

float x[2] = {1.f, 0.f};
float dt = 0.01f;
for (float t = 0.f; t < 1.f; t += dt) {
    rack::ode::stepRK4(t, dt, x, 2, [&](float t, const float x[], float dxdt[]) {
        dxdt[0] = x[1];
        dxdt[1] = -x[0];
    });
    printf("%f\n", x[0]);
}

Solves an ODE system using the 1st order Euler method

◆ stepRK2()

template<typename T , typename F >
void rack::dsp::stepRK2 ( t,
dt,
x[],
int  len,
f 
)

Solves an ODE system using the 2nd order Runge-Kutta method.

◆ stepRK4()

template<typename T , typename F >
void rack::dsp::stepRK4 ( t,
dt,
x[],
int  len,
f 
)

Solves an ODE system using the 4th order Runge-Kutta method.

◆ hann()

template<typename T >
T rack::dsp::hann ( p)
inline

Hann window function.

p: proportion from [0, 1], usually i / (len - 1) https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows

◆ hannWindow()

void rack::dsp::hannWindow ( float *  x,
int  len 
)
inline

Multiplies the Hann window by a signal x of length len in-place.

◆ blackman()

template<typename T >
T rack::dsp::blackman ( alpha,
p 
)
inline

Blackman window function.

https://en.wikipedia.org/wiki/Window_function#Blackman_window A typical alpha value is 0.16.

◆ blackmanWindow()

void rack::dsp::blackmanWindow ( float  alpha,
float *  x,
int  len 
)
inline

◆ blackmanNuttall()

template<typename T >
T rack::dsp::blackmanNuttall ( p)
inline

◆ blackmanNuttallWindow()

void rack::dsp::blackmanNuttallWindow ( float *  x,
int  len 
)
inline

◆ blackmanHarris()

template<typename T >
T rack::dsp::blackmanHarris ( p)
inline

◆ blackmanHarrisWindow()

void rack::dsp::blackmanHarrisWindow ( float *  x,
int  len 
)
inline

Variable Documentation

◆ VUMeter

DEPRECATED typedef VuMeter rack::dsp::VUMeter

◆ FREQ_C4

const float rack::dsp::FREQ_C4 = 261.6256f
static

◆ FREQ_A4

const float rack::dsp::FREQ_A4 = 440.0000f
static

◆ FREQ_SEMITONE

const float rack::dsp::FREQ_SEMITONE = 1.0594630943592953f
static