Commit a716c987 authored by Ryan C. Gordon's avatar Ryan C. Gordon

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.

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%404006
parent b613ffc4
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "SDL_alsa_audio.h" #include "SDL_alsa_audio.h"
#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
#include <dlfcn.h>
#include "SDL_name.h" #include "SDL_name.h"
#include "SDL_loadso.h" #include "SDL_loadso.h"
#else #else
...@@ -74,11 +73,11 @@ static int (*SDL_NAME(snd_pcm_hw_params_any))(snd_pcm_t *pcm, snd_pcm_hw_params_ ...@@ -74,11 +73,11 @@ static int (*SDL_NAME(snd_pcm_hw_params_any))(snd_pcm_t *pcm, snd_pcm_hw_params_
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); 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);
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); 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);
static int (*SDL_NAME(snd_pcm_hw_params_set_channels))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val); static int (*SDL_NAME(snd_pcm_hw_params_set_channels))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val);
static int (*SDL_NAME(snd_pcm_hw_params_get_channels))(const snd_pcm_hw_params_t *params); 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);
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); 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);
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); static int (*SDL_NAME(snd_pcm_hw_params_get_channels))(const snd_pcm_hw_params_t *params, unsigned int *val);
static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_hw_params_get_period_size))(const snd_pcm_hw_params_t *params); static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_hw_params_get_period_size))(const snd_pcm_hw_params_t *params);
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); 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);
static int (*SDL_NAME(snd_pcm_hw_params_get_periods))(snd_pcm_hw_params_t *params); static int (*SDL_NAME(snd_pcm_hw_params_get_periods))(snd_pcm_hw_params_t *params);
static int (*SDL_NAME(snd_pcm_hw_params))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params); static int (*SDL_NAME(snd_pcm_hw_params))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
/* /*
...@@ -125,8 +124,7 @@ static struct { ...@@ -125,8 +124,7 @@ static struct {
static void UnloadALSALibrary(void) { static void UnloadALSALibrary(void) {
if (alsa_loaded) { if (alsa_loaded) {
/* SDL_UnloadObject(alsa_handle);*/ SDL_UnloadObject(alsa_handle);
dlclose(alsa_handle);
alsa_handle = NULL; alsa_handle = NULL;
alsa_loaded = 0; alsa_loaded = 0;
} }
...@@ -135,18 +133,12 @@ static void UnloadALSALibrary(void) { ...@@ -135,18 +133,12 @@ static void UnloadALSALibrary(void) {
static int LoadALSALibrary(void) { static int LoadALSALibrary(void) {
int i, retval = -1; int i, retval = -1;
/* alsa_handle = SDL_LoadObject(alsa_library);*/ alsa_handle = SDL_LoadObject(alsa_library);
alsa_handle = dlopen(alsa_library,RTLD_NOW);
if (alsa_handle) { if (alsa_handle) {
alsa_loaded = 1; alsa_loaded = 1;
retval = 0; retval = 0;
for (i = 0; i < SDL_arraysize(alsa_functions); i++) { for (i = 0; i < SDL_arraysize(alsa_functions); i++) {
/* *alsa_functions[i].func = SDL_LoadFunction(alsa_handle,alsa_functions[i].name);*/ *alsa_functions[i].func = SDL_LoadFunction(alsa_handle,alsa_functions[i].name);
#if HAVE_DLVSYM
*alsa_functions[i].func = dlvsym(alsa_handle,alsa_functions[i].name,"ALSA_0.9");
if (!*alsa_functions[i].func)
#endif
*alsa_functions[i].func = dlsym(alsa_handle,alsa_functions[i].name);
if (!*alsa_functions[i].func) { if (!*alsa_functions[i].func) {
retval = -1; retval = -1;
UnloadALSALibrary(); UnloadALSALibrary();
...@@ -374,6 +366,9 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec) ...@@ -374,6 +366,9 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec)
snd_pcm_sw_params_t *swparams; snd_pcm_sw_params_t *swparams;
snd_pcm_format_t format; snd_pcm_format_t format;
snd_pcm_uframes_t frames; snd_pcm_uframes_t frames;
unsigned int rate;
unsigned int periods;
unsigned int channels;
Uint16 test_format; Uint16 test_format;
/* Open the audio device */ /* Open the audio device */
...@@ -445,30 +440,41 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec) ...@@ -445,30 +440,41 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec)
/* Set the number of channels */ /* Set the number of channels */
status = SDL_NAME(snd_pcm_hw_params_set_channels)(pcm_handle, hwparams, spec->channels); status = SDL_NAME(snd_pcm_hw_params_set_channels)(pcm_handle, hwparams, spec->channels);
channels = spec->channels;
if ( status < 0 ) { if ( status < 0 ) {
status = SDL_NAME(snd_pcm_hw_params_get_channels)(hwparams); status = SDL_NAME(snd_pcm_hw_params_get_channels)(hwparams, &channels);
if ( (status <= 0) || (status > 2) ) { if ( status < 0 ) {
SDL_SetError("Couldn't set audio channels"); SDL_SetError("Couldn't set audio channels");
ALSA_CloseAudio(this); ALSA_CloseAudio(this);
return(-1); return(-1);
} }
spec->channels = status; spec->channels = channels;
} }
/* Set the audio rate */ /* Set the audio rate */
status = SDL_NAME(snd_pcm_hw_params_set_rate_near)(pcm_handle, hwparams, spec->freq, NULL); rate = spec->freq;
status = SDL_NAME(snd_pcm_hw_params_set_rate_near)(pcm_handle, hwparams, &rate, NULL);
if ( status < 0 ) { if ( status < 0 ) {
SDL_SetError("Couldn't set audio frequency: %s", SDL_NAME(snd_strerror)(status)); SDL_SetError("Couldn't set audio frequency: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this); ALSA_CloseAudio(this);
return(-1); return(-1);
} }
spec->freq = status; spec->freq = rate;
/* Set the buffer size, in samples */ /* Set the buffer size, in samples */
frames = spec->samples; frames = spec->samples;
frames = SDL_NAME(snd_pcm_hw_params_set_period_size_near)(pcm_handle, hwparams, frames, NULL); status = SDL_NAME(snd_pcm_hw_params_set_period_size_near)(pcm_handle, hwparams, &frames, NULL);
if ( status < 0 ) {
SDL_SetError("Couldn't set audio frequency: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this);
return(-1);
}
spec->samples = frames; spec->samples = frames;
SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, 2, NULL);
periods = 2;
SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, &periods, NULL);
/* "set" the hardware with the desired parameters */ /* "set" the hardware with the desired parameters */
status = SDL_NAME(snd_pcm_hw_params)(pcm_handle, hwparams); status = SDL_NAME(snd_pcm_hw_params)(pcm_handle, hwparams);
......
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#ifndef _ALSA_PCM_audio_h #ifndef _ALSA_PCM_audio_h
#define _ALSA_PCM_audio_h #define _ALSA_PCM_audio_h
#define ALSA_PCM_OLD_HW_PARAMS_API
#define ALSA_PCM_OLD_SW_PARAMS_API
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment