libfluidsynth  2.3.5
Audio Driver

Functions for managing audio drivers. More...

Typedefs

typedef int(* fluid_audio_func_t) (void *data, int len, int nfx, float *fx[], int nout, float *out[])
 Callback function type used with new_fluid_audio_driver2() to allow for custom user audio processing before the audio is sent to the driver. More...
 

Lifecycle Functions for Audio Driver_linebr@{

fluid_audio_driver_tnew_fluid_audio_driver (fluid_settings_t *settings, fluid_synth_t *synth)
 Create a new audio driver. More...
 
fluid_audio_driver_tnew_fluid_audio_driver2 (fluid_settings_t *settings, fluid_audio_func_t func, void *data)
 Create a new audio driver. More...
 
void delete_fluid_audio_driver (fluid_audio_driver_t *driver)
 Deletes an audio driver instance. More...
 

Functions

int fluid_audio_driver_register (const char **adrivers)
 Registers audio drivers to use. More...
 

Detailed Description

Functions for managing audio drivers.

Defines functions for creating audio driver output. Use new_fluid_audio_driver() to create a new audio driver for a given synth and configuration settings.

The function new_fluid_audio_driver2() can be used if custom audio processing is desired before the audio is sent to the audio driver (although it is not as efficient).

See also
Creating the audio driver

Typedef Documentation

◆ fluid_audio_func_t

typedef int(* fluid_audio_func_t) (void *data, int len, int nfx, float *fx[], int nout, float *out[])

Callback function type used with new_fluid_audio_driver2() to allow for custom user audio processing before the audio is sent to the driver.

Parameters
dataThe user data parameter as passed to new_fluid_audio_driver2().
lenCount of audio frames to synthesize.
nfxCount of arrays in fx.
fxArray of buffers to store effects audio to. Buffers may alias with buffers of out.
noutCount of arrays in out.
outArray of buffers to store (dry) audio to. Buffers may alias with buffers of fx.
Returns
Should return FLUID_OK on success, FLUID_FAILED if an error occurred.

This function is responsible for rendering audio to the buffers. The buffers passed to this function are allocated and owned by the respective audio driver and are only valid during that specific call (do not cache them). The buffers have already been zeroed-out. For further details please refer to fluid_synth_process().

Note
Whereas fluid_synth_process() allows aliasing buffers, there is the guarantee that out and fx buffers provided by fluidsynth's audio drivers never alias. This prevents downstream applications from e.g. applying a custom effect accidentally to the same buffer multiple times.
Note
Also note that the Jack driver is currently the only driver that has dedicated fx buffers (but only if audio.jack.multi is true). All other drivers do not provide fx buffers. In this case, users are encouraged to mix the effects into the provided dry buffers when calling fluid_synth_process().
int myCallback(void *, int len, int nfx, float *fx[], int nout, float *out[])
{
int ret;
if(nfx == 0)
{
float *fxb[4] = {out[0], out[1], out[0], out[1]};
ret = fluid_synth_process(synth, len, sizeof(fxb) / sizeof(fxb[0]), fxb, nout, out);
}
else
{
ret = fluid_synth_process(synth, len, nfx, fx, nout, out);
}
// ... client-code ...
return ret;
}
int fluid_synth_process(fluid_synth_t *synth, int len, int nfx, float *fx[], int nout, float *out[])
Synthesize floating point audio to stereo audio channels (implements the default interface fluid_audi...
Definition: fluid_synth.c:4125
For other possible use-cases refer to fluidsynth_process.c .

Function Documentation

◆ delete_fluid_audio_driver()

void delete_fluid_audio_driver ( fluid_audio_driver_t driver)

Deletes an audio driver instance.

Parameters
driverAudio driver instance to delete

Shuts down an audio driver and deletes its instance.

Examples
example.c, fluidsynth_arpeggio.c, fluidsynth_fx.c, fluidsynth_metronome.c, fluidsynth_register_adriver.c, and fluidsynth_simple.c.

◆ fluid_audio_driver_register()

int fluid_audio_driver_register ( const char **  adrivers)

Registers audio drivers to use.

Parameters
adriversNULL-terminated array of audio drivers to register. Pass NULL to register all available drivers.
Returns
FLUID_OK if all the audio drivers requested by the user are supported by fluidsynth and have been successfully registered. Otherwise FLUID_FAILED is returned and this function has no effect.

When creating a settings instance with new_fluid_settings(), all audio drivers are initialized once. In the past this has caused segfaults and application crashes due to buggy soundcard drivers.

This function enables the user to only initialize specific audio drivers when settings instances are created. Therefore pass a NULL-terminated array of C-strings containing the names of audio drivers to register for the usage with fluidsynth. The names are the same as being used for the audio.driver setting.

By default all audio drivers fluidsynth has been compiled with are registered, so calling this function is optional.

Warning
This function may only be called if no thread is residing in fluidsynth's API and no instances of any kind are alive (e.g. as it would be the case right after fluidsynth's initial creation). Else the behaviour is undefined. Furthermore any attempt of using audio drivers that have not been registered is undefined behaviour!
Note
This function is not thread safe and will never be!
Since
1.1.9
Examples
fluidsynth_register_adriver.c.

◆ new_fluid_audio_driver()

fluid_audio_driver_t* new_fluid_audio_driver ( fluid_settings_t settings,
fluid_synth_t synth 
)

Create a new audio driver.

Parameters
settingsConfiguration settings used to select and create the audio driver.
synthSynthesizer instance for which the audio driver is created for.
Returns
The new audio driver instance or NULL on error

Creates a new audio driver for a given synth instance with a defined set of configuration settings. The settings instance must be the same that you have passed to new_fluid_synth() when creating the synth instance. Otherwise the behaviour is undefined.

Note
As soon as an audio driver is created, the synth starts rendering audio. This means that all necessary initialization and sound-setup should have been completed before calling this function. Thus, of all object types in use (synth, midi player, sequencer, etc.) the audio driver should always be the last one to be created and the first one to be deleted! Also refer to the order of object creation in the code examples.
Examples
example.c, fluidsynth_arpeggio.c, fluidsynth_metronome.c, fluidsynth_register_adriver.c, and fluidsynth_simple.c.

◆ new_fluid_audio_driver2()

fluid_audio_driver_t* new_fluid_audio_driver2 ( fluid_settings_t settings,
fluid_audio_func_t  func,
void *  data 
)

Create a new audio driver.

Parameters
settingsConfiguration settings used to select and create the audio driver.
funcFunction called to fill audio buffers for audio playback
dataUser defined data pointer to pass to func
Returns
The new audio driver instance or NULL on error

Like new_fluid_audio_driver() but allows for custom audio processing before audio is sent to audio driver. It is the responsibility of the callback func to render the audio into the buffers. If func uses a fluid_synth_t synth, the settings instance must be the same that you have passed to new_fluid_synth() when creating the synth instance. Otherwise the behaviour is undefined.

Note
Not as efficient as new_fluid_audio_driver().
As soon as an audio driver is created, a new thread is spawned starting to make callbacks to func. This means that all necessary sound-setup should be completed after this point, thus of all object types in use (synth, midi player, sequencer, etc.) the audio driver should always be the last one to be created and the first one to be deleted! Also refer to the order of object creation in the code examples.
Examples
fluidsynth_fx.c.