ws-audio2: Musepack / AC-3 bench lines, docs/guide/audio.md section (+ tools/fixtures/docs_lossy.py inputs), AVI AC-3 track test
This commit is contained in:
1 parent
41b72d9b8a
commit
2d99b9924a
5 files changed
+95
-5
No files matched your search
@@ -1078,3 +1078,31 @@ do
|
||||
jitTune(false)
|
||||
end
|
||||
end
|
||||
-- ws-audio2: lossy
|
||||
do
|
||||
-- Musepack (codecs/audio/Musepack) SV8 / SV7 and AC-3 5.1 (codecs/audio/Ac3): whole-file decodes, MB/s of f32 output
|
||||
-- (tools/fixtures/mpc.py: 1.2 s of 44.1 kHz stereo at quality 5; tools/fixtures/ac3.py: 0.16 s of 48 kHz 5.1 at
|
||||
-- 448 kbps, decoded 4 times per run)
|
||||
local Mpc = require("@formats/audio/mpc")
|
||||
local MpcFx = require("@tests/gen/mpc_cases")
|
||||
local Ac3F = require("@formats/audio/ac3")
|
||||
local Ac3Fx = require("@tests/gen/ac3_cases")
|
||||
for _, c in MpcFx do
|
||||
if c.name == "sv8_q5_stereo" or c.name == "sv7_q5_stereo" then
|
||||
local b = buffer.fromstring(c.data)
|
||||
bench("mpc " .. c.name, 5, c.frames * c.channels * 4, function()
|
||||
assert(Mpc.decode(Bytes.reader(b)))
|
||||
end)
|
||||
end
|
||||
end
|
||||
for _, c in Ac3Fx do
|
||||
if c.name == "5.1_448" then
|
||||
local b = buffer.fromstring(c.data)
|
||||
bench("ac3 5.1 448 kbps", 5, c.frames * c.channels * 4 * 4, function()
|
||||
for _ = 1, 4 do
|
||||
assert(Ac3F.decode(Bytes.reader(b)))
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,7 +3,7 @@
|
||||
# References: ffmpeg's float decode with -drc_scale 0 (dynamic range off, our default), except for block-switched
|
||||
# streams: ffmpeg (as packaged) mis-decodes the first of the two short transforms, so those use liba52's a52dec
|
||||
# (-r -a: no dynamic range, no level adjustment; float for stereo, 16-bit wav6 for more channels), which agrees with
|
||||
# the A/52 transform equations. AC-3 tracks in Matroska / MP4 / MPEG-TS (remuxed by ffmpeg) for the api's audio hook.
|
||||
# the A/52 transform equations. AC-3 tracks in Matroska / MP4 / MPEG-TS / AVI (remuxed by ffmpeg) for the api's audio hook.
|
||||
#
|
||||
# Both encoders set dithflag, and decoders draw their own random dither for the zero-bit mantissas, so two correct
|
||||
# decoders differ by about the coding noise. The reference streams therefore have their dithflags cleared (the bit
|
||||
@@ -214,7 +214,8 @@ def generate(ctx):
|
||||
with open(os.path.join(d, "t.raw"), "wb") as f:
|
||||
f.write(raw(sig))
|
||||
for name, video, layout in (("ac3.mkv", "-c:v mjpeg -pix_fmt yuvj420p", "5.1(side)"),
|
||||
("ac3.mp4", "-c:v mjpeg -pix_fmt yuvj420p", "stereo"), ("ac3.ts", "-c:v mpeg1video", "stereo")):
|
||||
("ac3.mp4", "-c:v mjpeg -pix_fmt yuvj420p", "stereo"), ("ac3.ts", "-c:v mpeg1video", "stereo"),
|
||||
("ac3.avi", "-c:v mjpeg -pix_fmt yuvj420p", "stereo")):
|
||||
run("ffmpeg -v error -y -f f32le -ar 48000 -ch_layout '5.1(side)' -i t.raw -af aformat=channel_layouts='%s' "
|
||||
"-c:a ac3 -b:a 192k t.ac3" % layout)
|
||||
with open(os.path.join(d, "t.ac3"), "rb") as f:
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# Docs inputs for the Musepack / AC-3 section of docs/guide/audio.md (tools/docs_check.py): a tagged stereo tone as
|
||||
# Musepack SV8 (mpcenc, built by tools/fixtures/mpc.py's nix expression) and a 5.1 tone as AC-3 (ffmpeg).
|
||||
# tests/gen/docs_lossy.luau { files = { [name] = bytes }, vars = { mpcBytes = "tone.mpc", ac3Bytes = "tone.ac3" } }
|
||||
import importlib.util, math, os, shutil, struct, subprocess, tempfile
|
||||
|
||||
INPUTS = ["tools/docs_check.py", "tools/fixtures/mpc.py"]
|
||||
|
||||
|
||||
def load(ctx, rel, name):
|
||||
spec = importlib.util.spec_from_file_location(name, os.path.join(ctx.root, rel))
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(m)
|
||||
return m
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
dc = load(ctx, "tools/docs_check.py", "docs_check")
|
||||
mpc = load(ctx, "tools/fixtures/mpc.py", "docs_lossy_mpc")
|
||||
d = tempfile.mkdtemp(prefix="fmt-docs-lossy-")
|
||||
try:
|
||||
rate, n = 44100, 44100
|
||||
st = [0.3 * math.sin(2 * math.pi * f * i / rate) for i in range(n) for f in (440, 660)]
|
||||
with open(os.path.join(d, "tone.wav"), "wb") as f:
|
||||
f.write(mpc.A.wav(st, rate, 2))
|
||||
subprocess.run([os.path.join(mpc.tools(), "mpcenc"), "--silent", "--overwrite", "--quality", "4",
|
||||
"--tag", "Title=Docs Tone", "--artist", "formats-luau", os.path.join(d, "tone.wav"),
|
||||
os.path.join(d, "tone.mpc")], capture_output=True, check=True)
|
||||
six = [0.2 * math.sin(2 * math.pi * (200 + 100 * c) * i / 48000) for i in range(24000) for c in range(6)]
|
||||
with open(os.path.join(d, "six.raw"), "wb") as f:
|
||||
f.write(struct.pack("<%df" % len(six), *six))
|
||||
ctx.nix("ffmpeg", ["sh", "-c", "cd '%s' && ffmpeg -v error -y -f f32le -ar 48000 -ch_layout '5.1(side)' -i six.raw "
|
||||
"-c:a ac3 -b:a 384k tone.ac3" % d])
|
||||
files = {}
|
||||
for name in ("tone.mpc", "tone.ac3"):
|
||||
with open(os.path.join(d, name), "rb") as f:
|
||||
files[name] = f.read()
|
||||
finally:
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
dc.emit_inputs(ctx, files, {"mpcBytes": "tone.mpc", "ac3Bytes": "tone.ac3"})
|
||||
Reference in new issue
Block a user