Files

58 lines
3.6 KiB
Python

# Ogg Vorbis fixtures (tools/fixtures.py): files made by oggenc (libvorbis, vorbis-tools) and ffmpeg (libvorbis) from
# the test signals in tools/fixtures/_audio.py: qualities -1 .. 10, managed bitrate, 8 .. 96 kHz, mono / stereo / 5.1,
# transients (block switching), silence, tags, a stream shorter than one block. References: oggdec (libvorbisfile:
# the authority on start / end trimming) as 16-bit samples, and ffmpeg's f32 decode (more precise, but its Ogg demuxer
# trims some streams differently: the test uses it only when its frame count agrees with oggdec).
# tests/gen/vorbis_cases.luau { name, data, rate, channels, frames (oggdec), ref16 (s16le, oggdec), ffFrames,
# ffRef (f32le, ffmpeg), inputFrames }
import importlib.util, os
_spec = importlib.util.spec_from_file_location("_audio", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_audio.py"))
A = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(A)
CASES = [
# name, signal, rate, channels, seconds, tool, args
("q5-stereo-44k-music", "music", 44100, 2, 1.5, "oggenc", ["-q", "5"]),
("q-1-mono-8k-music", "music", 8000, 1, 1.0, "oggenc", ["-q", "-1"]),
("q10-stereo-48k-sweep", "sweep", 48000, 2, 1.0, "oggenc", ["-q", "10"]),
("q3-mono-22k-noise", "noise", 22050, 1, 0.7, "oggenc", ["-q", "3"]),
("q0-stereo-44k-square", "square", 44100, 2, 1.0, "oggenc", ["-q", "0"]),
("q2-stereo-32k-tags", "sine", 32000, 2, 0.6, "oggenc", ["-q", "2", "-t", "A Title", "-a", "An Artist", "-l", "The Album", "-N", "7", "-c", "comment=hello vorbis"]),
("managed-64k-stereo", "music", 44100, 2, 1.0, "oggenc", ["--managed", "-b", "64"]),
("silence-stereo", "silence", 44100, 2, 0.5, "oggenc", ["-q", "4"]),
("short-100", "sine", 44100, 2, 100 / 44100, "oggenc", ["-q", "4"]),
("short-3000-mono", "music", 44100, 1, 3000 / 44100, "oggenc", ["-q", "4"]),
("q6-stereo-96k", "music", 96000, 2, 0.4, "oggenc", ["-q", "6"]),
("ffmpeg-5.1-48k", "music", 48000, 6, 0.6, "ffmpeg", ["-c:a", "libvorbis", "-q:a", "4"]),
("ffmpeg-mono-16k", "sweep", 16000, 1, 0.8, "ffmpeg", ["-c:a", "libvorbis", "-q:a", "1"]),
("loud-stereo", "loud", 44100, 2, 0.5, "oggenc", ["-q", "8"]),
]
INPUTS = []
def generate(ctx):
cases = []
bench = None
for name, kind, rate, ch, secs, tool, args in CASES:
frames = max(1, int(round(secs * rate)))
sig = A.signal(kind, rate, ch, frames, seed=len(name))
wav = A.wav(sig, rate, ch, float_=True) if tool == "ffmpeg" else A.wav(sig, rate, ch, 16)
if tool == "oggenc":
data = A.tool(ctx, "vorbis-tools", ["oggenc", "-Q", "--serial", "1234"] + args + ["-o", "{out}", "{in}"], wav, "wav", "ogg")
else:
data = A.tool(ctx, "ffmpeg", ["ffmpeg", "-v", "error", "-i", "{in}"] + args + ["-f", "ogg", "-y", "{out}"], wav, "wav", "ogg")
rrate, rch, ref = A.ffdecode(ctx, data, ext="ogg")
raw = A.tool(ctx, "vorbis-tools", ["oggdec", "-Q", "-R", "-o", "{out}", "{in}"], data, "ogg", "raw")
case = {"name": name, "data": data, "rate": rrate, "channels": rch, "frames": len(raw) // (2 * rch), "ref16": raw,
"ffFrames": len(ref) // rch, "inputFrames": frames}
if len(ref) // rch == len(raw) // (2 * rch):
case["ffRef"] = A.f32le(ref)
cases.append(case)
ctx.emit("vorbis_cases", cases)
# bench: 10 s of stereo music at q5
sig = A.signal("music", 44100, 2, 441000, seed=9)
data = A.tool(ctx, "vorbis-tools", ["oggenc", "-Q", "-q", "5", "-o", "{out}", "{in}"], A.wav(sig, 44100, 2, 16), "wav", "ogg")
ctx.emit("vorbis_bench", {"data": data, "frames": 441000, "rate": 44100, "channels": 2})