Files
andeecollard 9935d82215 fix(apu): ADPCM's reserved header byte is not validated, and the step index is clamped
adpcm_decode_block refused any block whose fourth header byte was non-zero
or whose step index was outside 0..88, returning 0 frames -- after it had
already written the first sample of each channel. The MCPX does neither:
the byte is reserved in the format, not checked by the decoder. Titles ship
such blocks. Jet Set Radio Future ends every ADPCM buffer in a 0x08 pad, and
3.5-4.4% of its blocks were silenced, measured in play.

The index is now clamped, as the per-nibble update already clamps it. It has
to be clamped rather than trusted, because step_table has 89 entries; the
byte is read as int8_t, so values above 127 arrive negative.

tests/adpcm_decode checks a block with the reserved byte set decodes
identically to the same block with it clear, the all-0x08 pad block, and
out-of-range indices (100, and 200 which is negative as int8_t). Five of its
checks fail against the previous decoder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017QvivF8psGzR3Ws8tv21Ut
2026-09-24 00:32:45 +01:00
..