ws-audio2: merge ws/audio2-lossless (WavPack, Monkey's Audio, TTA, ApeTag)

codecs/audio/Stream: both branches extended pull(): buffer pcm (adpcm) and scale / ints (lossless); combined.
This commit is contained in:
4DBug committed 2026-10-31 15:18:31 -05:00
commit f6188764b8
26 files changed
+4728 -6

No files matched your search

+29
View File
@@ -1182,3 +1182,32 @@ do
Qoa.decode(Bytes.reader(file))
end)
end
-- ws-audio2: lossless
do
-- WavPack / Monkey's Audio / TTA decoders (tools/fixtures/wavpack.py, ape.py, tta.py): MB/s of f32 output
local function lossless(label: string, mod: any, data: string)
local b = buffer.fromstring(data)
local dec = assert(mod.open(Bytes.reader(b)))
bench(label, 5, dec.frames * dec.channels * 4, function()
mod.decode(Bytes.reader(b))
end)
end
local Wv = require("@formats/audio/wavpack")
for _, c in require("@tests/gen/wavpack_cases") do
if c.name == "s16_long" or c.name == "s16_hh" or c.name == "s24_hh" or c.name == "f32" or c.name == "hyb_b3" then
lossless("wavpack " .. c.name, Wv, c.data)
end
end
local ApeF = require("@formats/audio/ape")
for _, c in require("@tests/gen/ape_cases") do
if c.name == "s16_long" or c.name == "s16_long_c4000" or c.name == "s16_c5000" or c.name == "s24" or c.name == "s16_c1000" then
lossless("ape " .. c.name, ApeF, c.data)
end
end
local TtaF = require("@formats/audio/tta")
for _, c in require("@tests/gen/tta_cases") do
if c.name == "s16_long" or c.name == "s24" or c.name == "ch6" then
lossless("tta " .. c.name, TtaF, c.data)
end
end
end
+137
View File
@@ -0,0 +1,137 @@
# Monkey's Audio fixtures (tools/fixtures.py): audio/ape, codecs/audio/Ape.
# tests/gen/ape_cases.luau synthetic signals encoded by the reference encoder (mac 13.28: -c1000 .. -c5000, 8 / 16 /
# 24 / 32-bit int and 32-bit float, 1 / 2 / 3 / 4 / 6 / 8 channels, odd rates, short and
# odd lengths, silence (special frames), mono-in-stereo (pseudo stereo), APEv2 tags), and
# the ffmpeg FATE samples luckynight-partial.ape (an older 3.99 encoder, cut) and
# NoLegacy-cut.ape (downloaded at fixture time, not committed); each with the CRC-32 of
# `mac -d`'s samples (integers as i32 LE, floats as their f32 bytes)
import importlib.util, os, struct, tempfile, urllib.request, zlib
_spec = importlib.util.spec_from_file_location("_wv", os.path.join(os.path.dirname(os.path.abspath(__file__)), "wavpack.py"))
WV = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(WV)
CTX = None
TMP = None
CASES = []
FATE = "https://fate-suite.ffmpeg.org/lossless-audio/"
def wav_samples(path):
"""(rate, channels, bits, float, ints-or-raw-bytes) of a WAV file (PCM / float, plain or extensible)"""
d = open(path, "rb").read()
i = 12
fmt = data = None
while i + 8 <= len(d):
cid, size = d[i:i + 4], struct.unpack_from("<I", d, i + 4)[0]
if cid == b"fmt ":
fmt = d[i + 8:i + 8 + size]
elif cid == b"data":
data = d[i + 8:i + 8 + size]
break
i += 8 + size + (size & 1)
tag, ch, rate = struct.unpack_from("<HHI", fmt, 0)
bits = struct.unpack_from("<H", fmt, 14)[0]
fl = tag == 3 or (tag == 0xFFFE and fmt[24:26] == b"\x03\x00")
w = bits // 8
if fl:
return rate, ch, bits, True, data
if w == 1:
ints = [b - 128 for b in data]
else:
ints = [int.from_bytes(data[k:k + w], "little", signed=True) for k in range(0, len(data) - w + 1, w)]
return rate, ch, bits, False, ints
def emit(name, ape, note, tags=None, partial=False):
out = ape + ".out.wav"
try:
CTX.nix("monkeys-audio", ["mac", ape, out, "-d"])
except Exception:
if not partial: # a cut file: mac writes the whole frames before the cut, then fails
raise
rate, ch, bits, fl, s = wav_samples(out)
if fl:
crc, n = zlib.crc32(s), len(s) // 4
else:
crc, n = zlib.crc32(b"".join(struct.pack("<i", v) for v in s)), len(s)
c = {"name": name, "note": note, "data": open(ape, "rb").read(), "rate": rate, "channels": ch, "bits": bits,
"float": fl, "frames": n // ch, "crc": crc, "partial": partial}
if tags:
c["tags"] = tags
CASES.append(c)
def case(name, level, secs=0.3, rate=44100, ch=2, bits=16, fl=False, kind="music", seed=1, frames=None, note=None,
tags=None, mono_stereo=False):
if fl:
bits = 32
wav = os.path.join(TMP, name + ".wav")
ape = os.path.join(TMP, name + ".ape")
vals = WV.signal(secs, rate, 1 if mono_stereo else ch, kind, seed, frames)
if mono_stereo:
vals = [v for v in vals for _ in range(ch)]
WV.write_wav(wav, vals, ch, rate, bits, fl)
args = ["mac", wav, ape, "-c%d" % level]
if tags:
args += ["-t", "|".join("%s=%s" % kv for kv in tags.items())]
CTX.nix("monkeys-audio", args)
emit(name, ape, note or "mac -c%d, %d-bit%s, %d ch" % (level, bits, " float" if fl else "", ch),
tags={({"year": "date"}).get(k.lower(), k.lower()): v for k, v in tags.items()} if tags else None)
def fate(name, file, cut=None):
path = os.path.join(TMP, file)
try:
with urllib.request.urlopen(FATE + file, timeout=60) as r:
data = r.read()
if cut: # keep `cut` whole frames and a little of the next one
desc = struct.unpack_from("<I", data, 8)[0]
head = struct.unpack_from("<I", data, 12)[0]
data = data[:struct.unpack_from("<I", data, desc + head + 4 * cut)[0] + 64]
open(path, "wb").write(data)
except Exception as e: # offline: skip the FATE samples
print("ape: skipping %s (%s)" % (file, e))
return
emit(name, path, "ffmpeg FATE sample " + file, partial=True)
def generate(ctx):
global CTX, TMP
CTX = ctx
WV.CTX = ctx
TMP = tempfile.mkdtemp()
CASES.clear()
for level in (1000, 2000, 3000, 4000, 5000):
case("s16_c%d" % level, level, seed=level // 1000)
case("s16_long", 2000, secs=3.0, seed=2, note="mac -c2000, 3 s (bench + seek)")
case("s16_long_c4000", 4000, secs=1.5, seed=3, note="mac -c4000, 1.5 s (bench)")
case("mono", 2000, ch=1)
case("mono_c5000", 5000, ch=1, rate=22050, seed=4)
case("u8", 2000, bits=8, ch=1, rate=8000, kind="mixed")
case("u8_stereo", 3000, bits=8, rate=11025)
case("s24", 2000, bits=24, rate=48000, secs=0.2)
case("s24_c4000", 4000, bits=24, rate=96000, secs=0.15, kind="mixed")
case("s24_c5000", 5000, bits=24, rate=48000, secs=0.15, seed=5)
case("s24_mono", 3000, bits=24, ch=1, rate=48000, secs=0.2)
case("s32", 2000, bits=32, rate=48000, secs=0.15)
case("s32_c4000", 4000, bits=32, rate=48000, secs=0.15, kind="mixed")
case("f32", 2000, fl=True, rate=48000, secs=0.15)
case("f32_c3000", 3000, fl=True, rate=44100, secs=0.15, kind="mixed")
case("ch3", 2000, ch=3, secs=0.15)
case("ch4", 3000, ch=4, secs=0.15)
case("ch6", 2000, ch=6, rate=48000, secs=0.15)
case("ch6_24", 3000, ch=6, bits=24, rate=48000, secs=0.1)
case("ch8", 1000, ch=8, rate=48000, secs=0.1)
case("noise", 2000, kind="noise", secs=0.2)
case("noise_c5000", 5000, kind="noise", secs=0.1, seed=6)
case("silence", 2000, kind="silence")
case("mixed", 3000, kind="mixed", secs=0.4)
case("pseudo_stereo", 2000, mono_stereo=True, note="the same signal in both channels (pseudo-stereo frames)")
case("one_frame", 2000, frames=1)
case("seven_frames", 3000, frames=7, ch=1)
case("odd_len", 2000, frames=300001, rate=48000, seed=7, note="300001 frames: two APE frames")
case("rate37000", 2000, rate=37000, secs=0.2)
case("tags", 2000, tags={"Title": "Lossless Tone", "Artist": "formats-luau", "Year": "2026", "Track": "3"})
fate("fate_lucky", "luckynight-partial.ape", cut=2)
ctx.emit("ape_cases", CASES)
+40
View File
@@ -0,0 +1,40 @@
# Docs inputs for the guide's lossless audio section (tools/fixtures.py; tools/docs_check.py reads them): the docs
# stereo tone (tools/fixtures/docs_inputs.py) encoded by the reference encoders, with tags: WavPack lossless, WavPack
# hybrid (.wv + its .wvc correction file), Monkey's Audio (-c2000) and TTA.
# tests/gen/docs_lossless.luau { files = { [name] = bytes }, vars = { wvBytes = "tone.wv", ... } }
# tests/gen/docs_files/assets/<name> the same files, for the snippets that load by path
import importlib.util, os, tempfile
INPUTS = ["tools/docs_check.py", "tools/fixtures/docs_inputs.py"]
def load(ctx, name):
spec = importlib.util.spec_from_file_location("docs_lossless_" + name.replace("/", "_"),
os.path.join(ctx.root, "tools", name + ".py"))
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
return m
def generate(ctx):
dc = load(ctx, "docs_check")
di = load(ctx, "fixtures/docs_inputs")
files = {}
with tempfile.TemporaryDirectory() as d:
wav = os.path.join(d, "tone.wav")
with open(wav, "wb") as f:
f.write(di.tone(44100, 1.0))
tags = ["-w", "Title=Docs Tone", "-w", "Artist=formats-luau"]
ctx.nix("wavpack", ["wavpack", "-q", "-y", "-h"] + tags + [wav, "-o", os.path.join(d, "tone.wv")])
ctx.nix("wavpack", ["wavpack", "-q", "-y", "-b3", "-c"] + tags + [wav, "-o", os.path.join(d, "tone_hybrid.wv")])
ctx.nix("monkeys-audio", ["mac", wav, os.path.join(d, "tone.ape"), "-c2000", "-t", "Title=Docs Tone|Artist=formats-luau"])
ctx.nix("ttaenc", ["ttaenc", "-e", wav, "-o", os.path.join(d, "tone.tta")])
for name in ("tone.wv", "tone_hybrid.wv", "tone_hybrid.wvc", "tone.ape", "tone.tta"):
files[name] = open(os.path.join(d, name), "rb").read()
dc.emit_inputs(ctx, files, {
"wvBytes": "tone.wv",
"hybridWvBytes": "tone_hybrid.wv",
"hybridWvcBytes": "tone_hybrid.wvc",
"apeBytes": "tone.ape",
"ttaBytes": "tone.tta",
})
+93
View File
@@ -0,0 +1,93 @@
# TTA fixtures (tools/fixtures.py): audio/tta, codecs/audio/Tta.
# tests/gen/tta_cases.luau synthetic signals encoded by the reference encoder (ttaenc 3.4.1: 8 / 16 / 24 bits,
# 1 / 2 / 3 / 6 channels, odd rates, short and odd lengths, several frames, silence, noise,
# full scale) and the ffmpeg FATE sample inside.tta (downloaded at fixture time, cut after 2
# frames, not committed); each with the CRC-32 of `ttaenc -d`'s samples (i32 LE)
import importlib.util, os, struct, tempfile, urllib.request, zlib
_dir = os.path.dirname(os.path.abspath(__file__))
_spec = importlib.util.spec_from_file_location("_wv", os.path.join(_dir, "wavpack.py"))
WV = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(WV)
_spec = importlib.util.spec_from_file_location("_ape", os.path.join(_dir, "ape.py"))
APE = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(APE)
CTX = None
TMP = None
CASES = []
FATE = "https://fate-suite.ffmpeg.org/lossless-audio/"
def emit(name, tta, note, partial=False, keep=None):
out = tta + ".out.wav"
try:
CTX.nix("ttaenc", ["ttaenc", "-d", tta, "-o", out])
except Exception:
if not partial:
raise
rate, ch, bits, fl, s = APE.wav_samples(out)
if keep is not None: # a cut file: ttaenc also writes the broken frame; keep the whole ones
s = s[:keep * ch]
CASES.append({"name": name, "note": note, "data": open(tta, "rb").read(), "rate": rate, "channels": ch,
"bits": bits, "float": False, "frames": len(s) // ch,
"crc": zlib.crc32(b"".join(struct.pack("<i", v) for v in s)), "partial": partial})
def plain_wav(path, vals, ch, rate, bits):
"""a plain PCM WAV (ttaenc reads WAVE_FORMAT_PCM)"""
w = bits // 8
top = (1 << (bits - 1)) - 1
data = bytearray()
for v in vals:
x = max(-top - 1, min(top, int(round(v * top))))
data += bytes([(x + 128) & 255]) if w == 1 else x.to_bytes(w, "little", signed=True)
fmt = struct.pack("<HHIIHH", 1, ch, rate, rate * ch * w, ch * w, bits)
body = b"WAVE" + b"fmt " + struct.pack("<I", len(fmt)) + fmt + b"data" + struct.pack("<I", len(data)) + bytes(data)
open(path, "wb").write(b"RIFF" + struct.pack("<I", len(body)) + body)
def case(name, secs=0.3, rate=44100, ch=2, bits=16, kind="music", seed=1, frames=None, note=None):
wav = os.path.join(TMP, name + ".wav")
tta = os.path.join(TMP, name + ".tta")
plain_wav(wav, WV.signal(secs, rate, ch, kind, seed, frames), ch, rate, bits)
CTX.nix("ttaenc", ["ttaenc", "-e", wav, "-o", tta])
emit(name, tta, note or "ttaenc -e, %d-bit, %d ch, %d Hz" % (bits, ch, rate))
def generate(ctx):
global CTX, TMP
CTX = ctx
APE.CTX = ctx
TMP = tempfile.mkdtemp()
CASES.clear()
case("s16")
case("s16_long", secs=3.0, seed=2, note="3 s, 3 frames (bench + seek)")
case("mono", ch=1)
case("u8", bits=8, ch=1, rate=8000, kind="mixed")
case("u8_stereo", bits=8, rate=11025)
case("s24", bits=24, rate=48000, secs=0.3)
case("s24_mixed", bits=24, rate=96000, secs=0.2, kind="mixed")
case("s24_mono", bits=24, ch=1, rate=48000)
case("ch3", ch=3, secs=0.2)
case("ch6", ch=6, rate=48000, secs=0.2)
case("noise", kind="noise", secs=0.2)
case("noise24", bits=24, kind="noise", secs=0.1)
case("silence", kind="silence")
case("mixed", kind="mixed", secs=0.4)
case("one_frame", frames=1)
case("seven_frames", frames=7, ch=1)
case("odd_len", frames=100001, rate=48000, seed=7, note="100001 frames: 3 TTA frames, a short last one")
case("rate37000", rate=37000, secs=0.2)
case("rate8000", rate=8000, secs=1.5, ch=1, note="8 kHz: 8359-sample frames")
path = os.path.join(TMP, "inside.tta")
try:
with urllib.request.urlopen(FATE + "inside.tta", timeout=60) as r:
data = r.read()
frames = (struct.unpack_from("<I", data, 18)[0] + 46079) // 46080
sizes = struct.unpack_from("<%dI" % frames, data, 22)
open(path, "wb").write(data[:22 + frames * 4 + 4 + sizes[0] + sizes[1] + 100])
emit("fate_inside", path, "ffmpeg FATE sample inside.tta (cut after 2 frames)", partial=True, keep=2 * 46080)
except OSError as e: # offline: skip the FATE sample
print("tta: skipping inside.tta (%s)" % e)
ctx.emit("tta_cases", CASES)
+177
View File
@@ -0,0 +1,177 @@
# WavPack fixtures (tools/fixtures.py): audio/wavpack, codecs/audio/WavPack.
# tests/gen/wavpack_cases.luau synthetic signals encoded by the reference encoder (wavpack 5.9: -f / default / -h /
# -hh / -x1..6, joint stereo on / off, 8 / 12 / 16 / 20 / 24 / 32-bit int and 32-bit
# float, 1 / 2 / 3 / 6 / 8 channels, odd rates, short and odd lengths, small blocks,
# hybrid lossy (-b, noise shaping) and hybrid lossless (+ the .wvc), APEv2 tags, MD5)
# and by ffmpeg's encoder; each with the CRC-32 of wvunpack's raw output (integers as
# i32 LE, floats as their f32 bytes)
import math, os, random, struct, tempfile, zlib
CTX = None
TMP = None
CASES = []
def signal(secs, rate, ch, kind="music", seed=1, frames=None):
"""floats in -1..1, interleaved"""
rnd = random.Random(seed)
n = frames if frames is not None else int(secs * rate)
out = []
notes = [(rnd.uniform(80, 1500), rnd.uniform(0, max(n, 1)), rnd.uniform(0.1, 0.5) * rate) for _ in range(int(n / rate * 6) + 3)]
for i in range(n):
t = i / rate
for c in range(ch):
if kind == "noise":
v = rnd.uniform(-0.95, 0.95)
elif kind == "silence":
v = 0.0
elif kind == "mixed": # silence, a tone, noise bursts, full scale
seg = (i * 8 // max(n, 1))
if seg in (0, 4):
v = 0.0
elif seg == 5:
v = rnd.uniform(-1, 1)
elif seg == 6:
v = 0.999 if (i // 37) % 2 else -1.0
else:
v = 0.7 * math.sin(2 * math.pi * (300 + 50 * c) * t)
else:
v = 0.0
for f, st, dur in notes:
if st <= i < st + dur:
e = math.exp(-3 * (i - st) / dur) * min(1.0, (i - st) / 100)
v += 0.25 * e * (math.sin(2 * math.pi * f * (1 + 0.002 * c) * t) + 0.3 * math.sin(6 * math.pi * f * t + c))
v += 0.003 * (rnd.random() - 0.5) + 0.04 * math.sin(2 * math.pi * (60 + 7 * c) * t)
out.append(max(-1.0, min(1.0, v)))
return out
def write_wav(path, vals, ch, rate, bits, fl=False):
container = 32 if fl else (bits + 7) // 8 * 8
data = bytearray()
top = (1 << (bits - 1)) - 1
for v in vals:
if fl:
data += struct.pack("<f", v)
continue
x = int(round(v * top)) if v < 1 else top
x = max(-top - 1, min(top, x)) << (container - bits)
if container == 8:
data.append((x + 128) & 255)
else:
data += x.to_bytes(container // 8, "little", signed=True)
sub = b"\x03\x00" if fl else b"\x01\x00"
guid = sub + b"\x00\x00\x00\x00\x10\x00\x80\x00\x00\xaa\x00\x38\x9b\x71"
mask = {1: 4, 2: 3, 3: 7, 4: 0x33, 6: 0x3F, 8: 0x63F}.get(ch, 0)
fmt = struct.pack("<HHIIHHHHI16s", 0xFFFE, ch, rate, rate * ch * container // 8, ch * container // 8, container,
22, bits, mask, guid)
body = b"WAVE" + b"fmt " + struct.pack("<I", len(fmt)) + fmt + b"data" + struct.pack("<I", len(data)) + bytes(data)
open(path, "wb").write(b"RIFF" + struct.pack("<I", len(body)) + body)
def reference(wv, container, fl, ignore_wvc=False):
raw = wv + ".raw"
CTX.nix("wavpack", ["wvunpack", "-q", "-y", "-r"] + (["-i"] if ignore_wvc else []) + [wv, "-o", raw])
d = open(raw, "rb").read()
if fl:
return zlib.crc32(d), len(d) // 4
w = container // 8
if w == 1:
ints = [b - 128 for b in d]
else:
ints = [int.from_bytes(d[i:i + w], "little", signed=True) for i in range(0, len(d), w)]
return zlib.crc32(b"".join(struct.pack("<i", v) for v in ints)), len(ints)
def case(name, args, secs=0.3, rate=44100, ch=2, bits=16, fl=False, kind="music", seed=1, frames=None, note=None,
wvc=False, lossy=False, tags=None, ffmpeg=None):
if fl:
bits = 32
wav = os.path.join(TMP, name + ".wav")
wv = os.path.join(TMP, name + ".wv")
write_wav(wav, signal(secs, rate, ch, kind, seed, frames), ch, rate, bits, fl)
if ffmpeg is not None:
CTX.nix("ffmpeg", ["ffmpeg", "-v", "error", "-y", "-i", wav] + ffmpeg + [wv])
else:
CTX.nix("wavpack", ["wavpack", "-q", "-y"] + args + [wav, "-o", wv])
data = open(wv, "rb").read()
k = 0
while struct.unpack_from("<I", data, k + 20)[0] == 0: # the first audio block's flags give the container
k += 8 + struct.unpack_from("<I", data, k + 4)[0]
flags = struct.unpack_from("<I", data, k + 24)[0]
container = ((flags & 3) + 1) * 8
crc, count = reference(wv, container, fl, ignore_wvc=lossy)
c = {"name": name, "note": note or ("ffmpeg " + " ".join(ffmpeg) if ffmpeg is not None else "wavpack " + " ".join(args)),
"data": data, "rate": rate, "channels": ch, "bits": bits, "container": container,
"float": fl, "frames": count // ch, "crc": crc, "lossy": lossy}
if wvc:
c["wvc"] = open(wv + "c", "rb").read()
c["lossy_crc"] = reference(wv, container, fl, ignore_wvc=True)[0]
if tags:
c["tags"] = tags
CASES.append(c)
def generate(ctx):
global CTX, TMP
CTX = ctx
TMP = tempfile.mkdtemp()
CASES.clear()
for mode in ("-f", "-g", "-h", "-hh"):
case("s16" + mode.replace("-", "_"), [mode])
for x in range(1, 7):
case("s16_x%d" % x, ["-x%d" % x], secs=0.2, seed=x)
case("s16_hhx6", ["-hh", "-x6"], seed=7)
case("s16_j0", ["-j0"], seed=8)
case("s16_j1_hh", ["-j1", "-hh"], seed=9)
case("s16_long", ["-h"], secs=3.0, seed=2, note="wavpack -h, 3 s (bench + seek)")
case("mono16", ["-g"], ch=1)
case("mono16_hh", ["-hh", "-x4"], ch=1, rate=22050)
case("u8", ["-g"], bits=8, ch=1, rate=8000, kind="mixed")
case("u8_stereo", ["-h"], bits=8, rate=11025)
case("s12", ["-g"], bits=12, rate=32000)
case("s20", ["-hh"], bits=20, rate=48000)
case("s24", ["-g"], bits=24, rate=96000, secs=0.2)
case("s24_hh", ["-hh", "-x3"], bits=24, rate=48000, kind="mixed")
case("s32", ["-g"], bits=32, rate=48000, secs=0.2)
case("s32_hh", ["-hh"], bits=32, rate=48000, secs=0.2, kind="mixed")
case("s32_opt", ["--optimize-int32"], bits=32, rate=48000, secs=0.2)
case("f32", ["-g"], fl=True, rate=48000, secs=0.2)
case("f32_hh", ["-hh", "-x2"], fl=True, rate=44100, kind="mixed")
case("f32_mono", ["-f"], fl=True, ch=1, rate=22050)
case("ch3", ["-g"], ch=3, bits=24, secs=0.2)
case("ch6", ["-h"], ch=6, rate=48000, secs=0.2)
case("ch8", ["-f"], ch=8, rate=48000, secs=0.1)
case("noise", ["-g"], kind="noise", secs=0.2)
case("silence", ["-g"], kind="silence", secs=0.3)
case("mixed", ["-hh"], kind="mixed", secs=0.4)
case("one_frame", ["-g"], frames=1)
case("seven_frames", ["-h"], frames=7, ch=1)
case("odd_len", ["-g", "--blocksize=1001"], frames=12345, seed=3, note="block size 1001, 12345 frames")
case("rate37000", ["-g"], rate=37000, secs=0.2, note="a rate without a header code")
case("rate7", ["-g"], rate=7, frames=300, note="7 Hz")
case("md5_tags", ["-g", "-m", "-w", "Title=Lossless Tone", "-w", "Artist=formats-luau", "-w", "Year=2026",
"-w", "Track=3/9", "-w", "Album Artist=Some Band"],
tags={"title": "Lossless Tone", "artist": "formats-luau", "date": "2026", "track": "3/9",
"albumartist": "Some Band"})
# hybrid: lossy (no correction file), and lossless with the .wvc
case("hyb_b3", ["-b3"], lossy=True, note="hybrid lossy, 3 bits / sample")
case("hyb_b2_mono", ["-b2.5", "-h"], ch=1, lossy=True)
case("hyb_b4_s0", ["-b4", "-s0"], lossy=True, note="hybrid lossy, no noise shaping")
case("hyb_b3_24", ["-b3.5", "-hh"], bits=24, rate=48000, lossy=True)
case("hyb_c3", ["-b3", "-c"], wvc=True, note="hybrid lossless (wv + wvc)")
case("hyb_c3_shape", ["-b3", "-c", "-s0.5"], wvc=True, seed=4, note="hybrid lossless, positive noise shaping")
case("hyb_c3_neg", ["-b3", "-c", "-s-0.5"], wvc=True, seed=5, note="hybrid lossless, negative shaping (NEW_SHAPING)")
case("hyb_cc", ["-b2.5", "-cc", "-h"], wvc=True, seed=6, note="hybrid lossless, max compression (cross decorr)")
case("hyb_c_mono", ["-b3", "-c", "-hh"], ch=1, wvc=True)
case("hyb_c_dns", ["-b3", "-c", "--use-dns"], wvc=True, seed=10, note="dynamic noise shaping")
case("hyb_c_24", ["-b4", "-c", "-x3"], bits=24, rate=48000, wvc=True)
case("hyb_c_f32", ["-b4", "-c"], fl=True, wvc=True, note="hybrid lossless float (wvx in the wvc)")
case("hyb_c_ch6", ["-b3", "-c"], ch=6, rate=48000, secs=0.2, wvc=True)
# ffmpeg's encoder
case("ff_s16", [], ffmpeg=["-c:a", "wavpack"])
case("ff_l8", [], ffmpeg=["-c:a", "wavpack", "-compression_level", "8"], seed=11)
case("ff_s24", [], bits=24, ffmpeg=["-c:a", "wavpack", "-sample_fmt", "s32p"], seed=12)
case("ff_f32", [], fl=True, ffmpeg=["-c:a", "wavpack"], seed=13)
case("ff_mono", [], ch=1, ffmpeg=["-c:a", "wavpack", "-compression_level", "3"], seed=14)
ctx.emit("wavpack_cases", CASES)