ws-music: music/it read + render (IT 2.14/2.15 decompression, NNA, filters, pitch-pan, OpenMPT note-fade coding), tracker tests tightened, MOD->XM + API checks, tracker bench lines, NOTICE
This commit is contained in:
1 parent
8b8b64885f
commit
7754646a86
14 files changed
+964
-28
No files matched your search
@@ -116,3 +116,59 @@ do
|
||||
end
|
||||
print(string.format("%-8s %-30s %8.2f ms %7.1f M voice-samples/s", runtime, "synth 32 voices x 2 s", best * 1000, 32 * frames / best / 1e6))
|
||||
end
|
||||
-- the tracker engine: 32 channels of looped samples (one note each, linear interpolation, volume ramps), and an
|
||||
-- IT-style module with background voices (NNA continue) and resonant filters on every channel
|
||||
do
|
||||
local Tracker = require("@formats/codecs/Tracker")
|
||||
local function song(format: string, filter: boolean): any
|
||||
local m = Tracker.newModule(format, 32)
|
||||
m.order = { 0 }
|
||||
m.patterns[1] = Tracker.newPattern(64, 32)
|
||||
local s = Tracker.newSample("saw")
|
||||
s.length = 1000
|
||||
s.data = buffer.create(4000)
|
||||
for i = 0, 999 do
|
||||
buffer.writef32(s.data, i * 4, (i % 100) / 50 - 1)
|
||||
end
|
||||
s.loopStart, s.loopEnd, s.loopType = 0, 1000, 1
|
||||
m.samples[1] = s
|
||||
if format == "it" then
|
||||
local ins = Tracker.newInstrument("nna")
|
||||
for n = 1, 120 do
|
||||
ins.sampleMap[n] = 1
|
||||
end
|
||||
ins.nna = 1
|
||||
ins.fadeout = 64
|
||||
if filter then
|
||||
ins.cutoff, ins.resonance = 60, 40
|
||||
end
|
||||
m.instruments[1] = ins
|
||||
end
|
||||
for ch = 1, 32 do
|
||||
for row = 0, 63, 16 do
|
||||
Tracker.setCell(m, 0, row, ch, 37 + ch + row // 16, 1, 0, 0, 0)
|
||||
end
|
||||
end
|
||||
return m
|
||||
end
|
||||
local function realtime(label: string, m: any, voices: number)
|
||||
local best, frames = math.huge, 0
|
||||
local out = buffer.create(4096 * 8)
|
||||
for _ = 1, 3 do
|
||||
local dec = Tracker.render(m) :: any
|
||||
frames = 0
|
||||
local t0 = os.clock()
|
||||
while true do
|
||||
local _, n = dec:read(4096, out)
|
||||
if n == 0 then
|
||||
break
|
||||
end
|
||||
frames += n
|
||||
end
|
||||
best = math.min(best, os.clock() - t0)
|
||||
end
|
||||
print(string.format("%-8s %-30s %8.2f ms %7.1f x realtime %5.1f M voice-samples/s", runtime, label, best * 1000, frames / 44100 / best, voices * frames / best / 1e6))
|
||||
end
|
||||
realtime("tracker 32 ch (mod)", song("mod", false), 32)
|
||||
realtime("tracker 32 ch + NNA, filters", song("it", true), 64)
|
||||
end
|
||||
@@ -305,7 +305,7 @@ def write_it(title, samples, instruments, orders, patterns, channels, speed=6, t
|
||||
instruments: None (sample mode) or [{name, nna, dct, dca, fadeout, gbv, pan | None, pps, ppc, ifc, ifr,
|
||||
keymap: [(note, sample)] * 120, volenv / panenv / pitchenv: {points [(tick, value)], loop, sustain, filter}}];
|
||||
patterns: [[row: [(note, ins, vol, cmd, param)] * channels]] with note 0 = none else IT note + 1 (1 = C-0) or
|
||||
255 / 254 / 253; vol None or the raw volume byte; cmd 0 = none (A = 1)."""
|
||||
255 off / 254 cut / 253 fade (stored as 246, like IT); vol None or the raw volume byte; cmd 0 = none (A = 1)."""
|
||||
ins_list = instruments or []
|
||||
ordn = list(orders) + [255]
|
||||
flags = 1 | (4 if instruments else 0) | (8 if linear else 0) | (16 if old else 0) | (32 if compat else 0)
|
||||
@@ -351,7 +351,7 @@ def write_it(title, samples, instruments, orders, patterns, channels, speed=6, t
|
||||
if mask:
|
||||
pk += bytes([(ch + 1) | 128, mask])
|
||||
if note:
|
||||
pk.append(note - 1 if note < 253 else note)
|
||||
pk.append(note - 1 if note < 253 else (246 if note == 253 else note))
|
||||
if ins:
|
||||
pk.append(ins)
|
||||
if vol is not None:
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
# IT fixtures (tools/fixtures.py): generated Impulse Tracker modules exercising instruments (new note actions,
|
||||
# duplicate checks, envelopes, filters, sustain loops, auto-vibrato, keymaps), sample mode with the IT effects, Amiga
|
||||
# slides with old effects, and IT 2.14 / 2.15 compressed, 16-bit and stereo samples, rendered by openmpt123.
|
||||
# tests/gen/it_cases.luau { name, data (the module), ref (features of openmpt's render, tools/fixtures/_tracker.py),
|
||||
# duration (openmpt's song length), plain (for "compressed": the same song uncompressed) }
|
||||
import os, sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
import _tracker as T # noqa: E402
|
||||
|
||||
INPUTS = ["tools/fixtures/_tracker.py"]
|
||||
|
||||
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, Tt, U, V, W, X, Y, Z = range(1, 27)
|
||||
OFF, CUT, FADE = 255, 254, 253
|
||||
|
||||
|
||||
def empty(ch, rows=64):
|
||||
return [[(0, 0, None, 0, 0) for _ in range(ch)] for _ in range(rows)]
|
||||
|
||||
|
||||
def put(p, row, ch, note=0, ins=0, vol=None, cmd=0, param=0):
|
||||
p[row][ch] = (note, ins, vol, cmd, param)
|
||||
|
||||
|
||||
def samples(compress=None):
|
||||
return [
|
||||
{"name": "sine", "data": T.s8(T.synth("sine", 64, 64)), "volume": 64, "c5": 8363, "loop": (0, 64, False), "compress": compress},
|
||||
{"name": "square", "data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 48, "c5": 16726, "loop": (0, 64, False), "gv": 48},
|
||||
{"name": "saw16", "data": T.s16(T.synth("saw", 128, 64, 0.6)), "bits": 16, "volume": 64, "c5": 11025, "loop": (0, 128, False),
|
||||
"compress": compress},
|
||||
{"name": "noise", "data": T.s8(T.synth("noise", 6000, 1, 0.7, decay=1500)), "volume": 60, "c5": 8363, "pan": 16},
|
||||
{"name": "ping sus", "data": T.s8(T.synth("tri", 400, 50, 0.8)), "volume": 64, "c5": 9000, "sus": (100, 300, True),
|
||||
"loop": (0, 400, False), "vib": (8, 16, 4, 0)},
|
||||
{"name": "stereo", "data": T.s16(T.synth("sine", 256, 32, 0.6) + T.synth("saw", 256, 64, 0.5)), "bits": 16, "stereo": True,
|
||||
"volume": 56, "c5": 8363, "loop": (0, 256, True), "compress": compress},
|
||||
{"name": "pluck", "data": T.s8(T.synth("saw", 3000, 40, 0.8, decay=900)), "volume": 64, "c5": 8363},
|
||||
]
|
||||
|
||||
|
||||
def keymap(sample, transpose=0, split=None):
|
||||
km = []
|
||||
for n in range(120):
|
||||
smp = sample if split is None or n < split[0] else split[1]
|
||||
km.append((max(0, min(119, n + transpose)), smp))
|
||||
return km
|
||||
|
||||
|
||||
def instruments():
|
||||
return [
|
||||
{"name": "nna cont", "nna": 1, "fadeout": 256, "keymap": keymap(7),
|
||||
"volenv": {"points": [(0, 64), (10, 48), (40, 0)]}},
|
||||
{"name": "nna off", "nna": 2, "fadeout": 128, "keymap": keymap(1),
|
||||
"volenv": {"points": [(0, 0), (3, 64), (8, 40), (20, 30)], "sustain": (2, 3)}},
|
||||
{"name": "nna fade dct", "nna": 3, "dct": 1, "dca": 0, "fadeout": 64, "keymap": keymap(2)},
|
||||
{"name": "pan pitch", "fadeout": 512, "keymap": keymap(3, 12), "pan": 48, "pps": 16, "ppc": 60,
|
||||
"panenv": {"points": [(0, -32), (16, 32), (32, -32)], "loop": (0, 2)},
|
||||
"pitchenv": {"points": [(0, 0), (10, 12), (20, -12), (30, 0)], "loop": (1, 2)}},
|
||||
{"name": "filter", "keymap": keymap(3), "ifc": 128 + 40, "ifr": 128 + 64, "fadeout": 300,
|
||||
"pitchenv": {"points": [(0, -32), (30, 32), (60, -32)], "loop": (0, 2), "filter": True}},
|
||||
{"name": "sus loop", "keymap": keymap(5), "fadeout": 400, "gbv": 96},
|
||||
{"name": "split stereo", "keymap": keymap(6, 0, (60, 1)), "fadeout": 200,
|
||||
"volenv": {"points": [(0, 64), (5, 32), (10, 64), (15, 32)], "sustain": (0, 3), "loop": (1, 2)}},
|
||||
]
|
||||
|
||||
|
||||
def song_instruments(compress=None):
|
||||
a, b = empty(5), empty(5)
|
||||
# new note actions: continue / note off / fade, with the duplicate check cutting same-note repeats
|
||||
for i, n in enumerate((61, 64, 68, 73)):
|
||||
put(a, i * 4, 0, n, 1)
|
||||
put(a, i * 4, 1, n - 12, 2)
|
||||
put(a, 16, 1, 0, 0, None, S, 0x71)
|
||||
put(a, 20, 1, 49, 2)
|
||||
put(a, 22, 1, 0, 0, None, S, 0x73)
|
||||
put(a, 24, 1, 56, 2)
|
||||
put(a, 28, 1, OFF)
|
||||
for r in (0, 4, 8, 9, 12, 16):
|
||||
put(a, r, 2, 61 if r != 12 else 64, 3)
|
||||
put(a, 20, 2, 0, 0, None, S, 0x70)
|
||||
put(a, 24, 2, 61, 3, None, S, 0x75)
|
||||
put(a, 26, 2, 66, 3)
|
||||
put(a, 30, 2, FADE)
|
||||
# panning / pitch envelopes, pitch-pan separation, instrument pan
|
||||
put(a, 32, 0, 37, 4)
|
||||
put(a, 32, 1, 61, 4)
|
||||
put(a, 40, 1, 73, 4, None, S, 0x7B)
|
||||
put(a, 44, 1, 0, 0, None, S, 0x7C)
|
||||
put(a, 48, 0, OFF)
|
||||
put(a, 56, 1, CUT)
|
||||
# filters: instrument cutoff + resonance, filter envelope, Zxx
|
||||
put(a, 36, 3, 49, 5)
|
||||
put(a, 44, 3, 0, 0, None, Z, 0x20)
|
||||
put(a, 48, 3, 0, 0, None, Z, 0x60)
|
||||
put(a, 52, 3, 0, 0, None, Z, 0x88)
|
||||
put(a, 60, 3, OFF)
|
||||
# sustain loop + ping-pong, auto-vibrato, instrument global volume, a stereo / mono key split
|
||||
put(b, 0, 0, 61, 6)
|
||||
put(b, 16, 0, OFF)
|
||||
put(b, 0, 1, 49, 7)
|
||||
put(b, 8, 1, 73, 7)
|
||||
put(b, 16, 1, 49, 7, 32)
|
||||
put(b, 24, 1, OFF)
|
||||
put(b, 32, 1, 85, 7)
|
||||
put(b, 8, 4, 61, 1, None, H, 0x44)
|
||||
put(b, 12, 4, 61, 1, None, S, 0x77)
|
||||
put(b, 20, 4, 0, 0, None, S, 0x78)
|
||||
put(b, 40, 4, 61, 3, 0, M, 0x20)
|
||||
put(b, 44, 4, 0, 0, None, N, 0x04)
|
||||
put(b, 48, 4, 0, 0, None, N, 0x30)
|
||||
return T.write_it("instruments", samples(compress), instruments(), [0, 1], [a, b], 5, speed=5, tempo=135,
|
||||
pans=[16, 48, 32, 32, 40], mv=64)
|
||||
|
||||
|
||||
def song_effects(linear=True, old=False, compat=False):
|
||||
a, b = empty(4), empty(4)
|
||||
put(a, 0, 0, 61, 1, 48, D, 0x00)
|
||||
put(a, 4, 0, 0, 0, 70)
|
||||
put(a, 5, 0, 0, 0, 80)
|
||||
put(a, 8, 0, 0, 0, 88)
|
||||
put(a, 12, 0, 0, 0, 99)
|
||||
put(a, 16, 0, 0, 0, 110)
|
||||
put(a, 20, 0, 0, 0, 120)
|
||||
put(a, 24, 0, 49, 0, 196)
|
||||
put(a, 28, 0, 0, 0, 205, H, 0x46)
|
||||
put(a, 32, 0, 0, 0, 160)
|
||||
put(a, 36, 0, 0, 0, None, Y, 0x48)
|
||||
put(a, 44, 0, 0, 0, None, P, 0x08)
|
||||
put(a, 48, 0, 0, 0, None, P, 0x30)
|
||||
put(a, 52, 0, 0, 0, None, P, 0xF4)
|
||||
put(a, 56, 0, 0, 0, None, X, 0xC0)
|
||||
put(a, 0, 1, 49, 2, None, E, 0x04)
|
||||
put(a, 4, 1, 0, 0, None, F, 0x10)
|
||||
put(a, 8, 1, 0, 0, None, E, 0xF8)
|
||||
put(a, 9, 1, 0, 0, None, F, 0xE8)
|
||||
put(a, 12, 1, 49, 2, None, G, 0x08)
|
||||
put(a, 13, 1, 61, 0, None, G, 0x00)
|
||||
put(a, 16, 1, 0, 0, None, E, 0x00)
|
||||
put(a, 20, 1, 56, 2, None, J, 0x37)
|
||||
put(a, 24, 1, 0, 0, None, U, 0x88)
|
||||
put(a, 28, 1, 0, 0, None, R, 0x46)
|
||||
put(a, 32, 1, 0, 0, None, I, 0x31)
|
||||
put(a, 36, 1, 0, 0, None, Q, 0x84)
|
||||
put(a, 40, 1, 0, 0, None, K, 0x02)
|
||||
put(a, 44, 1, 49, 2, None, L, 0x20)
|
||||
put(a, 48, 1, 0, 0, None, O, 0x00)
|
||||
put(a, 52, 1, 61, 4, None, O, 0x04)
|
||||
put(a, 56, 1, 61, 4, None, S, 0xD3)
|
||||
put(a, 60, 1, 61, 4, None, S, 0xC2)
|
||||
put(a, 0, 2, 37, 3, None, V, 0x60)
|
||||
put(a, 8, 2, 0, 0, None, W, 0x04)
|
||||
put(a, 16, 2, 0, 0, None, W, 0x60)
|
||||
put(a, 24, 2, 0, 0, None, Tt, 0x10 + 0x06)
|
||||
put(a, 28, 2, 0, 0, None, Tt, 0x04)
|
||||
put(a, 32, 2, 0, 0, None, Tt, 0x90)
|
||||
put(a, 36, 2, 0, 0, None, S, 0xB0)
|
||||
put(a, 38, 2, 0, 0, None, S, 0xB1)
|
||||
put(a, 40, 2, 0, 0, None, S, 0xE2)
|
||||
put(a, 44, 2, 0, 0, None, S, 0x63)
|
||||
put(a, 48, 2, 0, 0, None, A, 0x04)
|
||||
put(a, 52, 2, 0, 0, None, M, 0x30)
|
||||
put(a, 56, 2, 0, 0, None, N, 0x02)
|
||||
put(a, 0, 3, 73, 7, None, S, 0x91)
|
||||
put(a, 16, 3, 73, 7, None, X, 0x40)
|
||||
put(a, 32, 3, 61, 3, None, S, 0x8C)
|
||||
put(b, 0, 0, 61, 1)
|
||||
put(b, 0, 1, 64, 2)
|
||||
put(b, 0, 2, 68, 3)
|
||||
put(b, 8, 0, CUT)
|
||||
put(b, 12, 1, OFF)
|
||||
put(b, 16, 2, FADE)
|
||||
put(b, 20, 3, 61, 7, None, B, 0x01)
|
||||
return T.write_it("effects", samples(), None, [0, 1], [a, b], 4, speed=4, tempo=140, linear=linear, old=old,
|
||||
compat=compat, pans=[0, 64, 20, 44], vols=[64, 48, 64, 56], gv=112, mv=80)
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
cases = []
|
||||
plain = song_instruments()
|
||||
for nm, data in (("instruments", plain), ("effects", song_effects()), ("amiga old", song_effects(False, True, True)),
|
||||
("compressed 2.14", song_instruments(214)), ("compressed 2.15", song_instruments(215))):
|
||||
ref = T.reference(ctx, data, "it")
|
||||
c = {"name": nm, "data": data, "ref": ref, "duration": ref["duration"]}
|
||||
if nm.startswith("compressed"):
|
||||
c["plain"] = plain
|
||||
cases.append(c)
|
||||
ctx.emit("it_cases", cases)
|
||||
Reference in new issue
Block a user