ws-audio2: music/okt (Oktalyzer): it family with ProTracker periods (PAL), mixed channel pairs and their shared volume, three arpeggios, note slides, sustain loops released by R

This commit is contained in:
4DBug committed 2026-10-31 14:40:13 -05:00
1 parent 6b5e8ec6cf
commit 9a5f3796e2
6 files changed
+455

No files matched your search

+32
View File
@@ -749,3 +749,35 @@ def write_far(title, samples, orders, patterns, speed=4, pans=None, breaks=None,
1 if bps == 2 else 0, 8 if s.get("loop") else 0)
body += s["data"]
return bytes(body)
def write_okt(samples, orders, patterns, cmod=(0, 0, 0, 0), speed=6):
"""samples: [{name, data (signed bytes, even length), volume 0..64, type 0 paired / 1 raw / 2 both, loop: (start,
length) in bytes (even) | None}]; patterns: [[row: [(note, ins, effect, param)] * channels] * rows] with note 0 =
none else 1..36 (13 = C-5 of the module), ins 1-based; cmod: the four Amiga channels, 1 = a mixed pair"""
def chunk(cid, data):
return cid + struct.pack(">I", len(data)) + data
out = bytearray(b"OKTASONG")
out += chunk(b"CMOD", b"".join(struct.pack(">H", c) for c in cmod))
sh = bytearray()
for i in range(36):
if i < len(samples):
s = samples[i]
ls, ll = s.get("loop") or (0, 0)
sh += name(s.get("name", ""), 20) + struct.pack(">IHHHH", len(s["data"]), ls // 2, ll // 2, s.get("volume", 64), s.get("type", 2))
else:
sh += b"\0" * 32
out += chunk(b"SAMP", bytes(sh))
out += chunk(b"SPEE", struct.pack(">H", speed))
out += chunk(b"SLEN", struct.pack(">H", len(patterns)))
out += chunk(b"PLEN", struct.pack(">H", len(orders)))
out += chunk(b"PATT", bytes(orders) + b"\0" * (128 - len(orders)))
for pat in patterns:
pb = bytearray(struct.pack(">H", len(pat)))
for row in pat:
for (note, ins, fx, param) in row:
pb += bytes([note, max(0, ins - 1), fx, param])
out += chunk(b"PBOD", bytes(pb))
for s in samples:
out += chunk(b"SBOD", s["data"])
return bytes(out)
+105
View File
@@ -0,0 +1,105 @@
# OKT fixtures (tools/fixtures.py): generated Oktalyzer modules exercising the effects and the mixed channel pairs,
# rendered by openmpt123.
# tests/gen/okt_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.s8(T.synth("sine", 64, 64)), "volume": 64, "type": 2, "loop": (0, 64)},
{"name": "square", "data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 44, "type": 1, "loop": (0, 64)},
{"name": "saw", "data": T.s8(T.synth("saw", 128, 64, 0.6)), "volume": 64, "type": 0, "loop": (64, 64)},
{"name": "noise", "data": T.s8(T.synth("noise", 4000, 1, 0.7, decay=1200)), "volume": 60, "type": 2},
{"name": "tri", "data": T.s8(T.synth("tri", 32, 32, 0.8)), "volume": 52, "type": 2, "loop": (0, 32)},
]
def song_raw(keep=None):
"""four raw Paula channels: slides, arpeggios, note slides, volume, release"""
a, b = empty(4), empty(4, 48)
mel = [13, 17, 20, 25, 20, 17, 15, 13]
for i in range(16):
put(a, i * 4, 0, mel[i % 8], 1)
put(a, 2, 0, 0, 0, 10, 0x37) # arpeggio 1
put(a, 10, 0, 0, 0, 11, 0x37) # arpeggio 2
put(a, 18, 0, 0, 0, 12, 0x37) # arpeggio 3
put(a, 0, 1, 1, 2)
put(a, 4, 1, 0, 0, 1, 0x02) # period down (pitch up)
put(a, 12, 1, 0, 0, 2, 0x03)
put(a, 20, 1, 13, 2, 31, 0x20) # volume 0x20
put(a, 24, 1, 0, 0, 31, 0x43) # slide down
put(a, 28, 1, 0, 0, 31, 0x52) # slide up
put(a, 32, 1, 0, 0, 31, 0x64) # fine down
put(a, 36, 1, 0, 0, 31, 0x76) # fine up
put(a, 40, 1, 8, 2, 30, 0x01) # note slide up every tick
put(a, 44, 1, 0, 0, 13, 0x02)
put(a, 48, 1, 0, 0, 17, 0x03) # once
put(a, 52, 1, 0, 0, 21, 0x05)
for r in range(0, 64, 8):
put(a, r, 3, 13, 4)
put(a, 2, 2, 25, 5)
put(a, 30, 2, 0, 0, 27, 0) # release: the sustain loop ends
put(a, 36, 2, 1, 5)
put(a, 34, 3, 0, 0, 28, 0x04) # speed
put(b, 0, 0, 13, 1)
put(b, 8, 1, 20, 2)
put(b, 16, 2, 13, 3) # a paired-only sample on a raw channel: stops it
put(b, 24, 3, 25, 5, 25, 0x00) # jump to 0 (song end)
if keep is not None:
for p in (a, b):
for row in p:
for ch in range(4):
if ch not in keep and row[ch][2] not in (25, 28):
row[ch] = (0, 0, 0, 0)
return T.write_okt(samples(), [0, 1], [a, b], speed=6)
def song_pairs(keep=None):
"""two mixed pairs (channels 2 / 3 and 5 / 6) and two raw channels"""
a = empty(6)
for r in range(0, 64, 4):
put(a, r, 0, 13 + (r // 4) % 12, 1)
put(a, r, 1, 1 + (r // 4) % 7, 3)
put(a, r + 2, 2, 20, 1)
put(a, 16, 1, 0, 0, 31, 0x30) # pair volume (shared)
put(a, 32, 2, 0, 0, 31, 0x10) # the second channel's volume wins
put(a, 40, 1, 0, 0, 31, 0x52) # pair volume slide
put(a, 0, 3, 13, 2)
put(a, 8, 4, 25, 4)
put(a, 10, 5, 13, 5)
put(a, 20, 5, 30, 1) # too high on a pair: clamped
put(a, 48, 4, 13, 1, 31, 0x18)
if keep is not None:
for row in a:
for ch in range(6):
if ch not in keep:
row[ch] = (0, 0, 0, 0)
return T.write_okt(samples(), [0], [a], cmod=(1, 0, 1, 0), speed=5)
def generate(ctx):
cases = []
for nm, data in (("raw", song_raw()), ("pairs", song_pairs())):
ref = T.reference(ctx, data, "okt")
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
ctx.emit("okt_cases", cases)