VCV Rack API  v1
rack::dsp Namespace Reference

Digital signal processing routines. 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
 
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
 A simple cyclic buffer. 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
 
struct  Timer
 
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 1.f, turns LOW when value reaches 0.f. More...
 
struct  TSchmittTrigger< float >
 
struct  TSlewLimiter
 
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 TRCFilter RCFilter
 
typedef TExponentialFilter ExponentialFilter
 
typedef TPeakFilter PeakFilter
 
typedef TSlewLimiter SlewLimiter
 
typedef TExponentialSlewLimiter ExponentialSlewLimiter
 
typedef TBiquadFilter BiquadFilter
 

Functions

template<typename T >
approxExp2Floor (T x, T *xf)
 Returns 2^floor(x), assuming that x >= 0. More...
 
template<>
simd::float_4 approxExp2Floor (simd::float_4 x, simd::float_4 *xf)
 
template<>
float approxExp2Floor (float x, float *xf)
 
template<typename T >
approxExp2_taylor5 (T x)
 Returns 2^x, assuming that x >= 0. More...
 
float sinc (float x)
 The normalized sinc function See https://en.wikipedia.org/wiki/Sinc_function. More...
 
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. More...
 
float convolveNaive (const float *in, const float *kernel, int len)
 Performs a direct sum convolution. More...
 
void boxcarLowpassIR (float *out, int len, float cutoff=0.5f)
 Computes the impulse response of a boxcar lowpass filter. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
template<typename T >
hann (T p)
 Hann window function. More...
 
void hannWindow (float *x, int len)
 Multiplies the Hann window by a signal x of length len in-place. More...
 
template<typename T >
blackman (T alpha, T p)
 Blackman window function. More...
 
void blackmanWindow (float alpha, float *x, int len)
 
template<typename T >
blackmanNuttall (T p)
 Blackman-Nuttall window function. More...
 
void blackmanNuttallWindow (float *x, int len)
 
template<typename T >
blackmanHarris (T p)
 Blackman-Harris window function. More...
 
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.

Typedef Documentation

◆ SchmittTrigger

◆ RCFilter

◆ ExponentialFilter

◆ PeakFilter

◆ SlewLimiter

◆ ExponentialSlewLimiter

◆ BiquadFilter

Function Documentation

◆ approxExp2Floor() [1/3]

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

Returns 2^floor(x), assuming that x >= 0.

If xf is non-NULL, it is set to the fractional part of x.

◆ approxExp2Floor() [2/3]

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

◆ approxExp2Floor() [3/3]

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

◆ approxExp2_taylor5()

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

Returns 2^x, assuming that x >= 0.

Maximum 0.00024% error. For float, roughly 3x faster than std::pow(2.f, x). For float_4, roughly 2x faster than simd::pow(2.f, x).

If negative powers are needed, you may use a lower bound and rescale.

approxExp2(x + 20) / 1048576

◆ 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.

◆ 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