BASS.NET API for the Un4seen BASS Audio LibraryBassMidiBASS_MIDI_FontInit Method (String, BASSFlag)BASS.NET API for the Un4seen BASS Audio Library
Initializes a soundfont from a file (unicode).

Namespace: Un4seen.Bass.AddOn.Midi
Assembly: Bass.Net (in Bass.Net.dll) Version:

public static int BASS_MIDI_FontInit(
	string file,
	BASSFlag flags


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_MMAPMap 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_XGDRUMSUse 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_NOFXIgnore 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 Value

Type: Int32
If successful, the soundfont's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.

The BASS_UNICODE flag is applied automatically here.

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).

SFZ support

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, 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, hikey, hivel, key, lokey, loop_end, loop_mode, loop_start, lovel, offset, off_by, 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


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.

ERROR CODEDescription
BASS_ERROR_FILEOPENThe file could not be opened.
BASS_ERROR_FILEFORMThe 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[2];
newfonts[0] = new BASS_MIDI_FONT(font1, 10, 0);
newfonts[1] = new BASS_MIDI_FONT(font2, -1, 0);
// now set them
BassMidi.BASS_MIDI_StreamSetFonts(_stream, newfonts, 2);
See Also