ws-polish: Flash ADPCM (FLV SoundFormat 1) decodes through codecs/audio/Adpcm.swf

Adpcm.swf / swfFrames: the SWF ADPCM bit stream (2..5-bit codes, 4096-frame blocks), bit-exact with
ffmpeg's adpcm_swf (mono and stereo FLV fixtures). containers/AudioWrap decodes adpcm_swf tracks into a
float WAV, so FLV audio opens through the api hook.
This commit is contained in:
4DBug committed 2026-10-31 17:10:51 -05:00
1 parent c0412f76cb
commit c420eab820
7 files changed
+181 -12

No files matched your search

+24 -1
View File
@@ -2,7 +2,8 @@
-- (tools/fixtures/adpcm.py: ADX from ffmpeg and PS-ADPCM / DSP from our Python encoders decoded by vgmstream, Apple
-- ima4 from ffmpeg, IMA nibble streams decoded by ffmpeg); ADX coefficients; the encoders (IMA nibbles, IMA WAV
-- blocks, MS blocks) decoded back with a signal-to-noise floor; the Decoder layouts (seeking matches a straight
-- read); a fuzz pass of random bytes through every kernel (ranges valid, contents random) and the layouts.
-- read); Flash ADPCM by hand; a fuzz pass of random bytes through every kernel (ranges valid, contents random) and
-- the layouts.
local T = require("@tests/T")
local Adpcm = require("@formats/codecs/audio/Adpcm")
local Decoder = require("@formats/codecs/audio/Adpcm/Decoder")
@@ -88,6 +89,25 @@ do
end
end
-- Flash ADPCM (bit-exact with ffmpeg's adpcm_swf in tests/video/flv.luau): a hand-made 2-bit packet of 4 bytes:
-- code size 0 (2-bit codes), first sample 100, step index 0, then the codes 01 11 00 00
do
local bits = "00" .. "0000000001100100" .. "000000" .. "01110000"
local src = buffer.create(4)
for i = 0, 3 do
buffer.writeu8(src, i, tonumber(string.sub(bits, i * 8 + 1, i * 8 + 8), 2) :: number)
end
t:eq(Adpcm.swfFrames(src, 0, 4, 1), 5, "swf: frames in a 4-byte packet")
local out = buffer.create(20)
t:eq(Adpcm.swf(src, 0, 4, 1, out, 0), 5, "swf: frames decoded")
-- 01: +7 + 7/2 = 110 (index 0 + 2: step 9); 11: -(9 + 4) = 97 (index 4: step 11); 00: +5 = 102 (index 3: step
-- 10); 00: +5 = 107
local want = { 100, 110, 97, 102, 107 }
for i, v in want do
t:eq(buffer.readf32(out, (i - 1) * 4) * 32768, v, "swf sample " .. i)
end
end
-- ------------------------------------------------------------------------------------------------ encoders
local function snr(x: buffer, y: buffer, count: number): number
local sig, err = 0, 0
@@ -235,6 +255,9 @@ t:fuzz("kernels", function(b: buffer)
if n >= 17 then
Adpcm.modplug(b, 0, math.min((n - 16) * 2, 1000), out, 0)
end
if n >= 1 then
Adpcm.swf(b, 0, math.min(n, 600), 1 + n % 2, buffer.create(Adpcm.swfFrames(b, 0, math.min(n, 600), 1 + n % 2) * 8 + 8), 0)
end
Adpcm.imaWav(b, 0, n, 2, 1017, buffer.create(1017 * 2 * 4), 0)
Adpcm.msBlock(b, 0, n, 2, 1012, buffer.create(1012 * 2 * 4), 0, coefs, 8, buffer.create(40))
local dec = Decoder.interleaved({ sampleRate = 8000, channels = 2, tags = {} }, { kind = "adx", buf = b, offset = 0, size = n, interleave = 18, c1 = 7334, c2 = -3283 })
+6 -5
View File
@@ -1,9 +1,10 @@
-- video/flv tests: FLV files from ffmpeg (Sorenson Spark + MP3 / PCM s16 / PCM u8 / ADPCM / Nellymoser / Speex /
-- A-law, H.264 with B-frames + AAC, Flash screen video, audio only): tracks and every packet against ffprobe
-- (composition times in the pts, keyframes), onMetaData, frames against ffmpeg (Sorenson bit-exact, H.264 PSNR), audio
-- through the api hook (PCM exact; ADPCM / Nellymoser / Speex known but UNSUPPORTED), seeking; crafted VP6 /
-- enhanced FourCC / encrypted / truncated files; our writer (FLV, MP4, Matroska sources) read back by ffprobe and
-- ffmpeg (tools/fixtures/flv.py) and by our demuxer with the source's packets; fuzz. Fixtures: tools/fixtures/flv.py.
-- through the api hook (PCM and Flash ADPCM mono / stereo exact against ffmpeg's adpcm_swf; Nellymoser / Speex known
-- but UNSUPPORTED), seeking; crafted VP6 / enhanced FourCC / encrypted / truncated files; our writer (FLV, MP4,
-- Matroska sources) read back by ffprobe and ffmpeg (tools/fixtures/flv.py) and by our demuxer with the source's
-- packets; fuzz. Fixtures: tools/fixtures/flv.py.
local T = require("@tests/T")
local C = require("@tests/video/_common")
local F = require("@formats")
@@ -19,8 +20,8 @@ local t = T.suite("flv")
t:eq(Flv.name, "flv", "name")
t:eq(Flv.category, "video", "category")
local EXACT_AUDIO = { pcm_s16le = true, pcm_u8 = true, pcm_alaw = true }
local NO_AUDIO_FORMAT = { adpcm_swf = true, nellymoser = true, speex = true }
local EXACT_AUDIO = { pcm_s16le = true, pcm_u8 = true, pcm_alaw = true, adpcm_swf = true }
local NO_AUDIO_FORMAT = { nellymoser = true, speex = true }
local byName = {}
for _, c in Fx do
byName[c.name] = c