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,10 +1,7 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- audio/wav/Codecs: sample conversion loops (native) into interleaved f32, and back (the encoder's quantizers). The
|
||||
-- ADPCM block decoders moved to codecs/audio/Adpcm.
|
||||
-- Absorbed from wav-luau fd9a909 (same author); the encoder loops are new. They never throw: audio/wav (init.luau)
|
||||
-- only calls them with ranges it has checked against the source length and the output size.
|
||||
-- audio/wav/Codecs: PCM / float / G.711 sample loops into interleaved f32 and back; absorbed from wav-luau fd9a909.
|
||||
local readu8, readi8, readu16, readi16, readu32, readi32 =
|
||||
buffer.readu8, buffer.readi8, buffer.readu16, buffer.readi16, buffer.readu32, buffer.readi32
|
||||
local readf32, readf64, writef32, writeu32 = buffer.readf32, buffer.readf64, buffer.writef32, buffer.writeu32
|
||||
@@ -13,8 +10,7 @@ local writeu8, writeu16, writei16, writei32 = buffer.writeu8, buffer.writeu16, b
|
||||
|
||||
local Codecs = {}
|
||||
|
||||
-- Integer PCM: count samples of `bytes` bytes each (1 = unsigned 8-bit, 2 / 3 / 4 = signed), little- or big-endian,
|
||||
-- from src[off] to dst (f32) starting at sample index d.
|
||||
-- integer PCM: 1 byte = unsigned, 2 / 3 / 4 bytes = signed
|
||||
function Codecs.int(src: buffer, off: number, dst: buffer, d: number, count: number, bytes: number, be: boolean)
|
||||
local o = d * 4
|
||||
if bytes == 1 then
|
||||
@@ -64,7 +60,6 @@ function Codecs.int(src: buffer, off: number, dst: buffer, d: number, count: num
|
||||
end
|
||||
end
|
||||
|
||||
-- IEEE float, 4 or 8 bytes. tmp: an 8-byte scratch buffer for byte-swapping big-endian values.
|
||||
function Codecs.float(src: buffer, off: number, dst: buffer, d: number, count: number, bytes: number, be: boolean,
|
||||
tmp: buffer)
|
||||
local o = d * 4
|
||||
@@ -95,7 +90,6 @@ function Codecs.float(src: buffer, off: number, dst: buffer, d: number, count: n
|
||||
end
|
||||
end
|
||||
|
||||
-- 8-bit companded (A-law / mu-law) through a 256-entry f32 table
|
||||
function Codecs.law(src: buffer, off: number, dst: buffer, d: number, count: number, tbl: buffer)
|
||||
local o = d * 4
|
||||
for i = 0, count - 1 do
|
||||
@@ -103,13 +97,10 @@ function Codecs.law(src: buffer, off: number, dst: buffer, d: number, count: num
|
||||
end
|
||||
end
|
||||
|
||||
-- copy frames from a block cache into the output: count f32 values
|
||||
function Codecs.copy(src: buffer, sOff: number, dst: buffer, dOff: number, count: number)
|
||||
buffer.copy(dst, dOff * 4, src, sOff * 4, count * 4)
|
||||
end
|
||||
|
||||
-- Encoder: count f32 samples from src (sample index s) to dst[off] as `kind` ("u8", "s16", "s24", "s32", "f32"),
|
||||
-- little-endian, rounding to nearest and clamping to the integer range. Ranges are checked by the caller.
|
||||
function Codecs.quantize(src: buffer, s: number, dst: buffer, off: number, count: number, kind: string)
|
||||
local so = s * 4
|
||||
if kind == "f32" then
|
||||
|
||||
Reference in new issue
Block a user