# Docs inputs for the Musepack / AC-3 section of docs/guide/audio.md (tools/docs_check.py): a tagged stereo tone as # Musepack SV8 (mpcenc, built by tools/fixtures/mpc.py's nix expression) and a 5.1 tone as AC-3 (ffmpeg). # tests/gen/docs_lossy.luau { files = { [name] = bytes }, vars = { mpcBytes = "tone.mpc", ac3Bytes = "tone.ac3" } } import importlib.util, math, os, shutil, struct, subprocess, tempfile INPUTS = ["tools/docs_check.py", "tools/fixtures/mpc.py"] def load(ctx, rel, name): spec = importlib.util.spec_from_file_location(name, os.path.join(ctx.root, rel)) m = importlib.util.module_from_spec(spec) spec.loader.exec_module(m) return m def generate(ctx): dc = load(ctx, "tools/docs_check.py", "docs_check") mpc = load(ctx, "tools/fixtures/mpc.py", "docs_lossy_mpc") d = tempfile.mkdtemp(prefix="fmt-docs-lossy-") try: rate, n = 44100, 44100 st = [0.3 * math.sin(2 * math.pi * f * i / rate) for i in range(n) for f in (440, 660)] with open(os.path.join(d, "tone.wav"), "wb") as f: f.write(mpc.A.wav(st, rate, 2)) subprocess.run([os.path.join(mpc.tools(), "mpcenc"), "--silent", "--overwrite", "--quality", "4", "--tag", "Title=Docs Tone", "--artist", "rosetta", os.path.join(d, "tone.wav"), os.path.join(d, "tone.mpc")], capture_output=True, check=True) six = [0.2 * math.sin(2 * math.pi * (200 + 100 * c) * i / 48000) for i in range(24000) for c in range(6)] with open(os.path.join(d, "six.raw"), "wb") as f: f.write(struct.pack("<%df" % len(six), *six)) ctx.nix("ffmpeg", ["sh", "-c", "cd '%s' && ffmpeg -v error -y -f f32le -ar 48000 -ch_layout '5.1(side)' -i six.raw " "-c:a ac3 -b:a 384k tone.ac3" % d]) files = {} for name in ("tone.mpc", "tone.ac3"): with open(os.path.join(d, name), "rb") as f: files[name] = f.read() finally: shutil.rmtree(d, ignore_errors=True) dc.emit_inputs(ctx, files, {"mpcBytes": "tone.mpc", "ac3Bytes": "tone.ac3"})