ws-cleanup: Pcm.collect reads a known length in one call into the result (no copy); README links the guide

Measured in an A/B of the touched paths (best of 3-4, one core): LuaJIT wav decode through Pcm.drain was ~10%
slower than the old single read; now within noise.
This commit is contained in:
4DBug committed 2026-10-31 13:19:43 -05:00
1 parent 9941113b7b
commit 7cfec05eeb
2 files changed
+12 -1

No files matched your search

+2 -1
View File
@@ -7,7 +7,8 @@ generation) and on **LuaJIT / LÖVE** (through `tools/build.py`). Every format o
About 76 formats across images, audio, video, 3D models, CAD, fonts, archives, data, vector graphics, layered images,
subtitles, music and playlists: see [docs/FORMATS.md](docs/FORMATS.md) (generated from the code) for the list and each
format's capabilities, and [docs/API.md](docs/API.md) for the whole API.
format's capabilities, [docs/API.md](docs/API.md) for the whole API, and the guide
([docs/guide/README.md](docs/guide/README.md)) for walkthroughs.
```luau
local F = require(Formats) -- LuaJIT: require("formats"); luau CLI: require("@formats")
+10
View File
@@ -117,6 +117,16 @@ function Pcm.collect(src: Source, maxFrames: number?): (Types.Audio?, Err.Err?)
local total = 0
local limit = maxFrames or 2 ^ 31
local tmp: buffer? = nil
-- a known length: one read straight into the result (decoders write into a big enough out buffer: no copy)
if src.frames > 0 and src.frames <= limit then
local b, n = src:read(src.frames, data)
if n > 0 then
if b ~= data then
buffer.copy(data, 0, b, 0, math.min(n, cap) * ch * 4)
end
total = math.min(n, cap)
end
end
while true do
local b, n = src:read(16384, tmp)
if n <= 0 then