Types.luau: Midi gets an optional render(self, opts) -> Decoder field (backward compatible; set by music/midi decode).
45 lines
2.0 KiB
Luau
45 lines
2.0 KiB
Luau
--!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
|