ws-audio2: TTA: codecs/audio/Tta (written from the TTA1 format description; no libtta / ffmpeg code) + audio/tta

TTA1 format 1, 8/16/24 bits, any channel count, header / seek table / frame CRC-32s, seeking, ID3v2 skipped, APEv2
tags; password-protected files -> UNSUPPORTED. 20 fixtures (ttaenc 3.4.1, the FATE inside.tta sample) bit-exact
against ttaenc -d. Branch-free filter steps (LuaJIT: no register-coalescing aborts, 7 -> 40 MB/s).
WavPack: the unary / gamma counts a byte at a time (LuaJIT traces). APE: the predictor rotations as single
assignments. docs/guide/audio.md: the lossless section (+ tools/fixtures/docs_lossless.py inputs) and the Formats
table.
This commit is contained in:
4DBug committed 2026-10-31 15:08:47 -05:00
1 parent ae8ff9d6bf
commit 085e385674
12 files changed
+857 -20

No files matched your search

+31 -11
View File
@@ -277,7 +277,10 @@ local function values(st: State, q: number, lim: number, n: number, order: { num
value = x1 + rcBits(rc, S, k - 16) * 65536
end
value += ov * 2 ^ k
q, low, range, prev = rc.q, rc.low, rc.range, rc.prev
q = rc.q
low = rc.low
range = rc.range
prev = rc.prev
end
ks = (ks + (value + 1) // 2 - (ks + 16) // 32) % TWO32
ksum[ci] = ks
@@ -437,7 +440,9 @@ local function predictOne(st: State, v: { number }, n: number)
for t = 1, n do
local nA = v[t]
local A0 = lastA
A3, A2, A1 = A2, A1, A0 - prevA0
A3 = A2
A2 = A1
A1 = A0 - prevA0
prevA0 = A0
local predA = A0 * MA0 + A1 * MA1 + A2 * MA2 + A3 * MA3
local cur
@@ -487,11 +492,16 @@ local function predictStereo(st: State, X: { number }, Y: { number }, n: number)
-- Y
local nA = Y[t]
local A0 = yLast
yA3, yA2, yA1 = yA2, yA1, A0 - yPrev
yA3 = yA2
yA2 = yA1
yA1 = A0 - yPrev
yPrev = A0
local B0 = lastX - (yBin * 31) // 32
yBin = lastX
yB4, yB3, yB2, yB1 = yB3, yB2, yB1, B0 - yBprev
yB4 = yB3
yB3 = yB2
yB2 = yB1
yB1 = B0 - yBprev
yBprev = B0
local predA = A0 * yMA0 + yA1 * yMA1 + yA2 * yMA2 + yA3 * yMA3
local predB = B0 * yMB0 + yB1 * yMB1 + yB2 * yMB2 + yB3 * yMB3 + yB4 * yMB4
@@ -532,11 +542,16 @@ local function predictStereo(st: State, X: { number }, Y: { number }, n: number)
-- X
nA = X[t]
A0 = xLast
xA3, xA2, xA1 = xA2, xA1, A0 - xPrev
xA3 = xA2
xA2 = xA1
xA1 = A0 - xPrev
xPrev = A0
B0 = yv - (xBin * 31) // 32
xBin = yv
xB4, xB3, xB2, xB1 = xB3, xB2, xB1, B0 - xBprev
xB4 = xB3
xB3 = xB2
xB2 = xB1
xB1 = B0 - xBprev
xBprev = B0
predA = A0 * xMA0 + xA1 * xMA1 + xA2 * xMA2 + xA3 * xMA3
predB = B0 * xMB0 + xB1 * xMB1 + xB2 * xMB2 + xB3 * xMB3 + xB4 * xMB4
@@ -627,15 +642,19 @@ function Decode.frame(st: State, buf: buffer, at: number, rem: number, stop: num
local mode -- "silence", "pseudo", "stereo", "mono", "multi"
if C == 1 then
if band(special, 1) ~= 0 then
mode, order = "silence", {}
mode = "silence"
order = {}
else
mode, order = "mono", { 1 }
mode = "mono"
order = { 1 }
end
elseif C == 2 then
if band(special, 3) == 3 then
mode, order = "silence", {}
mode = "silence"
order = {}
elseif band(special, 4) ~= 0 then
mode, order = "pseudo", { 1 }
mode = "pseudo"
order = { 1 }
else
mode, order = "stereo", { 2, 1 }
end
@@ -696,7 +715,8 @@ function Decode.frame(st: State, buf: buffer, at: number, rem: number, stop: num
local a: number, b2: number = 0, 0
local pair = paired[c]
if mode == "silence" then
a, b2 = 0, 0
a = 0
b2 = 0
elseif mono then
a = X[t]
b2 = a