Commit Graph

62 Commits

Author SHA1 Message Date
52ed0b51a8 awc_opus: pass skip_existing into the parallel workers
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).
2026-11-30 18:58:49 +01:00
89b895f287 tests: end the file with one newline, not two
No content change.
2026-11-30 15:47:26 +01:00
8b605a7b71 awc_opus: a kept Ogg still contributes its cue-sheet limit
merzleckeier found it: the early `continue` on an Ogg that --skip-existing keeps
also skipped `frame_limits[cid]`, so a rebuilt cue sheet described only the
channels this run wrote.

The kept file's own EOS granule is the authority - recomputing the limit from
this run's packets would describe a file that was not written - so read it back
with ogg_last_granule(). The regression test fails without the change.

Written with an AI assistant.
2026-11-30 14:54:47 +01:00
cb89a384d2 tools: skip Ogg Opus outputs that already exist, so a stopped audio export resumes
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.
2026-11-30 14:54:46 +01:00
c26006fe4d Merge pull request #2457 from kirigayakazima/codex/awc-opus-incremental-ogg-pages
awc_opus: write Ogg pages incrementally to the staged file
2026-11-28 16:15:19 +01:00
0cda54c71c Merge pull request #2456 from kirigayakazima/codex/awc-music-channel-output-collisions
awc_opus: preserve music channels with colliding stream IDs
2026-11-28 16:14:56 +01:00
6be9184691 awc_opus: write Ogg pages incrementally to the staged file 2026-11-27 19:05:33 +08:00
6cd9392cce awc_opus: preserve music channels with colliding stream IDs 2026-11-27 19:04:46 +08:00
c640232b8b tools/awc_opus: honor empty chunk budgets in streamed music
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>
2026-11-24 12:52:53 -06:00
d05a68356e tools/awc_opus: bound streamed metadata packet retention
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>
2026-11-24 12:12:48 -06:00
c6ba76d74a tools/awc_opus: honor hdr24 block_samples budget, interleaved skip, and deficit continuation 2026-11-24 11:48:39 -06:00
a12cb85989 awc_opus: avoid full-size PCM copies during WAV export (#6728)
Squash-merged after diff review of PR #6728
2026-11-23 10:50:40 -06:00
0a8a5522f9 Invalidate previous music cue regions before a bank re-export (#6867)
Squash-merged after diff review of PR #6867 - Invalidate previous music cue regions before a bank re-export
2026-11-23 09:48:53 -06:00
b54dbd6a80 awc_opus: reject Ogg pages with more than 255 segments (#6336)
Squash-merged after review of PR #6336 - awc_opus: clear error for packets over 255 Ogg segments (AWC-OPUS-OGG-SEGMENT-LIMIT)
2026-11-23 08:16:49 -06:00
51931245d5 docs: point 15 more tools at their --help usage line (#5535)
Squash-merged after review of PR #5535 - docs: point 15 more tools at their --help usage line
2026-11-23 08:09:32 -06:00
953cf5b1ae Merge pull request #4399 from Maxime Mansiet
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:14:22 -05:00
49a078cf19 Merge pull request #3971 from bbareth
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:10:02 -05:00
a2fdf3172f awc_opus: reset a staged file's mode before removing it after a failed replace
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
2026-11-23 03:05:19 +01:00
694852694e awc_opus: refuse a codec 0 stream whose data size isn't samples * channels * 2
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
2026-11-23 02:13:13 +01:00
48214362a0 awc_opus: probe the new-file mode once per output folder
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
2026-11-23 02:12:13 +01:00
710880d624 awc_opus: address review nits
Note the u16 rate ceiling so the reference upper bound is clearly parity-only, and drop the codec skip branch made unreachable by descriptor validation.

AI-assisted (OpenCode).
2026-11-23 02:14:55 +03:00
2b2cf43e54 Reject overlapping AWC bank exports before starting workers 2026-11-22 23:44:27 +01:00
2f798a5a06 awc_opus: validate streamed-music channel rate and codec 2026-11-23 01:25:26 +03:00
30757f16b6 Merge pull request #3171 from Marco Luzzaro 2026-11-22 15:15:24 -05:00
61f9354713 Merge pull request #3160 from sds-228 2026-11-22 15:15:18 -05:00
c09337385e Fail AWC exports when bank discovery is incomplete 2026-11-22 20:36:11 +01:00
981156cc88 awc_opus: validate the optional AWC index table 2026-11-22 22:33:52 +03:00
8f20f7d196 Merge pull request #2549 from Arjun Nirgudkar 2026-11-22 13:16:05 -05:00
610f150a47 Merge pull request #1655 from ZazaJr24 2026-11-22 13:12:33 -05:00
ec9a99c69e tools: a process pool gets at most 61 workers on Windows
Windows waits on a pool's workers with WaitForMultipleObjects, which takes
at most 64 handles. With --jobs 62 or more, awc_opus.py, awc_shorts.py,
world_lights_paths.py and world_build.py stopped with "ValueError:
max_workers must be <= 61" (ProcessPoolExecutor), and anim_clips.py
(multiprocessing.Pool) printed "ValueError: need at most 63 handles" from
a helper thread and never returned: 62 workers were killed after 60 s where
61 finish in 0.8 s (Windows 11, Python 3.12.5).

awc_opus.py and awc_shorts.py default --jobs to half the CPU count, and
make_game.py hands its own --jobs to awc_opus.py, so a machine with 124
logical CPUs reached this with no option given.

tools/pool_workers.py holds the limit, and the five pools are created with
process_workers(jobs): unchanged elsewhere, 61 at most on Windows. The
job count is lowered rather than refused so that a build with a large
--jobs keeps running. world_census.py, which refuses --jobs above 61, is
not changed.

tests/test_pool_workers.py runs each tool's own code: with the limit
patched in and a recording pool (every platform), the audio tools from the
command line with --jobs 62, and the real pool with 62 jobs on Windows.
8 of its 10 tests fail on the tools as they were.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 11:54:49 -05:00
44e9921160 Merge current main into the streamed AWC fix
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.
2026-11-22 17:46:47 +01:00
e1a762f68b Audio: write the frame count in IEEE float WAV exports 2026-11-22 13:28:25 -03:00
a4cc5a8363 audio: write an EOS page for an empty packet list 2026-11-22 13:38:47 +00:00
5056ee85a2 audio: emit the Opus EOS page at the trim point, not the last page
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.
2026-11-22 13:38:46 +00:00
46aeb046ef Merge pull request #1638 from Rafael 2026-11-22 08:08:21 -05:00
9842d6f2ea Validate streamed AWC chunks and repeated Opus packets
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.
2026-11-22 13:58:28 +01:00
b8ad3a7be2 awc_opus: accept a streamed-music descriptor whose last block is short
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>
2026-11-22 09:47:34 -03:00
0471fd3bc6 awc_opus/awc_manifest: keep both streams when a bank holds two with the same id
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>
2026-11-22 09:31:30 -03:00
085e00dc47 Merge pull request #1449 from Kam471 2026-11-22 07:07:47 -05:00
284b3a8075 Merge pull request #1473 from bbareth 2026-11-22 06:38:12 -05:00
d9b9b002bf Merge pull request #1449 from Kam471 2026-11-22 06:38:06 -05:00
fba4605513 audio: use the format block's per-channel Opus frame count (+0x0C)
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.
2026-11-22 11:38:02 +00:00
dc2c23d56a awc_opus.py: isolate staging files for overlapping exports 2026-11-22 12:36:48 +01:00
73552dfcd3 audio: write the Opus pre-skip and correct plain-stream lengths (ASSET-104)
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.
2026-11-22 11:31:02 +00:00
f698bf2206 tools: a path outside the console's code page no longer crashes a tool's output
On Windows a redirected stdout uses the console's ANSI code page, and python -I ignores PYTHONUTF8 and
PYTHONIOENCODING, so a caller path with a character outside that code page ended a run with
UnicodeEncodeError as soon as a tool printed it. #1406 fixed make_game.py; every CLI tool in tools/ now starts
its __main__ block the same way (stdout errors="replace").

tests/test_tool_stdout_encoding.py checks every tool's __main__ block and reruns two measured crashes
(analyze_4240_full.py, meshlet_page.py) with a private-use-named input. Found by @abilliontokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:27:00 +00:00
944961c586 awc_opus: reject music descriptors that overrun the data tag
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.
2026-11-22 13:04:20 +03:00
1632373e9e awc_opus.py: validate CLI src, out and --jobs arguments in main() 2026-11-22 07:36:41 +01:00
bfa1983f80 Detect stereo Opus packets in later streamed music blocks 2026-11-21 23:06:08 -03:00
1ea261b6d1 Honor zero and reject negative audio bank export limits 2026-11-21 22:08:14 -03:00
7fdabf3ff3 Preserve nested bank paths during AWC audio export 2026-11-21 21:28:04 -03:00