merzleckeier measured it on CachyOS: --skip-existing --jobs 1 left 0 of 3
existing outputs alone, --skip-existing --jobs 2 rewrote 3 of 3. The submit call
passed export_bank four arguments where the serial call passed five, so the
flag never crossed into the pool. The unit test above it calls export_bank
directly - the function, not the CLI - which is why the plumbing was not
covered; the new test runs the tool as a subprocess for --jobs 1 and 2, freezes
an output, and carries its own control (the same command without the flag must
rewrite the frozen file).
awc_opus.py repacked every bank on every run, so a stopped assets run redid
the whole Ogg Opus step: on one machine 664,446 .ogg files were already
written and the restart began at bank 0. The stage marks the step done only
after it finishes, so there was no per-bank resume.
--skip-existing leaves an output that exists alone before packing a music
channel or writing a stream's .ogg/.wav, and make_game.py passes it in the
audio step. The staged writer publishes atomically, so an existing file is
always complete.
Measured on a 1 MB bank with 29 outputs: first export 0.8 s, second with the
flag 0.23 s and 0 files rewritten, while the same export without the flag
does rewrite them. tests/test_awc_opus.py covers that with the control.
Carry the full deficit across an empty budgeted block and preserve overlap state across empty blocks without a budget. Read packet payloads through views for metadata-only scans, and stop measuring packet durations at the declared budget.
Cover both empty-block cases and the packet-copy and duration-scan regressions.
Co-authored-by: OpenAI Codex <codex@openai.com>
Keep block locations instead of copies of all Opus packets during discovery. Check the allocation regression and record the exact sample-count evidence for the skip and budget handling.
Co-authored-by: OpenAI Codex <codex@openai.com>
Keep the per-chunk checks and repeated Opus packet verification alongside the short-final-block fix already on main. Set accurate mono and stereo sample counts in the overlap fixture so it also exercises the current Ogg trimming behavior. AI-assisted.
Clamping only the last page's granule made it smaller than the previous
page's when the trim target fell before that page started: a 27-packet
real-libopus fixture declared 24,000 frames but decoded 24,960, and the
Ogg granule went 24,960 -> 24,000. Emit the EOS page at the first packet
that reaches pre_skip + length and drop the remaining padding packets.
Also require +0x0C to agree with the interleaved +0 count before using
it, and clamp an oversized pre-skip to the stream length so the final
granule never falls below it.
Measured on real streams: with pre-skip 0, the 5%/10% attack point is
312 samples (30 streams from four banks, median 312; the 10% point ranges
278..868, none near 1920), so the default is measured, not just assumed
from libopus. 20 real streams at 48 and 32 kHz now decode to exactly
their declared counts.
Confine music channel tables and payloads to their own chunks, accept short final chunks, and verify that a declared repeat matches whole packets from the same channel group. Metadata scans and exports now reject the same malformed descriptors while sibling streams still export.
Tested on Linux with synthetic banks. A three-chunk libopus example with repeated packets decoded to exactly the same 6,720 PCM samples as the reference. AI-assisted.
944961c5 (#1320) rejected a music descriptor when blocks * chunk exceeds its data tag. But game
banks end the tag inside the last block: `chunk` is the stride between blocks, not the size of
the last one (e.g. 1 block of a 524,288-byte chunk in a 264,192-byte tag). So every real
streamed-music descriptor was refused, and its channels were dropped by awc_opus and
awc_manifest.
The descriptor-level check now requires each block to start inside the tag,
(blocks - 1) * chunk < d_size. Each block's record table (channels * 24 bytes) and its subblock
run are still checked against the bytes left at that block, so the malformed cases #1320 guards
against are still refused.
Real data (counts only), one audio carve window, 1,052 banks:
- main 41f4482: 46 "ignored malformed streamed-music descriptor" warnings, 0 music channels,
482,628 streams.
- this change: no warnings, 96 music channels (the same as before 944961c5), 482,724 streams.
- All 46 descriptors give channel and packet lists identical to the code before 944961c5.
Tests: ShortLastMusicBlockTest, with a single short block and a 3-block bank whose last block is
shorter than the stride (main: both refused), plus two refusal controls: a last subblock cut
short, and a block declared past the tag. MalformedMusicGeometryTest (#1320) still passes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A bank can list two different streams under the same 29-bit id. awc_opus named every file
`<id>.ogg`/`.wav`, so the second overwrote the first, and awc_manifest keyed its rows by id, so the
second replaced the first row. On a 1.0.2.1 copy's first 2 GB of audio.rpf (1,052 banks), two
banks do this: awc_opus reported 482,726 exports but left 482,724 files, and awc_manifest listed
482,724 rows for 482,726 streams.
awc_opus.export_stems names streams in table order: `<id>` for the first with an id, `<id>~2`,
`<id>~3`, ... after. awc_opus writes those names, and awc_manifest lists every stream and notes the
exported name on the later ones. A streamed-music channel still replaces a row with its id, as
before. Same window now: 482,726 exports, 482,726 files (2 named `~2`), 482,726 manifest rows.
Tests: one bank with two PCM16 streams under id 0x123 must export two different WAVs and list two
manifest rows; both fail on main (one file, one row).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The format block carries the per-channel count at +0x0C: equal to +0 for mono
and half of it for stereo in 7,451 measured streams (0 mismatches), matching
rpf9-explorer's OpusFrameCountPerChannel. Use it (with +0/channels as fallback)
instead of inferring the division, and document the field.
OpusHead declared pre-skip 0, so every exported stream started with 312
samples of libopus priming and the end trim removed the same amount of real
audio. Write the lookahead (312 by default, --pre-skip overrides it) and make
the trimmed final granule pre_skip + length.
The plain-stream length also scaled the format tag's sample count by
48000/rate and ignored stereo interleaving. Measured over 1,598,151 plain
streams: packet samples - declared is 1920..2879 for every 48 kHz and 32 kHz
stream, which is only possible if the declared count is already 48 kHz frames;
after halving stereo counts the same 1920..2879 window holds for all 17,983
stereo streams. Scaling a 32 kHz stream by 1.5 left the padding untrimmed.
Tests cover the pre-skip, the 48 kHz frame count, stereo halving and the
--pre-skip bounds. libopus round-trip: the fixed output matches the reference
Ogg sample-for-sample (max |diff| 0); before the fix it was shifted 312
samples and differed by up to 12,188.
music_channels() trusted the descriptor's block count and the chunk records' subblock counts. A descriptor declaring more blocks or subblocks than its 0x55 data tag holds read past the tag: into a sibling stream's payload, whose bytes were silently exported as music Opus packets, or past the end of the bank, where struct.error made main() skip the whole bank and lose its valid streams (exit 0).
Reject the descriptor ([]) when blocks * chunk exceeds the data tag size, or when a chunk's aligned header plus its subblock run does not fit the tag bytes remaining at that chunk -- the same refusal the existing descriptor checks use. Valid banks are unaffected, including single-block descriptors whose chunk field names only the record-table stride (the awc_manifest/awc_shorts fixtures).
Tests: MalformedMusicGeometryTest in tests/test_awc_opus.py (4 malformed cases + 1 valid-bank control). Negative control on main e7584c5: 4 of the 5 fail (struct.error, garbage packet export, whole-bank skip); with the fix all 24 pass. test_awc_manifest (6), test_awc_shorts (10), test_audio_stage_resume (10), test_audio_config (21) pass; compileall clean. Synthetic banks only, no game files.