diff --git a/docs/design.md b/docs/design.md index 4a9166486..50873cec6 100644 --- a/docs/design.md +++ b/docs/design.md @@ -77,7 +77,7 @@ add a source file, add it to `runtime\CMakeLists.txt` and to the file list in `b | Models | **Done: 155,598 models** (levels.rpf 149,811 with 1.9 billion triangles, story000 3,303, data 1,350, shared_minigame000 783, packs 314, core_restofworld 37; 0 failures). Exported with `tools\rpf9dump` (built on breadbbbb/rpf9-explorer's Core; see below). Resources are found at page offset +16 after 16 zero bytes, followed by a zlib system blob with a drawable/fragment header and then the following zlib blocks as graphics data. Positions are quantized: `bias + scale * ((q >> 8) & 0xFFFFFF)`. Output is OBJ (positions, UVs, indices) plus a manifest with real model names (e.g. `cvar_int_grg2b_toys_1`), bounds, per-mesh shader index and material texture references (parameter hash, name hash, 64-bit asset key). My earlier `0x1380`/`0x1601` descriptor notes stand, but the "data not located" blocker was wrong. | `\assets\\models\` | | Texture dictionaries | Same tool: TXD resources become DDS per texture. | `\assets\\textures\` | | World textures (TTPF) | **Done: 308,895 textures from all 57 pools, 0 failures, 48,220 entries skipped** (BCPack or unmapped). 46 pools are in `data\ttdb\**`, 11 in `pack\\data\ttdb\**` (exported under `ttpf_pack\\`). `data\ttdb\**\*.ttpf` (57 pools, 58 GiB) are loose RDS5 texture pools, **not** inside RPFs. rpf9-explorer's `TtpfReader` reads the catalog and detiles them; checked visually (`ttdb_graphics`: scope reticles, clean lines). Names are generated (`texture_N_`); models reference textures by asset key. Some rows are skipped (BCPack or unmapped shards). | `\assets\ttpf\\` + `manifest.json` | -| Audio | `audio.rpf` holds raw (not zlib) **AWC** banks: Opus (codec 0x0B) and XMA2 streams. Exported as whole `.awc` files plus `audio_manifest.json` (stream ids, codec, channels, rate, duration). **Done: 7,162 banks, 27 GiB, 1,603,231 streams, about 1,324 hours** (codec 0x0B Opus 1,601,167; 5: 1,818; 2: 227; 0 PCM: 19). `tools/awc_opus.py` repackages every Opus stream **losslessly** into a standard Ogg Opus file (no re-encode; PCM streams become .wav). The AWC framing is 2048-byte blocks of [u16 length][packet], with a zero length padding the block (as rpf9-explorer's OpusPreview reads it). The final granule is trimmed to the declared sample count. Checked: 300 random streams decode with ffmpeg with no errors, lengths match the declared counts. Streamed music (tag 0x48, interleaved multi-channel blocks) isn't converted yet. Output: `\assets\audio\ogg\\.ogg`. | `\assets\audio\awc\` | +| Audio | `audio.rpf` holds raw (not zlib) **AWC** banks: Opus (codec 0x0B) and XMA2 streams. Exported as whole `.awc` files plus `audio_manifest.json` (stream ids, codec, channels, rate, duration). **Done: 7,162 banks, 27 GiB, 1,603,231 streams, about 1,324 hours** (codec 0x0B Opus 1,601,167; 5: 1,818; 2: 227; 0 PCM: 19). `tools/awc_opus.py` repackages every Opus stream **losslessly** into a standard Ogg Opus file (no re-encode; PCM streams become .wav). The AWC framing is 2048-byte blocks of [u16 length][packet], with a zero length padding the block (as rpf9-explorer's OpusPreview reads it). The final granule is trimmed to the declared sample count. Checked: 300 random streams decode with ffmpeg with no errors, lengths match the declared counts. Streamed music (tag 0x48: chunks with a per-channel record table, each channel's 2048-byte subblocks after the aligned header, and a repeated-prefix skip per chunk) becomes one mono Ogg Opus per channel (3,008 banks contain music). Checked: a 4-channel music bank gives four 42.0 s channels with real levels and no decoder errors. Output: `\assets\audio\ogg\\.ogg`. | `\assets\audio\awc\` | ### rpf9dump (bulk export) diff --git a/tools/awc_opus.py b/tools/awc_opus.py index 1289a0bbb..36f7c4c38 100644 --- a/tools/awc_opus.py +++ b/tools/awc_opus.py @@ -8,6 +8,12 @@ AWC layout (little-endian "ADAT"), as read by rpf9-explorer's OpusPreview.cpp: a 2048-byte blocks of [u16 length][packet] ..., a zero length pads the rest of the block. Codec 0 = PCM16 (written as .wav). Streamed music (tag 0x48, multi-channel interleaved blocks) is not handled here yet. +Streamed music (tag 0x48 descriptor: u32 blocks, u32 chunk size, u32 channels, then 16 bytes per channel: id, +samples, rate at +10, codec at +12) is split into one mono Ogg Opus per channel: each chunk starts with a +24-byte record per channel (subblock count at +4, repeated-prefix samples to skip at +8), the channel data are +its run of 2048-byte subblocks after the 2048-aligned header, and the first `skip` samples of a chunk repeat the +previous chunk's tail and are dropped (whole packets). + Output: //.ogg (or .wav), plus a summary line per bank. """ import argparse @@ -107,11 +113,11 @@ def parse_awc(d: bytes): p += (n + 1) * 4 info = p p += n * 4 - streams = [] + streams, music = [], [] for i in range(n): v = struct.unpack_from("> 29 - data = fmt = None + data = fmt = mus = None for _ in range(ntags): t = struct.unpack_from("= 32: samples, = struct.unpack_from("= 2048 and m_size == 12 + 16 * channels): + return [] + info = [] + for c in range(channels): + base = m_at + 12 + 16 * c + cid = struct.unpack_from("= n and skip > 0: + skip -= n + continue + info[c][4].append(pk) + return [tuple(x) for x in info] + + def opus_packets(d: bytes, at: int, size: int): out = [] for b in range(at, at + size, 2048): @@ -148,8 +192,15 @@ def export_bank(path: str, out_dir: str): name = os.path.splitext(os.path.basename(path))[0] od = os.path.join(out_dir, name) os.makedirs(od, exist_ok=True) - counts = {"opus": 0, "pcm": 0, "other": 0} - for s in parse_awc(d): + counts = {"opus": 0, "pcm": 0, "other": 0, "music": 0} + streams = parse_awc(d) + for mus, data in parse_awc.music: + for cid, samples, rate, codec, pk in music_channels(d, mus, data): + if pk: + n48 = samples * 48000 // rate if rate else 0 + write_ogg_opus(os.path.join(od, f"{cid:08X}.ogg"), pk, 1, cid, n48) + counts["music"] += 1 + for s in streams: at, size = s["data"] if s["codec"] == 0x0B and size % 2048 == 0 and s["channels"] in (1, 2): pk = opus_packets(d, at, size) @@ -180,7 +231,7 @@ def main() -> int: else: banks = [a.src] banks = banks[: a.limit] if a.limit else banks - tot = {"opus": 0, "pcm": 0, "other": 0} + tot = {"opus": 0, "pcm": 0, "other": 0, "music": 0} for i, b in enumerate(banks): try: c = export_bank(b, a.out) @@ -191,7 +242,8 @@ def main() -> int: tot[k] += c[k] if (i + 1) % 200 == 0: print(f" {i + 1}/{len(banks)} banks: {tot}", flush=True) - print(f"{len(banks)} banks: {tot['opus']} Ogg Opus, {tot['pcm']} WAV, {tot['other']} not handled (music/XMA/other)") + print(f"{len(banks)} banks: {tot['opus']} Ogg Opus, {tot['music']} music channels (Ogg Opus), {tot['pcm']} WAV, " + f"{tot['other']} not handled (XMA/other)") return 0