ws-music: music/s3m read + render (OpenMPT-matched master volume / mono rule / default panning), finer comparison bands, voice ownership fix
This commit is contained in:
1 parent
ac3e143ce8
commit
cf7c1b8ad2
12 files changed
+598
-15
No files matched your search
@@ -23,7 +23,7 @@ local MOD, S3M, XM, IT = 1, 2, 3, 4
|
||||
Player.MOD, Player.S3M, Player.XM, Player.IT = MOD, S3M, XM, IT
|
||||
local FAMILY = { mod = MOD, s3m = S3M, xm = XM, it = IT }
|
||||
|
||||
local MAX_VOICES = 96 -- channels + IT background voices
|
||||
local BG_VOICES = 64 -- voices beyond one per channel, for IT new note actions
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ state
|
||||
local function newVoice(): any
|
||||
@@ -86,6 +86,7 @@ local function newVoice(): any
|
||||
tremorMute = false,
|
||||
surround = false,
|
||||
rampN = 0,
|
||||
owner = 0, -- the channel whose foreground voice this is (0: free or background)
|
||||
order = 0, -- allocation age
|
||||
}
|
||||
end
|
||||
@@ -225,7 +226,7 @@ function Player.new(m: any, sampleRate: number, opts: any): any
|
||||
end
|
||||
st.chans[i] = c
|
||||
end
|
||||
for i = 1, MAX_VOICES do
|
||||
for i = 1, m.channels + BG_VOICES do
|
||||
st.voices[i] = newVoice()
|
||||
end
|
||||
st.master = Player.masterGain(m, fmt)
|
||||
@@ -239,7 +240,7 @@ 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 0.5 * (m.mixVolume or 48) / 48
|
||||
return (m.mixVolume or 48) / 128 -- OpenMPT: linear in the master volume, 64 = 0.5
|
||||
end
|
||||
-- MOD: OpenMPT scales by the channel count (4 channels: 0.5; 2 / channels between 2 and 8)
|
||||
return 2 / clamp(m.channels, 2, 8)
|
||||
@@ -361,7 +362,7 @@ end
|
||||
local function allocVoice(st: any): any
|
||||
local best, bestScore = nil, math.huge
|
||||
for _, v in st.voices do
|
||||
if not v.active then
|
||||
if not v.active and v.owner == 0 then
|
||||
return v
|
||||
end
|
||||
if v.bg then
|
||||
@@ -375,7 +376,17 @@ local function allocVoice(st: any): any
|
||||
best.active = false
|
||||
return best
|
||||
end
|
||||
return st.voices[1] -- unreachable while MAX_VOICES > channels: every channel holds one foreground voice
|
||||
-- every voice is busy in the foreground (more channels than voices): reuse an inactive one anyway
|
||||
for _, v in st.voices do
|
||||
if not v.active then
|
||||
local c = st.chans[v.owner]
|
||||
if c and c.voice == v then
|
||||
c.voice = nil
|
||||
end
|
||||
return v
|
||||
end
|
||||
end
|
||||
return st.voices[1] -- unreachable: there are more voices than channels
|
||||
end
|
||||
|
||||
local function keyOff(st: any, v: any)
|
||||
@@ -422,6 +433,7 @@ local function startVoice(st: any, c: any, smp: any, smpIdx: number, ins: any, i
|
||||
if v == nil or v.bg then
|
||||
v = allocVoice(st)
|
||||
c.voice = v
|
||||
v.owner = c.idx
|
||||
end
|
||||
local wasActive = v.active
|
||||
v.active = smp.length > 0 and smp.data ~= nil
|
||||
@@ -494,6 +506,7 @@ local function newNoteAction(st: any, c: any, ins: any, insIdx: number, note: nu
|
||||
return
|
||||
end
|
||||
v.bg = true
|
||||
v.owner = 0
|
||||
c.voice = nil
|
||||
if nna == 2 then
|
||||
keyOff(st, v)
|
||||
|
||||
Reference in new issue
Block a user