audio perf: compat math.sign branch-free (WavPack on LuaJIT 1.7-2x), Opus MDCT running indices, SILK FIR12 rows, Vorbis residue / window / overlap-add loops without per-sample branches

This commit is contained in:
4DBug committed 2026-11-01 19:16:18 -06:00
1 parent 051aca5b74
commit 59c2438ca1
5 files changed
+165 -122

No files matched your search

+39 -50
View File
@@ -714,21 +714,27 @@ local function up2HQ(S: { number }, out: { number }, oo: number, inp: { number }
S[1], S[2], S[3], S[4], S[5], S[6] = s0, s1, s2, s3, s4, s5
end
-- FIR12 per phase ti, in tap order: FIR12[4 ti + 1 .. 4 ti + 4], FIR12[4 (11 - ti) + 4 .. 4 (11 - ti) + 1]
local FIR12_ROWS = table.create(12)
for ti = 0, 11 do
local f0, f1 = ti * 4, (11 - ti) * 4
FIR12_ROWS[ti + 1] = { FIR12[f0 + 1], FIR12[f0 + 2], FIR12[f0 + 3], FIR12[f0 + 4], FIR12[f1 + 4], FIR12[f1 + 3], FIR12[f1 + 2], FIR12[f1 + 1] }
end
local function iirFirInterpol(out: { number }, oo: number, buf: { number }, max_index_Q16: number, incr: number): number
local rows = FIR12_ROWS
local index_Q16 = 0
while index_Q16 < max_index_Q16 do
local ti = ((index_Q16 % 65536) * 12) // 65536
local r = rows[((index_Q16 % 65536) * 12) // 65536 + 1]
local b = index_Q16 // 65536 + 1 -- buf is 1-based
local f0 = ti * 4
local f1 = (11 - ti) * 4
local res_Q15 = buf[b] * FIR12[f0 + 1]
+ buf[b + 1] * FIR12[f0 + 2]
+ buf[b + 2] * FIR12[f0 + 3]
+ buf[b + 3] * FIR12[f0 + 4]
+ buf[b + 4] * FIR12[f1 + 4]
+ buf[b + 5] * FIR12[f1 + 3]
+ buf[b + 6] * FIR12[f1 + 2]
+ buf[b + 7] * FIR12[f1 + 1]
local res_Q15 = buf[b] * r[1]
+ buf[b + 1] * r[2]
+ buf[b + 2] * r[3]
+ buf[b + 3] * r[4]
+ buf[b + 4] * r[5]
+ buf[b + 5] * r[6]
+ buf[b + 6] * r[7]
+ buf[b + 7] * r[8]
out[oo] = sat16((res_Q15 + 16384) // 32768)
oo += 1
index_Q16 += incr
@@ -1316,52 +1322,35 @@ local function decodeCore(ch: any, ctrl: any, xq: { number }, xo: number, pulses
A_Q12_tmp[6], A_Q12_tmp[7], A_Q12_tmp[8], A_Q12_tmp[9], A_Q12_tmp[10]
local wide = order == 16
local a10, a11, a12, a13, a14, a15 = A_Q12_tmp[11], A_Q12_tmp[12], A_Q12_tmp[13], A_Q12_tmp[14], A_Q12_tmp[15], A_Q12_tmp[16]
-- the last 16 sLPC_Q14 values in locals, newest first (s1 = sLPC_Q14[MAX_LPC_ORDER + i - 1] in C)
local s1, s2, s3, s4, s5, s6, s7, s8 = sLPC_Q14[16], sLPC_Q14[15], sLPC_Q14[14], sLPC_Q14[13], sLPC_Q14[12], sLPC_Q14[11], sLPC_Q14[10], sLPC_Q14[9]
local s9, s10, s11, s12, s13, s14, s15, s16 = sLPC_Q14[8], sLPC_Q14[7], sLPC_Q14[6], sLPC_Q14[5], sLPC_Q14[4], sLPC_Q14[3], sLPC_Q14[2], sLPC_Q14[1]
local half = order // 2
for i = 1, subfr_length do
local pred = half
pred += (s1 * a0) // 65536
pred += (s2 * a1) // 65536
pred += (s3 * a2) // 65536
pred += (s4 * a3) // 65536
pred += (s5 * a4) // 65536
pred += (s6 * a5) // 65536
pred += (s7 * a6) // 65536
pred += (s8 * a7) // 65536
pred += (s9 * a8) // 65536
pred += (s10 * a9) // 65536
local j = 16 + i -- 1-based index of sLPC_Q14[MAX_LPC_ORDER + i - 1 (C)] + 1
local pred = order // 2
pred += (sLPC_Q14[j - 1] * a0) // 65536
pred += (sLPC_Q14[j - 2] * a1) // 65536
pred += (sLPC_Q14[j - 3] * a2) // 65536
pred += (sLPC_Q14[j - 4] * a3) // 65536
pred += (sLPC_Q14[j - 5] * a4) // 65536
pred += (sLPC_Q14[j - 6] * a5) // 65536
pred += (sLPC_Q14[j - 7] * a6) // 65536
pred += (sLPC_Q14[j - 8] * a7) // 65536
pred += (sLPC_Q14[j - 9] * a8) // 65536
pred += (sLPC_Q14[j - 10] * a9) // 65536
if wide then
pred += (s11 * a10) // 65536
pred += (s12 * a11) // 65536
pred += (s13 * a12) // 65536
pred += (s14 * a13) // 65536
pred += (s15 * a14) // 65536
pred += (s16 * a15) // 65536
pred += (sLPC_Q14[j - 11] * a10) // 65536
pred += (sLPC_Q14[j - 12] * a11) // 65536
pred += (sLPC_Q14[j - 13] * a12) // 65536
pred += (sLPC_Q14[j - 14] * a13) // 65536
pred += (sLPC_Q14[j - 15] * a14) // 65536
pred += (sLPC_Q14[j - 16] * a15) // 65536
end
pred = i32(pred)
local v = addSat32(presArr[presOff + i], lshiftSat32(pred, 4))
s16 = s15
s15 = s14
s14 = s13
s13 = s12
s12 = s11
s11 = s10
s10 = s9
s9 = s8
s8 = s7
s7 = s6
s6 = s5
s5 = s4
s4 = s3
s3 = s2
s2 = s1
s1 = v
sLPC_Q14[j] = v
xq[pxq + i - 1] = sat16((mulww(v, Gain_Q10) + 128) // 256)
end
sLPC_Q14[16], sLPC_Q14[15], sLPC_Q14[14], sLPC_Q14[13], sLPC_Q14[12], sLPC_Q14[11], sLPC_Q14[10], sLPC_Q14[9] = s1, s2, s3, s4, s5, s6, s7, s8
sLPC_Q14[8], sLPC_Q14[7], sLPC_Q14[6], sLPC_Q14[5], sLPC_Q14[4], sLPC_Q14[3], sLPC_Q14[2], sLPC_Q14[1] = s9, s10, s11, s12, s13, s14, s15, s16
for i = 1, 16 do
sLPC_Q14[i] = sLPC_Q14[subfr_length + i]
end
pexc += subfr_length
pxq += subfr_length
end