Files
rosetta/tools/fixtures/docs_lossless.py
T
4DBug 085e385674 ws-audio2: TTA: codecs/audio/Tta (written from the TTA1 format description; no libtta / ffmpeg code) + audio/tta
TTA1 format 1, 8/16/24 bits, any channel count, header / seek table / frame CRC-32s, seeking, ID3v2 skipped, APEv2
tags; password-protected files -> UNSUPPORTED. 20 fixtures (ttaenc 3.4.1, the FATE inside.tta sample) bit-exact
against ttaenc -d. Branch-free filter steps (LuaJIT: no register-coalescing aborts, 7 -> 40 MB/s).
WavPack: the unary / gamma counts a byte at a time (LuaJIT traces). APE: the predictor rotations as single
assignments. docs/guide/audio.md: the lossless section (+ tools/fixtures/docs_lossless.py inputs) and the Formats
table.
2026-10-31 15:08:47 -05:00

41 lines
2.0 KiB
Python

# 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",
})