tests/audio: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:51:26 -05:00
1 parent 75ddfb4068
commit 0eec255bfb
30 files changed
+66 -244

No files matched your search

+3 -18
View File
@@ -1,9 +1,5 @@
-- audio/opus tests: every fixture (opusenc / ffmpeg libopus: CELT frame sizes and bitrates, SILK NB / MB / WB, hybrid,
-- mode transitions, 5.1 multistream, a long tagged file) through open / read against opusdec --float (frame counts,
-- SNR per fixture), CELT-only and SILK-only decoding with the private decoders alone, SILK packet loss concealment,
-- tags, seeking, the stereo downmix, decode() to an Audio, the contract, sniff, error codes, random / bit-flipped
-- packets through the packet decoder, and the fuzz no-throw pass over whole files.
-- Ported from opus-luau tests/opus.luau, celt.luau, silk.luau, fuzz.luau. Fixtures: tools/fixtures/opus.py.
-- audio/opus tests: every fixture (opusenc / ffmpeg libopus) against opusdec --float (frame counts, SNR per fixture).
-- Fixtures: tools/fixtures/opus.py.
local T = require("@tests/T")
local Opus = require("@rosetta/audio/opus")
local Packet = require("@rosetta/codecs/audio/Opus/Packet")
@@ -58,7 +54,6 @@ do
Pcm.reorder(fx.ref, 0, buffer.len(fx.ref) // 24, 6, Pcm.WAVE_FROM_VORBIS[6])
end
-- SNR in dB of f32 samples against a reference over n samples; returns snr, max abs error
local function snr(out: buffer, ref: buffer, n: number, outOff: number?, refOff: number?): (number, number)
local oo, ro = outOff or 0, refOff or 0
local sig, err, maxe = 0, 0, 0
@@ -77,7 +72,6 @@ local function snr(out: buffer, ref: buffer, n: number, outOff: number?, refOff:
return 10 * math.log10(sig / err), maxe
end
-- the packets of the first stream: { data, offset, size }
local function packets(buf: buffer): { any }
local d = Ogg.open(buf)
local out = {}
@@ -87,7 +81,6 @@ local function packets(buf: buffer): { any }
return out
end
-- ------------------------------------------------------------------------------------------------ contract
t:eq(Opus.name, "opus", "name")
t:eq(Opus.category, "audio", "category")
t:check(Opus.caps.decode and Opus.caps.encode and Opus.open ~= nil and Opus.decode ~= nil and Opus.encode ~= nil, "caps (the CELT encoder: tests/audio/opus_encode.luau)")
@@ -95,7 +88,6 @@ t:eq(Opus.sniff(Bytes.reader(FX.celt_st_128.data)), 1, "sniff an Opus file")
t:eq(Opus.sniff(Bytes.reader(buffer.fromstring("OggS" .. string.rep("\0", 40)))), 0, "sniff another Ogg")
t:eq(Opus.sniff(Bytes.reader(buffer.create(0))), 0, "sniff nothing")
-- ------------------------------------------------------------------------------------------------ open / read vs opusdec
-- name, minimum SNR (dB). CELT is float-exact (> 130 dB in practice), SILK bit-exact; hybrid / transitions mix both.
local cases = {
{ "celt_st_128", 100 }, { "celt_st_32", 100 }, { "celt_st_64", 100 }, { "celt_st_256", 100 },
@@ -134,7 +126,6 @@ for _, case in cases do
t:check(math.abs(dec:position() - dec.duration) < 1e-9, name .. ": position at end")
end
-- read into a caller buffer, decode() to an Audio, a sub-range Reader
do
local fx = FX.hybrid_st
local dec = Opus.open(Bytes.reader(fx.data))
@@ -151,7 +142,6 @@ do
t:eq(a.meta.source.format, "opus", "decode: meta.source")
end
-- ------------------------------------------------------------------------------------------------ tags, seeking
do
local dec = Opus.open(Bytes.reader(FX.long_128.data))
t:eq(dec.tags.title, "Long Test", "tags: title")
@@ -203,7 +193,6 @@ do
t:check(db > 100, string.format("downmix SNR %.1f", db))
end
-- ------------------------------------------------------------------------------------------------ CELT alone
do
local endbands = { [Packet.BW_NB] = 13, [Packet.BW_MB] = 17, [Packet.BW_WB] = 17, [Packet.BW_SWB] = 19, [Packet.BW_FB] = 21 }
for _, name in { "celt_st_128", "celt_st_32", "celt_st_64", "celt_st_256", "celt_mono_64", "celt_fs2_5", "celt_fs5", "celt_fs10", "celt_fs40", "celt_fs60", "ff_cbr", "ff_lowdelay" } do
@@ -243,7 +232,6 @@ do
end
end
-- ------------------------------------------------------------------------------------------------ SILK alone
do
local rates = { [Packet.BW_NB] = 8000, [Packet.BW_MB] = 12000, [Packet.BW_WB] = 16000 }
local function decodeSilk(name: string, hybridOk: boolean?, lose: boolean?): ({ number }, number, number, number)
@@ -323,7 +311,6 @@ do
end
end
-- ------------------------------------------------------------------------------------------------ errors
do
local d, err = Opus.open(Bytes.reader(buffer.fromstring("not an ogg file at all")))
t:check(d == nil and err and err.code == Err.CORRUPT, "garbage is CORRUPT: " .. tostring(err))
@@ -371,8 +358,7 @@ do
end
end
-- ------------------------------------------------------------------------------------------------ packet fuzz
-- random packets (every TOC config, random payloads) and bit-flipped real packets: never throw, output finite
-- random packets (every TOC config) and bit-flipped real packets: never throw, output finite
do
local rand = T.rng(987654321)
local pcm = table.create(5760 * 2, 0)
@@ -431,7 +417,6 @@ do
t:note("packet fuzz: %d packets decoded, %d rejected", decoded, rejected)
end
-- ------------------------------------------------------------------------------------------------ fuzz (whole files)
do
local samples = {}
for _, name in { "hybrid_fb", "silk_nb", "celt_fs5" } do