Skip to content

wav_chunks: one public RIFF chunk walker, fast overrun scan - #16

Merged
thorwhalen merged 3 commits into
masterfrom
wav-chunks-public
Nov 9, 2026
Merged

thorwhalen merged 3 commits into
masterfrom
wav-chunks-public

Conversation

@thorwhalen

Copy link
Copy Markdown
Member

Adds recode.wav_chunks(wav_bytes) (yields WavChunk(chunk_id, offset, size)), the one RIFF chunk walker asked for in thorwhalen/voxy#85; voxy then drops its own and imports this. decode_wav_bytes / _wav_data_chunk now locate data through it, so recode has one walker too. A data chunk whose declared size is a placeholder (0, or past the end) ends where the chunks after it begin, or at the end of the buffer. The scan for that point is now fast: known trailing ids (LIST, id3, bext, ...) are matched first by a compiled regex, then any printable-ASCII id; 10 minutes of 24 kHz audio takes about 0.26 s (it took several seconds scanning every word in Python). A trailer missing its final pad byte is accepted.

Behaviour change: declared size 0 followed by other chunks now decodes the audio (it decoded zero samples before). No test pinned the old result.

Adversarial review (Fable): first version not landable: the fast known-id pass was dead code (my edit had not applied), the missing-pad-byte trailer regressed against voxy's walker, and decode_wav_bytes still used a second walker while the docstring said otherwise. Fixed all three, plus WavChunk as a NamedTuple, private id table, tests for printable-audio, missing pad byte, bytearray/memoryview input and decode_wav_bytes agreeing with wav_chunks. Left as documented quirk: an unknown chunk ahead of a known one is read as audio.

164 passed (156 before + 8 new), doctests pass.

@thorwhalen
thorwhalen merged commit 3195273 into master Nov 9, 2026
4 checks passed
@thorwhalen
thorwhalen deleted the wav-chunks-public branch November 9, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant