Assembly: Bass.Net (in Bass.Net.dll) Version: 188.8.131.52
public static int BASS_MIDI_FontInit( string file, BASSFlag flags )
Public Shared Function BASS_MIDI_FontInit ( file As String, flags As BASSFlag ) As Integer
- Type: SystemString
The file name of the sound font (e.g. an .sf2 file).
- Type: Un4seen.BassBASSFlag
Any combination of these flags (see BASSFlag):
BASS_MIDI_FONT_MMAP Map the file into memory. This flag is ignored if the soundfont is packed as the sample data cannot be played directly from a mapping; it needs to be decoded. This flag is also ignored if the file is too large to be mapped into memory. BASS_MIDI_FONT_XGDRUMS Use bank 127 in the soundfont for XG drum kits. When an XG drum kit is needed, bank 127 in soundfonts that have this flag set will be checked first, before falling back to bank 128 (the standard SF2 drum kit bank) if it is not available there. BASS_MIDI_FONT_NOFX Ignore the soundfont's reverb and chorus settings.
If you would like to ignore the soundfont's reverb/chorus on only some presets/banks, then you can load 2 instances of it (one with BASS_MIDI_FONT_NOFX flag and one without), and then assign them as wanted in a BASS_MIDI_StreamSetFonts call. The 2 instances will share resources, so they won't really use any more memory than 1 instance.
Return ValueType: Int32
If successful, the soundfont's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.
BASSMIDI uses SF2 and/or SFZ soundfonts to provide the sounds to use in the rendering of MIDI files. Several soundfonts can be found on the internet, including a couple on the BASS website.
A soundfont needs to be initialized before it can be used to render MIDI streams. Once initialized, a soundfont can be assigned to MIDI streams using the BASS_MIDI_StreamSetFonts(Int32, BASS_MIDI_FONT, Int32) function. A single soundfont can be shared by multiple MIDI streams.
Information on the initialized soundfont can be retrieved using BASS_MIDI_FontGetInfo(Int32, BASS_MIDI_FONTINFO).
If a soundfont is initialized multiple times, each instance will have its own handle but share the same sample/etc data.
Soundfonts use PCM sample data as standard, but BASSMIDI can accept any format that is supported by BASS or its add-ons. The BASS_MIDI_FontPack(Int32, String, String, BASSFlag) function can be used to compress the sample data in SF2 files. SFZ samples are in separate files and can be compressed using standard encoding tools.
Using soundfonts that are located somewhere other than the file system is possible via BASS_MIDI_FontInitUser(BASS_FILEPROCS, IntPtr, BASSFlag).
The SF2 synthesis model is fully supported, as are all SF2 generators. Basic support for the note velocity to filter cutoff (initialFilterFc) and note velocity to volume envelope attack (attackVolEnv) modulators is also included. In each case, multiple modulators in the global/instrument/preset zones is supported but only if they are identical (eg. all linear negative mono). If different types are present on a preset, then the last one (with a non-zero amount) will be used. The SF2 spec's slightly strange default note velocity to filter cutoff modulator is not used.
The following SFZ opcodes are supported: ampeg_attack, ampeg_decay, ampeg_delay, ampeg_hold, ampeg_release, ampeg_sustain, ampeg_vel2attack, ampeg_vel2decay, amplfo_delay/fillfo_delay/pitchlfo_delay, amplfo_depth, amplfo_freq/fillfo_freq/pitchlfo_freq, amp_veltrack, cutoff, default_path, effect1, effect2, end, fileg_attack/pitcheg_attack, fileg_decay/pitcheg_decay, fileg_delay/pitcheg_delay, fileg_depth, fileg_hold/pitcheg_hold, fileg_release/pitcheg_release, fileg_sustain/pitcheg_sustain, fileg_vel2depth, fillfo_depth, fil_veltrack, group, hicc1, hicc64, hikey, hirand, hivel, key, locc1, locc64, lokey, loop_end, loop_mode, loop_start, lorand, lovel, offset, off_by, off_mode, pan, pitcheg_depth, pitchlfo_depth, pitch_keycenter, pitch_keytrack, pitch_veltrack, resonance, sample, seq_length, seq_position, transpose, tune, volume. The fil_type opcode is also supported, but only to confirm that a low pass filter is wanted (the filter will be disabled otherwise). The combined EG and LFO entries in the opcode list reflect that there is a shared EG for pitch/filter and a shared LFO for amplitude/pitch/filter, as is the case in SF2. Information on these (and other) SFZ opcodes can be found at www.sfzformat.com.
Samples can also be loaded from memory by setting the "sample" opcode to "mem:<address>:<length>", where address and length are both in hexadecimal. The memory should remain valid until the font is freed via BASS_MIDI_FontFree(Int32).
SFZ files don't have a defined preset or bank number, so they are nominally assigned to preset 0 in bank 0 when loaded, but can be assigned to other presets/banks via BASS_MIDI_StreamSetFonts(Int32, BASS_MIDI_FONT, Int32).
The BASS_MIDI_FONT_MMAP option is not available on big-endian systems (eg. PowerPC) as a soundfont's little-endian sample data cannot be played directly from a mapping; its byte order needs to be reversed.
|BASS_ERROR_FILEOPEN||The file could not be opened.|
|BASS_ERROR_FILEFORM||The file's format is not recognised/supported.|
' first initialize the fonts Dim font1 As Integer = BassMidi.BASS_MIDI_FontInit("afont.sf2") Dim font2 As Integer = BassMidi.BASS_MIDI_FontInit("bfont.sf2") Dim newfonts(2) As BASS_MIDI_FONT newfonts(0) = New BASS_MIDI_FONT(font1, 10, 0) newfonts(1) = New BASS_MIDI_FONT(font2, -1, 0) BassMidi.BASS_MIDI_StreamSetFonts(_stream, newfonts, 2)
// first initialize the fonts int font1 = BassMidi.BASS_MIDI_FontInit("afont.sf2"); int font2 = BassMidi.BASS_MIDI_FontInit("bfont.sf2"); BASS_MIDI_FONT newfonts = new BASS_MIDI_FONT; newfonts = new BASS_MIDI_FONT(font1, 10, 0); newfonts = new BASS_MIDI_FONT(font2, -1, 0); // now set them BassMidi.BASS_MIDI_StreamSetFonts(_stream, newfonts, 2);