diff --git a/src/Formats/audio/ac3/init.luau b/src/Formats/audio/ac3/init.luau index 4f69ea9..c481523 100644 --- a/src/Formats/audio/ac3/init.luau +++ b/src/Formats/audio/ac3/init.luau @@ -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) diff --git a/tests/audio/ac3.luau b/tests/audio/ac3.luau index 447c959..7b67ca4 100644 --- a/tests/audio/ac3.luau +++ b/tests/audio/ac3.luau @@ -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)) diff --git a/tools/fixtures/ac3.py b/tools/fixtures/ac3.py index a0c394e..4e8f26f 100644 --- a/tools/fixtures/ac3.py +++ b/tools/fixtures/ac3.py @@ -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, []),