Skip superblock directory in awc_extract.py, fixing stereo tracks decoded as mono #33

Manually merged
github merged 1 commit from gh-pr/33/head into gh-pr/33/base 2026-11-27 02:32:17 +00:00
Owner

@⁠worstgirlinamerica on GitHub · 2026-11-22 03:24 UTC · original
worstgirlinamerica:fix/awc-extract-superblock-stereo → main · +138 −38 · 1 files · 1 commits · merged 2026-11-22 10:20 UTC

Summary

awc_extract.py read AWC data chunks flat from byte 0, treating the
superblock directory (0xFFFFFFFF marker + per-block count table) as
[u16 len][payload] Opus packets. Count-table integers in subsequent
blocks can look like valid in-bounds lengths, feeding bogus entries
into the packet list. Channel detection only checked packets[0], so
if a directory misread landed there, its arbitrary bit pattern decided
mono vs. stereo for the whole track -- while duration stayed accurate
(one bad packet among ~10,000), masking the bug entirely.

Confirmed live: unmodified main outputs channels=1 on
sound_4183_2st.awc despite every real audio frame's TOC byte reading
STEREO=True.

Changes

  • Ported probe_superblock_streams + packets_for_superblock_substream
    from src/awc.rs (PR #10) so directory bytes are skipped before
    packet collection begins
  • Replaced packets[0] channel check with channels_from_packets(),
    which uses the largest packet -- guards against a leading DTX/silence
    frame flipping the decision
  • Multi-substream chunks now write one file per substream (_s00_0,
    _s00_1, ...) instead of silently dropping all but substream 0
  • Non-superblock chunks fall back to the original flat
    collect_2kb_packets walk -- no behavior change on plain/SFX-bank AWCs

Testing

  • sound_4183_2st.awc (superblock-packed, stereo music track):
    • duration: 200.04s before and after (unchanged)
    • channels: 1 (mono) before -> 2 (stereo) after
    • cross-checked against independent community rip (200.0065s, 2ch)
      and a manual libopus decode -- all three agree
  • sound_4659_271st.awc (271 non-superblock SFX chunks):
    • output unchanged, correctly mono per-chunk -- no regression"
**@⁠worstgirlinamerica** on GitHub · 2026-11-22 03:24 UTC · [original](https://github.com/rpatty-dev/PercyStar/pull/33) `worstgirlinamerica:fix/awc-extract-superblock-stereo` → `main` · +138 −38 · 1 files · 1 commits · merged 2026-11-22 10:20 UTC ## Summary awc_extract.py read AWC data chunks flat from byte 0, treating the superblock directory (0xFFFFFFFF marker + per-block count table) as [u16 len][payload] Opus packets. Count-table integers in subsequent blocks can look like valid in-bounds lengths, feeding bogus entries into the packet list. Channel detection only checked packets[0], so if a directory misread landed there, its arbitrary bit pattern decided mono vs. stereo for the whole track -- while duration stayed accurate (one bad packet among ~10,000), masking the bug entirely. Confirmed live: unmodified main outputs channels=1 on sound_4183_2st.awc despite every real audio frame's TOC byte reading STEREO=True. ## Changes - Ported probe_superblock_streams + packets_for_superblock_substream from src/awc.rs (PR #10) so directory bytes are skipped before packet collection begins - Replaced packets[0] channel check with channels_from_packets(), which uses the largest packet -- guards against a leading DTX/silence frame flipping the decision - Multi-substream chunks now write one file per substream (_s00_0, _s00_1, ...) instead of silently dropping all but substream 0 - Non-superblock chunks fall back to the original flat collect_2kb_packets walk -- no behavior change on plain/SFX-bank AWCs ## Testing - sound_4183_2st.awc (superblock-packed, stereo music track): - duration: 200.04s before and after (unchanged) - channels: 1 (mono) before -> 2 (stereo) after - cross-checked against independent community rip (200.0065s, 2ch) and a manual libopus decode -- all three agree - sound_4659_271st.awc (271 non-superblock SFX chunks): - output unchanged, correctly mono per-chunk -- no regression"
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:32:14 +00:00
github manually merged commit 4d33c075e0 into gh-pr/33/base 2026-11-27 02:32:17 +00:00
Author
Owner

@⁠worstgirlinamerica on GitHub · 2026-11-22 04:02 UTC · original

I also for extra reference, compared my output against a community .opus rip of the same file / song which results in the exact same file size and type.

This is the community 3.07MB opus file:

Complete name                            : 017 - SLAYYYTER - INTERNET $TAR [05217731].opus
Format                                   : Ogg
File size                                : 3.07 MiB
Duration                                 : 3 min 20 s
Overall bit rate                         : 129 kb/s
Audio
Format                                   : Opus
Duration                                 : 3 min 20 s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz'

vs what this PR resolves for .opus files:

General
Complete name                            : sound_4183_2st_s00.opus
Format                                   : Ogg
File size                                : 3.07 MiB
Duration                                 : 3 min 20 s
Overall bit rate                         : 129 kb/s

Audio
Format                                   : Opus
Duration                                 : 3 min 20 s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
**@⁠worstgirlinamerica** on GitHub · 2026-11-22 04:02 UTC · [original](https://github.com/rpatty-dev/PercyStar/pull/33#issuecomment-7073946377) I also for extra reference, compared my output against a community .opus rip of the same file / song which results in the exact same file size and type. This is the community 3.07MB opus file: ```General Complete name : 017 - SLAYYYTER - INTERNET $TAR [05217731].opus Format : Ogg File size : 3.07 MiB Duration : 3 min 20 s Overall bit rate : 129 kb/s Audio Format : Opus Duration : 3 min 20 s Channel(s) : 2 channels Channel layout : L R Sampling rate : 48.0 kHz' ``` vs what this PR resolves for .opus files: ``` General Complete name : sound_4183_2st_s00.opus Format : Ogg File size : 3.07 MiB Duration : 3 min 20 s Overall bit rate : 129 kb/s Audio Format : Opus Duration : 3 min 20 s Channel(s) : 2 channels Channel layout : L R Sampling rate : 48.0 kHz ```
Author
Owner

@⁠rpatty-dev on GitHub · 2026-11-22 10:21 UTC · original · edited 2026-11-22 10:30 UTC

Merged onto main and released in v1.4.3! Also optimized collect_2kb_packets in scripts/awc_extract.py with memoryview slicing to avoid intermediate block copies, and ported your largest-packet TOC channel fix into native src/awc.rs so the built-in Rust player gets the same stereo fix. Great catch!

**@⁠rpatty-dev** on GitHub · 2026-11-22 10:21 UTC · [original](https://github.com/rpatty-dev/PercyStar/pull/33#issuecomment-7077735094) · edited 2026-11-22 10:30 UTC Merged onto main and released in v1.4.3! Also optimized `collect_2kb_packets` in `scripts/awc_extract.py` with `memoryview` slicing to avoid intermediate block copies, and ported your largest-packet TOC channel fix into native `src/awc.rs` so the built-in Rust player gets the same stereo fix. Great catch!
This discussion has been locked. Commenting is limited to contributors.
No description provided.