30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Render every song id (from the sound sets' C lists) to WAV + SPC via snd_build_spc.py ops and snd_play.
|
|
usage: snd_render_all.py ROM SND_PLAY OUTDIR [SECONDS]"""
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from snd_build_spc import SoundSim, sound_sets, write_ops # noqa: E402
|
|
|
|
rom = open(sys.argv[1], 'rb').read()
|
|
player, out = sys.argv[2], sys.argv[3]
|
|
seconds = int(sys.argv[4]) if len(sys.argv) > 4 else 20
|
|
os.makedirs(out, exist_ok=True)
|
|
songs = sorted({s for _a, _b, c in sound_sets(rom) for s in c})
|
|
boot = SoundSim(rom)
|
|
boot.boot()
|
|
boot_ops = list(boot.ops)
|
|
for s in songs:
|
|
sim = SoundSim(rom)
|
|
sim.boot()
|
|
sim.ops.clear()
|
|
sim.call(0x13, y=s)
|
|
sim.call(0x08, y=s) # 80:B781 sends $13 (load) then $08 (start); some sets only start on $08
|
|
ops = boot_ops + sim.ops + [('play', seconds * 60)]
|
|
p = f'{out}/song_{s:02X}.ops'
|
|
write_ops(ops, p)
|
|
r = subprocess.run([player, p, f'{out}/song_{s:02X}'], capture_output=True, text=True)
|
|
print(f'song {s:02X}: {r.stdout.strip() or r.stderr.strip()}')
|