audio perf: Ogg page CRC slice-by-4, Opus comb filter index offsets

This commit is contained in:
4DBug committed 2026-11-01 19:44:18 -06:00
1 parent 5e71837637
commit 738b881349
2 files changed
+28 -7

No files matched your search

+22 -3
View File
@@ -9,7 +9,7 @@
-- 18 sequence (u32) | 22 crc (u32) | 26 segment count | 27 lacing values | data
local Crc32 = require("@rosetta/core/Crc32")
local readu8, readu32, readi32 = buffer.readu8, buffer.readu32, buffer.readi32
local band, bxor, lshift, rshift = bit32.band, bit32.bxor, bit32.lshift, bit32.rshift
local band, bxor, lshift, rshift, byteswap = bit32.band, bit32.bxor, bit32.lshift, bit32.rshift, bit32.byteswap
local Page = {}
@@ -31,9 +31,28 @@ export type Info = {
local CRC = Crc32.MSB_TABLE
Page.CRC_TABLE = CRC
-- slice-by-4: T2 .. T4[i] = the CRC of byte i followed by 1 .. 3 zero bytes; the CRC is linear, so four bytes w
-- (big-endian) update crc to the xor of the bytes of crc ~ w through T4, T3, T2 and CRC
local T2, T3, T4 = table.create(256, 0), table.create(256, 0), table.create(256, 0)
for i = 0, 255 do
local c = CRC[i + 1]
c = bxor(lshift(c, 8), CRC[rshift(c, 24) + 1])
T2[i + 1] = c
c = bxor(lshift(c, 8), CRC[rshift(c, 24) + 1])
T3[i + 1] = c
c = bxor(lshift(c, 8), CRC[rshift(c, 24) + 1])
T4[i + 1] = c
end
local function crcRange(b: buffer, from: number, to: number, crc: number): number
for i = from, to - 1 do
crc = bxor(lshift(crc, 8), CRC[bxor(rshift(crc, 24), readu8(b, i)) + 1])
local i = from
while i + 4 <= to do
local x = bxor(crc, byteswap(readu32(b, i)))
crc = bxor(T4[rshift(x, 24) + 1], T3[band(rshift(x, 16), 255) + 1], T2[band(rshift(x, 8), 255) + 1], CRC[band(x, 255) + 1])
i += 4
end
for j = i, to - 1 do
crc = bxor(lshift(crc, 8), CRC[bxor(rshift(crc, 24), readu8(b, j)) + 1])
end
return crc
end