Qu

distort

Builtin index · Noise

result = distort(x, kind, [amount=0.3])

Input: x, kind, amount · Output: result

What it is

Put the signal through a nonlinearity: clip, soft, crossover, harmonic, quantize. See the dedicated table and signature above for the full parameter breakdown.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = distort(x, kind, [amount=0.3])
x —not documented yet
kind —not documented yet
amount optional (default 0.3)not documented yet
result Vec, Signal, or vector
Returns a plain length-N Vec — a Signal argument comes back as a bare vector, so re-wrap it with signal(...) if you need the sample rate.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

t = (0 to 999) / 1000
pure = sin(2 * pi * 31 * t)

clipped = distort(pure, "clip", 0.4)
soft = distort(pure, "soft", 0.4)
print("clip {thd(clipped):.1f} dB, soft {thd(soft):.1f} dB, below the fundamental")
output
clip -15.6 dB, soft -9.8 dB, below the fundamental

from noise

How it works

distort(x, "clip", 0.4) — the signal put through a nonlinearity, which is a different animal from noise: distortion is a FUNCTION of the signal, so averaging does nothing at all and the only cure is not to distort.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.