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:
4DBugandClaude Opus 5.5 committed 2026-10-31 11:01:22 -05:00
1 parent 8158acf3d5
commit fb2dd98db2
27 files changed
+164 -170

No files matched your search

+8 -8
View File
@@ -269,22 +269,22 @@ end
-- write(midi, opts?) -> buffer | nil, Err
function Smf.write(midi: Types.Midi, opts: WriteOptions?): (buffer?, Err.Err?)
if type(midi) ~= "table" or type(midi.tracks) ~= "table" then
return nil, Err.new(Err.ARG, "midi encode: needs a Midi value with tracks")
return nil, Err.new(Err.ARG, "needs a Midi value with tracks")
end
local running = not (opts and opts.runningStatus == false)
local format = midi.format or 1
local division = midi.division or 480
if type(format) ~= "number" or format < 0 or format > 2 or format % 1 ~= 0 then
return nil, Err.new(Err.ARG, "midi encode: format must be 0, 1 or 2")
return nil, Err.new(Err.ARG, "format must be 0, 1 or 2")
end
if type(division) ~= "number" or division == 0 or division < -32768 or division > 32767 or division % 1 ~= 0 then
return nil, Err.new(Err.ARG, "midi encode: division must be a non-zero 16-bit integer")
return nil, Err.new(Err.ARG, "division must be a non-zero 16-bit integer")
end
if format == 0 and #midi.tracks ~= 1 then
return nil, Err.new(Err.ARG, "midi encode: format 0 needs exactly one track")
return nil, Err.new(Err.ARG, "format 0 needs exactly one track")
end
if #midi.tracks > 65535 then
return nil, Err.new(Err.ARG, "midi encode: too many tracks")
return nil, Err.new(Err.ARG, "too many tracks")
end
local w = Bytes.writer(1024)
w:string("MThd")
@@ -295,7 +295,7 @@ function Smf.write(midi: Types.Midi, opts: WriteOptions?): (buffer?, Err.Err?)
for ti, track in midi.tracks do
local events = if type(track) == "table" then track.events else nil
if type(events) ~= "table" then
return nil, Err.new(Err.ARG, "midi encode: track " .. ti .. " has no events list")
return nil, Err.new(Err.ARG, "track " .. ti .. " has no events list")
end
-- stable order by tick
local sorted = true
@@ -338,7 +338,7 @@ function Smf.write(midi: Types.Midi, opts: WriteOptions?): (buffer?, Err.Err?)
end
local delta = ev.tick - prev
if delta > 0x0FFFFFFF then
return nil, Err.new(Err.ARG, "midi encode: a delta time over 0x0FFFFFFF ticks")
return nil, Err.new(Err.ARG, "a delta time over 0x0FFFFFFF ticks")
end
local base = TYPE_STATUS[t]
if base then
@@ -378,7 +378,7 @@ function Smf.write(midi: Types.Midi, opts: WriteOptions?): (buffer?, Err.Err?)
w:u8(if t == "sysex" then 0xF0 else 0xF7)
end
if #d > 0x0FFFFFFF then
return nil, Err.new(Err.ARG, "midi encode: event data too long")
return nil, Err.new(Err.ARG, "event data too long")
end
vlq(w, #d)
for _, c in d do