ws-audio2: music/stm (Scream Tracker 2): s3m family with the ST2 tempo byte, deferred Bxx, no effect memory
This commit is contained in:
1 parent
33d87e0c4d
commit
80f5fd2c5b
6 files changed
+396
No files matched your search
@@ -575,3 +575,44 @@ def write_669(message, samples, orders, patterns, tempos, breaks, restart=0, ext
|
||||
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)
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user