Commit 86dfb899 authored by Sam Lantinga's avatar Sam Lantinga

Option to fix bug #851

For some people setting the period size works better (and is what SDL 1.2.13 did), but for most people it's the same or worse.  You can use an environment variable to pick which one you want.

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%404099
parent 28207014
...@@ -43,8 +43,6 @@ ...@@ -43,8 +43,6 @@
/* The tag name used by ALSA audio */ /* The tag name used by ALSA audio */
#define DRIVER_NAME "alsa" #define DRIVER_NAME "alsa"
/* Whether we should set the buffer size or the period size */
/*#define SET_PERIOD_SIZE*/
/*#define DEBUG_PERIOD_SIZE*/ /*#define DEBUG_PERIOD_SIZE*/
/* Audio driver functions */ /* Audio driver functions */
...@@ -377,9 +375,7 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec) ...@@ -377,9 +375,7 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec)
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 rate;
#ifdef SET_PERIOD_SIZE
unsigned int periods; unsigned int periods;
#endif
unsigned int channels; unsigned int channels;
Uint16 test_format; Uint16 test_format;
...@@ -475,28 +471,33 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec) ...@@ -475,28 +471,33 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec)
spec->freq = rate; spec->freq = rate;
/* Set the buffer size, in samples */ /* Set the buffer size, in samples */
#ifdef SET_PERIOD_SIZE if (getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE")) {
frames = spec->samples; frames = spec->samples;
status = 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 ) { if ( status < 0 ) {
SDL_SetError("Couldn't set period size: %s", SDL_NAME(snd_strerror)(status)); SDL_SetError("Couldn't set period size: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this); ALSA_CloseAudio(this);
return(-1); return(-1);
} }
spec->samples = frames; spec->samples = frames;
periods = 2; periods = 2;
status = SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, &periods, NULL); status = SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, &periods, NULL);
if ( status < 0 ) { if ( status < 0 ) {
SDL_SetError("Couldn't set period count: %s", SDL_NAME(snd_strerror)(status)); SDL_SetError("Couldn't set period count: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this); ALSA_CloseAudio(this);
return(-1); return(-1);
}
} else {
frames = spec->samples * 2;
status = SDL_NAME(snd_pcm_hw_params_set_buffer_size_near)(pcm_handle, hwparams, &frames);
if ( status < 0 ) {
SDL_SetError("Couldn't set buffer size: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this);
return(-1);
}
} }
#else
frames = spec->samples * 2;
status = SDL_NAME(snd_pcm_hw_params_set_buffer_size_near)(pcm_handle, hwparams, &frames);
#endif
/* "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);
......
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