shithub: sox

Download patch

ref: 03a694872ae017ecf5aaa62592626a7545197937
parent: 6b73c041d6ff5835ddbda5b65670426255f4c690
author: cbagwell <cbagwell>
date: Tue Aug 22 11:19:42 EDT 2000

Varous overflow bugfixes by Joseph Ruff.

--- a/README
+++ b/README
@@ -185,6 +185,9 @@
 		Chris Bagwell		cbagwell@sprynet.com
 			OSS and Sun players, bugfixes, ADPCM support,
 			patch collection and maintance.
+		Matthias Nutt
+			Multiple effects from command line.
+
 		(your name could be here, too)
 		(I've probably lost a few, and several people fixed
 		 the same bugs.)
--- a/libst.c
+++ b/libst.c
@@ -57,6 +57,7 @@
 
     /* Get the sample into sign-magnitude. */
     sign = (sample >> 8) & 0x80;		/* set aside the sign */
+    if (sample < -uCLIP) sample = -uCLIP; /* prevent wrap-around in next step */
     if ( sign != 0 ) sample = -sample;		/* get magnitude */
     if ( sample > uCLIP ) sample = uCLIP;		/* clip the magnitude */
 
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -31,6 +31,7 @@
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <limits.h>
 #include "st.h"
 
 #define Float float/*double*/
@@ -522,6 +523,17 @@
 
 }
 
+static Float FLONG_MAX = LONG_MAX;
+
+static LONG clipfloat(Float sample)
+{
+	if (sample > FLONG_MAX)
+	return LONG_MAX;
+	if (sample < -FLONG_MAX)
+	return -LONG_MAX;
+	return sample;
+}
+
 int st_poly_flow(eff_t effp, LONG *ibuf, LONG *obuf, LONG *isamp, LONG *osamp)
 {
   poly_t rate = (poly_t) effp->priv;
@@ -598,7 +610,7 @@
 		if (out_size > oskip + *osamp) out_size = oskip + *osamp;
 
     for(q=obuf, k=oskip; k < out_size; k++)
-      *q++ = out_buf[k] * ISCALE; /* should clip-limit */
+      *q++ = clipfloat(out_buf[k] * ISCALE); /* should clip-limit */
 
 		*osamp = q-obuf;
 		rate->inpipe -= *osamp;
--- a/src/raw.c
+++ b/src/raw.c
@@ -346,31 +346,31 @@
 #	ifdef MAXWSPEED
 			q -= 4;
 			while (p<q) {
-				p[0] = st_swapw((buf[0] + 0x8000) >> 16); /* round for 16 bit */
-				p[1] = st_swapw((buf[1] + 0x8000) >> 16); /* round for 16 bit */
-				p[2] = st_swapw((buf[2] + 0x8000) >> 16); /* round for 16 bit */
-				p[3] = st_swapw((buf[3] + 0x8000) >> 16); /* round for 16 bit */
+				p[0] = st_swapw(buf[0] >> 16); 
+				p[1] = st_swapw(buf[1] >> 16); 
+				p[2] = st_swapw(buf[2] >> 16); 
+				p[3] = st_swapw(buf[3] >> 16); 
 				p += 4; buf += 4;
 			}
 			q += 4;
 #	endif
 			while (p<q) {
-				*p++ = st_swapw(((*buf++) + 0x8000) >> 16); /* round for 16 bit */
+				*p++ = st_swapw((*buf++) >> 16); 
 			}
 		} else {
 #	ifdef MAXWSPEED
 			q -= 4;
 			while (p<q) {
-				p[0] = (buf[0] + 0x8000) >> 16; /* round for 16 bit */
-				p[1] = (buf[1] + 0x8000) >> 16; /* round for 16 bit */
-				p[2] = (buf[2] + 0x8000) >> 16; /* round for 16 bit */
-				p[3] = (buf[3] + 0x8000) >> 16; /* round for 16 bit */
+				p[0] = buf[0] >> 16; 
+				p[1] = buf[1] >> 16; 
+				p[2] = buf[2] >> 16; 
+				p[3] = buf[3] >> 16; 
 				p += 4; buf += 4;
 			}
 			q += 4;
 #	endif
 			while (p<q) {
-				*p++ = ((*buf++) + 0x8000) >> 16; /* round for 16 bit */
+				*p++ = (*buf++) >> 16; 
 			}
 		}
 	}
@@ -412,11 +412,9 @@
 				return done;
 			case ST_ENCODING_ULAW:
 				while(done < nsamp) {
-					int datum;
+					short datum;
 					/* scale signed up to long's range */
-					datum = (int) RIGHT(*buf++, 16);
-					/* round up to 12 bits of data */
-					datum += 0x8;	/* + 0b1000 */
+					datum = (short) RIGHT(*buf++, 16);
 					datum = st_linear_to_ulaw(datum);
 					blockputc(ft, datum);
 					done++;
@@ -446,7 +444,7 @@
 					int datum;
 					unsigned short s;
 					/* scale signed up to long's range */
-					datum = *buf++ + 0x8000; /* round for 16 bit */
+					datum = *buf++; 
 					s = RIGHT(datum, 16) ^ 0x8000;
 					/* Convert to unsigned */
 					blockw(&s, sizeof(short),ft);
--- a/src/stat.c
+++ b/src/stat.c
@@ -359,7 +359,7 @@
 	}
 	/* print out the info */
 	fprintf(stderr, "Samples read:      %12lu\n", stat->read);
-	fprintf(stderr, "Length (seconds):  %12.6f\n", (double)stat->read/effp->ininfo.rate);
+	fprintf(stderr, "Length (seconds):  %12.6f\n", (double)stat->read/effp->ininfo.rate/effp->ininfo.channels);
 	if (stat->srms)
 		fprintf(stderr, "Scaled by rms:     %12.6f\n", rms);
 	else
--- a/src/wav.c
+++ b/src/wav.c
@@ -1417,7 +1417,7 @@
 		if (top>p+len) top = p+len;
 		len -= top-p; /* update residual len */
 		while (p < top)
-		   *p++ = ((*buf++) + 0x8000) >> 16;
+		   *p++ = (*buf++) >> 16;
 
 		wav->samplePtr = p;
 		if (p == wav->sampleTop)