ws-audio2: merge ws/audio2-adpcm (codecs/audio/Adpcm, Qoa; adx, vag, brstm/bcstm/bfstm, raw adpcm, qoa; wav/aiff/caf/xm ADPCM)
This commit is contained in:
commit
703af4cc71
43 files changed
+5121
-197
No files matched your search
+37
-1
@@ -180,6 +180,8 @@ Encoder options:
|
||||
| opus | `bitrate` (default 64000 per channel, 6000..510000); CELT only; resampled to 48 kHz |
|
||||
| aiff, au, voc | `sampleFormat` (see each format's `init.luau`) |
|
||||
| m4a, caf | ALAC (lossless); m4a and caf also keep tags |
|
||||
| adx, vag | `loop = { start, stop }` (frames; default the source's `meta.source.loop`) |
|
||||
| adpcm | `codec = "ima" \| "ima_wav" \| "ms"`, `blockAlign` (block codecs), `lowFirst` (ima nibble order) |
|
||||
|
||||
`bitrate` is in **bits per second** for every encoder (`bitrate = 192000`), as the Decoder's `bitrate` field is. A
|
||||
value below 1000 is read as kbit/s (`bitrate = 192` is 192000), so older code that passed kbit/s to MP3 still works.
|
||||
@@ -190,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) | aac (ADTS), m4a / caf AAC, mpc (Musepack SV7 / SV8), ac3 (Dolby Digital) |
|
||||
| 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 |
|
||||
|
||||
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
|
||||
@@ -265,6 +267,40 @@ local night = assert(F.audio.load(ac3Bytes, { drc = 1 })) -- the stream's dy
|
||||
assert(stereo.channels == 2 and night.channels == 6)
|
||||
```
|
||||
|
||||
### Game audio and ADPCM
|
||||
|
||||
Console and game engines store sound as 4-bit ADPCM or QOA: small, and cheap to decode while the game runs. They load
|
||||
and save like any other audio. Loop points (ADX, VAG, BRSTM) come out in `meta.source.loop` (and `dec.loop`), in
|
||||
frames, `stop` exclusive; the encoders write them back.
|
||||
|
||||
```luau
|
||||
local tone = F.Types.Audio.new(22050, 1, 22050) -- 1 s of 440 Hz
|
||||
for i = 0, tone.frames - 1 do
|
||||
buffer.writef32(tone.samples, i * 4, 0.5 * math.sin(2 * math.pi * 440 * i / 22050))
|
||||
end
|
||||
local qoa = assert(F.save(tone, nil, { format = "qoa" })) -- Quite OK Audio: 3.2 bits per sample, as qoa.h writes it
|
||||
assert(F.detect(qoa) == "qoa" and F.audio.load(qoa).frames == tone.frames)
|
||||
local adx = assert(F.save(tone, nil, { format = "adx", loop = { start = 0, stop = tone.frames } })) -- CRI ADX
|
||||
local looped = assert(F.audio.load(adx))
|
||||
assert(looped.meta.source.loop.stop == tone.frames)
|
||||
local vag = assert(F.save(tone, nil, { format = "vag" })) -- PlayStation VAG (mono VAGp; stereo is VAGi)
|
||||
assert(F.audio.load(vag).frames >= tone.frames) -- + the blank frame VAGs start with, and frame padding
|
||||
```
|
||||
|
||||
A raw ADPCM stream has no header, so the layout comes from the options, and only `opts.format` or the `.adpcm` / `.ima`
|
||||
extension finds it:
|
||||
|
||||
<!-- doc:continue -->
|
||||
```luau
|
||||
local raw = assert(F.save(tone, nil, { format = "adpcm", codec = "ima" })) -- 4 bits per sample
|
||||
local back = assert(F.audio.load(raw, { format = "adpcm", codec = "ima", sampleRate = 22050, channels = 1 }))
|
||||
assert(back.frames == tone.frames)
|
||||
```
|
||||
|
||||
Read only: Nintendo BRSTM / BCSTM / BFSTM (DSP ADPCM or PCM; `F.detect` names the flavour), KVAG, and the ADPCM
|
||||
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.
|
||||
|
||||
## Gotchas
|
||||
|
||||
- `F.ops.audio.downmix(a)` defaults to **2** channels, so a stereo input stays stereo. Use `downmix(a, 1)` for mono.
|
||||
|
||||
Reference in new issue
Block a user