fluxer-audio clips: cache byte budget, stale audio under a cached key, decode cost at odd sample rates #119

Open
opened 2026-11-11 19:51:45 +00:00 by charles · 0 comments
Owner

Follow-up from the review of #118 (Voice 5, #66), seen on 313e865.

Clip cache has no byte budget. ClipCache keeps the 32 most recently used decoded clips (Voice spec §6). A decoded clip is 48 kHz stereo i16, so 30 s is about 5.8 MB and a full cache of 30 s sounds about 184 MB. This matches the spec; a byte budget on top of the count (evict least recently used until under, say, 64 MB) would bound it.

A cached key ignores new bytes. AudioEngine::play_clip ignores bytes when key is cached (documented in its rustdoc), so a sound whose audio changed under the same id would play the old audio until evicted. Whoever wires the callers (Voice 10 / 14) should either use a key that changes with the audio (id plus a content hash or version) or the engine should grow an explicit forget_clip(key).

Decoding cost at odd sample rates. Rates from 8 kHz to 192 kHz are accepted. A rate that shares no factor with 48 kHz (for example 191 999 Hz) makes the FFT resampler work in one-second blocks: a 29 s mono clip at 191 999 Hz took 8.9 s to decode in a debug build on the calling thread (bounded by the 30 s and 20 MiB limits, no crash; release not measured). If play_clip ends up being called from the UI thread, decoding should move off it, or non-standard rates should go through a cheaper converter.

Follow-up from the review of #118 (Voice 5, #66), seen on 313e865. **Clip cache has no byte budget.** `ClipCache` keeps the 32 most recently used decoded clips (Voice spec §6). A decoded clip is 48 kHz stereo `i16`, so 30 s is about 5.8 MB and a full cache of 30 s sounds about 184 MB. This matches the spec; a byte budget on top of the count (evict least recently used until under, say, 64 MB) would bound it. **A cached key ignores new bytes.** `AudioEngine::play_clip` ignores `bytes` when `key` is cached (documented in its rustdoc), so a sound whose audio changed under the same id would play the old audio until evicted. Whoever wires the callers (Voice 10 / 14) should either use a key that changes with the audio (id plus a content hash or version) or the engine should grow an explicit `forget_clip(key)`. **Decoding cost at odd sample rates.** Rates from 8 kHz to 192 kHz are accepted. A rate that shares no factor with 48 kHz (for example 191 999 Hz) makes the FFT resampler work in one-second blocks: a 29 s mono clip at 191 999 Hz took 8.9 s to decode in a debug build on the calling thread (bounded by the 30 s and 20 MiB limits, no crash; release not measured). If `play_clip` ends up being called from the UI thread, decoding should move off it, or non-standard rates should go through a cheaper converter.
charles added this to the Voice milestone 2026-11-11 19:51:45 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/fluxer-native#119
No description provided.