ws-cleanup: consistency (lower-case tags, WAVE channel order, loops = play count, Err messages, caps)
- Audio tags keys are lower case everywhere (Types.Tags): FLAC no longer returns TITLE / ARTIST (the raw fields stay
in meta.source.comments; also for Vorbis and Opus); Vorbis / Opus / FLAC read and write tags through
codecs/VorbisComment (TRACKNUMBER -> track, DISCNUMBER -> disc, DESCRIPTION -> comment); MP3 albumArtist ->
albumartist and year -> date (ID3 TYER / TDRC, ID3v1); RIFF INFO / CAF / MP4 freeform names are lower-cased (MP4
writes iTunSMPB / iTunNORM back in their usual spelling; m4a reads tags.itunsmpb).
- Channel order: Vorbis (and Opus mapping family 1) decode to WAVE order like FLAC / WAV / AAC (both used to return
the Vorbis order); the Vorbis encoder takes WAVE order and writes Vorbis order. Pcm.WAVE_FROM_VORBIS / Pcm.reorder;
Vorbis.packetDecoder gives pd.order. Tests reorder oggdec's / opusdec's raw (Vorbis-order) references.
- img.loops is the play count in GIF, APNG and WebP (they already agreed; Types / WebP docs said "loop count");
tests/api round-trips loops 0 / 1 / 3 through all three.
- Err: messages without the format name (png / midi encoders said "png encode: ..."); codecs/Bzip2 and codecs/Zstd
check arguments through Bytes.span.
- caps: mp3 encodeLayers = { 2, 3 }, opus encodeChannels = 2.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
8158acf3d5
commit
fb2dd98db2
27 files changed
+164
-170
No files matched your search
@@ -129,4 +129,28 @@ do
|
||||
t:check(F.data.null == F.null, "F.data.null")
|
||||
end
|
||||
|
||||
-- img.loops is a play count in every animated format (GIF stores repeats; APNG / WebP store plays)
|
||||
do
|
||||
local function anim(loops: number): any
|
||||
local img = image(8, 8)
|
||||
img.frames = {}
|
||||
for k = 1, 2 do
|
||||
local fr = image(8, 8)
|
||||
buffer.writeu8(fr.pixels, 0, k)
|
||||
table.insert(img.frames, { image = fr, delay = 0.1, x = 0, y = 0, dispose = "none", blend = "source" })
|
||||
end
|
||||
img.loops = loops
|
||||
return img
|
||||
end
|
||||
for _, fmt in { "gif", "png", "webp" } do
|
||||
for _, loops in { 0, 1, 3 } do
|
||||
local saved, err = F.save(anim(loops), nil, { format = fmt, lossless = true })
|
||||
t:check(saved, fmt .. " loops " .. loops .. ": " .. tostring(err))
|
||||
local back = saved and F.load(saved)
|
||||
t:check(back and back.frames and #back.frames == 2, fmt .. " loops " .. loops .. ": animated")
|
||||
t:eq(back and back.loops, loops, fmt .. ": loops " .. loops .. " round trip")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -4,6 +4,7 @@
|
||||
-- Reader; tags and pictures; the length from the last frame; sniff; the api; damaged frames skipped; the fuzz pass.
|
||||
-- Ported from flac-luau tests/flac.luau. Fixtures: tools/fixtures/flac.py.
|
||||
local T = require("@tests/T")
|
||||
local VorbisComment = require("@formats/codecs/VorbisComment")
|
||||
local Flac = require("@formats/audio/flac")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
@@ -92,8 +93,8 @@ for _, fx in Cases do
|
||||
t:check(math.abs(pos - fx.frames / 3) <= 1, name .. ": seek seconds")
|
||||
dec:seek(dec.duration + 5)
|
||||
t:eq(select(2, dec:read(10)), 0, name .. ": read past the end")
|
||||
for key, v in fx.tags or {} do
|
||||
t:eq(dec.tags[key], v, name .. ": tag " .. key)
|
||||
for key, v in fx.tags or {} do -- (tags keys are lower case: codecs/VorbisComment)
|
||||
t:eq(dec.tags[VorbisComment.tagKey(key)], v, name .. ": tag " .. key)
|
||||
end
|
||||
t:eq(Flac.sniff(Bytes.reader(buffer.fromstring(fx.data))), 1, name .. ": sniff")
|
||||
end
|
||||
|
||||
@@ -80,9 +80,9 @@ do
|
||||
t:eq(back.meta.source.bitDepth, 8, "bit depth from meta.source")
|
||||
-- (the absorbed FLAC decoder keeps Vorbis comment keys upper case)
|
||||
local tags = back.tags :: any
|
||||
t:eq(tags.title or tags.TITLE, "Tïtle", "title")
|
||||
t:eq(tags.artist or tags.ARTIST, "Artist", "artist")
|
||||
t:eq(tags.track or tags.TRACKNUMBER, "3", "track number")
|
||||
t:eq(tags.title, "Tïtle", "title")
|
||||
t:eq(tags.artist, "Artist", "artist")
|
||||
t:eq(tags.track, "3", "track number")
|
||||
local empty = Flac.encode(Types.Audio.new(44100, 2, 0)) :: buffer
|
||||
local e0 = Flac.decode(Bytes.reader(empty))
|
||||
t:check(e0 and e0.frames == 0, "empty audio")
|
||||
|
||||
@@ -344,7 +344,7 @@ do
|
||||
eq(tg.title, "Test Title", "fixture title")
|
||||
eq(tg.artist, "Some Artist", "fixture artist")
|
||||
eq(tg.album, "An Album", "fixture album")
|
||||
eq(tg.year, "2001", "fixture year")
|
||||
eq(tg.date, "2001", "fixture year")
|
||||
eq(tg.track, "7", "fixture track")
|
||||
eq(tg.genre, "Rock", "fixture genre")
|
||||
eq(tg.comment, "hello", "fixture comment")
|
||||
@@ -405,7 +405,7 @@ do
|
||||
eq(dec.tags.title, "Ünïcödé ★ title", "v2.4 title")
|
||||
eq(dec.tags.artist, "One / Two", "v2.4 multi-value")
|
||||
eq(dec.tags.genre, "Rock", "v2.4 genre")
|
||||
eq(dec.tags.year, "1999-05-01", "v2.4 TDRC")
|
||||
eq(dec.tags.date, "1999-05-01", "v2.4 TDRC")
|
||||
eq(dec.tags.comment, "a comment", "v2.4 COMM")
|
||||
sameAudio(dec, "v2.4")
|
||||
t:check(Mp3.sniff(Bytes.reader(withAudio(tag))) >= 0.7, "sniff behind an ID3v2 tag")
|
||||
@@ -453,7 +453,7 @@ do
|
||||
eq(dec.tags.title, "V1 Title", "v1 title")
|
||||
eq(dec.tags.artist, "V1 Artist", "v1 artist")
|
||||
eq(dec.tags.album, "V1 Album", "v1 album")
|
||||
eq(dec.tags.year, "1987", "v1 year")
|
||||
eq(dec.tags.date, "1987", "v1 year")
|
||||
eq(dec.tags.comment, "v1 comment", "v1 comment")
|
||||
eq(dec.tags.track, "9", "v1.1 track")
|
||||
eq(dec.tags.genre, "Rock", "v1 genre")
|
||||
|
||||
@@ -7,6 +7,7 @@ local Vorbis = require("@formats/audio/vorbis")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Types = require("@formats/Types")
|
||||
local Pcm = require("@formats/codecs/Pcm")
|
||||
local Ogg = require("@formats/containers/Ogg")
|
||||
local Cases = require("@tests/gen/vorbis_cases")
|
||||
|
||||
@@ -57,6 +58,17 @@ for _, c in Cases do
|
||||
t:eq(a.frames, c.inputFrames, c.name .. ": frames = the encoder's input")
|
||||
local ref16 = buffer.fromstring(c.ref16)
|
||||
local n = c.frames * c.channels
|
||||
-- oggdec -R keeps the Vorbis channel order; the decoder returns WAVE order (codecs/Pcm)
|
||||
local order = Pcm.WAVE_FROM_VORBIS[c.channels]
|
||||
if c.channels > 2 and order then
|
||||
local w = buffer.create(buffer.len(ref16))
|
||||
for f = 0, c.frames - 1 do
|
||||
for ch = 1, c.channels do
|
||||
buffer.writei16(w, (f * c.channels + ch - 1) * 2, buffer.readi16(ref16, (f * c.channels + order[ch] - 1) * 2))
|
||||
end
|
||||
end
|
||||
ref16 = w
|
||||
end
|
||||
local d = maxDiff16(a.samples, 0, ref16, 0, n)
|
||||
t:check(d <= 1, string.format("%s: within 1 LSB of oggdec (max %d)", c.name, d))
|
||||
if c.ffRef then
|
||||
|
||||
@@ -182,7 +182,7 @@ end
|
||||
do -- tags
|
||||
local info = "INFO" .. "INAM" .. u32(3) .. "abc\0" .. "IART" .. u32(6) .. "xy\0\0\0\0" .. "IXYZ" .. u32(2) .. "zz" .. "ITRK" .. u32(2) .. "7\0"
|
||||
local dec = open(riff(fmt(1, 1, 8000, 8), chunk("LIST", info), chunk("data", "\128\128\128")))
|
||||
t:check(dec and dec.tags.title == "abc" and dec.tags.artist == "xy" and dec.tags.IXYZ == "zz" and dec.tags.track == "7", "tags")
|
||||
t:check(dec and dec.tags.title == "abc" and dec.tags.artist == "xy" and dec.tags.ixyz == "zz" and dec.tags.track == "7", "tags")
|
||||
t:check(dec and dec.frames == 3, "8-bit odd data")
|
||||
end
|
||||
do -- 8-bit, A-law and mu-law values
|
||||
@@ -251,7 +251,7 @@ do
|
||||
-- tags
|
||||
a.tags = { title = "Hello", artist = "Someone", IXYZ = "kept", comment = "" }
|
||||
local tg = Wav.decode(Bytes.reader(Wav.encode(a, { sampleFormat = "u8" }) :: buffer)) :: any
|
||||
t:check(tg.tags.title == "Hello" and tg.tags.artist == "Someone" and tg.tags.IXYZ == "kept" and tg.tags.comment == nil, "tag round trip")
|
||||
t:check(tg.tags.title == "Hello" and tg.tags.artist == "Someone" and tg.tags.ixyz == "kept" and tg.tags.comment == nil, "tag round trip")
|
||||
-- encodeParts, and RF64 chosen automatically past the threshold
|
||||
local big = Types.Audio.new(44100, 2, 3000)
|
||||
for i = 0, 3000 * 2 - 1 do
|
||||
|
||||
Reference in new issue
Block a user