shithub: sox

Download patch

ref: edf59c1fcf676f545e7ef2670a04b206fb981e97
parent: 58cdd4b33f5c567cfe61eda9ba735cda85bfa62c
author: cbagwell <cbagwell>
date: Mon Aug 6 13:14:25 EDT 2001

Commiting various bugfixes.

--- a/TODO
+++ b/TODO
@@ -9,6 +9,9 @@
     Also, add support to all file handlers to handle 32-bit and float
     data types since raw functions can handle them.
 
+  o Change read and write functions from LONG to st_size_t to get
+    the extra length support.  Make it ULONG type.
+
   o Change "float" from a data type to an encoding method.  This will
     effect command line usage but more accurately describes floats.
 
--- a/src/dcshift.c
+++ b/src/dcshift.c
@@ -30,10 +30,12 @@
 #define ONE	  ((DCSHIFT_FLOAT)(1.0e0))
 #define TWENTY	  ((DCSHIFT_FLOAT)(20.0e0))
 
-#define DCSHIFT_USAGE \
-    "Usage: dcshift shift [ limitergain ]" \
-    " The peak limiter has a gain much less than 1.0 (ie 0.05 or 0.02) which is only" \
-    " used on peaks to prevent clipping. (default is no limiter)"
+#define DCSHIFT_USAGE "Usage: dcshift shift [ limitergain ]"
+// The following is dieing on a solaris gcc 2.8.1 compiler!?!!
+#if 0
+#define DCSHIFT_USAGE2 " The peak limiter has a gain much less than 1.0 (ie 0.05 or 0.02) which is only"
+#define DCSHIFT_USAGE3 " used on peaks to prevent clipping. (default is no limiter)"
+#endif
 
 typedef struct {
     DCSHIFT_FLOAT dcshift; /* DC shift. */
--- a/src/sox.c
+++ b/src/sox.c
@@ -605,8 +605,6 @@
     int e, havedata, flowstatus = 0;
 
     do {
-      ULONG w;
-      
       /* run entire chain BACKWARDS: pull, don't push.*/
       /* this is because buffering system isn't a nice queueing system */
       for(e = neffects - 1; e > 0; e--) 
@@ -619,7 +617,7 @@
       /* If outputing and output data was generated then write it */
       if (writing&&(efftab[neffects-1].olen>efftab[neffects-1].odone)) 
       {
-          w = (* outformat->h->write)(outformat, 
+          (* outformat->h->write)(outformat, 
                                      efftab[neffects-1].obuf, 
                                      (LONG) efftab[neffects-1].olen);
           efftab[neffects-1].odone = efftab[neffects-1].olen;
--- a/src/wav.c
+++ b/src/wav.c
@@ -11,7 +11,7 @@
  * November  23, 1999 - Stan Brooks (stabro@megsinet.com)
  *   Merged in gsm support patches from Stuart Daines...
  *   Since we had simultaneously made similar changes in
- *   wavwriteheader() and wavstartread(), this was some
+ *   wavwritehdr() and wavstartread(), this was some
  *   work.  Hopefully the result is cleaner than either
  *   version, and nothing broke.
  *
@@ -1120,6 +1120,18 @@
 
 	if (ST_IS_BIGENDIAN) ft->swap = ft->swap ? 0 : 1;
 
+	/* FIXME: This reserves memory but things could fail
+	 * later on and not release this memory.
+	 */
+	if (ft->info.encoding != ST_ENCODING_ADPCM &&
+	    ft->info.encoding != ST_ENCODING_IMA_ADPCM &&
+	    ft->info.encoding != ST_ENCODING_GSM)
+	{
+		rc = st_rawstartwrite(ft);
+		if (rc)
+		    return rc;
+	}
+
 	wav->numSamples = 0;
 	wav->dataLength = 0;
 	if (!ft->seekable)
@@ -1127,6 +1139,7 @@
 	rc = wavwritehdr(ft, 0);  /* also calculates various wav->* info */
 	if (rc != 0)
 	    return rc;
+
 	wav->packet = NULL;
 	wav->samples = NULL;
 	wav->iCoefs = NULL;
@@ -1253,8 +1266,6 @@
 	ULONG bytespersample; 		/* (uncompressed) bytes per sample (per channel) */
 	ULONG blocksWritten = 0;
 
-	int rc;
-
 	wSamplesPerSecond = ft->info.rate;
 	wChannels = ft->info.channels;
 
@@ -1312,15 +1323,6 @@
 			break;
 	}
 
-	if (ft->info.encoding != ST_ENCODING_ADPCM &&
-	    ft->info.encoding != ST_ENCODING_IMA_ADPCM &&
-	    ft->info.encoding != ST_ENCODING_GSM)
-	{
-		rc = st_rawstartwrite(ft);
-		if (rc)
-		    return rc;
-	}
-
 	wSamplesPerBlock = 1;	/* common default for PCM data */
 
 	switch (ft->info.encoding)
@@ -1502,7 +1504,7 @@
 LONG *buf, len;
 {
 	wav_t	wav = (wav_t) ft->priv;
-	LONG	save_len = len;
+	LONG	total_len = len;
 
 	ft->st_errno = ST_SUCCESS;
 
@@ -1524,18 +1526,20 @@
 		    xxxAdpcmWriteBlock(ft);
 
 	    }
-	    return save_len - len;
+	    return total_len - len;
 	    break;
 
 #ifdef HAVE_LIBGSM
 	case WAVE_FORMAT_GSM610:
+	    len = wavgsmwrite(ft, buf, len);
 	    wav->numSamples += len;
-	    return wavgsmwrite(ft, buf, len);
+	    return len;
 	    break;
 #endif
 	default:
+	    len = st_rawwrite(ft, buf, len);
 	    wav->numSamples += len; /* must later be divided by wChannels */
-	    return st_rawwrite(ft, buf, len);
+	    return len;
 	}
 }
 
@@ -1559,8 +1563,6 @@
 	    wavgsmstopwrite(ft);
 	    break;
 #endif
-	default:
-	    st_rawstopwrite(ft);
 	}
 	if (wav->packet) free(wav->packet);
  	if (wav->samples) free(wav->samples);
@@ -1582,6 +1584,14 @@
 		return ST_EOF;
 	}
 	wavwritehdr(ft, 1);
+
+	if (wav->formatTag != WAVE_FORMAT_IMA_ADPCM &&
+	    wav->formatTag != WAVE_FORMAT_ADPCM &&
+	    wav->formatTag != WAVE_FORMAT_GSM610)
+	{
+	    st_rawstopwrite(ft);
+	}
+
 	return (ST_SUCCESS);
 }