Skip to content
Tom M edited this page Jul 1, 2017 · 11 revisions

Low latency tips

There are several [FluidSynth] options which affect audio latency. Many of these depend on what audio driver is being used. Additionally the operating system being used, how it is setup and what audio card you have will limit the lowest artifact free latency that can be achieved.

Specifying the audio driver

To specify the audio driver which [FluidSynth] will use, supply the -a DRIVER option, for example:

fluidsynth -a alsa

Audio buffer size and count

These options are used for the majority of audio drivers that [FluidSynth] supports. An exception is that the Jack driver does not use the audio buffer size or count options.

Command line switches and equivalent [FluidSynth] settings (in parenthesis):

  • -r=RATE (synth.sample-rate): Sample rate
  • -c=NUM (audio.periods): Set the number of audio buffers
  • -z=SIZE (audio.period-size): Set audio buffer size

The sample rate sets the native sample rate that [FluidSynth] synthesizes to. Typical values include 44100 and 48000.

Note: Currently the actual sample rate being used by the audio driver may differ, in which case the synth will be out of tune. Will be fixed in a future version of [FluidSynth]. Ensure that the internal [FluidSynth] sample rate matches that of your driver for proper operation.

The audio buffer count and size sets the values of these parameters used by the audio driver. Total latency in samples is NUM * SIZE. To calculate latency in seconds use NUM * SIZE / RATE. For example: 2 * 256 / 48000 = ~10ms latency. Suggested values for NUM is 2 or 3. Suggested values for SIZE include: 64, 128, 256, 512, 1024. Non power of 2 values can also be used and sound cards have different limits on this value.

ALSA specific tips

ALSA is a pretty flexible audio system and is the de-facto standard on Linux systems.

Specifying what ALSA device to use to playback to, can have a huge affect on achievable low latency. The hardware device layer is the best, followed by the plug hardware layer. Using dmix is not recommended for live playback, since it typically has rather high latency response. (Unfortunately specifying the hardware layer may bypass all of the desktop volume controls.)

To use the hardware layer, specify the ALSA audio device in the form "hw:N" where N is the card number. For example:

fluidsynth -a alsa -o audio.alsa.device=hw:0

If [FluidSynth] fails to initialize your sound card, you may need to specify a different sample rate (some sound cards only operate at fixed rates). Use the -o synth.sample-rate=RATE or -r=RATE command line options. Playing with the audio buffer size and count may also be required. If your sound card does not support 16 bit audio (for example it is fixed to 24 bit), then you will need to use the plughw layer as [FluidSynth] currently does not support 24 bit directly.

To use the plug hardware layer, specify the ALSA audio device in the form "plughw:N" where N is the card number. For example:

fluidsynth -a alsa -o audio.alsa.device=plughw:0

The advantage to the plug hardware layer is that it will do sample conversion as necessary, though this will require additional CPU, so the hw layer is preferred if possible.

Linux kernel

The version of the Linux kernel being used and its configured build time configuration options can have a pretty dramatic effect on achievable artifact free low latency. This can be an art in and of itself. Some people use RT kernels which may or may not have a lowlatency patch applied and usually have full preemption enabled.

FIXME: Add more info and/or links to Linux kernel tuning.