audio formats: comments are specs only

This commit is contained in:
4DBug committed 2026-11-01 01:53:49 -05:00
1 parent 0bd7b87d2b
commit 6ffbdbe0be
29 files changed
+143 -442

No files matched your search

+6 -11
View File
@@ -1,11 +1,7 @@
--!strict
-- audio/voc: Creative Voice File (.voc, Sound Blaster). New code from the Creative file format description.
-- Supports: decode / open of block types 1 (sound data: 8-bit unsigned, 16-bit), 2 (continuation), 3 (silence),
-- 5 (text: tags.comment), 8 (extended: stereo / high rates for the next type 1 block), 9 (new sound data: 8-bit
-- unsigned, 16-bit signed, A-law, mu-law, any rate / channel count); markers and repeat loops are skipped (played
-- once, as ffmpeg does); truncated files decode the data present. Encode (Audio or Decoder, streamed) as version
-- 1.20 type 9 blocks of u8 / s16 (default) / alaw / ulaw. Not supported: Creative 4 / 2.6 / 2-bit ADPCM
-- (Err.UNSUPPORTED), blocks that change the channel count mid-file (the sample rate of the first block is used).
-- audio/voc: Creative Voice File (.voc), from Creative's format description. Supports: block types 1, 2, 3, 5, 8, 9
-- (8 / 16-bit, A-law, mu-law); markers and repeats played once, as ffmpeg; truncated files; encode version 1.20 type 9
-- blocks. Not supported: Creative ADPCM, channel count changes mid-file (the first block's rate is used).
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
@@ -24,7 +20,7 @@ local Voc = {
}
export type DecodeOptions = {
maxFrames: number?, -- refuse more sample frames (default 2^28)
maxFrames: number?, -- default 2^28
}
export type EncodeOptions = {
sampleFormat: ("u8" | "s16" | "alaw" | "ulaw")?, -- default "s16"
@@ -73,7 +69,6 @@ function Voc.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Audio?, Err.E
local truncated = false
local tags: Types.Tags = {}
local p = base + hsize
-- add(at, bytes, fmt, ch, sr): a run of samples (or silence when fmt is nil and bytes = frames)
local function add(at: number, bytes: number, fmt: string?, ch: number, sr: number): Err.Err?
if channels == 0 then
channels, rate = ch, sr
@@ -177,7 +172,7 @@ function Voc.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Audio?, Err.E
local n = s.frames * channels
if s.fmt then
Pcm.Convert.decode(b, s.at, s.fmt :: string, n, a.samples, o)
end -- silence: the buffer is already zero
end
o += n * 4
end
a.tags = tags
@@ -238,7 +233,7 @@ function Voc.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
blockAt = w:tell()
blockFrames = 0
w:u8(9)
w:u24le(0) -- patched
w:u24le(0)
w:u32le(src.sampleRate)
w:u8(spec[3])
w:u8(src.channels)