# WAV fixtures (tools/fixtures.py): audio/wav. Ported from wav-luau tools/mkfixtures.py. # tests/gen/wav_cases.luau a short synthetic stereo signal in every supported format and container (ffmpeg / sox), # plus hand-patched variants (data size 0 / 0xFFFFFFFF, truncation, odd chunks with and # without the pad byte, tags after the data), with ffmpeg's (or sox's) f32le decode # tests/gen/wav_enc.luau encoder references: random samples at each depth, written by ffmpeg with -bitexact # (PCM u8 / s16 / s24 / s32 / f32, 1-8 channels, > 48 kHz, RF64); our encoder must # produce the same bytes import os, random, struct, tempfile CTX = None def build_cases(): work = tempfile.mkdtemp() RATE, DUR = 16000, 0.2 SRC = "aevalsrc=0.6*sin(2*PI*440*t)+0.25*sin(2*PI*3100*t*t*10)|0.5*sin(2*PI*660*t)+0.2*(random(1)*2-1):s=%d:d=%g" % (RATE, DUR) def run(*args): CTX.nix(["ffmpeg", "sox"], list(args)) def path(n): return os.path.join(work, n) def ffenc(name, *args, ac=2): run("ffmpeg", "-v", "error", "-y", "-f", "lavfi", "-i", SRC, "-ac", str(ac), *args, path(name)) return path(name) def ref(p): return CTX.nix("ffmpeg", ["ffmpeg", "-v", "error", "-i", p, "-f", "f32le", "-c:a", "pcm_f32le", "-"]) def soxref(p): # ffmpeg cannot read every RIFX file: sox decodes those (through its 32-bit integer pipeline) return CTX.nix("sox", ["sox", p, "-t", "raw", "-e", "floating-point", "-b", "32", "-L", "-"]) def chunks(d): be = d[:4] == b"RIFX" p, out = 12, [] while p + 8 <= len(d): cid = d[p:p + 4] size = struct.unpack_from(">I" if be else "= frames * 8 add("truncated_ima", dima[:cut], rima[:frames * 2 * 4], 2, "ima_adpcm") # odd-sized chunks before the data, padded and unpadded fp, fs = find(d16, b"fmt ") head, rest = d16[:fp + 8 + fs], d16[fp + 8 + fs:] def riff(body): return b"RIFF" + struct.pack("