From 525f988d1dcd505d8b7f3debeddc14a80533b9eb Mon Sep 17 00:00:00 2001 From: Schindler Date: Wed, 18 Nov 2026 20:59:41 -0500 Subject: [PATCH 1/3] Japanese voices: movies keep the player's picture, undub sound spliced in jp_audio.py copied each differing undub movie whole; six of the USA undub's (END, UP_END, UP_GIL, UP_OPN, UP_PRI, DES01_010) also have another picture. splice_movie_audio puts the undub's ATRAC3plus bytes where the installed movie's are (752-byte frames from the first sound byte on both discs, the packets' 4-byte headers kept); DES01_010's extra frame is left out; a movie whose streams do not line up is still copied whole. Checked: EU disc + USA undub, all 34 movies have the installed picture and the undub's sound byte for byte; in game (UP_GIL served as the title movie) the sound envelope matches the undub's movie (0.999) and not the English one. test_jp_audio.py covers the splice on synthetic movies. audio.md also records that the undub changes no story scene script, so the scene timing fix needs the Japanese disc. Method from VCKing101's port (docs/port/japanese-voices.md, MIT): https://github.com/VCKing101/Dissidia012-pc Co-Authored-By: Claude Opus 5.5 --- psprecomp/games/dissidia/docs/audio.md | 19 ++++- psprecomp/games/dissidia/tools/jp_audio.py | 68 +++++++++++++++- .../games/dissidia/tools/test_jp_audio.py | 78 +++++++++++++++++++ 3 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 psprecomp/games/dissidia/tools/test_jp_audio.py diff --git a/psprecomp/games/dissidia/docs/audio.md b/psprecomp/games/dissidia/docs/audio.md index 9a12d12..76cc3df 100644 --- a/psprecomp/games/dissidia/docs/audio.md +++ b/psprecomp/games/dissidia/docs/audio.md @@ -160,10 +160,25 @@ No per-action attribution was made. option of the installed game (the installer wizard runs it when "Japanese voices (undub)" is switched on). It compares the undub disc's `DATA/PACKAGE.BIN` with the installed one and extracts only audio that differs: the `voice/en/*` entries into `/voice_jp/` (same asset paths: the game asks for the English path and the loose-file layer serves the Japanese file), audio entries whose path is not in -`package_paths.txt` (RIFF / SSCF data) into `/voice_jp/by_crc/.bin`, and the `DATA/MOVIE/*.PMF` that differ into -`/movie_jp/`. Menus, text and other languages stay as they are. Checked on the EU image with the USA undub: 5,663 voice files +`package_paths.txt` (RIFF / SSCF data) into `/voice_jp/by_crc/.bin`, and for the `DATA/MOVIE/*.PMF` that differ, the +installed movie with the undub's sound spliced in, into `/movie_jp/`. Menus, text and other languages stay as they are. Checked on the EU image with the USA undub: 5,663 voice files (177 MB), 316 by-CRC audio entries and 34 movies (488 MB); a second run extracts nothing new. In the game: Settings > System > Voice (appears once `voice_jp/` exists; `voice=jp|en` in settings.ini, `PSPRECOMP_VOICE=jp|en`), applied at the next start. The runtime side is `games/dissidia/runtime/hooks_io.cpp` (`extra_dirs` voice pack in `PackageMods::build`, `remap_disc_path` for movies). Built and linked 2026-11-10; **not yet heard in game**. + +**Movies keep the player's picture** (since 18 November 2026, `splice_movie_audio`). The USA undub has another picture in six of its 34 +differing movies (`END`, `UP_END`, `UP_GIL`, `UP_OPN`, `UP_PRI`, `DES01_010`), so a whole copy showed it with Japanese voices on. A PMF is +2,048-byte packs of whole PES packets; the sound is private stream 1 (`0xBD`): a 4-byte header (stream number, where the first frame +starts) then 752-byte ATRAC3plus frames, contiguous from the first sound byte on both discs. So the undub's sound byte n goes where the +installed movie's sound byte n is, and every header stays right. `DES01_010`'s undub sound is one frame longer: the last frame is left +out. A movie whose streams do not have that layout is copied whole, as before. Method from VCKing101's port +(https://github.com/VCKing101/Dissidia012-pc, `docs/port/japanese-voices.md`, "Movies"). Checked on the EU disc with the USA undub: +all 34 have the installed picture byte for byte and the undub's sound byte for byte. + +**Story scenes are not fixed.** The undub disc changes only sound files: no `talkevent/*.evex` scene script differs from retail. Each +line of a scene waits a fixed time tuned to its own release's recording, and 302 voiced scenes have other scripts on the Japanese disc +(55 with other voice lists, 247 with other waits; VCKing101, same doc, "Story scenes"). On the undub, as on a PSP running it, Japanese +lines play on the English scripts: some are cut off, a few play under the wrong line (012 Chapter 2, Vaan and Terra), and 013's +narrations mix English-only recordings into the Japanese ones. Fixing that needs the Japanese disc (NPJH-50377) for its scripts. diff --git a/psprecomp/games/dissidia/tools/jp_audio.py b/psprecomp/games/dissidia/tools/jp_audio.py index 220cac8..3c405a3 100644 --- a/psprecomp/games/dissidia/tools/jp_audio.py +++ b/psprecomp/games/dissidia/tools/jp_audio.py @@ -10,7 +10,9 @@ /voice_jp/ entries of the voice/en/* tree that differ (the game requests English paths; the loose-file layer serves these instead when the Voice setting is Japanese) /voice_jp/by_crc/.bin audio entries (RIFF / SSCF data) whose path is not in package_paths.txt but that differ - /movie_jp/.PMF DATA/MOVIE movies of the undub disc that differ from the installed ones + /movie_jp/.PMF DATA/MOVIE movies whose sound differs: the installed movie's picture with the undub + disc's sound spliced in (splice_movie_audio; a whole copy of the undub movie only if + the two sound streams cannot be lined up) Nothing else is copied (menus, text and the other languages stay the player's own). The runtime offers a "Voice" row in the settings menu once /voice_jp exists (games/dissidia/runtime/hooks_io.cpp). Re-running skips files already extracted. @@ -29,6 +31,7 @@ SECTOR = 2048 AUDIO_MAGICS = (b"RIFF", b"SSCF") +ATRAC_FRAME = 752 PROGRESS = False @@ -94,6 +97,53 @@ def file_md5(path): return h.digest() +def _pes_audio(data): + """[(start, size)] of the ATRAC3plus bytes of every private-stream-1 (0xBD) packet of a PMF, after each packet's 4-byte + header, and whether the frame starts that header gives fit 752-byte frames from the stream's first byte.""" + off = struct.unpack(">I", data[8:12])[0] + out, pos, ok = [], 0, True + for p in range(off, len(data) - 13, SECTOR): + if data[p:p + 4] != b"\x00\x00\x01\xba": + continue + q, end = p + 14 + (data[p + 13] & 7), p + SECTOR + while q + 6 <= end and data[q:q + 3] == b"\x00\x00\x01": + length = struct.unpack(">H", data[q + 4:q + 6])[0] + if data[q + 3] == 0xBD: + s = q + 9 + data[q + 8] + first = struct.unpack(">H", data[s + 2:s + 4])[0] + n = q + 6 + length - s - 4 + if n < 0 or (first != 0xFFFF and (pos + first) % ATRAC_FRAME): + ok = False + out.append((s + 4, n)) + pos += max(n, 0) + q += 6 + length + return out, ok and pos % ATRAC_FRAME == 0 + + +def splice_movie_audio(mine, undub): + """The installed movie with the undub movie's sound: a PMF is 2,048-byte packs of whole PES packets, the sound private + stream 1 with a 4-byte header (stream number, where the first frame starts) and then 752-byte ATRAC3plus frames, from the + first sound byte on, on both discs. So the undub's sound byte n goes where the installed sound byte n is and every header + stays right. Where the undub's sound is longer (DES01_010.PMF, one frame) the rest is left out; where shorter, the + installed sound fills in. None when either stream does not have that layout. The picture is the player's own (the undub + disc's END, UP_END, UP_GIL, UP_OPN, UP_PRI and DES01_010 have another one). Same method as VCKing101's port + (https://github.com/VCKing101/Dissidia012-pc, docs/port/japanese-voices.md, "Movies").""" + a, ok_a = _pes_audio(mine) + b, ok_b = _pes_audio(undub) + if not (ok_a and ok_b and a and b): + return None + sound = b"".join(undub[s:s + n] for s, n in b) + out = bytearray(mine) + pos = 0 + for s, n in a: + take = sound[pos:pos + n] + out[s:s + len(take)] = take + pos += n + if pos >= len(sound): + break + return bytes(out) + + def main(): global PROGRESS ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) @@ -193,13 +243,25 @@ def main(): hash_range(iso.f, r["extent"] * SECTOR, 0, r["size"]) == file_md5(mine_path): continue dest = os.path.join(out_movie, r["name"]) - if os.path.isfile(dest) and os.path.getsize(dest) == r["size"]: + want = os.path.getsize(mine_path) if mine_path else r["size"] + if os.path.isfile(dest) and os.path.getsize(dest) == want: n_skip += 1 continue n_movie += 1 + spliced = None + if mine_path: + iso.f.seek(r["extent"] * SECTOR) + with open(mine_path, "rb") as mf: + spliced = splice_movie_audio(mf.read(), iso.f.read(r["size"])) if a.dry_run: - say(" would write movie %s (%d bytes)" % (r["name"], r["size"])) + say(" would write movie %s (%s)" % (r["name"], "your picture, Japanese sound" if spliced else "whole undub movie")) + elif spliced is not None: + os.makedirs(out_movie, exist_ok=True) + with open(dest + ".tmp", "wb") as o: + o.write(spliced) + os.replace(dest + ".tmp", dest) else: + say(" %s: the sound streams do not line up, using the undub disc's whole movie" % r["name"]) copy_range(iso.f, r["extent"] * SECTOR, 0, r["size"], dest) else: say("the undub disc has no DATA/MOVIE folder: movies stay as they are") diff --git a/psprecomp/games/dissidia/tools/test_jp_audio.py b/psprecomp/games/dissidia/tools/test_jp_audio.py new file mode 100644 index 0000000..f466414 --- /dev/null +++ b/psprecomp/games/dissidia/tools/test_jp_audio.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +"""Self-test for jp_audio.splice_movie_audio on synthetic PMF movies (no game data). Run: python3 -I test_jp_audio.py""" +import os +import struct +import sys + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import jp_audio as ja + +FRAME = ja.ATRAC_FRAME +HEADER = 0x800 # where the packs start (byte 8 of the file) + + +def pes(stream_id, payload): + hdr = b"\x81\x80\x00" # flags, no PTS, header length 0 + return b"\x00\x00\x01" + bytes([stream_id]) + struct.pack(">H", len(hdr) + len(payload)) + hdr + payload + + +def movie(video, sound, chunk): + """A PMF: per pack a video packet (from `video`) and a sound packet of up to `chunk` ATRAC bytes with its 4-byte header.""" + out = bytearray(b"PSMF0015" + struct.pack(">I", HEADER)) + out += b"\0" * (HEADER - len(out)) + vpos = spos = 0 + while spos < len(sound) or vpos < len(video): + pack = bytearray(b"\x00\x00\x01\xba" + b"\x44\x00\x04\x00\x04\x01\x01\x89\xc3\xf8") + v = video[vpos:vpos + 400] + vpos += len(v) + if v: + pack += pes(0xE0, v) + s = sound[spos:spos + chunk] + if s: + nxt = (-spos) % FRAME # bytes until the next frame starts + first = nxt if nxt < len(s) else 0xFFFF + pack += pes(0xBD, b"\x00\x00" + struct.pack(">H", first) + s) + spos += len(s) + pack += b"\xff" * (ja.SECTOR - len(pack)) + out += pack + return bytes(out) + + +def sound_of(data): + parts, ok = ja._pes_audio(data) + return b"".join(data[s:s + n] for s, n in parts), ok + + +def main(): + en_sound = bytes((i * 7) & 0xFF for i in range(FRAME * 5)) + jp_sound = bytes((i * 13 + 5) & 0xFF for i in range(FRAME * 6)) # one frame longer, like DES01_010 + mine = movie(b"E" * 3000, en_sound, 1500) + undub = movie(b"J" * 3200, jp_sound, 1600) # other picture, other packets + s, ok = sound_of(mine) + assert ok and s == en_sound, "parser: the installed movie's sound" + s, ok = sound_of(undub) + assert ok and s == jp_sound, "parser: the undub movie's sound" + + out = ja.splice_movie_audio(mine, undub) + assert out is not None and len(out) == len(mine) + s, ok = sound_of(out) + assert ok and s == jp_sound[:len(en_sound)], "the undub's sound, its last frame left out" + parts, _ = ja._pes_audio(out) + masked_out, masked_mine = bytearray(out), bytearray(mine) + for st, n in parts: + masked_out[st:st + n] = masked_mine[st:st + n] = b"\0" * n + assert masked_out == masked_mine, "everything but the sound bytes is the installed movie (picture, packet headers)" + + shorter = movie(b"J" * 3200, jp_sound[:FRAME * 4], 1600) + s, _ = sound_of(ja.splice_movie_audio(mine, shorter)) + assert s == jp_sound[:FRAME * 4] + en_sound[FRAME * 4:], "a shorter undub sound: the installed sound fills in" + + broken = bytearray(undub) + i = broken.index(b"\x00\x00\x01\xbd", HEADER + ja.SECTOR) # the second sound packet: a frame start off the 752 grid + broken[i + 9 + 2:i + 9 + 4] = struct.pack(">H", 5) + assert ja.splice_movie_audio(mine, bytes(broken)) is None, "a stream not on 752-byte frames is refused" + print("test_jp_audio: ok") + + +if __name__ == "__main__": + main() From f8f4c2ad6c660a7f561b7c8bb63d3e61bd4d3deb Mon Sep 17 00:00:00 2001 From: Schindler Date: Wed, 18 Nov 2026 20:59:46 -0500 Subject: [PATCH 2/3] related-projects.md: movie splice done, story scenes need the Japanese disc Co-Authored-By: Claude Opus 5.5 --- psprecomp/games/dissidia/docs/related-projects.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/psprecomp/games/dissidia/docs/related-projects.md b/psprecomp/games/dissidia/docs/related-projects.md index e219af1..c3a3645 100644 --- a/psprecomp/games/dissidia/docs/related-projects.md +++ b/psprecomp/games/dissidia/docs/related-projects.md @@ -75,6 +75,9 @@ top of 1 frame of delay covers about 100 to 130 ms without a stall. This is the ### 3. Japanese voices: story scene scripts +**Movies done** (18 November 2026, `tools/jp_audio.py`, [audio.md](audio.md)). The scenes are not: the undub disc changes no scene +script, so this needs the Japanese disc (NPJH-50377). + Source: [docs/port/japanese-voices.md](https://github.com/VCKing101/Dissidia012-pc/blob/main/docs/port/japanese-voices.md), "Story scenes". Our `jp_audio.py` swaps audio files only. They found that **302 voiced story scenes** (`talkevent/*.evex`, ARC From 1d39fadaf1d2a4f67046cfd09d0a68aa633bc0e9 Mon Sep 17 00:00:00 2001 From: Schindler Date: Wed, 18 Nov 2026 23:56:27 -0500 Subject: [PATCH 3/3] jp_audio.py: decide an existing movie by its content, not its size An earlier version copied each undub movie whole; UP_GIL's whole copy has the same size as the installed movie, so the size check kept it (undub picture). Co-Authored-By: Claude Opus 5.5 --- psprecomp/games/dissidia/tools/jp_audio.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/psprecomp/games/dissidia/tools/jp_audio.py b/psprecomp/games/dissidia/tools/jp_audio.py index 3c405a3..6f5a1a6 100644 --- a/psprecomp/games/dissidia/tools/jp_audio.py +++ b/psprecomp/games/dissidia/tools/jp_audio.py @@ -243,16 +243,22 @@ def main(): hash_range(iso.f, r["extent"] * SECTOR, 0, r["size"]) == file_md5(mine_path): continue dest = os.path.join(out_movie, r["name"]) - want = os.path.getsize(mine_path) if mine_path else r["size"] - if os.path.isfile(dest) and os.path.getsize(dest) == want: - n_skip += 1 - continue - n_movie += 1 spliced = None if mine_path: iso.f.seek(r["extent"] * SECTOR) with open(mine_path, "rb") as mf: spliced = splice_movie_audio(mf.read(), iso.f.read(r["size"])) + if os.path.isfile(dest): + # by content, not size: an earlier version copied the undub's movie whole, and UP_GIL's is the same size + if spliced is not None: + with open(dest, "rb") as df: + same = df.read() == spliced + else: + same = os.path.getsize(dest) == r["size"] + if same: + n_skip += 1 + continue + n_movie += 1 if a.dry_run: say(" would write movie %s (%s)" % (r["name"], "your picture, Japanese sound" if spliced else "whole undub movie")) elif spliced is not None: