absorb: opus (audio/opus from opus-luau dd2b4e5, libopus port: direct containers/Ogg require, Types.Decoder open + decode to Audio, Err values); tests vs opusdec --float on 24 generated streams, CELT / SILK alone, PLC, seek, downmix, fuzz; bench lines
This commit is contained in:
1 parent
e3f9d0fb38
commit
d20ffd7388
17 files changed
+6611
-2
No files matched your search
+12
-1
@@ -1,11 +1,16 @@
|
||||
-- Throughput (bash tools/bench.sh): codec MB/s under both runtimes. MB/s are of decompressed output, best of n runs.
|
||||
-- Fixtures: tools/fixtures/deflate.py (a 6 MB corpus) and tools/fixtures/png.py (1024 x 768 images).
|
||||
-- Fixtures: tools/fixtures/deflate.py (a 6 MB corpus), tools/fixtures/png.py (1024 x 768 images), tools/fixtures/opus.py
|
||||
-- (3 s stereo files; MB/s of f32 output, 48 kHz stereo f32 is 0.384 MB/s of real time).
|
||||
local Deflate = require("@formats/codecs/Deflate")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Png = require("@formats/image/png")
|
||||
local B = require("@tests/gen/deflate_bench")
|
||||
local PB = require("@tests/gen/png_bench")
|
||||
local Opus = require("@formats/audio/opus")
|
||||
local OpusCelt = require("@tests/gen/opus_celt_st_128")
|
||||
local OpusSilk = require("@tests/gen/opus_silk_wb_st")
|
||||
local OpusHybrid = require("@tests/gen/opus_hybrid_st")
|
||||
|
||||
local runtime = if (_G :: any).jit ~= nil then "luajit" else "luau"
|
||||
|
||||
@@ -56,3 +61,9 @@ do
|
||||
Png.encode(img)
|
||||
end)
|
||||
end
|
||||
for _, c in { { "celt 128k", OpusCelt }, { "silk wb", OpusSilk }, { "hybrid", OpusHybrid } } do
|
||||
local b = buffer.fromstring(c[2].data)
|
||||
bench("opus decode " .. c[1] .. " (3 s st)", 3, #c[2].ref, function()
|
||||
Opus.decode(Bytes.reader(b))
|
||||
end)
|
||||
end
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
LUAU=${LUAU:-$(command -v luau || nix shell nixpkgs#luau -c sh -c 'command -v luau')}
|
||||
LUAJIT=${LUAJIT:-$(command -v luajit || nix shell nixpkgs#luajit -c sh -c 'command -v luajit')}
|
||||
python3 -I tools/fixtures.py deflate png > /dev/null || exit 1
|
||||
python3 -I tools/fixtures.py deflate png opus > /dev/null || exit 1
|
||||
python3 -I tools/build.py luajit > /dev/null || exit 1
|
||||
"$LUAU" --codegen -O2 tools/bench.luau
|
||||
"$LUAJIT" -e 'package.path = "build/luajit/?.lua;build/luajit/?/init.lua;" .. package.path' build/luajit/tools/bench.lua
|
||||
@@ -0,0 +1,66 @@
|
||||
# Opus fixtures (tools/fixtures.py): audio/opus. Ported from opus-luau tools/fixtures.sh.
|
||||
# tests/gen/opus_<name>.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()})
|
||||
Reference in new issue
Block a user