Search
lxdream.org :: lxdream/src/aica/audio.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/audio.c
changeset 1024:c67f2d61ab97
prev989:7baf5ecd8e98
next1089:a3984d242909
author nkeynes
date Sat Jun 13 00:50:48 2009 +0000 (12 years ago)
permissions -rw-r--r--
last change Build drivers with library dependencies as shared objects (ie plugins)
file annotate diff log raw
1.1 --- a/src/aica/audio.c Sat Feb 28 06:26:48 2009 +0000
1.2 +++ b/src/aica/audio.c Sat Jun 13 00:50:48 2009 +0000
1.3 @@ -24,7 +24,7 @@
1.4 #include <assert.h>
1.5 #include <string.h>
1.6
1.7 -
1.8 +#define MAX_AUDIO_DRIVERS 16
1.9 extern struct audio_driver audio_null_driver;
1.10 extern struct audio_driver audio_osx_driver;
1.11 extern struct audio_driver audio_pulse_driver;
1.12 @@ -32,24 +32,8 @@
1.13 extern struct audio_driver audio_alsa_driver;
1.14 extern struct audio_driver audio_sdl_driver;
1.15
1.16 -audio_driver_t audio_driver_list[] = {
1.17 -#ifdef HAVE_CORE_AUDIO
1.18 - &audio_osx_driver,
1.19 -#endif
1.20 -#ifdef HAVE_SDL
1.21 - &audio_sdl_driver,
1.22 -#endif
1.23 -#ifdef HAVE_PULSE
1.24 - &audio_pulse_driver,
1.25 -#endif
1.26 -#ifdef HAVE_ESOUND
1.27 - &audio_esd_driver,
1.28 -#endif
1.29 -#ifdef HAVE_ALSA
1.30 - &audio_alsa_driver,
1.31 -#endif
1.32 - &audio_null_driver,
1.33 - NULL };
1.34 +static int audio_driver_count = 0;
1.35 +static audio_driver_t audio_driver_list[MAX_AUDIO_DRIVERS] = {};
1.36
1.37 #define NUM_BUFFERS 3
1.38 #define MS_PER_BUFFER 100
1.39 @@ -86,13 +70,39 @@
1.40 return (read == AUDIO_CHANNEL_COUNT ? 0 : -1 );
1.41 }
1.42
1.43 +static int audio_driver_priority_compare(const void *a, const void *b)
1.44 +{
1.45 + audio_driver_t ada = *(audio_driver_t *)a;
1.46 + audio_driver_t adb = *(audio_driver_t *)b;
1.47 + return ada->priority - adb->priority;
1.48 +}
1.49 +
1.50 +static int audio_driver_name_compare(const void *a, const void *b)
1.51 +{
1.52 + audio_driver_t ada = *(audio_driver_t *)a;
1.53 + audio_driver_t adb = *(audio_driver_t *)b;
1.54 + return strcasecmp( ada->name, adb->name );
1.55 +}
1.56 +
1.57 +
1.58 +
1.59 +gboolean audio_register_driver( audio_driver_t driver )
1.60 +{
1.61 + if( audio_driver_count >= MAX_AUDIO_DRIVERS ) {
1.62 + return FALSE;
1.63 + }
1.64 + audio_driver_list[audio_driver_count++] = driver;
1.65 + qsort( audio_driver_list, audio_driver_count, sizeof( audio_driver_t ), audio_driver_priority_compare );
1.66 + return TRUE;
1.67 +}
1.68 +
1.69 audio_driver_t get_audio_driver_by_name( const char *name )
1.70 {
1.71 int i;
1.72 if( name == NULL ) {
1.73 return audio_driver_list[0];
1.74 }
1.75 - for( i=0; audio_driver_list[i] != NULL; i++ ) {
1.76 + for( i=0; i < audio_driver_count; i++ ) {
1.77 if( strcasecmp( audio_driver_list[i]->name, name ) == 0 ) {
1.78 return audio_driver_list[i];
1.79 }
1.80 @@ -104,10 +114,13 @@
1.81 void print_audio_drivers( FILE * out )
1.82 {
1.83 int i;
1.84 + audio_driver_t temp_list[MAX_AUDIO_DRIVERS];
1.85 + memcpy( temp_list, audio_driver_list, audio_driver_count*sizeof(audio_driver_t) );
1.86 + qsort( temp_list, audio_driver_count, sizeof(audio_driver_t), audio_driver_name_compare );
1.87 fprintf( out, "Available audio drivers:\n" );
1.88 - for( i=0; audio_driver_list[i] != NULL; i++ ) {
1.89 - fprintf( out, " %-8s %s\n", audio_driver_list[i]->name,
1.90 - gettext(audio_driver_list[i]->description) );
1.91 + for( i=0; i < audio_driver_count; i++ ) {
1.92 + fprintf( out, " %-8s %s\n", temp_list[i]->name,
1.93 + gettext(temp_list[i]->description) );
1.94 }
1.95 }
1.96
1.97 @@ -119,7 +132,7 @@
1.98 exit(2);
1.99 } else if( audio_set_driver( audio_driver ) == FALSE ) {
1.100 int i;
1.101 - for( i=0; audio_driver_list[i] != NULL; i++ ) {
1.102 + for( i=0; i < audio_driver_count; i++ ) {
1.103 if( audio_driver_list[i] != audio_driver &&
1.104 audio_set_driver( audio_driver_list[i] ) ) {
1.105 ERROR( "Failed to initialize audio driver %s, falling back to %s",
1.106 @@ -133,6 +146,20 @@
1.107 return audio_driver;
1.108 }
1.109
1.110 +void audio_start_driver(void)
1.111 +{
1.112 + if( audio_driver != NULL && audio_driver->start != NULL ) {
1.113 + audio_driver->start();
1.114 + }
1.115 +}
1.116 +
1.117 +void audio_stop_driver(void)
1.118 +{
1.119 + if( audio_driver != NULL && audio_driver->stop != NULL ) {
1.120 + audio_driver->stop();
1.121 + }
1.122 +}
1.123 +
1.124 /**
1.125 * Set the output driver, sample rate and format. Also initializes the
1.126 * output buffers, flushing any current data and reallocating as
.