tests/audio: comments: specs only
This commit is contained in:
1 parent
75ddfb4068
commit
0eec255bfb
30 files changed
+66
-244
No files matched your search
+4
-17
@@ -1,8 +1,5 @@
|
||||
-- audio/mp3 tests: every fixture against its minimp3 reference decode (exact length, SNR > 90 dB on windows, block
|
||||
-- energies) and against ffmpeg (length, SNR > 75 dB), lame-written streams against ffmpeg; chunked reads, reads into
|
||||
-- a caller buffer, sample-accurate seeking; robustness (garbage, corruption, truncation, mono / stereo switches, API
|
||||
-- misuse); ID3v1 / v2.2 / 2.3 / 2.4 and APE tags; the contract, sniff, decode to Audio, the fuzz no-throw pass.
|
||||
-- Ported from mp3-luau tests/decode.luau, robust.luau, tags.luau. Fixtures: tools/fixtures/mp3.py.
|
||||
-- audio/mp3 tests: every fixture against its minimp3 reference decode (SNR > 90 dB) and ffmpeg (SNR > 75 dB).
|
||||
-- Fixtures: tools/fixtures/mp3.py.
|
||||
local T = require("@tests/T")
|
||||
local Mp3 = require("@rosetta/audio/mp3")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -78,13 +75,11 @@ end
|
||||
|
||||
local rand = T.rng(12345)
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
t:eq(Mp3.name, "mp3", "name")
|
||||
t:eq(Mp3.category, "audio", "category")
|
||||
t:check(table.find(Mp3.extensions, "mp3") ~= nil and table.find(Mp3.extensions, "mp2") ~= nil, "extensions")
|
||||
t:check(Mp3.caps.decode and Mp3.caps.encode and Mp3.open ~= nil, "caps") -- encode: ws-audio (tests/audio/mp3_encode.luau)
|
||||
t:check(Mp3.caps.decode and Mp3.caps.encode and Mp3.open ~= nil, "caps")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode vs references
|
||||
for _, c in Cases do
|
||||
local name = c.name
|
||||
local buf = buffer.fromstring(c.data)
|
||||
@@ -105,7 +100,6 @@ for _, c in Cases do
|
||||
t:eq(dec.frames, c.ffFrames, name .. ": frames vs ffmpeg")
|
||||
t:check(dec.bitrate > 0, name .. ": bitrate")
|
||||
|
||||
-- whole decode in chunks of varied sizes
|
||||
local all = buffer.create(dec.frames * ch * 4)
|
||||
local total = 0
|
||||
while true do
|
||||
@@ -184,7 +178,6 @@ for _, c in Cases do
|
||||
local pcm0, n3 = dec:read(256)
|
||||
t:check(n3 == 256 and maxDiff(pcm0, 0, all, 0, 256 * ch) == 0, name .. ": seek back to the start")
|
||||
|
||||
-- decode to Audio, also from a sub-range of a bigger buffer
|
||||
local big = buffer.create(buffer.len(buf) + 17)
|
||||
buffer.copy(big, 9, buf)
|
||||
local a, aerr = Mp3.decode(Bytes.reader(big, 9, buffer.len(buf)))
|
||||
@@ -196,7 +189,6 @@ for _, c in Cases do
|
||||
t:note("%-20s L%d MPEG-%s %5d Hz %d ch %6d frames %3d kbps SNR minimp3 %s, ffmpeg %.1f dB", name, dec.layer, tostring(dec.version), dec.sampleRate, ch, dec.frames, dec.bitrate // 1000, if ref then string.format("%.1f", worst) else "-", worstFF)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ robustness
|
||||
local function concat(...: buffer): buffer
|
||||
local n = 0
|
||||
for _, b in { ... } do
|
||||
@@ -215,7 +207,6 @@ local function slice(b: buffer, i: number, j: number): buffer
|
||||
buffer.copy(out, 0, b, i, j - i)
|
||||
return out
|
||||
end
|
||||
-- decodes everything; checks every sample is finite; returns pcm, frames, decoder
|
||||
local function decodeAll(b: buffer, label: string): (buffer?, number, any)
|
||||
local ok, dec, err = pcall(open, b)
|
||||
t:check(ok, label .. ": open does not throw (" .. tostring(dec) .. ")")
|
||||
@@ -303,7 +294,6 @@ do
|
||||
end
|
||||
t:check(same, "switch: mono part duplicated")
|
||||
end
|
||||
-- bad input and API misuse
|
||||
do
|
||||
local d, err = open(buffer.create(0))
|
||||
t:check(d == nil and Err.is(err) and err.code == Err.CORRUPT, "empty buffer")
|
||||
@@ -333,7 +323,6 @@ do
|
||||
t:eq(Mp3.sniff(Bytes.reader(buffer.create(0))), 0, "sniff nothing")
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ tags
|
||||
local function eq(a: any, b: any, label: string)
|
||||
t:eq(a, b, label)
|
||||
end
|
||||
@@ -478,7 +467,6 @@ do
|
||||
t:check(dec == nil or dec.frames <= plain.frames, "truncated tag")
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ through the api
|
||||
do
|
||||
local F = require("@rosetta")
|
||||
local data = byName.l3_tags.data
|
||||
@@ -487,11 +475,10 @@ do
|
||||
t:check(a and a.kind == "audio" and a.frames == 22050 and a.tags.title == "Test Title", "F.audio.load: " .. tostring(err))
|
||||
local dec = F.audio.open(data)
|
||||
t:check(dec and dec.sampleRate == 44100 and dec.frames == 22050, "F.audio.open")
|
||||
local saved, serr = F.save(a, nil, { format = "mp3" }) -- the layer III encoder (ws-audio)
|
||||
local saved, serr = F.save(a, nil, { format = "mp3" })
|
||||
t:check(saved and F.audio.load(saved).sampleRate == 44100, "F.save mp3: " .. tostring(serr))
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for _, name in { "l3_cbr32_mono", "l3_mpeg2_22k", "l3_mpeg25_8k", "l2_64_mono", "l2_mpeg2_24k", "l3_tags", "lame_cbr64_mono_22k" } do
|
||||
|
||||
Reference in new issue
Block a user