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