Skip to content

SDK 21's hardware Opus decoder manager and OutputStream - #1254

Closed
capibawa wants to merge 2 commits into
seedds:mainfrom
capibawa:sdk21-audio
Closed

capibawa wants to merge 2 commits into
seedds:mainfrom
capibawa:sdk21-audio

Conversation

@capibawa

@capibawa capibawa commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Xenoblade Chronicles 2's Switch 2 program (SDK 21.4.4) aborted at boot: 0xe15 in nn::codec, then 0xa99 from auddmg:u. SDK 21 decodes Opus through a hardware decoder manager and plays through an OutputStream on a virtual output device, and the host had neither.

hle_codec.c runs the manager's calls on the SDK's software decoder; hle_audio.c runs each OutputStream on the host's AudioOut (float planar or PCM16 converted to 16-bit blocks, 48 kHz only). Entries: SDK 21's OutputStream on a virtual output device, SDK 21's hardware Opus decoder manager.

Checked

  • Tests: t_output_stream (new) and t_audio in dm/host/tests.
  • Games run: Xenoblade Chronicles 2 Nintendo Switch 2 Edition 0400E95004038001 v1114112: boots past both aborts, through menus, opening and first battle, with the rest of the stack (its profile PR). Sound: on the Mac app, checked by ear after the layout fix (the first version read the interleaved frames as planar: an octave low, with crackling). Measured with DM_AUDIO_DUMP on a 4-minute route, before and after: energy above 20 kHz 16-39 % to 0.00 %, block-edge jump ratio 1.42 to 1.00, and 0 underruns in 48,000 callbacks of the real AudioUnit (muted). The measurements cover the opening only, no heavier gameplay. The OutputStream's PCM16 path has no game behind it.
  • Devices and OS: Apple M3 Pro, macOS 27.0.1.
  • Host change, new functions only: scripts/regress.py check --quick on Donkey Kong Bananza 040074A01BF12000, Fire Emblem Fortune's Weave 04007EF01F8AE000 and Hello Kitty Party Land 01001340271EC000, with all of this work together: PASS (0 newly failing, 0 changed MSL). These are the local builds; none has a route, so the harness ran no boot runs. Its report is from before the rebase on current main.

Docs

  • The finding is in its docs/reference/audio.md entry, and python3 dm/tools/docs_symptoms.py was run
  • No game files, keys or data extracted from a game in the change or the attachments

🤖 Generated with Claude Code

…me decodes and plays its sound instead of aborting at hwopus and auddmg:u

Xenoblade Chronicles 2's Switch 2 program (SDK 21.4.4) stopped at boot with abort 0xe15 from nn::codec: SDK 21 decodes Opus through a manager (GetHardwareOpusDecoderManagerWorkBufferSize, Initialize/Finalize, decoders made from it, packets enqueued, an Execute that decodes everything waiting, PCM dequeued, counts and a system event), which the host did not have. Past it, abort 0xa99 from auddmg:u: SDK 21 plays through an OutputStream on a virtual output device (GetDefaultVirtualOutputDevice, OpenOutputStream with float planar or PCM16 frames, Start/Stop/Close/Purge, state, free frame count, Write, gain, statistics), which the host did not have either.

hle_codec.c now runs the manager on the SDK's software decoder: an enqueued packet takes an I/O buffer, Execute decodes all waiting packets with DecodeOpusInterleaved (silence and a red line on a failure) and signals the manager's event, Dequeue hands back the 20 ms frame; the existing Finalize/Reset hooks also release a manager decoder. hle_audio.c runs each OutputStream on the host's AudioOut: a write converts the frames to one 16-bit interleaved block, the free frame count follows what was played, the release event fires; 48 kHz only.

Checked: t_output_stream (new: the block layout and clamping, 100 ms played in real time with release events, a purge after a stop, the states, a 44.1 kHz open refused) and t_audio; Xenoblade Chronicles 2's Switch 2 program boots past both, through its menus, opening and first battle on the Mac (headless, silent sink: the sound itself has not been heard). Docs: two entries in docs/reference/audio.md, symptom index regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its pitch, without a jump every block

Xenoblade Chronicles 2's Switch 2 program sounded an octave low with crackling (voices very deep), heard on the Mac app. WriteOutputStream takes interleaved frames (L, R, L, R), and the host read them as one run per channel, misled by the game's code that zeroes an unfilled tail (main+0xad1684) stepping by a period per channel: each 10 ms block's first half played as left and its second half as right, each at half speed, with a jump at every block. t_output_stream asserted the same wrong layout.

The block now keeps the order it is given (float scaled and clamped to 16 bits, PCM16 copied). The PCM16 path has no game behind it; it takes the same layout by reasoning, not measurement.

Checked on the same 4-minute route with DM_AUDIO_DUMP: energy above 20 kHz from 16-39 % to 0.00 %, left channel lag-1 autocorrelation from 0.18-0.64 to 0.99+, jumps at block edges from 1.42 times those elsewhere to 1.00, and through the real AudioUnit (muted) 0 underruns in 48,000 device callbacks. By ear on the rebuilt Mac app: sounds right. t_output_stream now checks the interleaved order. Docs: docs/reference/audio.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@seedds

seedds commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Landed in 67f1d00 with you credited as co-author, while bringing up Star Fox (same SDK, 21.4.4, Wwise 2024.1): your hle_audio.c and hle_codec.c pieces, t_output_stream and the reference entries, used instead of #1259's. Your state values (0 / 1 / 2) were the right ones, as the SDK and Star Fox's close path both show.

One change you should know about: GetOutputStreamStatistics now returns 24 bytes, not 32. Star Fox keeps its stack canary right behind the result (main+0xbce9b90), so 32 bytes ended in __stack_chk_fail. +0x10, the field the game reads, is unchanged. Also added for Star Fox: StartOutputStreams, GetOutputStreamFilledFrameCount and the input stream answers.

Xenoblade Chronicles 2 is not on this Mac, so this has not been run on it. Please retest it on main, and reopen this or file an issue if anything differs. Closing this PR since its contents are on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation host The Horizon host: SVCs, services, threads, memory (dm/host)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants