Mangled ALSA dynamic loading...static loading will still work if you have the SDL-ryan-multiple-audio-device
authorRyan C. Gordon <icculus@icculus.org>
Fri, 06 Oct 2006 19:45:11 +0000
branchSDL-ryan-multiple-audio-device
changeset 381849eadd6e8962
parent 3817 103bbe13f5eb
child 3819 b225d9820ee3
Mangled ALSA dynamic loading...static loading will still work if you have the
right libraries, but this is expected to break in general cases as we start
dealing with different symbol versions, etc (but may work with, say,
distro-specific packages, etc).
src/audio/alsa/SDL_alsa_audio.c
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Fri Oct 06 04:49:48 2006 +0000
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Fri Oct 06 19:45:11 2006 +0000
     1.3 @@ -25,6 +25,9 @@
     1.4  
     1.5  #include <sys/types.h>
     1.6  #include <signal.h>             /* For kill() */
     1.7 +#include <dlfcn.h>
     1.8 +#include <errno.h>
     1.9 +#include <string.h>
    1.10  
    1.11  #include "SDL_timer.h"
    1.12  #include "SDL_audio.h"
    1.13 @@ -32,14 +35,6 @@
    1.14  #include "../SDL_audio_c.h"
    1.15  #include "SDL_alsa_audio.h"
    1.16  
    1.17 -#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
    1.18 -#include <dlfcn.h>
    1.19 -#include "SDL_name.h"
    1.20 -#include "SDL_loadso.h"
    1.21 -#else
    1.22 -#define SDL_NAME(X)	X
    1.23 -#endif
    1.24 -
    1.25  
    1.26  /* The tag name used by ALSA audio */
    1.27  #define DRIVER_NAME         "alsa"
    1.28 @@ -54,149 +49,111 @@
    1.29  static Uint8 *ALSA_GetAudioBuf(_THIS);
    1.30  static void ALSA_CloseAudio(_THIS);
    1.31  
    1.32 +static int (*ALSA_snd_pcm_open)
    1.33 +                (snd_pcm_t **, const char *, snd_pcm_stream_t, int);
    1.34 +static int (*ALSA_snd_pcm_close)(snd_pcm_t * pcm);
    1.35 +static snd_pcm_sframes_t(*ALSA_snd_pcm_writei)
    1.36 +                (snd_pcm_t *,const void *, snd_pcm_uframes_t);
    1.37 +static int (*ALSA_snd_pcm_resume)(snd_pcm_t *);
    1.38 +static int (*ALSA_snd_pcm_prepare)(snd_pcm_t *);
    1.39 +static int (*ALSA_snd_pcm_drain)(snd_pcm_t *);
    1.40 +static const char *(*ALSA_snd_strerror)(int);
    1.41 +static size_t(*ALSA_snd_pcm_hw_params_sizeof)(void);
    1.42 +static size_t(*ALSA_snd_pcm_sw_params_sizeof)(void);
    1.43 +static int (*ALSA_snd_pcm_hw_params_any)(snd_pcm_t *, snd_pcm_hw_params_t *);
    1.44 +static int (*ALSA_snd_pcm_hw_params_set_access)
    1.45 +                (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_access_t);
    1.46 +static int (*ALSA_snd_pcm_hw_params_set_format)
    1.47 +                (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_format_t);
    1.48 +static int (*ALSA_snd_pcm_hw_params_set_channels)
    1.49 +                (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int);
    1.50 +static int (*ALSA_snd_pcm_hw_params_get_channels)(const snd_pcm_hw_params_t *);
    1.51 +static unsigned int (*ALSA_snd_pcm_hw_params_set_rate_near)
    1.52 +                (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int, int *);
    1.53 +static snd_pcm_uframes_t (*ALSA_snd_pcm_hw_params_set_period_size_near)
    1.54 +                (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t, int *);
    1.55 +static snd_pcm_sframes_t (*ALSA_snd_pcm_hw_params_get_period_size)
    1.56 +                (const snd_pcm_hw_params_t *);
    1.57 +static unsigned int (*ALSA_snd_pcm_hw_params_set_periods_near)
    1.58 +                (snd_pcm_t *,snd_pcm_hw_params_t *, unsigned int, int *);
    1.59 +static int (*ALSA_snd_pcm_hw_params_get_periods)(snd_pcm_hw_params_t *);
    1.60 +static int (*ALSA_snd_pcm_hw_params)(snd_pcm_t *, snd_pcm_hw_params_t *);
    1.61 +static int (*ALSA_snd_pcm_sw_params_current)(snd_pcm_t*, snd_pcm_sw_params_t*);
    1.62 +static int (*ALSA_snd_pcm_sw_params_set_start_threshold)
    1.63 +                (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
    1.64 +static int (*ALSA_snd_pcm_sw_params_set_avail_min)
    1.65 +                (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
    1.66 +static int (*ALSA_snd_pcm_sw_params)(snd_pcm_t *, snd_pcm_sw_params_t *);
    1.67 +static int (*ALSA_snd_pcm_nonblock)(snd_pcm_t *, int);
    1.68 +#define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof
    1.69 +#define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof
    1.70 +
    1.71 +
    1.72  #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
    1.73  
    1.74  static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC;
    1.75  static void *alsa_handle = NULL;
    1.76 -static int alsa_loaded = 0;
    1.77  
    1.78 -static int (*SDL_snd_pcm_open) (snd_pcm_t ** pcm, const char *name,
    1.79 -                                snd_pcm_stream_t stream, int mode);
    1.80 -static int (*SDL_NAME(snd_pcm_open)) (snd_pcm_t ** pcm, const char *name,
    1.81 -                                      snd_pcm_stream_t stream, int mode);
    1.82 -static int (*SDL_NAME(snd_pcm_close)) (snd_pcm_t * pcm);
    1.83 -static snd_pcm_sframes_t(*SDL_NAME(snd_pcm_writei)) (snd_pcm_t * pcm,
    1.84 -                                                     const void *buffer,
    1.85 -                                                     snd_pcm_uframes_t size);
    1.86 -static int (*SDL_NAME(snd_pcm_resume)) (snd_pcm_t * pcm);
    1.87 -static int (*SDL_NAME(snd_pcm_prepare)) (snd_pcm_t * pcm);
    1.88 -static int (*SDL_NAME(snd_pcm_drain)) (snd_pcm_t * pcm);
    1.89 -static const char *(*SDL_NAME(snd_strerror)) (int errnum);
    1.90 -static size_t(*SDL_NAME(snd_pcm_hw_params_sizeof)) (void);
    1.91 -static size_t(*SDL_NAME(snd_pcm_sw_params_sizeof)) (void);
    1.92 -static int (*SDL_NAME(snd_pcm_hw_params_any)) (snd_pcm_t * pcm,
    1.93 -                                               snd_pcm_hw_params_t * params);
    1.94 -static int (*SDL_NAME(snd_pcm_hw_params_set_access)) (snd_pcm_t * pcm,
    1.95 -                                                      snd_pcm_hw_params_t *
    1.96 -                                                      params,
    1.97 -                                                      snd_pcm_access_t
    1.98 -                                                      access);
    1.99 -static int (*SDL_NAME(snd_pcm_hw_params_set_format)) (snd_pcm_t * pcm,
   1.100 -                                                      snd_pcm_hw_params_t *
   1.101 -                                                      params,
   1.102 -                                                      snd_pcm_format_t val);
   1.103 -static int (*SDL_NAME(snd_pcm_hw_params_set_channels)) (snd_pcm_t * pcm,
   1.104 -                                                        snd_pcm_hw_params_t *
   1.105 -                                                        params,
   1.106 -                                                        unsigned int val);
   1.107 -static int (*SDL_NAME(snd_pcm_hw_params_get_channels)) (const
   1.108 -                                                        snd_pcm_hw_params_t *
   1.109 -                                                        params);
   1.110 -static unsigned int
   1.111 -    (*SDL_NAME(snd_pcm_hw_params_set_rate_near)) (snd_pcm_t *
   1.112 -                                                  pcm,
   1.113 -                                                  snd_pcm_hw_params_t
   1.114 -                                                  * params,
   1.115 -                                                  unsigned int val, int *dir);
   1.116 -static snd_pcm_uframes_t
   1.117 -    (*SDL_NAME(snd_pcm_hw_params_set_period_size_near)) (snd_pcm_t * pcm,
   1.118 -                                                         snd_pcm_hw_params_t
   1.119 -                                                         * params,
   1.120 -                                                         snd_pcm_uframes_t
   1.121 -                                                         val, int *dir);
   1.122 -static snd_pcm_sframes_t
   1.123 -    (*SDL_NAME(snd_pcm_hw_params_get_period_size)) (const
   1.124 -                                                    snd_pcm_hw_params_t
   1.125 -                                                    * params);
   1.126 -static unsigned int
   1.127 -    (*SDL_NAME(snd_pcm_hw_params_set_periods_near)) (snd_pcm_t * pcm,
   1.128 -                                                     snd_pcm_hw_params_t
   1.129 -                                                     * params,
   1.130 -                                                     unsigned int val,
   1.131 -                                                     int *dir);
   1.132 -static int (*SDL_NAME(snd_pcm_hw_params_get_periods)) (snd_pcm_hw_params_t *
   1.133 -                                                       params);
   1.134 -static int (*SDL_NAME(snd_pcm_hw_params)) (snd_pcm_t * pcm,
   1.135 -                                           snd_pcm_hw_params_t * params);
   1.136 -/*
   1.137 -*/
   1.138 -static int (*SDL_NAME(snd_pcm_sw_params_current)) (snd_pcm_t * pcm,
   1.139 -                                                   snd_pcm_sw_params_t *
   1.140 -                                                   swparams);
   1.141 -static int (*SDL_NAME(snd_pcm_sw_params_set_start_threshold)) (snd_pcm_t *
   1.142 -                                                               pcm,
   1.143 -                                                               snd_pcm_sw_params_t
   1.144 -                                                               * params,
   1.145 -                                                               snd_pcm_uframes_t
   1.146 -                                                               val);
   1.147 -static int (*SDL_NAME(snd_pcm_sw_params_set_avail_min)) (snd_pcm_t * pcm,
   1.148 -                                                         snd_pcm_sw_params_t
   1.149 -                                                         * params,
   1.150 -                                                         snd_pcm_uframes_t
   1.151 -                                                         val);
   1.152 -static int (*SDL_NAME(snd_pcm_sw_params)) (snd_pcm_t * pcm,
   1.153 -                                           snd_pcm_sw_params_t * params);
   1.154 -static int (*SDL_NAME(snd_pcm_nonblock)) (snd_pcm_t * pcm, int nonblock);
   1.155 -#define snd_pcm_hw_params_sizeof SDL_NAME(snd_pcm_hw_params_sizeof)
   1.156 -#define snd_pcm_sw_params_sizeof SDL_NAME(snd_pcm_sw_params_sizeof)
   1.157 +static int
   1.158 +load_alsa_sym(const char *fn, void **addr)
   1.159 +{
   1.160 +#if HAVE_DLVSYM
   1.161 +    *addr = dlvsym(alsa_handle, fn, "ALSA_0.9");
   1.162 +    if (*addr == NULL)
   1.163 +#endif
   1.164 +    {
   1.165 +        *addr = dlsym(alsa_handle, fn);
   1.166 +        if (*addr == NULL) {
   1.167 +            return 0;
   1.168 +        }
   1.169 +    }
   1.170 +
   1.171 +    return 1;
   1.172 +}
   1.173  
   1.174  /* cast funcs to char* first, to please GCC's strict aliasing rules. */
   1.175 -static struct
   1.176 +#define SDL_ALSA_SYM(x) \
   1.177 +    if (!load_alsa_sym(#x, (void **) (char *) &ALSA_##x)) return -1
   1.178 +#else
   1.179 +#define SDL_ALSA_SYM(x) ALSA_##x = x
   1.180 +#endif
   1.181 +
   1.182 +static int load_alsa_syms(void)
   1.183  {
   1.184 -    const char *name;
   1.185 -    void **func;
   1.186 -} alsa_functions[] = {
   1.187 -    {
   1.188 -    "snd_pcm_open", (void **) (char *) &SDL_NAME(snd_pcm_open)}, {
   1.189 -    "snd_pcm_close", (void **) (char *) &SDL_NAME(snd_pcm_close)}, {
   1.190 -    "snd_pcm_writei", (void **) (char *) &SDL_NAME(snd_pcm_writei)}, {
   1.191 -    "snd_pcm_resume", (void **) (char *) &SDL_NAME(snd_pcm_resume)}, {
   1.192 -    "snd_pcm_prepare", (void **) (char *) &SDL_NAME(snd_pcm_prepare)}, {
   1.193 -    "snd_pcm_drain", (void **) (char *) &SDL_NAME(snd_pcm_drain)}, {
   1.194 -    "snd_strerror", (void **) (char *) &SDL_NAME(snd_strerror)}, {
   1.195 -    "snd_pcm_hw_params_sizeof",
   1.196 -            (void **) (char *) &SDL_NAME(snd_pcm_hw_params_sizeof)}, {
   1.197 -    "snd_pcm_sw_params_sizeof",
   1.198 -            (void **) (char *) &SDL_NAME(snd_pcm_sw_params_sizeof)}, {
   1.199 -    "snd_pcm_hw_params_any",
   1.200 -            (void **) (char *) &SDL_NAME(snd_pcm_hw_params_any)}, {
   1.201 -    "snd_pcm_hw_params_set_access",
   1.202 -            (void **) (char *) &SDL_NAME(snd_pcm_hw_params_set_access)}, {
   1.203 -    "snd_pcm_hw_params_set_format",
   1.204 -            (void **) (char *) &SDL_NAME(snd_pcm_hw_params_set_format)}, {
   1.205 -    "snd_pcm_hw_params_set_channels",
   1.206 -            (void **) (char *) &SDL_NAME(snd_pcm_hw_params_set_channels)}, {
   1.207 -    "snd_pcm_hw_params_get_channels",
   1.208 -            (void **) (char *) &SDL_NAME(snd_pcm_hw_params_get_channels)}, {
   1.209 -    "snd_pcm_hw_params_set_rate_near",
   1.210 -            (void **) (char *) &SDL_NAME(snd_pcm_hw_params_set_rate_near)}, {
   1.211 -        "snd_pcm_hw_params_set_period_size_near", (void **) (char *)
   1.212 -    &SDL_NAME(snd_pcm_hw_params_set_period_size_near)}, {
   1.213 -    "snd_pcm_hw_params_get_period_size",
   1.214 -            (void **) (char *) &SDL_NAME(snd_pcm_hw_params_get_period_size)},
   1.215 -    {
   1.216 -        "snd_pcm_hw_params_set_periods_near", (void **) (char *)
   1.217 -    &SDL_NAME(snd_pcm_hw_params_set_periods_near)}, {
   1.218 -    "snd_pcm_hw_params_get_periods",
   1.219 -            (void **) (char *) &SDL_NAME(snd_pcm_hw_params_get_periods)}, {
   1.220 -    "snd_pcm_hw_params", (void **) (char *) &SDL_NAME(snd_pcm_hw_params)}, {
   1.221 -    "snd_pcm_sw_params_current",
   1.222 -            (void **) (char *) &SDL_NAME(snd_pcm_sw_params_current)}, {
   1.223 -        "snd_pcm_sw_params_set_start_threshold", (void **) (char *)
   1.224 -    &SDL_NAME(snd_pcm_sw_params_set_start_threshold)}, {
   1.225 -    "snd_pcm_sw_params_set_avail_min",
   1.226 -            (void **) (char *) &SDL_NAME(snd_pcm_sw_params_set_avail_min)}, {
   1.227 -    "snd_pcm_sw_params", (void **) (char *) &SDL_NAME(snd_pcm_sw_params)}, {
   1.228 -"snd_pcm_nonblock", (void **) (char *) &SDL_NAME(snd_pcm_nonblock)},};
   1.229 +    SDL_ALSA_SYM(snd_pcm_open);
   1.230 +    SDL_ALSA_SYM(snd_pcm_close);
   1.231 +    SDL_ALSA_SYM(snd_pcm_writei);
   1.232 +    SDL_ALSA_SYM(snd_pcm_resume);
   1.233 +    SDL_ALSA_SYM(snd_pcm_prepare);
   1.234 +    SDL_ALSA_SYM(snd_pcm_drain);
   1.235 +    SDL_ALSA_SYM(snd_strerror);
   1.236 +    SDL_ALSA_SYM(snd_pcm_hw_params_sizeof);
   1.237 +    SDL_ALSA_SYM(snd_pcm_sw_params_sizeof);
   1.238 +    SDL_ALSA_SYM(snd_pcm_hw_params_any);
   1.239 +    SDL_ALSA_SYM(snd_pcm_hw_params_set_access);
   1.240 +    SDL_ALSA_SYM(snd_pcm_hw_params_set_format);
   1.241 +    SDL_ALSA_SYM(snd_pcm_hw_params_set_channels);
   1.242 +    SDL_ALSA_SYM(snd_pcm_hw_params_get_channels);
   1.243 +    SDL_ALSA_SYM(snd_pcm_hw_params_set_rate_near);
   1.244 +    SDL_ALSA_SYM(snd_pcm_hw_params_set_period_size_near);
   1.245 +    SDL_ALSA_SYM(snd_pcm_hw_params_get_period_size);
   1.246 +    SDL_ALSA_SYM(snd_pcm_hw_params_set_periods_near);
   1.247 +    SDL_ALSA_SYM(snd_pcm_hw_params_get_periods);
   1.248 +    SDL_ALSA_SYM(snd_pcm_hw_params);
   1.249 +    SDL_ALSA_SYM(snd_pcm_sw_params_current);
   1.250 +    SDL_ALSA_SYM(snd_pcm_sw_params_set_start_threshold);
   1.251 +    SDL_ALSA_SYM(snd_pcm_sw_params_set_avail_min);
   1.252 +    SDL_ALSA_SYM(snd_pcm_sw_params);
   1.253 +    SDL_ALSA_SYM(snd_pcm_nonblock);
   1.254 +    return 0;
   1.255 +}
   1.256  
   1.257  static void
   1.258  UnloadALSALibrary(void)
   1.259  {
   1.260 -    if (alsa_loaded) {
   1.261 -/*		SDL_UnloadObject(alsa_handle);*/
   1.262 +    if (alsa_handle != NULL) {
   1.263          dlclose(alsa_handle);
   1.264          alsa_handle = NULL;
   1.265 -        alsa_loaded = 0;
   1.266      }
   1.267  }
   1.268  
   1.269 @@ -205,25 +162,14 @@
   1.270  {
   1.271      int i, retval = -1;
   1.272  
   1.273 -/*	alsa_handle = SDL_LoadObject(alsa_library);*/
   1.274      alsa_handle = dlopen(alsa_library, RTLD_NOW);
   1.275 -    if (alsa_handle) {
   1.276 -        alsa_loaded = 1;
   1.277 -        retval = 0;
   1.278 -        for (i = 0; i < SDL_arraysize(alsa_functions); i++) {
   1.279 -/*			*alsa_functions[i].func = SDL_LoadFunction(alsa_handle,alsa_functions[i].name);*/
   1.280 -#if HAVE_DLVSYM
   1.281 -            *alsa_functions[i].func =
   1.282 -                dlvsym(alsa_handle, alsa_functions[i].name, "ALSA_0.9");
   1.283 -            if (!*alsa_functions[i].func)
   1.284 -#endif
   1.285 -                *alsa_functions[i].func =
   1.286 -                    dlsym(alsa_handle, alsa_functions[i].name);
   1.287 -            if (!*alsa_functions[i].func) {
   1.288 -                retval = -1;
   1.289 -                UnloadALSALibrary();
   1.290 -                break;
   1.291 -            }
   1.292 +    if (alsa_handle == NULL) {
   1.293 +        SDL_SetError("ALSA: dlopen('%s') failed: %s\n",
   1.294 +                      alsa_library, strerror(errno));
   1.295 +    } else {
   1.296 +        retval = load_alsa_syms();
   1.297 +        if (retval < 0) {
   1.298 +            UnloadALSALibrary();
   1.299          }
   1.300      }
   1.301      return retval;
   1.302 @@ -240,6 +186,7 @@
   1.303  static int
   1.304  LoadALSALibrary(void)
   1.305  {
   1.306 +    load_alsa_syms();
   1.307      return 0;
   1.308  }
   1.309  
   1.310 @@ -275,12 +222,11 @@
   1.311      if (LoadALSALibrary() < 0) {
   1.312          return available;
   1.313      }
   1.314 -    status =
   1.315 -        SDL_NAME(snd_pcm_open) (&handle, get_audio_device(2),
   1.316 -                                SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
   1.317 +    status = ALSA_snd_pcm_open(&handle, get_audio_device(2),
   1.318 +                               SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
   1.319      if (status >= 0) {
   1.320          available = 1;
   1.321 -        SDL_NAME(snd_pcm_close) (handle);
   1.322 +        ALSA_snd_pcm_close(handle);
   1.323      }
   1.324      UnloadALSALibrary();
   1.325      return (available);
   1.326 @@ -427,8 +373,7 @@
   1.327      sample_buf = (signed short *) mixbuf;
   1.328  
   1.329      while (sample_len > 0) {
   1.330 -        status =
   1.331 -            SDL_NAME(snd_pcm_writei) (pcm_handle, sample_buf, sample_len);
   1.332 +        status = ALSA_snd_pcm_writei(pcm_handle, sample_buf, sample_len);
   1.333          if (status < 0) {
   1.334              if (status == -EAGAIN) {
   1.335                  SDL_Delay(1);
   1.336 @@ -437,11 +382,11 @@
   1.337              if (status == -ESTRPIPE) {
   1.338                  do {
   1.339                      SDL_Delay(1);
   1.340 -                    status = SDL_NAME(snd_pcm_resume) (pcm_handle);
   1.341 +                    status = ALSA_snd_pcm_resume(pcm_handle);
   1.342                  } while (status == -EAGAIN);
   1.343              }
   1.344              if (status < 0) {
   1.345 -                status = SDL_NAME(snd_pcm_prepare) (pcm_handle);
   1.346 +                status = ALSA_snd_pcm_prepare(pcm_handle);
   1.347              }
   1.348              if (status < 0) {
   1.349                  /* Hmm, not much we can do - abort */
   1.350 @@ -469,8 +414,8 @@
   1.351          mixbuf = NULL;
   1.352      }
   1.353      if (pcm_handle) {
   1.354 -        SDL_NAME(snd_pcm_drain) (pcm_handle);
   1.355 -        SDL_NAME(snd_pcm_close) (pcm_handle);
   1.356 +        ALSA_snd_pcm_drain(pcm_handle);
   1.357 +        ALSA_snd_pcm_close(pcm_handle);
   1.358          pcm_handle = NULL;
   1.359      }
   1.360  }
   1.361 @@ -487,34 +432,32 @@
   1.362  
   1.363      /* Open the audio device */
   1.364      /* Name of device should depend on # channels in spec */
   1.365 -    status =
   1.366 -        SDL_NAME(snd_pcm_open) (&pcm_handle,
   1.367 -                                get_audio_device(spec->channels),
   1.368 -                                SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
   1.369 +    status = ALSA_snd_pcm_open(&pcm_handle,
   1.370 +                               get_audio_device(spec->channels),
   1.371 +                               SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
   1.372  
   1.373      if (status < 0) {
   1.374          SDL_SetError("Couldn't open audio device: %s",
   1.375 -                     SDL_NAME(snd_strerror) (status));
   1.376 +                     ALSA_snd_strerror(status));
   1.377          return (-1);
   1.378      }
   1.379  
   1.380      /* Figure out what the hardware is capable of */
   1.381      snd_pcm_hw_params_alloca(&hwparams);
   1.382 -    status = SDL_NAME(snd_pcm_hw_params_any) (pcm_handle, hwparams);
   1.383 +    status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
   1.384      if (status < 0) {
   1.385          SDL_SetError("Couldn't get hardware config: %s",
   1.386 -                     SDL_NAME(snd_strerror) (status));
   1.387 +                     ALSA_snd_strerror(status));
   1.388          ALSA_CloseAudio(this);
   1.389          return (-1);
   1.390      }
   1.391  
   1.392      /* SDL only uses interleaved sample output */
   1.393 -    status =
   1.394 -        SDL_NAME(snd_pcm_hw_params_set_access) (pcm_handle, hwparams,
   1.395 -                                                SND_PCM_ACCESS_RW_INTERLEAVED);
   1.396 +    status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
   1.397 +                                               SND_PCM_ACCESS_RW_INTERLEAVED);
   1.398      if (status < 0) {
   1.399          SDL_SetError("Couldn't set interleaved access: %s",
   1.400 -                     SDL_NAME(snd_strerror) (status));
   1.401 +                     ALSA_snd_strerror(status));
   1.402          ALSA_CloseAudio(this);
   1.403          return (-1);
   1.404      }
   1.405 @@ -560,9 +503,8 @@
   1.406              break;
   1.407          }
   1.408          if (status >= 0) {
   1.409 -            status =
   1.410 -                SDL_NAME(snd_pcm_hw_params_set_format) (pcm_handle,
   1.411 -                                                        hwparams, format);
   1.412 +            status = ALSA_snd_pcm_hw_params_set_format(pcm_handle,
   1.413 +                                                       hwparams, format);
   1.414          }
   1.415          if (status < 0) {
   1.416              test_format = SDL_NextAudioFormat();
   1.417 @@ -576,11 +518,10 @@
   1.418      spec->format = test_format;
   1.419  
   1.420      /* Set the number of channels */
   1.421 -    status =
   1.422 -        SDL_NAME(snd_pcm_hw_params_set_channels) (pcm_handle, hwparams,
   1.423 -                                                  spec->channels);
   1.424 +    status = ALSA_snd_pcm_hw_params_set_channels(pcm_handle, hwparams,
   1.425 +                                                 spec->channels);
   1.426      if (status < 0) {
   1.427 -        status = SDL_NAME(snd_pcm_hw_params_get_channels) (hwparams);
   1.428 +        status = ALSA_snd_pcm_hw_params_get_channels(hwparams);
   1.429          if ((status <= 0) || (status > 2)) {
   1.430              SDL_SetError("Couldn't set audio channels");
   1.431              ALSA_CloseAudio(this);
   1.432 @@ -590,41 +531,37 @@
   1.433      }
   1.434  
   1.435      /* Set the audio rate */
   1.436 -    status =
   1.437 -        SDL_NAME(snd_pcm_hw_params_set_rate_near) (pcm_handle, hwparams,
   1.438 -                                                   spec->freq, NULL);
   1.439 +    status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
   1.440 +                                                  spec->freq, NULL);
   1.441      if (status < 0) {
   1.442 +        ALSA_CloseAudio(this);
   1.443          SDL_SetError("Couldn't set audio frequency: %s",
   1.444 -                     SDL_NAME(snd_strerror) (status));
   1.445 -        ALSA_CloseAudio(this);
   1.446 +                     ALSA_snd_strerror(status));
   1.447          return (-1);
   1.448      }
   1.449      spec->freq = status;
   1.450  
   1.451      /* Set the buffer size, in samples */
   1.452      frames = spec->samples;
   1.453 -    frames =
   1.454 -        SDL_NAME(snd_pcm_hw_params_set_period_size_near) (pcm_handle,
   1.455 -                                                          hwparams, frames,
   1.456 -                                                          NULL);
   1.457 +    frames = ALSA_snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams,
   1.458 +                                                         frames, NULL);
   1.459      spec->samples = frames;
   1.460 -    SDL_NAME(snd_pcm_hw_params_set_periods_near) (pcm_handle, hwparams, 2,
   1.461 -                                                  NULL);
   1.462 +    ALSA_snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, 2, NULL);
   1.463  
   1.464      /* "set" the hardware with the desired parameters */
   1.465 -    status = SDL_NAME(snd_pcm_hw_params) (pcm_handle, hwparams);
   1.466 +    status = ALSA_snd_pcm_hw_params(pcm_handle, hwparams);
   1.467      if (status < 0) {
   1.468 +        ALSA_CloseAudio(this);
   1.469          SDL_SetError("Couldn't set hardware audio parameters: %s",
   1.470 -                     SDL_NAME(snd_strerror) (status));
   1.471 -        ALSA_CloseAudio(this);
   1.472 +                     ALSA_snd_strerror(status));
   1.473          return (-1);
   1.474      }
   1.475  
   1.476  /* This is useful for debugging... */
   1.477  /*
   1.478  { snd_pcm_sframes_t bufsize; int fragments;
   1.479 -   bufsize = SDL_NAME(snd_pcm_hw_params_get_period_size)(hwparams);
   1.480 -   fragments = SDL_NAME(snd_pcm_hw_params_get_periods)(hwparams);
   1.481 +   bufsize = ALSA_snd_pcm_hw_params_get_period_size(hwparams);
   1.482 +   fragments = ALSA_snd_pcm_hw_params_get_periods(hwparams);
   1.483  
   1.484     fprintf(stderr, "ALSA: bufsize = %ld, fragments = %d\n", bufsize, fragments);
   1.485  }
   1.486 @@ -632,35 +569,30 @@
   1.487  
   1.488      /* Set the software parameters */
   1.489      snd_pcm_sw_params_alloca(&swparams);
   1.490 -    status = SDL_NAME(snd_pcm_sw_params_current) (pcm_handle, swparams);
   1.491 +    status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
   1.492      if (status < 0) {
   1.493          SDL_SetError("Couldn't get software config: %s",
   1.494 -                     SDL_NAME(snd_strerror) (status));
   1.495 +                     ALSA_snd_strerror(status));
   1.496          ALSA_CloseAudio(this);
   1.497          return (-1);
   1.498      }
   1.499 -    status =
   1.500 -        SDL_NAME(snd_pcm_sw_params_set_start_threshold) (pcm_handle,
   1.501 -                                                         swparams, 0);
   1.502 +    status = ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle,swparams,0);
   1.503      if (status < 0) {
   1.504          SDL_SetError("Couldn't set start threshold: %s",
   1.505 -                     SDL_NAME(snd_strerror) (status));
   1.506 +                     ALSA_snd_strerror(status));
   1.507          ALSA_CloseAudio(this);
   1.508          return (-1);
   1.509      }
   1.510 -    status =
   1.511 -        SDL_NAME(snd_pcm_sw_params_set_avail_min) (pcm_handle, swparams,
   1.512 -                                                   frames);
   1.513 +    status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, frames);
   1.514      if (status < 0) {
   1.515 -        SDL_SetError("Couldn't set avail min: %s",
   1.516 -                     SDL_NAME(snd_strerror) (status));
   1.517 +        SDL_SetError("Couldn't set avail min: %s", ALSA_snd_strerror(status));
   1.518          ALSA_CloseAudio(this);
   1.519          return (-1);
   1.520      }
   1.521 -    status = SDL_NAME(snd_pcm_sw_params) (pcm_handle, swparams);
   1.522 +    status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
   1.523      if (status < 0) {
   1.524          SDL_SetError("Couldn't set software audio parameters: %s",
   1.525 -                     SDL_NAME(snd_strerror) (status));
   1.526 +                     ALSA_snd_strerror(status));
   1.527          ALSA_CloseAudio(this);
   1.528          return (-1);
   1.529      }
   1.530 @@ -681,7 +613,7 @@
   1.531      parent = getpid();
   1.532  
   1.533      /* Switch to blocking mode for playback */
   1.534 -    SDL_NAME(snd_pcm_nonblock) (pcm_handle, 0);
   1.535 +    ALSA_snd_pcm_nonblock(pcm_handle, 0);
   1.536  
   1.537      /* We're ready to rock and roll. :-) */
   1.538      return (0);