@maruaudio/dsp/tables/sample-reader plays a mono table of up to 65536 f32 samples (SAMPLE_TABLE_MAX_SAMPLES) with linear interpolation. One state machine serves cyclic wavetable playback and one-shot regions: a region is chosen as normalized start and end points, the read position advances by playbackRate source samples per output frame, and at the region end it either wraps by the region span or stops and latches finished. Voices, polyphony and grain scheduling stay outside it.
Parameters
configureSampleTableReader(state, playbackRate, startNormalized, endNormalized, gain, loop) sets them together.
| Argument | Range as coded | Default from init | Unit |
|---|---|---|---|
playbackRate | 0 to 16 | 1 | source samples per frame |
startNormalized | 0 to 1, floored to an index, at most length − 1 | 0 | fraction of the table |
endNormalized | 0 to 1, floored; at least start + 1, at most length | table end | fraction of the table |
gain | 0 to 4 | 1 | linear |
loop | 0 one-shot, anything else loops | 0 | flag |
Lifecycle
initSampleTableReader() allocates the full-capacity table. loadSampleTable(state, available, readSample) runs on the control thread: it stores up to the capacity through the caller's decoder callback, resets the region to the whole table and returns the accepted length. Then configureSampleTableReader → sampleTableReaderTick per sample → resetSampleTableReader, which returns to the region start and clears finished. sampleTableLinearAt(state, position) is the shared interpolation read for table-driven voices.
When to use it
A single-cycle wavetable or a short sample played at a fixed rate, looped or once, inside a larger voice. For loop crossfades and reverse play see @maru/tables-looped-region.
Limits
- Mono sample tick; linear interpolation only. No smoothing on rate or gain.
- Configuring re-seeks to the region start. An empty table ticks 0 and is
finished. - At the end of a looped region the interpolation partner is the region start; in a one-shot it is the last sample.
- The loop wrap is a
whilesubtraction of the span; the rate cap of 16 keeps it short. Clamps are conditional, so NaN settings pass through.