ws-music: music/sf2 + SoundFont tests vs FluidSynth (envelope r 0.995, band spectra r >= 0.969, pitch peaks within 0.6%), gain ramp per block, bench lines
tools/bench.sh: also generates the midi + sf2 fixtures (the bench renders their songs). licenses: TinySoundFont MIT row in NOTICE.md.
This commit is contained in:
1 parent
08af33d82a
commit
d7c2d2eeb5
10 files changed
+707
-11
No files matched your search
@@ -56,3 +56,63 @@ do
|
||||
Png.encode(img)
|
||||
end)
|
||||
end
|
||||
|
||||
-- MIDI through the SoundFont synth (tools/fixtures/sf2.py's test song; tools/fixtures/midi.py's "song" through the
|
||||
-- built-in waveform set): seconds of stereo 44.1 kHz audio rendered per second of CPU
|
||||
do
|
||||
local Midi = require("@formats/music/midi")
|
||||
local Sf2 = require("@formats/music/sf2")
|
||||
local SF = require("@tests/gen/sf2_cases")
|
||||
local MC = require("@tests/gen/midi_cases")
|
||||
local sf = assert(Sf2.decode(Bytes.reader(buffer.fromstring(SF.sf2))))
|
||||
local function realtime(label: string, data: string, font: any)
|
||||
local song = assert(Midi.decode(Bytes.reader(buffer.fromstring(data))))
|
||||
local best = math.huge
|
||||
local frames = 0
|
||||
for _ = 1, 3 do
|
||||
local dec = assert(Midi.render(song, { soundfont = font, tail = 0 }))
|
||||
local out = buffer.create(4096 * 8)
|
||||
local t0 = os.clock()
|
||||
frames = 0
|
||||
while true do
|
||||
local _, n = dec:read(4096, out)
|
||||
if n == 0 then
|
||||
break
|
||||
end
|
||||
frames += n
|
||||
end
|
||||
best = math.min(best, os.clock() - t0)
|
||||
end
|
||||
print(string.format("%-8s %-30s %8.2f ms %7.1f x realtime", runtime, label, best * 1000, frames / 44100 / best))
|
||||
end
|
||||
realtime("midi render sf2 (test song)", SF.song, sf)
|
||||
for _, c in MC do
|
||||
if c.name == "song" then
|
||||
realtime("midi render fallback", c.data, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- the synth's per-voice cost: 32 sustained, filtered, looped voices (sf2 saw preset with a mod env) for 2 s
|
||||
do
|
||||
local SoundFont = require("@formats/codecs/SoundFont")
|
||||
local Sf2 = require("@formats/music/sf2")
|
||||
local SF = require("@tests/gen/sf2_cases")
|
||||
local sf = assert(Sf2.decode(Bytes.reader(buffer.fromstring(SF.sf2))))
|
||||
local frames = 88200
|
||||
local out = buffer.create(frames * 8)
|
||||
local best = math.huge
|
||||
for _ = 1, 3 do
|
||||
local s = SoundFont.synth(sf, 44100)
|
||||
SoundFont.Synth.midi(s, 0xC0, 1, 0)
|
||||
for k = 0, 31 do
|
||||
SoundFont.Synth.midi(s, 0x90, 40 + k, 100)
|
||||
end
|
||||
buffer.fill(out, 0, 0)
|
||||
local t0 = os.clock()
|
||||
for f = 0, frames - 1, 1024 do
|
||||
SoundFont.Synth.render(s, out, f, 1024)
|
||||
end
|
||||
best = math.min(best, os.clock() - t0)
|
||||
end
|
||||
print(string.format("%-8s %-30s %8.2f ms %7.1f M voice-samples/s", runtime, "synth 32 voices x 2 s", best * 1000, 32 * frames / best / 1e6))
|
||||
end
|
||||
Reference in new issue
Block a user