feat(audio): add multi-stream XMA2 decoding, WAVEFORMATEXTENSIBLE, and streaming voice control (#26) #189

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

@⁠Lewandox on GitHub · 2026-11-25 01:13 UTC · original
Lewandox:feat/audio-multistream-xma2 → main · +810 −52 · 7 files · 1 commits · closed without merging

Summary

Adds multi-stream XMA2 decoding (1–4 streams, 1–8 channels including 5.1 / 7.1 surround), full XMA2WAVEFORMATEX header parsing/validation, WAVEFORMATEXTENSIBLE export, and a streaming Xma2Voice decoder with the synthetic 2,048 / 512 / guard-byte / disabled-voice verification control requested in Issue #26.

What changed

  • rust/anyxboxx-audio/src/multistream.rs:
    • Adds stream_channel_layout(channels, streams) supporting mono through 7.1 (1..=8 channels across 1..=4 streams).
    • Implements MultiStreamDecoder using FFmpeg's packet_skip_count packet-routing algorithm (libavcodec/wmaprodec.c, LGPL-2.1+), handling round-robin multi-stream routing, burst skip == 0 packets, 0xFF end-of-block sentinels, XMA2 block-boundary resets (BytesPerBlock), frame interleaving, EOF flush, and SamplesEncoded / PlayBegin / PlayLength trimming.
  • rust/anyxboxx-audio/src/voice.rs:
    • Implements Xma2Voice: incremental FIFO-backed PCM voice decoder with submit_packets, pending_frames, set_enabled, render_pcm, and render_pcm_bytes (leaves output buffers untouched when disabled, preserves pending queued samples across partial refills, and never writes past the destination slice).
  • rust/anyxboxx-audio/src/lib.rs & src/main.rs:
    • Extends Xma2Format and parse() to read and validate all 52 bytes of XMA2WAVEFORMATEX (while keeping minimal 20-byte headers supported).
    • Routes decode() through MultiStreamDecoder so multi-stream files decode cleanly instead of erroring.
    • Adds wav_extensible(channels, sample_rate, channel_mask, samples) (WAVEFORMATEXTENSIBLE 0xFFFE) and CLI options --info <in.xma> and --extensible.
  • Tests & READMEs:
    • Adds rust/anyxboxx-audio/tests/multistream_and_voice.rs (5 integration tests including the exact synthetic 48 kHz mono 2,048 → 512 refill / 1,536 pending / 256 guard-byte / disabled-voice check from #26).
    • Adds 2 CLI tests in tests/test_audio.py (5.1 6-channel WAV decode and --info metadata) and updates the test count (658 → 660) across all 9 READMEs.

Verification

  • cargo build --release --manifest-path rust/Cargo.toml -p anyxboxx-audio — clean build.
  • cargo test --release --manifest-path rust/Cargo.toml -p anyxboxx-audio — 9 passed, 0 failed (4 unit + 5 integration tests).
  • cargo clippy --manifest-path rust/Cargo.toml -p anyxboxx-audio --all-targets -- -D warnings — 0 warnings.
  • python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools — passed.
  • python -m pytest -q — full suite passed (tests/test_audio.py: 4/4 passed; tests/test_readme_sync.py: 660 tests synced across all 9 languages).

Refs #26

**@⁠Lewandox** on GitHub · 2026-11-25 01:13 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/189) `Lewandox:feat/audio-multistream-xma2` → `main` · +810 −52 · 7 files · 1 commits · closed without merging ## Summary Adds multi-stream XMA2 decoding (1–4 streams, 1–8 channels including 5.1 / 7.1 surround), full `XMA2WAVEFORMATEX` header parsing/validation, `WAVEFORMATEXTENSIBLE` export, and a streaming `Xma2Voice` decoder with the synthetic 2,048 / 512 / guard-byte / disabled-voice verification control requested in Issue #26. ### What changed - **`rust/anyxboxx-audio/src/multistream.rs`**: - Adds `stream_channel_layout(channels, streams)` supporting mono through 7.1 (`1..=8` channels across `1..=4` streams). - Implements `MultiStreamDecoder` using FFmpeg's `packet_skip_count` packet-routing algorithm (`libavcodec/wmaprodec.c`, LGPL-2.1+), handling round-robin multi-stream routing, burst `skip == 0` packets, `0xFF` end-of-block sentinels, XMA2 block-boundary resets (`BytesPerBlock`), frame interleaving, EOF flush, and `SamplesEncoded` / `PlayBegin` / `PlayLength` trimming. - **`rust/anyxboxx-audio/src/voice.rs`**: - Implements `Xma2Voice`: incremental FIFO-backed PCM voice decoder with `submit_packets`, `pending_frames`, `set_enabled`, `render_pcm`, and `render_pcm_bytes` (leaves output buffers untouched when disabled, preserves pending queued samples across partial refills, and never writes past the destination slice). - **`rust/anyxboxx-audio/src/lib.rs` & `src/main.rs`**: - Extends `Xma2Format` and `parse()` to read and validate all 52 bytes of `XMA2WAVEFORMATEX` (while keeping minimal 20-byte headers supported). - Routes `decode()` through `MultiStreamDecoder` so multi-stream files decode cleanly instead of erroring. - Adds `wav_extensible(channels, sample_rate, channel_mask, samples)` (`WAVEFORMATEXTENSIBLE` 0xFFFE) and CLI options `--info <in.xma>` and `--extensible`. - **Tests & READMEs**: - Adds `rust/anyxboxx-audio/tests/multistream_and_voice.rs` (5 integration tests including the exact synthetic 48 kHz mono 2,048 → 512 refill / 1,536 pending / 256 guard-byte / disabled-voice check from #26). - Adds 2 CLI tests in `tests/test_audio.py` (5.1 6-channel WAV decode and `--info` metadata) and updates the test count (`658` → `660`) across all 9 READMEs. ### Verification - `cargo build --release --manifest-path rust/Cargo.toml -p anyxboxx-audio` — clean build. - `cargo test --release --manifest-path rust/Cargo.toml -p anyxboxx-audio` — **9 passed, 0 failed** (4 unit + 5 integration tests). - `cargo clippy --manifest-path rust/Cargo.toml -p anyxboxx-audio --all-targets -- -D warnings` — 0 warnings. - `python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools` — passed. - `python -m pytest -q` — full suite passed (`tests/test_audio.py`: 4/4 passed; `tests/test_readme_sync.py`: 660 tests synced across all 9 languages). Refs #26
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:36:23 +00:00
github-bot closed this pull request 2026-11-26 05:36:23 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-25 15:00 UTC · original

Closed by the maintainer during PR triage: since #199, VIctory lives in this repository and is what runs the game. It already has its own XMA decoder (third_party/victory/crates/victory-formats/src/xma.rs) and GFX10 texture tiling (victory-formats/src/texture.rs), while rust/anyxboxx-* is only used by a test. Improvements in this area should go to VIctory's crates instead. Thanks for the work.

**@⁠LooperSalty** on GitHub · 2026-11-25 15:00 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/189#issuecomment-7166159394) Closed by the maintainer during PR triage: since #199, VIctory lives in this repository and is what runs the game. It already has its own XMA decoder (`third_party/victory/crates/victory-formats/src/xma.rs`) and GFX10 texture tiling (`victory-formats/src/texture.rs`), while `rust/anyxboxx-*` is only used by a test. Improvements in this area should go to VIctory's crates instead. Thanks for the work.

Pull request closed

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