docs/guide/audio: HE-AAC section and opts.sbr; audio/caf: SBR only at the described rate
This commit is contained in:
1 parent
9a4cacc40b
commit
028bee3f59
3 files changed
+48
-1
No files matched your search
+15
-1
@@ -102,6 +102,7 @@ the guide's [README](README.md#inputs)). Options:
|
||||
| `maxFrames` | wav, flac, mp3, aiff, au, voc, aac, mpc, ac3 | `Err.LIMIT` past this many frames |
|
||||
| `drc` | ac3 | dynamic range control: 0 = off (default), 1 = as the stream says |
|
||||
| `stereo` | opus | downmix surround streams to stereo |
|
||||
| `sbr` | aac, m4a, the AAC tracks of mp4 / mkv / ts | `false`: decode only the AAC-LC core of HE-AAC (half the rate, mono for HE-AACv2, about 4x faster) |
|
||||
|
||||
```luau
|
||||
local tags = assert(F.audio.open(mp3Bytes)).tags -- opening reads the tags; nothing is decoded yet
|
||||
@@ -112,6 +113,19 @@ local bad, err = F.audio.load("not audio at all")
|
||||
assert(bad == nil and err.code == F.Err.UNKNOWN_FORMAT)
|
||||
```
|
||||
|
||||
### HE-AAC
|
||||
|
||||
HE-AAC (SBR) and HE-AACv2 (SBR + parametric stereo) decode at the full output rate in every AAC path: ADTS, M4A,
|
||||
and the audio tracks of MP4, Matroska and MPEG-TS (HLS radio). ADTS cannot signal SBR, so the decoder looks for SBR
|
||||
and PS data in the first frames, as ffmpeg does; `sampleRate`, `channels` and `frames` report the output.
|
||||
|
||||
```luau
|
||||
local dec = assert(F.audio.open(heAacBytes)) -- HE-AACv2 in ADTS: a 24 kHz mono core
|
||||
assert(dec.sampleRate == 48000 and dec.channels == 2) -- SBR doubles the rate, PS makes it stereo
|
||||
local core = assert(F.audio.open(heAacBytes, { sbr = false })) -- the AAC-LC core only, for slow devices
|
||||
assert(core.sampleRate == 24000 and core.channels == 1 and core.frames * 2 == dec.frames)
|
||||
```
|
||||
|
||||
## Editing: `F.ops.audio`
|
||||
|
||||
Every function returns a new Audio, or `nil, err` for bad arguments. Times are in seconds. Rates and channel counts
|
||||
@@ -192,7 +206,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, wavpack (.wv + .wvc), ape, tta |
|
||||
| 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; AAC-LC, HE-AAC, HE-AACv2), 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
|
||||
|
||||
@@ -398,6 +398,10 @@ local function source(r: Bytes.Reader, p: Parsed): (Source?, Err.Err?)
|
||||
if not dec then
|
||||
return nil, err
|
||||
end
|
||||
-- HE-AAC: SBR output only when the description is at the SBR rate (else the AAC-LC core)
|
||||
if dec.sbrOutput and dec.sampleRate ~= d.rate then
|
||||
dec = Aac.decoder(asc :: buffer, { sbr = false })
|
||||
end
|
||||
local ad = dec :: Aac.Decoder
|
||||
return {
|
||||
channels = ad.channels,
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Docs input for the HE-AAC section of docs/guide/audio.md (tools/fixtures.py; tools/docs_check.py reads it): half a
|
||||
# second of HE-AACv2 (SBR + PS) in ADTS from fdkaac, 48 kHz output from a 24 kHz mono core.
|
||||
# tests/gen/docs_heaac.luau { files = { ["radio.aac"] = bytes }, vars = { heAacBytes = "radio.aac" } }
|
||||
import importlib.util, math, os, struct, tempfile
|
||||
|
||||
INPUTS = ["tools/docs_check.py"]
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
spec = importlib.util.spec_from_file_location("docs_heaac_check", os.path.join(ctx.root, "tools", "docs_check.py"))
|
||||
dc = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(dc)
|
||||
rate, n = 48000, 24000
|
||||
ints = []
|
||||
for i in range(n):
|
||||
t = i / rate
|
||||
for c in range(2):
|
||||
v = 0.3 * math.sin(2 * math.pi * (330 + 110 * c) * t) + 0.1 * math.sin(2 * math.pi * 7000 * t + c)
|
||||
ints.append(int(v * 32767))
|
||||
data = struct.pack("<%dh" % len(ints), *ints)
|
||||
fmt = struct.pack("<HHIIHH", 1, 2, rate, rate * 4, 4, 16)
|
||||
wav = b"RIFF" + struct.pack("<I", 36 + len(data)) + b"WAVEfmt " + struct.pack("<I", 16) + fmt + b"data" + struct.pack("<I", len(data)) + data
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
with open(os.path.join(d, "in.wav"), "wb") as f:
|
||||
f.write(wav)
|
||||
ctx.nix(["fdk-aac-encoder"], ["sh", "-c", "cd '%s' && fdkaac -S -p 29 -b 32000 -f 2 -o radio.aac in.wav" % d])
|
||||
with open(os.path.join(d, "radio.aac"), "rb") as f:
|
||||
aac = f.read()
|
||||
dc.emit_inputs(ctx, {"radio.aac": aac}, {"heAacBytes": "radio.aac"})
|
||||
Reference in new issue
Block a user