Document radio track label keys and count matches

Describe the marker-derived keys and add a local checker that reports
title and artist coverage for a single text table. Use hand-built
fixtures to verify aggregation and path-free errors.

The translator suite reproduced two upstream baseline failures.

Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
Elijah-J
2026-11-23 16:14:54 -06:00
committed by IlyassRS
parent 0b45fdc211
commit ac55444709
3 changed files with 210 additions and 0 deletions

View File

@ -195,6 +195,29 @@ Not confirmed:
So the statement above stands for the config, and for the mixes without markers. For the five marked mixes a
runtime can read the track boundaries and track numbers from the bank.
#### Title and artist label keys
For a `trackid` marker with flags zero and track number N, hash the decimal number followed by `s` for
the title label or `a` for the artist label. For example, track number 7 gives `joaat("7s")` and
`joaat("7a")`, using the lowercase Jenkins one-at-a-time hash. These keys are independent of the
stream-name hash. Matching against the archive and a static trace support key construction. The runtime
lookup order and precedence between text tables remain unverified.
On Xbox Series 1.0.2.1, the five long mixes have 137 marker rows and 101 distinct track numbers.
In the English credits table (1,703 entries), 99 of those numbers have a nonempty title, one has an
empty title, and one has no title entry. There are 100 nonempty artists and one empty artist entry.
These counts describe the selected table only.
Run the counts-only checker on the five local AWC banks and a logical resource containing exactly
one text table. Join the resource's parts before passing it to `--table` if it spans multiple
carved files (see [String tables](text.md#string-tables)). The checker counts repeated marker rows
separately from distinct track numbers. Label counts are per distinct number. An invalid input
produces a fixed message without a file path.
```sh
python -I tools/track_labels.py mix-1.awc mix-2.awc mix-3.awc mix-4.awc mix-5.awc --table english-credits.bin
```
### Other banks
The 419,223 tags outside the music banks are the ones [rsc8_audio.md](rsc8_audio.md#the-0xbd-cue-records)

View File

@ -0,0 +1,99 @@
"""Counts-only radio label checks with hand-built AWC banks and text tables."""
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
sys.path.insert(0, str(Path(__file__).resolve().parent))
from test_awc_markers import build_bank, event # noqa: E402
from test_text_tables import T, make_resource # noqa: E402
TOOL = Path(__file__).resolve().parents[1] / "tools" / "track_labels.py"
TRACK_ID = 0xA6D93246
STREAM_ID = 0x10E76433 # hashdict.joaat("fixture_stream_7"), unchanged by the 29-bit mask
SENTINEL = "Synthetic title that must stay private"
DATA_ERROR = b"track_labels: could not read valid AWC banks and one string table"
ARGS_ERROR = b"track_labels: invalid arguments (see --help)"
class TrackLabelsTest(unittest.TestCase):
def setUp(self):
scratch = tempfile.TemporaryDirectory()
self.addCleanup(scratch.cleanup)
self.root = Path(scratch.name)
self.table = self.root / "private-table-name.bin"
def bank(self, filename, numbers):
markers = b"".join(event(TRACK_ID, float(n), i) for i, n in enumerate(numbers))
markers += event(0x11111111, 91.0, 9) + event(TRACK_ID, 92.0, 10, flags=1)
path = self.root / filename
path.write_bytes(build_bank([(STREAM_ID, [(0xBD, markers)])]))
return path
def run_tool(self, *args):
return subprocess.run([sys.executable, "-IB", TOOL, *args], capture_output=True)
def test_counts_rows_and_distinct_numbers_with_one_table(self):
first = self.bank("first.awc", [3, 3])
second = self.bank("second.awc", [3, 12, 0])
self.table.write_bytes(make_resource({"3s": SENTINEL, "3a": "Artist", "12s": "", "12a": ""}))
# Independently computed with hashdict.joaat, also used by the resource builder.
self.assertIn(bytes.fromhex("ead5bb87"), self.table.read_bytes())
result = self.run_tool(first, second, "--table", self.table)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(result.stderr, b"")
self.assertEqual(result.stdout, (
b"marker_rows 5\ndistinct_numbers 3\n"
b"title_present 1\ntitle_empty 1\ntitle_absent 1\n"
b"artist_present 1\nartist_empty 1\nartist_absent 1\n"
))
def test_does_not_use_the_stream_id_or_stream_name_hash(self):
bank = self.bank("mix.awc", [3])
self.table.write_bytes(make_resource({"fixture_stream_7": SENTINEL}))
result = self.run_tool(bank, "--table", self.table)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(result.stderr, b"")
self.assertEqual(result.stdout, (
b"marker_rows 1\ndistinct_numbers 1\n"
b"title_present 0\ntitle_empty 0\ntitle_absent 1\n"
b"artist_present 0\nartist_empty 0\nartist_absent 1\n"
))
def test_bad_inputs_emit_only_fixed_errors(self):
bank = self.bank("private-bank-name.awc", [3])
resource = make_resource({"3s": SENTINEL})
self.table.write_bytes(resource)
ambiguous = self.root / "two-tables.bin"
# Two descriptors can point at the same hand-built table data.
two_tables = resource + T.DESCRIPTOR.search(resource).group()
self.assertEqual(len(list(T.string_tables(two_tables))), 2)
ambiguous.write_bytes(two_tables)
bad = self.root / SENTINEL
bad.write_bytes(SENTINEL.encode())
missing = self.root / "private-missing.awc"
partial = self.root / "partial.awc"
partial.write_bytes(build_bank([(STREAM_ID, [(0xBD, event(TRACK_ID, 3.0, 0) + b"\0")])]))
fractional = self.bank("fractional.awc", [3.5])
negative = self.bank("negative.awc", [-1])
cases = [
(1, DATA_ERROR, (path, "--table", self.table))
for path in (bad, missing, partial, fractional, negative)
] + [
(1, DATA_ERROR, (bank, "--table", path)) for path in (bad, missing, ambiguous)
] + [
(2, ARGS_ERROR, (bank, "--table", self.table, *extra))
for extra in (("--table", self.table), ("--" + SENTINEL,))
]
for code, message, args in cases:
with self.subTest(args=args):
result = self.run_tool(*args)
self.assertEqual(result.returncode, code)
self.assertEqual(result.stdout, b"")
self.assertEqual(result.stderr.splitlines(), [message])
if __name__ == "__main__":
unittest.main()

88
tools/track_labels.py Normal file
View File

@ -0,0 +1,88 @@
"""Count title and artist labels for trackid markers in extracted AWC banks."""
import argparse
import os
from pathlib import Path
import struct
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from audio_config import joaat # noqa: E402
from awc_markers import EVENT, TAG_MARKER, events # noqa: E402
from rsc8_audio import parse_adat_at_file # noqa: E402
from text_tables import MAX_RESOURCE_BYTES, string_tables # noqa: E402
TRACK_ID = joaat("trackid")
def track_numbers(path):
with path.open("rb") as source:
bank = parse_adat_at_file(source, 0, os.fstat(source.fileno()).st_size)
if bank is None:
raise ValueError("invalid AWC bank")
for _, tags in bank["entries"]:
for kind, offset, size in tags:
if kind != TAG_MARKER:
continue
source.seek(offset)
chunk = source.read(size)
if len(chunk) != size or size % EVENT.size:
raise ValueError("incomplete marker chunk")
for event_type, bits, _, flags in events(chunk):
if event_type == TRACK_ID and flags == 0:
number, = struct.unpack("<f", bits.to_bytes(4, "little"))
if not number.is_integer() or number < 0:
raise ValueError("invalid track number")
yield int(number)
def counts(banks, table):
with table.open("rb") as source:
data = source.read(MAX_RESOURCE_BYTES + 1)
if len(data) > MAX_RESOURCE_BYTES:
raise ValueError("string table resource too large")
labels, = string_tables(data)
numbers = set()
rows = 0
for bank in banks:
for number in track_numbers(bank):
rows += 1
numbers.add(number)
result = {"marker_rows": rows, "distinct_numbers": len(numbers)}
for name, suffix in (("title", "s"), ("artist", "a")):
matches = [labels.get(joaat(f"{number}{suffix}")) for number in numbers]
result.update({
f"{name}_present": sum(bool(text) for text in matches),
f"{name}_empty": matches.count(""),
f"{name}_absent": matches.count(None),
})
return result
class ArgumentParser(argparse.ArgumentParser):
def error(self, message):
# argparse's default message can include argument values and file paths.
self.exit(2, "track_labels: invalid arguments (see --help)\n")
def main(argv=None):
parser = ArgumentParser(description=__doc__, allow_abbrev=False)
parser.add_argument("banks", nargs="+", type=Path, help="paths to extracted AWC banks")
parser.add_argument("--table", action="append", required=True, type=Path,
help="one extracted resource containing exactly one string table")
args = parser.parse_args(argv)
if len(args.table) != 1:
parser.error("expected exactly one table")
try:
report = counts(args.banks, args.table[0])
except (OSError, ValueError):
print("track_labels: could not read valid AWC banks and one string table", file=sys.stderr)
return 1
output = "".join(f"{name} {value}\n" for name, value in report.items())
sys.stdout.buffer.write(output.encode("ascii"))
return 0
if __name__ == "__main__":
sys.stdout.reconfigure(errors="replace")
sys.exit(main())