Files

36 lines
1.8 KiB
Python

# HVL fixtures (tools/fixtures.py): songs written by tools/fixtures/_hively.py (a hand-made 6-channel demo with ring
# modulation, panning and two effect columns; random 4..8 channel songs) plus songs from the HivelyTracker source, each
# rendered by hvl2wav (nixpkgs#hivelytracker) as the reference.
# tests/gen/hvl_cases.luau { { name, data, crc (CRC-32 of hvl2wav's s16le stereo output), head (its first HEAD frames), frames, sampleRate, subsong, maxDuration?, prefix } }
import importlib.util, os, zlib
INPUTS = ["tools/fixtures/_hively.py"]
_spec = importlib.util.spec_from_file_location("_hively", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_hively.py"))
H = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(H)
HEAD = 11025 # frames of hvl2wav output kept as raw samples (to locate a mismatch); the rest is checked by CRC
def case(ctx, name, data, rate=44100, subsong=0, limit=None):
args = ["-f%d" % rate, "-s%d" % subsong] + (["-t0:%02d" % limit] if limit else [])
pcm, frames = H.hvl2wav(ctx, data, "hvl", args)
c = {"name": name, "data": data, "crc": zlib.crc32(pcm), "head": pcm[:HEAD * 4], "frames": frames, "sampleRate": rate, "subsong": subsong,
"prefix": limit is not None}
if limit:
c["maxDuration"] = limit
return c
def generate(ctx):
rng = ctx.rng(0x4E1)
demo = H.write_hvl(H.demo_song(True))
cases = [case(ctx, "demo", demo), case(ctx, "demo 48000 Hz", demo, rate=48000), case(ctx, "demo subsong 1", demo, subsong=1)]
for i in range(4):
cases.append(case(ctx, "random %d" % i, H.write_hvl(H.random_song(rng, True))))
songs = H.source_songs(ctx)
for name in ["chiprolled.hvl", "sunspots.hvl", "syphus-Afterstorm.hvl"]:
cases.append(case(ctx, name, songs[name], limit=3))
ctx.emit("hvl_cases", cases)