Corrected misuse of snd_pcm_writei() in ALSA driver. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Mon, 12 Oct 2009 08:06:40 +0000
branchSDL-1.2
changeset 432033d306630296
parent 4319 edefeb52a627
child 4321 c9a1de1eda57
Corrected misuse of snd_pcm_writei() in ALSA driver.

Hopefully fixes Bugzilla #650.
src/audio/alsa/SDL_alsa_audio.c
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Sat Oct 10 15:10:06 2009 +0000
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Mon Oct 12 08:06:40 2009 +0000
     1.3 @@ -304,17 +304,18 @@
     1.4  
     1.5  static void ALSA_PlayAudio(_THIS)
     1.6  {
     1.7 -	int           status;
     1.8 -	int           sample_len;
     1.9 -	signed short *sample_buf;
    1.10 +	int status;
    1.11 +	snd_pcm_uframes_t frames_left;
    1.12 +	const Uint8 *sample_buf = (const Uint8 *) mixbuf;
    1.13 +	const int frame_size = ( ((int) this->spec.channels) *
    1.14 +	                         ((int) (this->spec.format & 0xFF)) );
    1.15  
    1.16  	swizzle_alsa_channels(this);
    1.17  
    1.18 -	sample_len = this->spec.samples;
    1.19 -	sample_buf = (signed short *)mixbuf;
    1.20 +	frames_left = ((snd_pcm_uframes_t) this->spec.samples) / this->spec.channels;
    1.21  
    1.22 -	while ( sample_len > 0 ) {
    1.23 -		status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, sample_len);
    1.24 +	while ( frames_left > 0 ) {
    1.25 +		status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, frames_left);
    1.26  		if ( status < 0 ) {
    1.27  			if ( status == -EAGAIN ) {
    1.28  				SDL_Delay(1);
    1.29 @@ -336,8 +337,8 @@
    1.30  			}
    1.31  			continue;
    1.32  		}
    1.33 -		sample_buf += status * this->spec.channels;
    1.34 -		sample_len -= status;
    1.35 +		sample_buf += status * frame_size;
    1.36 +		frames_left -= status;
    1.37  	}
    1.38  }
    1.39