ws-music: music/midi (SMF 0/1/2 read/write, tempo map, render), codecs/SoundFont (SF2 parser + TinySoundFont-port synth + fallback waveform set), midi tests vs mido
Types.luau: Midi gets an optional render(self, opts) -> Decoder field (backward compatible; set by music/midi decode).
This commit is contained in:
1 parent
cdcb5b0b77
commit
08af33d82a
14 files changed
+2955
No files matched your search
@@ -0,0 +1,44 @@
|
||||
--!strict
|
||||
-- music/sf2: SoundFont 2 banks (SoundFont 2.04 specification), read-only. A thin wrapper over codecs/SoundFont (the
|
||||
-- parser and the TinySoundFont-port synth music/midi renders with). Supports: INFO, 16-bit samples (+ sm24 24-bit),
|
||||
-- presets / instruments / sample headers with global zones, generator merging into playable regions.
|
||||
-- Not supported: writing, SF3 (Ogg Vorbis samples), modulators (read past, not applied).
|
||||
-- decode returns the SoundFont value (kind "soundfont"): pass it to music/midi render as opts.soundfont.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@formats/core/Err")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local SoundFont = require("@formats/codecs/SoundFont")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Sf2 = {
|
||||
name = "sf2",
|
||||
category = "music",
|
||||
extensions = { "sf2" },
|
||||
mime = { "audio/x-soundfont" },
|
||||
deps = { "core/Err", "core/Bytes", "codecs/SoundFont" },
|
||||
caps = { decode = true, encode = false, sm24 = true, sf3 = false },
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
maxRegions: number?, -- default 10^6
|
||||
maxSamples: number?, -- default 2^28
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
function Sf2.sniff(r: Bytes.Reader): number
|
||||
return if SoundFont.sniff(r) then 1 else 0
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
function Sf2.decode(r: Bytes.Reader, opts: DecodeOptions?): (SoundFont.SoundFont?, Err.Err?)
|
||||
return SoundFont.parse(r, opts)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ extras
|
||||
-- synth(sf?, sampleRate?, opts?) -> a synth State (codecs/SoundFont.Synth drives it)
|
||||
Sf2.synth = SoundFont.synth
|
||||
Sf2.fallback = SoundFont.fallback
|
||||
|
||||
return Sf2
|
||||
Reference in new issue
Block a user