ws-audio2: music/far (Farandole Composer): s3m family with Hz periods (36318 / 1024 Hz per step), auto tone portamento, variable-length patterns with break rows

This commit is contained in:
4DBug committed 2026-10-31 14:36:44 -05:00
1 parent bac37fb157
commit 6b5e8ec6cf
6 files changed
+378

No files matched your search

+33
View File
@@ -716,3 +716,36 @@ def write_ptm(title, samples, orders, patterns, channels, pans=None):
h[76:80] = b"PTMS"
body[smp_at + 80 * i:smp_at + 80 * i + 80] = h
return bytes(body)
def write_far(title, samples, orders, patterns, speed=4, pans=None, breaks=None, message=b"", restart=0, mute=()):
"""samples: [{name, data (signed bytes; 16-bit little-endian), bits 8|16, volume 0..15, loop: (start, end) in
frames | None}] (at most 64, stored in order); patterns: [[row: [(note, ins, vol, effect)] * 16] * rows] with note 0
= none else our note (37..108), ins 1-based, vol 0 = none else 1..16, effect byte (cmd << 4 | param); breaks: the
break-row byte per pattern"""
head = bytearray(b"FAR\xfe" + name(title, 40) + b"\r\n\x1a")
hl_at = len(head)
head += b"\0\0" + bytes([0x10]) + bytes([0 if i in mute else 1 for i in range(16)]) + b"\0" * 9 + bytes([speed])
head += bytes(list(pans or [(i % 2) * 15 for i in range(16)]))
head += b"\0" * 4 + struct.pack("<H", len(message)) + message
head += bytes(orders) + b"\xff" * (256 - len(orders)) + bytes([len(patterns), len(orders), restart])
sizes = [2 + len(p) * 64 for p in patterns] + [0] * (256 - len(patterns))
head += b"".join(struct.pack("<H", s) for s in sizes)
struct.pack_into("<H", head, hl_at, len(head))
body = head
for k, pat in enumerate(patterns):
body += bytes([(breaks or [0] * len(patterns))[k], 0])
for row in pat:
for (note, ins, vol, eff) in row:
body += bytes([note - 36 if note else 0, max(0, ins - 1), vol, eff])
smap = bytearray(8)
for i in range(len(samples)):
smap[i >> 3] |= 1 << (i & 7)
body += smap
for s in samples:
bps = 2 if s.get("bits", 8) == 16 else 1
ls, le = s.get("loop") or (0, 0)
body += name(s.get("name", ""), 32) + struct.pack("<IBBIIBB", len(s["data"]), 0, s.get("volume", 15), ls * bps, le * bps,
1 if bps == 2 else 0, 8 if s.get("loop") else 0)
body += s["data"]
return bytes(body)
+81
View File
@@ -0,0 +1,81 @@
# FAR fixtures (tools/fixtures.py): generated Farandole Composer modules exercising the effects, rendered by openmpt123.
# tests/gen/far_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(rows=64):
return [[(0, 0, 0, 0) for _ in range(16)] for _ in range(rows)]
def put(p, row, ch, note=0, ins=0, vol=0, cmd=None, param=0):
p[row][ch] = (note, ins, vol, 0 if cmd is None else (cmd << 4) | param)
def samples():
return [
{"name": "sine", "data": T.s8(T.synth("sine", 64, 64)), "volume": 15, "loop": (0, 64)},
{"name": "square", "data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 11, "loop": (0, 64)},
{"name": "saw16", "data": T.s16(T.synth("saw", 200, 100, 0.6)), "bits": 16, "volume": 15, "loop": (0, 200)},
{"name": "noise", "data": T.s8(T.synth("noise", 6000, 1, 0.7, decay=1500)), "volume": 14},
{"name": "tri", "data": T.s8(T.synth("tri", 50, 50, 0.8)), "volume": 12, "loop": (0, 50)},
]
def song_effects(keep=None):
a, b = empty(), empty(48)
mel = [61, 65, 68, 73, 68, 65, 63, 61]
for i in range(16):
put(a, i * 4, 0, mel[i % 8], 1, 16 - i % 4)
put(a, 0, 1, 49, 2, 12)
put(a, 4, 1, 0, 0, 0, 0x1, 0x3) # fine porta up
put(a, 8, 1, 0, 0, 0, 0x2, 0x5)
put(a, 12, 1, 0, 0, 0, 0x8, 0x2) # volume slide down
put(a, 16, 1, 51, 2, 14, 0x7, 0x1) # up
put(a, 20, 1, 0, 0, 0, 0x5, 0x4) # vibrato depth
put(a, 21, 1, 0, 0, 0, 0x6, 0x2) # vibrato speed
put(a, 28, 1, 56, 2, 14)
put(a, 32, 1, 61, 2, 0, 0x3, 0x4) # tone portamento (keeps going)
put(a, 40, 1, 49, 2, 0, 0x3, 0x2)
put(a, 48, 1, 0, 0, 0, 0xA, 0x8) # volume portamento
for r in range(0, 64, 8):
put(a, r, 3, 61, 4, 16 - r // 8)
put(a, 36, 3, 61, 4, 16, 0x4, 0x2) # retrigger
put(a, 4, 2, 37, 3, 12)
put(a, 2, 4, 73, 5, 10, 0xB, 0x2) # panning
put(a, 30, 4, 0, 0, 0, 0xB, 0xD)
put(a, 10, 5, 56, 1, 12)
put(a, 24, 5, 0, 0, 0, 0xF, 0x3) # speed
put(b, 0, 0, 49, 1, 16)
put(b, 8, 0, 61, 1, 16, 0x2, 0x8)
put(b, 0, 2, 37, 3, 12)
put(b, 16, 2, 44, 3, 10, 0x9, 0x3)
put(b, 20, 6, 68, 5, 16)
put(b, 24, 9, 56, 2, 16) # a muted channel
if keep is not None:
for p in (a, b):
for row in p:
for ch in range(16):
if ch not in keep and (row[ch][3] >> 4) != 0xF:
row[ch] = (0, 0, 0, 0)
return T.write_far("effects", samples(), [0, 1], [a, b], speed=5, breaks=[0, 30], mute=(9,),
pans=[3, 12, 7, 0, 15, 9, 5, 10, 8, 8, 8, 8, 8, 8, 8, 8], message=b"far test")
def generate(ctx):
cases = []
for nm, data in (("effects", song_effects()),):
ref = T.reference(ctx, data, "far")
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
ctx.emit("far_cases", cases)