diff --git a/tests/audio/_adpcm.luau b/tests/audio/_adpcm.luau index 7561c0d..a45ba3d 100644 --- a/tests/audio/_adpcm.luau +++ b/tests/audio/_adpcm.luau @@ -1,11 +1,8 @@ --- tests/audio/_adpcm: shared checks of the ADPCM game-audio formats (adx, vag, brstm): a file against the reference --- decoder's s16le output, bit-exact, through decode() and through open() with seeks (forward into unvisited packets, --- back, the end), loop points; the SNR of an encoder's round trip. +-- tests/audio/_adpcm: shared checks of adx, vag, brstm: bit-exact against the reference decoder's s16le output. local Bytes = require("@rosetta/core/Bytes") local H = {} --- same(f32 buffer, s16le reference buffer, first reference sample, count) -> true when every sample is equal function H.same(out: buffer, ref: buffer, from: number, count: number): boolean for i = 0, count - 1 do if buffer.readf32(out, i * 4) * 32768 ~= buffer.readi16(ref, (from + i) * 2) then @@ -26,7 +23,6 @@ function H.snr(x: buffer, y: buffer, count: number): number return if err == 0 then 200 else 10 * math.log10(sig / err) end --- check(t, Fmt, c, opts?): c = { name, data, rate, ch, frames?, ref, loopStart?, loopEnd? } function H.check(t: any, Fmt: any, c: any, opts: any?) local ref = buffer.fromstring(c.ref) local frames = buffer.len(ref) // (2 * c.ch) diff --git a/tests/audio/_encode_cases.luau b/tests/audio/_encode_cases.luau index 0869ec6..4563859 100644 --- a/tests/audio/_encode_cases.luau +++ b/tests/audio/_encode_cases.luau @@ -1,5 +1,4 @@ --- tests/audio/_encode_cases: the files our ALAC / CAF writers produce for the reference check (tools/fixtures/m4a.py --- runs tools/fixtures/_m4a_encode.luau over them; tests/audio/m4a.luau and caf.luau re-encode and compare). +-- tests/audio/_encode_cases: the ALAC / CAF writer inputs of the reference check (tools/fixtures/m4a.py). return { { name = "ours_alac16_stereo", container = "m4a", rate = 44100, frames = 4096 * 3 + 1234, channels = 2, bits = 16, seed = 1, tags = { title = "Our Title \u{e9}", artist = "rosetta", album = "Tests", track = "5", tracktotal = "10", date = "2026", genre = "Test", comment = "round trip" } }, { name = "ours_alac16_mono", container = "m4a", rate = 22050, frames = 5000, channels = 1, bits = 16, seed = 2 }, diff --git a/tests/audio/_lossless.luau b/tests/audio/_lossless.luau index d44260f..85f0d52 100644 --- a/tests/audio/_lossless.luau +++ b/tests/audio/_lossless.luau @@ -1,8 +1,5 @@ --- Shared checks of the lossless audio format tests (wavpack, ape, tta): every fixture opened, decoded bit-exact --- against the reference decoder's samples (readInt for integer streams, the f32 bytes for float ones), f32 scaling --- and output reuse, seeking to sample-accurate positions, reading past the end, tags, sniff. A fixture is a table --- { name, data, rate, channels, bits, float, frames, crc, tags?, partial? } (partial: a cut file whose decode stops --- with an error; the reference decoded its first `frames` frames). +-- Shared checks of the lossless audio format tests (wavpack, ape, tta): bit-exact against the reference decoder. +-- partial: a cut file whose decode stops with an error; the reference decoded its first `frames` frames. local T = require("@tests/T") local Bytes = require("@rosetta/core/Bytes") local Crc32 = require("@rosetta/core/Crc32") @@ -20,7 +17,6 @@ local function open(mod: any, b: any, opts: any?): (any, any) end L.open = open --- all(dec, fx) -> crc of every sample read (i32 for integer streams, f32 bytes for floats), frames, the values function L.all(dec: any, fx: any): (number, number, { number }) local ch = dec.channels local vals = table.create(fx.frames * ch, 0) @@ -52,7 +48,6 @@ function L.all(dec: any, fx: any): (number, number, { number }) return crc, n, vals end --- cases(t, mod, cases, optsOf?) -> seeks checked: the per-fixture checks; optsOf(fx) gives the open options function L.cases(t: any, mod: any, cases: { any }, optsOf: ((any) -> any)?): number local seekChecks = 0 for _, fx in cases do @@ -73,7 +68,6 @@ function L.cases(t: any, mod: any, cases: { any }, optsOf: ((any) -> any)?): num end t:eq(n, fx.frames, name .. ": decoded frames") t:eq(crc, fx.crc, name .. ": samples identical to the reference decoder") - -- f32 scaling, output reuse local ch = dec.channels dec:seek(0) local reuse = buffer.create(100 * ch * 4) @@ -120,7 +114,7 @@ function L.cases(t: any, mod: any, cases: { any }, optsOf: ((any) -> any)?): num return seekChecks end --- subrange(t, mod, fx, depth) : decode() from a Reader over a sub-range equals read(); meta.source +-- decode() from a Reader over a sub-range equals read() function L.subrange(t: any, mod: any, fx: any, format: string) local name = fx.name local big = buffer.create(#fx.data + 13) diff --git a/tests/audio/_opus_cases.luau b/tests/audio/_opus_cases.luau index 5cade81..5f913bf 100644 --- a/tests/audio/_opus_cases.luau +++ b/tests/audio/_opus_cases.luau @@ -1,6 +1,4 @@ --- tests/audio/_opus_cases: the inputs of the CELT encoder reference check (tools/fixtures/opus_celt.py runs --- tools/fixtures/_opus_encode.luau over them; tests/audio/opus_encode.luau re-encodes and compares): a deterministic --- music-like signal (chord + vibrato + chirp + clicks + a silent stretch) at a given rate / channel count. +-- tests/audio/_opus_cases: the CELT encoder reference check inputs (tools/fixtures/opus_celt.py). local Types = require("@rosetta/Types") local Cases = {} diff --git a/tests/audio/_signal.luau b/tests/audio/_signal.luau index 27b9fd5..eb206f8 100644 --- a/tests/audio/_signal.luau +++ b/tests/audio/_signal.luau @@ -1,6 +1,4 @@ --- tests/audio/_signal: the deterministic integer test signal of tools/fixtures/_m4a_signal.py (the same numbers), as --- an interleaved integer array and as a Types.Audio (f32, exact for up to 24 bits). Used by the m4a / caf tests and the --- fixture-time encoder runs (tools/fixtures/_m4a_encode.luau). +-- tests/audio/_signal: the deterministic integer test signal of tools/fixtures/_m4a_signal.py (the same numbers). local Types = require("@rosetta/Types") local Signal = {} diff --git a/tests/audio/aac.luau b/tests/audio/aac.luau index 0772b88..593dd50 100644 --- a/tests/audio/aac.luau +++ b/tests/audio/aac.luau @@ -1,6 +1,4 @@ --- audio/aac tests: ADTS streams from ffmpeg and fdkaac (stereo, mono 32 kHz) against ffmpeg's float decode (SNR, --- length); an HE-AAC ADTS stream plays its core; a leading ID3v2 tag (skipped, text frames as tags) and garbage before --- the first frame (resync); a truncated last frame; streaming + seek; sniff; errors; the fuzz no-throw pass. +-- audio/aac tests: ADTS streams from ffmpeg and fdkaac against ffmpeg's float decode (SNR, length). -- Fixtures: tools/fixtures/m4a.py. local T = require("@tests/T") local AacF = require("@rosetta/audio/aac") @@ -49,7 +47,6 @@ for _, c in Fx do t:note("%s: %d ch %d Hz, %d frames, SNR %.1f dB vs ffmpeg", c.name, c.channels, c.rate, a.frames, s) end --- HE-AAC ADTS: the core for _, c in He do if string.sub(c.name, -4) == ".aac" then local a, err = AacF.decode(reader(c.data)) @@ -57,7 +54,6 @@ for _, c in He do end end --- ID3v2 in front + garbage, truncated tail do local function frame(id: string, text: string): string local body = "\3" .. text @@ -77,7 +73,6 @@ do t:check(cut and cut.frames == first.frames - 1024, "truncated last frame dropped") end --- streaming + seek do local whole = AacF.decode(reader(first.data)) :: any local dec = AacF.open(reader(first.data)) :: any @@ -94,14 +89,12 @@ do end end --- errors do t:eq(AacF.sniff(reader("RIFF....WAVE")), 0, "sniff a WAV") local _, e = AacF.decode(reader(string.rep("\0", 100))) t:check(e and e.code == Err.CORRUPT, "no frames: " .. tostring(e)) end --- fuzz do local samples = {} for _, c in Fx do diff --git a/tests/audio/ac3.luau b/tests/audio/ac3.luau index 6dc0c96..1b48e66 100644 --- a/tests/audio/ac3.luau +++ b/tests/audio/ac3.luau @@ -1,9 +1,6 @@ --- audio/ac3 tests: AC-3 streams from ffmpeg (every acmod with and without LFE, coupling incl. cplbegf 0, rematrixing, --- 32 / 44.1 / 48 kHz) and aften (block switching, 1+1 dual mono, dynamic range profiles, the alternate BSI) against --- ffmpeg's float decode, or liba52's for block-switched streams (SNR, max difference; dithflags cleared in the --- fixture step so both sides decode the same numbers); dynamic range on; the encoders' dithered originals; AC-3 tracks --- of MKV / MP4 / MPEG-TS / AVI through the api's audio hook; exact seeking; resync and truncation; error codes (E-AC-3, --- CRC); the fuzz no-throw pass. Fixtures: tools/fixtures/ac3.py. +-- audio/ac3 tests: AC-3 streams from ffmpeg and aften against ffmpeg's float decode, or liba52's for block-switched +-- streams (dithflags cleared in the fixture step so both sides decode the same numbers). +-- Fixtures: tools/fixtures/ac3.py. local T = require("@tests/T") local F = require("@rosetta") local Ac3F = require("@rosetta/audio/ac3") @@ -19,7 +16,6 @@ local function reader(s: string): Bytes.Reader return Bytes.reader(buffer.fromstring(s)) end --- SNR (dB) and the largest difference of interleaved f32 `got` against the f32le reference `ref` local function compare(got: buffer, ref: string, count: number): (number, number) local rb = buffer.fromstring(ref) local n = math.min(count, #ref // 4, buffer.len(got) // 4) @@ -104,7 +100,6 @@ do end end --- resync over garbage, a truncated last frame, the raw codec API do local c = byName.stereo_44k local a = Ac3F.decode(reader("\0\11\119garbage" .. c.data)) :: any @@ -118,7 +113,6 @@ do t:check(n == 1536 and d.channels == 2 and #d.pcm == 1536 * 2, "decoder: one syncframe") end --- errors do local c = byName.stereo_44k.data t:eq(Ac3F.sniff(reader("RIFF....WAVE")), 0, "sniff a WAV") @@ -138,7 +132,7 @@ do t:check(e and e.code == Err.LIMIT, "maxFrames: " .. tostring(e)) end --- fuzz (without the CRC check, so mutations reach the decoder) +-- fuzz without the CRC check, so mutations reach the decoder do local samples = {} for _, c in Fx do diff --git a/tests/audio/adpcm.luau b/tests/audio/adpcm.luau index 8d99537..593ca86 100644 --- a/tests/audio/adpcm.luau +++ b/tests/audio/adpcm.luau @@ -1,7 +1,5 @@ --- audio/adpcm tests: headerless streams (IMA nibbles, IMA WAV / MS blocks, Apple ima4, PS-ADPCM) decoded with the --- layout in the options, bit-exact against ffmpeg / vgmstream (tools/fixtures/adpcm.py), with seeking; our encoder's --- streams (ima, ms, ima_wav) as ffmpeg decodes them (wrapped in KVAG / WAV in the fixture step) against our decode of --- the same bytes, and their quality; options and errors; the api by format name; the fuzz pass. +-- audio/adpcm tests: headerless ADPCM streams bit-exact against ffmpeg / vgmstream; our encoder's via ffmpeg. +-- Fixtures: tools/fixtures/adpcm.py. local T = require("@tests/T") local Raw = require("@rosetta/audio/adpcm") local Bytes = require("@rosetta/core/Bytes") @@ -47,7 +45,6 @@ for _, c in Cases do end t:note("%d raw streams bit-exact with ffmpeg / vgmstream", #Cases) --- ------------------------------------------------------------------------------------------------ encoder local function snr(x: buffer, y: buffer, count: number): number local sig, err = 0, 0 for i = 0, count - 1 do @@ -100,7 +97,6 @@ do t:check(lo.frames == 6 and buffer.tostring(lo.samples) == buffer.tostring(hi.samples), "nibble order") end --- ------------------------------------------------------------------------------------------------ api do local c = Cases[1] local a, err = F.audio.load(c.data, { format = "adpcm", codec = c.codec, sampleRate = c.rate, channels = c.ch }) @@ -110,7 +106,6 @@ do t:check(out ~= nil and buffer.len(out) % 256 == 0, "F.save adpcm") end --- ------------------------------------------------------------------------------------------------ fuzz local kinds = { "ima", "ima_wav", "ms", "ima_qt", "psx" } local k = 0 t:fuzz("open + read + seek", function(b: buffer) diff --git a/tests/audio/adx.luau b/tests/audio/adx.luau index 2d1852b..1542bd2 100644 --- a/tests/audio/adx.luau +++ b/tests/audio/adx.luau @@ -1,6 +1,5 @@ --- audio/adx tests: ffmpeg's ADX files (version 3) and a version 4 file with history and loop points, bit-exact with --- vgmstream (tools/fixtures/adx.py) through decode and open with seeks; our encoder's files as vgmstream decodes them --- (equal to our decode, loops reported) and their quality; header errors; the api; the fuzz pass. +-- audio/adx tests: ffmpeg's ADX files and a version 4 file with loop points, bit-exact with vgmstream. +-- Fixtures: tools/fixtures/adx.py. local T = require("@tests/T") local Adx = require("@rosetta/audio/adx") local Bytes = require("@rosetta/core/Bytes") @@ -24,7 +23,6 @@ for _, c in Cases do end t:note("%d files bit-exact with vgmstream", #Cases) --- ------------------------------------------------------------------------------------------------ encoder local audio = Types.Audio.new(Sig.rate, Sig.channels, Sig.frames) buffer.writestring(audio.samples, 0, Sig.data) for _, c in Ours do @@ -49,7 +47,6 @@ do t:check(e3 and e3.code == Err.ARG, "bad cutoff") end --- ------------------------------------------------------------------------------------------------ errors do local base = Cases[1].data local function patch(at: number, bytes: string): buffer diff --git a/tests/audio/aiff.luau b/tests/audio/aiff.luau index 956e1af..39387d0 100644 --- a/tests/audio/aiff.luau +++ b/tests/audio/aiff.luau @@ -1,6 +1,4 @@ --- audio/aiff tests: files written by ffmpeg and sox in every sample format (AIFF 8 / 12 / 16 / 24 / 32-bit, AIFF-C --- sowt / fl32 / fl64 / ulaw / alaw / ima4, 6 channels, text chunks) against ffmpeg's decode; streaming reads and seeks; --- our encoder's output for every sample format decoded by ffmpeg (fixture step) and by us; errors; fuzz. +-- audio/aiff tests: AIFF / AIFF-C files written by ffmpeg and sox against ffmpeg's decode; our encoder's via ffmpeg. -- Fixtures: tools/fixtures/aiff.py. local T = require("@tests/T") local Aiff = require("@rosetta/audio/aiff") @@ -16,7 +14,6 @@ local t = T.suite("aiff") local function reader(s: string): Bytes.Reader return Bytes.reader(buffer.fromstring(s)) end --- max |a - b| over n f32 samples (a at byte ao, b at byte bo) local function maxDiff(a: buffer, ao: number, b: buffer, bo: number, n: number): number local m = 0 for i = 0, n - 1 do @@ -28,12 +25,10 @@ local function maxDiff(a: buffer, ao: number, b: buffer, bo: number, n: number): return m end --- the contract t:eq(Aiff.name, "aiff", "name") t:eq(Aiff.category, "audio", "category") t:check(Aiff.caps.decode and Aiff.caps.encode and table.find(Aiff.extensions, "aif") ~= nil, "caps / extensions") --- reference files: decode, stream, seek for _, c in Cases do local a, err = Aiff.decode(reader(c.data)) t:check(a, c.name .. ": " .. tostring(err)) @@ -63,7 +58,6 @@ for _, c in Cases do end t:note("%d reference files match ffmpeg", #Cases) --- details of particular files local function case(name: string): any for _, c in Cases do if c.name == name then @@ -86,7 +80,6 @@ do t:check(s12.meta.source.bitDepth == 12 and maxDiff(s12.samples, 0, buffer.fromstring(s16.ref), 0, s16.frames * 2) < 1e-6, "12-bit sample size") local sw = Aiff.info(reader(case("ffmpeg-sowt").data)) t:check(sw and sw.compression == "sowt" and sw.format == "s16le", "info: sowt") - -- inside a bigger buffer local c = case("ffmpeg-s16be") local big = buffer.create(#c.data + 9) buffer.writestring(big, 5, c.data) @@ -114,7 +107,6 @@ for _, e in Enc do end t:note("%d encoder outputs read back by ffmpeg and by us", #Enc) --- encoder: tags, odd sizes, errors do local a = Types.Audio.new(44100, 1, 3) buffer.writef32(a.samples, 0, 0.5) @@ -143,7 +135,6 @@ do t:eq(Aiff.sniff(reader("")), 0, "sniff nothing") end --- errors do local _, e = Aiff.decode(reader("FORM\0\0\0\4WAVE")) t:check(e and e.code == Err.CORRUPT, "wrong FORM type: " .. tostring(e)) @@ -160,7 +151,6 @@ do t:check(e4 and e4.code == Err.LIMIT, "maxFrames: LIMIT") end --- fuzz do local samples = {} for i, c in Cases do diff --git a/tests/audio/ape.luau b/tests/audio/ape.luau index 79c77a9..02be12e 100644 --- a/tests/audio/ape.luau +++ b/tests/audio/ape.luau @@ -1,8 +1,5 @@ --- audio/ape tests: every fixture from tools/fixtures/ape.py (mac -c1000 .. -c5000, 8 - 32-bit int and 32-bit float, --- 1 - 8 channels, special frames (silence, pseudo stereo), odd rates and lengths, a second frame, APEv2 tags, the FATE --- sample of an older 3.99 encoder cut mid-frame) decoded bit-exact against `mac -d`; seeking; f32 scaling and output --- reuse; decode() from a sub-range Reader; an ID3v2 tag in front; the header facts; sniff; the api; a damaged frame --- (CRC); the fuzz pass. Fixtures: tools/fixtures/ape.py. +-- audio/ape tests: tools/fixtures/ape.py's files (mac -c1000 .. -c5000, a FATE 3.99 sample) bit-exact against `mac -d`. +-- Fixtures: tools/fixtures/ape.py. local T = require("@tests/T") local Ape = require("@rosetta/audio/ape") local Bytes = require("@rosetta/core/Bytes") @@ -30,7 +27,6 @@ for _, name in { "s16_c2000", "tags", "f32", "ch6" } do L.subrange(t, Ape, byName[name], "ape") end --- header facts do local d = open(byName.s16_c5000.data) t:eq(d.level, "insane", "level") @@ -50,7 +46,6 @@ do t:check(dec and (L.all(dec, fx)) == fx.crc, "ID3v2 in front") end --- the api do local fx = byName.s16_c2000 local _ = fx @@ -79,7 +74,6 @@ do t:eq(Ape.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff RIFF") end --- the fuzz pass local samples = {} for _, name in { "s16_c2000", "s16_c4000", "mono", "s24", "s32", "f32", "ch6", "silence", "pseudo_stereo" } do table.insert(samples, buffer.fromstring(byName[name].data)) diff --git a/tests/audio/au.luau b/tests/audio/au.luau index 7de870c..24ef135 100644 --- a/tests/audio/au.luau +++ b/tests/audio/au.luau @@ -1,6 +1,5 @@ --- audio/au tests: files written by ffmpeg and sox in every encoding (8 / 16 / 24 / 32-bit, float, double, mu-law, --- A-law, an annotation) against ffmpeg's decode; streaming reads and seeks; our encoder's output for every encoding --- decoded by ffmpeg (fixture step) and by us; an unknown data size; errors; fuzz. Fixtures: tools/fixtures/au.py. +-- audio/au tests: files written by ffmpeg and sox against ffmpeg's decode; our encoder's output via ffmpeg. +-- Fixtures: tools/fixtures/au.py. local T = require("@tests/T") local Au = require("@rosetta/audio/au") local Bytes = require("@rosetta/core/Bytes") diff --git a/tests/audio/brstm.luau b/tests/audio/brstm.luau index 0304901..ca7aa33 100644 --- a/tests/audio/brstm.luau +++ b/tests/audio/brstm.luau @@ -1,6 +1,5 @@ --- audio/brstm tests: BRSTM / BCSTM / BFSTM files (DSP ADPCM, PCM16, PCM8; big- and little-endian; loops) from our --- Python writer, bit-exact with vgmstream (tools/fixtures/brstm.py) through decode and open with seeks (forward seeks --- start from the ADPC / SEEK history table); errors; the api; the fuzz pass. +-- audio/brstm tests: BRSTM / BCSTM / BFSTM files from our Python writer, bit-exact with vgmstream (forward seeks +-- start from the ADPC / SEEK history table). Fixtures: tools/fixtures/brstm.py. local T = require("@tests/T") local Brstm = require("@rosetta/audio/brstm") local Bytes = require("@rosetta/core/Bytes") diff --git a/tests/audio/caf.luau b/tests/audio/caf.luau index 69b938d..2cec86f 100644 --- a/tests/audio/caf.luau +++ b/tests/audio/caf.luau @@ -1,7 +1,5 @@ --- audio/caf tests: ALAC CAF from ffmpeg bit-exact; AAC CAF (ffmpeg's ADTS frames wrapped by the fixture) against --- ffmpeg's float decode; our CAF writer (PCM 16 / 24-bit, ALAC; re-encoded here and compared with the bytes ffmpeg --- decoded bit-exactly); PCM layouts (little / big endian, float) through our writer + a hand-built header; info tags; --- seek; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/m4a.py. +-- audio/caf tests: ALAC CAF from ffmpeg bit-exact; AAC CAF against ffmpeg's float decode; our writer's bytes. +-- Fixtures: tools/fixtures/m4a.py. local T = require("@tests/T") local Caf = require("@rosetta/audio/caf") local Bytes = require("@rosetta/core/Bytes") @@ -128,7 +126,6 @@ do t:check(le and math.abs(buffer.readf32(le.samples, 4) - 0.5) < 1e-7 and math.abs(buffer.readf32(le.samples, 16) + 1) < 1e-7, "24-bit LE values") end --- seek do local c = Alac[#Alac] local whole = Caf.decode(reader(c.data)) :: any @@ -145,7 +142,6 @@ do end end --- errors do t:eq(Caf.sniff(reader("caff\0\2\0\0")), 0, "sniff: wrong version") local _, e = Caf.decode(reader("caff\0\1\0\0")) @@ -154,7 +150,6 @@ do t:check(e2 and e2.code == Err.ARG, "bad codec: " .. tostring(e2)) end --- fuzz do local samples = {} for _, c in Alac do diff --git a/tests/audio/flac.luau b/tests/audio/flac.luau index ba87253..354b166 100644 --- a/tests/audio/flac.luau +++ b/tests/audio/flac.luau @@ -1,8 +1,5 @@ --- audio/flac tests: every fixture from tools/fixtures/flac.py (flac 0-8, 4-32 bits, 1-6 channels, odd rates and block --- sizes, LPC order 32, wasted bits, every stereo mode, ffmpeg's encoder, Ogg FLAC, ID3v2 in front) decoded bit-exact --- against `flac -d`; sample-accurate seeking; f32 scaling and output reuse; decode() to an Audio from a sub-range --- Reader; tags and pictures; the length from the last frame; sniff; the api; damaged frames skipped; the fuzz pass. --- Ported from flac-luau tests/flac.luau. Fixtures: tools/fixtures/flac.py. +-- audio/flac tests: tools/fixtures/flac.py's files (flac 0-8, ffmpeg's encoder, Ogg FLAC) bit-exact against `flac -d`. +-- Fixtures: tools/fixtures/flac.py. local T = require("@tests/T") local VorbisComment = require("@rosetta/codecs/audio/VorbisComment") local Flac = require("@rosetta/audio/flac") @@ -23,7 +20,7 @@ for _, c in Cases do end t:eq(Flac.name, "flac", "name") -t:check(Flac.caps.decode and Flac.caps.encode, "caps") -- encode: ws-audio (tests/audio/flac_encode.luau) +t:check(Flac.caps.decode and Flac.caps.encode, "caps") local seekChecks = 0 for _, fx in Cases do @@ -53,7 +50,6 @@ for _, fx in Cases do t:eq(n, fx.frames, name .. ": decoded frames") t:eq(crc, fx.crc, name .. ": samples identical to flac -d") t:eq(select(2, dec:position()), fx.frames, name .. ": position at end") - -- f32 scaling, output reuse dec:seekSample(0) local reuse = buffer.create(100 * ch * 4) local f, gotf = dec:read(100, reuse) @@ -66,7 +62,6 @@ for _, fx in Cases do end end t:eq(bad, 0, name .. ": f32 samples") - -- seeking local rand = T.rng(99) local targets = { 0, 1, fx.frames - 1, fx.frames // 2, 4096, 4095, 4097, 1152, 1151 } for _ = 1, 12 do @@ -100,7 +95,6 @@ for _, fx in Cases do end t:note("%d fixtures bit-exact against flac -d, %d seeks", #Cases, seekChecks) --- decode() from a sub-range Reader for _, name in { "s16_l5", "ogg_s16", "id3", "s24_96k" } do local fx = byName[name] local big = buffer.create(#fx.data + 13) @@ -113,7 +107,6 @@ for _, name in { "s16_l5", "ogg_s16", "id3", "s24_96k" } do t:eq(a.meta.source.bitDepth, fx.bps, name .. ": meta.source") end --- tags and pictures do local dec = open(byName.s16_noseek.data) t:check(#dec.pictures == 1 and dec.pictures[1].mime == "image/png" and dec.pictures[1].width == 1, "picture") @@ -142,7 +135,6 @@ for _, name in { "s16_l5", "varblock", "bs17" } do t:check(n == fx.frames and crc == fx.crc, name .. ": decode without total length") end --- sniff, errors, the api do t:eq(Flac.sniff(Bytes.reader(buffer.fromstring("ID3\4\0\0\0\0\0\2xxfLaC"))), 1, "sniff ID3 + fLaC") t:eq(Flac.sniff(Bytes.reader(buffer.fromstring("ID3\4\0\0\0\0\0\2xx\255\251"))), 0, "sniff ID3 + mp3") @@ -157,7 +149,7 @@ do t:check(a and a.frames == fx.frames, "F.audio.load") local d = F.audio.open(byName.s16_l3.data) t:check(d and d.frames == byName.s16_l3.frames, "F.audio.open") - local saved, se = F.save(a, nil, { format = "flac" }) -- the encoder (ws-audio) + local saved, se = F.save(a, nil, { format = "flac" }) t:check(saved and F.audio.load(saved).frames == fx.frames, "F.save flac: " .. tostring(se)) end @@ -178,7 +170,6 @@ do t:check(total < d.frames and total >= d.frames - 2 * 4096, "one damaged frame dropped: " .. total) end --- fuzz local samples = {} for _, name in { "s16_l5", "ogg_s16", "id3", "varblock", "s32_rice2", "u8_mono", "bits4" } do table.insert(samples, byName[name].data) diff --git a/tests/audio/flac_encode.luau b/tests/audio/flac_encode.luau index 50617c2..893ffa7 100644 --- a/tests/audio/flac_encode.luau +++ b/tests/audio/flac_encode.luau @@ -1,7 +1,5 @@ --- audio/flac encoder tests: every fixture-step encode (levels 0-8, 1 / 2 / 6 channels, 8 / 12 / 16 / 20 / 24 bits, --- odd lengths and block sizes, odd rates, seek tables, padding) passed `flac -t` and carries the MD5 of the quantized --- input; sizes within 10% of libFLAC at the same level; each decodes bit-exactly through our own decoder; streaming --- from a Decoder gives the same bytes; tags; option errors. Fixtures: tools/fixtures/flac_enc.py. +-- audio/flac encoder tests: each fixture-step encode passed `flac -t`, has the input's MD5, is within 10% of libFLAC. +-- Fixtures: tools/fixtures/flac_enc.py. local T = require("@tests/T") local Flac = require("@rosetta/audio/flac") local Bytes = require("@rosetta/core/Bytes") @@ -88,7 +86,6 @@ do t:check(e0 and e0.frames == 0, "empty audio") end --- errors do local a = Types.Audio.new(44100, 2, 10) local function code(v: any, o: any): string? diff --git a/tests/audio/m4a.luau b/tests/audio/m4a.luau index 0e18208..c6e1924 100644 --- a/tests/audio/m4a.luau +++ b/tests/audio/m4a.luau @@ -1,8 +1,5 @@ --- audio/m4a tests: ALAC files from ffmpeg decode bit-exactly (16 / 24-bit, mono / stereo / 5.1, partial frames); --- AAC-LC files from ffmpeg and fdkaac (stereo / mono / 5.1, 8 - 96 kHz, PNS / intensity / M/S / TNS) against ffmpeg's --- float decode (SNR, gapless length through the edit list); HE-AAC / HE-AACv2 play their core; our ALAC writer --- (re-encoded here, compared with the bytes ffmpeg decoded bit-exactly and MP4Box accepted in the fixture step); tags --- and cover art round trips; streaming reads, seeking; the contract; the fuzz no-throw pass. +-- audio/m4a tests: ALAC from ffmpeg bit-exact; AAC from ffmpeg and fdkaac against ffmpeg's float decode (gapless). +-- our ALAC writer's bytes as ffmpeg decoded them bit-exactly and MP4Box accepted in the fixture step. -- Fixtures: tools/fixtures/m4a.py. local T = require("@tests/T") local M4a = require("@rosetta/audio/m4a") @@ -22,7 +19,6 @@ local function reader(s: string | buffer): Bytes.Reader return Bytes.reader(if type(s) == "string" then buffer.fromstring(s) else s) end --- the integers of a decoded Audio (exact for <= 24-bit sources), CRC-32 as little-endian int32 local function intCrc(a: any, bits: number): number local n = a.frames * a.channels local b = buffer.create(n * 4) @@ -49,12 +45,10 @@ local function snr(a: any, ref: string): (number, number) return 10 * math.log10(sig / err), n end --- the contract t:eq(M4a.name, "m4a", "name") t:eq(M4a.category, "audio", "category") t:check(M4a.caps.decode and M4a.caps.encode, "caps") --- ALAC from ffmpeg: bit-exact for _, c in Alac do if c.container ~= "m4a" then continue @@ -70,7 +64,6 @@ for _, c in Alac do end t:note("%d ffmpeg ALAC files decode bit-exactly", #Alac - 1) --- AAC: against ffmpeg's float decode local worst = math.huge for _, c in Aac do if c.container ~= "m4a" then @@ -102,7 +95,6 @@ for _, c in He do t:check(n == 8192 and e > 1, c.name .. ": the core decodes (energy " .. e .. ")") end --- our ALAC writer: the bytes ffmpeg validated do local byName = {} for _, o in Ours do @@ -141,7 +133,6 @@ do end end --- cover art + streaming a decoder into the encoder do local a = Signal.audio(44100, 5000, 2, 16, 9) a.meta.pictures = { { mime = "image/png", data = buffer.fromstring("\137PNG fake") } } @@ -164,7 +155,6 @@ for _, c in { Aac[1], Alac[1] } do local whole = M4a.decode(reader(c.data)) :: any local dec = M4a.open(reader(c.data)) :: any t:eq(dec.frames, whole.frames, c.name .. ": decoder frames") - -- read in odd chunks local got, out = 0, buffer.create(whole.frames * whole.channels * 4) while true do local b, n = dec:read(777) @@ -188,7 +178,6 @@ for _, c in { Aac[1], Alac[1] } do end end --- errors do local _, e = M4a.decode(reader("\0\0\0\8ftypM4A ")) t:check(e ~= nil, "a lone ftyp: " .. tostring(e)) @@ -197,7 +186,6 @@ do t:eq(M4a.sniff(reader("hello")), 0, "sniff junk") end --- fuzz do local samples = {} for i, c in Alac do diff --git a/tests/audio/mp3.luau b/tests/audio/mp3.luau index f1252cb..c80037c 100644 --- a/tests/audio/mp3.luau +++ b/tests/audio/mp3.luau @@ -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 diff --git a/tests/audio/mp3_encode.luau b/tests/audio/mp3_encode.luau index e7adf34..14db6fb 100644 --- a/tests/audio/mp3_encode.luau +++ b/tests/audio/mp3_encode.luau @@ -1,7 +1,5 @@ --- audio/mp3 encoder tests (layer III and layer II): every fixture-step encode (sample rates of MPEG-1 / 2 / 2.5, --- bit rates 24 .. 384 kbps, stereo / joint / mono) decodes in ffmpeg without errors and in LAME, with the expected --- length and an SNR over a per-bit-rate floor after aligning the decoder delay; our own decoder (the minimp3 port) --- agrees; streaming from a Decoder gives the same bytes; the ID3v2 tag round-trips; option errors. +-- audio/mp3 encoder tests (layer III and II): fixture-step encodes decode in ffmpeg and LAME, SNR over a per-bit-rate +-- floor after aligning the decoder delay. -- Fixtures: tools/fixtures/mp3_enc.py. local T = require("@tests/T") local Mp3 = require("@rosetta/audio/mp3") @@ -21,7 +19,6 @@ local function audio(name: string): Types.Audio return a end --- SNR of y (delayed by lag frames) against x over frames [from, to) local function snr(x: Types.Audio, y: Types.Audio, lag: number, from: number, to: number): number local ch = x.channels local sig, er = 0, 0 @@ -85,7 +82,6 @@ for _, e in Enc do if f > -math.huge then minByLayer[e.layer] = math.min(minByLayer[e.layer], e.ffSnr) end - -- our decoder agrees with ffmpeg local x = audio(e.sig) local y, err = Mp3.decode(Bytes.reader(buffer.fromstring(e.data))) t:check(y, e.name .. ": our decoder: " .. tostring(err)) @@ -96,7 +92,6 @@ for _, e in Enc do end t:note("%d encodes: ffmpeg + LAME decode them; lowest SNR layer III %.1f dB, layer II %.1f dB", #Enc, minByLayer[3], minByLayer[2]) --- streaming, tags, defaults do local a = audio("music_2_44100") local f1 = Mp3.encode(a, { bitrate = 128 }) :: buffer @@ -128,8 +123,7 @@ do t:check(empty and buffer.len(empty) > 0, "empty input: one flush frame") end --- other input rates are resampled (codecs/audio/Resample) to the next rate up: 44 kHz -> 44.1 kHz, 46 kHz -> 48 kHz, --- layer II 8 kHz -> 16 kHz, opts.sampleRate +-- other input rates are resampled to the next rate up (codecs/audio/Resample) do local function tone(rate: number, f: number): any local n = rate @@ -166,7 +160,6 @@ do end end --- errors do local function code(v: any, o: any): string? local _, e = Mp3.encode(v, o) diff --git a/tests/audio/mpc.luau b/tests/audio/mpc.luau index ea60b6a..785d6fb 100644 --- a/tests/audio/mpc.luau +++ b/tests/audio/mpc.luau @@ -1,7 +1,5 @@ --- audio/mpc tests: Musepack SV8 (mpcenc 1.30: stereo / mono, 32 / 44.1 / 48 kHz, quality 1 .. 9, 1 / 4 / 16 / 64 --- frames per packet) and SV7 (mppenc 1.16, quality 2 / 5 / 8) against libmpcdec's float output (mpcf32: gapless --- length, near bit-exact) and ffmpeg's decode (SNR); APEv2 tags; seeking (SV8 exact, SV7 like libmpcdec); a leading --- ID3v2 tag; truncated files; error codes; the fuzz no-throw pass. Fixtures: tools/fixtures/mpc.py. +-- audio/mpc tests: Musepack SV8 (mpcenc 1.30) and SV7 (mppenc 1.16) against libmpcdec's float output and ffmpeg. +-- Fixtures: tools/fixtures/mpc.py. local T = require("@tests/T") local Mpc = require("@rosetta/audio/mpc") local Bytes = require("@rosetta/core/Bytes") @@ -15,7 +13,6 @@ local function reader(s: string): Bytes.Reader return Bytes.reader(buffer.fromstring(s)) end --- SNR (dB) and the largest difference of frames [from, to) of got against a f32le reference (frames from 0) local function compare(got: buffer, gotFrom: number, ref: string, ch: number, frames: number): (number, number) local rb = buffer.fromstring(ref) local n = math.min(frames * ch, #ref // 4) @@ -64,8 +61,7 @@ for _, c in Fx do end end --- seeking: SV8 is exact (one packet of pre-roll); SV7 decodes like libmpcdec's seek (32 frames of pre-roll from reset --- scalefactors) +-- SV8 seeks exactly; SV7 like libmpcdec's seek (32 frames of pre-roll from reset scalefactors) for _, sk in Seek do local c = byName[sk.name] local whole = Mpc.decode(reader(c.data)) :: any @@ -94,7 +90,6 @@ for _, sk in Seek do t:check(n0 == 1000 and d0 < 1e-5, sk.name .. ": seek back to 0") end --- an ID3v2 tag in front; truncated files do local c = byName.sv8_q5_stereo local id3 = "ID3\3\0\0\0\0\0\20" .. string.rep("\0", 20) @@ -112,7 +107,6 @@ do end end --- errors do local c8, c7 = byName.sv8_q5_stereo.data, byName.sv7_q5_stereo.data t:eq(Mpc.sniff(reader("RIFF....WAVE")), 0, "sniff a WAV") @@ -131,7 +125,6 @@ do t:check(e and e.code == Err.LIMIT, "maxFrames: " .. tostring(e)) end --- fuzz do local samples = {} for _, c in Fx do diff --git a/tests/audio/opus.luau b/tests/audio/opus.luau index 00094fe..3f54bee 100644 --- a/tests/audio/opus.luau +++ b/tests/audio/opus.luau @@ -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 diff --git a/tests/audio/opus_encode.luau b/tests/audio/opus_encode.luau index 1952ac3..b49794b 100644 --- a/tests/audio/opus_encode.luau +++ b/tests/audio/opus_encode.luau @@ -1,7 +1,4 @@ --- audio/opus encoder tests (the CELT-only writer, ws-m4a; mono and mid / side stereo): our Ogg Opus files (re-encoded here, compared with the bytes --- checked in the fixture step) decode in libopus' opusdec to the input's exact length (pre-skip + end trimming) with a --- minimum SNR, opusinfo finds no problem, ffmpeg reads them, OpusTags carry the tags; our decoder agrees with opusdec; --- resampled 44.1 kHz input; silence frames; streaming input; errors; a fuzz no-throw pass over our files. +-- audio/opus encoder tests (CELT-only): our Ogg Opus decodes in opusdec to the input's exact length, opusinfo-clean. -- Fixtures: tools/fixtures/opus_celt.py. local T = require("@tests/T") local Opus = require("@rosetta/audio/opus") @@ -46,7 +43,6 @@ for _, c in Cases.list do local ch = c.channels t:eq(#fx.opusdec // (4 * ch), frames48, c.name .. ": opusdec length = the input's (pre-skip + end trimming)") t:eq(fx.ffmpegFrames, frames48, c.name .. ": ffmpeg length") - -- our decoder vs opusdec local ours = Opus.decode(Bytes.reader(file :: buffer)) :: any t:eq(ours.frames, frames48, c.name .. ": our decoder's length") local ref = buffer.fromstring(fx.opusdec) @@ -66,7 +62,6 @@ for _, c in Cases.list do end end --- silence frames decode to silence do local c = Cases.list[1] local ref = buffer.fromstring(byName[c.name].opusdec) @@ -77,7 +72,6 @@ do t:check(peak < 1e-3, "digital silence stays silent (peak " .. peak .. ")") end --- a streaming decoder as the input do local c = Cases.list[1] local dec = Opus.open(Bytes.reader(files[1] :: buffer)) :: any @@ -90,7 +84,6 @@ do t:check(kb ~= nil and buffer.tostring(kb :: buffer) == buffer.tostring(again :: buffer), "bitrate 64 = 64000 bit/s") end --- errors do local three = Cases.signal({ rate = 48000, channels = 3, seconds = 0.05 }) local _, e = Opus.encode(three) @@ -101,7 +94,6 @@ do t:check(e3 and e3.code == Err.ARG, "not audio") end --- fuzz the decoder over our files do local samples = {} for i, f in files do diff --git a/tests/audio/qoa.luau b/tests/audio/qoa.luau index 4e03808..0858af5 100644 --- a/tests/audio/qoa.luau +++ b/tests/audio/qoa.luau @@ -1,7 +1,5 @@ --- audio/qoa tests: files written by qoa.h (tools/fixtures/qoa.py; 1, 2 and 6 channels, a frame boundary, a partial --- last slice, clipping signals) decoded bit-exact against ffmpeg and qoa.h; our encoder byte-for-byte equal to --- qoa.h's qoa_encode, from an Audio and from a streaming Decoder; seeking; streaming files (total 0); a cut file; errors; --- the api; the fuzz pass. +-- audio/qoa tests: qoa.h's files bit-exact against ffmpeg and qoa.h; our encoder byte-for-byte equal to qoa_encode. +-- Fixtures: tools/fixtures/qoa.py. local T = require("@tests/T") local Qoa = require("@rosetta/audio/qoa") local Bytes = require("@rosetta/core/Bytes") @@ -51,7 +49,6 @@ for _, c in Cases do end t:note("%d qoa.h files decoded bit-exact (ffmpeg, qoa.h) and re-encoded byte-for-byte", #Cases) --- ------------------------------------------------------------------------------------------------ variants do local c = Cases[1] local ref = buffer.fromstring(c.ref) @@ -64,7 +61,6 @@ do -- a cut file keeps its whole frames local cut = Qoa.decode(Bytes.reader(buffer.fromstring(string.sub(c.data, 1, #c.data - 100)))) :: any t:check(cut and cut.frames == 5120 * 2 and H.same(cut.samples, ref, 0, cut.frames * c.ch), "cut file: the whole frames") - -- errors local _, e1 = Qoa.open(Bytes.reader(buffer.fromstring("qoaf\0\0\0\1"))) t:check(e1 and e1.code == Err.TRUNCATED, "no frames: " .. tostring(e1)) local bad = buffer.fromstring(c.data) diff --git a/tests/audio/tta.luau b/tests/audio/tta.luau index 732671f..e7bea11 100644 --- a/tests/audio/tta.luau +++ b/tests/audio/tta.luau @@ -1,8 +1,5 @@ --- audio/tta tests: every fixture from tools/fixtures/tta.py (ttaenc 3.4.1: 8 / 16 / 24 bits, 1 - 6 channels, odd --- rates and lengths, several frames, silence, noise; the FATE sample inside.tta cut mid-file) decoded bit-exact --- against `ttaenc -d`; seeking; f32 scaling and output reuse; decode() from a sub-range Reader; an ID3v2 tag in front --- and an APEv2 tag at the end; password-protected files (UNSUPPORTED); header / seek table / frame CRCs; sniff; the --- api; the fuzz pass. Fixtures: tools/fixtures/tta.py. +-- audio/tta tests: tools/fixtures/tta.py's files (ttaenc 3.4.1, FATE's inside.tta) bit-exact against `ttaenc -d`. +-- Fixtures: tools/fixtures/tta.py. local T = require("@tests/T") local Tta = require("@rosetta/audio/tta") local Bytes = require("@rosetta/core/Bytes") @@ -72,7 +69,6 @@ do t:eq(Tta.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff RIFF") end --- the api do local fx = byName.s16 t:eq(F.detect(buffer.fromstring(fx.data)), "tta", "detect") @@ -80,7 +76,7 @@ do t:check(a and a.frames == fx.frames and a.meta.source.format == "tta", "F.audio.load") end --- the fuzz pass (the frame CRC rejects most mutations; the second set skips it to reach the decoder) +-- the frame CRC rejects most mutations; the second fuzz set skips it to reach the decoder local samples = {} for _, name in { "s16", "mono", "s24", "u8", "ch6" } do table.insert(samples, buffer.fromstring(byName[name].data)) diff --git a/tests/audio/vag.luau b/tests/audio/vag.luau index c388120..62b3ba7 100644 --- a/tests/audio/vag.luau +++ b/tests/audio/vag.luau @@ -1,6 +1,5 @@ --- audio/vag tests: VAGp (with and without loop flags), VAGi and KVAG files from our Python encoders, bit-exact with --- vgmstream / ffmpeg (tools/fixtures/vag.py) through decode and open with seeks; our encoder's files as vgmstream --- decodes them (loops reported where vgmstream reads them), their quality; errors; the api; the fuzz pass. +-- audio/vag tests: VAGp, VAGi and KVAG files from our Python encoders, bit-exact with vgmstream / ffmpeg. +-- Fixtures: tools/fixtures/vag.py. local T = require("@tests/T") local Vag = require("@rosetta/audio/vag") local Bytes = require("@rosetta/core/Bytes") @@ -27,7 +26,6 @@ for _, c in Cases do end t:note("%d files bit-exact with vgmstream / ffmpeg", #Cases) --- ------------------------------------------------------------------------------------------------ encoder local function audioOf(S: any): any local a = Types.Audio.new(S.rate, S.channels, S.frames) buffer.writestring(a.samples, 0, S.data) @@ -57,7 +55,6 @@ do t:check(e3 and e3.code == Err.ARG, "bad interleave") end --- ------------------------------------------------------------------------------------------------ errors do local base = Cases[1].data local hevag = buffer.fromstring(base) diff --git a/tests/audio/voc.luau b/tests/audio/voc.luau index 1df70ee..f96fdaf 100644 --- a/tests/audio/voc.luau +++ b/tests/audio/voc.luau @@ -1,6 +1,4 @@ --- audio/voc tests: files written by ffmpeg (type 1 + 8 blocks for 8-bit, type 9 otherwise) and sox against ffmpeg's --- decode; silence / text / continuation blocks and repeat markers built here; streaming reads and seeks; our --- encoder's output for every sample format decoded by ffmpeg (fixture step) and by us; errors; fuzz. +-- audio/voc tests: files written by ffmpeg and sox against ffmpeg's decode; our encoder's output via ffmpeg. -- Fixtures: tools/fixtures/voc.py. local T = require("@tests/T") local Voc = require("@rosetta/audio/voc") @@ -45,7 +43,6 @@ for _, c in Cases do end t:note("%d reference files match ffmpeg", #Cases) --- hand-built blocks: text, type 1 u8, silence, continuation, repeat markers, terminator do local hdr = "Creative Voice File\26\26\0\10\1\41\17" local function blk(typ: number, payload: string): string diff --git a/tests/audio/vorbis.luau b/tests/audio/vorbis.luau index 89608c7..18943e7 100644 --- a/tests/audio/vorbis.luau +++ b/tests/audio/vorbis.luau @@ -1,7 +1,5 @@ --- audio/vorbis tests: oggenc / ffmpeg streams (qualities -1 .. 10, managed bitrate, 8 .. 96 kHz, mono / stereo / 5.1, --- transients, silence, tags, sub-block lengths) against oggdec (libvorbisfile: sample counts and 16-bit samples, so --- start / end trimming is exact) and ffmpeg's f32 decode (SNR); streaming reads; seeking (sample-exact against the --- reference at the target); the packet-level decoder; errors; fuzz. Fixtures: tools/fixtures/vorbis.py. +-- audio/vorbis tests: oggenc / ffmpeg streams against oggdec (16-bit, exact trimming) and ffmpeg's f32 decode (SNR). +-- Fixtures: tools/fixtures/vorbis.py. local T = require("@tests/T") local Vorbis = require("@rosetta/audio/vorbis") local Bytes = require("@rosetta/core/Bytes") @@ -20,7 +18,6 @@ local function s16(x: number): number local v = math.floor(x * 32768 + 0.5) return math.clamp(v, -32768, 32767) end --- the largest |our sample as s16 - oggdec's| over n samples of ours at byte a0 against ref16 from sample r0 local function maxDiff16(a: buffer, a0: number, ref: buffer, r0: number, n: number): number local m = 0 for i = 0, n - 1 do @@ -76,7 +73,6 @@ for _, c in Cases do minSnr = math.min(minSnr, s) t:check(s > 100, string.format("%s: SNR vs ffmpeg %.1f dB", c.name, s)) end - -- streaming in odd chunks gives the same samples local dec = Vorbis.open(reader(c.data)) :: Types.Decoder t:eq(dec.frames, c.frames, c.name .. ": Decoder.frames") local got, ok = 0, true @@ -117,7 +113,6 @@ local function case(name: string): any error("no case " .. name) end --- tags, meta, sniff, sub-range do local c = case("q2-stereo-32k-tags") local dec = Vorbis.open(reader(c.data)) :: any @@ -164,7 +159,6 @@ do t:check(e and e.code == Err.CORRUPT, "packetDecoder with headers swapped") end --- errors do local _, e1 = Vorbis.decode(reader("OggS but not really")) t:check(e1 and Err.is(e1), "junk: " .. tostring(e1)) diff --git a/tests/audio/vorbis_encode.luau b/tests/audio/vorbis_encode.luau index b7a6c4c..94a5cea 100644 --- a/tests/audio/vorbis_encode.luau +++ b/tests/audio/vorbis_encode.luau @@ -1,7 +1,5 @@ --- audio/vorbis encoder tests: every fixture-step encode (qualities -1 .. 10, mono / stereo / 5.1, 8 .. 96 kHz, odd --- lengths, silence) passes ogginfo, decodes in oggdec (libvorbisfile) with the exact input length and an SNR over a --- per-quality floor, and in ffmpeg; our own decoder gives the same; the codebooks are valid prefix codes; streaming --- from a Decoder gives the same bytes; tags round-trip; option errors. Fixtures: tools/fixtures/vorbis_enc.py. +-- audio/vorbis encoder tests: each fixture-step encode passes ogginfo, decodes in oggdec with the exact length and +-- an SNR over a per-quality floor, and in ffmpeg. Fixtures: tools/fixtures/vorbis_enc.py. local T = require("@tests/T") local Vorbis = require("@rosetta/audio/vorbis") local VEnc = require("@rosetta/audio/vorbis/Encode") @@ -75,7 +73,6 @@ for _, e in Enc do end t:note("%d encodes pass ogginfo / oggdec / ffmpeg; lowest SNR %.1f dB", #Enc, minSnr) --- streaming, tags do local a = audio("music_2_3000_44100") local f1 = Vorbis.encode(a) :: buffer @@ -92,7 +89,6 @@ do t:check(e0 and e0.frames == 0, "empty input") end --- errors do local a = Types.Audio.new(44100, 2, 10) local function code(v: any, o: any): string? diff --git a/tests/audio/wav.luau b/tests/audio/wav.luau index c1a2033..fafae6a 100644 --- a/tests/audio/wav.luau +++ b/tests/audio/wav.luau @@ -1,9 +1,5 @@ --- audio/wav tests: every format / container / damaged variant from tools/fixtures/wav.py decoded in reads of mixed --- sizes against ffmpeg's (or sox's) f32 decode, with tags, seeking and output-buffer reuse; hand-built files (header --- parsing, errors, argument clamping, EXTENSIBLE with valid bits, the truncated flag); the encoder byte-exact against --- ffmpeg -bitexact (u8 / s16 / s24 / s32 / f32, 1-8 channels, > 48 kHz, RF64), round trips from an Audio and from a --- streaming Decoder, tags, encodeParts, the RF64 switch; the api (F.audio.load / open / save); the fuzz pass. --- Ported from wav-luau tests/core.luau + tests/decode.luau. Fixtures: tools/fixtures/wav.py. +-- audio/wav tests: tools/fixtures/wav.py's files against ffmpeg's (or sox's) f32 decode; encoder vs ffmpeg -bitexact. +-- Fixtures: tools/fixtures/wav.py. local T = require("@tests/T") local Wav = require("@rosetta/audio/wav") local Bytes = require("@rosetta/core/Bytes") @@ -63,12 +59,10 @@ local function riff(...: string): string return "RIFF" .. u32(#body) .. body end --- the contract t:eq(Wav.name, "wav", "name") t:eq(Wav.category, "audio", "category") t:check(Wav.caps.decode and Wav.caps.encode and Wav.open ~= nil, "caps / open") --- ------------------------------------------------------------------------------------------------ fixtures local function readAll(dec: any, sizes: { number }): (buffer, number) local out = buffer.create(dec.frames * dec.channels * 4) local got, i = 0, 0 @@ -138,7 +132,6 @@ for _, fx in Cases do end t:note("%d fixture files match ffmpeg / sox", #Cases) --- ------------------------------------------------------------------------------------------------ hand-built files do local dec = open(riff(fmt(1, 2, 8000, 16), chunk("data", i16s(16384, -16384, 32767, -32768)))) t:check(dec, "open minimal") @@ -179,13 +172,13 @@ do -- EXTENSIBLE: 24 valid bits in a 32-bit container local _, e = open(riff(fmt(0xFFFE, 1, 8000, 16), chunk("data", "\0\0"))) t:check(e and e.code == Err.CORRUPT, "extensible without extension") end -do -- tags +do local info = "INFO" .. "INAM" .. u32(3) .. "abc\0" .. "IART" .. u32(6) .. "xy\0\0\0\0" .. "IXYZ" .. u32(2) .. "zz" .. "ITRK" .. u32(2) .. "7\0" local dec = open(riff(fmt(1, 1, 8000, 8), chunk("LIST", info), chunk("data", "\128\128\128"))) t:check(dec and dec.tags.title == "abc" and dec.tags.artist == "xy" and dec.tags.ixyz == "zz" and dec.tags.track == "7", "tags") t:check(dec and dec.frames == 3, "8-bit odd data") end -do -- 8-bit, A-law and mu-law values +do local o = open(riff(fmt(1, 1, 8000, 8), chunk("data", "\0\128\255"))):read(3) t:check(buffer.readf32(o, 0) == -1 and buffer.readf32(o, 4) == 0 and buffer.readf32(o, 8) == 127 / 128, "u8 values") local m = open(riff(fmt(7, 1, 8000, 8), chunk("data", "\255\127\0\128"))):read(4) @@ -195,7 +188,7 @@ do -- 8-bit, A-law and mu-law values t:check(buffer.readf32(a, 0) == 8 / 32768 and buffer.readf32(a, 4) == -8 / 32768, "A-law smallest") t:check(buffer.readf32(a, 8) == -32256 / 32768 and buffer.readf32(a, 12) == 32256 / 32768, "A-law extremes") end -do -- errors: nil, Err +do local function fails(s: any, code: string, pattern: string, label: string) local ok, dec, err = pcall(open, s) t:check(ok, label .. ": threw " .. tostring(dec)) @@ -216,7 +209,6 @@ do -- errors: nil, Err t:eq(Wav.sniff(Bytes.reader(buffer.fromstring("RIFF\0\0\0\0AVI "))), 0, "sniff AVI") end --- ------------------------------------------------------------------------------------------------ encoder do for _, c in Enc do local a = Types.Audio.new(c.rate, c.channels, c.frames) @@ -229,7 +221,6 @@ do t:note("%s: ffmpeg %s", c.name, T.hex(buffer.fromstring(c.file), 80)) end t:check(same, c.name .. ": identical to ffmpeg -bitexact") - -- and back local back = Wav.decode(Bytes.reader(out :: buffer)) t:check(back and back.frames == c.frames and buffer.tostring(back.samples) == c.samples, c.name .. ": round trip") -- from a streaming Decoder (our own, over ffmpeg's file) @@ -238,7 +229,6 @@ do t:check(out2 and buffer.tostring(out2) == c.file, c.name .. ": encode from a Decoder") end t:note("encoder: %d files identical to ffmpeg -bitexact", #Enc) - -- clamping and rounding local a = Types.Audio.new(8000, 1, 6) for i, v in { 2, -2, 0.5 / 32768, -0.5 / 32768, 1.5 / 32768, 0 / 0 } do buffer.writef32(a.samples, (i - 1) * 4, v) @@ -248,7 +238,6 @@ do for i, w in want do t:eq(math.floor(buffer.readf32(d.samples, (i - 1) * 4) * 32768 + 0.5), w, "s16 rounding / clamping " .. i) end - -- tags a.tags = { title = "Hello", artist = "Someone", IXYZ = "kept", comment = "" } local tg = Wav.decode(Bytes.reader(Wav.encode(a, { sampleFormat = "u8" }) :: buffer)) :: any t:check(tg.tags.title == "Hello" and tg.tags.artist == "Someone" and tg.tags.ixyz == "kept" and tg.tags.comment == nil, "tag round trip") @@ -269,7 +258,6 @@ do t:check(rd.container == "RF64" and rd.frames == 3000, "RF64 reads back") t:check(buffer.tostring(rd:read(3000)) == buffer.tostring(Wav.decode(Bytes.reader(Wav.encode(big) :: buffer)).samples), "RF64 samples") t:eq(buffer.readstring(Wav.encode(big) :: buffer, 0, 4), "RIFF", "plain RIFF below the threshold") - -- bad arguments local _, e1 = Wav.encode({} :: any) t:check(e1 and e1.code == Err.ARG, "encode {}: " .. tostring(e1)) local _, e2 = Wav.encode(a, { sampleFormat = "s12" } :: any) @@ -280,7 +268,6 @@ do t:check(e3 and e3.code == Err.ARG, "short samples buffer") end --- ------------------------------------------------------------------------------------------------ api do local c = Enc[1] local a, err = F.audio.load(c.file) @@ -292,7 +279,6 @@ do t:eq(F.detect(c.file), "wav", "F.detect") end --- ------------------------------------------------------------------------------------------------ fuzz t:fuzz("open + read + seek", function(b: buffer) local dec = Wav.open(Bytes.reader(b)) if dec then diff --git a/tests/audio/wavpack.luau b/tests/audio/wavpack.luau index 7557be3..fb4ffed 100644 --- a/tests/audio/wavpack.luau +++ b/tests/audio/wavpack.luau @@ -1,8 +1,5 @@ --- audio/wavpack tests: every fixture from tools/fixtures/wavpack.py (wavpack -f / -g / -h / -hh / -x1..6, joint stereo --- on / off, 8 - 32-bit int and 32-bit float, 1 - 8 channels, odd rates and lengths, hybrid lossy and hybrid lossless --- with the .wvc, noise shaping, ffmpeg's encoder) decoded bit-exact against wvunpack; seeking; f32 scaling and output --- reuse; decode() from a sub-range Reader; APEv2 tags and the MD5; the correction file through opts.resolve; sniff; --- the api; damaged blocks; the fuzz pass. Fixtures: tools/fixtures/wavpack.py. +-- audio/wavpack tests: tools/fixtures/wavpack.py's files (every mode, hybrid + .wvc) bit-exact against wvunpack. +-- Fixtures: tools/fixtures/wavpack.py. local T = require("@tests/T") local WavPack = require("@rosetta/audio/wavpack") local Bytes = require("@rosetta/core/Bytes") @@ -39,12 +36,10 @@ for _, fx in Cases do end t:note("%d fixtures bit-exact against wvunpack, %d seeks", #Cases, seekChecks) --- decode() from a sub-range Reader for _, name in { "s16_g", "md5_tags", "f32", "ch6" } do L.subrange(t, WavPack, byName[name], "wavpack") end --- tags, md5, the source facts do local dec = open(byName.md5_tags.data) t:eq(#dec.md5, 32, "md5") @@ -72,7 +67,6 @@ do t:check(dec2 and not dec2.lossless, "resolve: no wvc -> lossy") end --- the api do local fx = byName.s16_g t:eq(F.detect(buffer.fromstring(fx.data)), "wavpack", "detect") @@ -101,7 +95,6 @@ do t:eq(WavPack.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff RIFF") end --- the fuzz pass local samples = {} for _, name in { "s16_g", "f32", "hyb_b3", "s32_hh", "ch6", "u8" } do table.insert(samples, buffer.fromstring(byName[name].data))