diff src/audio/dsp/SDL_dspaudio.c @ 93:fc774f445e10

Applied Hannu's fix and switched to blocking writes .. seems to work?
author Sam Lantinga <slouken@lokigames.com>
date Sat, 07 Jul 2001 23:27:29 +0000
parents d3bc792e136d
children ae6e6b73333f
line wrap: on
line diff
--- a/src/audio/dsp/SDL_dspaudio.c	Sat Jul 07 23:12:42 2001 +0000
+++ b/src/audio/dsp/SDL_dspaudio.c	Sat Jul 07 23:27:29 2001 +0000
@@ -51,7 +51,7 @@
 #define DSP_DRIVER_NAME         "dsp"
 
 /* Open the audio device for playback, and don't block if busy */
-/*#define USE_BLOCKING_WRITES*/
+#define USE_BLOCKING_WRITES
 #ifdef USE_BLOCKING_WRITES
 #define OPEN_FLAGS	O_WRONLY
 #else
@@ -128,9 +128,6 @@
 /* This function waits until it is possible to write a full sound buffer */
 static void DSP_WaitAudio(_THIS)
 {
-#ifndef USE_BLOCKING_WRITES /* Not necessary because of blocking writes */
-	fd_set fdset;
-
 	/* Check to see if the thread-parent process is still alive */
 	{ static int cnt = 0;
 		/* Note that this only works with thread implementations 
@@ -143,6 +140,7 @@
 		}
 	}
 
+#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
 	/* See if we need to use timed audio synchronization */
 	if ( frame_ticks ) {
 		/* Use timer for general audio synchronization */
@@ -154,7 +152,9 @@
 		}
 	} else {
 		/* Use select() for audio synchronization */
+		fd_set fdset;
 		struct timeval timeout;
+
 		FD_ZERO(&fdset);
 		FD_SET(audio_fd, &fdset);
 		timeout.tv_sec = 10;
@@ -186,16 +186,24 @@
 
 static void DSP_PlayAudio(_THIS)
 {
-	int written;
+	int written, p=0;
 
 	/* Write the audio data, checking for EAGAIN on broken audio drivers */
 	do {
-		written = write(audio_fd, mixbuf, mixlen);
-		if ( (written < 0) && ((errno == 0) || (errno == EAGAIN)) ) {
+		written = write(audio_fd, &mixbuf[p], mixlen-p);
+		if (written>0)
+		   p += written;
+		if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR)
+		{
+		   /* Non recoverable error has occurred. It should be reported!!! */
+		   perror("audio");
+		   break;
+		}
+
+		if ( p < written || ((written < 0) && ((errno == 0) || (errno == EAGAIN))) ) {
 			SDL_Delay(1);	/* Let a little CPU time go by */
 		}
-	} while ( (written < 0) && 
-	          ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)) );
+	} while ( p < written );
 
 	/* If timer synchronization is enabled, set the next write frame */
 	if ( frame_ticks ) {