# src/fluid_adriver.c

    00001 /* FluidSynth - A Software Synthesizer
    00002  *
    00003  * Copyright (C) 2003  Peter Hanappe and others.
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Library General Public License
    00007  * as published by the Free Software Foundation; either version 2 of
    00008  * the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful, but
    00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Library General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Library General Public
    00016  * License along with this library; if not, write to the Free
    00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    00018  * 02111-1307, USA
    00019  */
    00020
    00021 #include "fluid_adriver.h"
    00022 #include "fluid_settings.h"
    00023
    00024 /*
    00025  * fluid_adriver_definition_t
    00026  */
    00027
    00028 typedef struct _fluid_audriver_definition_t
    00029 {
    00030   char* name;
    00031   fluid_audio_driver_t* (*new)(fluid_settings_t* settings, fluid_synth_t* synth);
    00032   fluid_audio_driver_t* (*new2)(fluid_settings_t* settings,
    00033                                 fluid_audio_func_t func,
    00034                                 void* data);
    00035   int (*free)(fluid_audio_driver_t* driver);
    00036   void (*settings)(fluid_settings_t* settings);
    00037 } fluid_audriver_definition_t;
    00038
    00039
    00040
    00041 #if ALSA_SUPPORT
    00042 fluid_audio_driver_t* new_fluid_alsa_audio_driver(fluid_settings_t* settings,
    00043                                                   fluid_synth_t* synth);
    00044 fluid_audio_driver_t* new_fluid_alsa_audio_driver2(fluid_settings_t* settings,
    00045                                                  fluid_audio_func_t func, void* data);
    00046 int delete_fluid_alsa_audio_driver(fluid_audio_driver_t* p);
    00047 void fluid_alsa_audio_driver_settings(fluid_settings_t* settings);
    00048 #endif
    00049
    00050 #if OSS_SUPPORT
    00051 fluid_audio_driver_t* new_fluid_oss_audio_driver(fluid_settings_t* settings,
    00052                                                  fluid_synth_t* synth);
    00053 fluid_audio_driver_t* new_fluid_oss_audio_driver2(fluid_settings_t* settings,
    00054                                                 fluid_audio_func_t func, void* data);
    00055 int delete_fluid_oss_audio_driver(fluid_audio_driver_t* p);
    00056 void fluid_oss_audio_driver_settings(fluid_settings_t* settings);
    00057 #endif
    00058
    00059 #if COREAUDIO_SUPPORT
    00060 fluid_audio_driver_t* new_fluid_core_audio_driver(fluid_settings_t* settings,
    00061                                                   fluid_synth_t* synth);
    00062 fluid_audio_driver_t* new_fluid_core_audio_driver2(fluid_settings_t* settings,
    00063                                                       fluid_audio_func_t func,
    00064                                                       void* data);
    00065 int delete_fluid_core_audio_driver(fluid_audio_driver_t* p);
    00066 void fluid_core_audio_driver_settings(fluid_settings_t* settings);
    00067 #endif
    00068
    00069 #if DSOUND_SUPPORT
    00070 fluid_audio_driver_t* new_fluid_dsound_audio_driver(fluid_settings_t* settings,
    00071                                                   fluid_synth_t* synth);
    00072 int delete_fluid_dsound_audio_driver(fluid_audio_driver_t* p);
    00073 void fluid_dsound_audio_driver_settings(fluid_settings_t* settings);
    00074 #endif
    00075
    00076 #if PORTAUDIO_SUPPORT
    00077 fluid_audio_driver_t* new_fluid_portaudio_driver(fluid_settings_t* settings,
    00078                                                  fluid_synth_t* synth);
    00079 int delete_fluid_portaudio_driver(fluid_audio_driver_t* p);
    00080 #endif
    00081
    00082 #if JACK_SUPPORT
    00083 fluid_audio_driver_t* new_fluid_jack_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth);
    00084 fluid_audio_driver_t* new_fluid_jack_audio_driver2(fluid_settings_t* settings,
    00085                                                  fluid_audio_func_t func, void* data);
    00086 int delete_fluid_jack_audio_driver(fluid_audio_driver_t* p);
    00087 void fluid_jack_audio_driver_settings(fluid_settings_t* settings);
    00088 #endif
    00089
    00090 #if SNDMAN_SUPPORT
    00091 fluid_audio_driver_t* new_fluid_sndmgr_audio_driver(fluid_settings_t* settings,
    00092                                                   fluid_synth_t* synth);
    00093 fluid_audio_driver_t* new_fluid_sndmgr_audio_driver2(fluid_settings_t* settings,
    00094                                                    fluid_audio_func_t func,
    00095                                                    void* data);
    00096 int delete_fluid_sndmgr_audio_driver(fluid_audio_driver_t* p);
    00097 #endif
    00098
    00099 #define AUFILE_SUPPORT 1
    00100 #if AUFILE_SUPPORT
    00101 fluid_audio_driver_t* new_fluid_file_audio_driver(fluid_settings_t* settings,
    00102                                                   fluid_synth_t* synth);
    00103 int delete_fluid_file_audio_driver(fluid_audio_driver_t* p);
    00104 void fluid_file_audio_driver_settings(fluid_settings_t* settings);
    00105 #endif
    00106
    00107 fluid_audriver_definition_t fluid_audio_drivers[] = {
    00108 #if OSS_SUPPORT
    00109   { "oss",
    00110     new_fluid_oss_audio_driver,
    00111     new_fluid_oss_audio_driver2,
    00112     delete_fluid_oss_audio_driver,
    00113     fluid_oss_audio_driver_settings },
    00114 #endif
    00115 #if ALSA_SUPPORT
    00116   { "alsa",
    00117     new_fluid_alsa_audio_driver,
    00118     new_fluid_alsa_audio_driver2,
    00119     delete_fluid_alsa_audio_driver,
    00120     fluid_alsa_audio_driver_settings },
    00121 #endif
    00122 #if COREAUDIO_SUPPORT
    00123   { "coreaudio",
    00124     new_fluid_core_audio_driver,
    00125     new_fluid_core_audio_driver2,
    00126     delete_fluid_core_audio_driver,
    00127     fluid_core_audio_driver_settings },
    00128 #endif
    00129 #if DSOUND_SUPPORT
    00130   { "dsound",
    00131     new_fluid_dsound_audio_driver,
    00132     NULL,
    00133     delete_fluid_dsound_audio_driver,
    00134     fluid_dsound_audio_driver_settings },
    00135 #endif
    00136 #if PORTAUDIO_SUPPORT
    00137   { "portaudio",
    00138     new_fluid_portaudio_driver,
    00139     NULL,
    00140     delete_fluid_portaudio_driver,
    00141     NULL },
    00142 #endif
    00143 #if SNDMAN_SUPPORT
    00144   { "sndman",
    00145     new_fluid_sndmgr_audio_driver,
    00146     new_fluid_sndmgr_audio_driver2,
    00147     delete_fluid_sndmgr_audio_driver,
    00148     NULL },
    00149 #endif
    00150 #if JACK_SUPPORT
    00151   { "jack",
    00152     new_fluid_jack_audio_driver,
    00153     new_fluid_jack_audio_driver2,
    00154     delete_fluid_jack_audio_driver,
    00155     fluid_jack_audio_driver_settings },
    00156 #endif
    00157 #if AUFILE_SUPPORT
    00158   { "file",
    00159     new_fluid_file_audio_driver,
    00160     NULL,
    00161     delete_fluid_file_audio_driver,
    00162     fluid_file_audio_driver_settings },
    00163 #endif
    00164   { NULL, NULL, NULL, NULL, NULL }
    00165 };
    00166
    00167
    00168
    00169
    00170 void fluid_audio_driver_settings(fluid_settings_t* settings)
    00171 {
    00172   int i;
    00173
    00174   fluid_settings_register_str(settings, "audio.sample-format", "16bits", 0, NULL, NULL);
    00175   fluid_settings_add_option(settings, "audio.sample-format", "16bits");
    00176   fluid_settings_add_option(settings, "audio.sample-format", "float");
    00177
    00178   fluid_settings_register_int(settings, "audio.output-channels", 2, 2, 32, 0, NULL, NULL);
    00179   fluid_settings_register_int(settings, "audio.input-channels", 0, 0, 2, 0, NULL, NULL);
    00180
    00181
    00182 #if defined(WIN32)
    00183   fluid_settings_register_int(settings, "audio.period-size", 512, 64, 8192, 0, NULL, NULL);
    00184   fluid_settings_register_int(settings, "audio.periods", 8, 2, 64, 0, NULL, NULL);
    00185 #elif defined(MACOS9)
    00186   fluid_settings_register_int(settings, "audio.period-size", 64, 64, 8192, 0, NULL, NULL);
    00187   fluid_settings_register_int(settings, "audio.periods", 8, 2, 64, 0, NULL, NULL);
    00188 #else
    00189   fluid_settings_register_int(settings, "audio.period-size", 64, 64, 8192, 0, NULL, NULL);
    00190   fluid_settings_register_int(settings, "audio.periods", 16, 2, 64, 0, NULL, NULL);
    00191 #endif
    00192
    00193   /* Set the default driver */
    00194 #if ALSA_SUPPORT
    00195   fluid_settings_register_str(settings, "audio.driver", "alsa", 0, NULL, NULL);
    00196 #elif OSS_SUPPORT
    00197   fluid_settings_register_str(settings, "audio.driver", "oss", 0, NULL, NULL);
    00198 #elif COREAUDIO_SUPPORT
    00199   fluid_settings_register_str(settings, "audio.driver", "coreaudio", 0, NULL, NULL);
    00200 #elif DSOUND_SUPPORT
    00201   fluid_settings_register_str(settings, "audio.driver", "dsound", 0, NULL, NULL);
    00202 #elif SNDMAN_SUPPORT
    00203   fluid_settings_register_str(settings, "audio.driver", "sndman", 0, NULL, NULL);
    00204 #elif PORTAUDIO_SUPPORT
    00205   fluid_settings_register_str(settings, "audio.driver", "portaudio", 0, NULL, NULL);
    00206 #elif JACK_SUPPORT
    00207   fluid_settings_register_str(settings, "audio.driver", "jack", 0, NULL, NULL);
    00208 #elif AUFILE_SUPPORT
    00209   fluid_settings_register_str(settings, "audio.driver", "file", 0, NULL, NULL);
    00210 #else
    00211   fluid_settings_register_str(settings, "audio.driver", "", 0, NULL, NULL);
    00212 #endif
    00213
    00214   /* Add all drivers to the list of options */
    00215 #if ALSA_SUPPORT
    00216   fluid_settings_add_option(settings, "audio.driver", "alsa");
    00217 #endif
    00218 #if OSS_SUPPORT
    00219   fluid_settings_add_option(settings, "audio.driver", "oss");
    00220 #endif
    00221 #if COREAUDIO_SUPPORT
    00222   fluid_settings_add_option(settings, "audio.driver", "coreaudio");
    00223 #endif
    00224 #if DSOUND_SUPPORT
    00225   fluid_settings_add_option(settings, "audio.driver", "dsound");
    00226 #endif
    00227 #if SNDMAN_SUPPORT
    00228   fluid_settings_add_option(settings, "audio.driver", "sndman");
    00229 #endif
    00230 #if PORTAUDIO_SUPPORT
    00231   fluid_settings_add_option(settings, "audio.driver", "portaudio");
    00232 #endif
    00233 #if JACK_SUPPORT
    00234   fluid_settings_add_option(settings, "audio.driver", "jack");
    00235 #endif
    00236 #if AUFILE_SUPPORT
    00237   fluid_settings_add_option(settings, "audio.driver", "file");
    00238 #endif
    00239
    00240   for (i = 0; fluid_audio_drivers[i].name != NULL; i++) {
    00241     if (fluid_audio_drivers[i].settings != NULL) {
    00242       fluid_audio_drivers[i].settings(settings);
    00243     }
    00244   }
    00245 }
    00246
    00247
    00258 fluid_audio_driver_t*
    00259 new_fluid_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth)
    00260 {
    00261   int i;
    00262   fluid_audio_driver_t* driver = NULL;
    00263   char* name;
    00264
    00265   fluid_settings_getstr(settings, "audio.driver", &name);
    00266
    00267   for (i = 0; fluid_audio_drivers[i].name != NULL; i++) {
    00268     if (fluid_settings_str_equal(settings, "audio.driver", fluid_audio_drivers[i].name)) {
    00269       FLUID_LOG(FLUID_DBG, "Using '%s' audio driver", fluid_audio_drivers[i].name);
    00270       driver = (*fluid_audio_drivers[i].new)(settings, synth);
    00271       if (driver) {
    00272         driver->name = fluid_audio_drivers[i].name;
    00273       }
    00274       return driver;
    00275     }
    00276   }
    00277
    00278   FLUID_LOG(FLUID_ERR, "Couldn't find the requested audio driver: %s", name);
    00279   return NULL;
    00280 }
    00281
    00295 fluid_audio_driver_t*
    00296 new_fluid_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data)
    00297 {
    00298   int i;
    00299   fluid_audio_driver_t* driver = NULL;
    00300   char* name;
    00301
    00302   fluid_settings_getstr(settings, "audio.driver", &name);
    00303
    00304   for (i = 0; fluid_audio_drivers[i].name != NULL; i++) {
    00305     if (fluid_settings_str_equal(settings, "audio.driver", fluid_audio_drivers[i].name) &&
    00306         (fluid_audio_drivers[i].new2 != NULL)) {
    00307       FLUID_LOG(FLUID_DBG, "Using '%s' audio driver", fluid_audio_drivers[i].name);
    00308       driver = (*fluid_audio_drivers[i].new2)(settings, func, data);
    00309       if (driver) {
    00310         driver->name = fluid_audio_drivers[i].name;
    00311       }
    00312       return driver;
    00313     }
    00314   }
    00315
    00316   FLUID_LOG(FLUID_ERR, "Couldn't find the requested audio driver: %s", name);
    00317   return NULL;
    00318 }
    00319
    00326 void
    00327 delete_fluid_audio_driver(fluid_audio_driver_t* driver)
    00328 {
    00329   int i;
    00330
    00331   for (i = 0; fluid_audio_drivers[i].name != NULL; i++) {
    00332     if (fluid_audio_drivers[i].name == driver->name) {
    00333       fluid_audio_drivers[i].free(driver);
    00334       return;
    00335     }
    00336   }
    00337 }