src/audio/alsa/SDL_alsa_audio.c
branchSDL-1.2
changeset 4347 38f22ed3a433
parent 4339 819270e2f893
child 4348 b312352d8c8d
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Sat Oct 17 05:05:29 2009 +0000
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Sat Oct 17 06:55:17 2009 +0000
     1.3 @@ -43,8 +43,6 @@
     1.4  /* The tag name used by ALSA audio */
     1.5  #define DRIVER_NAME         "alsa"
     1.6  
     1.7 -/* Whether we should set the buffer size or the period size */
     1.8 -/*#define SET_PERIOD_SIZE*/
     1.9  /*#define DEBUG_PERIOD_SIZE*/
    1.10  
    1.11  /* Audio driver functions */
    1.12 @@ -377,9 +375,7 @@
    1.13  	snd_pcm_format_t     format;
    1.14  	snd_pcm_uframes_t    frames;
    1.15  	unsigned int         rate;
    1.16 -#ifdef SET_PERIOD_SIZE
    1.17  	unsigned int         periods;
    1.18 -#endif
    1.19  	unsigned int 	     channels;
    1.20  	Uint16               test_format;
    1.21  
    1.22 @@ -475,28 +471,33 @@
    1.23  	spec->freq = rate;
    1.24  
    1.25  	/* Set the buffer size, in samples */
    1.26 -#ifdef SET_PERIOD_SIZE
    1.27 -	frames = spec->samples;
    1.28 -	status = SDL_NAME(snd_pcm_hw_params_set_period_size_near)(pcm_handle, hwparams, &frames, NULL);
    1.29 -	if ( status < 0 ) {
    1.30 -		SDL_SetError("Couldn't set period size: %s", SDL_NAME(snd_strerror)(status));
    1.31 -		ALSA_CloseAudio(this);
    1.32 -		return(-1);
    1.33 -	}
    1.34 +	if (getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE")) {
    1.35 +		frames = spec->samples;
    1.36 +		status = SDL_NAME(snd_pcm_hw_params_set_period_size_near)(pcm_handle, hwparams, &frames, NULL);
    1.37 +		if ( status < 0 ) {
    1.38 +			SDL_SetError("Couldn't set period size: %s", SDL_NAME(snd_strerror)(status));
    1.39 +			ALSA_CloseAudio(this);
    1.40 +			return(-1);
    1.41 +		}
    1.42  
    1.43 -	spec->samples = frames;
    1.44 +		spec->samples = frames;
    1.45  
    1.46 -	periods = 2;
    1.47 -	status = SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, &periods, NULL);
    1.48 -	if ( status < 0 ) {
    1.49 -		SDL_SetError("Couldn't set period count: %s", SDL_NAME(snd_strerror)(status));
    1.50 -		ALSA_CloseAudio(this);
    1.51 -		return(-1);
    1.52 +		periods = 2;
    1.53 +		status = SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, &periods, NULL);
    1.54 +		if ( status < 0 ) {
    1.55 +			SDL_SetError("Couldn't set period count: %s", SDL_NAME(snd_strerror)(status));
    1.56 +			ALSA_CloseAudio(this);
    1.57 +			return(-1);
    1.58 +		}
    1.59 +	} else {
    1.60 +		frames = spec->samples * 2;
    1.61 +		status = SDL_NAME(snd_pcm_hw_params_set_buffer_size_near)(pcm_handle, hwparams, &frames);
    1.62 +		if ( status < 0 ) {
    1.63 +			SDL_SetError("Couldn't set buffer size: %s", SDL_NAME(snd_strerror)(status));
    1.64 +			ALSA_CloseAudio(this);
    1.65 +			return(-1);
    1.66 +		}
    1.67  	}
    1.68 -#else
    1.69 -	frames = spec->samples * 2;
    1.70 -	status = SDL_NAME(snd_pcm_hw_params_set_buffer_size_near)(pcm_handle, hwparams, &frames);
    1.71 -#endif
    1.72  
    1.73  	/* "set" the hardware with the desired parameters */
    1.74  	status = SDL_NAME(snd_pcm_hw_params)(pcm_handle, hwparams);