ws-audio2: music/ult (UltraTracker): it family, two effect columns folded into the IT volume column, sustain loops, auto tone portamento (also from the volume column)
This commit is contained in:
1 parent
80f5fd2c5b
commit
f3299bf70f
8 files changed
+489
-2
No files matched your search
@@ -616,3 +616,50 @@ def write_stm(title, samples, orders, patterns, tempo=0x60, gvol=64, minor=21):
|
||||
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)
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user