BASS MIDI

BASS_MIDI_FontInit


Initializes a soundfont.

HSOUNDFONT BASS_MIDI_FontInit(
    void *file,
    DWORD flags
);

Parameters

fileThe soundfont filename.
flagsAny combination of these flags.
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_NOFXIgnore the reverb/chorus levels of the presets in the soundfont (only use the levels in the MIDI events).
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_UNICODEfile is in UTF-16 form. Otherwise it is ANSI on Windows, and UTF-8 on other platforms.

Return value

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

Error codes

BASS_ERROR_FILEOPENThe file could not be opened.
BASS_ERROR_FILEFORMThe file's format is not recognised/supported.

Remarks

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 via the BASS_MIDI_StreamSetFonts function. A single soundfont can be shared by multiple MIDI streams. If a soundfont is initialized multiple times, each instance will have its own handle but share the same sample data. Information on the initialized soundfont can be retrieved using BASS_MIDI_FontGetInfo.

Soundfonts use PCM sample data as standard, but BASSMIDI can accept any format that is supported by BASS or its add-ons (the add-ons need to be loaded via BASS_PluginLoad). The BASS_MIDI_FontPack 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.

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.

SFZ files do not 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.

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.

Example

Initialize a soundfont.
HSOUNDFONT sfont=BASS_MIDI_FontInit("afile.sf2", 0);

See also

BASS_MIDI_FontFree, BASS_MIDI_FontGetInfo, BASS_MIDI_FontGetPresets, BASS_MIDI_FontInitUser, BASS_MIDI_FontPack, BASS_MIDI_FontLoad, BASS_MIDI_FontSetVolume, BASS_MIDI_StreamSetFonts, BASS_CONFIG_MIDI_COMPACT