BASS.NET API for the Un4seen BASS Audio Library

BassMidiBASS_MIDI_FontPack Method

BASS.NET API for the Un4seen BASS Audio Library
Produces a compressed version of a soundfont.

Unicode version only here (BASS_UNICODE will be used automatically).

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

public static bool BASS_MIDI_FontPack(
	int handle,
	string outfile,
	string encoder,
	BASSFlag flags
)

Parameters

handle
Type: SystemInt32
The soundfont to pack.
outfile
Type: SystemString
Filename for the packed soundfont.
encoder
Type: SystemString
Encoder command-line (e.g. as returned by EncoderCommandLine).
flags
Type: Un4seen.BassBASSFlag
Any combination of these flags (see BASSFlag):
BASS_MIDI_PACK_NOHEADDon't send a WAVE header to the encoder. If this flag is used then the sample format (mono 16-bit) must be passed to the encoder some other way, eg. via the command-line.
BASS_MIDI_PACK_16BITReduce 24-bit sample data to 16-bit before encoding.
BASS_MIDI_PACK_48KHZEncode the sample data at 48000 Hz, else 44100 Hz. This is applied automatically if 'opus' is present in the encoder command-line. The encoding rate only really makes a difference with lossy codecs.

Return Value

Type: Boolean
If successful, the is returned, else is returned. Use BASS_ErrorGetCode to get the error code.
Remarks

Standard soundfonts use PCM samples, so they can be quite large, which can be a problem if they're to be distributed. To reduce the size, BASSMIDI can compress the samples using any command-line encoder with STDIN and STDOUT support. Packed soundfonts can be used for rendering by BASSMIDI just like normal soundfonts. They can also be unpacked using BASS_MIDI_FontUnpack(Int32, String, BASSFlag).

Although any command-line encoder can be used, it is best to use a lossless format like FLAC or WavPack, rather than a lossy one like OGG or MP3. Using a lossless encoder, the packed soundfont will produce exactly the same results as the original soundfont, and will be identical to the original when unpacked. As a compromise between quality and size, the WavPack hybrid/lossy mode also produces good sounding results.

The encoder must be told (via the command-line) to expect input from STDIN and to send it's output to STDOUT.

Before using a packed soundfont, the appropriate BASS add-on needs to be loaded via BASS_PluginLoad(String). For example, if the samples are FLAC encoded, BASSFLAC would need to be loaded. During rendering, the samples are unpacked as they're needed, which could result in CPU spikes. Where smooth performance is critical, it may be wise to preload the samples using BASS_MIDI_FontLoad(Int32, Int32, Int32) or BASS_MIDI_StreamLoadSamples(Int32).

A soundfont should not be packed while it is being used to render any MIDI streams, as that could delay the rendering. This function only applies to SF2 soundfonts. SFZ samples can be compressed using standard encoding tools.

Platform-specific

This function is not available on iOS or Android.

ERROR CODEDescription
BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_NOTAVAILThis function is not applicable to SFZ soundfonts.
BASS_ERROR_FILEOPENCouldn't start the encoder. Check that the executable exists.
BASS_ERROR_CREATECouldn't create the output file, outfile.
BASS_ERROR_UNKNOWNSome other mystery problem!

Examples

Create a FLAC encoded version of a soundfont:
// open original soundfont
int handle = BassMidi.BASS_MIDI_FontInit( "afile.sf2");
// produce packed version
BassMidi.BASS_MIDI_FontPack(handle, "afile.sf2pack", "flac --best -");
Using the build-in encoder framework:
EncoderFLAC flac = new EncoderFLAC(0);
flac.InputFile = null;    // use STDIN 
flac.OutputFile = null; // use STDOUT
// produce packed version
BassMidi.BASS_MIDI_FontPack(handle, "afile.sf2pack", flac.EncoderCommandLine);
See Also

Reference