ws-audio2: audio/ac3 sniffs E-AC-3 too (loading one says UNSUPPORTED, not an unknown format); fixture tidy

This commit is contained in:
4DBug committed 2026-10-31 14:52:41 -05:00
1 parent 2d99b9924a
commit 62aded60c0
3 files changed
+6 -8

No files matched your search

+2 -1
View File
@@ -32,10 +32,11 @@ export type DecodeOptions = {
}
-- ------------------------------------------------------------------------------------------------ sniff
-- (E-AC-3 streams sniff too, so loading one says UNSUPPORTED instead of an unknown format)
function Ac3Format.sniff(r: Bytes.Reader): number
local b, p, limit = r.buf, r.pos, r.limit
local h = Ac3.header(b, p, limit)
if not h or h.bsid > 10 then
if not h then
return 0
end
local h2 = Ac3.header(b, p + h.frameSize, limit)
+2
View File
@@ -128,6 +128,8 @@ do
local eac3 = "\11\119\0\255\128\128" .. string.rep("\0", 506)
_, e = Ac3F.decode(reader(eac3 .. eac3))
t:check(e and e.code == Err.UNSUPPORTED, "E-AC-3: " .. tostring(e))
local _, fe = F.audio.load(buffer.fromstring(eac3 .. eac3))
t:check(fe and fe.code == Err.UNSUPPORTED, "E-AC-3 through the api: " .. tostring(fe))
-- a flipped bit in the middle of the first frame: the CRC catches it
local bad = string.sub(c, 1, 300) .. string.char(bit32.bxor(string.byte(c, 301), 4)) .. string.sub(c, 302)
_, e = Ac3F.decode(reader(bad))
+2 -7
View File
@@ -12,7 +12,7 @@
# tests/gen/ac3_cases.luau { name, data, channels, rate, frames, ref (f32le, WAVE order), refTool, refDrc?,
# dithered? }
# tests/gen/ac3_tracks.luau { name, data (the container), channels, rate, ref (ffmpeg's decode of the AC-3) }
import importlib.util, math, os, random, shutil, struct, subprocess, tempfile
import importlib.util, math, os, random, shutil, struct, tempfile
_spec = importlib.util.spec_from_file_location("_audio", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_audio.py"))
A = importlib.util.module_from_spec(_spec)
@@ -28,7 +28,6 @@ def _lit(b):
return '"' + "".join("\\x%02x" % x for x in b) + '"'
def crc16(data, crc=0):
"""A/52 section 7.10.1: x^16 + x^15 + x^2 + 1, MSB first, zero start"""
for b in data:
@@ -99,11 +98,7 @@ end
out[o:o + size] = f
return bytes(out)
# 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
# positions come from our decoder's dec.blocks, the CRCs are recomputed): ffmpeg and we then decode the same numbers.
# `dithered` keeps the encoder's original stream for a few cases.
#
# name, encoder, layout (ffmpeg) or (acmod, lfe) (aften), rate, kbps, extra options
CASES = [
("mono_48k", "ffmpeg", "mono", 48000, 96, []),