55 lines
2.2 KiB
Luau
55 lines
2.2 KiB
Luau
-- 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.
|
|
local T = require("@tests/T")
|
|
local Brstm = require("@rosetta/audio/brstm")
|
|
local Bytes = require("@rosetta/core/Bytes")
|
|
local Err = require("@rosetta/core/Err")
|
|
local F = require("@rosetta")
|
|
local H = require("@tests/audio/_adpcm")
|
|
local Cases = require("@tests/gen/brstm_cases")
|
|
|
|
local t = T.suite("brstm")
|
|
t:eq(Brstm.name, "brstm", "name")
|
|
|
|
local samples = {}
|
|
for _, c in Cases do
|
|
table.insert(samples, c.data)
|
|
t:eq(Brstm.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, c.name .. ": sniff")
|
|
H.check(t, Brstm, c)
|
|
local flavour = ({ RSTM = "brstm", CSTM = "bcstm", FSTM = "bfstm" })[string.sub(c.data, 1, 4)]
|
|
t:eq(F.detect(c.data), flavour, c.name .. ": F.detect names the flavour")
|
|
t:check(F.format(flavour) ~= nil or F.format("brstm") ~= nil, c.name .. ": the flavour resolves")
|
|
end
|
|
t:note("%d files bit-exact with vgmstream", #Cases)
|
|
|
|
do
|
|
local base = Cases[1].data
|
|
local function fails(b: buffer, code: string, label: string)
|
|
local d, e = Brstm.open(Bytes.reader(b))
|
|
t:check(d == nil and e and e.code == code, label .. ": " .. tostring(e))
|
|
end
|
|
local beta = buffer.fromstring(base)
|
|
buffer.writeu16(beta, 6, 0x0100) -- bytes 01 00 read big-endian: version 0.1
|
|
fails(beta, Err.UNSUPPORTED, "version 0.1")
|
|
fails(buffer.fromstring(string.sub(base, 1, 0x30)), Err.TRUNCATED, "short")
|
|
fails(buffer.fromstring("RSTM\254\255\1\0" .. string.rep("\0", 100)), Err.CORRUPT, "no HEAD")
|
|
local a = F.audio.load(Cases[2].data)
|
|
t:check(a and a.meta.source.loop and a.meta.source.loop.start == Cases[2].loopStart, "F.audio.load keeps the loop")
|
|
end
|
|
|
|
t:fuzz("open + read + seek", function(b: buffer)
|
|
local dec = Brstm.open(Bytes.reader(b))
|
|
if dec then
|
|
dec:read(100000)
|
|
dec:seek(dec.duration / 2)
|
|
dec:read(33)
|
|
end
|
|
return dec
|
|
end, samples, { mutations = 8 })
|
|
t:fuzz("header", function(b: buffer)
|
|
return Brstm.decode(Bytes.reader(b))
|
|
end, samples, { mutations = 12, keepHeader = 0, garbage = 50 })
|
|
|
|
t:done()
|