merge ws/audio2
This commit is contained in:
commit
f0a23eb676
149 files changed
+23004
-312
No files matched your search
@@ -0,0 +1,57 @@
|
||||
-- codecs/audio/Ac3 tests: the codec API under audio/ac3 and the container hook: header fields of every fixture layout,
|
||||
-- the CRC (a syncframe checks to 0), one-frame decodes against the reference (frame by frame, as a container feeds
|
||||
-- them), the block offsets, reset, argument / data errors, and a fuzz pass over single frames (CRC off).
|
||||
-- Fixtures: tools/fixtures/ac3.py.
|
||||
local T = require("@tests/T")
|
||||
local Ac3 = require("@formats/codecs/audio/Ac3")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/ac3_cases")
|
||||
|
||||
local t = T.suite("codecs/ac3")
|
||||
|
||||
local ACMOD_CH = { [0] = 2, 1, 2, 3, 3, 4, 4, 5 }
|
||||
local frames = {}
|
||||
for _, c in Fx do
|
||||
local b = buffer.fromstring(c.data)
|
||||
local h = Ac3.header(b, 0, buffer.len(b))
|
||||
t:check(h, c.name .. ": header")
|
||||
if not h then
|
||||
continue
|
||||
end
|
||||
t:check(h.sampleRate == c.rate and h.channels == c.channels, c.name .. ": header rate / channels")
|
||||
t:eq(ACMOD_CH[h.acmod] + (if h.lfeon then 1 else 0), c.channels, c.name .. ": acmod + lfe")
|
||||
t:eq(Ac3.crc(b, 2, h.frameSize - 2), 0, c.name .. ": crc2 checks")
|
||||
-- frame by frame, fresh decoder: the second frame against the reference
|
||||
local d = Ac3.decoder()
|
||||
local n1 = d:decode(b, 0, h.frameSize)
|
||||
local h2 = Ac3.header(b, h.frameSize, buffer.len(b)) :: Ac3.Header
|
||||
local n2, err = d:decode(b, h.frameSize, h2.frameSize)
|
||||
t:check(n1 == 1536 and n2 == 1536, c.name .. ": two frames: " .. tostring(err))
|
||||
local rb = buffer.fromstring(c.ref)
|
||||
local maxd = 0
|
||||
for i = 1, 1536 * c.channels do
|
||||
maxd = math.max(maxd, math.abs(d.pcm[i] - buffer.readf32(rb, (1536 * c.channels + i - 1) * 4)))
|
||||
end
|
||||
t:check(maxd < 1e-4, string.format("%s: frame 2 (max diff %g)", c.name, maxd))
|
||||
t:check(#d.blocks == 6 and d.blocks[1] > 40 and d.blocks[6] < h2.frameSize * 8, c.name .. ": block offsets")
|
||||
d:reset()
|
||||
table.insert(frames, buffer.readstring(b, 0, h.frameSize))
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local d = Ac3.decoder()
|
||||
local _, e = d:decode(buffer.create(10), 20)
|
||||
t:check(e and e.code == Err.ARG, "offset past the buffer: " .. tostring(e))
|
||||
_, e = d:decode(buffer.fromstring(string.rep("\0", 64)), 0)
|
||||
t:check(e and e.code == Err.CORRUPT, "no sync: " .. tostring(e))
|
||||
_, e = d:decode(buffer.fromstring(string.sub(frames[1], 1, 100)), 0)
|
||||
t:check(e and e.code == Err.TRUNCATED, "short frame: " .. tostring(e))
|
||||
t:check(Ac3.header(buffer.fromstring("\11\119\0\0\255\0\0\0"), 0, 8) == nil, "frmsizecod 63 / fscod 3: no header")
|
||||
end
|
||||
|
||||
t:fuzz("decode one frame (crc off)", function(b: buffer)
|
||||
return Ac3.decoder({ crc = false }):decode(b, 0)
|
||||
end, frames, { mutations = 30, keepHeader = 6 })
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,247 @@
|
||||
-- codecs/adpcm tests: every decoder kernel of codecs/audio/Adpcm against a reference decoder, bit-exact as s16
|
||||
-- (tools/fixtures/adpcm.py: ADX from ffmpeg and PS-ADPCM / DSP from our Python encoders decoded by vgmstream, Apple
|
||||
-- ima4 from ffmpeg, IMA nibble streams decoded by ffmpeg); ADX coefficients; the encoders (IMA nibbles, IMA WAV
|
||||
-- blocks, MS blocks) decoded back with a signal-to-noise floor; the Decoder layouts (seeking matches a straight
|
||||
-- read); a fuzz pass of random bytes through every kernel (ranges valid, contents random) and the layouts.
|
||||
local T = require("@tests/T")
|
||||
local Adpcm = require("@formats/codecs/audio/Adpcm")
|
||||
local Decoder = require("@formats/codecs/audio/Adpcm/Decoder")
|
||||
local Cases = require("@tests/gen/adpcm_codec")
|
||||
local Sig = require("@tests/gen/adpcm_sig")
|
||||
|
||||
local t = T.suite("adpcm codec")
|
||||
|
||||
-- s16le reference vs interleaved f32: the count of differing samples and the first one
|
||||
local function compare(out: buffer, ref: string, count: number): (number, number)
|
||||
local r = buffer.fromstring(ref)
|
||||
local bad, first = 0, -1
|
||||
for i = 0, count - 1 do
|
||||
if buffer.readf32(out, i * 4) * 32768 ~= buffer.readi16(r, i * 2) then
|
||||
bad += 1
|
||||
if first < 0 then
|
||||
first = i
|
||||
end
|
||||
end
|
||||
end
|
||||
return bad, first
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ kernels
|
||||
for _, c in Cases do
|
||||
local src = buffer.fromstring(c.data)
|
||||
local ch, frames = c.ch, c.frames
|
||||
local out = buffer.create((frames + 64) * ch * 4)
|
||||
local st = buffer.create(8 * ch)
|
||||
if c.kind == "adx" then
|
||||
local c1, c2 = Adpcm.adxCoefs(c.cutoff, c.rate)
|
||||
local nf = math.ceil(frames / 32)
|
||||
for k = 0, ch - 1 do
|
||||
Adpcm.adx(src, k * 18, 18 * ch, nf, c1, c2, c.v3, st, k * 8, out, k, ch)
|
||||
end
|
||||
elseif c.kind == "psx" then
|
||||
Adpcm.psx(src, 0, 16, frames // 28, st, 0, out, 0, 1)
|
||||
elseif c.kind == "dsp" then
|
||||
local coefs = buffer.create(64)
|
||||
for i, v in c.coefs do
|
||||
buffer.writei32(coefs, (i - 1) * 4, v)
|
||||
end
|
||||
-- in pieces: the state carries over
|
||||
Adpcm.dsp(src, 0, 14 * 9, coefs, 0, st, 0, out, 0, 1)
|
||||
Adpcm.dsp(src, 8 * 9, frames - 14 * 9, coefs, 0, st, 0, out, 14 * 9, 1)
|
||||
elseif c.kind == "ima_qt" then
|
||||
for p = 0, frames // 64 - 1 do
|
||||
for k = 0, ch - 1 do
|
||||
Adpcm.imaQt(src, (p * ch + k) * 34, st, k * 8, out, p * 64 * ch + k, ch)
|
||||
end
|
||||
end
|
||||
elseif c.kind == "ima" then
|
||||
for k = 0, ch - 1 do
|
||||
Adpcm.ima(src, 0, k, ch, frames, true, st, k * 8, out, k, ch)
|
||||
end
|
||||
end
|
||||
local bad, first = compare(out, c.ref, frames * ch)
|
||||
t:check(bad == 0, string.format("%s: %d of %d samples differ (first at %d)", c.name, bad, frames * ch, first))
|
||||
end
|
||||
t:note("%d streams bit-exact with the reference decoders", #Cases)
|
||||
|
||||
-- ADX coefficients: 500 Hz at 44.1 kHz / 22.05 kHz (CRI's single-precision derivation, as vgmstream)
|
||||
do
|
||||
local a1, a2 = Adpcm.adxCoefs(500, 44100)
|
||||
t:check(a1 == 7334 and a2 == -3283, "adx coefs 44100: " .. a1 .. " " .. a2)
|
||||
local z1, z2 = Adpcm.adxCoefs(0, 0)
|
||||
t:check(z1 == 0 and z2 == 0, "adx coefs of rate 0")
|
||||
end
|
||||
|
||||
-- ModPlug ADPCM: deltas from the table, wrapping as a signed byte
|
||||
do
|
||||
local src = buffer.create(18)
|
||||
for k = 0, 15 do
|
||||
buffer.writei8(src, k, if k == 1 then 100 elseif k == 2 then -3 else 0)
|
||||
end
|
||||
buffer.writeu8(src, 16, 0x11) -- +100, +100 (wraps to -56)
|
||||
buffer.writeu8(src, 17, 0x02) -- -3, +0
|
||||
local out = buffer.create(16)
|
||||
Adpcm.modplug(src, 0, 4, out, 0)
|
||||
local want = { 100, -56, -59, -59 }
|
||||
for i, v in want do
|
||||
t:eq(buffer.readf32(out, (i - 1) * 4) * 128, v, "modplug sample " .. i)
|
||||
end
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encoders
|
||||
local function snr(x: buffer, y: buffer, count: number): number
|
||||
local sig, err = 0, 0
|
||||
for i = 0, count - 1 do
|
||||
local a = buffer.readf32(x, i * 4)
|
||||
local e = a - buffer.readf32(y, i * 4)
|
||||
sig += a * a
|
||||
err += e * e
|
||||
end
|
||||
return if err == 0 then 200 else 10 * math.log10(sig / err)
|
||||
end
|
||||
|
||||
do
|
||||
local x = buffer.fromstring(Sig.data)
|
||||
local ch, n = Sig.channels, Sig.frames
|
||||
-- IMA nibbles, both nibble orders
|
||||
for _, hi in { true, false } do
|
||||
local raw = buffer.create((n * ch + 1) // 2)
|
||||
local st = buffer.create(8 * ch)
|
||||
for c = 0, ch - 1 do
|
||||
Adpcm.imaEncode(x, c, ch, n, st, c * 8, raw, 0, c, ch, hi)
|
||||
end
|
||||
local back = buffer.create(n * ch * 4)
|
||||
local ds = buffer.create(8 * ch)
|
||||
for c = 0, ch - 1 do
|
||||
Adpcm.ima(raw, 0, c, ch, n, hi, ds, c * 8, back, c, ch)
|
||||
end
|
||||
local s = snr(x, back, n * ch)
|
||||
t:check(s > 20, string.format("ima encode (hi %s): %.1f dB", tostring(hi), s))
|
||||
t:check(buffer.readi32(st, 0) == buffer.readi32(ds, 0), "ima encoder and decoder end in the same state")
|
||||
end
|
||||
-- IMA WAV and MS blocks
|
||||
for _, kind in { "ima_wav", "ms" } do
|
||||
local ba = 512
|
||||
local spb = Decoder.blockFrames(kind, ba, ch) :: number
|
||||
local blocks = (n + spb - 1) // spb
|
||||
local raw = buffer.create(blocks * ba)
|
||||
local st = buffer.create(8 * ch)
|
||||
for b = 0, blocks - 1 do
|
||||
if kind == "ms" then
|
||||
Adpcm.msEncode(x, b * spb, n - b * spb, ch, spb, raw, b * ba)
|
||||
else
|
||||
Adpcm.imaWavEncode(x, b * spb, n - b * spb, ch, spb, st, raw, b * ba)
|
||||
end
|
||||
end
|
||||
local back = buffer.create(blocks * spb * ch * 4)
|
||||
local coefs = buffer.create(56)
|
||||
for k = 0, 6 do
|
||||
buffer.writei32(coefs, k * 8, Adpcm.MS_COEF1[k + 1])
|
||||
buffer.writei32(coefs, k * 8 + 4, Adpcm.MS_COEF2[k + 1])
|
||||
end
|
||||
local scratch = buffer.create(20 * ch)
|
||||
for b = 0, blocks - 1 do
|
||||
local got
|
||||
if kind == "ms" then
|
||||
got = Adpcm.msBlock(raw, b * ba, ba, ch, spb, back, b * spb * ch, coefs, 7, scratch)
|
||||
else
|
||||
got = Adpcm.imaWav(raw, b * ba, ba, ch, spb, back, b * spb * ch)
|
||||
end
|
||||
t:eq(got, spb, kind .. ": block frames")
|
||||
end
|
||||
local s = snr(x, back, n * ch)
|
||||
t:check(s > (if kind == "ms" then 24 else 20), string.format("%s encode: %.1f dB", kind, s))
|
||||
end
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ Decoder layouts
|
||||
local function readAll(dec: any, step: number): buffer
|
||||
local out = buffer.create(dec.frames * dec.channels * 4)
|
||||
local got = 0
|
||||
while true do
|
||||
local b, n = dec:read(step)
|
||||
if n == 0 then
|
||||
break
|
||||
end
|
||||
buffer.copy(out, got * dec.channels * 4, b, 0, n * dec.channels * 4)
|
||||
got += n
|
||||
end
|
||||
t:eq(got, dec.frames, "layout: frames read")
|
||||
return out
|
||||
end
|
||||
|
||||
do
|
||||
-- psx in rows of 64 bytes per channel (stereo), seeking back and forth lands on the same samples
|
||||
local rng = T.rng(5)
|
||||
local ch, il, rows = 2, 64, 40
|
||||
local data = buffer.create(il * ch * rows)
|
||||
for i = 0, buffer.len(data) - 1 do
|
||||
buffer.writeu8(data, i, if i % 16 == 0 then rng(5) * 16 + rng(13) elseif i % 16 == 1 then 0 else rng(256))
|
||||
end
|
||||
for _, kind in { "psx", "dsp" } do
|
||||
local coefs = buffer.create(64 * ch)
|
||||
for k = 0, 16 * ch - 1 do
|
||||
buffer.writei32(coefs, k * 4, (k % 2 == 0) and 1800 or -700)
|
||||
end
|
||||
local il2 = if kind == "dsp" then 64 else il
|
||||
local dec = Decoder.interleaved({ sampleRate = 8000, channels = ch, tags = {} }, {
|
||||
kind = kind :: any, buf = data, offset = 0, size = buffer.len(data), interleave = il2, coefs = coefs })
|
||||
t:check(dec ~= nil, kind .. ": interleaved decoder")
|
||||
local all = readAll(dec, 1000)
|
||||
for _, f in { 500, 3, dec.frames - 7, 1234, 0 } do
|
||||
dec:seek(f / 8000)
|
||||
local b, n = dec:read(5)
|
||||
local same = n == math.min(5, dec.frames - f)
|
||||
for k = 0, n * ch - 1 do
|
||||
same = same and buffer.readf32(b, k * 4) == buffer.readf32(all, (f * ch + k) * 4)
|
||||
end
|
||||
t:check(same, kind .. ": seek to " .. f .. " is exact")
|
||||
end
|
||||
end
|
||||
-- a cut file: the whole frames of every channel
|
||||
local dec = Decoder.interleaved({ sampleRate = 8000, channels = 2, tags = {} }, {
|
||||
kind = "psx", buf = data, offset = 0, size = il * ch * 3 + il + 20, interleave = il })
|
||||
t:eq(dec.frames, 3 * 4 * 28 + 28, "cut interleaved: the whole frames both channels have")
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ fuzz
|
||||
local samples = {}
|
||||
for _, c in Cases do
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
t:fuzz("kernels", function(b: buffer)
|
||||
local n = buffer.len(b)
|
||||
local out = buffer.create(64 * 64 * 4)
|
||||
local st = buffer.create(64)
|
||||
local coefs = buffer.create(64)
|
||||
for k = 0, 15 do
|
||||
buffer.writei32(coefs, k * 4, if n > k then buffer.readi8(b, k) * 64 else 0)
|
||||
end
|
||||
if n >= 18 then
|
||||
Adpcm.adx(b, 0, 18, 1, 7334, -3283, n % 2 == 0, st, 0, out, 0, 1)
|
||||
end
|
||||
if n >= 16 then
|
||||
Adpcm.psx(b, 0, 16, 1, st, 8, out, 0, 1)
|
||||
end
|
||||
if n >= 8 then
|
||||
Adpcm.dsp(b, 0, 14, coefs, 0, st, 16, out, 0, 1)
|
||||
end
|
||||
if n >= 34 then
|
||||
Adpcm.imaQt(b, 0, st, 24, out, 0, 1)
|
||||
end
|
||||
if n >= 1 then
|
||||
Adpcm.ima(b, 0, 0, 1, math.min(n * 2, 1000), true, st, 32, out, 0, 1)
|
||||
end
|
||||
if n >= 17 then
|
||||
Adpcm.modplug(b, 0, math.min((n - 16) * 2, 1000), out, 0)
|
||||
end
|
||||
Adpcm.imaWav(b, 0, n, 2, 1017, buffer.create(1017 * 2 * 4), 0)
|
||||
Adpcm.msBlock(b, 0, n, 2, 1012, buffer.create(1012 * 2 * 4), 0, coefs, 8, buffer.create(40))
|
||||
local dec = Decoder.interleaved({ sampleRate = 8000, channels = 2, tags = {} }, { kind = "adx", buf = b, offset = 0, size = n, interleave = 18, c1 = 7334, c2 = -3283 })
|
||||
if dec then
|
||||
dec:read(100000)
|
||||
dec:seek(0)
|
||||
end
|
||||
return true
|
||||
end, samples, { mutations = 6, garbage = 60 })
|
||||
t:done()
|
||||
@@ -0,0 +1,79 @@
|
||||
-- codecs/audio/ApeTag tests: APEv2 tags with and without a header, APEv1, multi-value items, binary items, an ID3v1
|
||||
-- tag after the APE tag, a tag inside a sub-range, malformed sizes / counts; the fuzz no-throw pass. The real files
|
||||
-- (wavpack -w, mac -t, ...) are covered by tests/audio/wavpack.luau and tests/audio/ape.luau.
|
||||
local T = require("@tests/T")
|
||||
local ApeTag = require("@formats/codecs/audio/ApeTag")
|
||||
|
||||
local t = T.suite("apetag")
|
||||
|
||||
local function u32(v: number): string
|
||||
return string.char(v % 256, (v // 256) % 256, (v // 65536) % 256, (v // 16777216) % 256)
|
||||
end
|
||||
-- tag(items, version, header) -> the tag bytes; items = { { key, value, flags? } }
|
||||
local function tag(items: { any }, version: number, header: boolean): string
|
||||
local body = {}
|
||||
for _, it in items do
|
||||
table.insert(body, u32(#it[2]) .. u32(it[3] or 0) .. it[1] .. "\0" .. it[2])
|
||||
end
|
||||
local b = table.concat(body)
|
||||
local flags = if header then 0x80000000 else 0
|
||||
local function block(isHeader: boolean): string
|
||||
return "APETAGEX" .. u32(version) .. u32(#b + 32) .. u32(#items) .. u32(flags + (if isHeader then 0x20000000 else 0)) .. string.rep("\0", 8)
|
||||
end
|
||||
return (if header then block(true) else "") .. b .. block(false)
|
||||
end
|
||||
|
||||
do
|
||||
local s = "audio data" .. tag({ { "Title", "Hello" }, { "Artist", "A\0B" }, { "Year", "2026" }, { "Track", "3/9" },
|
||||
{ "Cover Art (Front)", "f.png\0PNG", 2 }, { "Album Artist", "Band" } }, 2000, true)
|
||||
local b = buffer.fromstring(s)
|
||||
local tags, info = ApeTag.find(b, 0, #s)
|
||||
t:check(tags and info, "v2 found")
|
||||
t:eq(tags.title, "Hello", "title")
|
||||
t:eq(tags.artist, "A; B", "multi value")
|
||||
t:eq(tags.date, "2026", "year -> date")
|
||||
t:eq(tags.track, "3/9", "track")
|
||||
t:eq(tags.albumartist, "Band", "album artist")
|
||||
t:eq(tags["cover art (front)"], nil, "binary item not a tag")
|
||||
t:eq(info.start, 10, "start at the header")
|
||||
t:eq(info.stop, #s, "stop")
|
||||
t:eq(info.version, 2000, "version")
|
||||
t:eq(#info.items, 6, "items")
|
||||
t:eq(info.items[5].kind, "binary", "binary kind")
|
||||
t:eq(info.items[5].value, "f.png\0PNG", "binary value")
|
||||
-- ID3v1 after it
|
||||
local s2 = s .. "TAG" .. string.rep("x", 125)
|
||||
local tags2, info2 = ApeTag.find(buffer.fromstring(s2), 0, #s2)
|
||||
t:check(tags2 and tags2.title == "Hello" and info2.stop == #s, "before ID3v1")
|
||||
-- inside a sub-range
|
||||
local s3 = "zz" .. s .. "yyy"
|
||||
local tags3, info3 = ApeTag.find(buffer.fromstring(s3), 2, 2 + #s)
|
||||
t:check(tags3 and tags3.title == "Hello" and info3.start == 12, "sub-range")
|
||||
-- the start bounds the header
|
||||
local tags4, info4 = ApeTag.find(b, 50, #s)
|
||||
t:check(tags4 == nil and info4 == nil, "items before start")
|
||||
end
|
||||
do
|
||||
local s = tag({ { "Title", "Old" } }, 1000, false)
|
||||
local tags, info = ApeTag.find(buffer.fromstring(s), 0, #s)
|
||||
t:check(tags and tags.title == "Old" and info.start == 0 and info.version == 1000, "v1")
|
||||
t:eq(ApeTag.find(buffer.fromstring("no tag here at all, not even close to it"), 0, 40), nil, "none")
|
||||
end
|
||||
-- malformed: a huge item length, a huge count, a size larger than the file
|
||||
do
|
||||
local s = tag({ { "Title", "Hello" } }, 2000, false)
|
||||
local bad = string.sub(s, 1, 0) .. u32(0x7FFFFFFF) .. string.sub(s, 5)
|
||||
local tags = ApeTag.find(buffer.fromstring(bad), 0, #bad)
|
||||
t:check(tags and tags.title == nil, "bad item length stops")
|
||||
local big = string.sub(s, 1, #s - 32 + 12) .. u32(1e9) .. string.sub(s, #s - 32 + 17)
|
||||
t:eq(ApeTag.find(buffer.fromstring(big), 0, #big), nil, "size past the start")
|
||||
end
|
||||
|
||||
local samples = {
|
||||
buffer.fromstring("data" .. tag({ { "Title", "Hello" }, { "Artist", "X" } }, 2000, true)),
|
||||
buffer.fromstring(tag({ { "A", "b" } }, 1000, false) .. "TAG" .. string.rep("\0", 125)),
|
||||
}
|
||||
t:fuzz("find", function(b: buffer)
|
||||
return ApeTag.find(b, 0, buffer.len(b))
|
||||
end, samples, { mutations = 400 })
|
||||
t:done()
|
||||
@@ -0,0 +1,58 @@
|
||||
-- codecs/audio/Musepack tests: the codec API under audio/mpc: magic, the stream fields of SV7 / SV8 fixtures (version,
|
||||
-- rate, channels, band count, packet layout, gapless length), packets decoded by hand against libmpcdec (the
|
||||
-- synthesis delay at the front), out-of-order decodes, and a fuzz pass over open + every packet. Fixtures:
|
||||
-- tools/fixtures/mpc.py.
|
||||
local T = require("@tests/T")
|
||||
local Musepack = require("@formats/codecs/audio/Musepack")
|
||||
local Fx = require("@tests/gen/mpc_cases")
|
||||
|
||||
local t = T.suite("codecs/musepack")
|
||||
|
||||
for _, c in Fx do
|
||||
local b = buffer.fromstring(c.data)
|
||||
t:eq(Musepack.magic(b, 0, buffer.len(b)), c.version, c.name .. ": magic")
|
||||
local s, err = Musepack.open(b, 0, buffer.len(b))
|
||||
t:check(s, c.name .. ": open: " .. tostring(err))
|
||||
if not s then
|
||||
continue
|
||||
end
|
||||
t:check(s.version == c.version and s.sampleRate == c.rate and s.channels == c.channels, c.name .. ": fields")
|
||||
t:eq(s.frames, c.frames, c.name .. ": gapless length")
|
||||
t:check(s.maxBand >= 1 and s.maxBand <= 31 and s.count >= 1 and s.skip >= 481, c.name .. ": bands / packets")
|
||||
t:eq(s.stop - s.skip, c.frames, c.name .. ": stop - skip = length")
|
||||
-- the first packet by hand: output frame k is raw frame skip + k
|
||||
local n = s.decode(1)
|
||||
t:check(n and n > 0 and n % 1152 == 0 and n <= s.blockFrames * 1152, c.name .. ": first packet length")
|
||||
local pcm = s.pcm()
|
||||
local rb = buffer.fromstring(c.ref)
|
||||
local ch = c.channels
|
||||
local maxd = 0
|
||||
for k = 0, math.min(500, (n :: number) - s.skip - 1) do
|
||||
for j = 1, ch do
|
||||
maxd = math.max(maxd, math.abs(pcm[(s.skip + k) * ch + j] - buffer.readf32(rb, (k * ch + j - 1) * 4)))
|
||||
end
|
||||
end
|
||||
t:check(maxd < 1e-5, string.format("%s: first packet matches libmpcdec (max diff %g)", c.name, maxd))
|
||||
if s.count >= 3 then
|
||||
s.reset()
|
||||
t:check(s.decode(3) ~= nil and s.decode(1) ~= nil, c.name .. ": decodes out of order after reset")
|
||||
end
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for _, c in Fx do
|
||||
table.insert(samples, string.sub(c.data, 1, 2500))
|
||||
end
|
||||
t:fuzz("open + every packet", function(b: buffer)
|
||||
local s = Musepack.open(b, 0, buffer.len(b))
|
||||
if s then
|
||||
for i = 1, math.min(s.count, 40) do
|
||||
if not s.decode(i) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
return s
|
||||
end, samples, { mutations = 25, keepHeader = 4 })
|
||||
|
||||
t:done()
|
||||
Reference in new issue
Block a user