ws-audio2: bench lines (IMA / DSP decode, QOA encode / decode) and the guide's game audio section
This commit is contained in:
1 parent
9466c5f471
commit
5216cb29a1
2 files changed
+92
-1
No files matched your search
@@ -1078,3 +1078,58 @@ do
|
||||
jitTune(false)
|
||||
end
|
||||
end
|
||||
-- ws-audio2: adpcm / qoa
|
||||
do
|
||||
-- codecs/audio/Adpcm (IMA nibble stream, Nintendo DSP frames) and QOA decode / encode, over generated signals; MB/s
|
||||
-- of f32 output (MB/s of input for the encoder)
|
||||
local Adpcm = require("@formats/codecs/audio/Adpcm")
|
||||
local QoaCodec = require("@formats/codecs/audio/Qoa")
|
||||
local Qoa = require("@formats/audio/qoa")
|
||||
local n = 44100 * 5
|
||||
local sig = Types.Audio.new(44100, 2, n)
|
||||
for i = 0, n - 1 do
|
||||
local t = i / 44100
|
||||
buffer.writef32(sig.samples, i * 8, 0.5 * math.sin(2 * math.pi * 440 * t) + 0.1 * math.sin(2 * math.pi * 3000 * t))
|
||||
buffer.writef32(sig.samples, i * 8 + 4, 0.4 * math.sin(2 * math.pi * 660 * t + 1))
|
||||
end
|
||||
-- IMA: encode the left channel as a nibble stream, then decode it
|
||||
local ima = buffer.create(n // 2)
|
||||
Adpcm.imaEncode(sig.samples, 0, 2, n, buffer.create(8), 0, ima, 0, 0, 1, false)
|
||||
local out = buffer.create(n * 4)
|
||||
bench("adpcm ima decode", 5, n * 4, function()
|
||||
Adpcm.ima(ima, 0, 0, 1, n, false, buffer.create(8), 0, out, 0, 1)
|
||||
end)
|
||||
-- DSP: random frames with 8 coefficient pairs
|
||||
local frames = n // 14
|
||||
local dsp = buffer.create(frames * 8)
|
||||
local seed = 1
|
||||
for i = 0, frames * 8 - 1 do
|
||||
seed = (seed * 1103515245 + 12345) % 2147483648
|
||||
local v = seed // 65536 % 256
|
||||
buffer.writeu8(dsp, i, if i % 8 == 0 then (v % 8) * 16 + v % 12 else v)
|
||||
end
|
||||
local coefs = buffer.create(64)
|
||||
for k = 0, 7 do
|
||||
buffer.writei32(coefs, k * 8, 1800 + k * 200)
|
||||
buffer.writei32(coefs, k * 8 + 4, -900 - k * 100)
|
||||
end
|
||||
bench("adpcm dsp decode", 5, frames * 14 * 4, function()
|
||||
Adpcm.dsp(dsp, 0, frames * 14, coefs, 0, buffer.create(8), 0, out, 0, 1)
|
||||
end)
|
||||
-- QOA (stereo 44.1 kHz)
|
||||
local file = assert(Qoa.encode(sig))
|
||||
bench("qoa encode", 2, n * 2 * 4, function()
|
||||
Qoa.encode(sig)
|
||||
end)
|
||||
local pcm = buffer.create(QoaCodec.FRAME_LEN * 2 * 4)
|
||||
bench("qoa decode", 5, n * 2 * 4, function()
|
||||
local p = 8
|
||||
while p < buffer.len(file) do
|
||||
local _, size = QoaCodec.decodeFrame(file, p, buffer.len(file) - p, pcm, 0)
|
||||
p += size :: number
|
||||
end
|
||||
end)
|
||||
bench("qoa decode (F.load path)", 5, n * 2 * 4, function()
|
||||
Qoa.decode(Bytes.reader(file))
|
||||
end)
|
||||
end
|
||||
Reference in new issue
Block a user