src/audio/dsp/SDL_dspaudio.c
changeset 93 fc774f445e10
parent 35 d3bc792e136d
child 94 ae6e6b73333f
     1.1 --- a/src/audio/dsp/SDL_dspaudio.c	Sat Jul 07 23:12:42 2001 +0000
     1.2 +++ b/src/audio/dsp/SDL_dspaudio.c	Sat Jul 07 23:27:29 2001 +0000
     1.3 @@ -51,7 +51,7 @@
     1.4  #define DSP_DRIVER_NAME         "dsp"
     1.5  
     1.6  /* Open the audio device for playback, and don't block if busy */
     1.7 -/*#define USE_BLOCKING_WRITES*/
     1.8 +#define USE_BLOCKING_WRITES
     1.9  #ifdef USE_BLOCKING_WRITES
    1.10  #define OPEN_FLAGS	O_WRONLY
    1.11  #else
    1.12 @@ -128,9 +128,6 @@
    1.13  /* This function waits until it is possible to write a full sound buffer */
    1.14  static void DSP_WaitAudio(_THIS)
    1.15  {
    1.16 -#ifndef USE_BLOCKING_WRITES /* Not necessary because of blocking writes */
    1.17 -	fd_set fdset;
    1.18 -
    1.19  	/* Check to see if the thread-parent process is still alive */
    1.20  	{ static int cnt = 0;
    1.21  		/* Note that this only works with thread implementations 
    1.22 @@ -143,6 +140,7 @@
    1.23  		}
    1.24  	}
    1.25  
    1.26 +#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
    1.27  	/* See if we need to use timed audio synchronization */
    1.28  	if ( frame_ticks ) {
    1.29  		/* Use timer for general audio synchronization */
    1.30 @@ -154,7 +152,9 @@
    1.31  		}
    1.32  	} else {
    1.33  		/* Use select() for audio synchronization */
    1.34 +		fd_set fdset;
    1.35  		struct timeval timeout;
    1.36 +
    1.37  		FD_ZERO(&fdset);
    1.38  		FD_SET(audio_fd, &fdset);
    1.39  		timeout.tv_sec = 10;
    1.40 @@ -186,16 +186,24 @@
    1.41  
    1.42  static void DSP_PlayAudio(_THIS)
    1.43  {
    1.44 -	int written;
    1.45 +	int written, p=0;
    1.46  
    1.47  	/* Write the audio data, checking for EAGAIN on broken audio drivers */
    1.48  	do {
    1.49 -		written = write(audio_fd, mixbuf, mixlen);
    1.50 -		if ( (written < 0) && ((errno == 0) || (errno == EAGAIN)) ) {
    1.51 +		written = write(audio_fd, &mixbuf[p], mixlen-p);
    1.52 +		if (written>0)
    1.53 +		   p += written;
    1.54 +		if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR)
    1.55 +		{
    1.56 +		   /* Non recoverable error has occurred. It should be reported!!! */
    1.57 +		   perror("audio");
    1.58 +		   break;
    1.59 +		}
    1.60 +
    1.61 +		if ( p < written || ((written < 0) && ((errno == 0) || (errno == EAGAIN))) ) {
    1.62  			SDL_Delay(1);	/* Let a little CPU time go by */
    1.63  		}
    1.64 -	} while ( (written < 0) && 
    1.65 -	          ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)) );
    1.66 +	} while ( p < written );
    1.67  
    1.68  	/* If timer synchronization is enabled, set the next write frame */
    1.69  	if ( frame_ticks ) {