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)