# MP3 fixtures (tools/fixtures.py). Ported from mp3-luau tools/make_fixtures.sh + make_refs.py. # tests/gen/mp3_cases.luau the committed streams in tests/fixtures/mp3/ (made by ffmpeg's libmp3lame / mp2 encoders # from a synthetic test signal: tones, a chirp, noise, clicks) with their minimp3 reference # decodes (*.ref, from the minimp3 C harness: see the format below), plus streams lame # encodes here; each with ffmpeg's decode of three windows and its length. # .ref layout (little-endian): "MP3REF1\0", u32 hz, channels, frames, window frames W, window count N, then # N x (u32 start frame, W x channels f32), then u32 block size B, u32 block count, f64 sum of squares per block. import math, os, random, struct, tempfile INPUTS = ["tests/fixtures/mp3"] DIR = os.path.join("tests", "fixtures", "mp3") def ffmpeg_windows(ctx, data, ch, starts, W): with tempfile.TemporaryDirectory() as tmp: # a file, not a pipe: ffmpeg applies the LAME gapless info only when it can seek path = os.path.join(tmp, "in.mp3") with open(path, "wb") as f: f.write(data) out = ctx.nix("ffmpeg", ["ffmpeg", "-v", "error", "-i", path, "-f", "f32le", "-ac", str(ch), "pipe:1"]) frames = len(out) // (4 * ch) wins = [] for s in starts: s = max(0, min(frames - W, s)) wins.append({"start": s, "pcm": out[s * ch * 4:(s + W) * ch * 4]}) return frames, wins def ref_windows(ref): hz, ch, frames, W, N = struct.unpack_from("<5I", ref, 8) p, starts = 28, [] for _ in range(N): starts.append(struct.unpack_from("