merge ws/perf-audio (Ogg page CRC via core Crc32.msb from ws/perf-core)

This commit is contained in:
4DBug committed 2026-11-01 20:57:10 -06:00
commit 6ddc5b6017
113 files changed
+4582 -2280

No files matched your search

+58 -28
View File
@@ -1,4 +1,5 @@
--!strict
--!optimize 2
-- ops/AudioOps: editing on the standard Audio: collect, gain, normalize, mix, remix, resample (codecs/audio/Resample),
-- trim, concat, fades, peak / RMS. New code.
-- Conventions: samples are the Audio's interleaved f32 (no clipping is applied: values past +-1 are kept, encoders
@@ -61,8 +62,8 @@ function AudioOps.gain(a: Types.Audio, factor: number): (Types.Audio?, Err.Err?)
local n = a.frames * a.channels
local out = like(a, a.channels, a.frames)
local s, d = a.samples, out.samples
for i = 0, n - 1 do
writef32(d, i * 4, readf32(s, i * 4) * factor)
for o = 0, n * 4 - 4, 4 do
writef32(d, o, readf32(s, o) * factor)
end
return out, nil
end
@@ -81,14 +82,17 @@ function AudioOps.peak(a: Types.Audio): (number?, { number } | Err.Err)
local ch = a.channels
local per = table.create(ch, 0)
local s = a.samples
for f = 0, a.frames - 1 do
local p = f * ch * 4
for c = 1, ch do
local v = abs(readf32(s, p + (c - 1) * 4))
if v > per[c] then
per[c] = v
local last, step = (a.frames - 1) * ch * 4, ch * 4
for c = 1, ch do
local pk = 0
for p = (c - 1) * 4, last + (c - 1) * 4, step do
local v = abs(readf32(s, p))
if v ~= v then
v = 0 -- NaN never counts
end
pk = max(pk, v) -- branch-free (LuaJIT)
end
per[c] = pk
end
local m = 0
for c = 1, ch do
@@ -104,12 +108,14 @@ function AudioOps.rms(a: Types.Audio): (number?, { number } | Err.Err)
local ch = a.channels
local per = table.create(ch, 0)
local s = a.samples
for f = 0, a.frames - 1 do
local p = f * ch * 4
for c = 1, ch do
local v = readf32(s, p + (c - 1) * 4)
per[c] += v * v
local last, step = (a.frames - 1) * ch * 4, ch * 4
for c = 1, ch do
local acc = 0
for p = (c - 1) * 4, last + (c - 1) * 4, step do
local v = readf32(s, p)
acc += v * v
end
per[c] = acc
end
local total = 0
local n = max(1, a.frames)
@@ -290,23 +296,47 @@ function AudioOps.remix(a: Types.Audio, channels: number, m: { { number } }?): (
end
local out = like(a, channels, a.frames)
local s, d = a.samples, out.samples
local x = table.create(from, 0)
for f = 0, a.frames - 1 do
local p = f * from * 4
local frames = a.frames
local inStep, outStep = from * 4, channels * 4
for o = 1, channels do
-- the row's non-zero weights, in input order: v = sum w * x[i]
local row = mm[o]
local ws, offs = {}, {}
for i = 1, from do
x[i] = readf32(s, p + (i - 1) * 4)
local w = row[i]
if w and w ~= 0 then
table.insert(ws, w)
table.insert(offs, (i - 1) * 4)
end
end
local q = f * channels * 4
for o = 1, channels do
local row = mm[o]
local v = 0
for i = 1, from do
local w = row[i]
if w and w ~= 0 then
v += w * x[i]
local q = (o - 1) * 4
local nt = #ws
if nt == 0 then
for _ = 1, frames do
writef32(d, q, 0)
q += outStep
end
elseif nt == 1 then
local w0, o0 = ws[1], offs[1]
for p = 0, (frames - 1) * inStep, inStep do
writef32(d, q, 0 + w0 * readf32(s, p + o0))
q += outStep
end
elseif nt == 2 then
local w0, o0, w1, o1 = ws[1], offs[1], ws[2], offs[2]
for p = 0, (frames - 1) * inStep, inStep do
writef32(d, q, 0 + w0 * readf32(s, p + o0) + w1 * readf32(s, p + o1))
q += outStep
end
else
for p = 0, (frames - 1) * inStep, inStep do
local v = 0
for t = 1, nt do
v += ws[t] * readf32(s, p + offs[t])
end
writef32(d, q, v)
q += outStep
end
writef32(d, q + (o - 1) * 4, v)
end
end
return out, nil
@@ -437,8 +467,8 @@ function AudioOps.mix(list: { Types.Audio }, weights: { number }?): (Types.Audio
return bad("mix: weight " .. i .. " is not a number")
end
local s = a.samples
for k = 0, a.frames * ch - 1 do
writef32(d, k * 4, readf32(d, k * 4) + readf32(s, k * 4) * w)
for o = 0, a.frames * ch * 4 - 4, 4 do
writef32(d, o, readf32(d, o) + readf32(s, o) * w)
end
end
return out, nil
+1
View File
@@ -1,4 +1,5 @@
--!strict
--!optimize 2
-- ops/MusicOps: building and editing tracker Modules over codecs/audio/Tracker without touching the engine's internal
-- layout (5-byte cells, f32 samples, tuning fields). New code.
-- Conventions: pattern numbers are 0-based (as the order list names them), rows 0-based, channels 1-based, sample