Skip to content

docs, tools: the AWC 0xBD marker events of the music banks, awc_markers.py (ASSET-303) - #3916

Open
zzEmmazz wants to merge 4 commits into
ItsNotRexed:mainfrom
zzEmmazz:asset-303-awc-chunk-bd
Open

zzEmmazz wants to merge 4 commits into
ItsNotRexed:mainfrom
zzEmmazz:asset-303-awc-chunk-bd

Conversation

@zzEmmazz

Copy link
Copy Markdown
Contributor

ASSET-303, claimed in the coordination issue: #3796 (comment)

What and why

docs/audio_config.md says the config has no per-track start offsets. The finding in the coordination issue reported that AWC tag 0xBD of the music banks holds marker events, including track markers.

While this was being measured, main gained the record layout of the tag over the whole archive (4cf7e3e, #3272: decode_marker_records in tools/rsc8_audio.py and "The 0xbd cue records" in docs/rsc8_audio.md). This pull request is merged with that and does not repeat it: it adds what that page does not have, the music banks on their own and what their records mark. The two counts were made independently and agree where they overlap (945 + 419,223 = 420,168 tags, 31,330 + 750,020 = 781,350 records, 167 types, 363,166 records with a zero last field).

  • docs/audio_config.md: new section "Marker events (AWC tag 0xBD)": the tag in the 3,008 streamed-music banks (their streams have no 0x76 tag, so the offsets are checked against the 0x48 descriptor's length instead), the time unit, counts split by kind of bank, the event-type table (hashes and counts), what is confirmed about the track markers and what is not, and a Reproduce section.
  • tools/awc_markers.py (new, standard library, python -I): walks an archive, one bank or a directory of banks and reports counts, sizes, 32-bit hashes and numeric ranges for the 0xBD chunks. It prints no names and reads no audio.
  • tests/test_awc_markers.py (new): seven tests on hand-built synthetic banks; one holds awc_markers.events() to rsc8_audio.decode_marker_records().
  • Pointer lines in docs/audio.md and the docs/README.md row.

Measured

Xbox Series 1.0.2.1 audio.rpf, every bank (7,162 banks, 1,606,241 streams, the counts docs/rsc8_audio.md has):

Streamed-music banks (0x48) Other banks
Banks 3,008 4,154
Banks with a 0xBD chunk 938 1,019
Chunks 945 419,223
Events 31,330 750,020
Chunk size not a multiple of 16 0 0
Chunks where the time decreases 0 0
Last time past the stream length 0 of 945 0 of 419,222
Distinct types 17 153
Events with non-zero flags 0 418,184
  • Time unit: per-channel frames at 48 kHz. The last event is at a median 0.997 of the stream length and never past it, on 934 stereo and 11 mono streams.
  • Track marker type 0xA6D93246: 1,042 events in 910 chunks. 905 chunks have exactly one (900 at time 0); five long mixes (2,386 s to 7,232 s) have 22, 24, 25, 25 and 41.
  • 64 of the 137 mix markers carry the value of a one-marker bank (32 of 41, 22 of 22, 10 of 24, 0 of 25, 0 of 25).
  • The stretch between two mix markers is not the linked track's length: within 1 s for 0 of 64, shorter for 59, median 0.63. Against all 1,589 config durations, 41 of 137 stretches match within 0.05 s and a shifted control matches 47, so that is chance.
  • 9 of the 16 non-zero type hashes equal joaat of a plain lowercase word (the 7 words of the finding, 7 of 7, and 2 of 89 more tried). The page lists hashes only.
  • The finding's numbers (873 of 2,684 banks, 16 types, 16,207 and 981 events, 849 banks) are exactly the streamed-music banks 323 to 3,006 of 3,008 in archive order, so that count seems to have left out the first 322 and the last 2 banks (why is not known). The layout agrees.
  • Outside the music banks: in the 418,838 records of type 0xE5C74063 the last field equals the integer value (418,838 of 418,838), and the 330,756 records of type 0xDBEDD43C are all at time 0.
  • Existing numbers reproduced first: 1,589 records, ids 0xB422-0xBFC6, 272,442.8 s (rpf9_carve.py --until-adat, audio_config.py --join --json); 3,008 music banks, 3,116 descriptor channels, 2,501 of 2,958 one-channel descriptors with stereo packets. All 1,589 records have a streamed-music channel of the same length within 0.01 s. The "1,584 of 1,589" line of docs/audio_config.md did not reproduce exactly: 8 stream ids occur in two banks of different length, so the count is 1,581 to 1,589 depending on which bank is taken (1,585 with the first or last in archive order).

Tested

Windows 11, Python 3.14, CPU only (no GPU involved). Run again after the merge with main aa2988c.

python -I tests/test_awc_markers.py                 # 7 tests, OK
python -I tests/test_awc_manifest.py                # 17, OK
python -I tests/test_awc_names.py                   # 21, OK
python -I tests/test_awc_opus.py                    # 43, OK
python -I tests/test_awc_shorts.py                  # 12, OK
python -I tests/test_audio_config.py                # 21, OK
python -I tests/test_rsc8_audio.py                  # 25, OK
python -I tests/test_rpf9_carve.py                  # 14, OK
python -I tests/test_joaat_agreement.py             # 2, OK
python -I tests/test_text_write_line_endings.py     # 2, OK
python -I tests/test_tool_startup.py                # 2, OK
python -I tests/test_ci_registration.py             # 5, OK
python -I tests/test_docs_links.py                  # 5, OK
python -I tests/test_docs_repo_paths.py             # 2, OK
python -I tests/test_docs_list_items.py             # 2, OK
python -I tests/test_docs_design_rows.py            # 2, OK
python -m compileall -q make_game.py tools tests    # exit 0
python -I tools/awc_markers.py <game>/audio.rpf --out <temp>/awc_markers.json   # the counts above, 10 s with the file cached

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not a translator rule.)

Not checked: no audio was decoded, so the finding's test that a marker sits at an audible track change was not repeated; what the types other than the track marker mean; the other archives with AWC banks (story000.rpf and the rest) were not scanned; the track-marker cross-checks and the name-hash trials came from a local script that is not in this pull request.

AI-assisted.

@shdann

shdann commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 9cf2350 on Windows, CPython 3.14.7, CPU only (no GPU, no game files). python -m pytest -q tests/test_awc_markers.py (venv with the pinned tests/requirements.txt): 7 passed. The tool is new, so there is no merge-base control; all banks are found in the cases below.

One cost in iter_banks, reproduced: after each bank the scanner reads a fresh window of up to 1 MiB + 3 bytes from the next position, takes the first bank in it and throws the rest away. So every bank costs up to a mebibyte of reading, however small the bank is.

import io, sys
sys.path.insert(0, "tests")
import test_awc_markers as t
class Count(io.BytesIO):
    total = 0
    def read(self, n=-1):
        buf = super().read(n)
        self.total += len(buf)
        return buf
bank = t.speech_bank(3, 64, t.event(1, 1.0, 2))
for count in (128, 256, 512):
    data = bank * count
    f = Count(data)
    print(len(data), sum(1 for _ in t.awc_markers.iter_banks(f, len(data))), f.total)
banks input bytes bytes returned by read()
128 19,968 1,295,616
256 39,936 5,147,136
512 79,872 20,517,888

Below the window size that is quadratic in the number of banks; above it the cost is capped at about 1 MiB per bank, which for an archive of many small banks is still far more than its size. Keeping the current buffer while the next bank starts inside it, and refilling only at its end (with the three-byte overlap kept for a signature that crosses the boundary), reads each byte about once. These are bytes through read(), not a wall-time measurement on a real archive.

AI-assisted.

zzEmmazz added a commit to zzEmmazz/Leonida that referenced this pull request Nov 22, 2026
iter_banks read a fresh window of up to 1 MiB after every bank, so a run of
small banks cost a window each (found in review of ItsNotRexed#3916). A window is now
reused until the search leaves it; the report for audio.rpf is byte-identical.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zzEmmazz

Copy link
Copy Markdown
Contributor Author

@shdann thanks, reproduced and fixed in 9d851c06: iter_banks keeps its window while the next search starts inside it and refills only when the search leaves it.

Your script, before and after (bytes through read()):

banks input bytes before after
128 19,968 1,295,616 27,648
256 39,936 5,147,136 55,296
512 79,872 20,517,888 110,592

The rest above the input size is the header read of each bank by parse_adat_at_file. New test test_many_small_banks_are_read_about_once (8 tests now); on the previous commit it fails with 20517888 not less than 6478080. The report for the real audio.rpf is byte-identical to the one from before the change (same 7,162 banks). I did not get a comparable wall time on the real archive, since other work was using the disk; its banks are mostly larger than the window, so I expect little change there.

AI-assisted.

@CuteBooty

Copy link
Copy Markdown

Tested 9d851c06 on a SHA-256-verified Xbox Series 1.0.2.1 package, Windows 11, Python 3.14.10. I ran tools/awc_markers.py directly on both archives.

story000.rpf yielded 63,861 banks and 234,458 streams.

Bank group Banks Banks with markers Marker chunks Events Distinct types
Streamed music 753 572 572 10,592 2
Other 63,108 62,901 226,216 390,445 9

All 226,788 story marker chunks were multiples of 16 bytes. Every chunk had a stream length available for comparison. The scanner found zero chunks with decreasing timestamps and zero with a marker past the stream end.

As a control, audio.rpf reproduced the PR’s counts of 7,162 banks and 1,606,241 streams, including 31,330 streamed-music events and 750,020 other events. All 8 test_awc_markers.py tests passed. This checks marker structure and timing bounds. Audible track transitions remain untested. AI-assisted with Codex.

@CuteBooty

Copy link
Copy Markdown

I traced the one missing length comparison in audio.rpf on Xbox Series 1.0.2.1 at 9d851c06. Of the 419,223 non-music marker chunks, 419,222 passed the Opus length check. The remaining chunk has a single readable 0x76 format tag with codec 5 (XMA2), one channel at 32,007 Hz, and one 0xBD event. Its marker time fits within the declared sample count. The codec check in bank_chunks explains why the report excludes it from the denominator. Duplicate tags do not account for this case.

A synthetic eight-stream bank distinguished the codec check from the duplicate-format case. A second classifier independently reproduced the non-music counts. All eight test_awc_markers.py tests passed on Windows with CPython 3.14.10 (Ryzen 5 3600, CPU only). A short note beside the 419,222 denominator in docs/audio_config.md would explain the difference. This one mono stream cannot establish timing units for XMA2 generally.

AI-assisted with Claude and Codex.

@zzEmmazz

Copy link
Copy Markdown
Contributor Author

Addressed the denominator clarification in 039e87d2. docs/audio_config.md now states that 419,222 non-music length comparisons cover Opus (codec 11 / 0x0B), while the remaining one of 419,223 marker chunks belongs to mono XMA2 (codec 5). It cites the independent check and explicitly avoids extending the Opus timing measurement to XMA2.

Documentation checks (links, repository paths, list items, design rows) and all eight marker tests pass: 20 checks total. No new corpus measurements or game files. CPU only. AI-assisted (Codex).

@abilliontokens

Copy link
Copy Markdown
Contributor

Tested 039e87d2 on Windows 11 (26200), Python 3.12.10, on my own 1.0.2.1 copy: the counts reproduce, with one defect in the tool. AI-assisted (omp orchestrator). CPU only; counts only below.

Passes

  • python -I tests/test_awc_markers.py 8 OK; test_rsc8_audio.py 30, test_audio_config.py 21, and test_docs_{links,repo_paths,list_items,design_rows}.py all OK.
  • python -I tools/awc_markers.py <game>\audio.rpf --out <scratch>\awc_markers.json took 84 s (file not cached). It prints 7162 banks, 1606241 streams. Streamed music: 3,008 banks, 938 with a 0xBD chunk, 945 chunks, 31,330 events, 17 types, 0 not a multiple of 16, 0 time decreases, 0 of 945 past the stream end. Other: 4,154 banks, 1,019 with a chunk, 419,223 chunks, 750,020 events, 153 types, 0, 0, 0 of 419,222. All match the PR's table.
  • From the JSON: 0 and 418,184 events with non-zero flags. 0xA6D93246 has 1,042 events in 910 chunks, 905 chunks with exactly one, at most 41 in a chunk. 0xE5C74063 has 418,838 events and 0xDBEDD43C 330,756, all at time 0. These match docs/audio_config.md:154/179 and the description.

Defect: tools/awc_markers.py:196-214 (main): --out can overwrite the input bank. The report is written after the scan, and nothing checks the --out path against the input. With a synthetic bank from tests/test_awc_markers.py (speech_bank(3, 64, event(1, 1.0, 2)), 156 bytes):

  • python -I tools/awc_markers.py bank.awc --out bank.awc exits 0, and bank.awc is now the 1,019-byte JSON report.
  • python -I tools/awc_markers.py banks --out banks\a.awc does the same to a bank inside the scanned folder.
  • --out naming an existing directory ends in a PermissionError traceback, not a one-line error.

Its sibling tools/awc_manifest.py:167 already refuses this with report_paths.same_report_path. Suggested fix: in main, before scan(), refuse an --out that is a directory, or that same_report_path matches to a.src or to any .awc the directory walk would read. Exit 2 with one awc_markers: error: line, like the missing-src case. Add one test with --out set to the input bank.

Not checked: the track-marker link and stretch figures and the name-hash trials. The page says those came from an uncommitted script (docs/audio_config.md, end of "Reproduce").

@kapitche

Copy link
Copy Markdown
Contributor

Tested 039e87d merged with main 3faac55 on Linux (WSL2), Python 3.12.16: pass.
Ran tests/test_awc_markers.py (8 OK) and all tests/test_docs_*.py (pass), including the docs/README.md, audio.md, audio_config.md edits.
Negative control: tools/awc_markers.py is a new file, so with it removed the test fails at import (ModuleNotFoundError).

@MKmajster

Copy link
Copy Markdown

Independent reproduction, from a separate pass over audio.rpf (whole-archive scan for ADAT banks validated the way rpf9_carve/rsc8_audio accept them, then every 0xBD tag decoded as 16-byte records): the numbers match.

  • 7,162 ADAT banks validated; 1,957 carry a 0xBD tag. 945 of those tags sit on streamed-music banks (0x48 present), in 938 of the 3,008 music banks — and 419,223 sit on the others, the same count as the PR's other-banks row.
  • 31,330 music events; the flags word at +12 is 0 on 31,330/31,330; times never decrease (945/945 non-decreasing, with 3,259 tied pairs); last-event / (descriptor samples / 2) is 0.997 median and 1.000 max — the same per-channel 48 kHz conclusion the PR derives, reached from the 0x48 side.
  • Where a bank carries the tag on more than one channel stream the copies are byte-identical (4 music banks, up to 5 copies). Not in the PR; a line about it may save someone a double decode.

One observation for the type table: the six single-record chunks labeled 0x7A495DB3 carry 113.0, 131.0 and 158.0 (twice each) — a range that fits a tempo in BPM, if that hash is still among the unresolved.

(Measured with a local standard-library script run under python -I; automated pass, AI-assisted. Counts and hashes only — no game data.)

zzEmmazz and others added 2 commits November 23, 2026 10:57
The report is written after the scan, and nothing compared --out with what the
scan reads, so `awc_markers.py bank.awc --out bank.awc` replaced the bank with
the JSON report, as did an --out naming a bank inside a scanned folder; an
--out naming a directory ended in a PermissionError traceback after the scan.

main() now checks --out before reading anything: a directory, or a path that
report_paths.same_report_path matches to the archive, the bank or any *.awc
the directory walk reads, is one "awc_markers: error:" line and exit 2, as
awc_manifest.py already does. Reported in the review of ItsNotRexed#3916.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zzEmmazz

Copy link
Copy Markdown
Contributor Author

@abilliontokens thanks, confirmed and fixed in a9af2440 (plus 0470c6b6, a line wrap); the head is now 0470c6b6.

main() checks --out before anything is read: a directory, or a path that report_paths.same_report_path matches to the archive, the bank or any *.awc the directory walk reads, is one awc_markers: error: line and exit 2, the same refusal as awc_manifest.py. The scan itself is unchanged; the list of files it reads moved into input_paths() so the check and the scan use the same list.

Tested on Windows 11 (26200), Python 3.12, CPU only:

  • python -I tests/test_awc_markers.py: 9 OK. The new test covers your three cases (the bank itself, a bank inside the scanned folder, a directory) plus the same bank under another spelling of its path and an archive named as its own output; each exits 2 with one line on stderr and nothing on stdout, and the input still has its bytes. A report written next to the banks under a name the scan does not read still works.
  • Negative control: the same test file with the tool from 039e87d2 gives 5 failures and 1 error (the PermissionError).
  • test_rsc8_audio.py, test_audio_config.py, test_awc_manifest.py, test_docs_{links,repo_paths,list_items,design_rows}.py, test_text_write_line_endings.py: OK.
  • The census over my copy's audio.rpf with the new head prints the same lines as before (7,162 banks, 1,606,241 streams; music 938 / 945 / 31,330 / 17 types; other 1,019 / 419,223 / 750,020 / 153 types; all the zero checks still 0), and --out naming the archive in a different letter case is refused before the scan starts.

Not changed: the report is still written in place, not through a temporary file, so a write that fails halfway leaves a partial report. And you are right that the track-marker link, stretch figures and name-hash trials came from a one-off script that is not in the tree; the page says so, and they stay unverified by anything committed here.

The earlier passes on this PR were for 039e87d2; the two commits since touch only tools/awc_markers.py (main and the path list) and its test.

AI-assisted.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At 0470c6b an independent parser reproduced all 203 marker records in order across 11 chunks in the first eight marker-bearing banks found among 2,285 visited. Every chunk held whole 16-byte records. All flags were zero and timestamps were nondecreasing within each chunk and within the tool-reported stream length. Discovery and lengths came from the reviewed tool. The 48 kHz unit and marker semantics remain independently unverified.

AI-assisted independent review.

main already has the tool (an earlier head of this branch) and, since ItsNotRexed#6774, an OSError check for an
unlistable folder in the lines this branch changed. Both are kept: input_paths() does the walk with
main's onerror, scan() and the --out check use it, and main() reports an OSError from either.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zzEmmazz

Copy link
Copy Markdown
Contributor Author

Merged main 8575d36e; the head is now 36801a14.

main already has the tool and its docs (an earlier head of this branch went in with a triage round), so what this PR still adds is small: tools/awc_markers.py +22/-7, its test +37, and six lines of docs/audio_config.md. That is the --out guard from the review above (a report path that is a directory or names an input is refused before anything is read) and the sentence about the length-check denominator.

One conflict: #6774 added an OSError check for an unlistable folder in the same lines. Both are kept. input_paths() does the walk with main's onerror, scan() and the --out check both use it, and main() reports an OSError from either as one error line, exit 1.

python -I tests/test_awc_markers.py: 12 tests OK (main's and this branch's). test_rsc8_audio.py, test_audio_config.py, test_docs_repo_paths.py, test_docs_list_items.py, test_docs_design_rows.py: OK. test_text_write_line_endings.py fails on main 8575d36e itself (tools/leonida_tui.py:753, tools/wave_diff.py:373), not from this branch. Windows 11, Python 3.14; no scan of a real archive on this head.

AI-assisted.

@hcampbell98

Copy link
Copy Markdown

Tested 36801a141 merged with main 5cf3dafe3 on Linux (WSL2, Python 3.14.4, CPU only, no game files): pass.

  • git diff --check, compileall, and python3 -I scripts/check_no_game_data.py: clean; none of the touched files appear in test_text_write_line_endings.py or test_tool_stdout_encoding.py.
  • python3 -I tests/test_awc_markers.py -v: 12/12 OK.
  • Related suites: tests/test_rsc8_audio.py 49/49 OK, tests/test_audio_config.py 21/21 OK, tests/test_awc_manifest.py 22/22 OK, tests/test_docs_repo_paths.py 3/3 OK, tests/test_docs_list_items.py 3/3 OK. (tests/test_docs_links.py has only the pre-existing docs/dev-tools.md anchor failure also present on main 5cf3dafe3.)
  • Negative control (origin/main tools/awc_markers.py): tests/test_awc_markers.py fails (5 failures, 1 error in 12 tests).

AI-assisted.

@mewajda

mewajda commented Nov 23, 2026

Copy link
Copy Markdown

Independent run on my own 1.0.2.1 copy — every count in the docs table reproduces exactly.

  • python -m pytest tests/test_awc_markers.py -q: 12 tests + 7 subtests pass.
  • python -I tools/awc_markers.py <my audio.rpf> --out … on 28.5 GB: 17 s wall, 7,162 banks, 1,606,241 streams. Against the table this PR adds to docs/audio_config.md:
streamed_music other doc
banks 3,008 4,154 —
banks with a chunk 938 1,019 928 one-channel + 10 multi-channel = 938
chunks 945 419,223 945 / 419,223
chunks with a length 945 419,222 419,222
distinct types 17 153 17 / 153
events with non-zero flags 0 418,184 0 / 418,184

So the XMA2 note is right on independent data: exactly one of the 419,223 non-music chunks lacks an Opus-derived length, and the length comparison covers the other 419,222.

The layout checks are clean at full scale, not just on fixtures: chunks_not_multiple_of_16 0, chunks_time_decreases 0, chunks_past_end 0 in both groups. That is the part a synthetic test cannot show, and it is the part that would break first if the tag were being misread on some bank shape.

One presentation note. The text summary ends with ... 133 more types (use --out), which is fine, but the two events-per-chunk spreads are worth surfacing in the text too: music is min 1, median 23, max 1,435 against min 1, median 2, max 3 for the others. That single line explains why the music path needed the length comparison at all.

Verdict: the tool, the tests and the docs agree with an independent package; no blocking issues. AI-assisted.

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.

9 participants