Initializes a soundfont.
|file||The soundfont filename.
|flags||Any combination of these flags.|
|BASS_MIDI_FONT_LINATTMOD||Use 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_LINDECVOL||Use linear decay and release phases in volume envelopes. Otherwise a concave curve is used. The attack phase is always linear.
|BASS_MIDI_FONT_MINFX||Treat 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_MMAP||Map 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_NOFX||Ignore the reverb/chorus levels in the soundfont and only use the MIDI levels (CC91/93).
|BASS_MIDI_FONT_NOLIMITS||Do not limit SF2 generator values to emulate Creative/SoundBlaster hardware.
|BASS_MIDI_FONT_NORAMPIN||Never 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_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_UNICODE||file is in UTF-16 form. Otherwise it is ANSI on Windows, and UTF-8 on other platforms.
If successful, the soundfont's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.
|BASS_ERROR_FILEOPEN||The file could not be opened.
|BASS_ERROR_FILEFORM||The file's format is not recognised/supported.
|BASS_ERROR_MEM||There is insufficient memory.
|BASS_ERROR_MIDI_INCLUDE||An SFZ #include directive file could not be opened.
BASSMIDI uses SF2 and/or SFZ soundfonts to provide the sounds to use in the rendering of MIDI streams. 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. Information on the initialized soundfont can be retrieved from BASS_MIDI_FontGetInfo. 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 data. If the file's last-modified timestamp has changed since it was last loaded then it will be reloaded rather than shared.
Sample data will be loaded from soundfonts to memory as needed while rendering a MIDI stream, and can also be loaded in advance with BASS_MIDI_FontLoad or BASS_MIDI_FontLoadEx or BASS_MIDI_StreamLoadSamples.
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. SF3 files (another form of compressed SF2) can also be used with BASSMIDI, but not created with it. 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.
The SF2 synthesis model is fully supported, as are all SF2 generators. Support for the note velocity to attenuation (initialAttenuation), note velocity to filter cutoff (initialFilterFc), note velocity to modulation envelope filter cutoff (modEnvToFilterFc), note velocity to volume envelope attack/decay/release (attackVolEnv/decayVolEnv/releaseVolEnv), note velocity to start offset (startAddrsOffset), key number to attenuation, key number to filter cutoff, and key number to pan modulators is also included. MIDI CC21-24 to initialFilterFc/initialAttenuation/attackVolEnv/decayVolEnv/releaseVolEnv/releaseModEnv/modEnvToFilterFc modulators are also supported, but each CC can only have one destination per-preset. In each case, all curve types are supported and multiple modulators in the global/instrument/preset zones is supported but only if they are identical (eg. all negative unipolar linear). 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: amp_keycenter, amp_keytrack, ampeg_attack, ampeg_decay, ampeg_delay, ampeg_hold, ampeg_release, ampeg_sustain, ampeg_vel2attack, ampeg_vel2decay, ampeg_vel2release, amplfo_delay, amplfo_depth, amplfo_fade, amplfo_freq, amp_veltrack, cutoff, default_path, delay, delay_beats, effect1, effect2, end, fil_keycenter, fil_keytrack, 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_delay, fillfo_depth, fillfo_fade, fillfo_freq, fil_veltrack, group, hicc1, hicc64, hicc67, hikey, hirand, hivel, key, locc1, locc64, locc67, lokey, loop_end, loop_mode, loop_start, lorand, lovel, offset, off_by, off_mode, pan, pan_keycenter, pan_keytrack, pitcheg_depth, pitchlfo_delay, pitchlfo_depth, pitchlfo_fade, pitchlfo_freq, pitch_keycenter, pitch_keytrack, pitch_random, pitch_veltrack, resonance, rt_decay, sample, seq_length, seq_position, sw_default, sw_last, sw_lokey, sw_lolast, sw_hikey, sw_hilast, transpose, trigger, tune, volume, xf_keycurve, xf_velcurve, xfin_hikey, xfin_hivel, xfin_lokey, xfin_lovel, xfout_hikey, xfout_hivel, xfout_lokey, xfout_lovel. 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 fileg/pitcheg entries in the opcode list reflect that there is a shared envelope generator for pitch and filter, as is the case in SF2 soundfonts. Information on these (and other) SFZ opcodes can be found at www.sfzformat.com. The #define and #include directives are also supported.
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. When multiple SFZ files use the same sample, a single copy of the sample is loaded and shared by all of them. SFZ samples must be either mono or stereo, and not 8-bit.
An SFZ header can be set via the BASS_CONFIG_MIDI_SFZHEAD config option, which will be prepended to all SFZ files. This can be useful for defining macros for the SFZ files.
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.
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.
On Android, file may be a String, ByteBuffer, ParcelFileDescriptor, or asset (via the Asset class) when using Java. See the BASSMIDI.JAVA file for available overloads
Initialize a soundfont.
HSOUNDFONT sfont = BASS_MIDI_FontInit("blah.sf2", 0);
BASS_MIDI_FontFree, BASS_MIDI_FontGetInfo, BASS_MIDI_FontGetPresets, BASS_MIDI_FontInitUser, BASS_MIDI_FontPack, BASS_MIDI_FontLoad, BASS_MIDI_FontLoadEx, BASS_MIDI_FontSetVolume, BASS_MIDI_StreamSetFonts, BASS_CONFIG_MIDI_COMPACT, BASS_CONFIG_MIDI_SFZHEAD