# Opus fixtures (tools/fixtures.py): audio/opus. Ported from opus-luau tools/fixtures.sh. # tests/gen/opus_.luau { name, data = the .opus file, ref = opusdec --float output (f32 LE interleaved) } # Sources: 48 kHz signals synthesised by ffmpeg (aevalsrc: tones, vibrato, chirps, noise bursts, clicks, a speech-like # harmonic source with moving formants), encoded by opusenc (CELT-only frame sizes / bitrates, forced SILK NB / MB / # WB, hybrid SWB / FB, a 5.1 mapping-family-1 stream, a long tagged file) and ffmpeg libopus (CBR, voip, lowdelay). import os, tempfile MUSIC = ("0.25*sin(2*PI*(220+30*sin(2*PI*5*t))*t)+0.15*sin(2*PI*(100*t+700*t*t))+0.3*exp(-25*mod(t,0.375))*(random(0)-0.5)" "+0.4*lt(mod(t,0.5),0.0006)") MUSIC2 = ("0.2*sin(2*PI*330*t)+0.1*sin(2*PI*1320*t)*lt(mod(t,0.25),0.125)+0.25*exp(-40*mod(t+0.1,0.375))*(random(1)-0.5)" "+0.12*sin(2*PI*(3000-2500*t/3)*t)") F0 = "(120+40*sin(2*PI*0.7*t))" FM = "(600+300*sin(2*PI*1.3*t))" SPEECH = ("(0.5+0.5*sin(2*PI*2.1*t))*(sin(2*PI*{f0}*t)*0.3+sin(2*PI*2*{f0}*t)*0.25+sin(2*PI*3*{f0}*t)*0.2*exp(-abs(3*{f0}-{fm})/400)" "+sin(2*PI*5*{f0}*t)*0.15*exp(-abs(5*{f0}-{fm}*2)/400)+sin(2*PI*8*{f0}*t)*0.08+0.02*(random(2)-0.5))").format(f0=F0, fm=FM) SOURCES = { "music": (MUSIC + "|" + MUSIC2, 3), "mono": (MUSIC + "+0.5*" + SPEECH, 3), "speech": (SPEECH, 3), "speechst": (SPEECH + "|0.7*" + SPEECH + "+0.1*sin(2*PI*440*t)", 3), "mixst": (MUSIC + "+" + SPEECH + "|" + MUSIC2 + "+0.6*" + SPEECH, 3), "surround": (MUSIC + "|" + MUSIC2 + "|" + SPEECH + "|0.3*sin(2*PI*55*t)|0.5*" + MUSIC2 + "|0.5*" + MUSIC, 2), "long": (MUSIC + "+0.3*" + SPEECH + "|" + MUSIC2 + "+0.3*" + SPEECH, 12), } # name, source, encoder ("enc" = opusenc, "ff" = ffmpeg libopus), arguments CASES = [ ("celt_st_128", "music", "enc", ["--music", "--bitrate", "128"]), ("celt_st_32", "music", "enc", ["--music", "--bitrate", "32"]), ("celt_st_64", "mixst", "enc", ["--music", "--bitrate", "64"]), ("celt_st_256", "music", "enc", ["--music", "--bitrate", "256"]), ("celt_mono_64", "mono", "enc", ["--music", "--bitrate", "64"]), ("celt_fs2_5", "music", "enc", ["--music", "--bitrate", "96", "--framesize", "2.5"]), ("celt_fs5", "music", "enc", ["--music", "--bitrate", "96", "--framesize", "5"]), ("celt_fs10", "mixst", "enc", ["--music", "--bitrate", "96", "--framesize", "10"]), ("celt_fs40", "music", "enc", ["--music", "--bitrate", "96", "--framesize", "40"]), ("celt_fs60", "mixst", "enc", ["--music", "--bitrate", "160", "--framesize", "60"]), ("silk_nb", "speech", "enc", ["--speech", "--bitrate", "8", "--max-delay", "0"]), ("silk_mb", "speech", "enc", ["--speech", "--bitrate", "12", "--set-ctl-int", "4008=1102"]), ("silk_wb", "speech", "enc", ["--speech", "--bitrate", "20", "--framesize", "40", "--set-ctl-int", "4008=1103"]), ("silk_wb_st", "speechst", "enc", ["--speech", "--bitrate", "28", "--framesize", "60", "--set-ctl-int", "4008=1103"]), ("silk_nb_st", "speechst", "enc", ["--speech", "--bitrate", "12", "--framesize", "10", "--set-ctl-int", "4008=1101"]), ("hybrid_swb", "speech", "enc", ["--speech", "--bitrate", "24"]), ("hybrid_fb", "speech", "enc", ["--speech", "--bitrate", "36", "--framesize", "10"]), ("hybrid_st", "speechst", "enc", ["--speech", "--bitrate", "40"]), ("mix_st_24", "mixst", "enc", ["--bitrate", "24"]), ("surround51", "surround", "enc", ["--bitrate", "192"]), ("long_128", "long", "enc", ["--bitrate", "128", "--comment", "TITLE=Long Test", "--artist", "opus-luau"]), ("ff_cbr", "mixst", "ff", ["-b:a", "96k", "-vbr", "off"]), ("ff_voip", "speechst", "ff", ["-b:a", "32k", "-application", "voip"]), ("ff_lowdelay", "music", "ff", ["-b:a", "128k", "-application", "lowdelay", "-frame_duration", "5"]), ] def generate(ctx): tmp = tempfile.mkdtemp() for name, (expr, secs) in SOURCES.items(): ctx.nix("ffmpeg", ["ffmpeg", "-loglevel", "error", "-y", "-f", "lavfi", "-i", "aevalsrc='%s':s=48000:d=%d" % (expr, secs), "-c:a", "pcm_s16le", os.path.join(tmp, name + ".wav")]) for name, src, enc, args in CASES: wav, opus, ref = (os.path.join(tmp, x) for x in (src + ".wav", name + ".opus", name + ".f32")) if enc == "enc": ctx.nix("opus-tools", ["opusenc", "--quiet"] + args + [wav, opus]) else: ctx.nix("ffmpeg", ["ffmpeg", "-loglevel", "error", "-y", "-i", wav, "-c:a", "libopus"] + args + [opus]) ctx.nix("opus-tools", ["opusdec", "--quiet", "--float", opus, ref]) ctx.emit("opus_" + name, {"name": name, "data": open(opus, "rb").read(), "ref": open(ref, "rb").read()})