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 4320 33d306630296
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
--- a/src/audio/alsa/SDL_alsa_audio.c	Sat Oct 10 15:10:06 2009 +0000
+++ b/src/audio/alsa/SDL_alsa_audio.c	Mon Oct 12 08:06:40 2009 +0000
@@ -304,17 +304,18 @@
 
 static void ALSA_PlayAudio(_THIS)
 {
-	int           status;
-	int           sample_len;
-	signed short *sample_buf;
+	int status;
+	snd_pcm_uframes_t frames_left;
+	const Uint8 *sample_buf = (const Uint8 *) mixbuf;
+	const int frame_size = ( ((int) this->spec.channels) *
+	                         ((int) (this->spec.format & 0xFF)) );
 
 	swizzle_alsa_channels(this);
 
-	sample_len = this->spec.samples;
-	sample_buf = (signed short *)mixbuf;
+	frames_left = ((snd_pcm_uframes_t) this->spec.samples) / this->spec.channels;
 
-	while ( sample_len > 0 ) {
-		status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, sample_len);
+	while ( frames_left > 0 ) {
+		status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, frames_left);
 		if ( status < 0 ) {
 			if ( status == -EAGAIN ) {
 				SDL_Delay(1);
@@ -336,8 +337,8 @@
 			}
 			continue;
 		}
-		sample_buf += status * this->spec.channels;
-		sample_len -= status;
+		sample_buf += status * frame_size;
+		frames_left -= status;
 	}
 }