codecs/audio/Aac: HE-AAC (SBR) and HE-AACv2 (baseline PS) decoding
New shared modules under codecs/audio/Aac: Sbr (bitstream, band tables, delta decoding), SbrBits, SbrQmf (32-band analysis / 64-band synthesis QMF through DCT-IV), SbrHf (HF generation and adjustment), Ps (baseline PS), SbrTables (ISO tables, from syom 0.8.1, MIT). Explicit signalling enables SBR at construction; implicit SBR / PS is found by Decoder:probe / Aac.probeFrames. audio/aac and audio/m4a report the output rate and take opts.sbr = false for the core only; m4a scales iTunSMPB by the media tick. Outside the folder: containers/AudioWrap writes an AAC-LC ADTS header for HE-AAC AudioSpecificConfigs (the decoder finds SBR in the stream); the api's default openAudio hook forwards opts.sbr.
This commit is contained in:
1 parent
627ddded77
commit
686a1fbf86
14 files changed
+2967
-35
No files matched your search
@@ -1,8 +1,9 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/aac: raw AAC in ADTS framing (ISO/IEC 13818-7 / 14496-3 1.A.3). Supports: AAC-LC via codecs/audio/Aac (1-8
|
||||
-- channels, every rate), CRC-protected headers, a leading ID3v2 tag, resync, seeking by frame; HE-AAC plays its
|
||||
-- AAC-LC core. Not supported: writing, ADIF, LATM.
|
||||
-- channels, every rate), HE-AAC / HE-AACv2 (SBR / PS found in the stream: ADTS cannot signal them; opts.sbr = false
|
||||
-- keeps the AAC-LC core), CRC-protected headers, a leading ID3v2 tag, resync, seeking by frame. Not supported: writing,
|
||||
-- ADIF, LATM.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -25,6 +26,7 @@ local AacFormat = {
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
maxFrames: number?, -- default 2^22
|
||||
sbr: boolean?, -- false: decode only the AAC-LC core of HE-AAC (half rate, faster); default true
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
@@ -150,14 +152,18 @@ function AacFormat.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?,
|
||||
return nil, Err.new(Err.UNSUPPORTED, "ADTS with a program config element (channel configuration 0)")
|
||||
end
|
||||
local channels = ({ 1, 2, 3, 4, 5, 6, 8 })[h.channelConfig] :: number
|
||||
local dec, derr = Aac.decoder({ sfIndex = h.sfIndex, channels = channels, channelConfig = h.channelConfig })
|
||||
local dec, derr = Aac.decoder({ sfIndex = h.sfIndex, channels = channels, channelConfig = h.channelConfig }, { sbr = o.sbr })
|
||||
if not dec then
|
||||
return nil, derr
|
||||
end
|
||||
local d = dec :: Aac.Decoder
|
||||
local sr = d.sampleRate
|
||||
if Aac.probeFrames(d, r.buf, offs, sizes) then
|
||||
d:reset()
|
||||
end
|
||||
local sr, fl = d.sampleRate, d.frameLength
|
||||
channels = d.channels
|
||||
local nframes = #offs
|
||||
local total = nframes * 1024
|
||||
local total = nframes * fl
|
||||
local bytes = 0
|
||||
for _, s in sizes do
|
||||
bytes += s
|
||||
@@ -174,11 +180,11 @@ function AacFormat.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?,
|
||||
tags = tags,
|
||||
codec = "aac",
|
||||
}
|
||||
-- 1024 samples per ADTS frame; one frame of pre-roll for the overlap
|
||||
-- 1024 (2048 with SBR) samples per ADTS frame; pre-roll for the overlap (and the SBR filterbanks / time deltas)
|
||||
return Stream.packets(out, {
|
||||
count = nframes,
|
||||
start = function(i: number): number
|
||||
return (i - 1) * 1024
|
||||
return (i - 1) * fl
|
||||
end,
|
||||
decode = function(i: number): (number?, Err.Err?)
|
||||
return d:decode(buf, offs[i], sizes[i])
|
||||
@@ -189,7 +195,7 @@ function AacFormat.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?,
|
||||
reset = function()
|
||||
d:reset()
|
||||
end,
|
||||
preroll = 1,
|
||||
preroll = if d.sbrOutput then 3 else 1,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user