ws-music: music/it read + render (IT 2.14/2.15 decompression, NNA, filters, pitch-pan, OpenMPT note-fade coding), tracker tests tightened, MOD->XM + API checks, tracker bench lines, NOTICE

This commit is contained in:
4DBug committed 2026-10-31 09:31:34 -05:00
1 parent 8b8b64885f
commit 7754646a86
14 files changed
+964 -28

No files matched your search

+34 -17
View File
@@ -102,6 +102,7 @@ local function newChannel(i: number, pan: number, vol: number): any
smp = nil :: any,
vol = 0,
pan = pan,
basePan = pan,
chanVol = vol,
period = 0,
target = 0,
@@ -220,6 +221,7 @@ function Player.new(m: any, sampleRate: number, opts: any): any
local pan = m.channelPan[i] or 128
local cv = m.channelVolume[i] or 64
local c = newChannel(i, pan, cv)
c.basePan = pan
c.muted = m.channelMute[i] or false
if pan == 512 then -- surround marker
c.pan = 128
@@ -238,10 +240,8 @@ end
-- the output scale per format, calibrated against OpenMPT's default mix levels (tools/fixtures: a full-scale sine at
-- volume 64 on one centred channel)
function Player.masterGain(m: any, fmt: number): number
if fmt == IT then
return 0.5 * (m.mixVolume or 48) / 48
elseif fmt == S3M then
return (m.mixVolume or 48) / 128 -- OpenMPT: linear in the master volume, 64 = 0.5
if fmt == IT or fmt == S3M then
return (m.mixVolume or 48) / 128 -- OpenMPT: linear in the mix / master volume, 64 = 0.5
end
if fmt == XM then
return 0.375 -- OpenMPT's XM pre-amp (48 / 128), whatever the channel count
@@ -557,16 +557,21 @@ end
local function setInstrumentDefaults(st: any, c: any, smp: any, ins: any)
if smp then
c.vol = smp.volume
if smp.pan then
c.pan = smp.pan
end
if st.fmt == IT then
-- IT: a sample's or instrument's default panning holds for its notes; the channel panning (set by the
-- effects) comes back for the others
local p = (smp and smp.pan) or (ins and ins.pan)
c.pan = p or c.basePan
if p then
c.surround = false
end
elseif smp and smp.pan then
c.pan = smp.pan
c.basePan = c.pan
c.surround = false
end
if ins and st.fmt == IT then
if ins.pan and not (smp and smp.pan) then
c.pan = ins.pan
c.surround = false
end
if ins.cutoff then
c.cutoff = ins.cutoff
end
@@ -615,7 +620,6 @@ local function trigger(st: any, c: any, note: number, insIdx: number, vcmd: numb
if insIdx > 0 then
local valid = if st.insMode then m.instruments[insIdx] ~= nil else m.samples[insIdx] ~= nil
if valid then
local prev = c.insIdx
c.insIdx = insIdx
local n = if hasNote then note else c.note
local smp, _, ins = resolve(st, insIdx, if n > 0 then n else 61)
@@ -673,6 +677,7 @@ local function trigger(st: any, c: any, note: number, insIdx: number, vcmd: numb
c.tremorOn = true
c.retrigCount = 0
v = startVoice(st, c, smp, smpIdx, ins, useIns, realNote, period, base, keep)
v.patNote = note
c.period, c.target, c.base = period, period, base
c.note, c.realNote = note, realNote
c.smp, c.smpIdx = smp, smpIdx
@@ -724,6 +729,7 @@ local function trigger(st: any, c: any, note: number, insIdx: number, vcmd: numb
c.vol = vcmd - 0x10
elseif vcmd >= 0xC0 and vcmd <= 0xCF then
c.pan = (vcmd - 0xC0) * 16
c.basePan = c.pan
end
elseif f == IT then
local v = vcmd - 1
@@ -731,6 +737,7 @@ local function trigger(st: any, c: any, note: number, insIdx: number, vcmd: numb
c.vol = v
elseif v >= 128 and v <= 192 then
c.pan = (v - 128) * 4
c.basePan = c.pan
c.surround = false
end
end
@@ -748,7 +755,7 @@ local function volSlideMod(c: any, param: number)
end
local function tonePorta(st: any, c: any, speed: number)
if c.target == 0 or c.period == c.target then
if c.period == c.target then
return
end
if c.period < c.target then
@@ -874,6 +881,7 @@ local function fxModXm(st: any, c: any, tick: number)
elseif fx == 8 then
if tick == 0 then
c.pan = param
c.basePan = c.pan
c.surround = false
end
elseif fx == 0xB then
@@ -935,6 +943,7 @@ local function fxModXm(st: any, c: any, tick: number)
elseif x == 8 then
if tick == 0 then -- FT2 ignores E8x in XM; OpenMPT (the reference) applies it
c.pan = y * 17
c.basePan = c.pan
c.surround = false
end
elseif x == 9 then
@@ -1011,8 +1020,10 @@ local function fxModXm(st: any, c: any, tick: number)
local px, py = p // 16, p % 16
if px > 0 then
c.pan = min(255, c.pan + px)
c.basePan = c.pan
else
c.pan = max(0, c.pan - py)
c.basePan = c.pan
end
end
elseif fx == 27 then -- R
@@ -1115,10 +1126,12 @@ local function volColXm(st: any, c: any, tick: number)
elseif hi == 0xD then
if tick > 0 then
c.pan = max(0, c.pan - lo)
c.basePan = c.pan
end
elseif hi == 0xE then
if tick > 0 then
c.pan = min(255, c.pan + lo)
c.basePan = c.pan
end
elseif hi == 0xF then
if lo > 0 then
@@ -1230,6 +1243,7 @@ local function fxS3mIt(st: any, c: any, tick: number)
end
end
c.pan = pan64 * 4
c.basePan = c.pan
c.surround = false
elseif fx == 17 then -- Q retrigger + volume change
local p = mem(st, c, "mRetrig", param)
@@ -1308,6 +1322,7 @@ local function fxS3mIt(st: any, c: any, tick: number)
elseif x == 8 then
if tick == 0 then
c.pan = y * 17
c.basePan = c.pan
c.surround = false
end
elseif x == 9 then
@@ -1382,9 +1397,11 @@ local function fxS3mIt(st: any, c: any, tick: number)
if tick == 0 then
if it then
c.pan = param
c.basePan = c.pan
c.surround = false
elseif param <= 0x80 then
c.pan = param * 2
c.basePan = c.pan
c.surround = false
elseif param == 0xA4 then
c.surround = true
@@ -1753,13 +1770,13 @@ local function updateVoice(st: any, v: any)
end
-- panning
local pan = v.pan
if it and ins and (ins.pps or 0) ~= 0 then
pan = clamp(pan + ((v.patNote or v.note) - (ins.ppc or 60) - 1) * ins.pps / 2, 0, 256)
end
if envPan ~= 0 then
local range = 128 - abs(pan - 128)
pan += envPan * range / 32
end
if it and ins and (ins.pps or 0) ~= 0 then
pan += (v.note - (ins.ppc or 60) - 1) * ins.pps / 2
end
pan = clamp(pan, 0, 256)
pan = clamp(128 + (pan - 128) * st.separation, 0, 256)
local g = vol * st.master
@@ -1854,8 +1871,8 @@ function Player.tick(st: any): number
updateVoice(st, v)
end
end
-- frames for this tick: 2.5 / tempo seconds, rounded per tick as OpenMPT / FT2 do
local frames = floor(st.sr * 2.5 / max(1, st.tempo) + 0.5)
-- frames for this tick: 2.5 / tempo seconds, truncated per tick (as OpenMPT does)
local frames = floor(st.sr * 2.5 / max(1, st.tempo))
-- advance
st.tick += 1
if st.tick >= st.speed + st.fineDelay then
+9 -6
View File
@@ -70,6 +70,7 @@ export type Envelope = {
susEnd: number,
carry: boolean?,
filter: boolean?,
raw: any?, -- format-specific fields kept for a faithful re-save (XM)
}
export type Pattern = { rows: number, data: buffer }
@@ -262,12 +263,14 @@ local function fixEnvelope(e: any): (any, string?)
return e
end
local function fixLoop(s: number, e: number, t: number, len: number): (number, number, number)
if not num(t, 0, 2) or t == 0 then
local function fixLoop(s0: any, e0: any, t0: any, len: number): (number, number, number)
if not num(t0, 0, 2) or t0 == 0 or not num(s0, -2 ^ 52, 2 ^ 52) or not num(e0, -2 ^ 52, 2 ^ 52) then
return 0, 0, 0
end
s, e = math.floor(math.clamp(s, 0, len)), math.floor(math.clamp(e, 0, len))
if e - s < 1 then
local s: number = math.floor(math.clamp(s0, 0, len))
local e: number = math.floor(math.clamp(e0, 0, len))
local t: number = math.floor(t0)
if e - s < 1 or t == 0 then
return 0, 0, 0
end
if t == 2 and e - s < 2 then
@@ -378,7 +381,7 @@ function Tracker.validate(m: any): (boolean?, Err.Err?)
ins.resonance = nil
end
end
return true
return true, nil
end
-- ------------------------------------------------------------------------------------------------ rendering
@@ -402,7 +405,7 @@ function Tracker.duration(m: any, opts: RenderOptions?): (number?, Err.Err?)
end
frames += f
end
return math.min(frames, maxFrames) / sr
return math.min(frames, maxFrames) / sr, nil
end
local function newPlayer(self: any)