Documentation
¶
Overview ¶
Package midi renders Standard MIDI Files (.mid, .midi, .kar and RIFF .rmi) to stereo float audio. By default notes are played on an emulated OPL3 FM chip by libADLMIDI with an embedded General MIDI bank, so MIDI works with nothing installed; when a SoundFont is configured the song is rendered from its samples by TinySoundFont instead. A Decoder is a beep StreamSeekCloser.
Index ¶
Constants ¶
const ( // DefaultSampleRate is the output rate used when Options.SampleRate is 0. DefaultSampleRate = 48000 // DefaultMaxVoices is the SoundFont voice cap used when // Options.MaxVoices is 0. DefaultMaxVoices = 64 // MaxFileBytes is the largest MIDI file Open reads. MaxFileBytes = 8 << 20 // MaxSoundFontBytes is the largest SoundFont file that is loaded. MaxSoundFontBytes = 512 << 20 // DefaultSoundFontMemory is the SoundFont memory budget used when // Options.SoundFontMemory is 0. DefaultSoundFontMemory = 2 << 30 // RendererFM and RendererSoundFont are the values of Info.Renderer. RendererFM = "fm" RendererSoundFont = "soundfont" )
Variables ¶
var ( // ErrSoundFont is wrapped by the error logged when the configured // SoundFont cannot be used. Open does not return it: the song is // rendered with the FM synthesizer instead. ErrSoundFont = errors.New("midi: cannot load SoundFont") // ErrClosed is returned by a Decoder used after Close. ErrClosed = errors.New("midi: decoder closed") // ErrTooLarge is returned for a MIDI file above MaxFileBytes. ErrTooLarge = errors.New("midi: file too large") )
Functions ¶
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder streams one rendered song. It is not safe for concurrent use.
func OpenBytes ¶
OpenBytes renders a MIDI file held in memory. data may be a Standard MIDI File or an RMI file wrapping one; FM rendering also takes the other formats libADLMIDI reads (XMI, MUS and friends). A SoundFont that cannot be loaded is logged and the song is rendered with FM instead.
func (*Decoder) Len ¶
Len is the stream length in frames, including a release tail of about a second after the last event.
func (*Decoder) SampleRate ¶
SampleRate is the output rate in Hz.
type Info ¶
type Info struct {
// Title comes from the karaoke title, track name or text meta events;
// it is "" when the file has none.
Title string
// Renderer is RendererFM or RendererSoundFont for a Decoder, and ""
// from ReadInfo, which does not pick a renderer.
Renderer string
}
Info describes a song.
type Options ¶
type Options struct {
// SoundFontPath selects SoundFont rendering; "" uses FM synthesis.
SoundFontPath string
// SampleRate is the output rate in Hz; 0 means DefaultSampleRate.
SampleRate int
// MaxVoices caps simultaneous SoundFont voices; 0 means
// DefaultMaxVoices. It does not apply to FM synthesis.
MaxVoices int
// SoundFontMemory caps the memory loading the SoundFont may take: the
// file plus the samples it decodes to, which for SF3 can be many times
// the file. A SoundFont over it renders with FM instead. 0 means
// DefaultSoundFontMemory.
SoundFontMemory int64
}
Options configures a Decoder.