complete implementation of fluid_audio_driver_register()

This commit is contained in:
derselbst 2017-11-01 16:20:16 +01:00
parent 9b6d3d4c55
commit 78ab309bb6

View file

@ -118,81 +118,150 @@ fluid_audio_driver_t* new_fluid_file_audio_driver(fluid_settings_t* settings,
int delete_fluid_file_audio_driver(fluid_audio_driver_t* p);
#endif
/* Available audio drivers, listed in order of preference */
static const fluid_audriver_definition_t fluid_audio_drivers_template[] = {
#if JACK_SUPPORT
{ "jack",
new_fluid_jack_audio_driver,
new_fluid_jack_audio_driver2,
delete_fluid_jack_audio_driver,
fluid_jack_audio_driver_settings },
#define JACK_DEF_INIT \
{ "jack", \
new_fluid_jack_audio_driver, \
new_fluid_jack_audio_driver2, \
delete_fluid_jack_audio_driver, \
fluid_jack_audio_driver_settings },
#else
#define JACK_DEF_INIT
#endif
#if ALSA_SUPPORT
{ "alsa",
new_fluid_alsa_audio_driver,
new_fluid_alsa_audio_driver2,
delete_fluid_alsa_audio_driver,
fluid_alsa_audio_driver_settings },
#define ALSA_DEF_INIT \
{ "alsa", \
new_fluid_alsa_audio_driver, \
new_fluid_alsa_audio_driver2, \
delete_fluid_alsa_audio_driver, \
fluid_alsa_audio_driver_settings },
#else
#define ALSA_DEF_INIT
#endif
#if OSS_SUPPORT
{ "oss",
new_fluid_oss_audio_driver,
new_fluid_oss_audio_driver2,
delete_fluid_oss_audio_driver,
fluid_oss_audio_driver_settings },
#define OSS_DEF_INIT \
{ "oss", \
new_fluid_oss_audio_driver, \
new_fluid_oss_audio_driver2, \
delete_fluid_oss_audio_driver, \
fluid_oss_audio_driver_settings },
#else
#define OSS_DEF_INIT
#endif
#if PULSE_SUPPORT
{ "pulseaudio",
new_fluid_pulse_audio_driver,
new_fluid_pulse_audio_driver2,
delete_fluid_pulse_audio_driver,
fluid_pulse_audio_driver_settings },
#define PULSE_DEF_INIT \
{ "pulseaudio", \
new_fluid_pulse_audio_driver, \
new_fluid_pulse_audio_driver2, \
delete_fluid_pulse_audio_driver, \
fluid_pulse_audio_driver_settings },
#else
#define PULSE_DEF_INIT
#endif
#if COREAUDIO_SUPPORT
{ "coreaudio",
new_fluid_core_audio_driver,
new_fluid_core_audio_driver2,
delete_fluid_core_audio_driver,
fluid_core_audio_driver_settings },
#define COREAUDIO_DEF_INIT \
{ "coreaudio", \
new_fluid_core_audio_driver, \
new_fluid_core_audio_driver2, \
delete_fluid_core_audio_driver, \
fluid_core_audio_driver_settings },
#else
#define COREAUDIO_DEF_INIT
#endif
#if DSOUND_SUPPORT
{ "dsound",
new_fluid_dsound_audio_driver,
NULL,
delete_fluid_dsound_audio_driver,
fluid_dsound_audio_driver_settings },
#define DSOUND_DEF_INIT \
{ "dsound", \
new_fluid_dsound_audio_driver, \
NULL, \
delete_fluid_dsound_audio_driver, \
fluid_dsound_audio_driver_settings },
#else
#define DSOUND_DEF_INIT
#endif
#if PORTAUDIO_SUPPORT
{ "portaudio",
new_fluid_portaudio_driver,
NULL,
delete_fluid_portaudio_driver,
fluid_portaudio_driver_settings },
#define PORTAUDIO_DEF_INIT \
{ "portaudio", \
new_fluid_portaudio_driver, \
NULL, \
delete_fluid_portaudio_driver, \
fluid_portaudio_driver_settings },
#else
#define PORTAUDIO_DEF_INIT
#endif
#if SNDMAN_SUPPORT
{ "sndman",
new_fluid_sndmgr_audio_driver,
new_fluid_sndmgr_audio_driver2,
delete_fluid_sndmgr_audio_driver,
NULL },
#define SNDMAN_DEF_INIT \
{ "sndman", \
new_fluid_sndmgr_audio_driver, \
new_fluid_sndmgr_audio_driver2, \
delete_fluid_sndmgr_audio_driver, \
NULL },
#else
#define SNDMAN_DEF_INIT
#endif
#if DART_SUPPORT
{ "dart",
new_fluid_dart_audio_driver,
NULL,
delete_fluid_dart_audio_driver,
fluid_dart_audio_driver_settings },
#define DART_DEF_INIT \
{ "dart", \
new_fluid_dart_audio_driver, \
NULL, \
delete_fluid_dart_audio_driver, \
fluid_dart_audio_driver_settings },
#else
#define DART_DEF_INIT
#endif
#if AUFILE_SUPPORT
{ "file",
new_fluid_file_audio_driver,
NULL,
delete_fluid_file_audio_driver,
NULL },
#define AUFILE_DEF_INIT \
{ "file", \
new_fluid_file_audio_driver, \
NULL, \
delete_fluid_file_audio_driver, \
NULL },
#else
#define AUFILE_DEF_INIT
#endif
#define AVAILABLE_AUDRIVERS \
JACK_DEF_INIT \
ALSA_DEF_INIT \
OSS_DEF_INIT \
PULSE_DEF_INIT \
COREAUDIO_DEF_INIT \
DSOUND_DEF_INIT \
PORTAUDIO_DEF_INIT \
SNDMAN_DEF_INIT \
DART_DEF_INIT \
AUFILE_DEF_INIT
/* fluid_audio_drivers_template is a compile-constant template containing all audio drivers
* fluidsynth has been built with
*
* fluid_audio_drivers contains all the drivers registered for usage with
* fluid_audio_driver_register()
*
* To maintain backwards compatibility, all available drivers are initially registered, so
* this must be the same as fluid_audio_drivers_template. But arrays are unassignable in C
* and copying them at runtime with memcpy in fluid_audio_driver_settings() wouldnt be
* threadsafe. So use this ugly macro hack to initialize both equally at compiletime.
*/
static const fluid_audriver_definition_t fluid_audio_drivers_template[] =
{
AVAILABLE_AUDRIVERS
};
static fluid_audriver_definition_t fluid_audio_drivers[FLUID_N_ELEMENTS(fluid_audio_drivers_template)];
static fluid_audriver_definition_t fluid_audio_drivers[] =
{
AVAILABLE_AUDRIVERS
};
void fluid_audio_driver_settings(fluid_settings_t* settings)
@ -274,7 +343,7 @@ void fluid_audio_driver_settings(fluid_settings_t* settings)
fluid_settings_add_option(settings, "audio.driver", "file");
#endif
for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers); i++) {
for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers) && fluid_audio_drivers[i].name != NULL; i++) {
if (fluid_audio_drivers[i].settings != NULL) {
fluid_audio_drivers[i].settings(settings);
}
@ -299,7 +368,7 @@ new_fluid_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth)
char* name;
char *allnames;
for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers); i++) {
for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers) && fluid_audio_drivers[i].name != NULL; i++) {
if (fluid_settings_str_equal(settings, "audio.driver", fluid_audio_drivers[i].name)) {
FLUID_LOG(FLUID_DBG, "Using '%s' audio driver", fluid_audio_drivers[i].name);
driver = (*fluid_audio_drivers[i].new)(settings, synth);
@ -340,7 +409,7 @@ new_fluid_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, voi
fluid_audio_driver_t* driver = NULL;
char* name;
for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers); i++) {
for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers) && fluid_audio_drivers[i].name != NULL; i++) {
if (fluid_settings_str_equal(settings, "audio.driver", fluid_audio_drivers[i].name) &&
(fluid_audio_drivers[i].new2 != NULL)) {
FLUID_LOG(FLUID_DBG, "Using '%s' audio driver", fluid_audio_drivers[i].name);
@ -389,7 +458,7 @@ delete_fluid_audio_driver(fluid_audio_driver_t* driver)
* 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 \c names of audio drivers to register
* for the usage with fluidsynth.
* The \c names are the same as used for the \c audio.driver setting.
* The \c names are the same as being used for the \c audio.driver setting.
*
* By default all audio drivers fluidsynth has been compiled with are registered.
*
@ -407,17 +476,20 @@ delete_fluid_audio_driver(fluid_audio_driver_t* driver)
*/
int fluid_audio_driver_register(const char** adrivers)
{
unsigned int i, j, add=0;
unsigned int i=0, add=0;
int res = FLUID_FAILED;
if(adrivers == NULL)
{
FLUID_MEMCPY(fluid_audio_drivers, fluid_audio_drivers_template, sizeof(fluid_audio_drivers));
res = FLUID_OK;
goto cleanup;
}
else
{
FLUID_MEMSET(fluid_audio_drivers, 0, sizeof(fluid_audio_drivers));
for(i=0; adrivers[i] != NULL; i++)
{
unsigned int j;
/* search the requested audio driver in the template and copy it over if found */
for (j = 0; j < FLUID_N_ELEMENTS(fluid_audio_drivers_template); j++)
{
@ -432,7 +504,7 @@ int fluid_audio_driver_register(const char** adrivers)
if(j >= FLUID_N_ELEMENTS(fluid_audio_drivers_template))
{
/* requested driver not found, failure */
goto error;
goto cleanup;
}
}
}
@ -440,12 +512,13 @@ int fluid_audio_driver_register(const char** adrivers)
if(i >= FLUID_N_ELEMENTS(fluid_audio_drivers_template))
{
/* user requested more drivers than this build of fluidsynth supports, failure */
goto error;
goto cleanup;
}
return FLUID_OK;
res = FLUID_OK;
return res;
error:
FLUID_MEMSET(fluid_audio_drivers, 0, sizeof(fluid_audio_drivers));
return FLUID_FAILED;
cleanup:
FLUID_MEMCPY(fluid_audio_drivers, fluid_audio_drivers_template, sizeof(fluid_audio_drivers));
return res;
}