Repository navigation
fix(stb_vorbis): correct type-2 residue size for multichannel audio - #60
Closed
ohxiaoguang wants to merge 1 commit into
Closed
ohxiaoguang wants to merge 1 commit into
ohxiaoguang wants to merge 1 commit into
Conversation
Use the actual submap channel count when bounding interleaved type-2 residues. Reserve enough classification scratch memory for all stream channels when reporting caller-owned arena requirements. Track the included decoder in the Mac host's dependencies and add synthetic mono/stereo/multichannel regression coverage for heap and fixed-buffer decoding through both pull and push APIs.
ohxiaoguang
force-pushed
the
fix/stb-vorbis-multichannel-residue
branch
from
October 22, 2026 16:04
7018994 to
9be3041
Compare
seedds
added a commit
that referenced
this pull request
Oct 22, 2026
…es span every channel of their submap (GitHub PR #60) 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 <[email protected]>
Owner
|
Thanks @ohxiaoguang, this is in main as e10277b (e10277b), with you as co-author. It takes the type-2 bound ( |
Know-It-All-Brother
pushed a commit
to Know-It-All-Brother/nxnative
that referenced
this pull request
Nov 9, 2026
…es span every channel of their submap (GitHub PR seedds#60) 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 seedds#879, seedds#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 <[email protected]>
theorigden
pushed a commit
to theorigden/nxnative
that referenced
this pull request
Nov 17, 2026
The frame step counted in vsyncs of 1/60 s, so a hold could only be 16.7 or 33.3 ms: a device whose GPU takes 17-24 ms a frame (TotK on an M1 iPad Pro) dropped from 60 to 30 with time to spare. A 120 Hz screen can show a frame for three refreshes, 25 ms. - State page +0x2c: the step's ticks a second (float), 60 from the loader. TotK's stub reads it (same instruction count: ldr s3 for fmov seedds#30, fcvtzu for the fadd, a nop for mov seedds#60) and declares FRAME_STEP_120 (fixups.tsv, the loader's dm_fps_step_120). - hle_nvn.c fs_ticks: for such stubs on a screen that shows 120 Hz, the frame step counts in ticks of 1/120 s (decided at the first present), the display link runs at 120 Hz, and a 40 target is a hold of 3; at 60, late frames go to 40 before 30. The link callback holds 25 ms frames for their period (was > 25 ms only). A screen that drops to 60 Hz (Low Power Mode) runs 40 at 30 and keeps the cap's hold. DM_FSTEP_120=0 keeps 1/60 s; =1 takes 1/120 s on any screen (tests). - nvn_fstep.h: holds and steps up to FSTEP_KMAX (6 ticks, the stub's 3 vsyncs); FSTEP_MAX stays the default largest step. - DM_FPS_TARGET=40 in the loader, the live setting and settings.tsv (offered with fixups:FRAME_STEP_120). - Docs: frame-rate.md entry, settings.md, env_switches.tsv, the TotK note; symptom and patch indexes. Checked: host build; host, graphics (t_fstep: 40 fps holds 3 ticks at game time = real time; at 60, 2.6-tick frames step to 3, 3.5 to 4) and docs / settings tests. TotK headless with DM_FPS_TARGET=40 DM_FSTEP_120=1 on the Mac (M1 Max): two windows of 1,800 frames, every frame held 3 ticks (25.0 ms), game time 45.00 and 45.02 s in 45.00 s (1.000 of real time), GPU 17-23 ms, no red lines. The rewritten main has the new stub (TotK's work folder, patched_v720896). Not yet run on a 120 Hz screen (the Mac's display is a 60 Hz external one, where 40 falls back to 30 as designed). Front-ends: DM_FPS_TARGET has a new value, 40, offered where the fixups name FRAME_STEP_120 (dm/games/settings.tsv). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
5.1 Vorbis movie audio in Link's Awakening can sound distorted/gurgling, with occasional pops, from the opening through the title screen.
decode_residue()clamps the interleaved type-2 residue vector ton * 2, even when its submap contains more than two channels. This truncates the residue decode and leaves subsequent encoded data misinterpreted.Changes
n * chfor type-2 residues, wherechis the actual submap channel count; types 0 and 1 retain their existing bounds.start_decoder()'s temporary-memory estimate for type-2 residues. The stream channel count is a conservative upper bound for any submap. Fixing only the decode bound can otherwise exceed the advertised caller-owned arena size.stb_vorbis.ctodmhost's prerequisites so incremental Mac builds pick up decoder changes.Validation
Run the synthetic regressions without a game profile, encoder, audio device, or game data:
STB_VORBIS_DIVIDES_IN_RESIDUEbuilds pass all 10 scenarios (four heap/arena and pull/push combinations each).The vendored file still carries this bug in
nothings/stbmaster. Related upstream reports: #879, #1594. stb PR #1487 addresses the related scratch-space underestimate for the existing stereo bound; the estimate here also accounts for the corrected multichannel bound.