Build with this node

Start with a prompt in Studio, or copy it into your own coding agent.

Ask Studio

@maruaudio/dsp/math/quantizer is a bit-depth staircase read through a sampled curve. It reproduces the public "crush" web preview, a 2048-point bitcrushCurve fed to a WaveShaperNode with no oversampling, rather than the ideal closed-form staircase. The curve stores round((x + 1) / step) × step − 1 at f32, with step = 2 / (2^bits − 1), and each sample is the Web Audio curve-application formula: the input maps to v = 0.5 × (x + 1) × 2047, neighbouring curve points are interpolated linearly in f64, and the result is stored to f32.

Parameters

PathSetterRange as codedDefaultUnit
bitssetQuantizerBitsquantizerDepthFor: rounded, then 1 to 164bits

Lifecycle

initQuantizerNode(sampleRate) allocates the 2048-point curve and a one-slot f32 buffer and fills the curve for 4 bits. setQuantizerBits rebuilds the curve only when the clamped depth changes; run it at control rate. quantizerNodeTick(state, x) reads one sample. resetQuantizerNode only zeroes the rounding slot, since the curve depends on the parameter alone.

When to use it

Bit-depth reduction that must match the shipped web preview at the same setting, on any target. Rate reduction, held samples and boost are not part of it; they belong to @maru/distortion-bitcrusher.

Limits

  • Mono sample tick. No smoothing: a depth change applies to the next sample.
  • Inputs below −1 return curve[0] and inputs at or above +1 return curve[2047]; a NaN input returns NaN.
  • At 11 bits and above the levels outnumber the curve points, so the output is the interpolated curve, not 2^bits distinct levels.
  • No oversampling or rate reduction, so high-frequency quantization products may alias (the demo note says so).

Algorithm properties and proofs

No Lean 4 proof is mapped to this node.

Explore proofs alongside performance

Parameters

ParameterTypeSetter
Value valuefloatsetQuantizerBits

Ports

  • In ininput · audio · mono
  • Out outoutput · audio · mono

One sample per quantizerNodeTick call.

Dependencies

None: this node imports no other node.

Dependents

No other node imports this one.

Used by

No plugin with a published composition uses this node yet.