ws-audio2: merge ws/audio2-lossless (WavPack, Monkey's Audio, TTA, ApeTag)

codecs/audio/Stream: both branches extended pull(): buffer pcm (adpcm) and scale / ints (lossless); combined.
This commit is contained in:
4DBug committed 2026-10-31 15:18:31 -05:00
commit f6188764b8
26 files changed
+4728 -6

No files matched your search

+6
View File
@@ -21,6 +21,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| audio | adpcm | .adpcm .ima | yes | yes | streaming: true, lossy: true, headerless: true, codecs: "ima", "ima_wav", "ms", "ima_qt", "psx" | `tests/audio/adpcm.luau` |
| audio | adx | .adx | yes | yes | streaming: true, lossy: true, loops: true, channels: 8 | `tests/audio/adx.luau` |
| audio | aiff | .aiff .aif .aifc .afc | yes | yes | streaming: true, depths: 8, 16, 24, 32, float: true, lossy: false | `tests/audio/aiff.luau` |
| audio | ape | .ape | yes | - | streaming: true, seek: true, lossless: true, float: true, depths: 8, 16, 24, 32 | `tests/audio/ape.luau` |
| audio | au | .au .snd | yes | yes | streaming: true, depths: 8, 16, 24, 32, float: true, lossy: false | `tests/audio/au.luau` |
| audio | brstm | .brstm .bcstm .bfstm | yes | - | streaming: true, lossy: true, loops: true, containers: "RSTM", "CSTM", "FSTM" | `tests/audio/brstm.luau` |
| audio | caf | .caf .caff | yes | yes | codecs: "pcm", "alac", "aac", "ulaw", "alaw", encodeCodecs: "pcm", "alac", tags: true, streaming: true | `tests/audio/caf.luau` |
@@ -30,10 +31,12 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| audio | mpc | .mpc .mp+ .mpp | yes | - | codecs: "musepack", versions: 7, 8, streaming: true, lossy: true | `tests/audio/mpc.luau` |
| audio | opus | .opus | yes | yes | streaming: true, seek: true, lossy: true, channels: 255, rates: 48000, encodeModes: "celt", encodeChannels: 2 | `tests/audio/opus.luau` |
| audio | qoa | .qoa | yes | yes | streaming: true, lossy: true, seek: true, channels: 8 | `tests/audio/qoa.luau` |
| audio | tta | .tta | yes | - | streaming: true, seek: true, lossless: true, depths: 8, 16, 24 | `tests/audio/tta.luau` |
| audio | vag | .vag | yes | yes | streaming: true, lossy: true, loops: true, channels: 2 | `tests/audio/vag.luau` |
| audio | voc | .voc | yes | yes | streaming: true, depths: 8, 16, lossy: false | `tests/audio/voc.luau` |
| audio | vorbis | .ogg .oga | yes | yes | streaming: true, seek: true, lossy: true, channels: 255 | `tests/audio/vorbis.luau` |
| audio | wav | .wav .wave .rf64 .bw64 | yes | yes | streaming: true, depths: 8, 16, 24, 32, float: true, rf64: true | `tests/audio/wav.luau` |
| audio | wavpack | .wv | yes | - | streaming: true, seek: true, lossless: true, hybrid: true, float: true, depths: 8, 12, 16, 20, 24, 32 | `tests/audio/wavpack.luau` |
| video | avi | .avi | yes | yes | streaming: true, video: "mjpeg", "mpeg1", "rawvideo", audio: true, odml: true | `tests/video/avi.luau` |
| video | h264 | .h264 .264 .avc .jsv .26l .jvt | yes | yes | streaming: true, video: "h264", depths: 8 | `tests/video/h264.luau` |
| video | mkv | .mkv .webm .mka .mk3d | yes | yes | streaming: true, remux: true, video: "vp8", "mjpeg", "mpeg1", "rawvideo", audio: true, subtitles: true | `tests/video/mkv.luau` |
@@ -102,6 +105,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- codecs/audio/Ac3: AC-3 (Dolby Digital, ATSC A/52) syncframes: the syncinfo / BSI header, the CRC check, and the
- codecs/audio/Adpcm: the 4-bit ADPCM family, decode (and encode where it is cheap). New in formats-luau; the IMA and
- codecs/audio/Alac: Apple Lossless (ALAC) decoder and encoder, the codec inside m4a / mov / caf. A codec (layer 1).
- codecs/audio/Ape: the Monkey's Audio codec (.ape). A codec (layer 3). Ported from the Monkey's Audio SDK 13.28
- codecs/audio/ApeTag: APEv1 / APEv2 tags (the tag block of Monkey's Audio, WavPack, Musepack, TTA, OptimFROG and
- codecs/audio/Flac: FLAC frames without the container: frame header parsing, subframe decoding (constant, verbatim,
- codecs/audio/Hively: the AHX / HivelyTracker engine behind music/ahx and music/hvl: the loader for both file formats
@@ -116,8 +120,10 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- codecs/audio/SoundFont: SoundFont 2 banks and the sample synth that plays MIDI through them. A codec (layer 1) shared by
- codecs/audio/Stream: the streaming Decoder (Types.Decoder: read / seek / position) over a packetised codec, the part
- codecs/audio/Tracker: the shared tracker engine behind music/mod, music/s3m, music/xm and music/it. The four loaders read
- codecs/audio/Tta: the TTA1 (True Audio) lossless codec. A codec (layer 3). Written from the TTA1 format description
- codecs/audio/Vorbis: the Vorbis I decoder without its container: identification / comment / setup headers (Setup),
- codecs/audio/VorbisComment: Vorbis comment fields ("KEY=value", the tag block of Vorbis, Opus and FLAC) <-> Types.Tags.
- codecs/audio/WavPack: the WavPack 4 / 5 audio codec (the blocks of .wv files, and of WavPack in Matroska). A codec
- **compress**
- codecs/compress/Brotli: Brotli (RFC 7932) decompression. A codec (layer 3): archive/br and font/woff2 build on it. Written
- codecs/compress/Bzip2: bzip2 decompressor (BWT + MTF + Huffman, the .bz2 stream format of bzip2 0.9.5 / 1.0.x). A codec
+35 -1
View File
@@ -192,7 +192,7 @@ Tags are written from `audio.tags`, or from the Decoder's `tags`, wherever the f
| Read and write | Read only |
|---|---|
| wav (+ RF64), flac (+ Ogg FLAC), mp3 / mp2, vorbis (.ogg), opus, aiff / aifc, au, voc, caf, m4a (ALAC), qoa, adx, vag, adpcm (raw IMA / MS) | aac (ADTS), m4a / caf AAC, mpc (Musepack SV7 / SV8), ac3 (Dolby Digital), brstm / bcstm / bfstm, KVAG, wav / aifc / caf IMA and MS ADPCM |
| wav (+ RF64), flac (+ Ogg FLAC), mp3 / mp2, vorbis (.ogg), opus, aiff / aifc, au, voc, caf, m4a (ALAC), qoa, adx, vag, adpcm (raw IMA / MS) | aac (ADTS), m4a / caf AAC, mpc (Musepack SV7 / SV8), ac3 (Dolby Digital), brstm / bcstm / bfstm, KVAG, wav / aifc / caf IMA and MS ADPCM, wavpack (.wv + .wvc), ape, tta |
Each format's capabilities are listed in [FORMATS.md](../FORMATS.md). The audio tracks of video files open as
Decoders too: see `v.audio` in [video.md](video.md). Music files (MOD, MIDI, ...) render to a Decoder: see
@@ -301,6 +301,40 @@ Read only: Nintendo BRSTM / BCSTM / BFSTM (DSP ADPCM or PCM; `F.detect` names th
inside WAV (IMA, MS), AIFF-C and CAF (ima4). Decoding is bit-exact with vgmstream (ADX, VAG, BRSTM) and ffmpeg
(IMA, MS, ima4, QOA). Seeking is exact everywhere: the decoders keep the predictor state of every block they pass.
### Lossless: WavPack, Monkey's Audio, TTA
WavPack (`.wv`), Monkey's Audio (`.ape`) and TTA (`.tta`) open and load like FLAC. Their tags (APEv2) come out in
`tags` with lower-case keys. Integer streams also have `readInt`, which returns the exact samples as i32. Every
frame of these formats is independent, so `seek` lands on the exact sample.
```luau
local wv = assert(F.audio.open(wvBytes))
assert(wv.bitsPerSample == 16 and wv.lossless and wv.tags.title == "Docs Tone")
local exact, n = wv:readInt(1024) -- i32 samples, as wvunpack writes them
assert(n == 1024 and buffer.readi32(exact, 0) == 0)
local ape = assert(F.audio.load(apeBytes)) -- any level, fast .. insane
assert(ape.meta.source.format == "ape" and ape.tags.artist == "formats-luau")
local tta = assert(F.audio.open(ttaBytes))
tta:seek(0.5)
assert(math.abs(tta:position() - 0.5) < 1e-6)
```
A hybrid WavPack file holds a lossy stream. Its `.wvc` correction file makes it lossless again. Pass the correction
file as `correction`. When you load a file by path, the `.wvc` next to it is found automatically. Without it, the
file decodes lossy.
```luau
local lossy = assert(F.audio.open(hybridWvBytes))
local full = assert(F.audio.open(hybridWvBytes, { correction = hybridWvcBytes }))
assert(lossy.hybrid and not lossy.lossless and full.lossless)
```
<!-- doc:files -->
```luau
local song = assert(F.audio.load("assets/tone_hybrid.wv")) -- reads assets/tone_hybrid.wvc too
assert(song.meta.source.correction == true)
```
## Gotchas
- `F.ops.audio.downmix(a)` defaults to **2** channels, so a stereo input stays stereo. Use `downmix(a, 1)` for mono.