merge ws/audio

This commit is contained in:
4DBug committed 2026-10-31 09:37:28 -05:00
commit fa98dd77c2
43 files changed
+8963 -19

No files matched your search

+59
View File
@@ -90,6 +90,16 @@ for _, c in { { "celt 128k", OpusCelt }, { "silk wb", OpusSilk }, { "hybrid", Op
Opus.decode(Bytes.reader(b))
end)
end
-- vorbis (ws-audio): 10 s of 44.1 kHz stereo music at oggenc -q 5 (tools/fixtures/vorbis.py)
do
local Vorbis = require("@formats/audio/vorbis")
local VB = require("@tests/gen/vorbis_bench")
local b = buffer.fromstring(VB.data)
local dt = bench("vorbis decode q5 (10 s st)", 3, VB.frames * VB.channels * 4, function()
Vorbis.decode(Bytes.reader(b))
end)
print(string.format("%-8s %-30s %8.0fx real time", runtime, "", VB.frames / VB.rate / dt))
end
for _, name in { "s16_long", "s24_96k" } do
for _, c in FC do
if c.name == name then
@@ -116,6 +126,55 @@ 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
-- mp3 / mp2 encode (ws-audio): 10 s of 44.1 kHz stereo tones
do
local M3 = require("@formats/audio/mp3")
local n = 441000
local a = Types.Audio.new(44100, 2, n)
for i = 0, n - 1 do
buffer.writef32(a.samples, i * 8, math.sin(i * 0.031) * 0.4 + math.sin(i * 0.21) * 0.1)
buffer.writef32(a.samples, i * 8 + 4, math.sin(i * 0.017) * 0.3)
end
for _, cfg in { { layer = 3, bitrate = 128 }, { layer = 2, bitrate = 192 } } do
local dt = bench(string.format("mp%d encode %d kbps (10 s st)", cfg.layer, cfg.bitrate), 2, n * 8, function()
M3.encode(a, cfg)
end)
print(string.format("%-8s %-30s %8.1fx real time", runtime, "", 10 / dt))
end
end
-- vorbis encode (ws-audio): 10 s of 44.1 kHz stereo tones at quality 3
do
local Vb = require("@formats/audio/vorbis")
local n = 441000
local a = Types.Audio.new(44100, 2, n)
for i = 0, n - 1 do
buffer.writef32(a.samples, i * 8, math.sin(i * 0.031) * 0.4 + math.sin(i * 0.21) * 0.1)
buffer.writef32(a.samples, i * 8 + 4, math.sin(i * 0.017) * 0.3)
end
local dt = bench("vorbis encode q3 (10 s st)", 2, n * 8, function()
Vb.encode(a, { quality = 3 })
end)
print(string.format("%-8s %-30s %8.1fx real time", runtime, "", 10 / dt))
end
do
local Json = require("@formats/codecs/Json")
local JB = require("@tests/gen/json_bench")