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

Closed
Lewandox wants to merge 1 commit from upstream-pr/189 into main
Lewandox commented 2026-11-25 01:13:23 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Lewandox on 2026-11-25T01:13:23Z.


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

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:6594830087 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/189). Originally posted by [Lewandox](https://github.com/Lewandox) on 2026-11-25T01:13:23Z. --- ## 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
LooperSalty commented 2026-11-25 15:00:35 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-25T15:00:35Z.


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.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7166159394 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/189#issuecomment-7166159394). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-25T15:00:35Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LooperSalty/AnyXboxX!189
No description provided.