2017-11-26 09:07:08 +00:00
|
|
|
/*
|
2017-11-09 18:07:31 +00:00
|
|
|
* This is a simple C99 program that demonstrates the usage of fluid_audio_driver_register()
|
2018-06-24 11:01:31 +00:00
|
|
|
*
|
2017-11-09 18:07:31 +00:00
|
|
|
* There are 3 calls to fluid_audio_driver_register(), i.e. 3 iterations:
|
|
|
|
* First the alsa driver is registered and created, followed by the jack and portaudio driver.
|
2018-06-24 11:01:31 +00:00
|
|
|
*
|
2017-11-09 18:07:31 +00:00
|
|
|
* The usual usecase would be to call fluid_audio_driver_register() only once providing the audio drivers needed during fluidsynth usage.
|
|
|
|
* If necessary however fluid_audio_driver_register() can be called multiple times as demonstrated here.
|
|
|
|
* Therefore the user must make sure to delete all fluid-instances of any kind before making the call to fluid_audio_driver_register().
|
|
|
|
* Else the behaviour is undefined and the application is likely to crash.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fluidsynth.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2018-06-24 11:01:31 +00:00
|
|
|
const char *DRV[] = { "alsa", "jack", "portaudio" };
|
|
|
|
const char *adrivers[2];
|
|
|
|
|
|
|
|
for(int i = 0; i < sizeof(DRV) / sizeof(DRV[0]); i++)
|
2017-11-09 18:07:31 +00:00
|
|
|
{
|
|
|
|
adrivers[0] = DRV[i];
|
2017-11-11 14:13:12 +00:00
|
|
|
/* register any other driver you need
|
2018-06-24 11:01:31 +00:00
|
|
|
*
|
2017-11-11 14:13:12 +00:00
|
|
|
* adrivers[X] = "whatever";
|
|
|
|
*/
|
|
|
|
adrivers[1] = NULL; /* NULL terminate the array */
|
2017-11-09 18:07:31 +00:00
|
|
|
|
2017-11-22 12:51:18 +00:00
|
|
|
/* register those audio drivers. Note that at this time no fluidsynth objects are alive! */
|
2017-11-09 18:07:31 +00:00
|
|
|
int res = fluid_audio_driver_register(adrivers);
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2017-11-09 18:07:31 +00:00
|
|
|
if(res != FLUID_OK)
|
|
|
|
{
|
|
|
|
puts("adriver reg err");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-24 11:01:31 +00:00
|
|
|
fluid_settings_t *settings = new_fluid_settings();
|
2017-11-09 18:07:31 +00:00
|
|
|
res = fluid_settings_setstr(settings, "audio.driver", DRV[i]);
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-01-02 15:14:56 +00:00
|
|
|
/* settings API will be refactored to return FLUID_OK|FAILED next major release
|
|
|
|
* returning TRUE or FALSE is deprecated
|
|
|
|
*/
|
|
|
|
#if FLUIDSYNTH_VERSION_MAJOR >= 2
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2017-11-09 18:07:31 +00:00
|
|
|
if(res != FLUID_OK)
|
2018-01-02 15:14:56 +00:00
|
|
|
#else
|
|
|
|
if(res == 0)
|
|
|
|
#endif
|
2017-11-09 18:07:31 +00:00
|
|
|
{
|
|
|
|
puts("audio.driver set err");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-24 11:01:31 +00:00
|
|
|
fluid_synth_t *synth = new_fluid_synth(settings);
|
|
|
|
fluid_audio_driver_t *ad = new_fluid_audio_driver(settings, synth);
|
2017-11-09 18:07:31 +00:00
|
|
|
|
2017-11-11 14:13:12 +00:00
|
|
|
/*
|
|
|
|
* ~~~ Do your daily business here ~~~
|
|
|
|
*/
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2017-11-09 18:07:31 +00:00
|
|
|
delete_fluid_audio_driver(ad);
|
|
|
|
delete_fluid_synth(synth);
|
|
|
|
delete_fluid_settings(settings);
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2017-11-11 14:13:12 +00:00
|
|
|
/* everything cleaned up, fluid_audio_driver_register() can be called again if needed */
|
2017-11-09 18:07:31 +00:00
|
|
|
}
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2017-11-09 18:07:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|