ws-audio2: music/mtm (MultiTracker) on the tracker engine; engine: m.engine family, m.preamp, flags (periods amiga/hz, fastPortas, autoTonePorta, autoReset, st2Tempo, oktSlides), extension effects (note slides, auto portamento, frequency adjust), codecs/audio/Tracker/Load helpers (OpenMPT BSD)

Engine changes are backward compatible: m.engine defaults to m.format; the channel / sample / instrument
global volumes now apply in every family (defaults leave MOD / S3M / XM unchanged); mod/s3m/xm/it tests green.
This commit is contained in:
4DBug committed 2026-10-31 14:11:20 -05:00
1 parent de4f14a343
commit 384cdc407d
13 files changed
+1026 -52

No files matched your search

+52
View File
@@ -493,3 +493,55 @@ 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)
+105
View File
@@ -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)