codecs/audio/Aac/SbrDct: straight-line DCT-IV / DST-IV for the SBR QMF banks; HE-AAC bench lines
This commit is contained in:
1 parent
778502c54d
commit
c291312f8a
3 files changed
+1642
-37
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -2,25 +2,20 @@
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Aac/SbrQmf: the SBR 32-band complex analysis and 64-band synthesis QMF banks (ISO/IEC 14496-3
|
||||
-- 4.6.18.4.1 / 4.6.18.4.2), through DCT-IV factorisations of the modulation (codecs/audio/Mdct). Written from the
|
||||
-- standard; the window is codecs/audio/Aac/SbrTables.QMF_WINDOW.
|
||||
-- 4.6.18.4.1 / 4.6.18.4.2), through DCT-IV factorisations of the modulation (codecs/audio/Aac/SbrDct). Written from
|
||||
-- the standard; the window is codecs/audio/Aac/SbrTables.QMF_WINDOW.
|
||||
-- analysis: W(k) = 2 e^(-i 3 pi (k + 1/2) / 128) (DCT4_32(u(m) - u(63 - m)) + i DST4_32(u(m) + u(63 - m)))(k)
|
||||
-- synthesis: v(n) = -(DCT4_64(Re X) - DST4_64(Im X))(n) / 64, v(127 - n) = (DCT4_64(Re X) + DST4_64(Im X))(n) / 64
|
||||
local Mdct = require("@rosetta/codecs/audio/Mdct")
|
||||
local SbrDct = require("@rosetta/codecs/audio/Aac/SbrDct")
|
||||
local SbrTables = require("@rosetta/codecs/audio/Aac/SbrTables")
|
||||
|
||||
local cos, sin, pi = math.cos, math.sin, math.pi
|
||||
|
||||
local SbrQmf = {}
|
||||
|
||||
local C = SbrTables.QMF_WINDOW
|
||||
local DCT32 = Mdct.new(64) :: Mdct.Plan
|
||||
local DCT64 = Mdct.new(128) :: Mdct.Plan
|
||||
local dct4 = Mdct.dct4
|
||||
local dct32, ana32, dct64, syn64 = SbrDct.dct32, SbrDct.ana32, SbrDct.dct64, SbrDct.syn64
|
||||
|
||||
-- the core decoder's samples are scaled by 1 / 32768; the SBR energies assume 16-bit sample values
|
||||
local IN_SCALE = 32768
|
||||
local OUT_SCALE = 1 / (64 * 32768)
|
||||
|
||||
-- analysis taps: CA[j * 64 + n + 1] = c[2n + 128j] * IN_SCALE
|
||||
local CA = table.create(320, 0)
|
||||
@@ -29,20 +24,10 @@ for j = 0, 4 do
|
||||
CA[j * 64 + n + 1] = C[2 * n + 128 * j + 1] * IN_SCALE
|
||||
end
|
||||
end
|
||||
-- e^(-i beta_k) * 2 with beta_k = 0.75 pi (k + 1/2) / 32, the DST sign (-1)^k folded into SS
|
||||
local AC, AS, SC, SS = table.create(32, 0), table.create(32, 0), table.create(32, 0), table.create(32, 0)
|
||||
for k = 0, 31 do
|
||||
local b = 0.75 * pi * (k + 0.5) / 32
|
||||
local sg = if k % 2 == 0 then 1 else -1
|
||||
AC[k + 1], AS[k + 1] = 2 * cos(b), 2 * sin(b)
|
||||
SC[k + 1], SS[k + 1] = sg * 2 * cos(b), sg * 2 * sin(b)
|
||||
end
|
||||
|
||||
local U = table.create(64, 0)
|
||||
local A = table.create(32, 0)
|
||||
local B = table.create(32, 0)
|
||||
local CR = table.create(64, 0)
|
||||
local CI = table.create(64, 0)
|
||||
|
||||
-- per-channel filterbank state
|
||||
function SbrQmf.state(): any
|
||||
@@ -65,7 +50,7 @@ function SbrQmf.analysis(s: any, inp: { number }, io: number, is: number)
|
||||
local xr: { number }, xi: { number } = s.XLr, s.XLi
|
||||
table.move(xr, 1025, 1280, 1)
|
||||
table.move(xi, 1025, 1280, 1)
|
||||
local u, a, b, cr, ci = U, A, B, CR, CI
|
||||
local u, a, b, cr = U, A, B, CR
|
||||
for l = 0, 31 do
|
||||
local t = 352 + 32 * l
|
||||
for n = 1, 64 do
|
||||
@@ -78,14 +63,8 @@ function SbrQmf.analysis(s: any, inp: { number }, io: number, is: number)
|
||||
a[m] = u0 - u1
|
||||
b[m] = u0 + u1
|
||||
end
|
||||
dct4(DCT32, a, 1, 1, cr, 1, 1, 1)
|
||||
dct4(DCT32, b, 32, -1, ci, 1, 1, 1)
|
||||
local o = (8 + l) * 32
|
||||
for k = 1, 32 do
|
||||
local c0, s0 = cr[k], ci[k]
|
||||
xr[o + k] = c0 * AC[k] + s0 * SS[k]
|
||||
xi[o + k] = s0 * SC[k] - c0 * AS[k]
|
||||
end
|
||||
dct32(a, 0, cr)
|
||||
ana32(b, 0, cr, xr, xi, (8 + l) * 32)
|
||||
end
|
||||
table.move(x, 1025, 1344, 1)
|
||||
end
|
||||
@@ -93,16 +72,9 @@ end
|
||||
-- one synthesis slot: 64 complex subbands (xr / xi at [xo + k], k = 1 .. 64) -> 64 samples at out[o + j * os]
|
||||
function SbrQmf.synthesis(s: any, slot: number, xr: { number }, xi: { number }, xo: number, out: { number }, o: number, os: number)
|
||||
local v: { number } = s.qs
|
||||
local cr, ci = CR, CI
|
||||
dct4(DCT64, xr, xo + 1, 1, cr, 1, 1, OUT_SCALE)
|
||||
dct4(DCT64, xi, xo + 64, -1, ci, 1, 1, OUT_SCALE)
|
||||
local base = (9 + slot) * 128
|
||||
for n = 1, 64 do
|
||||
local c0 = cr[n]
|
||||
local s0 = if n % 2 == 1 then ci[n] else -ci[n]
|
||||
v[base + n] = s0 - c0
|
||||
v[base + 129 - n] = c0 + s0
|
||||
end
|
||||
dct64(xr, xo, CR)
|
||||
syn64(xi, xo, CR, v, base)
|
||||
local b0, b1 = base, base - 128
|
||||
local p = o
|
||||
for k = 1, 64 do
|
||||
|
||||
Reference in new issue
Block a user