diff libao2/ao_sun.c @ 23334:f665e123e6f9

Implement flushing of audio data. Fixes bug #754. Based on patch by Sergey Svishchev (svs ropnet ru).
author reimar
date Sun, 20 May 2007 12:05:16 +0000
parents 0471ad67050e
children 69696caa0b1b
line wrap: on
line diff
--- a/libao2/ao_sun.c	Sun May 20 11:36:50 2007 +0000
+++ b/libao2/ao_sun.c	Sun May 20 12:05:16 2007 +0000
@@ -65,6 +65,13 @@
 } enable_sample_timing;
 
 
+static void flush_audio(int fd) {
+#ifdef AUDIO_FLUSH
+  ioctl(fd, AUDIO_FLUSH, 0);
+#elif defined(__svr4__)
+  ioctl(fd, I_FLUSH, FLUSHW);
+#endif
+}
 
 // convert an OSS audio format specification into a sun audio encoding
 static int af2sunfmt(int format)
@@ -203,12 +210,9 @@
 error:
     if (silence != NULL) free(silence);
     if (fd >= 0) {
-#ifdef	__svr4__
 	// remove the 0 bytes from the above measurement from the
 	// audio driver's STREAMS queue
-	ioctl(fd, I_FLUSH, FLUSHW);
-#endif
-	//ioctl(fd, AUDIO_DRAIN, 0);
+        flush_audio(fd);
 	close(fd);
     }
 
@@ -576,11 +580,9 @@
 
 // close audio device
 static void uninit(int immed){
-#ifdef	__svr4__
     // throw away buffered data in the audio driver's STREAMS queue
     if (immed)
-	ioctl(audio_fd, I_FLUSH, FLUSHW);
-#endif
+	flush_audio(audio_fd);
     close(audio_fd);
 }