Contents

Math Functions

Mathematical operations for signal processing and control logic.

Note: sin(x), cos(x), tan(x), and tanh(x) are pure math functions operating on values in radians. For audio oscillators, use sine(freq) or saw(freq) etc.

Arithmetic

add

Add - Adds two signals.

ParamTypeDefaultDescription
asignal-First operand
bsignal-Second operand

Equivalent to the + operator.

// Mixing two oscillators
add(sine(220), sine(330)) * 0.5 |> out(@)

sub

Subtract - Subtracts second signal from first.

ParamTypeDefaultDescription
asignal-First operand
bsignal-Second operand

Equivalent to the - operator.

// Difference of oscillators
sub(sine(220), sine(221)) |> out(@)

mul

Multiply - Multiplies two signals.

ParamTypeDefaultDescription
asignal-First operand
bsignal-Second operand

Equivalent to the * operator. Commonly used for amplitude modulation.

// Ring modulation
mul(sine(220), sine(30)) |> out(@)

div

Divide - Divides first signal by second.

ParamTypeDefaultDescription
asignal-Dividend
bsignal-Divisor

Equivalent to the / operator.


pow

Power - Raises base to exponent.

ParamTypeDefaultDescription
basesignal-Base value
expsignal-Exponent

Equivalent to the ^ operator.

// Exponential curve
pow(lfo(0.5), 2) |> out(@)

Unary math

neg

Negate - Inverts the sign of a signal.

ParamTypeDefaultDescription
xsignal-Input
// Invert phase
neg(sine(220)) |> out(@)

abs

Absolute value - Returns the absolute value.

ParamTypeDefaultDescription
xsignal-Input

Useful for full-wave rectification or envelope following.

// Full-wave rectification
abs(sine(110)) |> lp(@, 50) |> out(@)

sqrt

Square root - Returns the square root.

ParamTypeDefaultDescription
xsignal-Input (should be >= 0)

log

Natural logarithm - Returns ln(x).

ParamTypeDefaultDescription
xsignal-Input (should be > 0)

exp

Exponential - Returns e^x.

ParamTypeDefaultDescription
xsignal-Input

Useful for exponential envelopes and frequency scaling.


floor

Floor - Rounds down to nearest integer.

ParamTypeDefaultDescription
xsignal-Input
// Quantize an LFO
floor(lfo(0.5) * 8) / 8 |> out(@)

ceil

Ceiling - Rounds up to nearest integer.

ParamTypeDefaultDescription
xsignal-Input

Binary math

min

Minimum - Returns the smaller of two values.

ParamTypeDefaultDescription
asignal-First value
bsignal-Second value
// Limit signal to 0.5
min(sine(220), 0.5) |> out(@)

max

Maximum - Returns the larger of two values.

ParamTypeDefaultDescription
asignal-First value
bsignal-Second value
// Ensure signal doesn't go below 0
max(sine(220), 0) |> out(@)

Ternary math

clamp

Clamp - Constrains value between lo and hi.

ParamTypeDefaultDescription
xsignal-Input value
losignal-Lower bound
hisignal-Upper bound
// Keep signal in -0.5 to 0.5 range
clamp(saw(110), -0.5, 0.5) |> out(@)

wrap

Wrap - Wraps value around range boundaries.

ParamTypeDefaultDescription
xsignal-Input value
losignal-Lower bound
hisignal-Upper bound

When the value exceeds hi, it wraps to lo (and vice versa). Useful for creating sawtooth-like modulation.

// Wrapped phasor
wrap(phasor(1) * 3, 0, 1) |> out(@)

Trigonometric functions

These functions operate on values in radians. They are pure math functions, not audio oscillators.

sin

Sine - Returns the sine of an angle in radians.

ParamTypeDefaultDescription
xsignal-Angle in radians

Important: This is a pure math function, not an oscillator. For a sine oscillator, use sine(freq).

// Create a sine wave manually from a phasor
sin(phasor(440) * 2 * 3.14159) |> out(@)
// Waveshaping with sine
saw(110) |> sin(@ * 3.14159) |> out(@)

cos

Cosine - Returns the cosine of an angle in radians.

ParamTypeDefaultDescription
xsignal-Angle in radians
// Cosine is sine shifted by 90 degrees
cos(phasor(440) * 2 * 3.14159) |> out(@)

tan

Tangent - Returns the tangent of an angle in radians.

ParamTypeDefaultDescription
xsignal-Angle in radians
// Tangent waveshaping (careful - goes to infinity!)
sine(110) * 0.3 |> tan(@) |> clamp(@, -1, 1) |> out(@)

asin

Arcsine - Returns the inverse sine (result in radians).

ParamTypeDefaultDescription
xsignal-Value between -1 and 1

acos

Arccosine - Returns the inverse cosine (result in radians).

ParamTypeDefaultDescription
xsignal-Value between -1 and 1

atan

Arctangent - Returns the inverse tangent (result in radians).

ParamTypeDefaultDescription
xsignal-Input value

Useful for soft saturation effects.

// Soft saturation using atan
saw(110) * 3 |> atan(@) / 1.57 |> out(@)

atan2

Two-argument arctangent - Returns the angle between the positive x-axis and the point (x, y).

ParamTypeDefaultDescription
ysignal-Y coordinate
xsignal-X coordinate

Useful for phase calculations and coordinate conversions.


Hyperbolic functions

sinh

Hyperbolic sine - Returns the hyperbolic sine.

ParamTypeDefaultDescription
xsignal-Input value

cosh

Hyperbolic cosine - Returns the hyperbolic cosine.

ParamTypeDefaultDescription
xsignal-Input value

tanh

Hyperbolic tangent - Returns the hyperbolic tangent.

ParamTypeDefaultDescription
xsignal-Input value

Important: This is a pure math function. For tanh-based distortion with drive control, use saturate(in, drive).

The tanh function outputs values between -1 and 1, making it useful for custom waveshaping when combined with multiplication.

// Manual saturation using tanh
saw(110) * 3 |> tanh(@) |> out(@)
// Adjustable saturation (multiply input for more drive)
saw(110) |> tanh(@ * 5) |> out(@)

Related: saturate