@maruaudio/dsp/voices/serial-voice-pool chooses the slot a new voice starts in: the lowest free slot, else the sounding slot with the lowest age, where the age is a monotonic serial the caller stamped when that voice started. Stealing by serial rather than by slot position makes "oldest" unambiguous wherever a voice landed. The source header says it was extracted unchanged from @maru/voices-sampler-zone. It is a different policy from @maru/voices-polyphonic-pool (same-note retrigger, f32 ages, 16 slots).
Parameters
Argument of freeOrOldestVoiceSlot | Meaning |
|---|---|
active: Uint8Array | Non-zero while a slot sounds |
age: Uint32Array | The serial stamped at the voice's start |
capacity | Slots in use; loops stop at SERIAL_VOICE_POOL_MAX_SLOTS (96) with capacity as the inner guard |
The function returns a slot index. active[slot] !== 0 on the result means the slot was stolen.
Lifecycle
Pure over the caller's arrays: there is no init or reset. The caller retires a stolen slot before reusing it, then stamps age[slot] from its own strictly increasing serial.
When to use it
A sampler or drum voice pool where the oldest sounding voice should give way when the pool is full, and where the same note may sound in several slots at once.
Limits
- At most 96 slots; arrays longer than that are not scanned past slot 95.
- Ties in age go to the lowest slot; a capacity of 0 returns slot 0.
- The leaf does not retire, fade or stamp anything; voice DSP belongs to the composing instrument.