-- music/umx tests: Unreal packages wrapping generated S3M / IT modules, rendered like openmpt123 renders the package. -- Fixtures: tools/fixtures/umx.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local F = require("@rosetta") local Umx = require("@rosetta/music/umx") local Bytes = require("@rosetta/core/Bytes") local Cases = require("@tests/gen/umx_cases") local t = T.suite("umx") t:eq(Umx.name, "umx", "name") t:eq(Umx.category, "music", "category") t:check(Umx.caps.decode and not Umx.caps.encode, "caps") local THRESH = { gainDb = 0.5, envErr = 1.0, spectral = 0.95, balance = 0.04, duration = 0.01 } local function hook(b: buffer, format: string?): (any, any) return F.load(b, { category = "music", format = format }) end for _, c in Cases do local r = Bytes.reader(buffer.fromstring(c.data)) t:check(Umx.sniff(r) == 1, c.name .. ": sniff") local list = Umx.extract(r) t:check(list and #list == 1 and list[1].name == string.lower(c.name) and list[1].format == c.format, c.name .. ": extract") t:eq(list and buffer.tostring(list[1].data), c.inner, c.name .. ": the embedded module's bytes") local _, err = Umx.decode(Bytes.reader(buffer.fromstring(c.data))) t:check(err and err.code == F.Err.UNSUPPORTED, c.name .. ": no hook: UNSUPPORTED") local m, merr = Umx.decode(Bytes.reader(buffer.fromstring(c.data)), { decodeModule = hook }) t:check(m and m.format == c.format and m.meta.container.format == "umx", c.name .. ": decode " .. tostring(merr)) local viaApi = F.load(c.data) t:check(viaApi and viaApi.kind == "music" and viaApi.meta.container and viaApi.meta.container.name == string.lower(c.name), c.name .. ": F.load") t:eq(F.detect(c.data), "umx", c.name .. ": F.detect") local dec = m:render({ sampleRate = S.SR }) t:check(math.abs(dec.duration - c.duration) < THRESH.duration, string.format("%s: duration %.3f s, openmpt %.3f s", c.name, dec.duration, c.duration)) local buf, frames = S.renderAll(dec, math.floor(c.duration * S.SR)) local res = S.compare(S.features(buf, frames), c.ref) t:note("%-10s gain %+.2f dB, loudness error %.2f dB, spectrum %.3f, balance %.3f, %.2f s", c.name, res.gainDb, res.envErr, res.spectral, res.balance, dec.duration) t:check(math.abs(res.gainDb) < THRESH.gainDb and res.envErr < THRESH.envErr, c.name .. ": loudness") t:check(res.spectral > THRESH.spectral and res.balance < THRESH.balance, c.name .. ": spectrum, balance") local d2 = F.open(c.data) t:check(d2 and d2.channels == 2, c.name .. ": F.open renders") end t:fuzz("decode", function(b: buffer) local m = Umx.decode(Bytes.reader(b), { decodeModule = hook }) Umx.extract(Bytes.reader(b)) return m end, S.samples(Cases), { mutations = 30 }) t:done()