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,15 +1,7 @@
|
||||
--!strict
|
||||
-- audio/vorbis: Ogg Vorbis (Vorbis I specification, Xiph.Org; RFC 5215 for the Ogg mapping). The decoder is a Luau
|
||||
-- port of stb_vorbis 1.22 (public domain / MIT, licenses/stb_vorbis-LICENSE.txt) on containers/Ogg and codecs/audio/Mdct,
|
||||
-- with libvorbis' sample-exact timing: start trimming from the first page's granule, end trimming from the last
|
||||
-- page's, granule-exact seeking (bisection, then decoding forward to a page boundary to recover the position).
|
||||
-- Supports: decode / open of any channel count (1..255), rates, block sizes 64..8192, floor 1, residues 0 / 1 / 2,
|
||||
-- coupling, sparse / ordered codebooks, lookup types 1 / 2; comment-header tags (lower-cased keys); a packet-level
|
||||
-- decoder (Vorbis.packetDecoder) for Vorbis in Matroska / WebM / MP4. Encode (audio/vorbis/Encode, new code): a basic
|
||||
-- Ogg Vorbis encoder from an Audio or a streamed Decoder (long blocks, floor 1, coupled residue 2, a fixed codebook
|
||||
-- set, quality -1 .. 10). Not supported: floor 0 (Err.UNSUPPORTED, as in stb_vorbis; no encoder has produced it since
|
||||
-- 2000), chained streams (the first logical Vorbis stream is decoded), short blocks in the encoder.
|
||||
-- The codec itself is codecs/audio/Vorbis; this folder maps it onto the file (container, tags, seeking, writing).
|
||||
-- audio/vorbis: Ogg Vorbis (Vorbis I spec; RFC 5215); the decoder is a port of stb_vorbis 1.22 (public domain / MIT,
|
||||
-- licenses/stb_vorbis-LICENSE.txt) with libvorbis' sample-exact trimming and seeking. Supports: 1-255 channels,
|
||||
-- floor 1, residues 0-2, packetDecoder for Matroska / MP4; an encoder. Not supported: floor 0, chained streams.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -42,7 +34,6 @@ export type EncodeOptions = {
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
-- waveOrder(channels) -> output channel c is Vorbis channel order[c] (codecs/audio/Pcm; identity past 8 channels)
|
||||
local function waveOrder(ch: number): { number }
|
||||
local m = Pcm.WAVE_FROM_VORBIS[ch]
|
||||
if m then
|
||||
@@ -55,7 +46,6 @@ local function waveOrder(ch: number): { number }
|
||||
return id
|
||||
end
|
||||
|
||||
-- the three headers -> ident, setup, vendor, tags, raw comment fields | nil, Err
|
||||
local function headers(h1: any, h2: any, h3: any): (any, any, string?, Types.Tags?, { VorbisComment.Field }?, Err.Err?)
|
||||
local id, ierr = Setup.ident(h1.data, h1.offset, h1.size)
|
||||
if not id then
|
||||
@@ -98,7 +88,6 @@ function Vorbis.decode(r: Bytes.Reader, opts: OpenOptions?): (Types.Audio?, Err.
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encode
|
||||
-- encode(audioOrDecoder, opts?) -> an Ogg Vorbis file | nil, Err
|
||||
function Vorbis.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
local src, serr = Pcm.source(value)
|
||||
if not src then
|
||||
@@ -130,7 +119,6 @@ end
|
||||
local Stream = {}
|
||||
Stream.__index = Stream
|
||||
|
||||
-- queue the chunk arrays[first .. first + count - 1] whose first sample has granule g0, trimmed to [lo, hi)
|
||||
local function push(self: any, arrays: { { number } }, g0: number, count: number, hi: number)
|
||||
local lo = math.max(g0, self.startG, self.skipTo)
|
||||
if hi > g0 + count then
|
||||
@@ -152,7 +140,6 @@ local function copyOut(self: any, count: number): { { number } }
|
||||
return t
|
||||
end
|
||||
|
||||
-- decode packets until something is queued; false at the end of the stream
|
||||
local function decodeMore(self: any): boolean
|
||||
local reader, st = self.reader, self.st
|
||||
while not self.ended do
|
||||
@@ -251,7 +238,6 @@ function Stream.position(self: any): number
|
||||
return (self.next - self.startG) / self.sampleRate
|
||||
end
|
||||
|
||||
-- back to the first audio packet
|
||||
local function restart(self: any)
|
||||
local r = self.reader
|
||||
r:rewind()
|
||||
@@ -430,11 +416,7 @@ function Vorbis.open(r: any, opts: OpenOptions?): (Types.Decoder?, Err.Err?)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ extras
|
||||
-- packetDecoder(ident, comment, setup) -> a decoder of raw Vorbis packets (Matroska / WebM / MP4 carry the three
|
||||
-- headers in their codec private data) | nil, Err. Each argument is a buffer holding one header packet.
|
||||
-- local pd = Vorbis.packetDecoder(h1, h2, h3)
|
||||
-- local n = pd:decode(buf, offset, size) -- frames returned (first packet 0; -1 = not audio); pd.out[ch][1 .. n]
|
||||
-- pd:reset() -- after a seek
|
||||
-- raw Vorbis packets: Matroska / WebM / MP4 carry the three headers in their codec private data
|
||||
function Vorbis.packetDecoder(h1: buffer, h2: buffer, h3: buffer): (any, Err.Err?)
|
||||
local function pk(b: buffer): any
|
||||
return { data = b, offset = 0, size = buffer.len(b) }
|
||||
|
||||
Reference in new issue
Block a user