ws-audio2: merge ws/audio2-tracker (MTM, 669, STM, ULT, OKT, MED, PTM, FAR, UMX; Tracker engine families)
This commit is contained in:
commit
270eccab0f
43 files changed
+4907
-65
No files matched your search
@@ -1211,3 +1211,29 @@ do
|
||||
end
|
||||
end
|
||||
end
|
||||
-- ws-audio2: trackers
|
||||
do
|
||||
-- the other tracker loaders on the shared engine: a 669 (Hz periods, auto slides) and an MMD1 (hold / decay
|
||||
-- envelopes, instruments) from tools/fixtures/{669,med}.py, decoded and rendered at 44.1 kHz
|
||||
local Six69 = require("@formats/music/669")
|
||||
local Med = require("@formats/music/med")
|
||||
local songs = { { Six69, require("@tests/gen/669_cases")[1].data }, { Med, require("@tests/gen/med_cases")[2].data } }
|
||||
local best, frames = math.huge, 0
|
||||
local out = buffer.create(4096 * 8)
|
||||
for _ = 1, 3 do
|
||||
frames = 0
|
||||
local t0 = os.clock()
|
||||
for _, s in songs do
|
||||
local dec = (s[1].decode(Bytes.reader(buffer.fromstring(s[2]))) :: any):render()
|
||||
while true do
|
||||
local _, n = dec:read(4096, out)
|
||||
if n == 0 then
|
||||
break
|
||||
end
|
||||
frames += n
|
||||
end
|
||||
end
|
||||
best = math.min(best, os.clock() - t0)
|
||||
end
|
||||
print(string.format("%-8s %-30s %8.2f ms %7.1f x realtime", runtime, "render 669 / med", best * 1000, frames / 44100 / best))
|
||||
end
|
||||
@@ -0,0 +1,94 @@
|
||||
# 669 fixtures (tools/fixtures.py): generated Composer 669 / UNIS 669 modules exercising the effects, rendered by
|
||||
# openmpt123.
|
||||
# tests/gen/669_cases.luau { name, data (the module), ref (features of openmpt's render, tools/fixtures/_tracker.py),
|
||||
# duration (openmpt's song length) }
|
||||
import 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:
|
||||
import importlib.util
|
||||
_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"]
|
||||
|
||||
|
||||
def empty():
|
||||
return [[(0, 0, None, None) for _ in range(8)] for _ in range(64)]
|
||||
|
||||
|
||||
def put(p, row, ch, note=0, ins=0, vol=None, cmd=None, param=0):
|
||||
p[row][ch] = (note, ins, vol, None if cmd is None else (cmd << 4) | param)
|
||||
|
||||
|
||||
def samples():
|
||||
return [
|
||||
{"name": "sine", "data": T.u8(T.synth("sine", 64, 64)), "loop": (0, 64)},
|
||||
{"name": "square", "data": T.u8(T.synth("square", 64, 64, 0.5)), "loop": (0, 64)},
|
||||
{"name": "saw", "data": T.u8(T.synth("saw", 100, 100, 0.6)), "loop": (0, 100)},
|
||||
{"name": "noise", "data": T.u8(T.synth("noise", 6000, 1, 0.7, decay=1500))},
|
||||
{"name": "tri", "data": T.u8(T.synth("tri", 50, 50, 0.8)), "loop": (0, 50)},
|
||||
]
|
||||
|
||||
|
||||
def song_effects(keep=None):
|
||||
a, b = empty(), empty()
|
||||
mel = [61, 65, 68, 73, 68, 65, 63, 61]
|
||||
for i in range(16):
|
||||
put(a, i * 4, 0, mel[i % 8], 1, 15)
|
||||
put(a, 0, 1, 49, 2, 12)
|
||||
put(a, 8, 1, 0, 0, None, 0, 2) # auto portamento up (runs until the next effect)
|
||||
put(a, 16, 1, 0, 0, None, 1, 3) # auto portamento down
|
||||
put(a, 24, 1, 0, 0, None, 5, 3) # speed (stops the auto slide)
|
||||
put(a, 28, 1, 56, 2, 10)
|
||||
put(a, 32, 1, 61, 2, None, 2, 2) # tone portamento (keeps going)
|
||||
put(a, 40, 1, 49, 2, None, 2, 4)
|
||||
put(a, 48, 1, 0, 0, 6, 3, 5) # frequency adjust
|
||||
put(a, 52, 1, 0, 0, None, 4, 3) # frequency vibrato
|
||||
for r in range(0, 64, 8):
|
||||
put(a, r, 3, 61, 4, 15 - r // 8)
|
||||
put(a, 4, 2, 37, 3, 15)
|
||||
put(a, 36, 2, 0, 0, 4)
|
||||
put(a, 10, 4, 73, 5, 9)
|
||||
put(a, 20, 4, 0, 0, None, 4, 6)
|
||||
# b: speed per pattern, a break row, more slides
|
||||
put(b, 0, 0, 49, 1, 15)
|
||||
put(b, 4, 0, 0, 0, None, 1, 1)
|
||||
put(b, 12, 0, 61, 1, 15)
|
||||
put(b, 16, 0, 0, 0, None, 0, 1)
|
||||
put(b, 20, 0, 0, 0, 10, None)
|
||||
put(b, 0, 2, 37, 3, 12)
|
||||
put(b, 8, 2, 44, 3, None, 2, 1)
|
||||
put(b, 24, 2, 0, 0, None, 3, 2)
|
||||
put(b, 0, 5, 56, 5, 13)
|
||||
put(b, 16, 5, 52, 2, 13)
|
||||
if keep is not None:
|
||||
for p in (a, b):
|
||||
for row in p:
|
||||
for ch in range(8):
|
||||
if ch not in keep:
|
||||
row[ch] = (0, 0, None, None)
|
||||
return T.write_669("effects 669", samples(), [0, 1], [a, b], [4, 3], [63, 40])
|
||||
|
||||
|
||||
def song_unis():
|
||||
"""UNIS 669: balance slides, slot retrigger, a restart position"""
|
||||
a = empty()
|
||||
put(a, 0, 0, 61, 1, 15, 6, 0) # balance slide left (repeats until the next note)
|
||||
put(a, 16, 0, 64, 1, 15, 6, 1) # right
|
||||
put(a, 32, 1, 49, 4, 15, 7, 3) # slot retrigger
|
||||
put(a, 40, 1, 49, 4, 15, 7, 6)
|
||||
put(a, 8, 2, 68, 2, 11)
|
||||
put(a, 48, 3, 56, 3, 14)
|
||||
return T.write_669("unis", samples(), [0, 0], [a], [5], [63], extended=True)
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
cases = []
|
||||
for nm, data in (("effects", song_effects()), ("unis", song_unis())):
|
||||
ref = T.reference(ctx, data, "669")
|
||||
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
|
||||
ctx.emit("669_cases", cases)
|
||||
@@ -494,3 +494,439 @@ def reference(ctx, data, ext, extra=()):
|
||||
f = features(left, right)
|
||||
f["duration"] = duration(ctx, data, ext)
|
||||
return f
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------- other trackers
|
||||
# (ws-audio2: MTM, 669, STM, ULT, OKT, MED, PTM, FAR, UMX writers for tools/fixtures/{mtm,669,...}.py)
|
||||
def write_mtm(title, samples, orders, patterns, channels, pans=None, rows=64, comment=b""):
|
||||
"""samples: [{name, data (raw unsigned bytes; 16-bit: little-endian unsigned), bits 8|16, volume 0..64,
|
||||
finetune -8..7, loop: (start, end) in bytes | None}]; patterns: [[row: [(note, ins, fx, param)] * channels] * rows]
|
||||
with note 0 = none else our note (1 = C-0; 49 = C-4 plays at 8363 Hz; >= 25)"""
|
||||
tracks, index = [], {}
|
||||
table = []
|
||||
for pat in patterns:
|
||||
ids = []
|
||||
for ch in range(32):
|
||||
if ch >= channels:
|
||||
ids.append(0)
|
||||
continue
|
||||
tb = bytearray()
|
||||
for r in range(rows):
|
||||
note, ins, fx, param = pat[r][ch] if r < len(pat) else (0, 0, 0, 0)
|
||||
n = note - 25 if note else 0
|
||||
tb += bytes([(n << 2) | (ins >> 4), ((ins & 15) << 4) | fx, param])
|
||||
tb = bytes(tb) + b"\0" * (192 - len(tb))
|
||||
if not any(tb):
|
||||
ids.append(0)
|
||||
continue
|
||||
if tb not in index:
|
||||
tracks.append(tb)
|
||||
index[tb] = len(tracks)
|
||||
ids.append(index[tb])
|
||||
table.append(ids)
|
||||
out = bytearray(b"MTM\x10" + name(title, 20))
|
||||
out += struct.pack("<HBBHBBBB", len(tracks), len(patterns) - 1, len(orders) - 1, len(comment), len(samples), 0, rows,
|
||||
channels)
|
||||
pp = list(pans or [(i % 2) * 15 for i in range(channels)])
|
||||
out += bytes(pp + [0] * (32 - len(pp)))
|
||||
for s in samples:
|
||||
ls, le = s.get("loop") or (0, 0)
|
||||
out += name(s.get("name", ""), 22) + struct.pack("<IIIbBB", len(s["data"]), ls, le, s.get("finetune", 0),
|
||||
s.get("volume", 64), 1 if s.get("bits", 8) == 16 else 0)
|
||||
out += bytes(orders) + b"\0" * (128 - len(orders))
|
||||
for tb in tracks:
|
||||
out += tb
|
||||
for ids in table:
|
||||
out += b"".join(struct.pack("<H", t) for t in ids)
|
||||
out += comment
|
||||
for s in samples:
|
||||
out += s["data"]
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def u16(xs):
|
||||
return b"".join(struct.pack("<H", max(0, min(65535, int(round(x * 32767)) + 32768))) for x in xs)
|
||||
|
||||
|
||||
def write_669(message, samples, orders, patterns, tempos, breaks, restart=0, extended=False):
|
||||
"""samples: [{name, data (unsigned bytes), loop: (start, end) | None}]; patterns: [[row: [(note, ins, vol, effect)]
|
||||
* 8] * 64] with note 0 = none else our note (>= 37), ins 1-based, vol 0..15 or None, effect byte (cmd << 4 | param)
|
||||
or None; tempos / breaks: per pattern"""
|
||||
out = bytearray(b"JN" if extended else b"if")
|
||||
msg = message.encode()[:108]
|
||||
out += msg + b" " * (108 - len(msg))
|
||||
out += bytes([len(samples), len(patterns), restart])
|
||||
out += bytes(orders) + b"\xff" * (128 - len(orders))
|
||||
out += bytes(tempos) + b"\x04" * (128 - len(tempos))
|
||||
out += bytes(breaks) + b"\x3f" * (128 - len(breaks))
|
||||
for s in samples:
|
||||
ls, le = s.get("loop") or (0, 0xFFFFF)
|
||||
out += name(s.get("name", ""), 13) + struct.pack("<III", len(s["data"]), ls, le)
|
||||
for pat in patterns:
|
||||
for row in pat:
|
||||
for (note, ins, vol, eff) in row:
|
||||
if note:
|
||||
n, i = note - 37, ins - 1
|
||||
out += bytes([(n << 2) | (i >> 4), ((i & 15) << 4) | (vol if vol is not None else 0)])
|
||||
elif vol is not None:
|
||||
out += bytes([0xFE, vol])
|
||||
else:
|
||||
out += b"\xff\x00"
|
||||
out.append(0xFF if eff is None else eff)
|
||||
for s in samples:
|
||||
out += s["data"]
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def write_stm(title, samples, orders, patterns, tempo=0x60, gvol=64, minor=21):
|
||||
"""samples: [{name, data (signed bytes), volume, c2spd, loop: (start, end) | None}] (up to 31); patterns: [[row:
|
||||
[(note, ins, vol, cmd, info)] * 4] * 64] with note 0 = none, 254 = cut, else our note (>= 37); vol None = none;
|
||||
cmd 0 = none (A = 1, letters as in S3M)"""
|
||||
head = bytearray(name(title, 20) + b"!Scream!" + bytes([0x1A, 2, 2, minor, tempo, len(patterns), gvol]) + b"\0" * 13)
|
||||
smp_at = len(head)
|
||||
head += b"\0" * (31 * 32)
|
||||
head += bytes(orders) + bytes([99] * ((64 if minor == 0 else 128) - len(orders)))
|
||||
for pat in patterns:
|
||||
for row in pat:
|
||||
for (note, ins, vol, cmd, info) in row:
|
||||
if note in ("skip", "fb"):
|
||||
head.append(0xFC if note == "skip" else 0xFB) # nothing / a C-0 at volume 0
|
||||
continue
|
||||
if note == 254:
|
||||
nb = 0xFE
|
||||
elif note:
|
||||
n = note - 37
|
||||
nb = (n // 12) << 4 | (n % 12)
|
||||
else:
|
||||
nb = 0xFF
|
||||
v = 65 if vol is None else vol
|
||||
head += bytes([nb, (ins << 3) | (v & 7), ((v >> 3) << 4) | cmd, info])
|
||||
body = head
|
||||
for i in range(31):
|
||||
h = bytearray(32)
|
||||
if i < len(samples):
|
||||
s = samples[i]
|
||||
while len(body) % 16:
|
||||
body.append(0)
|
||||
off = len(body) // 16
|
||||
body += s["data"]
|
||||
ls, le = s.get("loop") or (0, 0xFFFF)
|
||||
h[0:12] = name(s.get("name", ""), 12)
|
||||
struct.pack_into("<HHHHBBH", h, 14, off, len(s["data"]), ls, le, s.get("volume", 64), 0, s.get("c2spd", 8363))
|
||||
else:
|
||||
struct.pack_into("<HHHH", h, 14, 0, 0, 0, 0xFFFF)
|
||||
body[smp_at + 32 * i:smp_at + 32 * i + 32] = h
|
||||
return bytes(body)
|
||||
|
||||
|
||||
def write_ult(title, samples, orders, patterns, channels, version=4, pans=None, message=b""):
|
||||
"""samples: [{name, data (signed bytes; 16-bit little-endian), bits 8|16, volume 0..255, speed (c2spd / 2... the
|
||||
file's C-4 rate), finetune, loop: (start, end) in frames | None, pingpong}]; patterns: [[row: [(note, ins, e1, p1,
|
||||
e2, p2)] * channels] * 64] with note 0 = none else our note (25..120), e1 / e2 effect nibbles (low / high nibble of
|
||||
the effect byte); repeated identical events are run-length packed"""
|
||||
out = bytearray(b"MAS_UTrack_V00" + bytes([0x30 + version]) + name(title, 32).replace(b"\0", b" "))
|
||||
out.append(len(message) // 32)
|
||||
out += message
|
||||
out.append(len(samples))
|
||||
pos = 0
|
||||
for s in samples:
|
||||
bps = 2 if s.get("bits", 8) == 16 else 1
|
||||
n = len(s["data"]) // bps
|
||||
ls, le = s.get("loop") or (0, 0)
|
||||
fl = (4 if bps == 2 else 0) | (8 if s.get("loop") else 0) | (16 if s.get("pingpong") else 0)
|
||||
out += name(s.get("name", ""), 32) + name(s.get("name", "")[:8] + ".smp", 12)
|
||||
out += struct.pack("<IIIIBB", ls * bps, le * bps, pos, pos + n, s.get("volume", 255), fl)
|
||||
if version >= 4:
|
||||
out += struct.pack("<Hh", s.get("speed", 8363), s.get("finetune", 0))
|
||||
else:
|
||||
out += struct.pack("<h", s.get("finetune", 0))
|
||||
pos += n
|
||||
out += bytes(orders) + b"\xff" * (256 - len(orders))
|
||||
out += bytes([channels - 1, len(patterns) - 1])
|
||||
if version >= 3:
|
||||
out += bytes(pans or [(i % 2) * 15 for i in range(channels)])
|
||||
for ch in range(channels):
|
||||
for pat in patterns:
|
||||
evs = []
|
||||
for row in pat:
|
||||
note, ins, e1, p1, e2, p2 = row[ch]
|
||||
evs.append(bytes([note - 24 if note else 0, ins, (e2 << 4) | e1, p1, p2]))
|
||||
i = 0
|
||||
while i < len(evs):
|
||||
j = i
|
||||
while j + 1 < len(evs) and evs[j + 1] == evs[i] and j - i < 250:
|
||||
j += 1
|
||||
if j > i:
|
||||
out += bytes([0xFC, j - i + 1]) + evs[i]
|
||||
else:
|
||||
out += evs[i]
|
||||
i = j + 1
|
||||
for s in samples:
|
||||
out += s["data"]
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def write_ptm(title, samples, orders, patterns, channels, pans=None):
|
||||
"""samples: [{name, data (signed bytes; 16-bit little-endian), bits 8|16, volume, c4spd, loop: (start, end) in
|
||||
frames | None, pingpong}] (stored delta coded: 8-bit deltas of the byte stream, also for 16-bit); patterns: [[row:
|
||||
[(note, ins, vol, cmd, param)] * channels] * 64] with note 0 = none, 254 = cut, else our note (1..120); vol None =
|
||||
none; cmd None = none, else 0..0x16 (MOD effects 0..F, then PolyTracker's G..)"""
|
||||
head = bytearray(name(title, 28) + bytes([26, 3, 2, 0]))
|
||||
head += struct.pack("<HHHHH", len(orders), len(samples), len(patterns), channels, 0) + b"\0\0PTMF" + b"\0" * 16
|
||||
pp = list(pans or [(i % 2) * 15 for i in range(channels)])
|
||||
head += bytes(pp + [0] * (32 - len(pp)))
|
||||
head += bytes(orders) + b"\xff" * (256 - len(orders))
|
||||
pat_at = len(head)
|
||||
head += b"\0" * 256
|
||||
smp_at = len(head)
|
||||
head += b"\0" * (80 * len(samples))
|
||||
body = head
|
||||
for k, pat in enumerate(patterns):
|
||||
while len(body) % 16:
|
||||
body.append(0)
|
||||
struct.pack_into("<H", body, pat_at + 2 * k, len(body) // 16)
|
||||
for row in pat:
|
||||
for ch, (note, ins, vol, cmd, param) in enumerate(row):
|
||||
what = (0x20 if note or ins else 0) | (0x40 if cmd is not None else 0) | (0x80 if vol is not None else 0)
|
||||
if what:
|
||||
body.append(what | ch)
|
||||
if what & 0x20:
|
||||
body += bytes([note, ins])
|
||||
if what & 0x40:
|
||||
body += bytes([cmd, param])
|
||||
if what & 0x80:
|
||||
body.append(vol)
|
||||
body.append(0)
|
||||
for i, s in enumerate(samples):
|
||||
bps = 2 if s.get("bits", 8) == 16 else 1
|
||||
raw = s["data"]
|
||||
enc, prev = bytearray(), 0
|
||||
for b in raw:
|
||||
enc.append((b - prev) & 255)
|
||||
prev = b
|
||||
off = len(body)
|
||||
body += enc
|
||||
ls, le = s.get("loop") or (0, 0)
|
||||
fl = 1 | (4 if s.get("loop") else 0) | (8 if s.get("pingpong") else 0) | (16 if bps == 2 else 0)
|
||||
h = bytearray(80)
|
||||
h[0] = fl
|
||||
h[1:13] = name(s.get("name", "")[:8] + ".smp", 12)
|
||||
h[13] = s.get("volume", 64)
|
||||
struct.pack_into("<HHIIII", h, 14, s.get("c4spd", 8363), 0, off, len(raw), ls * bps, (le * bps + 1) if s.get("loop") else 0)
|
||||
h[48:76] = name(s.get("name", ""), 28)
|
||||
h[76:80] = b"PTMS"
|
||||
body[smp_at + 80 * i:smp_at + 80 * i + 80] = h
|
||||
return bytes(body)
|
||||
|
||||
|
||||
def write_far(title, samples, orders, patterns, speed=4, pans=None, breaks=None, message=b"", restart=0, mute=()):
|
||||
"""samples: [{name, data (signed bytes; 16-bit little-endian), bits 8|16, volume 0..15, loop: (start, end) in
|
||||
frames | None}] (at most 64, stored in order); patterns: [[row: [(note, ins, vol, effect)] * 16] * rows] with note 0
|
||||
= none else our note (37..108), ins 1-based, vol 0 = none else 1..16, effect byte (cmd << 4 | param); breaks: the
|
||||
break-row byte per pattern"""
|
||||
head = bytearray(b"FAR\xfe" + name(title, 40) + b"\r\n\x1a")
|
||||
hl_at = len(head)
|
||||
head += b"\0\0" + bytes([0x10]) + bytes([0 if i in mute else 1 for i in range(16)]) + b"\0" * 9 + bytes([speed])
|
||||
head += bytes(list(pans or [(i % 2) * 15 for i in range(16)]))
|
||||
head += b"\0" * 4 + struct.pack("<H", len(message)) + message
|
||||
head += bytes(orders) + b"\xff" * (256 - len(orders)) + bytes([len(patterns), len(orders), restart])
|
||||
sizes = [2 + len(p) * 64 for p in patterns] + [0] * (256 - len(patterns))
|
||||
head += b"".join(struct.pack("<H", s) for s in sizes)
|
||||
struct.pack_into("<H", head, hl_at, len(head))
|
||||
body = head
|
||||
for k, pat in enumerate(patterns):
|
||||
body += bytes([(breaks or [0] * len(patterns))[k], 0])
|
||||
for row in pat:
|
||||
for (note, ins, vol, eff) in row:
|
||||
body += bytes([note - 36 if note else 0, max(0, ins - 1), vol, eff])
|
||||
smap = bytearray(8)
|
||||
for i in range(len(samples)):
|
||||
smap[i >> 3] |= 1 << (i & 7)
|
||||
body += smap
|
||||
for s in samples:
|
||||
bps = 2 if s.get("bits", 8) == 16 else 1
|
||||
ls, le = s.get("loop") or (0, 0)
|
||||
body += name(s.get("name", ""), 32) + struct.pack("<IBBIIBB", len(s["data"]), 0, s.get("volume", 15), ls * bps, le * bps,
|
||||
1 if bps == 2 else 0, 8 if s.get("loop") else 0)
|
||||
body += s["data"]
|
||||
return bytes(body)
|
||||
|
||||
|
||||
def write_okt(samples, orders, patterns, cmod=(0, 0, 0, 0), speed=6):
|
||||
"""samples: [{name, data (signed bytes, even length), volume 0..64, type 0 paired / 1 raw / 2 both, loop: (start,
|
||||
length) in bytes (even) | None}]; patterns: [[row: [(note, ins, effect, param)] * channels] * rows] with note 0 =
|
||||
none else 1..36 (13 = C-5 of the module), ins 1-based; cmod: the four Amiga channels, 1 = a mixed pair"""
|
||||
def chunk(cid, data):
|
||||
return cid + struct.pack(">I", len(data)) + data
|
||||
out = bytearray(b"OKTASONG")
|
||||
out += chunk(b"CMOD", b"".join(struct.pack(">H", c) for c in cmod))
|
||||
sh = bytearray()
|
||||
for i in range(36):
|
||||
if i < len(samples):
|
||||
s = samples[i]
|
||||
ls, ll = s.get("loop") or (0, 0)
|
||||
sh += name(s.get("name", ""), 20) + struct.pack(">IHHHH", len(s["data"]), ls // 2, ll // 2, s.get("volume", 64), s.get("type", 2))
|
||||
else:
|
||||
sh += b"\0" * 32
|
||||
out += chunk(b"SAMP", bytes(sh))
|
||||
out += chunk(b"SPEE", struct.pack(">H", speed))
|
||||
out += chunk(b"SLEN", struct.pack(">H", len(patterns)))
|
||||
out += chunk(b"PLEN", struct.pack(">H", len(orders)))
|
||||
out += chunk(b"PATT", bytes(orders) + b"\0" * (128 - len(orders)))
|
||||
for pat in patterns:
|
||||
pb = bytearray(struct.pack(">H", len(pat)))
|
||||
for row in pat:
|
||||
for (note, ins, fx, param) in row:
|
||||
pb += bytes([note, max(0, ins - 1), fx, param])
|
||||
out += chunk(b"PBOD", bytes(pb))
|
||||
for s in samples:
|
||||
out += chunk(b"SBOD", s["data"])
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def write_med(version, samples, blocks, sequence, tempo=125, tempo2=6, flags=0, flags2=0, trackvols=None,
|
||||
pans=None, master=64, play_transpose=0, sections=None, title=None):
|
||||
"""an MMD0 .. MMD3 module. samples: [{data (signed 8-bit bytes, or big-endian 16-bit with bits 16), bits, volume,
|
||||
transpose, loop: (start, length) in bytes (even) | None, hold, decay, finetune, octaves (IFF multi-octave count:
|
||||
data holds the octaves from the lowest, each twice as long)}]; blocks: [[row: [(note, ins, cmd, param)] * tracks]
|
||||
* rows] with note 0 = none else the MED note (1 = C-1; MMD1+: 0x80 = note off); sequence: block numbers (MMD0 / 1)
|
||||
or the play sequence (MMD2 / 3; sections: [[playseq numbers]] and playseqs = [sequence])"""
|
||||
out = bytearray(52)
|
||||
song_at = 52
|
||||
out += b"\0" * (63 * 8 + 284)
|
||||
need_ext = any(s.get("hold") or s.get("finetune") for s in samples) or title is not None
|
||||
|
||||
def align():
|
||||
while len(out) % 4:
|
||||
out.append(0)
|
||||
|
||||
# blocks
|
||||
block_ptrs = []
|
||||
for blk in blocks:
|
||||
align()
|
||||
block_ptrs.append(len(out))
|
||||
ntr = len(blk[0])
|
||||
if version == 0:
|
||||
out += bytes([ntr, len(blk) - 1])
|
||||
else:
|
||||
out += struct.pack(">HHI", ntr, len(blk) - 1, 0)
|
||||
for row in blk:
|
||||
for (note, ins, cmd, param) in row:
|
||||
if version == 0:
|
||||
out += bytes([(note & 0x3F) | ((ins & 0x10) << 3) | ((ins & 0x20) << 1), ((ins & 15) << 4) | (cmd & 15), param])
|
||||
else:
|
||||
out += bytes([note, ins & 0x3F, cmd, param])
|
||||
align()
|
||||
block_arr = len(out)
|
||||
for p in block_ptrs:
|
||||
out += struct.pack(">I", p)
|
||||
# instruments
|
||||
inst_ptrs = []
|
||||
for s in samples:
|
||||
align()
|
||||
inst_ptrs.append(len(out))
|
||||
oct_ = s.get("octaves", 1)
|
||||
typ = {1: 0, 5: 1, 3: 2, 2: 3, 4: 4, 6: 5, 7: 6}[oct_] | (0x10 if s.get("bits", 8) == 16 else 0)
|
||||
out += struct.pack(">Ih", len(s["data"]), typ) + s["data"]
|
||||
align()
|
||||
smp_arr = len(out)
|
||||
for p in inst_ptrs:
|
||||
out += struct.pack(">I", p)
|
||||
# play sequences (MMD2 / 3)
|
||||
seq_info = None
|
||||
if version >= 2:
|
||||
align()
|
||||
psq = []
|
||||
for sq in [sequence]:
|
||||
psq.append(len(out))
|
||||
out += name("seq", 32) + struct.pack(">IIH", 0, 0, len(sq)) + b"".join(struct.pack(">H", b) for b in sq)
|
||||
align()
|
||||
ps_table = len(out)
|
||||
for p in psq:
|
||||
out += struct.pack(">I", p)
|
||||
sec_table = len(out)
|
||||
secs = sections or [0]
|
||||
for sc in secs:
|
||||
out += struct.pack(">H", sc)
|
||||
align()
|
||||
tv = len(out)
|
||||
out += bytes(trackvols or [64] * len(blocks[0][0]))
|
||||
tp = 0
|
||||
if pans:
|
||||
tp = len(out)
|
||||
out += bytes([p & 255 for p in pans])
|
||||
seq_info = (ps_table, sec_table, tv, tp, len(secs))
|
||||
# expansion: instrument extras + song name
|
||||
exp = 0
|
||||
if need_ext:
|
||||
align()
|
||||
ie = len(out)
|
||||
for s in samples:
|
||||
ls, ll = s.get("loop") or (0, 0)
|
||||
out += struct.pack(">BBBbBBHBBIIBBH", s.get("hold", 0), s.get("decay", 0), 0, s.get("finetune", 0), 0,
|
||||
1 if s.get("loop") else 0, 0, 0, 0, ls, ll, 127, 0, 0)
|
||||
nm = (title or "").encode() + b"\0"
|
||||
na = len(out)
|
||||
out += nm
|
||||
align()
|
||||
exp = len(out)
|
||||
e = bytearray(80)
|
||||
struct.pack_into(">IIHH", e, 0, 0, ie, len(samples), 22)
|
||||
struct.pack_into(">II", e, 44, na, len(nm))
|
||||
out += e
|
||||
# the song header
|
||||
for i, s in enumerate(samples):
|
||||
ls, ll = s.get("loop") or (0, 0)
|
||||
struct.pack_into(">HHBBBb", out, song_at + 8 * i, ls // 2, ll // 2, 0, 0, s.get("volume", 64), s.get("transpose", 0))
|
||||
sh = song_at + 63 * 8
|
||||
if version < 2:
|
||||
struct.pack_into(">HH", out, sh, len(blocks), len(sequence))
|
||||
out[sh + 4:sh + 4 + len(sequence)] = bytes(sequence)
|
||||
else:
|
||||
ps_table, sec_table, tv, tp, nsec = seq_info
|
||||
struct.pack_into(">HH", out, sh, len(blocks), nsec)
|
||||
struct.pack_into(">IIIHHIIHH", out, sh + 4, ps_table, sec_table, tv, len(blocks[0][0]), 1, tp, 0, 100, 0)
|
||||
struct.pack_into(">HbBBB", out, sh + 260, tempo, play_transpose, flags, flags2, tempo2)
|
||||
out[sh + 266:sh + 282] = bytes((trackvols or [64] * 16)[:16]) + bytes(max(0, 16 - len(trackvols or [0] * 16)))
|
||||
out[sh + 282] = master
|
||||
out[sh + 283] = len(samples)
|
||||
hdr = bytearray(b"MMD" + bytes([0x30 + version]))
|
||||
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)
|
||||
@@ -1,12 +1,13 @@
|
||||
# Docs inputs for the audio / music / video / subtitle guide pages (tools/fixtures.py; tools/docs_check.py reads them):
|
||||
# tiny ffmpeg test clips (testsrc 64x48, 10 frames at 10 fps, with a sine track): MP4 (H.264 + AAC), AVI (MJPEG +
|
||||
# PCM), WebM (VP8 + Vorbis); a MIDI file written here (SMF 1: a tempo track and a melody), the SoundFont of
|
||||
# tools/fixtures/sf2.py (build_sf2), a ProTracker module from tools/fixtures/mod.py (song_basic), and SRT / WebVTT /
|
||||
# ASS subtitles.
|
||||
# tools/fixtures/sf2.py (build_sf2), a ProTracker module from tools/fixtures/mod.py (song_basic), MultiTracker / MED
|
||||
# modules and an Unreal package (tools/fixtures/mtm.py, med.py, s3m.py), and SRT / WebVTT / ASS subtitles.
|
||||
# tests/gen/docs_av.luau { files = { [name] = bytes }, vars = { mp4Bytes = "clip.mp4", ... } }
|
||||
import importlib.util, os, struct, tempfile
|
||||
|
||||
INPUTS = ["tools/docs_check.py", "tools/fixtures/sf2.py", "tools/fixtures/mod.py"]
|
||||
INPUTS = ["tools/docs_check.py", "tools/fixtures/sf2.py", "tools/fixtures/mod.py", "tools/fixtures/mtm.py",
|
||||
"tools/fixtures/med.py", "tools/fixtures/s3m.py", "tools/fixtures/_tracker.py"]
|
||||
|
||||
|
||||
def load(ctx, name):
|
||||
@@ -100,6 +101,11 @@ def generate(ctx):
|
||||
files["bank.sf2"] = sf2.build_sf2(False)[0]
|
||||
mod = load(ctx, "fixtures/mod")
|
||||
files["song.mod"] = mod.song_basic()
|
||||
# ws-audio2: more tracker formats (tools/fixtures/mtm.py, med.py; an Unreal package around an S3M)
|
||||
files["song.mtm"] = load(ctx, "fixtures/mtm").song_effects()
|
||||
files["song.med"] = load(ctx, "fixtures/med").song_basic(version=1)
|
||||
tracker = load(ctx, "fixtures/_tracker")
|
||||
files["music.umx"] = tracker.write_umx([("Theme", load(ctx, "fixtures/s3m").song_mono())])
|
||||
files["subs.srt"] = SRT
|
||||
files["subs.vtt"] = VTT
|
||||
files["subs.ass"] = ASS
|
||||
@@ -110,6 +116,9 @@ def generate(ctx):
|
||||
"midiBytes": "tune.mid",
|
||||
"sf2Bytes": "bank.sf2",
|
||||
"modBytes": "song.mod",
|
||||
"mtmBytes": "song.mtm",
|
||||
"medBytes": "song.med",
|
||||
"umxBytes": "music.umx",
|
||||
"srtText": "subs.srt",
|
||||
"vttText": "subs.vtt",
|
||||
"assText": "subs.ass",
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
# FAR fixtures (tools/fixtures.py): generated Farandole Composer modules exercising the effects, rendered by openmpt123.
|
||||
# tests/gen/far_cases.luau { name, data (the module), ref (features of openmpt's render, tools/fixtures/_tracker.py),
|
||||
# duration (openmpt's song length) }
|
||||
import 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:
|
||||
import importlib.util
|
||||
_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"]
|
||||
|
||||
|
||||
def empty(rows=64):
|
||||
return [[(0, 0, 0, 0) for _ in range(16)] for _ in range(rows)]
|
||||
|
||||
|
||||
def put(p, row, ch, note=0, ins=0, vol=0, cmd=None, param=0):
|
||||
p[row][ch] = (note, ins, vol, 0 if cmd is None else (cmd << 4) | param)
|
||||
|
||||
|
||||
def samples():
|
||||
return [
|
||||
{"name": "sine", "data": T.s8(T.synth("sine", 64, 64)), "volume": 15, "loop": (0, 64)},
|
||||
{"name": "square", "data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 11, "loop": (0, 64)},
|
||||
{"name": "saw16", "data": T.s16(T.synth("saw", 200, 100, 0.6)), "bits": 16, "volume": 15, "loop": (0, 200)},
|
||||
{"name": "noise", "data": T.s8(T.synth("noise", 6000, 1, 0.7, decay=1500)), "volume": 14},
|
||||
{"name": "tri", "data": T.s8(T.synth("tri", 50, 50, 0.8)), "volume": 12, "loop": (0, 50)},
|
||||
]
|
||||
|
||||
|
||||
def song_effects(keep=None):
|
||||
a, b = empty(), empty(48)
|
||||
mel = [61, 65, 68, 73, 68, 65, 63, 61]
|
||||
for i in range(16):
|
||||
put(a, i * 4, 0, mel[i % 8], 1, 16 - i % 4)
|
||||
put(a, 0, 1, 49, 2, 12)
|
||||
put(a, 4, 1, 0, 0, 0, 0x1, 0x3) # fine porta up
|
||||
put(a, 8, 1, 0, 0, 0, 0x2, 0x5)
|
||||
put(a, 12, 1, 0, 0, 0, 0x8, 0x2) # volume slide down
|
||||
put(a, 16, 1, 51, 2, 14, 0x7, 0x1) # up
|
||||
put(a, 20, 1, 0, 0, 0, 0x5, 0x4) # vibrato depth
|
||||
put(a, 21, 1, 0, 0, 0, 0x6, 0x2) # vibrato speed
|
||||
put(a, 28, 1, 56, 2, 14)
|
||||
put(a, 32, 1, 61, 2, 0, 0x3, 0x4) # tone portamento (keeps going)
|
||||
put(a, 40, 1, 49, 2, 0, 0x3, 0x2)
|
||||
put(a, 48, 1, 0, 0, 0, 0xA, 0x8) # volume portamento
|
||||
for r in range(0, 64, 8):
|
||||
put(a, r, 3, 61, 4, 16 - r // 8)
|
||||
put(a, 36, 3, 61, 4, 16, 0x4, 0x2) # retrigger
|
||||
put(a, 4, 2, 37, 3, 12)
|
||||
put(a, 2, 4, 73, 5, 10, 0xB, 0x2) # panning
|
||||
put(a, 30, 4, 0, 0, 0, 0xB, 0xD)
|
||||
put(a, 10, 5, 56, 1, 12)
|
||||
put(a, 24, 5, 0, 0, 0, 0xF, 0x3) # speed
|
||||
put(b, 0, 0, 49, 1, 16)
|
||||
put(b, 8, 0, 61, 1, 16, 0x2, 0x8)
|
||||
put(b, 0, 2, 37, 3, 12)
|
||||
put(b, 16, 2, 44, 3, 10, 0x9, 0x3)
|
||||
put(b, 20, 6, 68, 5, 16)
|
||||
put(b, 24, 9, 56, 2, 16) # a muted channel
|
||||
if keep is not None:
|
||||
for p in (a, b):
|
||||
for row in p:
|
||||
for ch in range(16):
|
||||
if ch not in keep and (row[ch][3] >> 4) != 0xF:
|
||||
row[ch] = (0, 0, 0, 0)
|
||||
return T.write_far("effects", samples(), [0, 1], [a, b], speed=5, breaks=[0, 30], mute=(9,),
|
||||
pans=[3, 12, 7, 0, 15, 9, 5, 10, 8, 8, 8, 8, 8, 8, 8, 8], message=b"far test")
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
cases = []
|
||||
for nm, data in (("effects", song_effects()),):
|
||||
ref = T.reference(ctx, data, "far")
|
||||
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
|
||||
ctx.emit("far_cases", cases)
|
||||
@@ -0,0 +1,113 @@
|
||||
# MED fixtures (tools/fixtures.py): generated MED / OctaMED modules (MMD0, MMD1 with instrument extras, MMD2 with a play
|
||||
# sequence) exercising the effects, rendered by openmpt123.
|
||||
# tests/gen/med_cases.luau { name, data (the module), ref (features of openmpt's render, tools/fixtures/_tracker.py),
|
||||
# duration (openmpt's song length) }
|
||||
import 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:
|
||||
import importlib.util
|
||||
_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"]
|
||||
|
||||
|
||||
def empty(ch, rows=64):
|
||||
return [[(0, 0, 0, 0) for _ in range(ch)] for _ in range(rows)]
|
||||
|
||||
|
||||
def put(p, row, ch, note=0, ins=0, cmd=0, param=0):
|
||||
p[row][ch] = (note, ins, cmd, param)
|
||||
|
||||
|
||||
def samples(extras=False):
|
||||
s = [
|
||||
{"data": T.s8(T.synth("sine", 64, 64)), "volume": 64, "loop": (0, 64)},
|
||||
{"data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 44, "loop": (0, 64)},
|
||||
{"data": T.s8(T.synth("saw", 128, 64, 0.6)), "volume": 64, "loop": (64, 64), "transpose": -12},
|
||||
{"data": T.s8(T.synth("noise", 4000, 1, 0.7, decay=1200)), "volume": 60},
|
||||
{"data": T.s8(T.synth("tri", 32, 32, 0.8)), "volume": 52, "loop": (0, 32)},
|
||||
]
|
||||
if extras:
|
||||
s[0]["hold"], s[0]["decay"] = 6, 4 # hold / decay: a volume envelope
|
||||
s[1]["finetune"] = 3
|
||||
s[4]["hold"], s[4]["decay"] = 2, 0
|
||||
return s
|
||||
|
||||
|
||||
def song_basic(keep=None, version=0):
|
||||
a, b = empty(4), empty(4, 32)
|
||||
mel = [13, 17, 20, 25, 20, 17, 15, 13]
|
||||
for i in range(16):
|
||||
put(a, i * 4, 0, mel[i % 8], 1)
|
||||
put(a, 2, 0, 0, 0, 0x0, 0x37) # arpeggio
|
||||
put(a, 0, 1, 1, 2)
|
||||
put(a, 4, 1, 0, 0, 0x1, 0x02)
|
||||
put(a, 12, 1, 0, 0, 0x2, 0x03)
|
||||
put(a, 20, 1, 13, 2, 0xC, 0x32) # volume (decimal: 32)
|
||||
put(a, 24, 1, 0, 0, 0xD, 0x03) # volume slide down (every tick)
|
||||
put(a, 28, 1, 0, 0, 0xD, 0x20)
|
||||
put(a, 32, 1, 8, 2, 0x4, 0x34) # vibrato (twice as deep)
|
||||
put(a, 40, 1, 13, 2)
|
||||
put(a, 41, 1, 20, 0, 0x3, 0x10) # tone portamento
|
||||
put(a, 48, 1, 0, 0, 0x5, 0x01)
|
||||
for r in range(0, 64, 8):
|
||||
put(a, r, 3, 13, 4, 0xC, 0x64 - r)
|
||||
put(a, 2, 2, 25, 3)
|
||||
put(a, 36, 2, 1, 5, 0xF, 0xF2) # delay note
|
||||
put(a, 44, 2, 1, 5, 0xF, 0xF1) # play twice
|
||||
put(a, 34, 3, 0, 0, 0x9, 0x04) # secondary speed
|
||||
put(a, 50, 3, 0, 0, 0xF, 0x90) # tempo 0x90 (BPM 144 / 0.264...)
|
||||
put(b, 0, 0, 13, 1)
|
||||
put(b, 8, 1, 20, 2)
|
||||
put(b, 16, 2, 13, 3, 0x8, 0x40) # panning (8xx)
|
||||
put(b, 24, 3, 25, 5, 0xF, 0x00) # pattern break
|
||||
if keep is not None:
|
||||
for p in (a, b):
|
||||
for row in p:
|
||||
for ch in range(4):
|
||||
if ch not in keep and row[ch][2] not in (0x9, 0xF):
|
||||
row[ch] = (0, 0, 0, 0)
|
||||
return T.write_med(version, samples(version > 0), [a, b], [0, 1, 0], tempo=0x21 if version == 0 else 125, tempo2=6,
|
||||
flags=0x10 if version > 0 else 0, flags2=0x23 if version > 0 else 0, title="med test" if version > 0 else None)
|
||||
|
||||
|
||||
def song_mmd2():
|
||||
"""MMD2: 6 tracks, a play sequence with a section, ProTracker-style slides, BPM tempo, track volumes"""
|
||||
a = empty(6, 48)
|
||||
for r in range(0, 48, 4):
|
||||
put(a, r, r // 4 % 6, 13 + (r // 4) % 12, 1 + r // 4 % 5)
|
||||
put(a, 6, 1, 0, 0, 0x1, 0x04)
|
||||
put(a, 10, 2, 0, 0, 0xD, 0x02)
|
||||
put(a, 20, 4, 0, 0, 0x16, 0x00) # loop start
|
||||
put(a, 23, 4, 0, 0, 0x16, 0x01) # loop once
|
||||
put(a, 30, 5, 0, 0, 0x1F, 0x20) # note delay 2
|
||||
put(a, 44, 0, 0, 0, 0x1D, 0x08) # break to row 8 (hex)
|
||||
b = empty(6, 16)
|
||||
put(b, 0, 0, 25, 2, 0x0C, 0x20)
|
||||
put(b, 8, 3, 30, 4)
|
||||
return T.write_med(2, samples(), [a, b], [0, 1], tempo=120, tempo2=5, flags=0x20 | 0x10, flags2=0x20 | 3,
|
||||
trackvols=[64, 48, 64, 32, 64, 64])
|
||||
|
||||
|
||||
def song_octaves():
|
||||
"""MMD1 with an IFF 3-octave sample (three copies of a waveform, each twice as long as the last): a keymap"""
|
||||
w = T.s8(T.synth("saw", 32, 32, 0.7)) + T.s8(T.synth("saw", 64, 64, 0.7)) + T.s8(T.synth("saw", 128, 128, 0.7))
|
||||
smp = [{"data": w, "volume": 64, "octaves": 3, "loop": (0, 32)}, samples()[0]]
|
||||
a = empty(2, 48)
|
||||
for i, n in enumerate([1, 8, 13, 20, 25, 32, 37, 30, 18, 6, 13, 25]):
|
||||
put(a, i * 4, 0, n, 1)
|
||||
put(a, i * 4 + 2, 1, n, 2, 0xC, 0x20)
|
||||
return T.write_med(1, smp, [a], [0], tempo=125, tempo2=6, flags=0x10, flags2=0x23)
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
cases = []
|
||||
for nm, data in (("mmd0", song_basic()), ("mmd1", song_basic(version=1)), ("mmd2", song_mmd2()), ("octaves", song_octaves())):
|
||||
ref = T.reference(ctx, data, "med")
|
||||
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
|
||||
ctx.emit("med_cases", cases)
|
||||
@@ -0,0 +1,105 @@
|
||||
# MTM fixtures (tools/fixtures.py): generated MultiTracker modules exercising the effects, rendered by openmpt123.
|
||||
# tests/gen/mtm_cases.luau { name, data (the module), ref (features of openmpt's render, tools/fixtures/_tracker.py),
|
||||
# duration (openmpt's song length) }
|
||||
import 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:
|
||||
import importlib.util
|
||||
_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"]
|
||||
|
||||
|
||||
def empty(ch, rows=64):
|
||||
return [[(0, 0, 0, 0) for _ in range(ch)] for _ in range(rows)]
|
||||
|
||||
|
||||
def put(p, row, ch, note=0, ins=0, fx=0, param=0):
|
||||
p[row][ch] = (note, ins, fx, param)
|
||||
|
||||
|
||||
def samples():
|
||||
return [
|
||||
{"name": "sine", "data": T.u8(T.synth("sine", 64, 64)), "volume": 64, "loop": (0, 64)},
|
||||
{"name": "square", "data": T.u8(T.synth("square", 64, 64, 0.5)), "volume": 44, "loop": (0, 64)},
|
||||
{"name": "saw16", "data": T.u16(T.synth("saw", 128, 64, 0.6)), "bits": 16, "volume": 64, "loop": (0, 256)},
|
||||
{"name": "noise", "data": T.u8(T.synth("noise", 5000, 1, 0.7, decay=1500)), "volume": 60},
|
||||
{"name": "tri ft", "data": T.u8(T.synth("tri", 32, 32, 0.8)), "volume": 52, "finetune": 3, "loop": (0, 32)},
|
||||
]
|
||||
|
||||
|
||||
def song_effects(keep=None):
|
||||
a, b = empty(6), empty(6)
|
||||
mel = [49, 53, 56, 61, 56, 53, 51, 49]
|
||||
for i in range(16):
|
||||
put(a, i * 4, 0, mel[i % 8], 1)
|
||||
put(a, i * 4, 1, 37 + (i % 4) * 2, 2, 0x0, 0x37 if i % 2 else 0)
|
||||
put(a, 0, 2, 49, 3, 0x1, 0x02)
|
||||
put(a, 16, 2, 0, 0, 0x2, 0x03)
|
||||
put(a, 32, 2, 61, 3, 0xC, 0x30)
|
||||
put(a, 33, 2, 0, 0, 0xA, 0x02)
|
||||
put(a, 48, 2, 0, 0, 0xA, 0x40)
|
||||
for r in range(0, 64, 8):
|
||||
put(a, r, 3, 61, 4, 0xC, 0x40 - r // 2)
|
||||
put(a, 60, 3, 61, 4, 0xE, 0xC2)
|
||||
put(a, 2, 4, 56, 5, 0xE, 0x84)
|
||||
put(a, 20, 4, 0, 0, 0xE, 0x8C)
|
||||
put(a, 8, 5, 44, 2, 0xE, 0x82)
|
||||
put(a, 40, 5, 0, 0, 0x0, 0x00)
|
||||
# pattern b: portamento, vibrato, tremolo, offsets, fine slides, break
|
||||
put(b, 0, 0, 49, 1)
|
||||
put(b, 4, 0, 61, 0, 0x3, 0x08)
|
||||
put(b, 8, 0, 0, 0, 0x3, 0x00)
|
||||
put(b, 12, 0, 49, 0, 0x5, 0x02)
|
||||
put(b, 16, 0, 56, 5, 0x4, 0x46)
|
||||
put(b, 20, 0, 0, 0, 0x6, 0x01)
|
||||
put(b, 24, 0, 0, 0, 0x4, 0x8F)
|
||||
put(b, 0, 1, 37, 2, 0x7, 0x48)
|
||||
put(b, 8, 1, 0, 0, 0x7, 0x00)
|
||||
put(b, 16, 1, 44, 2, 0xE, 0x12)
|
||||
put(b, 17, 1, 0, 0, 0xE, 0x12)
|
||||
put(b, 20, 1, 0, 0, 0xE, 0x24)
|
||||
put(b, 24, 1, 0, 0, 0xE, 0xB8)
|
||||
put(b, 28, 1, 0, 0, 0xE, 0xA4)
|
||||
put(b, 0, 3, 49, 4, 0x9, 0x08)
|
||||
put(b, 24, 2, 49, 3, 0xF, 0x03)
|
||||
put(b, 24, 4, 0, 0, 0xF, 0x8C)
|
||||
put(b, 40, 2, 53, 3, 0xF, 0x06)
|
||||
put(b, 40, 4, 0, 0, 0xF, 0x7D)
|
||||
put(b, 44, 0, 49, 5)
|
||||
put(b, 48, 0, 0, 0, 0xD, 0x00)
|
||||
if keep is not None: # debugging: only some channels
|
||||
for p in (a, b):
|
||||
for row in p:
|
||||
for ch in range(6):
|
||||
if ch not in keep and row[ch][2] not in (0xB, 0xD, 0xF):
|
||||
row[ch] = (0, 0, 0, 0)
|
||||
return T.write_mtm("effects", samples(), [0, 1], [a, b], 6, pans=[3, 12, 7, 0, 15, 9], comment=b"test song".ljust(40, b"\0"))
|
||||
|
||||
|
||||
def song_quirk():
|
||||
"""speed and tempo commands never on one row: MultiTracker's reset (speed -> tempo 125, tempo -> speed 6)"""
|
||||
a, b = empty(4), empty(4)
|
||||
for r in range(0, 64, 4):
|
||||
put(a, r, 0, 49 + (r // 4) % 12, 1)
|
||||
put(b, r, 1, 61 - (r // 4) % 12, 2)
|
||||
put(a, 0, 3, 0, 0, 0xF, 0x03)
|
||||
put(a, 32, 3, 0, 0, 0xF, 0xA0)
|
||||
put(b, 16, 3, 0, 0, 0xF, 0x04)
|
||||
put(b, 40, 3, 0, 0, 0xF, 0x50)
|
||||
put(b, 0, 2, 37, 4, 0xB, 0x02)
|
||||
return T.write_mtm("quirk", samples(), [0, 1, 0], [a, b], 4)
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
cases = []
|
||||
for nm, data in (("effects", song_effects()), ("quirk", song_quirk())):
|
||||
ref = T.reference(ctx, data, "mtm")
|
||||
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
|
||||
ctx.emit("mtm_cases", cases)
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
# OKT fixtures (tools/fixtures.py): generated Oktalyzer modules exercising the effects and the mixed channel pairs,
|
||||
# rendered by openmpt123.
|
||||
# tests/gen/okt_cases.luau { name, data (the module), ref (features of openmpt's render, tools/fixtures/_tracker.py),
|
||||
# duration (openmpt's song length) }
|
||||
import 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:
|
||||
import importlib.util
|
||||
_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"]
|
||||
|
||||
|
||||
def empty(ch, rows=64):
|
||||
return [[(0, 0, 0, 0) for _ in range(ch)] for _ in range(rows)]
|
||||
|
||||
|
||||
def put(p, row, ch, note=0, ins=0, fx=0, param=0):
|
||||
p[row][ch] = (note, ins, fx, param)
|
||||
|
||||
|
||||
def samples():
|
||||
return [
|
||||
{"name": "sine", "data": T.s8(T.synth("sine", 64, 64)), "volume": 64, "type": 2, "loop": (0, 64)},
|
||||
{"name": "square", "data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 44, "type": 1, "loop": (0, 64)},
|
||||
{"name": "saw", "data": T.s8(T.synth("saw", 128, 64, 0.6)), "volume": 64, "type": 0, "loop": (64, 64)},
|
||||
{"name": "noise", "data": T.s8(T.synth("noise", 4000, 1, 0.7, decay=1200)), "volume": 60, "type": 2},
|
||||
{"name": "tri", "data": T.s8(T.synth("tri", 32, 32, 0.8)), "volume": 52, "type": 2, "loop": (0, 32)},
|
||||
]
|
||||
|
||||
|
||||
def song_raw(keep=None):
|
||||
"""four raw Paula channels: slides, arpeggios, note slides, volume, release"""
|
||||
a, b = empty(4), empty(4, 48)
|
||||
mel = [13, 17, 20, 25, 20, 17, 15, 13]
|
||||
for i in range(16):
|
||||
put(a, i * 4, 0, mel[i % 8], 1)
|
||||
put(a, 2, 0, 0, 0, 10, 0x37) # arpeggio 1
|
||||
put(a, 10, 0, 0, 0, 11, 0x37) # arpeggio 2
|
||||
put(a, 18, 0, 0, 0, 12, 0x37) # arpeggio 3
|
||||
put(a, 0, 1, 1, 2)
|
||||
put(a, 4, 1, 0, 0, 1, 0x02) # period down (pitch up)
|
||||
put(a, 12, 1, 0, 0, 2, 0x03)
|
||||
put(a, 20, 1, 13, 2, 31, 0x20) # volume 0x20
|
||||
put(a, 24, 1, 0, 0, 31, 0x43) # slide down
|
||||
put(a, 28, 1, 0, 0, 31, 0x52) # slide up
|
||||
put(a, 32, 1, 0, 0, 31, 0x64) # fine down
|
||||
put(a, 36, 1, 0, 0, 31, 0x76) # fine up
|
||||
put(a, 40, 1, 8, 2, 30, 0x01) # note slide up every tick
|
||||
put(a, 44, 1, 0, 0, 13, 0x02)
|
||||
put(a, 48, 1, 0, 0, 17, 0x03) # once
|
||||
put(a, 52, 1, 0, 0, 21, 0x05)
|
||||
for r in range(0, 64, 8):
|
||||
put(a, r, 3, 13, 4)
|
||||
put(a, 2, 2, 25, 5)
|
||||
put(a, 30, 2, 0, 0, 27, 0) # release: the sustain loop ends
|
||||
put(a, 36, 2, 1, 5)
|
||||
put(a, 34, 3, 0, 0, 28, 0x04) # speed
|
||||
put(b, 0, 0, 13, 1)
|
||||
put(b, 8, 1, 20, 2)
|
||||
put(b, 16, 2, 13, 3) # a paired-only sample on a raw channel: stops it
|
||||
put(b, 24, 3, 25, 5, 25, 0x00) # jump to 0 (song end)
|
||||
if keep is not None:
|
||||
for p in (a, b):
|
||||
for row in p:
|
||||
for ch in range(4):
|
||||
if ch not in keep and row[ch][2] not in (25, 28):
|
||||
row[ch] = (0, 0, 0, 0)
|
||||
return T.write_okt(samples(), [0, 1], [a, b], speed=6)
|
||||
|
||||
|
||||
def song_pairs(keep=None):
|
||||
"""two mixed pairs (channels 2 / 3 and 5 / 6) and two raw channels"""
|
||||
a = empty(6)
|
||||
for r in range(0, 64, 4):
|
||||
put(a, r, 0, 13 + (r // 4) % 12, 1)
|
||||
put(a, r, 1, 1 + (r // 4) % 7, 3)
|
||||
put(a, r + 2, 2, 20, 1)
|
||||
put(a, 16, 1, 0, 0, 31, 0x30) # pair volume (shared)
|
||||
put(a, 32, 2, 0, 0, 31, 0x10) # the second channel's volume wins
|
||||
put(a, 40, 1, 0, 0, 31, 0x52) # pair volume slide
|
||||
put(a, 0, 3, 13, 2)
|
||||
put(a, 8, 4, 25, 4)
|
||||
put(a, 10, 5, 13, 5)
|
||||
put(a, 20, 5, 30, 1) # too high on a pair: clamped
|
||||
put(a, 48, 4, 13, 1, 31, 0x18)
|
||||
if keep is not None:
|
||||
for row in a:
|
||||
for ch in range(6):
|
||||
if ch not in keep:
|
||||
row[ch] = (0, 0, 0, 0)
|
||||
return T.write_okt(samples(), [0], [a], cmod=(1, 0, 1, 0), speed=5)
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
cases = []
|
||||
for nm, data in (("raw", song_raw()), ("pairs", song_pairs())):
|
||||
ref = T.reference(ctx, data, "okt")
|
||||
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
|
||||
ctx.emit("okt_cases", cases)
|
||||
@@ -0,0 +1,89 @@
|
||||
# PTM fixtures (tools/fixtures.py): generated PolyTracker modules exercising the effects, rendered by openmpt123.
|
||||
# tests/gen/ptm_cases.luau { name, data (the module), ref (features of openmpt's render, tools/fixtures/_tracker.py),
|
||||
# duration (openmpt's song length) }
|
||||
import 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:
|
||||
import importlib.util
|
||||
_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"]
|
||||
|
||||
|
||||
def empty(ch):
|
||||
return [[(0, 0, None, None, 0) for _ in range(ch)] for _ in range(64)]
|
||||
|
||||
|
||||
def put(p, row, ch, note=0, ins=0, vol=None, cmd=None, param=0):
|
||||
p[row][ch] = (note, ins, vol, cmd, param)
|
||||
|
||||
|
||||
def samples():
|
||||
return [
|
||||
{"name": "sine", "data": T.s8(T.synth("sine", 64, 64)), "volume": 64, "c4spd": 8363, "loop": (0, 64)},
|
||||
{"name": "square", "data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 40, "c4spd": 16726, "loop": (0, 64)},
|
||||
{"name": "saw16", "data": T.s16(T.synth("saw", 200, 100, 0.6)), "bits": 16, "volume": 64, "c4spd": 13000, "loop": (0, 200), "pingpong": True},
|
||||
{"name": "noise", "data": T.s8(T.synth("noise", 6000, 1, 0.7, decay=1500)), "volume": 60, "c4spd": 8363},
|
||||
{"name": "tri", "data": T.s8(T.synth("tri", 50, 50, 0.8)), "volume": 50, "c4spd": 10000, "loop": (0, 50)},
|
||||
]
|
||||
|
||||
|
||||
def song_effects(keep=None):
|
||||
a, b = empty(6), empty(6)
|
||||
mel = [61, 65, 68, 73, 68, 65, 63, 61]
|
||||
for i in range(16):
|
||||
put(a, i * 4, 0, mel[i % 8], 1, None, 0x0 if i % 4 == 1 else None, 0x37)
|
||||
put(a, 0, 1, 49, 2, 48)
|
||||
put(a, 4, 1, 0, 0, None, 0xA, 0x04)
|
||||
put(a, 8, 1, 0, 0, None, 0xA, 0x20)
|
||||
put(a, 12, 1, 0, 0, None, 0xA, 0xF2) # S3M-style fine slide
|
||||
put(a, 16, 1, 51, 2, None, 0x2, 0x03)
|
||||
put(a, 20, 1, 0, 0, None, 0x1, 0x06)
|
||||
put(a, 24, 1, 0, 0, None, 0x1, 0xF4) # fine porta
|
||||
put(a, 28, 1, 56, 2, None, 0x4, 0x46)
|
||||
put(a, 36, 1, 0, 0, None, 0x6, 0x02)
|
||||
put(a, 40, 1, 49, 2)
|
||||
put(a, 41, 1, 61, 0, None, 0x3, 0x10)
|
||||
put(a, 44, 1, 0, 0, None, 0x5, 0x01)
|
||||
put(a, 48, 1, 54, 2, None, 0x7, 0x58)
|
||||
put(a, 56, 1, 0, 0, None, 0xC, 0x20)
|
||||
for r in range(0, 64, 8):
|
||||
put(a, r, 3, 61, 4, 64 - r // 2)
|
||||
put(a, 20, 3, 61, 4, None, 0x9, 0x08)
|
||||
put(a, 32, 3, 61, 4, None, 0xE, 0xC3)
|
||||
put(a, 40, 3, 61, 4, None, 0xE, 0xD2)
|
||||
put(a, 48, 3, 61, 4, None, 0x11, 0x03) # retrigger
|
||||
put(a, 4, 2, 37, 3, 50)
|
||||
put(a, 2, 4, 73, 5, None, 0x8, 0x30) # panning
|
||||
put(a, 18, 4, 0, 0, None, 0x8, 0xD0)
|
||||
put(a, 10, 5, 56, 1, None, 0x12, 0x46) # fine vibrato
|
||||
put(a, 24, 5, 0, 0, None, 0x13, 0x22) # note slide up: every 2 ticks by 2
|
||||
put(a, 30, 5, 0, 0, None, 0x14, 0x31) # note slide down
|
||||
put(a, 36, 5, 60, 1, None, 0x15, 0x21) # with retrigger
|
||||
put(b, 0, 0, 49, 1, None, 0xF, 0x04)
|
||||
put(b, 4, 0, 0, 0, None, 0xF, 0x90)
|
||||
put(b, 8, 0, 61, 1, None, 0x10, 0x20) # global volume
|
||||
put(b, 24, 0, 0, 0, None, 0x10, 0x40)
|
||||
put(b, 0, 2, 37, 3)
|
||||
put(b, 16, 2, 0, 0, None, 0xE, 0x92)
|
||||
put(b, 32, 4, 68, 5, None, 0xD, 0x00)
|
||||
if keep is not None:
|
||||
for p in (a, b):
|
||||
for row in p:
|
||||
for ch in range(6):
|
||||
if ch not in keep and row[ch][3] not in (0xD, 0xF, 0x10):
|
||||
row[ch] = (0, 0, None, None, 0)
|
||||
return T.write_ptm("effects", samples(), [0, 1], [a, b], 6, pans=[3, 12, 7, 0, 15, 9])
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
cases = []
|
||||
for nm, data in (("effects", song_effects()),):
|
||||
ref = T.reference(ctx, data, "ptm")
|
||||
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
|
||||
ctx.emit("ptm_cases", cases)
|
||||
@@ -0,0 +1,90 @@
|
||||
# STM fixtures (tools/fixtures.py): generated Scream Tracker 2 modules exercising the effects, rendered by openmpt123.
|
||||
# tests/gen/stm_cases.luau { name, data (the module), ref (features of openmpt's render, tools/fixtures/_tracker.py),
|
||||
# duration (openmpt's song length) }
|
||||
import 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:
|
||||
import importlib.util
|
||||
_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"]
|
||||
|
||||
A, B, C, D, E, F, G, H, I, J = range(1, 11)
|
||||
|
||||
|
||||
def empty():
|
||||
return [[(0, 0, None, 0, 0) for _ in range(4)] for _ in range(64)]
|
||||
|
||||
|
||||
def put(p, row, ch, note=0, ins=0, vol=None, cmd=0, info=0):
|
||||
p[row][ch] = (note, ins, vol, cmd, info)
|
||||
|
||||
|
||||
def samples():
|
||||
return [
|
||||
{"name": "sine", "data": T.s8(T.synth("sine", 64, 64)), "volume": 64, "c2spd": 8363, "loop": (0, 64)},
|
||||
{"name": "square", "data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 40, "c2spd": 16726, "loop": (0, 64)},
|
||||
{"name": "saw", "data": T.s8(T.synth("saw", 100, 100, 0.6)), "volume": 64, "c2spd": 13000, "loop": (0, 100)},
|
||||
{"name": "noise", "data": T.s8(T.synth("noise", 6000, 1, 0.7, decay=1500)), "volume": 60, "c2spd": 8363},
|
||||
{"name": "tri", "data": T.s8(T.synth("tri", 50, 50, 0.8)), "volume": 50, "c2spd": 10000, "loop": (0, 50)},
|
||||
]
|
||||
|
||||
|
||||
def song_effects():
|
||||
a, b, c = empty(), empty(), empty()
|
||||
mel = [61, 65, 68, 73, 68, 65, 63, 61]
|
||||
for i in range(16):
|
||||
put(a, i * 4, 0, mel[i % 8], 1, None, J if i % 4 == 1 else 0, 0x47 if i % 4 == 1 else 0)
|
||||
put(a, 0, 1, 49, 2, 48)
|
||||
put(a, 4, 1, 0, 0, None, D, 0x04)
|
||||
put(a, 8, 1, 0, 0, None, D, 0x20)
|
||||
put(a, 16, 1, 51, 2, None, E, 0x03)
|
||||
put(a, 20, 1, 0, 0, None, F, 0x06)
|
||||
put(a, 28, 1, 56, 2, None, H, 0x46)
|
||||
put(a, 40, 1, 49, 2, None, G, 0x00)
|
||||
put(a, 41, 1, 61, 0, None, G, 0x10)
|
||||
put(a, 52, 1, 0, 0, None, I, 0x21)
|
||||
for r in range(0, 64, 8):
|
||||
put(a, r, 3, 61, 4, 64 - r // 2)
|
||||
put(a, 24, 3, 254)
|
||||
put(a, 48, 2, 37, 3)
|
||||
put(a, 32, 2, 0, 0, None, A, 0x40) # ST2 tempo byte: speed 4, a fine tick length
|
||||
put(b, 0, 2, 49, 3, None, A, 0x63)
|
||||
put(b, 8, 2, 52, 5)
|
||||
put(b, 10, 0, 64, 1)
|
||||
put(b, 20, 0, 61, 1, 30)
|
||||
put(b, 24, 0, 254)
|
||||
put(b, 16, 1, 0, 0, None, B, 0x02) # deferred: taken at the C below (unreachable orders would be openmpt subsongs)
|
||||
put(b, 40, 3, 0, 0, None, C, 0x08)
|
||||
put(c, 8, 0, 49, 1, 32)
|
||||
put(c, 12, 1, 61, 2)
|
||||
put(c, 20, 0, 0, 0, None, B, 0x00) # deferred to the end of the pattern
|
||||
put(c, 30, 2, 0, 0, None, A, 0x8F)
|
||||
return T.write_stm("effects", samples(), [0, 1, 2], [a, b, c], tempo=0x60)
|
||||
|
||||
|
||||
def song_old():
|
||||
"""an ST 2.00 file: decimal tempo bytes, a short order list, no global volume"""
|
||||
a = empty()
|
||||
put(a, 0, 0, 61, 1)
|
||||
put(a, 8, 1, 68, 2)
|
||||
put(a, 16, 0, 0, 0, None, H, 0x28)
|
||||
put(a, 32, 1, 0, 0, None, A, 50) # decimal 50 = 0x50
|
||||
put(a, 40, 2, 49, 5, 40)
|
||||
put(a, 44, 3, 56, 3)
|
||||
put(a, 52, 3, "fb")
|
||||
put(a, 2, 0, "skip")
|
||||
return T.write_stm("old", samples(), [0], [a], tempo=72, gvol=20, minor=0)
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
cases = []
|
||||
for nm, data in (("effects", song_effects()), ("old", song_old())):
|
||||
ref = T.reference(ctx, data, "stm")
|
||||
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
|
||||
ctx.emit("stm_cases", cases)
|
||||
@@ -0,0 +1,95 @@
|
||||
# ULT fixtures (tools/fixtures.py): generated UltraTracker modules exercising the effects (two per cell), rendered by
|
||||
# openmpt123.
|
||||
# tests/gen/ult_cases.luau { name, data (the module), ref (features of openmpt's render, tools/fixtures/_tracker.py),
|
||||
# duration (openmpt's song length) }
|
||||
import 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:
|
||||
import importlib.util
|
||||
_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"]
|
||||
|
||||
|
||||
def empty(ch):
|
||||
return [[(0, 0, 0, 0, 0, 0) for _ in range(ch)] for _ in range(64)]
|
||||
|
||||
|
||||
def put(p, row, ch, note=0, ins=0, e1=0, p1=0, e2=0, p2=0):
|
||||
p[row][ch] = (note, ins, e1, p1, e2, p2)
|
||||
|
||||
|
||||
def samples():
|
||||
return [
|
||||
{"name": "sine", "data": T.s8(T.synth("sine", 64, 64)), "volume": 255, "loop": (0, 64)},
|
||||
{"name": "square", "data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 180, "speed": 16726, "loop": (0, 64)},
|
||||
{"name": "saw16", "data": T.s16(T.synth("saw", 200, 100, 0.6)), "bits": 16, "volume": 240, "loop": (0, 200), "pingpong": True},
|
||||
{"name": "noise", "data": T.s8(T.synth("noise", 6000, 1, 0.7, decay=1500)), "volume": 230},
|
||||
{"name": "tri", "data": T.s8(T.synth("tri", 50, 50, 0.8)), "volume": 200, "speed": 10000, "finetune": 3000, "loop": (0, 50)},
|
||||
]
|
||||
|
||||
|
||||
def song_effects(keep=None):
|
||||
a, b = empty(6), empty(6)
|
||||
mel = [61, 65, 68, 73, 68, 65, 63, 61]
|
||||
for i in range(16):
|
||||
put(a, i * 4, 0, mel[i % 8], 1, 0xC, 0x80 + i * 8) # note + set volume (volume column)
|
||||
put(a, 0, 1, 49, 2)
|
||||
put(a, 4, 1, 0, 0, 0xA, 0x04) # volume slide down
|
||||
put(a, 8, 1, 0, 0, 0xA, 0x20, 0x4, 0x46) # slide + vibrato: two columns
|
||||
put(a, 16, 1, 51, 2, 0x2, 0x03)
|
||||
put(a, 20, 1, 0, 0, 0x1, 0x06, 0xB, 0x0C) # porta up + panning
|
||||
put(a, 24, 1, 0, 0, 0xE, 0x14) # fine porta up
|
||||
put(a, 28, 1, 56, 2, 0x4, 0x46)
|
||||
put(a, 40, 1, 49, 2)
|
||||
put(a, 41, 1, 61, 0, 0x3, 0x10) # tone portamento (keeps going)
|
||||
put(a, 48, 1, 54, 2, 0x7, 0x58) # tremolo (v4)
|
||||
put(a, 56, 1, 0, 0, 0xE, 0xA4)
|
||||
put(a, 58, 1, 0, 0, 0xE, 0xB8)
|
||||
for r in range(0, 64, 8):
|
||||
put(a, r, 3, 61, 4, 0xC, 255 - r * 3)
|
||||
put(a, 20, 3, 61, 4, 0x9, 0x20) # offset (x 4)
|
||||
put(a, 32, 3, 61, 4, 0xE, 0xC3) # note cut
|
||||
put(a, 40, 3, 61, 4, 0xE, 0xD2) # note delay
|
||||
put(a, 4, 2, 37, 3)
|
||||
put(a, 30, 2, 0, 0, 0x5, 0x0C) # key off: the sustain loop ends
|
||||
put(a, 36, 2, 44, 3, 0x0, 0x47) # arpeggio
|
||||
put(a, 2, 4, 73, 5, 0xB, 0x03)
|
||||
put(a, 44, 4, 0, 0, 0xE, 0x93) # retrigger
|
||||
put(a, 10, 5, 56, 1, 0xF, 0x04) # speed
|
||||
put(a, 34, 5, 0, 0, 0xF, 0x90) # tempo
|
||||
put(b, 0, 0, 49, 1, 0xC, 0xFF, 0xF, 0x05) # volume + speed in one cell
|
||||
put(b, 8, 0, 61, 1, 0x1, 0x04, 0xA, 0x03) # porta up -> volume column
|
||||
put(b, 16, 0, 56, 1, 0x3, 0x08, 0x4, 0x05) # tone porta + vibrato depth
|
||||
put(b, 24, 2, 49, 3, 0xE, 0x84) # fine pattern delay
|
||||
put(b, 0, 5, 37, 2, 0xA, 0xF0, 0x3, 0x00)
|
||||
put(b, 32, 4, 68, 5, 0xD, 0x00, 0xC, 0x60) # break + volume
|
||||
if keep is not None: # debugging: only some channels (their speed / tempo / break effects stay)
|
||||
for p in (a, b):
|
||||
for row in p:
|
||||
for ch in range(6):
|
||||
if ch not in keep and row[ch][2] not in (0xD, 0xF) and row[ch][4] not in (0xD, 0xF):
|
||||
row[ch] = (0, 0, 0, 0, 0, 0)
|
||||
return T.write_ult("effects", samples(), [0, 1], [a, b], 6, pans=[3, 12, 7, 0, 15, 9])
|
||||
|
||||
|
||||
def song_old():
|
||||
"""a v1.3 file: no tremolo, no sample speed; arpeggio"""
|
||||
a = empty(4)
|
||||
for r in range(0, 64, 4):
|
||||
put(a, r, r // 4 % 4, 49 + (r // 4) % 12, 1 + r // 4 % 3, 0x0, 0x37)
|
||||
put(a, 32, 0, 0, 0, 0xF, 0x03)
|
||||
return T.write_ult("old", samples(), [0, 0], [a], 4, version=3)
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
cases = []
|
||||
for nm, data in (("effects", song_effects()), ("old", song_old())):
|
||||
ref = T.reference(ctx, data, "ult")
|
||||
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
|
||||
ctx.emit("ult_cases", cases)
|
||||
@@ -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