stb_vorbis cut a type-2 residue's interleaved vector at n * 2 values even when its submap holds more channels, so the rest of the packet was read as the wrong data: the 5.1 tracks libvorbis encodes came out distorted and gurgling, with pops. The bound is now n * ch, as in the Vorbis spec and libvorbis's res2_inverse, and the temporary-memory estimate for a caller-owned buffer counts every channel of the stream for type-2 residues (with the decode fix alone, a 6-channel stream overran the advertised buffer). Upstream stb still has the bug (nothings/stb #879, #1594). Link's Awakening's opening and title movies were the report; DRAGON QUEST XI S's movies open only 6-channel Vorbis tracks too. Its 23 6-channel cutscene and title tracks, decoded as the host does, now match FFmpeg to within 0.02 PCM16 units, where main's decoder was off by an RMS of 1,700 to 70,000 units. dm/host/tests/t_vorbis builds tiny Vorbis streams in memory (types 0/1/2, mono to 8 channels, two submaps) and checks heap and fixed-buffer decoding through the pull and push APIs, with and without STB_VORBIS_DIVIDES_IN_RESIDUE; it needs no game profile. dmhost rebuilds when stb_vorbis.c changes. On top of the PR: the test rules sit with the others, and the stb_vorbis README and the per-game notes say what the fix repairs. Co-authored-by: ohxiaoguang <44696970+ohxiaoguang@users.noreply.github.com>
1.1 KiB
Source: https://github.com/nothings/stb stb_vorbis.c at commit 1ee679c (version 1.22). License in LICENSE (MIT or public domain, your choice; the same text ends the source file).
Use: the host decodes the Vorbis sound tracks of the games' WebM movies with it (dm/host/hle_movie.c includes the file with STB_VORBIS_NO_STDIO, STB_VORBIS_NO_PULLDATA_API and STB_VORBIS_NO_INTEGER_CONVERSION, and feeds each raw packet in as an Ogg page of its own). First needed by Link's Awakening.
Local change (GitHub PR #60; upstream still has the bug, nothings/stb issues #879 and #1594): a type-2 residue interleaves every channel of its submap, so decode_residue reads up to n × the submap's channel count values, not n × 2, and start_decoder's temporary-memory estimate for a caller-owned buffer counts every channel of the stream for type-2 residues. Without it the 5.1 tracks libvorbis encodes (Link's Awakening's and DRAGON QUEST XI S's movies) come out distorted (gurgling, with pops, in Link's Awakening). Regression test: make -C dm/host/tests build/t_vorbis build/t_vorbis_divides, then run both binaries.