← Gallery File I/O — WAV save, reload, chunked reading

File I/O — WAV save, reload, chunked reading

scripts/xa-file.js + scripts/xa-fileio.js

Save a tone out as a WAV file, load it straight back in, and check that nothing was lost — the original and reloaded waveforms are drawn on top of each other below and should coincide. A sample cache proves repeat loads skip the network entirely, and a chunked reader slices a long tone into equal blocks without dropping a sample. The three automated proofs: (1) saveAudio (post-repair: delegates to the canonical io/wav.encodeWav and returns the Blob) writes a 1 s 440 Hz tone that loadFile reloads within the 16-bit quantization bound; (2) example()/exampleBuffer() exercise the AudioCache against a local fixture (fixtures/trumpet.ogg — WAV bytes; the remote sample registry stays unverified, see barrel note) proving entries+1 after first load and a zero-network cache hit on the second; (3) fileio.stream() (post-repair docs: chunked reader, NOT streaming frame-generator semantics) splits a 3 s tone into exactly ⌈N/2048⌉ lossless blocks. Chunk math node-verified 2026-07-02 via injected decoder (65 blocks, bitwise re-concat). Saving triggers one real download of pleco-tone-440.wav — that side effect is the point.

original (blue) vs reloaded (orange, drawn on top)

cache stats



live mic RMS (manual, optional)