What happens
awc_opus.py writes OpusHead with pre-skip 0, so every exported .ogg plays the encoder's priming samples at the start, and the end trim (length) then cuts the same amount of real audio off the end. with a libopus stream that's 312 samples (6.5 ms) shifted on both ends.
Commit
c2967a5e (main)
System
Linux, Python 3.10, ffmpeg 4.4 (libopus). no game files.
Where
A tool run by hand (tools/, scripts/)
Command and steps
tools/awc_opus.py:83:
head = b"OpusHead" + struct.pack("<BBHIhB", 1, channels, 0, 48000, 0, 0)
# ^ pre-skip = 0every Opus encoder has lookahead, so its first ~312 output samples (libopus default) are priming and not audio. RFC 7845 §4.2 says the decoder drops pre-skip samples, and the granule positions count them too (§4.4: last granule = pre-skip + real samples).
repro without game data: encode a 1 s sine with libopus, pull the raw packets out of the ogg, and push them through write_ogg_opus(..., length=48000):
ref pre-skip 312, 51 packets
decoded samples: ref 48000, ours 48000
first non-silent sample: ref 5, ours 317
best alignment of ours vs ref: shifted by 312 samplesso the length matches, but the content is 312 samples late and the last 312 real samples are gone.
Fix (probably)
- write the real pre-skip into OpusHead, and add it to every granule position (including the trimmed last one:
min(granule, pre_skip + length)) - where does the value come from: for the music streams the per-channel
skipalready drops whole repeated packets, which is a different thing. for plain streams the AWC might store the encoder delay somewhere (rpf9-explorer's OpusPreview would be the place to check). if it doesn't, 312 (libopus at 48 kHz) is the safe default, since that's what any libopus encoder would have used.
i couldn't check what the game's own encoder used without game files, so whoever has a bank could compare one sfx's onset against the in-game sound, or check whether its packet count × frame size exceeds samples by about 312.
Output
n/a (wrong result, no error)
TL;DR: exported game audio (.ogg) starts about 6.5 ms late and loses the same amount at the end, because the Opus header says pre-skip 0. fix: write the encoder's pre-skip (probably 312) and count it in the granule positions. shown with a libopus round-trip, not yet with real game banks. AI-assisted (Claude Code).
Activity
0No activity yet.