XAudio2: pure-Rust XMA1/XMA2 audio decoder #20
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!20
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/20/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@raylitebull on GitHub · 2026-11-21 21:31 UTC · original
raylitebull:xma2-decoder→main· +3164 −125 · 9 files · 1 commits · merged 2026-11-21 22:50 UTCImplements real XMA1 (
0x0165) and XMA2 (0x0166) audio decoding for XAudio2 on top of currentmainin pure safe Rust — closing out the remaining audio gap listed inREADME.mdandcrates/xcl/src/hle/xaudio2.rswith zero external runtime DLLs and zero new Cargo dependencies.The decoder and static Huffman/DSP tables are cleanly ported from FFmpeg's LGPL-2.1+
wmaprodec.c/wmaprodata.h/wma.c/sinewin_tablegen.h/float_dsp.c/tx_template.c(GPL-2.0-only compatible under LGPL-2.1 §3, with GPL-2.0 §2a provenance headers in the files andTHIRD_PARTY.md).Summary of changes
crates/xcl/src/hle/xma2/(mod.rs,tables.rs)StreamConfig): supportsXMA2WAVEFORMATEX(cbSize == 34), legacyXMA2WAVEFORMAT(rev 3/4), andXMAWAVEFORMAT(0x0165), up to 8 interleaved 1–2 ch streams (16 channels total).Decoder): decodes fixed 2048-byte XMA1/XMA2 packets with cross-packet bit-reservoir frame assembly (num_bits_prev_frame), multi-streamskip_packetsrouting,0xFFFFFFFFpadding-packet skipping, 64-sample initial encoder-delay skip,trim_start/trim_endtrimming, and overlap-add EOF flushing.imdct_half, and sine window overlap-add.xma2/xma1decoders: all 7 synthetic test vectors (mono 48 kHz tone, stereo M/S transform, non-uniform 256/128 subframes + RL scale factors, all vector/RLE/quant-escape paths at 32 kHz, cross-packet frames +trim_start/trim_end, 5.1 6-channel 3-stream interleaving, and XMA1 24 kHz stereo) match FFmpeg's output to< 1.5e-7float32 (0–1 LSB PCM16).crates/xcl/src/hle/xaudio2.rsDecodedVoiceState/DecodedCallback) to back both Opus (hle::opus) and XMA1/XMA2 (hle::xma2) voices without code duplication.WAVE_FORMAT_XMA(0x0165) andWAVE_FORMAT_XMA2(0x0166) inCreateSourceVoice, decoding submitted buffers to PCM16, clamping play/loop regions, managing decoded PCM buffer lifetimes untilOnBufferEnd/DestroyVoice, mapping contexts back inGetState, and flushing decoder state onFlushSourceBuffers/XAUDIO2_END_OF_STREAM.xma_buffers_decodedandxma_decode_errorsinAudioStats(report.json -> audio).hle::xma2covering fast IMDCT vs naive reference, all 7 Huffman tables round-tripping every symbol, XMA1/XMA2 config parsing, all 7 FFmpeg-verified bitstreams, streaming chunk-by-chunk parity with single-shot decode, 5.1 channel isolation,0xFFFFFFFFpadding packets, and corrupt/empty input safety.hle::xaudio2(xma2_source_voice_decodes_and_manages_lifetime) covering valid XMA2 playback, corrupt-buffer silence fallback,GetStatecontext mapping,FlushSourceBuffers, callback forwarding, and zero decoded-buffer leaks.tests/testtitle/src/audio.rs,tests/testtitle/src/main.rs, andcrates/xcl/tests/e2e.rsto submit a real 48 kHz mono XMA2 packet and assertxma_voices == 1,xma_buffers_decoded == 1,xma_decode_errors == 0,silent_voices == 0, andbuffers_silenced == 0.README.mdandTHIRD_PARTY.md.Testing
cargo build --workspace && cargo test --workspace -- --test-threads=4:e2e– XMA2 and Opus 0.1 s voices both decode and finish in ~96 ms)console_dlls_e2e), 1 passed (console_shaders), 6 passed (gpu_pso_e2e), 3 passed (xg_oracle)@ivall on GitHub · 2026-11-21 22:50 UTC · original
Reviewed and merged, thanks. FFmpeg LGPL-2.1+ provenance is in the file header and THIRD_PARTY.md (compatible with GPL-2.0-only); the decoder is safe Rust, the unwraps are test-only and the bit reader reads zeros past the end, so corrupt input cannot panic the audio path. Clippy nits for later: a 14-argument function, two manual
is_multiple_of. Checked together with #17, #18, #19 and #20 on top of current main: full workspace tests pass (271 lib tests, e2e, console_dlls_e2e, gpu_pso_e2e, rpf_e2e, the console-library tests), no new build warnings.