Skip to content

DSP Builtins

NameDescription
SRSample rate in Hz. Configure with config.sample_rate(rate).
INV_SRInverse sample rate (1.0 / SR). Useful for phase increment calculations.
PIPi (3.14159…)
TWOPITwo pi / tau (6.28318…). Full cycle in radians.
CYCLECurrent cycle position (0.0 to 1.0), derived from the transport clock.
CPSCycles per second — tempo-derived frequency (e.g. 120 BPM = 2.0 CPS).
TIMEElapsed time in seconds since the signal’s epoch. Available in dsp signal blocks only.

SR and INV_SR are injected at runtime and reflect the actual sample rate. CYCLE and CPS are updated each sample from the transport. TIME is only available inside dsp signal blocks.

FunctionDescription
sin(x)Sine
cos(x)Cosine
tan(x)Tangent
tanh(x)Hyperbolic tangent (useful for soft clipping)
FunctionDescription
exp(x)e^x
log(x)Natural logarithm (ln)
log2(x)Base-2 logarithm
log10(x)Base-10 logarithm
sqrt(x)Square root
pow(base, exp)Power (base^exp)
FunctionDescription
abs(x)Absolute value
floor(x)Round down to nearest integer
ceil(x)Round up to nearest integer
round(x)Round to nearest integer
fract(x)Fractional part (x - floor(x))
clamp(x, lo, hi)Clamp x to the range [lo, hi]
min(a, b)Minimum of two values
max(a, b)Maximum of two values
lerp(a, b, t)Linear interpolation: a + (b - a) * t
FunctionDescription
mtof(note)MIDI note to frequency: 440 * 2^((note - 69) / 12). Accepts fractional notes for microtonal pitches (e.g. mtof(60.5) gives a quarter-tone above C4)
ftom(freq)Frequency to MIDI note: 69 + 12 * log2(freq / 440)

These functions maintain internal state across samples. Each call site gets its own independent state.

FunctionDescription
svf_lp(signal, freq, Q)State Variable Filter — lowpass
svf_hp(signal, freq, Q)State Variable Filter — highpass
svf_bp(signal, freq, Q)State Variable Filter — bandpass
svf_notch(signal, freq, Q)State Variable Filter — notch
onepole(signal, coeff)One-pole lowpass filter

SVF filters use a topology-preserving transform (Zavalishin). freq is in Hz, Q controls resonance (0.707 = Butterworth, higher = more resonant). The sample rate is injected automatically.

onepole is a simple first-order lowpass. coeff ranges from 0 to 1 — higher values track the input faster.

FunctionDescription
delay(signal, samples)Integer sample delay (circular buffer, max 1 second)
delay_interp(signal, samples)Fractional delay with linear interpolation (max 1 second)
FunctionDescription
noise()White noise, range [-1.0, 1.0]
sample_hold(signal, trigger)Captures signal on rising edge of trigger (transition from <=0 to >0)