ws-m4a: CELT-only Opus encoder in audio/opus (RangeEncoder + CeltEncoder ported from the libopus 1.6 encoder paths to mirror the absorbed decoder: 20 ms full-band CBR, mono and mid/side stereo, silence frames; Encode: Ogg Opus with OpusHead/OpusTags, end trimming, 48 kHz resampling); checked by opusdec / opusinfo / ffmpeg; Opus.caps.encode = true (opus test updated), deps += codecs/Mdct

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
4DBugandClaude Opus 5.5 committed 2026-10-31 09:22:52 -05:00
1 parent c3cf73e29f
commit c43c56eadd
13 files changed
+1761 -8

No files matched your search

+10
View File
@@ -184,3 +184,13 @@ do
end
end)
end
do
local Opus = require("@formats/audio/opus")
local Cases = require("@tests/audio/_opus_cases")
local c = Cases.list[2]
local a = Cases.signal(c)
local dt = bench("opus celt encode 128k (1.5 s st)", 2, a.frames * a.channels * 2, function()
Opus.encode(a, { bitrate = 128000 })
end)
local _ = dt
end
+17
View File
@@ -0,0 +1,17 @@
-- tools/fixtures/_opus_encode: run by tools/fixtures/opus_celt.py (luau, from the repo root): encodes
-- tests/audio/_opus_cases with audio/opus's CELT encoder and prints "<name> <hex>" lines for opusdec / ffmpeg.
local Opus = require("@formats/audio/opus")
local Cases = require("@tests/audio/_opus_cases")
for _, c in Cases.list do
local out, err = Opus.encode(Cases.signal(c), { bitrate = c.bitrate })
if not out then
print(c.name .. " ERROR " .. tostring(err))
else
local t = table.create(buffer.len(out))
for i = 0, buffer.len(out) - 1 do
t[i + 1] = string.format("%02x", buffer.readu8(out, i))
end
print(c.name .. " " .. table.concat(t))
end
end
+48
View File
@@ -0,0 +1,48 @@
# The CELT encoder reference check (tools/fixtures.py): runs tools/fixtures/_opus_encode.luau (our encoder over
# tests/audio/_opus_cases.luau), then the reference tools through nix: opusdec --float (libopus), opusinfo (stream
# structure), ffmpeg (an independent Ogg / Opus reader).
# tests/gen/opus_celt.luau { { name, crc (of our bytes), opusdec (f32le 48 kHz decode), opusinfo (exit 0),
# ffmpeg (decoded), ffmpegFrames, comments (opusinfo's user comments) } }
import os, re, shutil, subprocess, tempfile, zlib
INPUTS = ["src/Formats/audio/opus", "src/Formats/codecs/Mdct", "src/Formats/containers/Ogg",
"tests/audio/_opus_cases.luau", "tools/fixtures/_opus_encode.luau"]
def generate(ctx):
luau = os.environ.get("LUAU") or shutil.which("luau")
script = os.path.join(ctx.root, "tools/fixtures/_opus_encode.luau")
if luau:
out = subprocess.run([luau, script], capture_output=True, check=True, cwd=ctx.root).stdout
else:
out = ctx.nix("luau", ["luau", script])
d = tempfile.mkdtemp(prefix="opus-celt-fx-")
try:
cases = []
for line in out.decode().split("\n"):
if not line.strip():
continue
name, hx = line.split(" ", 1)
if hx.startswith("ERROR"):
raise RuntimeError("opus_celt fixtures: our encoder failed on %s: %s" % (name, hx))
data = bytes.fromhex(hx)
path = os.path.join(d, name + ".opus")
with open(path, "wb") as f:
f.write(data)
raw = os.path.join(d, name + ".f32")
ctx.nix("opus-tools", ["opusdec", "--quiet", "--float", "--rate", "48000", path, raw])
with open(raw, "rb") as f:
pcm = f.read()
info = subprocess.run(["nix", "shell", "nixpkgs#opus-tools", "-c", "opusinfo", path], capture_output=True)
text = info.stdout.decode(errors="replace")
comments = {}
for m in re.finditer(r"^\s*([A-Za-z]+)=(.*)$", text, re.M):
comments[m.group(1).lower()] = m.group(2)
ok = info.returncode == 0 and "WARNING" not in text and "ERROR" not in text.upper().replace("ERRORS", "")
ff = subprocess.run(["nix", "shell", "nixpkgs#ffmpeg", "-c", "ffmpeg", "-v", "error", "-i", path, "-f", "f32le", "-ac", "1", "-"], capture_output=True)
cases.append({"name": name, "crc": zlib.crc32(data), "opusdec": pcm, "opusinfo": ok,
"ffmpeg": ff.returncode == 0 and len(ff.stderr) == 0, "ffmpegFrames": len(ff.stdout) // 4,
"comments": comments})
ctx.emit("opus_celt", cases)
finally:
shutil.rmtree(d, ignore_errors=True)