Audio: read the codec id at 0x1C; export PCM as WAV and XMA2 as RIFF XMA2 #11

Closed
github-bot wants to merge 1 commit from gh-pr/11/head into gh-pr/11/base
Owner

@⁠Ahmet-Dedeler on GitHub · 2026-11-22 17:33 UTC · original
Ahmet-Dedeler:feat/xma2-pcm-audio → master · +267 −22 · 4 files · 1 commits · closed without merging

What

The AWC format-chunk codec was read from byte 0x13. In the 32-byte format chunk that every audio.rpf stream uses, the codec id is at 0x1C and the channel count at 0x1D (TrinitronClient/GTA6-Asset-Info structure/03-audio-awc.md). Byte 0x13 is 0 on all PCM streams and on 268 XMA2 streams. So 514 non-Opus streams were exported as "Opus" noise, and 1,550 were raw-only.

Real census of audio.rpf with this change: 1,598,051 Opus, 3,008 music, 1,818 XMA2 (mono, 32 kHz), 227 float32 PCM, 19 PCM16, 3,118 with no data.

Changes

  • Layouts pcm16, pcmf32 and xma2 (index codes 4-6). The index gets version: 2. Older indexes return an error asking for a rescan: the CLI rescans by itself, the GUI shows its Scan button.
  • PCM goes to WAV with samples as stored (16-bit, or IEEE float with a fact chunk), cut to the header's sample count.
  • XMA2 data is whole 2 KiB XMA2 packets, with a seek table of one u32 per packet. It goes to .xma: RIFF WAVE with an XMA2WAVEFORMATEX fmt chunk (tag 0x166, cbSize 34, PlayLength = header samples). This is a lossless remux. No new dependencies: I found no permissive pure-Rust XMA2 decoder.
  • GUI: codec labels and .wav/.xma export buttons. CLI help updated, README audio row updated. Unit tests on synthetic data (WAV headers, XMA2 header fields, frame count, index tuple).

Checker (all 2,064 non-Opus streams, local audio.rpf)

  • Before (origin/master): 0 correct. 1,641 refused, 423 written by decoding PCM/XMA2 bytes as Opus.
  • After: 2,064/2,064 export.
    • PCM: 246/246 bit-exact. The sample count equals the header, and FFmpeg decodes every file without errors.
    • XMA2: 1,818/1,818 decode in FFmpeg 9.0.2 without errors. The packet frame count × 512 equals the header sample count on all 1,818. FFmpeg's decoded output is 384-768 samples shorter than the header (−512 on 841 streams, −640 on 346, −384 on 314, −768 on 311, about 1 sample off on the 6 streams with odd rate fields). That gap fits FFmpeg dropping the first frame and honouring the in-stream trim, but it is not proven.
  • Opus regression check on bank 12a2000: 44 files, FFmpeg clean.
**@⁠Ahmet-Dedeler** on GitHub · 2026-11-22 17:33 UTC · [original](https://github.com/holdmysocks/SixNG/pull/11) `Ahmet-Dedeler:feat/xma2-pcm-audio` → `master` · +267 −22 · 4 files · 1 commits · closed without merging ## What The AWC format-chunk codec was read from byte 0x13. In the 32-byte format chunk that every audio.rpf stream uses, the codec id is at 0x1C and the channel count at 0x1D (TrinitronClient/GTA6-Asset-Info structure/03-audio-awc.md). Byte 0x13 is 0 on all PCM streams and on 268 XMA2 streams. So 514 non-Opus streams were exported as "Opus" noise, and 1,550 were raw-only. Real census of audio.rpf with this change: 1,598,051 Opus, 3,008 music, 1,818 XMA2 (mono, 32 kHz), 227 float32 PCM, 19 PCM16, 3,118 with no data. ## Changes - Layouts pcm16, pcmf32 and xma2 (index codes 4-6). The index gets `version: 2`. Older indexes return an error asking for a rescan: the CLI rescans by itself, the GUI shows its Scan button. - PCM goes to WAV with samples as stored (16-bit, or IEEE float with a fact chunk), cut to the header's sample count. - XMA2 data is whole 2 KiB XMA2 packets, with a seek table of one u32 per packet. It goes to `.xma`: RIFF WAVE with an XMA2WAVEFORMATEX fmt chunk (tag 0x166, cbSize 34, PlayLength = header samples). This is a lossless remux. No new dependencies: I found no permissive pure-Rust XMA2 decoder. - GUI: codec labels and .wav/.xma export buttons. CLI help updated, README audio row updated. Unit tests on synthetic data (WAV headers, XMA2 header fields, frame count, index tuple). ## Checker (all 2,064 non-Opus streams, local audio.rpf) - Before (origin/master): 0 correct. 1,641 refused, 423 written by decoding PCM/XMA2 bytes as Opus. - After: 2,064/2,064 export. - PCM: 246/246 bit-exact. The sample count equals the header, and FFmpeg decodes every file without errors. - XMA2: 1,818/1,818 decode in FFmpeg 9.0.2 without errors. The packet frame count × 512 equals the header sample count on all 1,818. FFmpeg's decoded output is 384-768 samples shorter than the header (−512 on 841 streams, −640 on 346, −384 on 314, −768 on 311, about 1 sample off on the 6 streams with odd rate fields). That gap fits FFmpeg dropping the first frame and honouring the in-stream trim, but it is not proven. - Opus regression check on bank 12a2000: 44 files, FFmpeg clean.
The codec was read from byte 0x13 of the format chunk. In the 32-byte form
used by every stream in audio.rpf the codec id is the byte at 0x1C and the
channel count the byte at 0x1D (11 Opus, 0 PCM16, 2 PCM float32, 5 XMA2;
GTA6-Asset-Info structure/03). Byte 0x13 is 0 on all PCM streams and on
268 XMA2 streams, so 514 non-Opus streams were treated as Opus blocks and
exported as noise, and the 1,550 with a non-zero byte were raw-only.

- New layouts pcm16, pcmf32 and xma2 (index codes 4-6); the index gets a
  version and older indexes ask for a rescan.
- PCM exports as WAV with the samples as stored (16-bit integer, or 32-bit
  float with a fact chunk), cut to the format chunk's sample count.
- XMA2 data is whole 2 KiB XMA2 packets (one seek-table entry per packet).
  It is remuxed losslessly to RIFF WAVE with an XMA2WAVEFORMATEX fmt chunk
  (.xma); FFmpeg's xma2 decoder reads it.
- GUI: codec labels and .wav / .xma export buttons for these streams.

Checked on audio.rpf (all 2,064 non-Opus streams): every stream exports;
PCM 246/246 bit-exact, sample count equal to the header and decoded by
FFmpeg without errors; XMA2 1,818/1,818 decoded by FFmpeg without errors,
and the packets' frame count x 512 equals the header sample count on all.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:02:58 +00:00
github-bot closed this pull request 2026-11-26 20:02:58 +00:00
Author
Owner

@⁠holdmysocks on GitHub · 2026-11-22 17:41 UTC · original

Squash-merged into master as 908a301, with small wording edits (source comment and tool names in the README/GUI text). Thanks!

**@⁠holdmysocks** on GitHub · 2026-11-22 17:41 UTC · [original](https://github.com/holdmysocks/SixNG/pull/11#issuecomment-7083028796) Squash-merged into master as 908a301, with small wording edits (source comment and tool names in the README/GUI text). Thanks!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.