Build with this node

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

Ask Studio

@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

SetterRange as codedDefaultUnit
setPcm16InterpolatedDelayCurrentFramesFloored, 1 to maxFrames; the read wrapmaxFramesframes
setPcm16InterpolatedDelayInteger part truncated; a negative or too-large integer becomes currentFrames − 1, keeping the f32 fraction1samples
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 modulo currentFrames. 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.

Algorithm properties and proofs

No Lean 4 proof is mapped to this node.

Explore proofs alongside performance

Parameters

ParameterTypeSetter
Frames frames

Upstream `SetCurrentSize`: the read wrap, capped at the allocation.

floatsetPcm16InterpolatedDelayCurrentFrames
Delay samples delaySamples

Upstream `SetDelay(float)`: int32 truncation, f32 fraction, clamp to `currentFrames - 1`.

floatsetPcm16InterpolatedDelay

Dependencies

None: this node imports no other node.

Dependents

Used by