ws-cleanup: shared plumbing: Err.from, core/Sniff, Pcm.drain, Bits.msbPut; DUP lint; tools/move.py
- core/Err.from(message, offset?, kind?): the private-submodule -> Err plumbing (a kind, or a 'code: ' prefix / 'truncated' / 'past the end' in the message) that Brotli, Bzip2, Zstd, Jpeg, WOFF2, FBX, plist, msgpack and bmfont each wrote. - core/Sniff (new): Sniff.text(r, n, trim?) (the start of a text file without its BOM), Sniff.dropBom(s), Sniff.magic(r, s); 13 text formats' sniff / decode BOM handling goes through it. - codecs/Pcm.drain(dec, source?, maxFrames?): a format's decode() through its open(); the collect-the-Decoder loops of aac, aiff, au, caf, flac, m4a, mp3, opus, vorbis and wav are one call each. - core/Bits.msbPut: the MSB-first bit writer the MP3 / MP2 / FLAC encoders each copied. - tools/lint_rules.py DUP: a function body of 12+ code lines repeated token for token in another module fails. - tools/move.py: moves a module and rewrites every reference (requires, deps, headers, fixture INPUTS, docs). - tools/fixtures/zstd.py: the incompressible corpus is smaller (zstd.luau 15.1 -> 13.4 MB; every fixture module is now under 14.3 MB). - tools/bench.luau: MPEG-1 also runs with the api's LuaJIT trace limits; the sections that compare tuned / default limits set them explicitly (jitTune), so the order of sections no longer leaks the tuning.
This commit is contained in:
1 parent
3243404374
commit
763f4a7c04
44 files changed
+374
-370
No files matched your search
@@ -29,7 +29,7 @@ local Flac = {
|
||||
category = "audio",
|
||||
extensions = { "flac", "oga" },
|
||||
mime = { "audio/flac", "audio/x-flac" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Ogg", "core/Md5", "codecs/Pcm", "codecs/VorbisComment" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Bits", "Types", "containers/Ogg", "core/Md5", "codecs/Pcm", "codecs/VorbisComment" },
|
||||
caps = { decode = true, encode = true, streaming = true, depths = { 4, 8, 12, 16, 20, 24, 32 }, ogg = true, seek = true },
|
||||
}
|
||||
|
||||
@@ -89,34 +89,7 @@ function Flac.decode(r: Bytes.Reader, opts: OpenOptions?): (Types.Audio?, Err.Er
|
||||
if d.frames > limit or d.frames * d.channels > 2 ^ 28 then
|
||||
return nil, Err.new(Err.LIMIT, string.format("%d frames is over the limit", d.frames))
|
||||
end
|
||||
local ch = d.channels
|
||||
local parts, total = {}, 0
|
||||
if d.frames > 0 then
|
||||
local out, n = d:read(d.frames)
|
||||
table.insert(parts, out)
|
||||
total = n
|
||||
end
|
||||
while true do -- frames past what STREAMINFO / the scan said
|
||||
local out, n = d:read(65536)
|
||||
if n == 0 then
|
||||
break
|
||||
end
|
||||
table.insert(parts, out)
|
||||
total += n
|
||||
if total > limit then
|
||||
return nil, Err.new(Err.LIMIT, "stream over the frame limit")
|
||||
end
|
||||
end
|
||||
local a = Types.Audio.new(d.sampleRate, ch, total)
|
||||
local o = 0
|
||||
for _, p in parts do
|
||||
local n = math.min(buffer.len(p), total * ch * 4 - o)
|
||||
buffer.copy(a.samples, o, p, 0, n)
|
||||
o += n
|
||||
end
|
||||
a.tags = d.tags
|
||||
a.meta.source = { format = "flac", bitDepth = d.bitsPerSample, container = d.container, vendor = d.vendor, md5 = d.md5, pictures = d.pictures, comments = d.comments }
|
||||
return a, nil
|
||||
return Pcm.drain(d, { format = "flac", bitDepth = d.bitsPerSample, container = d.container, vendor = d.vendor, md5 = d.md5, pictures = d.pictures, comments = d.comments }, limit)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encode
|
||||
|
||||
Reference in new issue
Block a user