audio formats: comments are specs only
This commit is contained in:
1 parent
0bd7b87d2b
commit
6ffbdbe0be
29 files changed
+143
-442
No files matched your search
@@ -1,8 +1,7 @@
|
||||
--!strict
|
||||
-- audio/aac: raw AAC in ADTS framing (ISO/IEC 13818-7 / 14496-3 1.A.3), the .aac files encoders and radio streams
|
||||
-- write. Supports: reading AAC-LC through codecs/audio/Aac (1 - 8 channels, every rate, multi-block frames, CRC-protected
|
||||
-- headers skipped), a leading ID3v2 tag (skipped; its text frames become tags), resync after garbage, seeking (by
|
||||
-- frame), HE-AAC streams play their AAC-LC core. Not supported: writing (AAC encoding is out of scope), ADIF, LATM.
|
||||
-- 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.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -24,13 +23,12 @@ local AacFormat = {
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
maxFrames: number?, -- refuse streams with more ADTS frames (default 2^22)
|
||||
maxFrames: number?, -- default 2^22
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
local readu8 = buffer.readu8
|
||||
|
||||
-- the size of an ID3v2 tag at p (0 if none)
|
||||
local function id3Size(b: buffer, p: number, limit: number): number
|
||||
if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then
|
||||
return 0
|
||||
@@ -43,7 +41,6 @@ local function id3Size(b: buffer, p: number, limit: number): number
|
||||
return 10 + s + footer
|
||||
end
|
||||
|
||||
-- a few ID3v2.3 / 2.4 text frames -> tags
|
||||
local ID3_TAGS: { [string]: string } = {
|
||||
TIT2 = "title", TPE1 = "artist", TALB = "album", TYER = "date", TDRC = "date", TCON = "genre", TRCK = "track",
|
||||
COMM = "comment", TCOM = "composer", TPE2 = "albumartist",
|
||||
@@ -94,7 +91,6 @@ function AacFormat.sniff(r: Bytes.Reader): number
|
||||
if not h then
|
||||
return 0
|
||||
end
|
||||
-- a second header right after the first makes it certain
|
||||
local h2 = Aac.adts(b, p + h.frameSize, limit)
|
||||
if h2 and h2.sfIndex == h.sfIndex and h2.channelConfig == h.channelConfig then
|
||||
return 0.9
|
||||
@@ -103,7 +99,6 @@ function AacFormat.sniff(r: Bytes.Reader): number
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
-- the frame index: offsets of every ADTS frame (resyncing over garbage)
|
||||
local function index(r: Bytes.Reader, maxFrames: number): ({ number }, { number }, Aac.Adts?, Err.Err?)
|
||||
local b, limit = r.buf, r.limit
|
||||
local p = r.base + id3Size(b, r.base, limit)
|
||||
@@ -112,14 +107,14 @@ local function index(r: Bytes.Reader, maxFrames: number): ({ number }, { number
|
||||
while p + 7 <= limit do
|
||||
local h = Aac.adts(b, p, limit)
|
||||
if h and first and (h.sfIndex ~= first.sfIndex or h.channelConfig ~= first.channelConfig) then
|
||||
h = nil -- a false sync inside the data
|
||||
h = nil
|
||||
end
|
||||
if not h then
|
||||
p += 1
|
||||
continue
|
||||
end
|
||||
if p + h.frameSize > limit then
|
||||
break -- a truncated last frame
|
||||
break
|
||||
end
|
||||
if not first then
|
||||
first = h
|
||||
@@ -178,7 +173,7 @@ function AacFormat.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?,
|
||||
tags = tags,
|
||||
codec = "aac",
|
||||
}
|
||||
-- 1024 frames per ADTS frame; one frame of pre-roll for the overlap when seeking
|
||||
-- 1024 samples per ADTS frame; one frame of pre-roll for the overlap
|
||||
return Stream.packets(out, {
|
||||
count = nframes,
|
||||
start = function(i: number): number
|
||||
|
||||
Reference in new issue
Block a user