XAudio2: real Opus decoder via Windows MSOpusDecoder MFT #2
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3"
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?
Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-21T16:29:33Z.
Implements real Opus audio decoding for XAudio2 on top of current
mainusing Windows' built-inMSOpusDecoder.dllMedia Foundation transform (as noted inHANDOFF.md), with no additional third-party crates.Summary of changes
crates/xcl/src/hle/opus.rsOpusHeadbuilder & parser: supports 1–8 channels (mapping family 0 for mono/stereo, Vorbis mapping family 1 for 3–8 ch),pre_skip, andoutput_gain.OggS), single- and multi-block[u16 LE len][packet]...with optional trailing zero padding (matching the 2048 B AWC blocks), and raw RFC 6716 packets.Decoder: dynamically loadsmfplat.dllandMSOpusDecoder.dllviaDllGetClassObject(no static Media Foundation dependency; GPL-2.0 system-library compatible). Decodes 1–2 ch single-stream directly and 3–8 ch multistream (5.1/7.1) by splitting RFC 6716 Appendix B self-delimited sub-packets acrossstream_countMFT instances and interleaving via the channel map.crates/xcl/src/hle/xaudio2.rsWAVE_FORMAT_OPUS(0x704F) andWAVE_FORMAT_EXTENSIBLEwithMFAudioFormat_Opus, creating a PCM16 source voice backed byopus::Decoder(with RFC 6716-sized silence fallback ifMSOpusDecoder.dllis unavailable).IXAudio2VoiceCallbackto keep decoded PCM16 buffers alive at stable heap addresses untilOnBufferEnd(orDestroyVoice) while forwarding the title's originalpBufferContext.FlushSourceBuffers(#22) to flush decoder state andGetState(#25) to map internal buffer tokens back to the title'spCurrentBufferContext.opus_voices,opus_buffers_decoded, andopus_decode_errorstoAudioStats(report.json -> audio).hle::opuscovering all 32 RFC 6716 configs, codes 0–3, framing detection, real libopus packets across SILK/Hybrid/CELT/2.5–60 ms, 440/880 Hz tone verification, 5.1 surround channel isolation,pre_skip, 24 kHz output, andflush.hle::xaudio2covering format detection, region clamping, live Opus voice playback,GetStatecontext mapping, callback forwarding, and zero decoded-buffer leaks.0x704Fvoice (2048 B AWC-framed block) totests/testtitle/src/audio.rsand checked itsreport.jsonstats incrates/xcl/tests/e2e.rs.README.mdandTHIRD_PARTY.md.Testing
cargo build --workspace && cargo test --workspace -- --test-threads=4:e2e– XMA2 and Opus 0.1 s voices both finish in ~96 ms)console_dlls_e2e), 6 passed (gpu_pso_e2e)upstream-sync referenced this pull request2026-11-24 06:57:41 +00:00