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
@@ -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