ws-audio2: music/mtm (MultiTracker) on the tracker engine; engine: m.engine family, m.preamp, flags (periods amiga/hz, fastPortas, autoTonePorta, autoReset, st2Tempo, oktSlides), extension effects (note slides, auto portamento, frequency adjust), codecs/audio/Tracker/Load helpers (OpenMPT BSD)
Engine changes are backward compatible: m.engine defaults to m.format; the channel / sample / instrument global volumes now apply in every family (defaults leave MOD / S3M / XM unchanged); mod/s3m/xm/it tests green.
This commit is contained in:
1 parent
de4f14a343
commit
384cdc407d
13 files changed
+1026
-52
No files matched your search
@@ -206,4 +206,79 @@ function S.worst(a: any, b: any, count: number): { { number } }
|
||||
return out
|
||||
end
|
||||
|
||||
-- against(t, Fmt, cases, thresh, family?): the shared body of the tracker loader tests (ws-audio2: mtm, 669, stm, ult,
|
||||
-- okt, med, ptm, far, umx): each case decodes, sniffs, plays as long as openmpt's render (thresh.duration s) and
|
||||
-- matches its loudness / envelope / spectrum / balance within thresh; then a seek. cases: { name, data, ref,
|
||||
-- duration }. Returns the decoded modules. The tests run their fuzz pass with S.fuzzer / S.samples.
|
||||
function S.against(t: any, Fmt: any, cases: { any }, thresh: any, family: string?): { any }
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Tracker = require("@formats/codecs/audio/Tracker")
|
||||
local mods = {}
|
||||
for _, c in cases do
|
||||
local m, err = Fmt.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
t:check(m, c.name .. ": " .. tostring(err))
|
||||
if not m then
|
||||
continue
|
||||
end
|
||||
table.insert(mods, m)
|
||||
t:eq(m.format, Fmt.name, c.name .. ": format")
|
||||
if family then
|
||||
t:eq(Tracker.family(m), family, c.name .. ": engine family")
|
||||
end
|
||||
t:check(Fmt.sniff(Bytes.reader(buffer.fromstring(c.data))) > 0, c.name .. ": sniff")
|
||||
local dec = m:render({ sampleRate = S.SR })
|
||||
t:check(dec, c.name .. ": render")
|
||||
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 f = S.features(buf, frames)
|
||||
local r = S.compare(f, c.ref)
|
||||
t:note("%-8s gain %+.2f dB, loudness error %.2f dB, spectrum %.3f, balance %.3f, %.2f s", c.name, r.gainDb, r.envErr, r.spectral, r.balance, dec.duration)
|
||||
if r.spectral < thresh.spectral or r.envErr > thresh.envErr then
|
||||
for _, w in S.worst(f, c.ref, 6) do
|
||||
t:note(" block %d (%.2f s): spectrum %.3f, ours %.1f dB, ref %.1f dB", w[1], (w[1] - 1) * 2048 / S.SR, w[2], w[3], w[4])
|
||||
end
|
||||
end
|
||||
t:check(math.abs(r.gainDb) < thresh.gainDb, c.name .. ": loudness")
|
||||
t:check(r.envErr < thresh.envErr, c.name .. ": loudness envelope")
|
||||
t:check(r.spectral > thresh.spectral, c.name .. ": spectrum")
|
||||
t:check(r.balance < thresh.balance, c.name .. ": stereo balance")
|
||||
end
|
||||
-- seek: the position after a seek and the output continuing
|
||||
local m = mods[1]
|
||||
if m then
|
||||
local dec = m:render()
|
||||
dec:seek(1)
|
||||
t:check(math.abs(dec:position() - 1) < 0.001, "seek position")
|
||||
local _, n = dec:read(1000)
|
||||
t:eq(n, 1000, "read after seek")
|
||||
t:check(Tracker.duration(m) == dec.duration, "duration()")
|
||||
end
|
||||
return mods
|
||||
end
|
||||
|
||||
-- fuzzer(Fmt) -> the fuzz function of a tracker loader: decode, and a short render of whatever decodes
|
||||
function S.fuzzer(Fmt: any): (buffer) -> any
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Tracker = require("@formats/codecs/audio/Tracker")
|
||||
return function(b: buffer): any
|
||||
local fm = Fmt.decode(Bytes.reader(b))
|
||||
if fm then
|
||||
local d = Tracker.render(fm, { maxDuration = 0.5, sampleRate = 8000 })
|
||||
if d then
|
||||
d:read(4000)
|
||||
end
|
||||
end
|
||||
return fm
|
||||
end
|
||||
end
|
||||
|
||||
-- samples(cases) -> the fuzz seeds (each case's data)
|
||||
function S.samples(cases: { any }): { string }
|
||||
local out = {}
|
||||
for _, c in cases do
|
||||
table.insert(out, c.data)
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
return S
|
||||
@@ -0,0 +1,20 @@
|
||||
-- music/mtm tests: generated MultiTracker modules (tools/fixtures/mtm.py) parsed, rendered through codecs/audio/Tracker
|
||||
-- and compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song length), the contract,
|
||||
-- and the fuzz no-throw pass.
|
||||
local T = require("@tests/T")
|
||||
local S = require("@tests/music/_similar")
|
||||
local Mtm = require("@formats/music/mtm")
|
||||
local Cases = require("@tests/gen/mtm_cases")
|
||||
|
||||
local t = T.suite("mtm")
|
||||
|
||||
t:eq(Mtm.name, "mtm", "name")
|
||||
t:eq(Mtm.category, "music", "category")
|
||||
t:check(Mtm.caps.decode and not Mtm.caps.encode, "caps")
|
||||
|
||||
local mods = S.against(t, Mtm, Cases, { gainDb = 0.5, envErr = 1.0, spectral = 0.95, balance = 0.04, duration = 0.01 }, "xm")
|
||||
t:check(mods[1] and #mods[1].samples == 5 and mods[1].samples[3].bits == 16, "16-bit sample")
|
||||
t:check(mods[1] and mods[1].meta.message ~= nil, "message")
|
||||
|
||||
t:fuzz("decode", S.fuzzer(Mtm), S.samples(Cases), { mutations = 30 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user