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
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_NOHEAD Don'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_16BIT Reduce 24-bit sample data to 16-bit before encoding. BASS_MIDI_PACK_48KHZ Encode 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: BooleanIf successful, the is returned, else is returned. Use BASS_ErrorGetCode to get the error code.
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 CODE | Description |
---|---|
BASS_ERROR_HANDLE | handle is not valid. |
BASS_ERROR_NOTAVAIL | This function is not applicable to SFZ soundfonts. |
BASS_ERROR_FILEOPEN | Couldn't start the encoder. Check that the executable exists. |
BASS_ERROR_CREATE | Couldn't create the output file, outfile. |
BASS_ERROR_UNKNOWN | Some other mystery problem! |
// open original soundfont int handle = BassMidi.BASS_MIDI_FontInit( "afile.sf2"); // produce packed version BassMidi.BASS_MIDI_FontPack(handle, "afile.sf2pack", "flac --best -");
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);