Table 1. Synthesizer settings
synth.audio-channels |
Type |
integer |
|
Default |
1 |
|
Min-Max |
1-128 |
|
Description |
By default, the synthesizer outputs a single stereo signal.
Using this option, the synthesizer can output multichannel
audio. Sets the number of stereo channel pairs. So 1 is actually
2 channels (a stereo pair). |
synth.audio-groups |
Type |
integer |
|
Default |
1 |
|
Min-Max |
1-128 |
|
Description |
Normally the same value as synth.audio-channels. LADSPA
effects subsystem can use this value though, in which case it may
differ. |
synth.chorus.active |
Type |
boolean |
|
Default |
1 (TRUE) |
|
Description |
When set to 1 (TRUE) the chorus effects module is activated.
Otherwise, no chorus will be added to the output signal. Note
that the amount of signal sent to the chorus module depends on the
"chorus send" generator defined in the SoundFont. |
synth.cpu-cores |
Type |
integer |
|
Default |
1 |
|
Min-Max |
1-256 |
|
Description |
(Experimental) Sets the number of synthesis CPU cores. If set to a value
greater than 1, then additional synthesis threads will be created to take
advantage of a multi CPU or CPU core system. This has the affect of
utilizing more of the total CPU for voices or decreasing render times
when synthesizing audio to a file. |
synth.device-id |
Type |
integer |
|
Default |
0 |
|
Min-Max |
0-126 |
|
Description |
Device identifier used for SYSEX commands, such as MIDI
Tuning Standard commands. Only those SYSEX commands destined
for this ID or to all devices will be acted upon. |
synth.dump |
Type |
boolean |
|
Default |
0 (FALSE) |
|
Description |
Does nothing currently. |
synth.effects-channels |
Type |
integer |
|
Default |
2 |
|
Min-Max |
2-2 |
|
Description |
|
synth.gain |
Type |
number |
|
Default |
0.2 |
|
Min-Max |
0.0-10.0 |
|
Description |
The gain is applied to the final or master output of the
synthesizer. It is set to a low value by default to avoid the
saturation of the output when many notes are played. |
synth.ladspa.active |
Type |
boolean |
|
Default |
0 (FALSE) |
|
Description |
When set to "yes" the LADSPA subsystem will be enabled. This
subsystem allows to load and interconnect LADSPA plug-ins. The
output of the synthesizer is processed by the LADSPA subsystem.
Note that the synthesizer has to be compiled with LADSPA
support. More information about the LADSPA subsystem
later. |
synth.midi-channels |
Type |
integer |
|
Default |
16 |
|
Min-Max |
16-256 |
|
Description |
This setting defines the number of MIDI channels of the
synthesizer. The MIDI standard defines 16 channels, so MIDI
hardware is limited to this number. Internally FluidSynth can use
more channels which can be mapped to different MIDI sources. |
synth.midi-bank-select |
Type |
string |
|
Default |
gs |
|
Options |
gm, gs, xg, mma |
|
Description |
This setting defines how the synthesizer interprets Bank Select messages.
- gm: ignores CC0 and CC32 messages.
- gs: (default) CC0 becomes the bank number, CC32 is ignored.
- xg: CC32 becomes the bank number, CC0 is ignored.
- mma: bank is calculated as CC0*128+CC32.
|
synth.min-note-length |
Type |
integer |
|
Default |
10 |
|
Min-Max |
0-65535 |
|
Description |
Sets the minimum note duration in milliseconds. This
ensures that really short duration note events, such as
percussion notes, have a better chance of sounding as
intended. Set to 0 to disable this feature. |
synth.parallel-render |
Type |
boolean |
|
Default |
1 (TRUE) |
|
Description |
synth.parallel-render is the low-latency setting. If on, you're allowed
to call fluid_synth_write_s16, fluid_synth_write_float,
fluid_synth_nwrite_float or fluid_synth_process in parallel with the
rest of the calls, and it won't be blocked by time intensive calls to
the synth. Turn it off if throughput is more important than latency, e g
in rendering-to-file scenarios where underruns is not an issue.
Deprecated: As of 1.1.7 this option is deprecated. This option enforces thread safety for rvoice_mixer, which causes rvoice_events to be queued internally. The current implementation relies on the fact that this option is set to TRUE to correctly render any amount of requested audio. Also calling fluid_synth_write_* in parallel is not considered to be a use-case. It would cause undefined audio output, as it would be unpredictable for the user which rvoice_events specifically would be dispatched to which fluid_synth_write_* call.
|
synth.polyphony |
Type |
integer |
|
Default |
256 |
|
Min-Max |
1-65535 |
|
Description |
The polyphony defines how many voices can be played in
parallel. A note event produces one or more voices.
Its good to set this to a value which the system can handle
and will thus limit FluidSynth's CPU usage. When FluidSynth
runs out of voices it will begin terminating lower priority
voices for new note events. |
synth.reverb.active |
Type |
boolean |
|
Default |
1 (TRUE) |
|
Description |
When set to 1 (TRUE) the reverb effects module is activated.
Otherwise, no reverb will be added to the output signal. Note
that the amount of signal sent to the reverb module depends on the
"reverb send" generator defined in the SoundFont. |
synth.sample-rate |
Type |
number |
|
Default |
44100 |
|
Min-Max |
22050-96000 |
|
Description |
The sample rate of the audio generated by the
synthesizer. |
synth.threadsafe-api |
Type |
boolean |
|
Default |
1 (TRUE) |
|
Description |
synth.threadsafe-api controls whether the synth's public API is
protected by a mutex or not. Default is on, turn it off for slightly
better performance if you know you're only accessing the synth from one
thread only, this could be the case in many embedded use cases for
example. Note that libfluidsynth can use many threads by itself (shell
is one, midi driver is one, midi player is one etc) so you should usually
leave it on. Also see synth.parallel-render. |
synth.verbose |
Type |
boolean |
|
Default |
0 (FALSE) |
|
Description |
When set to 1 (TRUE) the synthesizer will print out
information about the received MIDI events to the stdout. This
can be helpful for debugging. This setting cannot be changed
after the synthesizer has started. |
\section CreatingAudioDriver Creating the Audio Driver
The synthesizer itself does not write any audio to the audio output. This allows application developers to manage the audio output themselves if they wish. The next section describes the use of the synthesizer without an audio driver in more detail.
Creating the audio driver is straightforward: set the appropriate settings and create the driver object. Because the FluidSynth has support for several audio systems, you may want to change which one you want to use. The list below shows the audio systems that are currently supported. It displays the name, as used by the fluidsynth library, and a description.
- jack: JACK Audio Connection Kit (Linux, Mac OS X, Windows)
- alsa: Advanced Linux Sound Architecture (Linux)
- oss: Open Sound System (Linux, Unix)
- pulseaudio: PulseAudio (Linux, Mac OS X, Windows)
- coreaudio: Apple CoreAudio (Mac OS X)
- dsound: Microsoft DirectSound (Windows)
- portaudio: PortAudio Library (Mac OS 9 & X, Windows, Linux)
- sndman: Apple SoundManager (Mac OS Classic)
- dart: DART sound driver (OS/2)
- file: Driver to output audio to a file
The default audio driver depends on the settings with which FluidSynth was compiled. You can get the default driver with fluid_settings_getstr_default(). To get the list of available drivers use the fluid_settings_foreach_option() function. Finally, you can set the driver with fluid_settings_setstr(). In most cases, the default driver should work out of the box.
Additional options that define the audio quality and latency are "audio.sample-format", "audio.period-size", and "audio.periods". The details are described later.
You create the audio driver with the new_fluid_audio_driver() function. This function takes the settings and synthesizer object as arguments. For example:
\code
void init()
{
fluid_settings_t* settings;
fluid_synth_t* synth;
fluid_audio_driver_t* adriver;
settings = new_fluid_settings();
/* Set the synthesizer settings, if necessary */
synth = new_fluid_synth(settings);
fluid_settings_setstr(settings, "audio.driver", "jack");
adriver = new_fluid_audio_driver(settings, synth);
}
\endcode
As soon as the audio driver is created, it will start playing. The audio driver creates a separate thread that uses the synthesizer object to generate the audio.
There are a number of general audio driver settings. The audio.driver settings define the audio subsystem that will be used. The audio.periods and audio.period-size settings define the latency and robustness against scheduling delays. There are additional settings for the audio subsystems used which are documented in another table.
Table 2. General audio driver settings
audio.driver |
Type |
string |
|
Default |
jack (Linux), dsound (Windows), sndman (MacOS9), coreaudio
(Mac OS X), dart (OS/2) |
|
Options |
jack, alsa, oss, pulseaudio, coreaudio, dsound, portaudio, sndman, dart, file |
|
Description |
The audio system to be used. |
audio.periods |
Type |
int |
|
Default |
16 (Linux, Mac OS X), 8 (Windows) |
|
Min-Max |
2-64 |
|
Description |
The number of the audio buffers used by the driver. This
number of buffers, multiplied by the buffer size (see setting
audio.period-size), determines the maximum latency of the audio
driver. |
audio.period-size |
Type |
integer |
|
Default |
64 (Linux, Mac OS X), 512 (Windows) |
|
Min-Max |
64-8192 |
|
Description |
The size of the audio buffers (in frames). |
audio.realtime-prio |
Type |
integer |
|
Default |
60 |
|
Min-Max |
0-99 |
|
Description |
Sets the realtime scheduling priority of the audio synthesis thread
(0 disables high priority scheduling). Linux is the only platform which
currently makes use of different priority levels. Drivers which use this
option: alsa, oss and pulseaudio |
audio.sample-format |
Type |
string |
|
Default |
"16bits" |
|
Options |
"16bits", "float" |
|
Description |
The format of the audio samples. This is currently only an
indication; the audio driver may ignore this setting if it
can't handle the specified format. |
The following table describes audio driver specific settings.
Table 3. Audio driver specific settings
audio.alsa.device |
Type |
string |
|
Default |
"default" |
|
Options |
ALSA device string, such as: "hw:0", "plughw:1", etc. |
|
Description |
Selects the ALSA audio device to use. |
audio.coreaudio.device |
Type |
string |
|
Default |
"default" |
|
Description |
Selects the CoreAudio device to use. |
audio.dart.device |
Type |
string |
|
Default |
"default" |
|
Description |
Selects the Dart (OS/2 driver) device to use. |
audio.dsound.device |
Type |
string |
|
Default |
"default" |
|
Description |
Selects the DirectSound (Windows) device to use. |
audio.file.endian |
Type |
string |
|
Default |
'auto' if libsndfile support is built in, 'cpu' otherwise. |
|
Options |
auto, big, cpu, little ('cpu' is all that is supported if libsndfile
support is not built in) |
|
Description |
Defines the byte order when using the 'file' driver or file renderer to
store audio to a file. 'auto' uses the default for the given file type,
'cpu' uses the CPU byte order, 'big' uses big endian byte order and 'little' uses
little endian byte order. |
audio.file.format |
Type |
string |
|
Default |
s16 |
|
Options |
double, float, s16, s24, s32, s8, u8 ('s16' is all that is supported if
libsndfile support not built in) |
|
Description |
Defines the audio format when rendering audio to a file. 'double' is
64 bit floating point, 'float' is 32 bit floating point, 's16' is 16 bit signed
PCM, 's24' is 24 bit signed PCM, 's32' is 32 bit signed PCM, 's8' is 8 bit
signed PCM and 'u8' is 8 bit unsigned PCM. |
audio.file.name |
Type |
string |
|
Default |
'fluidsynth.wav' if libsndfile support is built in, 'fluidsynth.raw'
otherwise. |
|
Description |
Specifies the file name to store the audio to, when rendering audio to
a file. |
audio.file.type |
Type |
string |
|
Default |
'auto' if libsndfile support is built in, 'raw' otherwise. |
|
Options |
aiff, au, auto, avr, caf, flac, htk, iff, mat, oga, paf, pvf, raw, sd2, sds,
sf, voc, w64, wav, xi (actual list of types may vary and depends on the
libsndfile library used, 'raw' is the only type available if no libsndfile
support is built in). |
|
Description |
Sets the file type of the file which the audio will be stored to.
'auto' attempts to determine the file type from the audio.file.name file
extension and falls back to 'wav' if the extension doesn't match any types. |
audio.jack.autoconnect |
Type |
boolean |
|
Default |
0 (FALSE) |
|
Description |
If 1 (TRUE), then FluidSynth output is automatically connected to jack
system audio output. |
audio.jack.id |
Type |
string |
|
Default |
fluidsynth |
|
Description |
ID used when creating Jack client connection. |
audio.jack.multi |
Type |
boolean |
|
Default |
0 (FALSE) |
|
Description |
If 1 (TRUE), then multi-channel Jack output will be enabled if
synth.audio-channels is greater than 1. |
audio.jack.server |
Type |
string |
|
Default |
|
|
Description |
Jack server to connect to. Defaults to an empty string, which uses
default Jack server. |
audio.oss.device |
Type |
string |
|
Default |
/dev/dsp |
|
Description |
Device to use for OSS audio output. |
audio.portaudio.device |
Type |
string |
|
Default |
PortAudio Default |
|
Description |
Device to use for PortAudio driver output. Note that 'PortAudio Default'
is a special value which outputs to the default PortAudio device. |
audio.pulseaudio.device |
Type |
string |
|
Default |
"default" |
|
Description |
Device to use for PulseAudio driver output |
audio.pulseaudio.server |
Type |
string |
|
Default |
"default" |
|
Description |
Server to use for PulseAudio driver output |
\section UsingSynth Using the synthesizer without an audio driver
It is possible to use the synthesizer object without creating an audio driver. This is desirable if the application using FluidSynth manages the audio output itself. The synthesizer has several API functions that can be used to obtain the audio output:
fluid_synth_write_s16() fills two buffers (left and right channel) with samples coded as signed 16 bits (the endian-ness is machine dependent). fluid_synth_write_float() fills a left and right audio buffer with 32 bits floating point samples. For multi channel audio output, the function fluid_synth_nwrite_float() has to be used.
The function fluid_synth_process() is still experimental and its use is therefore not recommended but it will probably become the generic interface in future versions.
\section LoadingSoundfonts Loading and managing SoundFonts
Before any sound can be produced, the synthesizer needs a SoundFont.
SoundFonts are loaded with the fluid_synth_sfload() function. The function takes the path to a SoundFont file and a boolean to indicate whether the presets of the MIDI channels should be updated after the SoundFont is loaded. When the boolean value is TRUE, all MIDI channel bank and program numbers will be refreshed, which may cause new instruments to be selected from the newly loaded SoundFont.
The synthesizer can load any number of SoundFonts. The loaded SoundFonts are treated as a stack, where each new loaded SoundFont is placed at the top of the stack. When selecting presets by bank and program numbers, SoundFonts are searched beginning at the top of the stack. In the case where there are presets in different SoundFonts with identical bank and program numbers, the preset from the most recently loaded SoundFont is used. The fluid_synth_program_select() can be used for unambiguously selecting a preset or bank offsets could be applied to each SoundFont with fluid_synth_set_bank_offset(), to try and ensure that each preset has unique bank and program numbers.
The fluid_synth_sfload() function returns the unique identifier of the loaded SoundFont, or -1 in case of an error. This identifier is used in subsequent management functions: fluid_synth_sfunload() removes the SoundFont, fluid_synth_sfreload() reloads the SoundFont. When a SoundFont is reloaded, it retains it's ID and position on the SoundFont stack.
Additional API functions are provided to get the number of loaded SoundFonts and to get a pointer to the SoundFont.
\section SendingMIDI Sending MIDI Events
Once the synthesizer is up and running and a SoundFont is loaded, most people will want to do something useful with it. Make noise, for example. MIDI messages can be sent using the fluid_synth_noteon(), fluid_synth_noteoff(), fluid_synth_cc(), fluid_synth_pitch_bend(), fluid_synth_pitch_wheel_sens(), and fluid_synth_program_change() functions. For convenience, there's also a fluid_synth_bank_select() function (the bank select message is normally sent using a control change message).
The following example show a generic graphical button that plays a note when clicked:
\code
class SoundButton : public SomeButton
{
public:
SoundButton() : SomeButton() {
if (!_synth) {
initSynth();
}
}
static void initSynth() {
_settings = new_fluid_settings();
_synth = new_fluid_synth(_settings);
_adriver = new_fluid_audio_driver(_settings, _synth);
}
/* ... */
virtual int handleMouseDown(int x, int y) {
/* Play a note on key 60 with velocity 100 on MIDI channel 0 */
fluid_synth_noteon(_synth, 0, 60, 100);
}
virtual int handleMouseUp(int x, int y) {
/* Release the note on key 60 */
fluid_synth_noteoff(_synth, 0, 60);
}
protected:
static fluid_settings_t* _settings;
static fluid_synth_t* _synth;
static fluid_audio_driver_t* _adriver;
};
\endcode
\section RealtimeMIDI Creating a Real-time MIDI Driver
FluidSynth can process real-time MIDI events received from hardware MIDI ports or other applications. To do so, the client must create a MIDI input driver. It is a very similar process to the creation of the audio driver: you initialize some properties in a settings instance and call the new_fluid_midi_driver() function providing a callback function that will be invoked when a MIDI event is received. The following MIDI drivers are currently supported:
- jack: JACK Audio Connection Kit MIDI driver (Linux, Mac OS X)
- oss: Open Sound System raw MIDI (Linux, Unix)
- alsa_raw: ALSA raw MIDI interface (Linux)
- alsa_seq: ALSA sequencer MIDI interface (Linux)
- winmidi: Microsoft Windows MM System (Windows)
- midishare: MIDI Share (Linux, Mac OS X)
- coremidi: Apple CoreMIDI (Mac OS X)
\code
#include