Skip to content

hle/opus: honor Ogg Opus EOS granule trimming and pre-skip - #110

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
certified-retart:fix/opus-eos-trim
Nov 23, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
certified-retart:fix/opus-eos-trim

Conversation

@certified-retart

Copy link
Copy Markdown
Contributor

Summary

Honors RFC 7845 Ogg Opus end trimming (EOS granule position) and OpusHead pre-skip for complete, contiguous Ogg Opus submissions in crates/xcl/src/hle/opus.rs.

Previously, extract_ogg_opus flattened Ogg pages into raw packets and dropped page granule positions, causing decoded PCM and estimate_buffer_frames to include trailing padding samples past the final granule (and to ignore the Ogg OpusHead pre-skip when the voice format had no extra_data).

Changes

  • OggTiming + contiguous Ogg page validation (extract_ogg_opus):
    • Tracks page sequence, serial number, BOS/EOS/continuation flags, OpusHead, OpusTags, continued packets across page boundaries, and exact granule deltas across pages.
    • Computes the playable end on the EOS page per RFC 7845 §4.4 (multi-page delta from previous audio granule) and §4.5 (single-page zero origin vs inferred initial granule offset), and clamps pre_skip to end_48k per §4.2 so granule <= pre_skip yields 0 frames without underflow.
    • Uses u128 scaling in frames_at_rate to avoid overflow.
    • Falls back safely to the existing untrimmed behavior for partial/fragmented, chained, multiplexed, or non-contiguous submissions.
  • PCM trimming (Decoder::decode_buffer, OggTiming::trim_pcm):
    • Applies OggTiming only at a decoder stream boundary (timestamp_100ns == 0) with matching channel/mapping/gain configuration, and only when the MFT produced the complete expected decoded timeline (so buffered/primed short outputs keep the existing fallback path).
    • Applies OpusHead pre-skip once (never double-skipping) and updates estimate_buffer_frames to use the same trimmed window.
    • Keeps raw and AWC length-prefixed packet extraction unchanged.
  • Tests:
    • ogg_eos_frame_estimate_handles_preskip_and_initial_granules (including granule < pre_skip, granule == pre_skip, initial granule offset, and 24 kHz scaling)
    • ogg_timing_requires_one_complete_contiguous_link
    • ogg_timing_counts_continued_packet_on_its_completion_page
    • ogg_pcm_trim_requires_full_mft_output
    • decode_ogg_eos_matches_raw_pcm_window_mono_and_stereo (live MSOpusDecoder.dll check with both empty and OpusHead extra_data)

Verification

  • cargo test -p xcl --lib -- --test-threads=1: 500 passed, 0 failed, 16 ignored
  • cargo test -p xcl --test e2e -- --test-threads=1: 2 passed, 0 failed

@ivall
ivall merged commit 7bf9896 into xcl-dev:main Nov 23, 2026
ivall added a commit that referenced this pull request Nov 23, 2026
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Merged. Checked on Windows 11 with an RX 9070 (RDNA4), merged together with the rest of #110–#129: cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with XCL_SPLIT_WAVE64=1; the retail pack still translates 26 698 / 26 698; the FSR4 GPU probe passes; Unicorn Overlord and XDefiant run. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants