ws-cleanup: merge ws/cleanup-types (type annotations)

This commit is contained in:
4DBug committed 2026-10-31 11:27:42 -05:00
commit 5d7c223ab8
115 files changed
+583 -515

No files matched your search

+1 -1
View File
@@ -136,7 +136,7 @@ local function index(r: Bytes.Reader, maxFrames: number): ({ number }, { number
end
function AacFormat.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.Err?)
local o = opts or {}
local o: DecodeOptions = opts or {}
local offs, sizes, first, ierr = index(r, o.maxFrames or 2 ^ 22)
if ierr then
return nil, ierr
+16 -16
View File
@@ -78,42 +78,42 @@ end
local function sampleFormat(comp: string, bits: number): (string?, string?)
if comp == "NONE" or comp == "twos" or comp == "" then
if bits >= 1 and bits <= 8 then
return "s8"
return "s8", nil
elseif bits <= 16 then
return "s16be"
return "s16be", nil
elseif bits <= 24 then
return "s24be"
return "s24be", nil
elseif bits <= 32 then
return "s32be"
return "s32be", nil
end
return nil, "bad sample size " .. bits
elseif comp == "sowt" then
if bits >= 1 and bits <= 8 then
return "s8"
return "s8", nil
elseif bits <= 16 then
return "s16le"
return "s16le", nil
elseif bits <= 24 then
return "s24le"
return "s24le", nil
elseif bits <= 32 then
return "s32le"
return "s32le", nil
end
return nil, "bad sample size " .. bits
elseif comp == "raw " then
return "u8"
return "u8", nil
elseif comp == "in24" then
return "s24be"
return "s24be", nil
elseif comp == "in32" then
return "s32be"
return "s32be", nil
elseif comp == "42ni" then
return "s32le"
return "s32le", nil
elseif comp == "fl32" or comp == "FL32" then
return "f32be"
return "f32be", nil
elseif comp == "fl64" or comp == "FL64" then
return "f64be"
return "f64be", nil
elseif comp == "ulaw" or comp == "ULAW" then
return "ulaw"
return "ulaw", nil
elseif comp == "alaw" or comp == "ALAW" then
return "alaw"
return "alaw", nil
end
return nil, "compression " .. string.format("%q", comp)
end
+2 -2
View File
@@ -350,7 +350,7 @@ local function source(r: Bytes.Reader, p: Parsed): (Source?, Err.Err?)
return nil, Err.new(Err.CORRUPT, "compressed CAF without a packet table")
end
end
local offsets = table.create(#sizes, 0)
local offsets = table.create(#(sizes :: { number }), 0)
local o = p.dataStart
for i, s in sizes :: { number } do
offsets[i] = o
@@ -585,7 +585,7 @@ end
-- encode(audio | decoder, opts?) -> buffer | nil, Err
function Caf.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
local o = opts or {}
local o: EncodeOptions = opts or {}
if type(value) ~= "table" or type(value.sampleRate) ~= "number" or type(value.channels) ~= "number" then
return nil, Err.new(Err.ARG, "expected an Audio or a Decoder")
end
+4 -4
View File
@@ -121,7 +121,7 @@ end
-- open(r, opts?) -> Types.Decoder | nil, Err
function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.Err?)
local o = opts or {}
local o: DecodeOptions = opts or {}
local movie, err = IsoBmff.parse(r, { maxSamples = o.maxSamples })
if not movie then
return nil, err
@@ -169,9 +169,9 @@ function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.E
-- iTunes gapless info (fdkaac, iTunes) when there is no edit list: " 0 <priming> <padding> <samples> ..." (hex)
local smpb = tags.itunsmpb
if gapless and not t.edits and smpb then
local f = {}
local f: { number } = {}
for w in string.gmatch(smpb, "%x+") do
table.insert(f, tonumber(w, 16))
table.insert(f, tonumber(w, 16) :: number)
end
if #f >= 4 and f[2] and f[4] and f[4] > 0 and f[2] + f[4] <= total then
skip = f[2]
@@ -337,7 +337,7 @@ end
-- ------------------------------------------------------------------------------------------------ encode
-- encode(audio | decoder, opts?) -> buffer | nil, Err: an ALAC M4A
function M4a.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
local o = opts or {}
local o: EncodeOptions = opts or {}
if type(value) ~= "table" or type(value.sampleRate) ~= "number" or type(value.channels) ~= "number" then
return nil, Err.new(Err.ARG, "expected an Audio or a Decoder")
end
+14 -5
View File
@@ -561,7 +561,8 @@ local function intensityStereo(h1: number, h3: number, gr: number)
kr = 1
end
end
kl, kr = f32(kl * s), f32(kr * s)
kl = f32(kl * s)
kr = f32(kr * s)
for k = left * 4, (left + n - 1) * 4, 4 do
local v = rf(GRBUF, k)
wf(GRBUF, k + 2304, v * kr)
@@ -1183,8 +1184,14 @@ local function synth(xl: number, dstl: number, nch: number, lins: number)
a3 += z3 * w0 - y3 * w1
vz -= 256
vy += 256
z0, z1, z2, z3 = rf(SYN, vz), rf(SYN, vz + 4), rf(SYN, vz + 8), rf(SYN, vz + 12)
y0, y1, y2, y3 = rf(SYN, vy), rf(SYN, vy + 4), rf(SYN, vy + 8), rf(SYN, vy + 12)
z0 = rf(SYN, vz)
z1 = rf(SYN, vz + 4)
z2 = rf(SYN, vz + 8)
z3 = rf(SYN, vz + 12)
y0 = rf(SYN, vy)
y1 = rf(SYN, vy + 4)
y2 = rf(SYN, vy + 8)
y3 = rf(SYN, vy + 12)
b0 += z0 * w3 + y0 * w2
b1 += z1 * w3 + y1 * w2
b2 += z2 * w3 + y2 * w2
@@ -1212,8 +1219,10 @@ local function synth(xl: number, dstl: number, nch: number, lins: number)
a2 += z2 * w0 - y2 * w1
vz -= 256
vy += 256
z0, z2 = rf(SYN, vz), rf(SYN, vz + 8)
y0, y2 = rf(SYN, vy), rf(SYN, vy + 8)
z0 = rf(SYN, vz)
z2 = rf(SYN, vz + 8)
y0 = rf(SYN, vy)
y2 = rf(SYN, vy + 8)
b0 += z0 * w3 + y0 * w2
b2 += z2 * w3 + y2 * w2
a0 += y0 * w3 - z0 * w2
+3 -1
View File
@@ -375,7 +375,9 @@ function Encode2.encode(src: Source, opts: Options): (buffer?, string?)
local q = floor((x * inv + 1) * L / 2)
return if q < 0 then 0 elseif q > L - 1 then L - 1 else q
end
q0, q1, q2 = quant(sb[o + 1]), quant(sb[o + 2]), quant(sb[o + 3])
q0 = quant(sb[o + 1])
q1 = quant(sb[o + 2])
q2 = quant(sb[o + 3])
end
if ba >= 17 then
put(w, q0 + L * (q1 + L * q2), tripleBits(ba))
+2 -2
View File
@@ -101,7 +101,7 @@ function Index.build(b: buffer, start: number, stop: number): Index?
if first then
first = false
hz, nch, layer, spf = fHz, fCh, fLayer, Header.frameSamples(h1)
hz, nch, layer, spf = fHz, fCh, fLayer, Header.frameSamples(h1) :: number
version = if band(h1, 8) ~= 0 then 1 elseif band(h1, 0x10) ~= 0 then 2 else 2.5
if fLayer == 3 then
local ret, frames, d, p = Core.vbrTag(b, pos, fs)
@@ -150,7 +150,7 @@ function Index.build(b: buffer, start: number, stop: number): Index?
end
if n == cap then
cap *= 2
OFF, SIZE, FLAGS, OUT, MAIN = grow(OFF, cap * 4), grow(SIZE, cap * 2), grow(FLAGS, cap), grow(OUT, cap * 4), grow(MAIN, cap * 2)
OFF, SIZE, FLAGS, OUT, MAIN = grow(OFF, cap * 4), grow(SIZE, cap * 2), grow(FLAGS, cap), grow(OUT, cap * 4), grow(MAIN, cap * 2) :: buffer
end
buffer.writeu32(OFF, n * 4, pos)
buffer.writeu16(SIZE, n * 2, fs)
+5 -3
View File
@@ -179,7 +179,8 @@ local function parseV2(b: buffer, o: number, size: number, tags: any)
local p, e = o + 10, bodyEnd
if band(flags, 0x80) ~= 0 and ver < 4 then
body = deunsync(b, p, e)
p, e = 0, buffer.len(body)
p = 0
e = buffer.len(body)
end
if band(flags, 0x40) ~= 0 and ver >= 3 and p + 4 <= e then
-- extended header: v2.3 size excludes its own 4 bytes, v2.4 includes them (syncsafe)
@@ -216,7 +217,8 @@ local function parseV2(b: buffer, o: number, size: number, tags: any)
end
if not skip and band(fflags, 0x0002) ~= 0 and fs < fe then
fb = deunsync(body, fs, fe)
fs, fe = 0, buffer.len(fb)
fs = 0
fe = buffer.len(fb)
end
end
if not skip and fs < fe then
@@ -273,7 +275,7 @@ function Tags.parse(b: buffer): (any, number, number)
if size >= 128 and buffer.readstring(b, start + size - 128, 3) == "TAG" then
local o = start + size - 128
tags.id3v1 = true
local v1 = {
local v1: { [string]: any } = {
title = v1String(b, o + 3, 30),
artist = v1String(b, o + 33, 30),
album = v1String(b, o + 63, 30),