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,9 +1,7 @@
|
||||
--!strict
|
||||
-- audio/m4a: MPEG-4 audio files (M4A / M4B / MP4 / MOV audio tracks) through containers/IsoBmff. Supports: reading
|
||||
-- AAC-LC (codecs/audio/Aac; HE-AAC files play their AAC-LC core at the core rate) and ALAC (codecs/audio/Alac) tracks, gapless
|
||||
-- trimming through the edit list (encoder priming / padding), seeking, iTunes tags and cover art (dec.pictures);
|
||||
-- writing ALAC (16 / 20 / 24-bit, 1 - 8 channels) with tags and cover art. Not supported: writing AAC, other codecs
|
||||
-- inside MP4 (MP3 / Opus / FLAC / AC-3: UNSUPPORTED), encrypted files.
|
||||
-- audio/m4a: MPEG-4 audio (M4A / M4B / MP4 / MOV audio tracks) via containers/IsoBmff. Supports: AAC-LC (HE-AAC plays
|
||||
-- its core), ALAC, edit-list gapless trimming, seeking, iTunes tags and cover art; encode ALAC (16 / 20 / 24-bit, 1-8
|
||||
-- channels). Not supported: writing AAC, other codecs in MP4 (UNSUPPORTED), encrypted files.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -29,13 +27,13 @@ local M4a = {
|
||||
export type DecodeOptions = {
|
||||
track: number?, -- the track id to play (default: the first AAC / ALAC track)
|
||||
gapless: boolean?, -- apply the edit list (default true)
|
||||
maxSamples: number?, -- sample table limit (default 2^25)
|
||||
maxSamples: number?, -- default 2^25
|
||||
}
|
||||
export type EncodeOptions = {
|
||||
bitDepth: number?, -- 16 (default), 20 or 24
|
||||
frameLength: number?, -- samples per packet, default 4096
|
||||
tags: Types.Tags?, -- default: the audio's tags
|
||||
pictures: { { mime: string, data: buffer } }?, -- cover art (default: audio.meta.pictures)
|
||||
pictures: { { mime: string, data: buffer } }?, -- default: audio.meta.pictures
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
@@ -57,7 +55,6 @@ function M4a.sniff(r: Bytes.Reader): number
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
-- the packet decoder of a track: decode(buf, off, len) -> frames | nil, Err; pcm: interleaved floats
|
||||
type PacketDecoder = {
|
||||
channels: number,
|
||||
sampleRate: number,
|
||||
@@ -121,7 +118,6 @@ local function packetDecoder(t: IsoBmff.Track): (PacketDecoder?, Err.Err?)
|
||||
return nil, Err.new(Err.UNSUPPORTED, "audio codec " .. t.codec .. " in MP4")
|
||||
end
|
||||
|
||||
-- open(r, opts?) -> Types.Decoder | nil, Err
|
||||
function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.Err?)
|
||||
local o: DecodeOptions = opts or {}
|
||||
local movie, err = IsoBmff.parse(r, { maxSamples = o.maxSamples })
|
||||
@@ -155,7 +151,6 @@ function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.E
|
||||
end
|
||||
local p = pd :: PacketDecoder
|
||||
local channels, sr = p.channels, p.sampleRate
|
||||
-- media ticks -> sample frames
|
||||
local tickScale = sr / t.timescale
|
||||
local gapless = o.gapless ~= false
|
||||
local skip = if gapless then math.floor(t.skip * tickScale + 0.5) else 0
|
||||
@@ -219,7 +214,6 @@ function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.E
|
||||
})
|
||||
end
|
||||
|
||||
-- decode(r, opts?) -> Types.Audio | nil, Err (the whole stream, tags, cover pictures in meta.pictures)
|
||||
function M4a.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Audio?, Err.Err?)
|
||||
local dec, err = M4a.open(r, opts)
|
||||
if not dec then
|
||||
@@ -234,7 +228,6 @@ function M4a.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Audio?, Err.E
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encode
|
||||
-- encode(audio | decoder, opts?) -> buffer | nil, Err: an ALAC M4A
|
||||
function M4a.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
local o: EncodeOptions = opts or {}
|
||||
if type(value) ~= "table" or type(value.sampleRate) ~= "number" or type(value.channels) ~= "number" then
|
||||
@@ -254,7 +247,6 @@ function M4a.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
local ints = table.create(fl * ch, 0)
|
||||
local floor = math.floor
|
||||
local readf32 = buffer.readf32
|
||||
-- frames from an Audio buffer or a streaming Decoder
|
||||
local src: buffer, srcFrames = nil :: any, 0
|
||||
local isAudio = value.kind == "audio" and type(value.samples) == "buffer"
|
||||
if isAudio then
|
||||
|
||||
Reference in new issue
Block a user