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)
|
||||
Reference in new issue
Block a user