Files
rosetta/tools/fixtures/docs_lossless.py
T

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=rosetta"]
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=rosetta"])
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",
})