Produces a compressed version of a soundfont.
BOOL BASS_MIDI_FontPack( HSOUNDFONT handle, void *outfile, void *encoder, DWORD flags );
handle | The soundfont to pack. | ||||||||
outfile | Filename for the packed soundfont. | ||||||||
encoder | Encoder command-line. | ||||||||
flags | Any combination of these flags.
|
BASS_ERROR_HANDLE | handle is not valid. |
BASS_ERROR_NOTAVAIL | This function is not applicable to SFZ soundfonts. |
BASS_ERROR_FILEOPEN | Could not start the encoder. Check that the executable exists. |
BASS_ERROR_CREATE | Could not create the output file, outfile. |
BASS_ERROR_UNKNOWN | Some other mystery problem! |
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 its output to STDOUT.
Before using a packed soundfont, the appropriate BASS add-on needs to be loaded via BASS_PluginLoad. For example, if the samples are FLAC encoded, BASSFLAC would need to be loaded. During rendering, the samples are unpacked as they are needed, which could result in CPU spikes. Where smooth performance is critical, it may be wise to preload the samples using BASS_MIDI_FontLoad or BASS_MIDI_StreamLoadSamples.
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.
HSOUNDFONT handle = BASS_MIDI_FontInit("afile.sf2", 0); // open original soundfont BASS_MIDI_FontPack(handle, "afile.sf2pack", "flac --best -", 0); // produce packed version