changeset 214:e27b33a6d5fe

Now attempts to wait for SDL to finish playing the end of the buffered data before closing the audio device.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 13 Jan 2002 19:50:02 +0000
parents 948b62500a54
children 9bafd3e8276e
files playsound/playsound.c
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/playsound/playsound.c	Sun Jan 13 19:48:16 2002 +0000
+++ b/playsound/playsound.c	Sun Jan 13 19:50:02 2002 +0000
@@ -240,6 +240,7 @@
     int predecode = 0;
     int use_specific_audiofmt = 0;
     int i;
+    int delay;
 
     setbuf(stdout, NULL);
     setbuf(stderr, NULL);
@@ -463,6 +464,12 @@
         } /* while */
         SDL_PauseAudio(1);
 
+	/* Sleep two buffers' worth of audio before closing, in order
+	   to allow the playback to finish. This isn't always enough;
+	   perhaps SDL needs a way to explicitly wait for device drain? */
+	delay = 2 * 1000 * sdl_desired.samples / sdl_desired.freq;
+	SDL_Delay(delay);
+
         if (sample->flags & SOUND_SAMPLEFLAG_ERROR)
         {
             fprintf(stderr, "Error in decoding sound file!\n"