68 lines
2.4 KiB
Luau
68 lines
2.4 KiB
Luau
-- music/hvl tests: HVL songs (tools/fixtures/_hively.py, HivelyTracker's) rendered by codecs/audio/Hively vs hvl2wav.
|
|
-- Fixtures: tools/fixtures/hvl.py.
|
|
local T = require("@tests/T")
|
|
local H = require("@tests/music/_hively")
|
|
local Hvl = require("@rosetta/music/hvl")
|
|
local Bytes = require("@rosetta/core/Bytes")
|
|
local Err = require("@rosetta/core/Err")
|
|
local Cases = require("@tests/gen/hvl_cases")
|
|
|
|
local t = T.suite("hvl")
|
|
|
|
t:eq(Hvl.name, "hvl", "name")
|
|
t:eq(Hvl.category, "music", "category")
|
|
t:check(Hvl.caps.decode and not Hvl.caps.encode, "caps")
|
|
t:eq(Hvl.sniff(Bytes.reader(buffer.fromstring("THX\1"))), 0, "sniff AHX")
|
|
|
|
local samples = {}
|
|
for _, c in Cases do
|
|
local song = H.check(t, Hvl, c)
|
|
if song and c.name == "demo" then
|
|
t:eq(song.kind, "music", "kind")
|
|
t:eq(song.format, "hvl", "format")
|
|
t:eq(song.title, "demo", "title")
|
|
t:eq(song.channels, 6, "channels")
|
|
t:eq(song.meta.source.stereo, 3, "stereo")
|
|
t:eq(#song.instruments, 6, "instruments")
|
|
t:eq(#song.order, 2, "positions")
|
|
t:eq(song.instruments[1].name, "tri", "instrument name")
|
|
t:eq(#song.instruments[3].plist.entries, 4, "play list")
|
|
t:eq(song.patterns[2].rows, 16, "track rows")
|
|
t:eq(buffer.readu8(song.patterns[2].data, 0), 25, "track 1 row 0 note")
|
|
t:eq(#song.subsongs, 1, "subsongs")
|
|
local dec = song:render()
|
|
local a = dec:read(4410)
|
|
dec:seek(0.5)
|
|
dec:seek(0)
|
|
local b = dec:read(4410)
|
|
t:check(buffer.tostring(a) == buffer.tostring(b), "seek restarts exactly")
|
|
end
|
|
if #samples < 4 then
|
|
table.insert(samples, buffer.fromstring(c.data))
|
|
end
|
|
end
|
|
|
|
local function code(s: string): string?
|
|
local _, e = Hvl.decode(Bytes.reader(buffer.fromstring(s)))
|
|
return e and e.code
|
|
end
|
|
t:eq(code("HVL\1\0\16\0\1\0"), Err.TRUNCATED, "short header")
|
|
t:eq(code("HVL\1\0\16\0\0\0\0\16\0\0\0\100\2"), Err.CORRUPT, "no positions")
|
|
t:eq(code("HVL\1\0\16\0\1\255\0\16\0\0\0\100\2"), Err.UNSUPPORTED, "67 channels")
|
|
t:eq(code(string.sub(Cases[1].data, 1, 60)), Err.TRUNCATED, "truncated")
|
|
local song = assert(Hvl.decode(Bytes.reader(buffer.fromstring(Cases[1].data))))
|
|
t:check(song:render({ subsong = 9 }).err ~= nil, "subsong out of range")
|
|
|
|
t:fuzz("decode", function(b: buffer)
|
|
return Hvl.decode(Bytes.reader(b))
|
|
end, samples)
|
|
t:fuzz("decode + render", function(b: buffer)
|
|
local s = Hvl.decode(Bytes.reader(b))
|
|
if s then
|
|
local d = s:render({ sampleRate = 8000, maxDuration = 0.5 })
|
|
d:read(4000)
|
|
end
|
|
return s
|
|
end, samples, { mutations = 150, garbage = 20 })
|
|
t:done()
|