shithub: sox

Download patch

ref: 26fb5f3d5e1bd3771f90a4dfaf2aac80b7c1390b
parent: de3efbf70d870d9b34d126d3c437eeb7f75db33f
author: cbagwell <cbagwell>
date: Mon Oct 18 11:17:21 EDT 1999

Updating aiff support again.  When we started ignoring empty INST
chunks, we should have also ignored empty INST blocks.

Finally, the Solaris audio drivers will actually ask the hardware
what it is so that it can force the output to a known working format.

--- a/Changelog
+++ b/Changelog
@@ -14,6 +14,9 @@
     it from deleting files when a user mistakenly types "sox *.wav".
   o Added new compander effect from Nick Bailey.  Nice general purpose
     filter.
+  o Under Solaris, SoX now checks hardware ability to play stereo/PCM
+    and forces output data to match.  Sorry, no SunOS support.  I don't
+    have access to one any more.
 
 sox-12.16
 ---------
--- a/TODO
+++ b/TODO
@@ -24,6 +24,10 @@
   o Internally sox can handle multiple effects on a given sound file.
     Add support for this from the command line.
 
+  o Endian checks are probably invalid on 64-bit machines.  Need to use
+    something a more constant size the "int".  Probably should make it
+    at least a util function/macro that can be overriden at compile time.
+
   o Enhance sox for better interactive support.  This includes updating
     effect parameters in real time and ablity to start/stop/scan
     file handlers in real time.
--- a/play
+++ b/play
@@ -159,12 +159,13 @@
 arch=`uname -s`
 case $arch in
   SunOS)
-    case `arch -k` in
-	# Use below for older Sun audio hardware
-	sun4|sun4c|sun4d)
-	    arch_defines="-t sunau -U -c 1"
+    case `uname -r` in
+        # Solaris software can auto-detect hardware capabilities.
+        5.*)
+	    arch_defines="-t sunau"
 	    ;;
-	# Use below for newer Sun audio hardware that supports stereo linear
+	# For SunOS default to signed words.  Some hardware can only play u-law and would need
+	# to be changed here.
 	*)
 	    arch_defines="-t sunau -w -s"
 	    ;;
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -150,6 +150,16 @@
 			/* MARK chunk */
 			chunksize = rlong(ft);
 			nmarks = rshort(ft);
+
+			/* Some programs like to always have a MARK chunk
+			 * but will set number of marks to 0 and force
+			 * software to detect and ignore it.
+			 */
+			if (nmarks == 0)
+			    foundmark = 0;
+			else
+			    foundmark = 1;
+
 			chunksize -= 2;
 			for(i = 0; i < nmarks; i++) {
 				int len;
@@ -172,7 +182,6 @@
 			/* for MARK field */
 			while(chunksize-- > 0)
 				getc(ft->fp);
-			foundmark = 1;
 		}
 		else if (strncmp(buf, "INST", 4) == 0) {
 			/* INST chunk */
--- a/src/sunaudio.c
+++ b/src/sunaudio.c
@@ -45,6 +45,10 @@
 {
     int samplesize, encoding;
     audio_info_t audio_if;
+#ifdef __SVR4
+    audio_device_t audio_dev;
+#endif
+    char simple_hw=0;
 
     /* Hard code for now. */
     ft->file.count = 0;
@@ -59,6 +63,37 @@
     if (ft->info.size == -1) ft->info.size = BYTE;
     if (ft->info.style == -1) ft->info.style = ULAW;
 
+#ifdef __SVR4
+    /* Read in old values, change to what we need and then send back */
+    if (ioctl(fileno(ft->fp), AUDIO_GETDEV, &audio_dev) < 0) {
+	fail("Unable to get device information.");
+    }
+    report("Hardware detected:  %s\n",audio_dev.name);
+    if (strcmp("SUNW,am79c30",audio_dev.name) == 0)
+    {
+	simple_hw = 1;
+    }
+#endif
+
+    // If simple hardware detected in force data to ulaw.
+    if (simple_hw)
+    {
+	if (ft->info.size == BYTE)
+	{
+	    if (ft->info.style != ULAW && ft->info.style != ALAW)
+	    {
+		report("Warning: Detected simple hardware.  Forcing output to ULAW");
+		ft->info.style = ULAW;
+	    }
+	}
+	else if (ft->info.size == WORD)
+	{
+	    report("Warning: Detected simple hardware.  Forcing output to ULAW");
+	    ft->info.size = BYTE;
+	    ft->info.style = ULAW;
+	}
+    }
+   
     if (ft->info.size == BYTE) {
 	samplesize = 8;
 	if (ft->info.style != ULAW &&
@@ -66,7 +101,11 @@
 	    ft->info.style != SIGN2) {
 	    fail("Sun Audio driver only supports ULAW, ALAW, and Signed Linear for bytes.");
 	}
-
+	if ((ft->info.style == ULAW || ft->info.style == ALAW) && ft->info.channels == 2)
+	{
+	    report("Warning: only support mono for ULAW and ALAW data.  Forcing to mono");
+	    ft->info.channels = 2;
+	}
     }
     else if (ft->info.size == WORD) {
 	samplesize = 16;
@@ -126,6 +165,10 @@
 {
     int samplesize, encoding;
     audio_info_t audio_if;
+#ifdef __SVR4
+    audio_device_t audio_dev;
+#endif
+    char simple_hw=0;
 
     /* Hard code for now. */
     ft->file.count = 0;
@@ -135,7 +178,37 @@
     if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
 	fail("unable to allocate output buffer of size %d", ft->file.size);
     }
-    
+
+#ifdef __SVR4
+    /* Read in old values, change to what we need and then send back */
+    if (ioctl(fileno(ft->fp), AUDIO_GETDEV, &audio_dev) < 0) {
+	fail("Unable to get device information.");
+    }
+    report("Hardware detected:  %s\n",audio_dev.name);
+    if (strcmp("SUNW,am79c30",audio_dev.name) == 0)
+    {
+	simple_hw = 1;
+    }
+#endif
+
+    if (simple_hw)
+    {
+	if (ft->info.size == BYTE)
+	{
+	    if (ft->info.style != ULAW && ft->info.style != ALAW)
+	    {
+		report("Warning: Detected simple hardware.  Forcing output to ULAW");
+		ft->info.style = ULAW;
+	    }
+	}
+	else if (ft->info.size == WORD)
+	{
+	    report("Warning: Detected simple hardware.  Forcing output to ULAW");
+	    ft->info.size = BYTE;
+	    ft->info.style = ULAW;
+	}
+    }
+ 
     if (ft->info.rate == 0.0) ft->info.rate = 8000;
     if (ft->info.size == -1) ft->info.size = BYTE;
     if (ft->info.style == -1) ft->info.style = ULAW;
@@ -148,6 +221,11 @@
 	    report("Sun Audio driver only supports ULAW, ALAW, and Signed Linear for bytes.");
 	    report("Forcing to ULAW");
 	    ft->info.style = ULAW;
+	}
+	if ((ft->info.style == ULAW || ft->info.style == ALAW) && ft->info.channels == 2)
+	{
+	    report("Warning: only support mono for ULAW and ALAW data.  Forcing to mono");
+	    ft->info.channels = 2;
 	}
 
     }