shithub: sox

Download patch

ref: a540717a81d810ec03ea64d2ab7ea035f334c036
parent: 2754a7c0759a3bc32937ca397b7589a0b21eedfc
author: cbagwell <cbagwell>
date: Wed Jan 17 13:08:50 EST 2001

Fix for OSS driver to stop dropping data when under heavy loads.

--- a/Changelog
+++ b/Changelog
@@ -23,6 +23,10 @@
   o Removed broken support for non-ANSI compilers.
   o Makefile now places the correct path to SoX in the play/rec scripts
     based on configuration script values.
+  o Alexander Pevzner provided a fix for OSS driver for sound being
+    dropped under heavy CPU loads.  Moved GETBLKSIZE operation
+    until after setting up the format (SBLive! was modify the block size
+    after changing formats).
 
 sox-12.17.1
 -----------
--- a/src/oss.c
+++ b/src/oss.c
@@ -84,21 +84,7 @@
 	st_fail("Unable to reset OSS driver.  Possibly accessing an invalid file/device");
 	return(ST_EOF);
     }
-    ft->file.size = 0;
-    ioctl (fileno(ft->fp), SNDCTL_DSP_GETBLKSIZE, &ft->file.size);
-    if (ft->file.size < 4 || ft->file.size > 65536) {
-	    st_fail("Invalid audio buffer size %d", ft->file.size);
-	    return (ST_EOF);
-    }
-    ft->file.count = 0;
-    ft->file.pos = 0;
-    ft->file.eof = 0;
 
-    if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
-	st_fail("Unable to allocate input/output buffer of size %d", ft->file.size);
-	return (ST_EOF);
-    }
-
     if (ioctl(fileno(ft->fp), SNDCTL_DSP_SYNC, NULL) < 0) {
 	st_fail("Unable to sync dsp");
 	return (ST_EOF);
@@ -160,6 +146,24 @@
 		     ft->info.rate, tmp);
 	    ft->info.rate = tmp;
 	}
+    }
+
+    /* Find out block size to use last because the driver could compute
+     * its size based on specific rates/formats.
+     */
+    ft->file.size = 0;
+    ioctl (fileno(ft->fp), SNDCTL_DSP_GETBLKSIZE, &ft->file.size);
+    if (ft->file.size < 4 || ft->file.size > 65536) {
+	    st_fail("Invalid audio buffer size %d", ft->file.size);
+	    return (ST_EOF);
+    }
+    ft->file.count = 0;
+    ft->file.pos = 0;
+    ft->file.eof = 0;
+
+    if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
+	st_fail("Unable to allocate input/output buffer of size %d", ft->file.size);
+	return (ST_EOF);
     }
 
     /* Change to non-buffered I/O */