ws-audio: FLAC encoder (audio/flac/Encode: levels 0-8 like libFLAC presets, fixed + LPC + Rice/Rice2 partition search, wasted bits, stereo decorrelation, MD5, VORBIS_COMMENT, SEEKTABLE, padding; streams from a Decoder) wired into audio/flac encode; core/Md5 (new core module, RFC 1321) + test; fixtures: flac -t + MD5 bit-exact on 76 encodes, sizes within 1.1% of libFLAC; bench lines

This commit is contained in:
4DBug committed 2026-10-31 09:04:31 -05:00
1 parent bdab71df77
commit c74c93ae11
10 files changed
+1553 -6

No files matched your search

+19
View File
@@ -125,3 +125,22 @@ do
Wav.decode(Bytes.reader(file))
end)
end
-- flac encode (ws-audio): 10 s of 44.1 kHz stereo 16-bit (a synthetic two-tone signal with noise)
do
local Fl = require("@formats/audio/flac")
local n = 441000
local a = Types.Audio.new(44100, 2, n)
local seed = 1
for i = 0, n - 1 do
seed = (seed * 1103515245 + 12345) % 2147483648
local noise = (seed / 2147483648 - 0.5) * 0.01
buffer.writef32(a.samples, i * 8, math.floor((math.sin(i * 0.031) * 0.4 + math.sin(i * 0.21) * 0.1 + noise) * 32768) / 32768)
buffer.writef32(a.samples, i * 8 + 4, math.floor((math.sin(i * 0.017) * 0.3 + noise) * 32768) / 32768)
end
for _, level in { 0, 5, 8 } do
local dt = bench("flac encode -" .. level .. " (10 s st 16)", 2, n * 4, function()
Fl.encode(a, { level = level })
end)
print(string.format("%-8s %-30s %8.0fx real time", runtime, "", 10 / dt))
end
end