libfluidsynth  1.1.11
fluidsynth_register_adriver.c

Example of how to register audio drivers using fluid_audio_driver_register() (advanced users only)

#include <stdio.h>
#include <fluidsynth.h>
int main()
{
const char* DRV[] = { "alsa", "jack", "portaudio" };
const char* adrivers[2];
for(int i=0; i<sizeof(DRV)/sizeof(DRV[0]); i++)
{
adrivers[0] = DRV[i];
/* register any other driver you need
*
* adrivers[X] = "whatever";
*/
adrivers[1] = NULL; /* NULL terminate the array */
/* register those audio drivers. Note that at this time no fluidsynth objects are alive! */
int res = fluid_audio_driver_register(adrivers);
if(res != FLUID_OK)
{
puts("adriver reg err");
return -1;
}
res = fluid_settings_setstr(settings, "audio.driver", DRV[i]);
/* settings API will be refactored to return FLUID_OK|FAILED next major release
* returning TRUE or FALSE is deprecated
*/
#if FLUIDSYNTH_VERSION_MAJOR >= 2
if(res != FLUID_OK)
#else
if(res == 0)
#endif
{
puts("audio.driver set err");
return -1;
}
fluid_synth_t* synth = new_fluid_synth(settings);
/*
* ~~~ Do your daily business here ~~~
*/
/* everything cleaned up, fluid_audio_driver_register() can be called again if needed */
}
return 0;
}