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.
| Param | Type | Default | Description |
|---|---|---|---|
| a | signal | - | First operand |
| b | signal | - | Second operand |
Equivalent to the + operator.
// Mixing two oscillators
add(sine(220), sine(330)) * 0.5 |> out(@) sub
Subtract - Subtracts second signal from first.
| Param | Type | Default | Description |
|---|---|---|---|
| a | signal | - | First operand |
| b | signal | - | Second operand |
Equivalent to the - operator.
// Difference of oscillators
sub(sine(220), sine(221)) |> out(@) mul
Multiply - Multiplies two signals.
| Param | Type | Default | Description |
|---|---|---|---|
| a | signal | - | First operand |
| b | signal | - | 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.
| Param | Type | Default | Description |
|---|---|---|---|
| a | signal | - | Dividend |
| b | signal | - | Divisor |
Equivalent to the / operator.
pow
Power - Raises base to exponent.
| Param | Type | Default | Description |
|---|---|---|---|
| base | signal | - | Base value |
| exp | signal | - | Exponent |
Equivalent to the ^ operator.
// Exponential curve
pow(lfo(0.5), 2) |> out(@) Unary math
neg
Negate - Inverts the sign of a signal.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Input |
// Invert phase
neg(sine(220)) |> out(@) abs
Absolute value - Returns the absolute value.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | 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.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Input (should be >= 0) |
log
Natural logarithm - Returns ln(x).
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Input (should be > 0) |
exp
Exponential - Returns e^x.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Input |
Useful for exponential envelopes and frequency scaling.
floor
Floor - Rounds down to nearest integer.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Input |
// Quantize an LFO
floor(lfo(0.5) * 8) / 8 |> out(@) ceil
Ceiling - Rounds up to nearest integer.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Input |
Binary math
min
Minimum - Returns the smaller of two values.
| Param | Type | Default | Description |
|---|---|---|---|
| a | signal | - | First value |
| b | signal | - | Second value |
// Limit signal to 0.5
min(sine(220), 0.5) |> out(@) max
Maximum - Returns the larger of two values.
| Param | Type | Default | Description |
|---|---|---|---|
| a | signal | - | First value |
| b | signal | - | Second value |
// Ensure signal doesn't go below 0
max(sine(220), 0) |> out(@) Ternary math
clamp
Clamp - Constrains value between lo and hi.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Input value |
| lo | signal | - | Lower bound |
| hi | signal | - | 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.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Input value |
| lo | signal | - | Lower bound |
| hi | signal | - | 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.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | 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.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | 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.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | 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).
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Value between -1 and 1 |
acos
Arccosine - Returns the inverse cosine (result in radians).
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Value between -1 and 1 |
atan
Arctangent - Returns the inverse tangent (result in radians).
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | 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).
| Param | Type | Default | Description |
|---|---|---|---|
| y | signal | - | Y coordinate |
| x | signal | - | X coordinate |
Useful for phase calculations and coordinate conversions.
Hyperbolic functions
sinh
Hyperbolic sine - Returns the hyperbolic sine.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Input value |
cosh
Hyperbolic cosine - Returns the hyperbolic cosine.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | Input value |
tanh
Hyperbolic tangent - Returns the hyperbolic tangent.
| Param | Type | Default | Description |
|---|---|---|---|
| x | signal | - | 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