BASS.NET API for the Un4seen BASS Audio Library

BassMidiBASS_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: 2.4.17.5
Syntax

public static int BASS_MIDI_FontInit(
	string file,
	BASSFlag flags
)

Parameters

file
Type: SystemString
The file name of the sound font (e.g. an .sf2 file).
flags
Type: Un4seen.BassBASSFlag
Any combination of these flags (see BASSFlag):
BASS_MIDI_FONT_LINATTMODUse a linear attack phase in SF2 modulation (pitch/filter) envelopes. Otherwise a convex curve is used. The attack phase is always linear in SFZ envelopes.
BASS_MIDI_FONT_LINDECVOLUse linear decay and release phases in volume envelopes. Otherwise a concave curve is used. The attack phase is always linear.
BASS_MIDI_FONT_MINFXTreat the reverb/chorus levels in the soundfont as minimums. The higher of them and the MIDI levels (CC91/93) will be used instead of the sum of both.
BASS_MIDI_FONT_MMAPMap the file into memory. This flag only applies to SF2 files, not SFZ files (or their samples). It is ignored if the file is too large to be mapped into memory, or if the soundfont is packed as the sample data cannot be played directly from a mapping (it needs to be decoded).
BASS_MIDI_FONT_NOFXIgnore the reverb/chorus levels in the soundfont and only use the MIDI levels (CC91/93).
BASS_MIDI_FONT_NOLIMITSDo not limit SF2 generator values to emulate Creative/SoundBlaster hardware.
BASS_MIDI_FONT_NORAMPINNever ramp-in the start of a sample in the soundfont. Otherwise a sample will be ramped-in if its data does not begin with a 0 (further away results in a longer ramp). This is only relevant when the volume envelope has no attack phase.
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.

Return Value

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

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

SF2 support

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.

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

Platform-specific

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.
BASS_ERROR_MEMThere is insufficient memory.
BASS_ERROR_MIDI_INCLUDEAn SFZ #include directive file could not be opened.

Examples

// 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

Reference