diff --git a/README.md b/README.md index 746ab76..0fcb581 100644 --- a/README.md +++ b/README.md @@ -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") diff --git a/src/Formats/codecs/audio/Pcm/init.luau b/src/Formats/codecs/audio/Pcm/init.luau index 3b8118c..cabb8e0 100644 --- a/src/Formats/codecs/audio/Pcm/init.luau +++ b/src/Formats/codecs/audio/Pcm/init.luau @@ -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