@maruaudio/dsp/delays/pcm16-interpolated is the CHOMPI firmware's stereo delay line with int16 storage, held exactly in Float32Arrays. A read interpolates a + (b − a)·frac in f32 and truncates toward zero into int16, so the line quantizes on read as well as write. The write pointer decrements; int32 conversions follow ARM vcvt (truncate, NaN to 0, saturate).
const state = initPcm16InterpolatedDelay(48000)
setPcm16InterpolatedDelay(state, 12000.5)
pcm16InterpolatedDelayRead(state) // state.readLeft, state.readRight
pcm16InterpolatedDelayWrite(state, floatToPcm16(l), floatToPcm16(r))Parameters
| Setter | Range as coded | Default | Unit |
|---|---|---|---|
setPcm16InterpolatedDelayCurrentFrames | Floored, 1 to maxFrames; the read wrap | maxFrames | frames |
setPcm16InterpolatedDelay | Integer part truncated; a negative or too-large integer becomes currentFrames − 1, keeping the f32 fraction | 1 | samples |
pcm16InterpolatedDelayReadAt(state, delay) | Unclamped, like the firmware | — | samples |
Write values that are not int16 are stored like a C++ int16_t: truncated, then wrapped to 16 bits.
Lifecycle
initPcm16InterpolatedDelay(maxFrames) allocates both lines once → setters → per frame, …Read or …ReadAt, then …Write (or …TickWritePointer to advance without writing). clearPcm16InterpolatedDelayStep clears at most 256 frames per call, returning maxFrames when done; …Current clears the active frames; resetPcm16InterpolatedDelay clears all and restores pointer 0, delay 1 and fraction 0, outside realtime.
When to use it
Reproducing the CHOMPI firmware's 16-bit delay bit for bit, or porting on it.
Limits
- Writes wrap modulo
maxFrames, reads modulocurrentFrames. With a shrunk current size the effective delay jumps when the write pointer passes it; the firmware never shrinks the line. - Delay 0 reads the oldest slot, delay 1 the frame written one tick earlier. Callers convert floats with
@maru/math-pcm16.