ws-audio2: music/umx (Unreal music packages): the package tables parsed, the music export's module handed to a new api hook opts.decodeModule(buf, format?)
src/Formats/init.luau: withHooks adds opts.decodeModule (F.load of the bytes as music) next to decodeImage / openAudio, so a format never requires another; docs/API.md lists it. Backward compatible (a new optional hook).
This commit is contained in:
1 parent
3d5cf3130e
commit
26fa887370
8 files changed
+368
-1
No files matched your search
@@ -893,3 +893,39 @@ def write_med(version, samples, blocks, sequence, tempo=125, tempo2=6, flags=0,
|
||||
hdr += struct.pack(">IIHHIB3sIIII11sB", len(out), song_at, 0, 0, block_arr, 0, b"\0\0\0", smp_arr, 0, exp, 0, b"\0" * 11, 0)
|
||||
out[0:52] = hdr
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def umx_index(v):
|
||||
"""an Unreal compact index"""
|
||||
neg, v = v < 0, abs(v)
|
||||
out = bytearray([(0x80 if neg else 0) | (v & 0x3F) | (0x40 if v > 0x3F else 0)])
|
||||
v >>= 6
|
||||
while v:
|
||||
out.append((v & 0x7F) | (0x80 if v > 0x7F else 0))
|
||||
v >>= 7
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def write_umx(modules, version=69):
|
||||
"""an Unreal package (UT99-era, package version 61..99) whose exports are Music objects: modules = [(object
|
||||
name, module bytes)]"""
|
||||
names = ["None", "Music", "Core", "Class"] + [n for n, _ in modules]
|
||||
out = bytearray(36)
|
||||
name_at = len(out)
|
||||
for n in names:
|
||||
b = n.encode() + b"\0"
|
||||
out += (umx_index(len(b)) if version >= 64 else b"") + b + struct.pack("<I", 0x04070010)
|
||||
imp_at = len(out)
|
||||
out += umx_index(names.index("Core")) + umx_index(names.index("Class")) + struct.pack("<i", 0) + umx_index(names.index("Music"))
|
||||
bodies = []
|
||||
for i, (n, data) in enumerate(modules):
|
||||
bodies.append(len(out))
|
||||
out += umx_index(0) + umx_index(0) + struct.pack("<I", 0) + umx_index(len(data)) + data
|
||||
exp_at = len(out)
|
||||
for i, (n, data) in enumerate(modules):
|
||||
size = len(umx_index(0)) * 2 + 4 + len(umx_index(len(data))) + len(data)
|
||||
out += umx_index(-1) + umx_index(0) + struct.pack("<i", 0) + umx_index(names.index(n)) + struct.pack("<I", 0x70004)
|
||||
out += umx_index(size) + umx_index(bodies[i])
|
||||
hdr = b"\xc1\x83\x2a\x9e" + struct.pack("<HHIIIIIII", version, 0, 1, len(names), name_at, len(modules), exp_at, 1, imp_at)
|
||||
out[0:36] = hdr
|
||||
return bytes(out)
|
||||
@@ -0,0 +1,34 @@
|
||||
# UMX fixtures (tools/fixtures.py): Unreal music packages wrapping generated modules (an S3M from tools/fixtures/s3m.py,
|
||||
# an IT from tools/fixtures/it.py), rendered by openmpt123 (which unwraps the package itself).
|
||||
# tests/gen/umx_cases.luau { name, data (the package), inner (the embedded module), format (its format), ref
|
||||
# (features of openmpt's render, tools/fixtures/_tracker.py), duration }
|
||||
import importlib.util, os, sys
|
||||
|
||||
# the shared tracker module, loaded by path (tools/fixtures/ must not go on sys.path: xml.py there would shadow xml)
|
||||
T = sys.modules.get("_tracker")
|
||||
if T is None:
|
||||
_spec = importlib.util.spec_from_file_location("_tracker", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_tracker.py"))
|
||||
T = importlib.util.module_from_spec(_spec)
|
||||
sys.modules["_tracker"] = T
|
||||
_spec.loader.exec_module(T)
|
||||
|
||||
INPUTS = ["tools/fixtures/_tracker.py", "tools/fixtures/s3m.py", "tools/fixtures/it.py"]
|
||||
|
||||
|
||||
def sibling(name):
|
||||
spec = importlib.util.spec_from_file_location("umx_" + name, os.path.join(os.path.dirname(os.path.abspath(__file__)), name + ".py"))
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(m)
|
||||
return m
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
s3m = sibling("s3m").song_mono()
|
||||
it = sibling("it").song_effects()
|
||||
cases = []
|
||||
items = [("s3m", "Mono_Theme", s3m, 69), ("it", "Effects", it, 63)]
|
||||
for fmt, nm, data, ver in items:
|
||||
pkg = T.write_umx([(nm, data)], version=ver)
|
||||
ref = T.reference(ctx, pkg, "umx")
|
||||
cases.append({"name": nm, "data": pkg, "inner": data, "format": fmt, "ref": ref, "duration": ref["duration"]})
|
||||
ctx.emit("umx_cases", cases)
|
||||
Reference in new issue
Block a user