audio perf: Tracker mixer fast path for mono interpolated voices (after the ramp, unchecked while in range)

This commit is contained in:
4DBug committed 2026-11-01 19:31:09 -06:00
1 parent 8b07f26666
commit 0d05130526
1 file changed
+45 -1
+45 -1
View File
@@ -88,7 +88,10 @@ local function mixVoice(v: any, out: buffer?, off: number, n: number, linear: bo
local fa, fb0, fb1 = v.fa, v.fb0, v.fb1
local y1l, y2l, y1r, y2r = v.y1l, v.y2l, v.y1r, v.y2r
local o = (off + i) * 8
for _ = 1, m do
-- the common voice (mono, interpolated, unfiltered) runs the general loop only while its volume ramps
local fast = nch == 1 and linear and not fOn
local mg = if fast then (if rl > 0 then min(rl, m) else 0) else m
for _ = 1, mg do
local idx = floor(p)
if idx > hi then
idx = hi
@@ -149,6 +152,47 @@ local function mixVoice(v: any, out: buffer?, off: number, n: number, linear: bo
o += 8
p += step
end
if mg < m then -- the general loop, specialised to the fast voice after its ramp
local k0 = mg + 1
if step >= 0.001 and p >= 0 and s >= 0 and e <= len then
-- while p < e - 1, idx = floor(p) is in range and idx + 1 < e needs no wrap; two steps of margin
-- for the rounding of the running p
local safe = min(m, mg + floor((e - 1 - p) / step) - 2)
for _ = k0, safe do
local idx = floor(p)
local a = readf32(data, idx * 4)
local x = a + (readf32(data, idx * 4 + 4) - a) * (p - idx)
writef32(out, o, readf32(out, o) + x * gl)
writef32(out, o + 4, readf32(out, o + 4) + x * gr)
o += 8
p += step
end
if safe >= k0 then
k0 = safe + 1
end
end
for _ = k0, m do
local idx = floor(p)
if idx > hi then
idx = hi
elseif idx < 0 then
idx = 0
end
local j = idx + 1
if j >= e then
j = wrapJ
end
if j > hi then
j = hi
end
local a = readf32(data, idx * 4)
local x = a + (readf32(data, j * 4) - a) * (p - idx)
writef32(out, o, readf32(out, o) + x * gl)
writef32(out, o + 4, readf32(out, o + 4) + x * gr)
o += 8
p += step
end
end
v.p = p
v.gl, v.gr, v.rampN = gl, gr, rl
v.y1l, v.y2l, v.y1r, v.y2r = y1l, y2l, y1r, y2r