Moved to stable ALSA API. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Sat, 10 Oct 2009 07:33:18 +0000
branchSDL-1.2
changeset 4292464126f4c7db
parent 4291 6cc2b35ac610
child 4293 63b54ddd38ea
Moved to stable ALSA API.

This cleans up a few problems with our use of the ancient ALSA 0.9 API.

This means we can ditch the dlvsym() nonsense and use SDL_LoadFunction(), too.

Fixes Bugzilla #745.
src/audio/alsa/SDL_alsa_audio.c
src/audio/alsa/SDL_alsa_audio.h
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Sat Oct 10 07:30:00 2009 +0000
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Sat Oct 10 07:33:18 2009 +0000
     1.3 @@ -33,7 +33,6 @@
     1.4  #include "SDL_alsa_audio.h"
     1.5  
     1.6  #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
     1.7 -#include <dlfcn.h>
     1.8  #include "SDL_name.h"
     1.9  #include "SDL_loadso.h"
    1.10  #else
    1.11 @@ -74,11 +73,11 @@
    1.12  static int (*SDL_NAME(snd_pcm_hw_params_set_access))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access);
    1.13  static int (*SDL_NAME(snd_pcm_hw_params_set_format))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val);
    1.14  static int (*SDL_NAME(snd_pcm_hw_params_set_channels))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val);
    1.15 -static int (*SDL_NAME(snd_pcm_hw_params_get_channels))(const snd_pcm_hw_params_t *params);
    1.16 -static unsigned int (*SDL_NAME(snd_pcm_hw_params_set_rate_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int *dir);
    1.17 -static snd_pcm_uframes_t (*SDL_NAME(snd_pcm_hw_params_set_period_size_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int *dir);
    1.18 +static int (*SDL_NAME(snd_pcm_hw_params_set_rate_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
    1.19 +static int (*SDL_NAME(snd_pcm_hw_params_set_period_size_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
    1.20 +static int (*SDL_NAME(snd_pcm_hw_params_get_channels))(const snd_pcm_hw_params_t *params, unsigned int *val);
    1.21  static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_hw_params_get_period_size))(const snd_pcm_hw_params_t *params);
    1.22 -static unsigned int (*SDL_NAME(snd_pcm_hw_params_set_periods_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int *dir);
    1.23 +static int (*SDL_NAME(snd_pcm_hw_params_set_periods_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
    1.24  static int (*SDL_NAME(snd_pcm_hw_params_get_periods))(snd_pcm_hw_params_t *params);
    1.25  static int (*SDL_NAME(snd_pcm_hw_params))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
    1.26  /*
    1.27 @@ -125,8 +124,7 @@
    1.28  
    1.29  static void UnloadALSALibrary(void) {
    1.30  	if (alsa_loaded) {
    1.31 -/*		SDL_UnloadObject(alsa_handle);*/
    1.32 -		dlclose(alsa_handle);
    1.33 +		SDL_UnloadObject(alsa_handle);
    1.34  		alsa_handle = NULL;
    1.35  		alsa_loaded = 0;
    1.36  	}
    1.37 @@ -135,18 +133,12 @@
    1.38  static int LoadALSALibrary(void) {
    1.39  	int i, retval = -1;
    1.40  
    1.41 -/*	alsa_handle = SDL_LoadObject(alsa_library);*/
    1.42 -	alsa_handle = dlopen(alsa_library,RTLD_NOW);
    1.43 +	alsa_handle = SDL_LoadObject(alsa_library);
    1.44  	if (alsa_handle) {
    1.45  		alsa_loaded = 1;
    1.46  		retval = 0;
    1.47  		for (i = 0; i < SDL_arraysize(alsa_functions); i++) {
    1.48 -/*			*alsa_functions[i].func = SDL_LoadFunction(alsa_handle,alsa_functions[i].name);*/
    1.49 -#if HAVE_DLVSYM
    1.50 -			*alsa_functions[i].func = dlvsym(alsa_handle,alsa_functions[i].name,"ALSA_0.9");
    1.51 -			if (!*alsa_functions[i].func)
    1.52 -#endif
    1.53 -				*alsa_functions[i].func = dlsym(alsa_handle,alsa_functions[i].name);
    1.54 +			*alsa_functions[i].func = SDL_LoadFunction(alsa_handle,alsa_functions[i].name);
    1.55  			if (!*alsa_functions[i].func) {
    1.56  				retval = -1;
    1.57  				UnloadALSALibrary();
    1.58 @@ -374,6 +366,9 @@
    1.59  	snd_pcm_sw_params_t *swparams;
    1.60  	snd_pcm_format_t     format;
    1.61  	snd_pcm_uframes_t    frames;
    1.62 +	unsigned int         rate;
    1.63 +	unsigned int         periods;
    1.64 +	unsigned int 		 channels;
    1.65  	Uint16               test_format;
    1.66  
    1.67  	/* Open the audio device */
    1.68 @@ -445,30 +440,41 @@
    1.69  
    1.70  	/* Set the number of channels */
    1.71  	status = SDL_NAME(snd_pcm_hw_params_set_channels)(pcm_handle, hwparams, spec->channels);
    1.72 +	channels = spec->channels;
    1.73  	if ( status < 0 ) {
    1.74 -		status = SDL_NAME(snd_pcm_hw_params_get_channels)(hwparams);
    1.75 -		if ( (status <= 0) || (status > 2) ) {
    1.76 +		status = SDL_NAME(snd_pcm_hw_params_get_channels)(hwparams, &channels);
    1.77 +		if ( status < 0 ) {
    1.78  			SDL_SetError("Couldn't set audio channels");
    1.79  			ALSA_CloseAudio(this);
    1.80  			return(-1);
    1.81  		}
    1.82 -		spec->channels = status;
    1.83 +		spec->channels = channels;
    1.84  	}
    1.85  
    1.86  	/* Set the audio rate */
    1.87 -	status = SDL_NAME(snd_pcm_hw_params_set_rate_near)(pcm_handle, hwparams, spec->freq, NULL);
    1.88 +	rate = spec->freq;
    1.89 +
    1.90 +	status = SDL_NAME(snd_pcm_hw_params_set_rate_near)(pcm_handle, hwparams, &rate, NULL);
    1.91  	if ( status < 0 ) {
    1.92  		SDL_SetError("Couldn't set audio frequency: %s", SDL_NAME(snd_strerror)(status));
    1.93  		ALSA_CloseAudio(this);
    1.94  		return(-1);
    1.95  	}
    1.96 -	spec->freq = status;
    1.97 +	spec->freq = rate;
    1.98  
    1.99  	/* Set the buffer size, in samples */
   1.100  	frames = spec->samples;
   1.101 -	frames = SDL_NAME(snd_pcm_hw_params_set_period_size_near)(pcm_handle, hwparams, frames, NULL);
   1.102 +	status = SDL_NAME(snd_pcm_hw_params_set_period_size_near)(pcm_handle, hwparams, &frames, NULL);
   1.103 +	if ( status < 0 ) {
   1.104 +		SDL_SetError("Couldn't set audio frequency: %s", SDL_NAME(snd_strerror)(status));
   1.105 +		ALSA_CloseAudio(this);
   1.106 +		return(-1);
   1.107 +	}
   1.108 +
   1.109  	spec->samples = frames;
   1.110 -	SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, 2, NULL);
   1.111 +
   1.112 +	periods = 2;
   1.113 +	SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, &periods, NULL);
   1.114  
   1.115  	/* "set" the hardware with the desired parameters */
   1.116  	status = SDL_NAME(snd_pcm_hw_params)(pcm_handle, hwparams);
     2.1 --- a/src/audio/alsa/SDL_alsa_audio.h	Sat Oct 10 07:30:00 2009 +0000
     2.2 +++ b/src/audio/alsa/SDL_alsa_audio.h	Sat Oct 10 07:33:18 2009 +0000
     2.3 @@ -24,8 +24,6 @@
     2.4  #ifndef _ALSA_PCM_audio_h
     2.5  #define _ALSA_PCM_audio_h
     2.6  
     2.7 -#define ALSA_PCM_OLD_HW_PARAMS_API
     2.8 -#define ALSA_PCM_OLD_SW_PARAMS_API
     2.9  #include <alsa/asoundlib.h>
    2.10  
    2.11  #include "../SDL_sysaudio.h"