shithub: sox

Download patch

ref: a83636279984823b1d7e04cff5bfaa7588655f66
parent: e8893f3feff1f7b93f848f42a82a2d52fea10e0b
author: cbagwell <cbagwell>
date: Fri Jul 30 16:28:19 EDT 2004

Security fix to wav parsing and prototype fix in resample.

--- a/Changelog
+++ b/Changelog
@@ -20,6 +20,10 @@
     to play WAV and AIFF files that have MP3 data in them until
     those handlers support it directly.  To play those, force
     sox to use the mp3 handler with the "-t mp3" option.
+  o Added patch from Ulf Harnhammar to wav handler to prevent
+    buffer overflows.
+  o Added patch from Redhat to allow resample to work on certain 64-bit
+    machines.
 
 sox-12.17.4
 -----------
--- a/src/resample.c
+++ b/src/resample.c
@@ -93,18 +93,18 @@
 } *resample_t;
 
 static void LpFilter(double c[],
-		     long N,
-		     double frq,
-		     double Beta,
-		     long Num);
+                     long N,
+                     double frq,
+                     double Beta,
+                     long Num);
 
 /* makeFilter is used by filter.c */
 int makeFilter(Float Imp[],
-	       long Nwing,
-	       double Froll,
-	       double Beta,
-	       long Num,
-	       int Normalize);
+               long Nwing,
+               double Froll,
+               double Beta,
+               long Num,
+               int Normalize);
 
 static long SrcUD(resample_t r, long Nx);
 static long SrcEX(resample_t r, long Nx);
@@ -115,57 +115,57 @@
  */
 int st_resample_getopts(eff_t effp, int n, char **argv) 
 {
-	resample_t r = (resample_t) effp->priv;
+        resample_t r = (resample_t) effp->priv;
 
-	/* These defaults are conservative with respect to aliasing. */
-	r->rolloff = 0.80;
-	r->beta = 16; /* anything <=2 means Nutall window */
-	r->quadr = 0;
-	r->Nmult = 45;
+        /* These defaults are conservative with respect to aliasing. */
+        r->rolloff = 0.80;
+        r->beta = 16; /* anything <=2 means Nutall window */
+        r->quadr = 0;
+        r->Nmult = 45;
 
-	/* This used to fail, but with sox-12.15 it works. AW */
-	if ((n >= 1)) {
-		if (!strcmp(argv[0], "-qs")) {
-			r->quadr = 1;
-			n--; argv++;
-		}
-		else if (!strcmp(argv[0], "-q")) {
-			r->rolloff = 0.875;
-			r->quadr = 1;
-			r->Nmult = 75;
-			n--; argv++;
-		}
-		else if (!strcmp(argv[0], "-ql")) {
-			r->rolloff = 0.94;
-			r->quadr = 1;
-			r->Nmult = 149;
-			n--; argv++;
-		}
-	}
+        /* This used to fail, but with sox-12.15 it works. AW */
+        if ((n >= 1)) {
+                if (!strcmp(argv[0], "-qs")) {
+                        r->quadr = 1;
+                        n--; argv++;
+                }
+                else if (!strcmp(argv[0], "-q")) {
+                        r->rolloff = 0.875;
+                        r->quadr = 1;
+                        r->Nmult = 75;
+                        n--; argv++;
+                }
+                else if (!strcmp(argv[0], "-ql")) {
+                        r->rolloff = 0.94;
+                        r->quadr = 1;
+                        r->Nmult = 149;
+                        n--; argv++;
+                }
+        }
 
-	if ((n >= 1) && (sscanf(argv[0], "%lf", &r->rolloff) != 1))
-	{
-	  st_fail("Usage: resample [ rolloff [ beta ] ]");
-	  return (ST_EOF);
-	}
-	else if ((r->rolloff <= 0.01) || (r->rolloff >= 1.0))
-	{
-	  st_fail("resample: rolloff factor (%f) no good, should be 0.01<x<1.0", r->rolloff);
-	  return(ST_EOF);
-	}
+        if ((n >= 1) && (sscanf(argv[0], "%lf", &r->rolloff) != 1))
+        {
+          st_fail("Usage: resample [ rolloff [ beta ] ]");
+          return (ST_EOF);
+        }
+        else if ((r->rolloff <= 0.01) || (r->rolloff >= 1.0))
+        {
+          st_fail("resample: rolloff factor (%f) no good, should be 0.01<x<1.0", r->rolloff);
+          return(ST_EOF);
+        }
 
-	if ((n >= 2) && !sscanf(argv[1], "%lf", &r->beta))
-	{
-	  st_fail("Usage: resample [ rolloff [ beta ] ]");
-	  return (ST_EOF);
-	}
-	else if (r->beta <= 2.0) {
-	  r->beta = 0;
-		st_report("resample opts: Nuttall window, cutoff %f\n", r->rolloff);
-	} else {
-		st_report("resample opts: Kaiser window, cutoff %f, beta %f\n", r->rolloff, r->beta);
-	}
-	return (ST_SUCCESS);
+        if ((n >= 2) && !sscanf(argv[1], "%lf", &r->beta))
+        {
+          st_fail("Usage: resample [ rolloff [ beta ] ]");
+          return (ST_EOF);
+        }
+        else if (r->beta <= 2.0) {
+          r->beta = 0;
+                st_report("resample opts: Nuttall window, cutoff %f\n", r->rolloff);
+        } else {
+                st_report("resample opts: Kaiser window, cutoff %f, beta %f\n", r->rolloff, r->beta);
+        }
+        return (ST_SUCCESS);
 }
 
 /*
@@ -173,92 +173,92 @@
  */
 int st_resample_start(eff_t effp)
 {
-	resample_t r = (resample_t) effp->priv;
-	long Xoff, gcdrate;
-	int i;
+        resample_t r = (resample_t) effp->priv;
+        long Xoff, gcdrate;
+        int i;
 
-	if (effp->ininfo.rate == effp->outinfo.rate)
-	{
-	    st_fail("Input and Output rates must be different to use resample effect");
-	    return(ST_EOF);
-	}
-		
-	r->Factor = (double)effp->outinfo.rate / (double)effp->ininfo.rate;
-
-	gcdrate = st_gcd((long)effp->ininfo.rate, (long)effp->outinfo.rate);
-	r->a = effp->ininfo.rate / gcdrate;
-	r->b = effp->outinfo.rate / gcdrate;
+        if (effp->ininfo.rate == effp->outinfo.rate)
+        {
+            st_fail("Input and Output rates must be different to use resample effect");
+            return(ST_EOF);
+        }
+                
+        r->Factor = (double)effp->outinfo.rate / (double)effp->ininfo.rate;
 
-	if (r->a <= r->b && r->b <= NQMAX) {
-		r->quadr = -1; /* exact coeff's   */
-		r->Nq = r->b;  /* MAX(r->a,r->b);	*/
-	} else {
-		r->Nq = Nc; /* for now */
-	}
+        gcdrate = st_gcd((long)effp->ininfo.rate, (long)effp->outinfo.rate);
+        r->a = effp->ininfo.rate / gcdrate;
+        r->b = effp->outinfo.rate / gcdrate;
 
-	/* Check for illegal constants */
+        if (r->a <= r->b && r->b <= NQMAX) {
+                r->quadr = -1; /* exact coeff's   */
+                r->Nq = r->b;  /* MAX(r->a,r->b);       */
+        } else {
+                r->Nq = Nc; /* for now */
+        }
+
+        /* Check for illegal constants */
 # if 0
-	if (Lp >= 16) st_fail("Error: Lp>=16");
-	if (Nb+Nhg+NLpScl >= 32) st_fail("Error: Nb+Nhg+NLpScl>=32");
-	if (Nh+Nb > 32) st_fail("Error: Nh+Nb>32");
+        if (Lp >= 16) st_fail("Error: Lp>=16");
+        if (Nb+Nhg+NLpScl >= 32) st_fail("Error: Nb+Nhg+NLpScl>=32");
+        if (Nh+Nb > 32) st_fail("Error: Nh+Nb>32");
 # endif
 
-	/* Nwing: # of filter coeffs in right wing */
-	r->Nwing = r->Nq * (r->Nmult/2+1) + 1;
+        /* Nwing: # of filter coeffs in right wing */
+        r->Nwing = r->Nq * (r->Nmult/2+1) + 1;
 
-	r->Imp = (Float *)malloc(sizeof(Float) * (r->Nwing+2)) + 1;
-	/* need Imp[-1] and Imp[Nwing] for quadratic interpolation */
-	/* returns error # <=0, or adjusted wing-len > 0 */
-	i = makeFilter(r->Imp, r->Nwing, r->rolloff, r->beta, r->Nq, 1);
-	if (i <= 0)
-	{
-		st_fail("resample: Unable to make filter\n");
-		return (ST_EOF);
-	}
+        r->Imp = (Float *)malloc(sizeof(Float) * (r->Nwing+2)) + 1;
+        /* need Imp[-1] and Imp[Nwing] for quadratic interpolation */
+        /* returns error # <=0, or adjusted wing-len > 0 */
+        i = makeFilter(r->Imp, r->Nwing, r->rolloff, r->beta, r->Nq, 1);
+        if (i <= 0)
+        {
+                st_fail("resample: Unable to make filter\n");
+                return (ST_EOF);
+        }
 
-	/*st_report("Nmult: %ld, Nwing: %ld, Nq: %ld\n",r->Nmult,r->Nwing,r->Nq);*/
+        /*st_report("Nmult: %ld, Nwing: %ld, Nq: %ld\n",r->Nmult,r->Nwing,r->Nq);*/
 
-	if (r->quadr < 0) { /* exact coeff's method */
-		r->Xh = r->Nwing/r->b;
-	  st_report("resample: rate ratio %ld:%ld, coeff interpolation not needed\n", r->a, r->b);
-	} else {
-	  r->dhb = Np;  /* Fixed-point Filter sampling-time-increment */
-	  if (r->Factor<1.0) r->dhb = r->Factor*Np + 0.5;
-	  r->Xh = (r->Nwing<<La)/r->dhb;
-	  /* (Xh * dhb)>>La is max index into Imp[] */
-	}
+        if (r->quadr < 0) { /* exact coeff's method */
+                r->Xh = r->Nwing/r->b;
+          st_report("resample: rate ratio %ld:%ld, coeff interpolation not needed\n", r->a, r->b);
+        } else {
+          r->dhb = Np;  /* Fixed-point Filter sampling-time-increment */
+          if (r->Factor<1.0) r->dhb = r->Factor*Np + 0.5;
+          r->Xh = (r->Nwing<<La)/r->dhb;
+          /* (Xh * dhb)>>La is max index into Imp[] */
+        }
 
-	/* reach of LP filter wings + some creeping room */
-	Xoff = r->Xh + 10;
-	r->Xoff = Xoff;
+        /* reach of LP filter wings + some creeping room */
+        Xoff = r->Xh + 10;
+        r->Xoff = Xoff;
 
-	/* Current "now"-sample pointer for input to filter */
-	r->Xp = Xoff;
-	/* Position in input array to read into */
-	r->Xread = Xoff;
-	/* Current-time pointer for converter */
-	r->Time = Xoff;
-	if (r->quadr < 0) { /* exact coeff's method */
-		r->t = Xoff*r->Nq;
-	}
-	i = BUFFSIZE - 2*Xoff;
-	if (i < r->Factor + 1.0/r->Factor)      /* Check input buffer size */
-	{
-		st_fail("Factor is too small or large for BUFFSIZE");
-		return (ST_EOF);
-	}
-	
-	r->Xsize = 2*Xoff + i/(1.0+r->Factor);
-	r->Ysize = BUFFSIZE - r->Xsize;
-	/* st_report("Xsize %d, Ysize %d, Xoff %d",r->Xsize,r->Ysize,r->Xoff); */
+        /* Current "now"-sample pointer for input to filter */
+        r->Xp = Xoff;
+        /* Position in input array to read into */
+        r->Xread = Xoff;
+        /* Current-time pointer for converter */
+        r->Time = Xoff;
+        if (r->quadr < 0) { /* exact coeff's method */
+                r->t = Xoff*r->Nq;
+        }
+        i = BUFFSIZE - 2*Xoff;
+        if (i < r->Factor + 1.0/r->Factor)      /* Check input buffer size */
+        {
+                st_fail("Factor is too small or large for BUFFSIZE");
+                return (ST_EOF);
+        }
+        
+        r->Xsize = 2*Xoff + i/(1.0+r->Factor);
+        r->Ysize = BUFFSIZE - r->Xsize;
+        /* st_report("Xsize %d, Ysize %d, Xoff %d",r->Xsize,r->Ysize,r->Xoff); */
 
-	r->X = (Float *) malloc(sizeof(Float) * (BUFFSIZE));
-	r->Y = r->X + r->Xsize;
+        r->X = (Float *) malloc(sizeof(Float) * (BUFFSIZE));
+        r->Y = r->X + r->Xsize;
 
-	/* Need Xoff zeros at beginning of sample */
-	for (i=0; i<Xoff; i++)
-		r->X[i] = 0;
-	return (ST_SUCCESS);
+        /* Need Xoff zeros at beginning of sample */
+        for (i=0; i<Xoff; i++)
+                r->X[i] = 0;
+        return (ST_SUCCESS);
 }
 
 /*
@@ -268,109 +268,109 @@
 int st_resample_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
                      st_size_t *isamp, st_size_t *osamp)
 {
-	resample_t r = (resample_t) effp->priv;
-	long i, last, Nout, Nx, Nproc;
+        resample_t r = (resample_t) effp->priv;
+        long i, last, Nout, Nx, Nproc;
 
-	/* constrain amount we actually process */
-	/*fprintf(stderr,"Xp %d, Xread %d, isamp %d, ",r->Xp, r->Xread,*isamp);*/
+        /* constrain amount we actually process */
+        /*fprintf(stderr,"Xp %d, Xread %d, isamp %d, ",r->Xp, r->Xread,*isamp);*/
 
-	Nproc = r->Xsize - r->Xp;
+        Nproc = r->Xsize - r->Xp;
 
-	i = (r->Ysize < *osamp)? r->Ysize : *osamp;
-	if (Nproc * r->Factor >= i)
-	  Nproc = i / r->Factor;
+        i = (r->Ysize < *osamp)? r->Ysize : *osamp;
+        if (Nproc * r->Factor >= i)
+          Nproc = i / r->Factor;
 
-	Nx = Nproc - r->Xread; /* space for right-wing future-data */
-	if (Nx <= 0)
-	{
-		st_fail("resample: Can not handle this sample rate change. Nx not positive: %d", Nx);
-		return (ST_EOF);
-	}
-	if (Nx > *isamp)
-		Nx = *isamp;
-	/*fprintf(stderr,"Nx %d\n",Nx);*/
+        Nx = Nproc - r->Xread; /* space for right-wing future-data */
+        if (Nx <= 0)
+        {
+                st_fail("resample: Can not handle this sample rate change. Nx not positive: %d", Nx);
+                return (ST_EOF);
+        }
+        if (Nx > *isamp)
+                Nx = *isamp;
+        /*fprintf(stderr,"Nx %d\n",Nx);*/
 
-	if (ibuf == NULL) {
-		for(i = r->Xread; i < Nx + r->Xread  ; i++) 
-			r->X[i] = 0;
-	} else {
-		for(i = r->Xread; i < Nx + r->Xread  ; i++) 
-			r->X[i] = (Float)(*ibuf++)/ISCALE;
-	}
-	last = i;
-	Nproc = last - r->Xoff - r->Xp;
+        if (ibuf == NULL) {
+                for(i = r->Xread; i < Nx + r->Xread  ; i++) 
+                        r->X[i] = 0;
+        } else {
+                for(i = r->Xread; i < Nx + r->Xread  ; i++) 
+                        r->X[i] = (Float)(*ibuf++)/ISCALE;
+        }
+        last = i;
+        Nproc = last - r->Xoff - r->Xp;
 
-	if (Nproc <= 0) {
-		/* fill in starting here next time */
-		r->Xread = last;
-		/* leave *isamp alone, we consumed it */
-		*osamp = 0;
-		return (ST_SUCCESS);
-	}
-	if (r->quadr < 0) { /* exact coeff's method */
-		long creep; 
-		Nout = SrcEX(r, Nproc);
-		/*fprintf(stderr,"Nproc %d --> %d\n",Nproc,Nout);*/
-		/* Move converter Nproc samples back in time */
-		r->t -= Nproc * r->b;
-		/* Advance by number of samples processed */
-		r->Xp += Nproc;
-		/* Calc time accumulation in Time */
-		creep = r->t/r->b - r->Xoff; 
-		if (creep)
-		{
-		  r->t -= creep * r->b;  /* Remove time accumulation   */
-		  r->Xp += creep;        /* and add it to read pointer */
-		  /*fprintf(stderr,"Nproc %ld, creep %ld\n",Nproc,creep);*/
-		}
-	} else { /* approx coeff's method */
-		long creep; 
-		Nout = SrcUD(r, Nproc);
-		/*fprintf(stderr,"Nproc %d --> %d\n",Nproc,Nout);*/
-		/* Move converter Nproc samples back in time */
-		r->Time -= Nproc;
-		/* Advance by number of samples processed */
-		r->Xp += Nproc;
-		/* Calc time accumulation in Time */
-		creep = r->Time - r->Xoff; 
-		if (creep)
-		{
-		  r->Time -= creep;   /* Remove time accumulation   */
-		  r->Xp += creep;     /* and add it to read pointer */
-		  /* fprintf(stderr,"Nproc %ld, creep %ld\n",Nproc,creep); */
-		}
-	}
+        if (Nproc <= 0) {
+                /* fill in starting here next time */
+                r->Xread = last;
+                /* leave *isamp alone, we consumed it */
+                *osamp = 0;
+                return (ST_SUCCESS);
+        }
+        if (r->quadr < 0) { /* exact coeff's method */
+                long creep; 
+                Nout = SrcEX(r, Nproc);
+                /*fprintf(stderr,"Nproc %d --> %d\n",Nproc,Nout);*/
+                /* Move converter Nproc samples back in time */
+                r->t -= Nproc * r->b;
+                /* Advance by number of samples processed */
+                r->Xp += Nproc;
+                /* Calc time accumulation in Time */
+                creep = r->t/r->b - r->Xoff; 
+                if (creep)
+                {
+                  r->t -= creep * r->b;  /* Remove time accumulation   */
+                  r->Xp += creep;        /* and add it to read pointer */
+                  /*fprintf(stderr,"Nproc %ld, creep %ld\n",Nproc,creep);*/
+                }
+        } else { /* approx coeff's method */
+                long creep; 
+                Nout = SrcUD(r, Nproc);
+                /*fprintf(stderr,"Nproc %d --> %d\n",Nproc,Nout);*/
+                /* Move converter Nproc samples back in time */
+                r->Time -= Nproc;
+                /* Advance by number of samples processed */
+                r->Xp += Nproc;
+                /* Calc time accumulation in Time */
+                creep = r->Time - r->Xoff; 
+                if (creep)
+                {
+                  r->Time -= creep;   /* Remove time accumulation   */
+                  r->Xp += creep;     /* and add it to read pointer */
+                  /* fprintf(stderr,"Nproc %ld, creep %ld\n",Nproc,creep); */
+                }
+        }
 
-	{
-	long i,k;
-	/* Copy back portion of input signal that must be re-used */
-	k = r->Xp - r->Xoff;
-	/*fprintf(stderr,"k %d, last %d\n",k,last);*/
-	for (i=0; i<last - k; i++) 
-	    r->X[i] = r->X[i+k];
+        {
+        long i,k;
+        /* Copy back portion of input signal that must be re-used */
+        k = r->Xp - r->Xoff;
+        /*fprintf(stderr,"k %d, last %d\n",k,last);*/
+        for (i=0; i<last - k; i++) 
+            r->X[i] = r->X[i+k];
 
-	/* Pos in input buff to read new data into */
-	r->Xread = i;                 
-	r->Xp = r->Xoff;
+        /* Pos in input buff to read new data into */
+        r->Xread = i;                 
+        r->Xp = r->Xoff;
 
-	for(i=0; i < Nout; i++) { 
-		// orig: *obuf++ = r->Y[i] * ISCALE;
-		Float ftemp = r->Y[i] * ISCALE;
+        for(i=0; i < Nout; i++) { 
+                // orig: *obuf++ = r->Y[i] * ISCALE;
+                Float ftemp = r->Y[i] * ISCALE;
 
-		if (ftemp >= ST_SAMPLE_MAX)
-			*obuf = ST_SAMPLE_MAX;
-		else if (ftemp <= ST_SAMPLE_MIN)
-			*obuf = ST_SAMPLE_MIN;
-		else
-			*obuf = ftemp;
-		obuf++;
+                if (ftemp >= ST_SAMPLE_MAX)
+                        *obuf = ST_SAMPLE_MAX;
+                else if (ftemp <= ST_SAMPLE_MIN)
+                        *obuf = ST_SAMPLE_MIN;
+                else
+                        *obuf = ftemp;
+                obuf++;
         }
 
-	*isamp = Nx;
-	*osamp = Nout;
+        *isamp = Nx;
+        *osamp = Nout;
 
-	}
-	return (ST_SUCCESS);
+        }
+        return (ST_SUCCESS);
 }
 
 /*
@@ -378,35 +378,35 @@
  */
 int st_resample_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
 {
-	resample_t r = (resample_t) effp->priv;
-	long isamp_res, osamp_res;
-	st_sample_t *Obuf;
-	int rc;
+        resample_t r = (resample_t) effp->priv;
+        long isamp_res, osamp_res;
+        st_sample_t *Obuf;
+        int rc;
 
-	/* fprintf(stderr,"Xoff %d, Xt %d  <--- DRAIN\n",r->Xoff, r->Xt); */
+        /* fprintf(stderr,"Xoff %d, Xt %d  <--- DRAIN\n",r->Xoff, r->Xt); */
 
-	/* stuff end with Xoff zeros */
-	isamp_res = r->Xoff;
-	osamp_res = *osamp;
-	Obuf = obuf;
-	while (isamp_res>0 && osamp_res>0) {
-		st_sample_t Isamp, Osamp;
-		Isamp = isamp_res;
-		Osamp = osamp_res;
-		rc = st_resample_flow(effp, NULL, Obuf, (st_size_t *)&Isamp, (st_size_t *)&Osamp);
-		if (rc)
-		    return rc;
-	  /* fprintf(stderr,"DRAIN isamp,osamp  (%d,%d) -> (%d,%d)\n",
-		     isamp_res,osamp_res,Isamp,Osamp); */
-		Obuf += Osamp;
-		osamp_res -= Osamp;
-		isamp_res -= Isamp;
-	}
-	*osamp -= osamp_res;
-	/* fprintf(stderr,"DRAIN osamp %d\n", *osamp); */
-	if (isamp_res)
-		st_warn("drain overran obuf by %d\n", isamp_res); fflush(stderr);
-	return (ST_SUCCESS);
+        /* stuff end with Xoff zeros */
+        isamp_res = r->Xoff;
+        osamp_res = *osamp;
+        Obuf = obuf;
+        while (isamp_res>0 && osamp_res>0) {
+                st_sample_t Isamp, Osamp;
+                Isamp = isamp_res;
+                Osamp = osamp_res;
+                rc = st_resample_flow(effp, NULL, Obuf, (st_size_t *)&Isamp, (st_size_t *)&Osamp);
+                if (rc)
+                    return rc;
+          /* fprintf(stderr,"DRAIN isamp,osamp  (%d,%d) -> (%d,%d)\n",
+                     isamp_res,osamp_res,Isamp,Osamp); */
+                Obuf += Osamp;
+                osamp_res -= Osamp;
+                isamp_res -= Isamp;
+        }
+        *osamp -= osamp_res;
+        /* fprintf(stderr,"DRAIN osamp %d\n", *osamp); */
+        if (isamp_res)
+                st_warn("drain overran obuf by %d\n", isamp_res); fflush(stderr);
+        return (ST_SUCCESS);
 }
 
 /*
@@ -415,18 +415,18 @@
  */
 int st_resample_stop(eff_t effp)
 {
-	resample_t r = (resample_t) effp->priv;
-	
-	free(r->Imp - 1);
-	free(r->X);
-	/* free(r->Y); Y is in same block starting at X */ 
-	return (ST_SUCCESS);
+        resample_t r = (resample_t) effp->priv;
+        
+        free(r->Imp - 1);
+        free(r->X);
+        /* free(r->Y); Y is in same block starting at X */ 
+        return (ST_SUCCESS);
 }
 
 /* over 90% of CPU time spent in this iprodUD() function */
 /* quadratic interpolation */
 static double qprodUD(const Float Imp[], const Float *Xp, long Inc, double T0, 
-	              long dhb, long ct)
+                      long dhb, long ct)
 {
   const double f = 1.0/(1<<La);
   double v;
@@ -458,7 +458,7 @@
 
 /* linear interpolation */
 static double iprodUD(const Float Imp[], const Float *Xp, long Inc, 
-	              double T0, long dhb, long ct)
+                      double T0, long dhb, long ct)
 {
   const double f = 1.0/(1<<La);
   double v;
@@ -491,7 +491,7 @@
    double Factor;
    double dt;                  /* Step through input signal */
    double time;
-   double (*prodUD)();
+   double (*prodUD)(const Float[], const Float *, long, double, long, long);
    int n;
 
    prodUD = (r->quadr)? qprodUD:iprodUD; /* quadratic or linear interp */
@@ -504,7 +504,7 @@
    /*fprintf(stderr,"ct=%d\n",ct);*/
    /*fprintf(stderr,"ct=%.2f %d\n",(double)r->Nwing*Na/r->dhb, r->Xh);*/
    /*fprintf(stderr,"ct=%ld, T=%.6f, dhb=%6f, dt=%.6f\n",
-		         r->Xh, time-floor(time),(double)r->dhb/Na,dt);*/
+                         r->Xh, time-floor(time),(double)r->dhb/Na,dt);*/
    Ystart = Y = r->Y;
    n = (int)ceil((double)Nx/dt);
    while(n--)
@@ -531,7 +531,7 @@
 
 /* exact coeff's */
 static double prodEX(const Float Imp[], const Float *Xp, 
-	             long Inc, long T0, long dhb, long ct)
+                     long Inc, long T0, long dhb, long ct)
 {
   double v;
   const Float *Cp;
@@ -563,20 +563,20 @@
    n = (Nx*b + (a-1))/a;
    while(n--)
       {
-	Float *Xp;
-	double v;
-	long T;
-	T = time % b;              /* fractional part of Time */
-	Xp = r->X + (time/b);      /* Ptr to current input sample */
+        Float *Xp;
+        double v;
+        long T;
+        T = time % b;              /* fractional part of Time */
+        Xp = r->X + (time/b);      /* Ptr to current input sample */
 
-	/* Past  inner product: */
-	v = prodEX(r->Imp, Xp, -1, T, b, r->Xh);
-	/* Future inner product: */
-	v += prodEX(r->Imp, Xp+1, 1, b-T, b, r->Xh);
+        /* Past  inner product: */
+        v = prodEX(r->Imp, Xp, -1, T, b, r->Xh);
+        /* Future inner product: */
+        v += prodEX(r->Imp, Xp+1, 1, b-T, b, r->Xh);
 
-	if (Factor < 1) v *= Factor;
-	*Y++ = v;             /* Deposit output */
-	time += a;            /* Move to next sample by time increment */
+        if (Factor < 1) v *= Factor;
+        *Y++ = v;             /* Deposit output */
+        time += a;            /* Move to next sample by time increment */
       }
    r->t = time;
    return (Y - Ystart);        /* Return the number of output samples */
@@ -583,7 +583,7 @@
 }
 
 int makeFilter(Float Imp[], long Nwing, double Froll, double Beta, 
-	       long Num, int Normalize)
+               long Num, int Normalize)
 {
    double *ImpR;
    long Mwing, i;
--- a/src/wav.c
+++ b/src/wav.c
@@ -59,12 +59,12 @@
  *
  */
 
-#include <string.h>		/* Included for strncmp */
-#include <stdlib.h>		/* Included for malloc and free */
+#include <string.h>             /* Included for strncmp */
+#include <stdlib.h>             /* Included for malloc and free */
 #include <stdio.h>
 
 #ifdef HAVE_UNISTD_H
-#include <unistd.h>		/* For SEEK_* defines if not found in stdio */
+#include <unistd.h>             /* For SEEK_* defines if not found in stdio */
 #endif
 
 #include "st_i.h"
@@ -80,36 +80,36 @@
 
 /* Private data for .wav file */
 typedef struct wavstuff {
-    st_size_t	   numSamples;     /* samples/channel reading: starts at total count and decremented  */
-    		                   /* writing: starts at 0 and counts samples written */
-    st_size_t	   dataLength;     /* needed for ADPCM writing */
-    unsigned short formatTag;	   /* What type of encoding file is using */
+    st_size_t      numSamples;     /* samples/channel reading: starts at total count and decremented  */
+                                   /* writing: starts at 0 and counts samples written */
+    st_size_t      dataLength;     /* needed for ADPCM writing */
+    unsigned short formatTag;      /* What type of encoding file is using */
     unsigned short samplesPerBlock;
     unsigned short blockAlign;
     st_size_t dataStart;  /* need to for seeking */
     
     /* following used by *ADPCM wav files */
-    unsigned short nCoefs;	    /* ADPCM: number of coef sets */
-    short	  *iCoefs;	    /* ADPCM: coef sets           */
-    unsigned char *packet;	    /* Temporary buffer for packets */
-    short	  *samples;	    /* interleaved samples buffer */
-    short	  *samplePtr;       /* Pointer to current sample  */
-    short	  *sampleTop;       /* End of samples-buffer      */
+    unsigned short nCoefs;          /* ADPCM: number of coef sets */
+    short         *iCoefs;          /* ADPCM: coef sets           */
+    unsigned char *packet;          /* Temporary buffer for packets */
+    short         *samples;         /* interleaved samples buffer */
+    short         *samplePtr;       /* Pointer to current sample  */
+    short         *sampleTop;       /* End of samples-buffer      */
     unsigned short blockSamplesRemaining;/* Samples remaining per channel */    
-    int 	   state[16];       /* step-size info for *ADPCM writes */
+    int            state[16];       /* step-size info for *ADPCM writes */
 
     /* following used by GSM 6.10 wav */
 #ifdef ENABLE_GSM
-    gsm		   gsmhandle;
-    gsm_signal	   *gsmsample;
-    int		   gsmindex;
-    int		   gsmbytecount;    /* counts bytes written to data block */
+    gsm            gsmhandle;
+    gsm_signal     *gsmsample;
+    int            gsmindex;
+    int            gsmbytecount;    /* counts bytes written to data block */
 #endif
 } *wav_t;
 
 /*
 #if sizeof(struct wavstuff) > PRIVSIZE
-#	warn "Uh-Oh"
+#       warn "Uh-Oh"
 #endif
 */
 
@@ -129,7 +129,7 @@
  */
 unsigned short  ImaAdpcmReadBlock(ft_t ft)
 {
-    wav_t	wav = (wav_t) ft->priv;
+    wav_t       wav = (wav_t) ft->priv;
     int bytesRead;
     int samplesThisBlock;
 
@@ -138,15 +138,15 @@
     samplesThisBlock = wav->samplesPerBlock;
     if (bytesRead < wav->blockAlign) 
     { 
-	/* If it looks like a valid header is around then try and */
-	/* work with partial blocks.  Specs say it should be null */
-	/* padded but I guess this is better than trailing quiet. */
-	samplesThisBlock = ImaSamplesIn(0, ft->info.channels, bytesRead, 0);
-	if (samplesThisBlock == 0) 
-	{
-	    st_warn("Premature EOF on .wav input file");
-	    return 0;
-	}
+        /* If it looks like a valid header is around then try and */
+        /* work with partial blocks.  Specs say it should be null */
+        /* padded but I guess this is better than trailing quiet. */
+        samplesThisBlock = ImaSamplesIn(0, ft->info.channels, bytesRead, 0);
+        if (samplesThisBlock == 0) 
+        {
+            st_warn("Premature EOF on .wav input file");
+            return 0;
+        }
     }
     
     wav->samplePtr = wav->samples;
@@ -169,7 +169,7 @@
  */
 unsigned short  AdpcmReadBlock(ft_t ft)
 {
-    wav_t	wav = (wav_t) ft->priv;
+    wav_t       wav = (wav_t) ft->priv;
     int bytesRead;
     int samplesThisBlock;
     const char *errmsg;
@@ -179,21 +179,21 @@
     samplesThisBlock = wav->samplesPerBlock;
     if (bytesRead < wav->blockAlign) 
     {
-	/* If it looks like a valid header is around then try and */
-	/* work with partial blocks.  Specs say it should be null */
-	/* padded but I guess this is better than trailing quiet. */
-	samplesThisBlock = AdpcmSamplesIn(0, ft->info.channels, bytesRead, 0);
-	if (samplesThisBlock == 0) 
-	{
-	    st_warn("Premature EOF on .wav input file");
-	    return 0;
-	}
+        /* If it looks like a valid header is around then try and */
+        /* work with partial blocks.  Specs say it should be null */
+        /* padded but I guess this is better than trailing quiet. */
+        samplesThisBlock = AdpcmSamplesIn(0, ft->info.channels, bytesRead, 0);
+        if (samplesThisBlock == 0) 
+        {
+            st_warn("Premature EOF on .wav input file");
+            return 0;
+        }
     }
     
     errmsg = AdpcmBlockExpandI(ft->info.channels, wav->nCoefs, wav->iCoefs, wav->packet, wav->samples, samplesThisBlock);
 
     if (errmsg)
-	st_warn((char*)errmsg);
+        st_warn((char*)errmsg);
 
     return samplesThisBlock;
 }
@@ -212,28 +212,28 @@
     p = wav->samplePtr;
     ct = p - wav->samples;
     if (ct>=chans) { 
-	/* zero-fill samples if needed to complete block */
-	for (p = wav->samplePtr; p < wav->sampleTop; p++) *p=0;
-	/* compress the samples to wav->packet */
-	if (wav->formatTag == WAVE_FORMAT_ADPCM) {
-	    AdpcmBlockMashI(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, wav->blockAlign,9);
-	}else{ /* WAVE_FORMAT_IMA_ADPCM */
-	    ImaBlockMashI(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, 9);
-	}
-	/* write the compressed packet */
-	if (fwrite(wav->packet, wav->blockAlign, 1, ft->fp) != 1)
-	{
-	    st_fail_errno(ft,ST_EOF,"write error");
-	    return (ST_EOF);
-	}
-	/* update lengths and samplePtr */
-	wav->dataLength += wav->blockAlign;
+        /* zero-fill samples if needed to complete block */
+        for (p = wav->samplePtr; p < wav->sampleTop; p++) *p=0;
+        /* compress the samples to wav->packet */
+        if (wav->formatTag == WAVE_FORMAT_ADPCM) {
+            AdpcmBlockMashI(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, wav->blockAlign,9);
+        }else{ /* WAVE_FORMAT_IMA_ADPCM */
+            ImaBlockMashI(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, 9);
+        }
+        /* write the compressed packet */
+        if (fwrite(wav->packet, wav->blockAlign, 1, ft->fp) != 1)
+        {
+            st_fail_errno(ft,ST_EOF,"write error");
+            return (ST_EOF);
+        }
+        /* update lengths and samplePtr */
+        wav->dataLength += wav->blockAlign;
 #ifndef PAD_NSAMPS
-	wav->numSamples += ct/chans;
+        wav->numSamples += ct/chans;
 #else
-	wav->numSamples += wav->samplesPerBlock;
+        wav->numSamples += wav->samplesPerBlock;
 #endif
-	wav->samplePtr = wav->samples;
+        wav->samplePtr = wav->samples;
     }
     return (ST_SUCCESS);
 }
@@ -244,26 +244,26 @@
 #ifdef ENABLE_GSM
 /* create the gsm object, malloc buffer for 160*2 samples */
 int wavgsminit(ft_t ft)
-{	
+{       
     int valueP=1;
-    wav_t	wav = (wav_t) ft->priv;
+    wav_t       wav = (wav_t) ft->priv;
     wav->gsmbytecount=0;
     wav->gsmhandle=gsm_create();
     if (!wav->gsmhandle)
     {
-	st_fail_errno(ft,ST_EOF,"cannot create GSM object");
-	return (ST_EOF);
+        st_fail_errno(ft,ST_EOF,"cannot create GSM object");
+        return (ST_EOF);
     }
-	
+        
     if(gsm_option(wav->gsmhandle,GSM_OPT_WAV49,&valueP) == -1){
-	st_fail_errno(ft,ST_EOF,"error setting gsm_option for WAV49 format. Recompile gsm library with -DWAV49 option and relink sox");
-	return (ST_EOF);
+        st_fail_errno(ft,ST_EOF,"error setting gsm_option for WAV49 format. Recompile gsm library with -DWAV49 option and relink sox");
+        return (ST_EOF);
     }
 
     wav->gsmsample=malloc(sizeof(gsm_signal)*160*2);
     if (wav->gsmsample == NULL){
-	st_fail_errno(ft,ST_ENOMEM,"error allocating memory for gsm buffer");
-	return (ST_EOF);
+        st_fail_errno(ft,ST_ENOMEM,"error allocating memory for gsm buffer");
+        return (ST_EOF);
     }
     wav->gsmindex=0;
     return (ST_SUCCESS);
@@ -271,8 +271,8 @@
 
 /*destroy the gsm object and free the buffer */
 void wavgsmdestroy(ft_t ft)
-{	
-    wav_t	wav = (wav_t) ft->priv;
+{       
+    wav_t       wav = (wav_t) ft->priv;
     gsm_destroy(wav->gsmhandle);
     free(wav->gsmsample);
 }
@@ -279,43 +279,43 @@
 
 st_ssize_t wavgsmread(ft_t ft, st_sample_t *buf, st_ssize_t len)
 {
-    wav_t	wav = (wav_t) ft->priv;
+    wav_t       wav = (wav_t) ft->priv;
     int done=0;
     int bytes;
-    gsm_byte	frame[65];
+    gsm_byte    frame[65];
 
-	ft->st_errno = ST_SUCCESS;
+        ft->st_errno = ST_SUCCESS;
 
   /* copy out any samples left from the last call */
     while(wav->gsmindex && (wav->gsmindex<160*2) && (done < len))
-	buf[done++]=ST_SIGNED_WORD_TO_SAMPLE(wav->gsmsample[wav->gsmindex++]);
+        buf[done++]=ST_SIGNED_WORD_TO_SAMPLE(wav->gsmsample[wav->gsmindex++]);
 
   /* read and decode loop, possibly leaving some samples in wav->gsmsample */
     while (done < len) {
-	wav->gsmindex=0;
-	bytes = fread(frame,1,65,ft->fp);   
-	if (bytes <=0)
-	    return done;
-	if (bytes<65) {
-	    st_warn("invalid wav gsm frame size: %d bytes",bytes);
-	    return done;
-	}
-	/* decode the long 33 byte half */
-	if(gsm_decode(wav->gsmhandle,frame, wav->gsmsample)<0)
-	{
-	    st_fail_errno(ft,ST_EOF,"error during gsm decode");
-	    return 0;
-	}
-	/* decode the short 32 byte half */
-	if(gsm_decode(wav->gsmhandle,frame+33, wav->gsmsample+160)<0)
-	{
-	    st_fail_errno(ft,ST_EOF,"error during gsm decode");
-	    return 0;
-	}
+        wav->gsmindex=0;
+        bytes = fread(frame,1,65,ft->fp);   
+        if (bytes <=0)
+            return done;
+        if (bytes<65) {
+            st_warn("invalid wav gsm frame size: %d bytes",bytes);
+            return done;
+        }
+        /* decode the long 33 byte half */
+        if(gsm_decode(wav->gsmhandle,frame, wav->gsmsample)<0)
+        {
+            st_fail_errno(ft,ST_EOF,"error during gsm decode");
+            return 0;
+        }
+        /* decode the short 32 byte half */
+        if(gsm_decode(wav->gsmhandle,frame+33, wav->gsmsample+160)<0)
+        {
+            st_fail_errno(ft,ST_EOF,"error during gsm decode");
+            return 0;
+        }
 
-	while ((wav->gsmindex <160*2) && (done < len)){
-	    buf[done++]=ST_SIGNED_WORD_TO_SAMPLE(wav->gsmsample[(wav->gsmindex)++]);
-	}
+        while ((wav->gsmindex <160*2) && (done < len)){
+            buf[done++]=ST_SIGNED_WORD_TO_SAMPLE(wav->gsmsample[(wav->gsmindex)++]);
+        }
     }
 
     return done;
@@ -323,12 +323,12 @@
 
 static int wavgsmflush(ft_t ft, int pad)
 {
-    gsm_byte	frame[65];
-    wav_t	wav = (wav_t) ft->priv;
+    gsm_byte    frame[65];
+    wav_t       wav = (wav_t) ft->priv;
 
     /* zero fill as needed */
     while(wav->gsmindex<160*2)
-	wav->gsmsample[wav->gsmindex++]=0;
+        wav->gsmsample[wav->gsmindex++]=0;
 
     /*encode the even half short (32 byte) frame */
     gsm_encode(wav->gsmhandle, wav->gsmsample, frame);
@@ -336,8 +336,8 @@
     gsm_encode(wav->gsmhandle, wav->gsmsample+160, frame+32);
     if (fwrite(frame, 1, 65, ft->fp) != 65)
     {
-	st_fail_errno(ft,ST_EOF,"write error");
-	return (ST_EOF);
+        st_fail_errno(ft,ST_EOF,"write error");
+        return (ST_EOF);
     }
     wav->gsmbytecount += 65;
 
@@ -344,13 +344,13 @@
     wav->gsmindex = 0;
 
     if (pad & wav->gsmbytecount){
-	/* pad output to an even number of bytes */
-	if(st_writeb(ft, 0))
-	{
-	    st_fail_errno(ft,ST_EOF,"write error");
-	    return (ST_EOF);
-	}
-	wav->gsmbytecount += 1;
+        /* pad output to an even number of bytes */
+        if(st_writeb(ft, 0))
+        {
+            st_fail_errno(ft,ST_EOF,"write error");
+            return (ST_EOF);
+        }
+        wav->gsmbytecount += 1;
     }
     return (ST_SUCCESS);
 }
@@ -357,23 +357,23 @@
 
 st_ssize_t wavgsmwrite(ft_t ft, st_sample_t *buf, st_ssize_t len)
 {
-    wav_t	wav = (wav_t) ft->priv;
+    wav_t       wav = (wav_t) ft->priv;
     int done = 0;
     int rc;
 
-	ft->st_errno = ST_SUCCESS;
+        ft->st_errno = ST_SUCCESS;
 
     while (done < len) {
-	while ((wav->gsmindex < 160*2) && (done < len))
-	    wav->gsmsample[(wav->gsmindex)++] = 
-		ST_SAMPLE_TO_SIGNED_WORD(buf[done++]);
+        while ((wav->gsmindex < 160*2) && (done < len))
+            wav->gsmsample[(wav->gsmindex)++] = 
+                ST_SAMPLE_TO_SIGNED_WORD(buf[done++]);
 
-	if (wav->gsmindex < 160*2)
-	    break;
+        if (wav->gsmindex < 160*2)
+            break;
 
-	rc = wavgsmflush(ft, 0);
-	if (rc)
-	    return 0;
+        rc = wavgsmflush(ft, 0);
+        if (rc)
+            return 0;
     }     
     return done;
 
@@ -381,12 +381,12 @@
 
 void wavgsmstopwrite(ft_t ft)
 {
-    wav_t	wav = (wav_t) ft->priv;
+    wav_t       wav = (wav_t) ft->priv;
 
-	ft->st_errno = ST_SUCCESS;
+        ft->st_errno = ST_SUCCESS;
 
     if (wav->gsmindex)
-	wavgsmflush(ft, 1);
+        wavgsmflush(ft, 1);
 
     wavgsmdestroy(ft);
 }
@@ -401,18 +401,18 @@
     uint32_t len;
     for (;;)
     {
-	if (st_reads(ft, magic, 4) == ST_EOF)
-	{
-	    st_fail_errno(ft,ST_EHDR,"WAVE file has missing %s chunk", Label);
-	    return ST_EOF;
-	}
-	st_readdw(ft, &len);
-	st_report("Chunk %s",magic);
-	if (strncmp(Label, magic, 4) == 0)
-	    break;		/* Found the data chunk */
+        if (st_reads(ft, magic, 4) == ST_EOF)
+        {
+            st_fail_errno(ft,ST_EHDR,"WAVE file has missing %s chunk", Label);
+            return ST_EOF;
+        }
+        st_readdw(ft, &len);
+        st_report("Chunk %s",magic);
+        if (strncmp(Label, magic, 4) == 0)
+            break;              /* Found the data chunk */
 
-	
-	st_seek(ft, len, SEEK_CUR); 	/* skip to next chunk */
+        
+        st_seek(ft, len, SEEK_CUR);     /* skip to next chunk */
     }
     return len;
 }
@@ -420,20 +420,20 @@
 /*
  * Do anything required before you start reading samples.
  * Read file header. 
- *	Find out sampling rate, 
- *	size and encoding of samples, 
- *	mono/stereo/quad.
+ *      Find out sampling rate, 
+ *      size and encoding of samples, 
+ *      mono/stereo/quad.
  */
 int st_wavstartread(ft_t ft) 
 {
-    wav_t	wav = (wav_t) ft->priv;
-    char	magic[5];
-    uint32_t	len;
-    int		rc;
+    wav_t       wav = (wav_t) ft->priv;
+    char        magic[5];
+    uint32_t    len;
+    int         rc;
 
     /* wave file characteristics */
     uint32_t      dwRiffLength;
-    unsigned short wChannels;	    /* number of channels */
+    unsigned short wChannels;       /* number of channels */
     uint32_t      dwSamplesPerSecond; /* samples per second per channel */
     uint32_t      dwAvgBytesPerSec;/* estimate of bytes per second needed */
     uint16_t wBitsPerSample;  /* bits per sample */
@@ -442,18 +442,18 @@
 
     uint32_t      dwDataLength;    /* length of sound data in bytes */
     st_size_t    bytesPerBlock = 0;
-    int    bytespersample;	    /* bytes per sample (per channel */
+    int    bytespersample;          /* bytes per sample (per channel */
     char text[256];
     uint32_t      dwLoopPos;
 
-	ft->st_errno = ST_SUCCESS;
+        ft->st_errno = ST_SUCCESS;
 
     if (ST_IS_BIGENDIAN) ft->swap = ft->swap ? 0 : 1;
 
     if (st_reads(ft, magic, 4) == ST_EOF || strncmp("RIFF", magic, 4))
     {
-	st_fail_errno(ft,ST_EHDR,"WAVE: RIFF header not found");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EHDR,"WAVE: RIFF header not found");
+        return ST_EOF;
     }
 
     st_readdw(ft, &dwRiffLength);
@@ -460,8 +460,8 @@
 
     if (st_reads(ft, magic, 4) == ST_EOF || strncmp("WAVE", magic, 4))
     {
-	st_fail_errno(ft,ST_EHDR,"WAVE header not found");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EHDR,"WAVE header not found");
+        return ST_EOF;
     }
 
     /* Now look for the format chunk */
@@ -470,142 +470,142 @@
     
     if (wFmtSize < 16)
     {
-	st_fail_errno(ft,ST_EHDR,"WAVE file fmt chunk is too short");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EHDR,"WAVE file fmt chunk is too short");
+        return ST_EOF;
     }
 
     st_readw(ft, &(wav->formatTag));
     st_readw(ft, &wChannels);
     st_readdw(ft, &dwSamplesPerSecond);
-    st_readdw(ft, &dwAvgBytesPerSec);	/* Average bytes/second */
-    st_readw(ft, &(wav->blockAlign));	/* Block align */
-    st_readw(ft, &wBitsPerSample);	/* bits per sample per channel */
+    st_readdw(ft, &dwAvgBytesPerSec);   /* Average bytes/second */
+    st_readw(ft, &(wav->blockAlign));   /* Block align */
+    st_readw(ft, &wBitsPerSample);      /* bits per sample per channel */
     len -= 16;
 
     switch (wav->formatTag)
     {
     case WAVE_FORMAT_UNKNOWN:
-	st_fail_errno(ft,ST_EHDR,"WAVE file is in unsupported Microsoft Official Unknown format.");
-	return ST_EOF;
-	
+        st_fail_errno(ft,ST_EHDR,"WAVE file is in unsupported Microsoft Official Unknown format.");
+        return ST_EOF;
+        
     case WAVE_FORMAT_PCM:
-	/* Default (-1) depends on sample size.  Set that later on. */
-	if (ft->info.encoding != -1 && ft->info.encoding != ST_ENCODING_UNSIGNED &&
-	    ft->info.encoding != ST_ENCODING_SIGN2)
-	    st_report("User options overriding encoding read in .wav header");
+        /* Default (-1) depends on sample size.  Set that later on. */
+        if (ft->info.encoding != -1 && ft->info.encoding != ST_ENCODING_UNSIGNED &&
+            ft->info.encoding != ST_ENCODING_SIGN2)
+            st_report("User options overriding encoding read in .wav header");
 
-	/* Needed by rawread() functions */
+        /* Needed by rawread() functions */
         rc = st_rawstartread(ft);
         if (rc)
-	    return rc;
+            return rc;
 
-	break;
-	
+        break;
+        
     case WAVE_FORMAT_IMA_ADPCM:
-	if (ft->info.encoding == -1 || ft->info.encoding == ST_ENCODING_IMA_ADPCM)
-	    ft->info.encoding = ST_ENCODING_IMA_ADPCM;
-	else
-	    st_report("User options overriding encoding read in .wav header");
-	break;
+        if (ft->info.encoding == -1 || ft->info.encoding == ST_ENCODING_IMA_ADPCM)
+            ft->info.encoding = ST_ENCODING_IMA_ADPCM;
+        else
+            st_report("User options overriding encoding read in .wav header");
+        break;
 
     case WAVE_FORMAT_ADPCM:
-	if (ft->info.encoding == -1 || ft->info.encoding == ST_ENCODING_ADPCM)
-	    ft->info.encoding = ST_ENCODING_ADPCM;
-	else
-	    st_report("User options overriding encoding read in .wav header");
-	break;
+        if (ft->info.encoding == -1 || ft->info.encoding == ST_ENCODING_ADPCM)
+            ft->info.encoding = ST_ENCODING_ADPCM;
+        else
+            st_report("User options overriding encoding read in .wav header");
+        break;
 
     case WAVE_FORMAT_IEEE_FLOAT:
-	st_fail_errno(ft,ST_EHDR,"Sorry, this WAV file is in IEEE Float format.");
-	return ST_EOF;
-	
+        st_fail_errno(ft,ST_EHDR,"Sorry, this WAV file is in IEEE Float format.");
+        return ST_EOF;
+        
     case WAVE_FORMAT_ALAW:
-	if (ft->info.encoding == -1 || ft->info.encoding == ST_ENCODING_ALAW)
-	    ft->info.encoding = ST_ENCODING_ALAW;
-	else
-	    st_report("User options overriding encoding read in .wav header");
+        if (ft->info.encoding == -1 || ft->info.encoding == ST_ENCODING_ALAW)
+            ft->info.encoding = ST_ENCODING_ALAW;
+        else
+            st_report("User options overriding encoding read in .wav header");
 
-	/* Needed by rawread() functions */
+        /* Needed by rawread() functions */
         rc = st_rawstartread(ft);
         if (rc)
-	    return rc;
+            return rc;
 
-	break;
-	
+        break;
+        
     case WAVE_FORMAT_MULAW:
-	if (ft->info.encoding == -1 || ft->info.encoding == ST_ENCODING_ULAW)
-	    ft->info.encoding = ST_ENCODING_ULAW;
-	else
-	    st_report("User options overriding encoding read in .wav header");
+        if (ft->info.encoding == -1 || ft->info.encoding == ST_ENCODING_ULAW)
+            ft->info.encoding = ST_ENCODING_ULAW;
+        else
+            st_report("User options overriding encoding read in .wav header");
 
-	/* Needed by rawread() functions */
+        /* Needed by rawread() functions */
         rc = st_rawstartread(ft);
         if (rc)
-	    return rc;
+            return rc;
 
-	break;
-	
+        break;
+        
     case WAVE_FORMAT_OKI_ADPCM:
-	st_fail_errno(ft,ST_EHDR,"Sorry, this WAV file is in OKI ADPCM format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EHDR,"Sorry, this WAV file is in OKI ADPCM format.");
+        return ST_EOF;
     case WAVE_FORMAT_DIGISTD:
-	st_fail_errno(ft,ST_EHDR,"Sorry, this WAV file is in Digistd format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EHDR,"Sorry, this WAV file is in Digistd format.");
+        return ST_EOF;
     case WAVE_FORMAT_DIGIFIX:
-	st_fail_errno(ft,ST_EHDR,"Sorry, this WAV file is in Digifix format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EHDR,"Sorry, this WAV file is in Digifix format.");
+        return ST_EOF;
     case WAVE_FORMAT_DOLBY_AC2:
-	st_fail_errno(ft,ST_EHDR,"Sorry, this WAV file is in Dolby AC2 format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EHDR,"Sorry, this WAV file is in Dolby AC2 format.");
+        return ST_EOF;
     case WAVE_FORMAT_GSM610:
 #ifdef ENABLE_GSM
-	if (ft->info.encoding == -1 || ft->info.encoding == ST_ENCODING_GSM )
-	    ft->info.encoding = ST_ENCODING_GSM;
-	else
-	    st_report("User options overriding encoding read in .wav header");
-	break;
+        if (ft->info.encoding == -1 || ft->info.encoding == ST_ENCODING_GSM )
+            ft->info.encoding = ST_ENCODING_GSM;
+        else
+            st_report("User options overriding encoding read in .wav header");
+        break;
 #else
-	st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in GSM6.10 format and no GSM support present, recompile sox with gsm library");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in GSM6.10 format and no GSM support present, recompile sox with gsm library");
+        return ST_EOF;
 #endif
     case WAVE_FORMAT_ROCKWELL_ADPCM:
-	st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in Rockwell ADPCM format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in Rockwell ADPCM format.");
+        return ST_EOF;
     case WAVE_FORMAT_ROCKWELL_DIGITALK:
-	st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in Rockwell DIGITALK format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in Rockwell DIGITALK format.");
+        return ST_EOF;
     case WAVE_FORMAT_G721_ADPCM:
-	st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in G.721 ADPCM format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in G.721 ADPCM format.");
+        return ST_EOF;
     case WAVE_FORMAT_G728_CELP:
-	st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in G.728 CELP format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in G.728 CELP format.");
+        return ST_EOF;
     case WAVE_FORMAT_MPEG:
-	st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in MPEG format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in MPEG format.");
+        return ST_EOF;
     case WAVE_FORMAT_MPEGLAYER3:
-	st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in MPEG Layer 3 format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in MPEG Layer 3 format.");
+        return ST_EOF;
     case WAVE_FORMAT_G726_ADPCM:
-	st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in G.726 ADPCM format.");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in G.726 ADPCM format.");
+        return ST_EOF;
     case WAVE_FORMAT_G722_ADPCM:
-	st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in G.722 ADPCM format.");
-	return ST_EOF;
-    default:	st_fail_errno(ft,ST_EOF,"WAV file has unknown format type of %x",wav->formatTag);
-		return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"Sorry, this WAV file is in G.722 ADPCM format.");
+        return ST_EOF;
+    default:    st_fail_errno(ft,ST_EOF,"WAV file has unknown format type of %x",wav->formatTag);
+                return ST_EOF;
     }
 
     /* User options take precedence */
     if (ft->info.channels == -1 || ft->info.channels == wChannels)
-	ft->info.channels = wChannels;
+        ft->info.channels = wChannels;
     else
-	st_report("User options overriding channels read in .wav header");
+        st_report("User options overriding channels read in .wav header");
 
     if (ft->info.rate == 0 || ft->info.rate == dwSamplesPerSecond)
-	ft->info.rate = dwSamplesPerSecond;
+        ft->info.rate = dwSamplesPerSecond;
     else
-	st_report("User options overriding rate read in .wav header");
+        st_report("User options overriding rate read in .wav header");
     
 
     wav->iCoefs = NULL;
@@ -614,160 +614,160 @@
 
     /* non-PCM formats have extended fmt chunk.  Check for those cases. */
     if (wav->formatTag != WAVE_FORMAT_PCM) {
-	if (len >= 2) {
-	    st_readw(ft, &wExtSize);
-	    len -= 2;
-	} else {
-	    st_warn("wave header missing FmtExt chunk");
-	}
+        if (len >= 2) {
+            st_readw(ft, &wExtSize);
+            len -= 2;
+        } else {
+            st_warn("wave header missing FmtExt chunk");
+        }
     }
 
     if (wExtSize > len)
     {
-	st_fail_errno(ft,ST_EOF,"wave header error: wExtSize inconsistent with wFmtLen");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"wave header error: wExtSize inconsistent with wFmtLen");
+        return ST_EOF;
     }
 
     switch (wav->formatTag)
     {
     case WAVE_FORMAT_ADPCM:
-	if (wExtSize < 4)
-	{
-	    st_fail_errno(ft,ST_EOF,"format[%s]: expects wExtSize >= %d",
-			wav_format_str(wav->formatTag), 4);
-	    return ST_EOF;
-	}
+        if (wExtSize < 4)
+        {
+            st_fail_errno(ft,ST_EOF,"format[%s]: expects wExtSize >= %d",
+                        wav_format_str(wav->formatTag), 4);
+            return ST_EOF;
+        }
 
-	if (wBitsPerSample != 4)
-	{
-	    st_fail_errno(ft,ST_EOF,"Can only handle 4-bit MS ADPCM in wav files");
-	    return ST_EOF;
-	}
+        if (wBitsPerSample != 4)
+        {
+            st_fail_errno(ft,ST_EOF,"Can only handle 4-bit MS ADPCM in wav files");
+            return ST_EOF;
+        }
 
-	st_readw(ft, &(wav->samplesPerBlock));
-	bytesPerBlock = AdpcmBytesPerBlock(ft->info.channels, wav->samplesPerBlock);
-	if (bytesPerBlock > wav->blockAlign)
-	{
-	    st_fail_errno(ft,ST_EOF,"format[%s]: samplesPerBlock(%d) incompatible with blockAlign(%d)",
-		wav_format_str(wav->formatTag), wav->samplesPerBlock, wav->blockAlign);
-	    return ST_EOF;
-	}
+        st_readw(ft, &(wav->samplesPerBlock));
+        bytesPerBlock = AdpcmBytesPerBlock(ft->info.channels, wav->samplesPerBlock);
+        if (bytesPerBlock > wav->blockAlign)
+        {
+            st_fail_errno(ft,ST_EOF,"format[%s]: samplesPerBlock(%d) incompatible with blockAlign(%d)",
+                wav_format_str(wav->formatTag), wav->samplesPerBlock, wav->blockAlign);
+            return ST_EOF;
+        }
 
-	st_readw(ft, &(wav->nCoefs));
-	if (wav->nCoefs < 7 || wav->nCoefs > 0x100) {
-	    st_fail_errno(ft,ST_EOF,"ADPCM file nCoefs (%.4hx) makes no sense\n", wav->nCoefs);
-	    return ST_EOF;
-	}
-	wav->packet = (unsigned char *)malloc(wav->blockAlign);
-	if (!wav->packet)
-	{
-	    st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
-	    return ST_EOF;
-	}
+        st_readw(ft, &(wav->nCoefs));
+        if (wav->nCoefs < 7 || wav->nCoefs > 0x100) {
+            st_fail_errno(ft,ST_EOF,"ADPCM file nCoefs (%.4hx) makes no sense\n", wav->nCoefs);
+            return ST_EOF;
+        }
+        wav->packet = (unsigned char *)malloc(wav->blockAlign);
+        if (!wav->packet)
+        {
+            st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
+            return ST_EOF;
+        }
 
-	len -= 4;
+        len -= 4;
 
-	if (wExtSize < 4 + 4*wav->nCoefs)
-	{
-	    st_fail_errno(ft,ST_EOF,"wave header error: wExtSize(%d) too small for nCoefs(%d)", wExtSize, wav->nCoefs);
-	    return ST_EOF;
-	}
+        if (wExtSize < 4 + 4*wav->nCoefs)
+        {
+            st_fail_errno(ft,ST_EOF,"wave header error: wExtSize(%d) too small for nCoefs(%d)", wExtSize, wav->nCoefs);
+            return ST_EOF;
+        }
 
-	wav->samples = (short *)malloc(wChannels*wav->samplesPerBlock*sizeof(short));
-	if (!wav->samples)
-	{
-	    st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
-	    return ST_EOF;
-	}
+        wav->samples = (short *)malloc(wChannels*wav->samplesPerBlock*sizeof(short));
+        if (!wav->samples)
+        {
+            st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
+            return ST_EOF;
+        }
 
-	/* nCoefs, iCoefs used by adpcm.c */
-	wav->iCoefs = (short *)malloc(wav->nCoefs * 2 * sizeof(short));
-	if (!wav->iCoefs)
-	{
-	    st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
-	    return ST_EOF;
-	}
-	{
-	    int i, errct=0;
-	    for (i=0; len>=2 && i < 2*wav->nCoefs; i++) {
-		st_readw(ft, (unsigned short *)&(wav->iCoefs[i]));
-		len -= 2;
-		if (i<14) errct += (wav->iCoefs[i] != iCoef[i/2][i%2]);
-		/* fprintf(stderr,"iCoefs[%2d] %4d\n",i,wav->iCoefs[i]); */
-	    }
-	    if (errct) st_warn("base iCoefs differ in %d/14 positions",errct);
-	}
+        /* nCoefs, iCoefs used by adpcm.c */
+        wav->iCoefs = (short *)malloc(wav->nCoefs * 2 * sizeof(short));
+        if (!wav->iCoefs)
+        {
+            st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
+            return ST_EOF;
+        }
+        {
+            int i, errct=0;
+            for (i=0; len>=2 && i < 2*wav->nCoefs; i++) {
+                st_readw(ft, (unsigned short *)&(wav->iCoefs[i]));
+                len -= 2;
+                if (i<14) errct += (wav->iCoefs[i] != iCoef[i/2][i%2]);
+                /* fprintf(stderr,"iCoefs[%2d] %4d\n",i,wav->iCoefs[i]); */
+            }
+            if (errct) st_warn("base iCoefs differ in %d/14 positions",errct);
+        }
 
-	bytespersample = ST_SIZE_WORD;  /* AFTER de-compression */
-	break;
+        bytespersample = ST_SIZE_WORD;  /* AFTER de-compression */
+        break;
 
     case WAVE_FORMAT_IMA_ADPCM:
-	if (wExtSize < 2)
-	{
-	    st_fail_errno(ft,ST_EOF,"format[%s]: expects wExtSize >= %d",
-		    wav_format_str(wav->formatTag), 2);
-	    return ST_EOF;
-	}
+        if (wExtSize < 2)
+        {
+            st_fail_errno(ft,ST_EOF,"format[%s]: expects wExtSize >= %d",
+                    wav_format_str(wav->formatTag), 2);
+            return ST_EOF;
+        }
 
-	if (wBitsPerSample != 4)
-	{
-	    st_fail_errno(ft,ST_EOF,"Can only handle 4-bit IMA ADPCM in wav files");
-	    return ST_EOF;
-	}
+        if (wBitsPerSample != 4)
+        {
+            st_fail_errno(ft,ST_EOF,"Can only handle 4-bit IMA ADPCM in wav files");
+            return ST_EOF;
+        }
 
-	st_readw(ft, &(wav->samplesPerBlock));
-	bytesPerBlock = ImaBytesPerBlock(ft->info.channels, wav->samplesPerBlock);
-	if (bytesPerBlock > wav->blockAlign || wav->samplesPerBlock%8 != 1)
-	{
-	    st_fail_errno(ft,ST_EOF,"format[%s]: samplesPerBlock(%d) incompatible with blockAlign(%d)",
-		wav_format_str(wav->formatTag), wav->samplesPerBlock, wav->blockAlign);
-	    return ST_EOF;
-	}
+        st_readw(ft, &(wav->samplesPerBlock));
+        bytesPerBlock = ImaBytesPerBlock(ft->info.channels, wav->samplesPerBlock);
+        if (bytesPerBlock > wav->blockAlign || wav->samplesPerBlock%8 != 1)
+        {
+            st_fail_errno(ft,ST_EOF,"format[%s]: samplesPerBlock(%d) incompatible with blockAlign(%d)",
+                wav_format_str(wav->formatTag), wav->samplesPerBlock, wav->blockAlign);
+            return ST_EOF;
+        }
 
-	wav->packet = (unsigned char *)malloc(wav->blockAlign);
-	if (!wav->packet)
-	{
-	    st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
-	    return ST_EOF;
-	}
-	len -= 2;
+        wav->packet = (unsigned char *)malloc(wav->blockAlign);
+        if (!wav->packet)
+        {
+            st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
+            return ST_EOF;
+        }
+        len -= 2;
 
-	wav->samples = (short *)malloc(wChannels*wav->samplesPerBlock*sizeof(short));
-	if (!wav->samples)
-	{
-	    st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
-	    return ST_EOF;
-	}
+        wav->samples = (short *)malloc(wChannels*wav->samplesPerBlock*sizeof(short));
+        if (!wav->samples)
+        {
+            st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
+            return ST_EOF;
+        }
 
-	bytespersample = ST_SIZE_WORD;  /* AFTER de-compression */
-	break;
+        bytespersample = ST_SIZE_WORD;  /* AFTER de-compression */
+        break;
 
 #ifdef ENABLE_GSM
     /* GSM formats have extended fmt chunk.  Check for those cases. */
     case WAVE_FORMAT_GSM610:
-	if (wExtSize < 2)
-	{
-	    st_fail_errno(ft,ST_EOF,"format[%s]: expects wExtSize >= %d",
-		    wav_format_str(wav->formatTag), 2);
-	    return ST_EOF;
-	}
-	st_readw(ft, &wav->samplesPerBlock);
-	bytesPerBlock = 65;
-	if (wav->blockAlign != 65)
-	{
-	    st_fail_errno(ft,ST_EOF,"format[%s]: expects blockAlign(%d) = %d",
-		    wav_format_str(wav->formatTag), wav->blockAlign, 65);
-	    return ST_EOF;
-	}
-	if (wav->samplesPerBlock != 320)
-	{
-	    st_fail_errno(ft,ST_EOF,"format[%s]: expects samplesPerBlock(%d) = %d",
-		    wav_format_str(wav->formatTag), wav->samplesPerBlock, 320);
-	    return ST_EOF;
-	}
-	bytespersample = ST_SIZE_WORD;  /* AFTER de-compression */
-	len -= 2;
-	break;
+        if (wExtSize < 2)
+        {
+            st_fail_errno(ft,ST_EOF,"format[%s]: expects wExtSize >= %d",
+                    wav_format_str(wav->formatTag), 2);
+            return ST_EOF;
+        }
+        st_readw(ft, &wav->samplesPerBlock);
+        bytesPerBlock = 65;
+        if (wav->blockAlign != 65)
+        {
+            st_fail_errno(ft,ST_EOF,"format[%s]: expects blockAlign(%d) = %d",
+                    wav_format_str(wav->formatTag), wav->blockAlign, 65);
+            return ST_EOF;
+        }
+        if (wav->samplesPerBlock != 320)
+        {
+            st_fail_errno(ft,ST_EOF,"format[%s]: expects samplesPerBlock(%d) = %d",
+                    wav_format_str(wav->formatTag), wav->samplesPerBlock, 320);
+            return ST_EOF;
+        }
+        bytespersample = ST_SIZE_WORD;  /* AFTER de-compression */
+        len -= 2;
+        break;
 #endif
 
     default:
@@ -777,44 +777,44 @@
 
     switch (bytespersample)
     {
-	
+        
     case ST_SIZE_BYTE:
-	/* User options take precedence */
-	if (ft->info.size == -1 || ft->info.size == ST_SIZE_BYTE)
-	    ft->info.size = ST_SIZE_BYTE;
-	else
-	    st_warn("User options overriding size read in .wav header");
+        /* User options take precedence */
+        if (ft->info.size == -1 || ft->info.size == ST_SIZE_BYTE)
+            ft->info.size = ST_SIZE_BYTE;
+        else
+            st_warn("User options overriding size read in .wav header");
 
-	/* Now we have enough information to set default encodings. */
-	if (ft->info.encoding == -1)
-	    ft->info.encoding = ST_ENCODING_UNSIGNED;
-	break;
-	
+        /* Now we have enough information to set default encodings. */
+        if (ft->info.encoding == -1)
+            ft->info.encoding = ST_ENCODING_UNSIGNED;
+        break;
+        
     case ST_SIZE_WORD:
-	if (ft->info.size == -1 || ft->info.size == ST_SIZE_WORD)
-	    ft->info.size = ST_SIZE_WORD;
-	else
-	    st_warn("User options overriding size read in .wav header");
+        if (ft->info.size == -1 || ft->info.size == ST_SIZE_WORD)
+            ft->info.size = ST_SIZE_WORD;
+        else
+            st_warn("User options overriding size read in .wav header");
 
-	/* Now we have enough information to set default encodings. */
-	if (ft->info.encoding == -1)
-	    ft->info.encoding = ST_ENCODING_SIGN2;
-	break;
-	
+        /* Now we have enough information to set default encodings. */
+        if (ft->info.encoding == -1)
+            ft->info.encoding = ST_ENCODING_SIGN2;
+        break;
+        
     case ST_SIZE_DWORD:
-	if (ft->info.size == -1 || ft->info.size == ST_SIZE_DWORD)
-	    ft->info.size = ST_SIZE_DWORD;
-	else
-	    st_warn("User options overriding size read in .wav header");
+        if (ft->info.size == -1 || ft->info.size == ST_SIZE_DWORD)
+            ft->info.size = ST_SIZE_DWORD;
+        else
+            st_warn("User options overriding size read in .wav header");
 
-	/* Now we have enough information to set default encodings. */
-	if (ft->info.encoding == -1)
-	    ft->info.encoding = ST_ENCODING_SIGN2;
-	break;
-	
+        /* Now we have enough information to set default encodings. */
+        if (ft->info.encoding == -1)
+            ft->info.encoding = ST_ENCODING_SIGN2;
+        break;
+        
     default:
-	st_fail_errno(ft,ST_EOF,"Sorry, don't understand .wav size");
-	return ST_EOF;
+        st_fail_errno(ft,ST_EOF,"Sorry, don't understand .wav size");
+        return ST_EOF;
     }
 
     /* Skip anything left over from fmt chunk */
@@ -827,75 +827,75 @@
     dwDataLength = len = findChunk(ft, "data");
     /* findChunk() only returns if chunk was found */
 
-	/* Data starts here */
-	wav->dataStart = ftell(ft->fp);
+        /* Data starts here */
+        wav->dataStart = ftell(ft->fp);
 
     switch (wav->formatTag)
     {
 
     case WAVE_FORMAT_ADPCM:
-	wav->numSamples = 
-	    AdpcmSamplesIn(dwDataLength, ft->info.channels, 
-		           wav->blockAlign, wav->samplesPerBlock);
-	/*st_report("datalen %d, numSamples %d",dwDataLength, wav->numSamples);*/
-	wav->blockSamplesRemaining = 0;	       /* Samples left in buffer */
-	ft->length = wav->numSamples*ft->info.channels;
-	break;
+        wav->numSamples = 
+            AdpcmSamplesIn(dwDataLength, ft->info.channels, 
+                           wav->blockAlign, wav->samplesPerBlock);
+        /*st_report("datalen %d, numSamples %d",dwDataLength, wav->numSamples);*/
+        wav->blockSamplesRemaining = 0;        /* Samples left in buffer */
+        ft->length = wav->numSamples*ft->info.channels;
+        break;
 
     case WAVE_FORMAT_IMA_ADPCM:
-	/* Compute easiest part of number of samples.  For every block, there
-	   are samplesPerBlock samples to read. */
-	wav->numSamples = 
-	    ImaSamplesIn(dwDataLength, ft->info.channels, 
-		         wav->blockAlign, wav->samplesPerBlock);
-	/*st_report("datalen %d, numSamples %d",dwDataLength, wav->numSamples);*/
-	wav->blockSamplesRemaining = 0;	       /* Samples left in buffer */
-	initImaTable();
-	ft->length = wav->numSamples*ft->info.channels;
-	break;
+        /* Compute easiest part of number of samples.  For every block, there
+           are samplesPerBlock samples to read. */
+        wav->numSamples = 
+            ImaSamplesIn(dwDataLength, ft->info.channels, 
+                         wav->blockAlign, wav->samplesPerBlock);
+        /*st_report("datalen %d, numSamples %d",dwDataLength, wav->numSamples);*/
+        wav->blockSamplesRemaining = 0;        /* Samples left in buffer */
+        initImaTable();
+        ft->length = wav->numSamples*ft->info.channels;
+        break;
 
 #ifdef ENABLE_GSM
     case WAVE_FORMAT_GSM610:
-	wav->numSamples = (((dwDataLength / wav->blockAlign) * wav->samplesPerBlock) * ft->info.channels);
-	wavgsminit(ft);
-	ft->length = wav->numSamples;
-	break;
+        wav->numSamples = (((dwDataLength / wav->blockAlign) * wav->samplesPerBlock) * ft->info.channels);
+        wavgsminit(ft);
+        ft->length = wav->numSamples;
+        break;
 #endif
 
     default:
-	wav->numSamples = dwDataLength/ft->info.size;	/* total samples */
-	ft->length = wav->numSamples;
+        wav->numSamples = dwDataLength/ft->info.size;   /* total samples */
+        ft->length = wav->numSamples;
 
     }
 
     st_report("Reading Wave file: %s format, %d channel%s, %d samp/sec",
-	   wav_format_str(wav->formatTag), ft->info.channels,
-	   wChannels == 1 ? "" : "s", dwSamplesPerSecond);
+           wav_format_str(wav->formatTag), ft->info.channels,
+           wChannels == 1 ? "" : "s", dwSamplesPerSecond);
     st_report("        %d byte/sec, %d block align, %d bits/samp, %u data bytes",
-	   dwAvgBytesPerSec, wav->blockAlign, wBitsPerSample, dwDataLength);
+           dwAvgBytesPerSec, wav->blockAlign, wBitsPerSample, dwDataLength);
 
     /* Can also report extended fmt information */
     switch (wav->formatTag)
     {
     case WAVE_FORMAT_ADPCM:
-	st_report("        %d Extsize, %d Samps/block, %d bytes/block %d Num Coefs",
-		wExtSize,wav->samplesPerBlock,bytesPerBlock,wav->nCoefs);
-	break;
+        st_report("        %d Extsize, %d Samps/block, %d bytes/block %d Num Coefs",
+                wExtSize,wav->samplesPerBlock,bytesPerBlock,wav->nCoefs);
+        break;
 
     case WAVE_FORMAT_IMA_ADPCM:
-	st_report("        %d Extsize, %d Samps/block, %d bytes/block",
-		wExtSize,wav->samplesPerBlock,bytesPerBlock);
-	break;
+        st_report("        %d Extsize, %d Samps/block, %d bytes/block",
+                wExtSize,wav->samplesPerBlock,bytesPerBlock);
+        break;
 
 #ifdef ENABLE_GSM
     case WAVE_FORMAT_GSM610:
-	st_report("GSM .wav: %d Extsize, %d Samps/block,  %d samples",
-		wExtSize,wav->samplesPerBlock,wav->numSamples);
-	break;
+        st_report("GSM .wav: %d Extsize, %d Samps/block,  %d samples",
+                wExtSize,wav->samplesPerBlock,wav->numSamples);
+        break;
 #endif
 
     default:
-	break;
+        break;
     }
 
     /* Horrible way to find Cool Edit marker points. Taken from Quake source*/
@@ -907,59 +907,69 @@
         len = (len + 1) & ~1;
         st_seek(ft, len, SEEK_CUR);
         if( findChunk(ft, "LIST") != ST_EOF){
-	    ft->comment = (char*)malloc(256);
-	    /* Initialize comment to a NULL string */
-	    ft->comment[0] = 0;
-	    while(!feof(ft->fp)){
-		st_reads(ft,magic,4);
-		if(strncmp(magic,"INFO",4) == 0){
-			/*Skip*/
-		} else if(strncmp(magic,"ICRD",4) == 0){
-			st_readdw(ft,&len); 
-			len = (len + 1) & ~1;
-			st_reads(ft,text,len);
-			if (strlen(ft->comment) + strlen(text) < 254)
-			{
-			    strcat(ft->comment,text);
-    			    strcat(ft->comment,"\n");
-			}
-		} else if(strncmp(magic,"ISFT",4) == 0){
-			st_readdw(ft,&len); 
-			len = (len + 1) & ~1;
-			st_reads(ft,text,len);
-			if (strlen(ft->comment) + strlen(text) < 254)
-			{
-			    strcat(ft->comment,text);
-    			    strcat(ft->comment,"\n");
-			}
-		} else if(strncmp(magic,"cue ",4) == 0){
-			st_readdw(ft,&len);
-			len = (len + 1) & ~1;
-			st_seek(ft,len-4,SEEK_CUR);
-			st_readdw(ft,&dwLoopPos);
-			ft->loops[0].start = dwLoopPos;
-		} else if(strncmp(magic,"note",4) == 0){
-			/*Skip*/
-			st_readdw(ft,&len);
-			len = (len + 1) & ~1;
-			st_seek(ft,len-4,SEEK_CUR);
-		} else if(strncmp(magic,"adtl",4) == 0){
-			/*Skip*/
-		} else if(strncmp(magic,"ltxt",4) == 0){
-			st_seek(ft,4,SEEK_CUR);
-			st_readdw(ft,&dwLoopPos);
-			ft->loops[0].length = dwLoopPos - ft->loops[0].start;
-		} else if(strncmp(magic,"labl",4) == 0){
-			/*Skip*/
-			st_readdw(ft,&len);
-			len = (len + 1) & ~1;
-			st_seek(ft,len-4,SEEK_CUR);
-		}
-	    }
-        }
+            ft->comment = (char*)malloc(256);
+            /* Initialize comment to a NULL string */
+            ft->comment[0] = 0;
+            while(!feof(ft->fp)){
+                st_reads(ft,magic,4);
+                if(strncmp(magic,"INFO",4) == 0){
+                        /*Skip*/
+                } else if(strncmp(magic,"ICRD",4) == 0){
+                        st_readdw(ft,&len); 
+                        len = (len + 1) & ~1;
+                        if (len > 254)
+                        {
+                            fprintf(stderr, "Possible buffer overflow hack attack (ICRD)!\n");
+                            break;
+                        }
+                        st_reads(ft,text,len);
+                        if (strlen(ft->comment) + strlen(text) < 254)
+                        {
+                            strcat(ft->comment,text);
+                            strcat(ft->comment,"\n");
+                        }
+                } else if(strncmp(magic,"ISFT",4) == 0){
+                        st_readdw(ft,&len); 
+                        len = (len + 1) & ~1;
+                        if (len > 254)
+                        {
+                            fprintf(stderr, "Possible buffer overflow hack attack (ISFT)!\n");
+                            break;
+                        }
+                        st_reads(ft,text,len);
+                        if (strlen(ft->comment) + strlen(text) < 254)
+                        {
+                            strcat(ft->comment,text);
+                            strcat(ft->comment,"\n");
+                        }
+                } else if(strncmp(magic,"cue ",4) == 0){
+                        st_readdw(ft,&len);
+                        len = (len + 1) & ~1;
+                        st_seek(ft,len-4,SEEK_CUR);
+                        st_readdw(ft,&dwLoopPos);
+                        ft->loops[0].start = dwLoopPos;
+                } else if(strncmp(magic,"note",4) == 0){
+                        /*Skip*/
+                        st_readdw(ft,&len);
+                        len = (len + 1) & ~1;
+                        st_seek(ft,len-4,SEEK_CUR);
+                } else if(strncmp(magic,"adtl",4) == 0){
+                        /*Skip*/
+                } else if(strncmp(magic,"ltxt",4) == 0){
+                        st_seek(ft,4,SEEK_CUR);
+                        st_readdw(ft,&dwLoopPos);
+                        ft->loops[0].length = dwLoopPos - ft->loops[0].start;
+                } else if(strncmp(magic,"labl",4) == 0){
+                        /*Skip*/
+                        st_readdw(ft,&len);
+                        len = (len + 1) & ~1;
+                        st_seek(ft,len-4,SEEK_CUR);
+                }
+            }
+        }
         clearerr(ft->fp);
         st_seek(ft,wav->dataStart,SEEK_SET);
-    }	
+    }   
     return ST_SUCCESS;
 }
 
@@ -973,92 +983,92 @@
 
 st_ssize_t st_wavread(ft_t ft, st_sample_t *buf, st_ssize_t len) 
 {
-	wav_t	wav = (wav_t) ft->priv;
-	st_ssize_t done;
+        wav_t   wav = (wav_t) ft->priv;
+        st_ssize_t done;
 
-	ft->st_errno = ST_SUCCESS;
-	
-	/* If file is in ADPCM encoding then read in multiple blocks else */
-	/* read as much as possible and return quickly. */
-	switch (ft->info.encoding)
-	{
-	case ST_ENCODING_IMA_ADPCM:
-	case ST_ENCODING_ADPCM:
+        ft->st_errno = ST_SUCCESS;
+        
+        /* If file is in ADPCM encoding then read in multiple blocks else */
+        /* read as much as possible and return quickly. */
+        switch (ft->info.encoding)
+        {
+        case ST_ENCODING_IMA_ADPCM:
+        case ST_ENCODING_ADPCM:
 
-	    /* FIXME: numSamples is not used consistently in
-	     * wav handler.  Sometimes it accounts for stereo,
-	     * sometimes it does not.
-	     */
-	    if (len > (wav->numSamples*ft->info.channels)) 
-	        len = (wav->numSamples*ft->info.channels);
+            /* FIXME: numSamples is not used consistently in
+             * wav handler.  Sometimes it accounts for stereo,
+             * sometimes it does not.
+             */
+            if (len > (wav->numSamples*ft->info.channels)) 
+                len = (wav->numSamples*ft->info.channels);
 
-	    done = 0;
-	    while (done < len) { /* Still want data? */
-		/* See if need to read more from disk */
-		if (wav->blockSamplesRemaining == 0) { 
-		    if (wav->formatTag == WAVE_FORMAT_IMA_ADPCM)
-			wav->blockSamplesRemaining = ImaAdpcmReadBlock(ft);
-		    else
-			wav->blockSamplesRemaining = AdpcmReadBlock(ft);
-		    if (wav->blockSamplesRemaining == 0)
-		    {
-			/* Don't try to read any more samples */
-			wav->numSamples = 0;
-			return done;
-		    }
-		    wav->samplePtr = wav->samples;
-		}
+            done = 0;
+            while (done < len) { /* Still want data? */
+                /* See if need to read more from disk */
+                if (wav->blockSamplesRemaining == 0) { 
+                    if (wav->formatTag == WAVE_FORMAT_IMA_ADPCM)
+                        wav->blockSamplesRemaining = ImaAdpcmReadBlock(ft);
+                    else
+                        wav->blockSamplesRemaining = AdpcmReadBlock(ft);
+                    if (wav->blockSamplesRemaining == 0)
+                    {
+                        /* Don't try to read any more samples */
+                        wav->numSamples = 0;
+                        return done;
+                    }
+                    wav->samplePtr = wav->samples;
+                }
 
-		/* Copy interleaved data into buf, converting to st_sample_t */
-		{
-		    short *p, *top;
-		    int ct;
-		    ct = len-done;
-		    if (ct > (wav->blockSamplesRemaining*ft->info.channels))
-			ct = (wav->blockSamplesRemaining*ft->info.channels);
+                /* Copy interleaved data into buf, converting to st_sample_t */
+                {
+                    short *p, *top;
+                    int ct;
+                    ct = len-done;
+                    if (ct > (wav->blockSamplesRemaining*ft->info.channels))
+                        ct = (wav->blockSamplesRemaining*ft->info.channels);
 
-		    done += ct;
-		    wav->blockSamplesRemaining -= (ct/ft->info.channels);
-		    p = wav->samplePtr;
-		    top = p+ct;
-		    /* Output is already signed */
-		    while (p<top)
-			*buf++ = ST_SIGNED_WORD_TO_SAMPLE((*p++));
+                    done += ct;
+                    wav->blockSamplesRemaining -= (ct/ft->info.channels);
+                    p = wav->samplePtr;
+                    top = p+ct;
+                    /* Output is already signed */
+                    while (p<top)
+                        *buf++ = ST_SIGNED_WORD_TO_SAMPLE((*p++));
 
-		    wav->samplePtr = p;
-		}
-	    }
-	    /* "done" for ADPCM equals total data processed and not
-	     * total samples procesed.  The only way to take care of that
-	     * is to return here and not fall thru.
-	     */
-	    wav->numSamples -= (done / ft->info.channels);
-	    return done;
-	    break;
+                    wav->samplePtr = p;
+                }
+            }
+            /* "done" for ADPCM equals total data processed and not
+             * total samples procesed.  The only way to take care of that
+             * is to return here and not fall thru.
+             */
+            wav->numSamples -= (done / ft->info.channels);
+            return done;
+            break;
 
 #ifdef ENABLE_GSM
-	case ST_ENCODING_GSM:
-	    if (len > wav->numSamples) 
-	        len = wav->numSamples;
+        case ST_ENCODING_GSM:
+            if (len > wav->numSamples) 
+                len = wav->numSamples;
 
-	    done = wavgsmread(ft, buf, len);
-	    if (done == 0 && wav->numSamples != 0)
-		st_warn("Premature EOF on .wav input file");
-	break;
+            done = wavgsmread(ft, buf, len);
+            if (done == 0 && wav->numSamples != 0)
+                st_warn("Premature EOF on .wav input file");
+        break;
 #endif
-	default: /* assume PCM encoding */
-	    if (len > wav->numSamples) 
-	        len = wav->numSamples;
+        default: /* assume PCM encoding */
+            if (len > wav->numSamples) 
+                len = wav->numSamples;
 
-	    done = st_rawread(ft, buf, len);
-	    /* If software thinks there are more samples but I/O */
-	    /* says otherwise, let the user know about this.     */
-	    if (done == 0 && wav->numSamples != 0)
-		st_warn("Premature EOF on .wav input file");
-	}
+            done = st_rawread(ft, buf, len);
+            /* If software thinks there are more samples but I/O */
+            /* says otherwise, let the user know about this.     */
+            if (done == 0 && wav->numSamples != 0)
+                st_warn("Premature EOF on .wav input file");
+        }
 
-	wav->numSamples -= done;
-	return done;
+        wav->numSamples -= done;
+        return done;
 }
 
 /*
@@ -1067,10 +1077,10 @@
  */
 int st_wavstopread(ft_t ft) 
 {
-    wav_t	wav = (wav_t) ft->priv;
-    int		rc = ST_SUCCESS;
+    wav_t       wav = (wav_t) ft->priv;
+    int         rc = ST_SUCCESS;
 
-	ft->st_errno = ST_SUCCESS;
+        ft->st_errno = ST_SUCCESS;
 
     if (wav->packet) free(wav->packet);
     if (wav->samples) free(wav->samples);
@@ -1080,15 +1090,15 @@
     {
 #ifdef ENABLEGSM
     case ST_ENCODING_GSM:
-	wavgsmdestroy(ft);
-	break;
+        wavgsmdestroy(ft);
+        break;
 #endif
     case ST_ENCODING_IMA_ADPCM:
     case ST_ENCODING_ADPCM:
-	break;
+        break;
     default:
-	/* Needed for rawread() */
-	rc = st_rawstopread(ft);
+        /* Needed for rawread() */
+        rc = st_rawstopread(ft);
     }
     return rc;
 }
@@ -1095,67 +1105,67 @@
 
 int st_wavstartwrite(ft_t ft) 
 {
-	wav_t	wav = (wav_t) ft->priv;
-	int	rc;
+        wav_t   wav = (wav_t) ft->priv;
+        int     rc;
 
-	ft->st_errno = ST_SUCCESS;
+        ft->st_errno = ST_SUCCESS;
 
-	if (ST_IS_BIGENDIAN) ft->swap = ft->swap ? 0 : 1;
+        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;
-	}
+        /* 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)
-		st_warn("Length in output .wav header will be wrong since can't seek to fix it");
-	rc = wavwritehdr(ft, 0);  /* also calculates various wav->* info */
-	if (rc != 0)
-	    return rc;
+        wav->numSamples = 0;
+        wav->dataLength = 0;
+        if (!ft->seekable)
+                st_warn("Length in output .wav header will be wrong since can't seek to fix it");
+        rc = wavwritehdr(ft, 0);  /* also calculates various wav->* info */
+        if (rc != 0)
+            return rc;
 
-	wav->packet = NULL;
-	wav->samples = NULL;
-	wav->iCoefs = NULL;
-	switch (wav->formatTag)
-	{
-	int ch, sbsize;
-	case WAVE_FORMAT_IMA_ADPCM:
-	    initImaTable();
-	/* intentional case fallthru! */
-	case WAVE_FORMAT_ADPCM:
-	    /* #channels already range-checked for overflow in wavwritehdr() */
-	    for (ch=0; ch<ft->info.channels; ch++)
-	    	wav->state[ch] = 0;
-	    sbsize = ft->info.channels * wav->samplesPerBlock;
-	    wav->packet = (unsigned char *)malloc(wav->blockAlign);
-	    wav->samples = (short *)malloc(sbsize*sizeof(short));
-	    if (!wav->packet || !wav->samples)
-	    {
-		st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
-		return ST_EOF;
-	    }
-	    wav->sampleTop = wav->samples + sbsize;
-	    wav->samplePtr = wav->samples;
-	    break;
+        wav->packet = NULL;
+        wav->samples = NULL;
+        wav->iCoefs = NULL;
+        switch (wav->formatTag)
+        {
+        int ch, sbsize;
+        case WAVE_FORMAT_IMA_ADPCM:
+            initImaTable();
+        /* intentional case fallthru! */
+        case WAVE_FORMAT_ADPCM:
+            /* #channels already range-checked for overflow in wavwritehdr() */
+            for (ch=0; ch<ft->info.channels; ch++)
+                wav->state[ch] = 0;
+            sbsize = ft->info.channels * wav->samplesPerBlock;
+            wav->packet = (unsigned char *)malloc(wav->blockAlign);
+            wav->samples = (short *)malloc(sbsize*sizeof(short));
+            if (!wav->packet || !wav->samples)
+            {
+                st_fail_errno(ft,ST_EOF,"Unable to alloc resources");
+                return ST_EOF;
+            }
+            wav->sampleTop = wav->samples + sbsize;
+            wav->samplePtr = wav->samples;
+            break;
 
 #ifdef ENABLE_GSM
-	case WAVE_FORMAT_GSM610:
-	    wavgsminit(ft);
-	    break;
+        case WAVE_FORMAT_GSM610:
+            wavgsminit(ft);
+            break;
 #endif
-	default:
-	    break;
-	}
-	return ST_SUCCESS;
+        default:
+            break;
+        }
+        return ST_SUCCESS;
 }
 
 /* wavwritehdr:  write .wav headers as follows:
@@ -1216,7 +1226,7 @@
 
 static int wavwritehdr(ft_t ft, int second_header) 
 {
-    wav_t	wav = (wav_t) ft->priv;
+    wav_t       wav = (wav_t) ft->priv;
 
     /* variables written to wav file header */
     /* RIFF header */    
@@ -1235,11 +1245,11 @@
     /* wSamplesPerBlock and other things may go into format extension */
 
     /* fact chunk (not PCM) */
-    uint32_t dwFactSize=4;	  /* length of the fact chunk */
+    uint32_t dwFactSize=4;        /* length of the fact chunk */
     uint32_t dwSamplesWritten=0;  /* windows doesnt seem to use this*/
 
     /* data chunk */
-    uint32_t  dwDataLength=0x7ffff000L;	/* length of sound data in bytes */
+    uint32_t  dwDataLength=0x7ffff000L; /* length of sound data in bytes */
     /* end of variables written to header */
 
     /* internal variables, intermediate values etc */
@@ -1255,153 +1265,153 @@
      * on verbose output.
      */
     if ((ft->info.encoding == ST_ENCODING_ADPCM ||
-	 ft->info.encoding == ST_ENCODING_IMA_ADPCM ||
-	 ft->info.encoding == ST_ENCODING_GSM) &&
-	 ft->info.size != ST_SIZE_BYTE)
+         ft->info.encoding == ST_ENCODING_IMA_ADPCM ||
+         ft->info.encoding == ST_ENCODING_GSM) &&
+         ft->info.size != ST_SIZE_BYTE)
     {
-	st_warn("Overriding output size to bytes for compressed data.");
-	ft->info.size = ST_SIZE_BYTE;
+        st_warn("Overriding output size to bytes for compressed data.");
+        ft->info.size = ST_SIZE_BYTE;
     }
 
     switch (ft->info.size)
     {
-	case ST_SIZE_BYTE:
-	    wBitsPerSample = 8;
-	    if (ft->info.encoding != ST_ENCODING_UNSIGNED &&
-		    ft->info.encoding != ST_ENCODING_ULAW &&
-		    ft->info.encoding != ST_ENCODING_ALAW &&
-		    ft->info.encoding != ST_ENCODING_GSM &&
-		    ft->info.encoding != ST_ENCODING_ADPCM &&
-		    ft->info.encoding != ST_ENCODING_IMA_ADPCM)
-	    {
-		st_warn("Do not support %s with 8-bit data.  Forcing to unsigned",st_encodings_str[(unsigned char)ft->info.encoding]);
-		ft->info.encoding = ST_ENCODING_UNSIGNED;
-	    }
-	    break;
-	case ST_SIZE_WORD:
-	    wBitsPerSample = 16;
-	    if (ft->info.encoding != ST_ENCODING_SIGN2)
-	    {
-		st_warn("Do not support %s with 16-bit data.  Forcing to Signed.",st_encodings_str[(unsigned char)ft->info.encoding]);
-		ft->info.encoding = ST_ENCODING_SIGN2;
-	    }
-	    break;
-	case ST_SIZE_DWORD:
-	    wBitsPerSample = 32;
-	    if (ft->info.encoding != ST_ENCODING_SIGN2)
-	    {
-		st_warn("Do not support %s with 16-bit data.  Forcing to Signed.",st_encodings_str[(unsigned char)ft->info.encoding]);
-		ft->info.encoding = ST_ENCODING_SIGN2;
-	    }
+        case ST_SIZE_BYTE:
+            wBitsPerSample = 8;
+            if (ft->info.encoding != ST_ENCODING_UNSIGNED &&
+                    ft->info.encoding != ST_ENCODING_ULAW &&
+                    ft->info.encoding != ST_ENCODING_ALAW &&
+                    ft->info.encoding != ST_ENCODING_GSM &&
+                    ft->info.encoding != ST_ENCODING_ADPCM &&
+                    ft->info.encoding != ST_ENCODING_IMA_ADPCM)
+            {
+                st_warn("Do not support %s with 8-bit data.  Forcing to unsigned",st_encodings_str[(unsigned char)ft->info.encoding]);
+                ft->info.encoding = ST_ENCODING_UNSIGNED;
+            }
+            break;
+        case ST_SIZE_WORD:
+            wBitsPerSample = 16;
+            if (ft->info.encoding != ST_ENCODING_SIGN2)
+            {
+                st_warn("Do not support %s with 16-bit data.  Forcing to Signed.",st_encodings_str[(unsigned char)ft->info.encoding]);
+                ft->info.encoding = ST_ENCODING_SIGN2;
+            }
+            break;
+        case ST_SIZE_DWORD:
+            wBitsPerSample = 32;
+            if (ft->info.encoding != ST_ENCODING_SIGN2)
+            {
+                st_warn("Do not support %s with 16-bit data.  Forcing to Signed.",st_encodings_str[(unsigned char)ft->info.encoding]);
+                ft->info.encoding = ST_ENCODING_SIGN2;
+            }
 
-	    break;
-	default:
-	    st_warn("Do not support %s in WAV files.  Forcing to Signed Words.",st_sizes_str[(unsigned char)ft->info.size]);
-	    ft->info.encoding = ST_ENCODING_SIGN2;
-	    ft->info.size = ST_SIZE_WORD;
-	    wBitsPerSample = 16;
-	    break;
+            break;
+        default:
+            st_warn("Do not support %s in WAV files.  Forcing to Signed Words.",st_sizes_str[(unsigned char)ft->info.size]);
+            ft->info.encoding = ST_ENCODING_SIGN2;
+            ft->info.size = ST_SIZE_WORD;
+            wBitsPerSample = 16;
+            break;
     }
 
-    wSamplesPerBlock = 1;	/* common default for PCM data */
+    wSamplesPerBlock = 1;       /* common default for PCM data */
 
     switch (ft->info.encoding)
     {
-	case ST_ENCODING_UNSIGNED:
-	case ST_ENCODING_SIGN2:
-	    wFormatTag = WAVE_FORMAT_PCM;
-	    bytespersample = (wBitsPerSample + 7)/8;
-	    wBlockAlign = wChannels * bytespersample;
-	    break;
-	case ST_ENCODING_ALAW:
-	    wFormatTag = WAVE_FORMAT_ALAW;
-	    wBlockAlign = wChannels;
-	    break;
-	case ST_ENCODING_ULAW:
-	    wFormatTag = WAVE_FORMAT_MULAW;
-	    wBlockAlign = wChannels;
-	    break;
-	case ST_ENCODING_IMA_ADPCM:
-	    if (wChannels>16)
-	    {
-		st_fail_errno(ft,ST_EOF,"Channels(%d) must be <= 16\n",wChannels);
-		return ST_EOF;
-	    }
-	    wFormatTag = WAVE_FORMAT_IMA_ADPCM;
-	    wBlockAlign = wChannels * 256; /* reasonable default */
-	    wBitsPerSample = 4;
-	    wExtSize = 2;
-	    wSamplesPerBlock = ImaSamplesIn(0, wChannels, wBlockAlign, 0);
-	    break;
-	case ST_ENCODING_ADPCM:
-	    if (wChannels>16)
-	    {
-		st_fail_errno(ft,ST_EOF,"Channels(%d) must be <= 16\n",wChannels);
-		return ST_EOF;
-	    }
-	    wFormatTag = WAVE_FORMAT_ADPCM;
-	    wBlockAlign = wChannels * 128; /* reasonable default */
-	    wBitsPerSample = 4;
-	    wExtSize = 4+4*7;      /* Ext fmt data length */
-	    wSamplesPerBlock = AdpcmSamplesIn(0, wChannels, wBlockAlign, 0);
-	    break;
-	case ST_ENCODING_GSM:
+        case ST_ENCODING_UNSIGNED:
+        case ST_ENCODING_SIGN2:
+            wFormatTag = WAVE_FORMAT_PCM;
+            bytespersample = (wBitsPerSample + 7)/8;
+            wBlockAlign = wChannels * bytespersample;
+            break;
+        case ST_ENCODING_ALAW:
+            wFormatTag = WAVE_FORMAT_ALAW;
+            wBlockAlign = wChannels;
+            break;
+        case ST_ENCODING_ULAW:
+            wFormatTag = WAVE_FORMAT_MULAW;
+            wBlockAlign = wChannels;
+            break;
+        case ST_ENCODING_IMA_ADPCM:
+            if (wChannels>16)
+            {
+                st_fail_errno(ft,ST_EOF,"Channels(%d) must be <= 16\n",wChannels);
+                return ST_EOF;
+            }
+            wFormatTag = WAVE_FORMAT_IMA_ADPCM;
+            wBlockAlign = wChannels * 256; /* reasonable default */
+            wBitsPerSample = 4;
+            wExtSize = 2;
+            wSamplesPerBlock = ImaSamplesIn(0, wChannels, wBlockAlign, 0);
+            break;
+        case ST_ENCODING_ADPCM:
+            if (wChannels>16)
+            {
+                st_fail_errno(ft,ST_EOF,"Channels(%d) must be <= 16\n",wChannels);
+                return ST_EOF;
+            }
+            wFormatTag = WAVE_FORMAT_ADPCM;
+            wBlockAlign = wChannels * 128; /* reasonable default */
+            wBitsPerSample = 4;
+            wExtSize = 4+4*7;      /* Ext fmt data length */
+            wSamplesPerBlock = AdpcmSamplesIn(0, wChannels, wBlockAlign, 0);
+            break;
+        case ST_ENCODING_GSM:
 #ifdef ENABLE_GSM
-	    if (wChannels!=1)
-	    {
-		st_warn("Overriding GSM audio from %d channel to 1\n",wChannels);
-		wChannels = ft->info.channels = 1;
-	    }
-	    wFormatTag = WAVE_FORMAT_GSM610;
-	    /* dwAvgBytesPerSec = 1625*(dwSamplesPerSecond/8000.)+0.5; */
-	    wBlockAlign=65;
-	    wBitsPerSample=0;  /* not representable as int   */
-	    wExtSize=2;        /* length of format extension */
-	    wSamplesPerBlock = 320;
+            if (wChannels!=1)
+            {
+                st_warn("Overriding GSM audio from %d channel to 1\n",wChannels);
+                wChannels = ft->info.channels = 1;
+            }
+            wFormatTag = WAVE_FORMAT_GSM610;
+            /* dwAvgBytesPerSec = 1625*(dwSamplesPerSecond/8000.)+0.5; */
+            wBlockAlign=65;
+            wBitsPerSample=0;  /* not representable as int   */
+            wExtSize=2;        /* length of format extension */
+            wSamplesPerBlock = 320;
 #else
-	    st_fail_errno(ft,ST_EOF,"sorry, no GSM6.10 support, recompile sox with gsm library");
-	    return ST_EOF;
+            st_fail_errno(ft,ST_EOF,"sorry, no GSM6.10 support, recompile sox with gsm library");
+            return ST_EOF;
 #endif
-	    break;
+            break;
     }
     wav->formatTag = wFormatTag;
     wav->blockAlign = wBlockAlign;
     wav->samplesPerBlock = wSamplesPerBlock;
 
-    if (!second_header) { 	/* adjust for blockAlign */
-	blocksWritten = dwDataLength/wBlockAlign;
-	dwDataLength = blocksWritten * wBlockAlign;
-	dwSamplesWritten = blocksWritten * wSamplesPerBlock;
-    } else { 	/* fixup with real length */
-	dwSamplesWritten = wav->numSamples;
-	switch(wFormatTag)
-	{
-	    case WAVE_FORMAT_ADPCM:
-	    case WAVE_FORMAT_IMA_ADPCM:
-		dwDataLength = wav->dataLength;
-		break;
+    if (!second_header) {       /* adjust for blockAlign */
+        blocksWritten = dwDataLength/wBlockAlign;
+        dwDataLength = blocksWritten * wBlockAlign;
+        dwSamplesWritten = blocksWritten * wSamplesPerBlock;
+    } else {    /* fixup with real length */
+        dwSamplesWritten = wav->numSamples;
+        switch(wFormatTag)
+        {
+            case WAVE_FORMAT_ADPCM:
+            case WAVE_FORMAT_IMA_ADPCM:
+                dwDataLength = wav->dataLength;
+                break;
 #ifdef ENABLE_GSM
-	    case WAVE_FORMAT_GSM610:
-		/* intentional case fallthrough! */
+            case WAVE_FORMAT_GSM610:
+                /* intentional case fallthrough! */
 #endif
-	    default:
-		dwSamplesWritten /= wChannels; /* because how rawwrite()'s work */
-		blocksWritten = (dwSamplesWritten+wSamplesPerBlock-1)/wSamplesPerBlock;
-		dwDataLength = blocksWritten * wBlockAlign;
-	}
+            default:
+                dwSamplesWritten /= wChannels; /* because how rawwrite()'s work */
+                blocksWritten = (dwSamplesWritten+wSamplesPerBlock-1)/wSamplesPerBlock;
+                dwDataLength = blocksWritten * wBlockAlign;
+        }
     }
 
 #ifdef ENABLE_GSM
     if (wFormatTag == WAVE_FORMAT_GSM610)
-	dwDataLength = (dwDataLength+1) & ~1; /*round up to even */
+        dwDataLength = (dwDataLength+1) & ~1; /*round up to even */
 #endif
 
     if (wFormatTag != WAVE_FORMAT_PCM)
-	wFmtSize += 2+wExtSize; /* plus ExtData */
+        wFmtSize += 2+wExtSize; /* plus ExtData */
 
     wRiffLength = 4 + (8+wFmtSize) + (8+dwDataLength); 
     if (wFormatTag != WAVE_FORMAT_PCM) /* PCM omits the "fact" chunk */
-	wRiffLength += (8+dwFactSize);
+        wRiffLength += (8+dwFactSize);
 
     /* dwAvgBytesPerSec <-- this is BEFORE compression, isn't it? guess not. */
     dwAvgBytesPerSec = (double)wBlockAlign*ft->info.rate / (double)wSamplesPerBlock + 0.5;
@@ -1421,59 +1431,59 @@
 
     /* if not PCM, we need to write out wExtSize even if wExtSize=0 */
     if (wFormatTag != WAVE_FORMAT_PCM)
-	st_writew(ft,wExtSize);
+        st_writew(ft,wExtSize);
 
     switch (wFormatTag)
     {
-	int i;
-	case WAVE_FORMAT_IMA_ADPCM:
-	st_writew(ft, wSamplesPerBlock);
-	break;
-	case WAVE_FORMAT_ADPCM:
-	st_writew(ft, wSamplesPerBlock);
-	st_writew(ft, 7); /* nCoefs */
-	for (i=0; i<7; i++) {
-	    st_writew(ft, iCoef[i][0]);
-	    st_writew(ft, iCoef[i][1]);
-	}
-	break;
+        int i;
+        case WAVE_FORMAT_IMA_ADPCM:
+        st_writew(ft, wSamplesPerBlock);
+        break;
+        case WAVE_FORMAT_ADPCM:
+        st_writew(ft, wSamplesPerBlock);
+        st_writew(ft, 7); /* nCoefs */
+        for (i=0; i<7; i++) {
+            st_writew(ft, iCoef[i][0]);
+            st_writew(ft, iCoef[i][1]);
+        }
+        break;
 #ifdef ENABLE_GSM
-	case WAVE_FORMAT_GSM610:
-	st_writew(ft, wSamplesPerBlock);
-	break;
+        case WAVE_FORMAT_GSM610:
+        st_writew(ft, wSamplesPerBlock);
+        break;
 #endif
-	default:
-	break;
+        default:
+        break;
     }
 
     /* if not PCM, write the 'fact' chunk */
     if (wFormatTag != WAVE_FORMAT_PCM){
-	st_writes(ft, "fact");
-	st_writedw(ft,dwFactSize); 
-	st_writedw(ft,dwSamplesWritten);
+        st_writes(ft, "fact");
+        st_writedw(ft,dwFactSize); 
+        st_writedw(ft,dwSamplesWritten);
     }
 
     st_writes(ft, "data");
-    st_writedw(ft, dwDataLength);		/* data chunk size */
+    st_writedw(ft, dwDataLength);               /* data chunk size */
 
     if (!second_header) {
-	st_report("Writing Wave file: %s format, %d channel%s, %d samp/sec",
-		wav_format_str(wFormatTag), wChannels,
-		wChannels == 1 ? "" : "s", dwSamplesPerSecond);
-	st_report("        %d byte/sec, %d block align, %d bits/samp",
-		dwAvgBytesPerSec, wBlockAlign, wBitsPerSample);
+        st_report("Writing Wave file: %s format, %d channel%s, %d samp/sec",
+                wav_format_str(wFormatTag), wChannels,
+                wChannels == 1 ? "" : "s", dwSamplesPerSecond);
+        st_report("        %d byte/sec, %d block align, %d bits/samp",
+                dwAvgBytesPerSec, wBlockAlign, wBitsPerSample);
     } else {
-	st_report("Finished writing Wave file, %u data bytes %u samples\n",
-		dwDataLength,wav->numSamples);
+        st_report("Finished writing Wave file, %u data bytes %u samples\n",
+                dwDataLength,wav->numSamples);
 #ifdef ENABLE_GSM
-	if (wFormatTag == WAVE_FORMAT_GSM610){
-	    st_report("GSM6.10 format: %u blocks %u padded samples %u padded data bytes\n",
-		    blocksWritten, dwSamplesWritten, dwDataLength);
-	    if (wav->gsmbytecount != dwDataLength)
-		st_warn("help ! internal inconsistency - data_written %u gsmbytecount %u",
-			dwDataLength, wav->gsmbytecount);
+        if (wFormatTag == WAVE_FORMAT_GSM610){
+            st_report("GSM6.10 format: %u blocks %u padded samples %u padded data bytes\n",
+                    blocksWritten, dwSamplesWritten, dwDataLength);
+            if (wav->gsmbytecount != dwDataLength)
+                st_warn("help ! internal inconsistency - data_written %u gsmbytecount %u",
+                        dwDataLength, wav->gsmbytecount);
 
-	}
+        }
 #endif
     }
     return ST_SUCCESS;
@@ -1481,91 +1491,91 @@
 
 st_ssize_t st_wavwrite(ft_t ft, st_sample_t *buf, st_ssize_t len) 
 {
-	wav_t	wav = (wav_t) ft->priv;
-	st_ssize_t total_len = len;
+        wav_t   wav = (wav_t) ft->priv;
+        st_ssize_t total_len = len;
 
-	ft->st_errno = ST_SUCCESS;
+        ft->st_errno = ST_SUCCESS;
 
-	switch (wav->formatTag)
-	{
-	case WAVE_FORMAT_IMA_ADPCM:
-	case WAVE_FORMAT_ADPCM:
-	    while (len>0) {
-		short *p = wav->samplePtr;
-		short *top = wav->sampleTop;
+        switch (wav->formatTag)
+        {
+        case WAVE_FORMAT_IMA_ADPCM:
+        case WAVE_FORMAT_ADPCM:
+            while (len>0) {
+                short *p = wav->samplePtr;
+                short *top = wav->sampleTop;
 
-		if (top>p+len) top = p+len;
-		len -= top-p; /* update residual len */
-		while (p < top)
-		   *p++ = (*buf++) >> 16;
+                if (top>p+len) top = p+len;
+                len -= top-p; /* update residual len */
+                while (p < top)
+                   *p++ = (*buf++) >> 16;
 
-		wav->samplePtr = p;
-		if (p == wav->sampleTop)
-		    xxxAdpcmWriteBlock(ft);
+                wav->samplePtr = p;
+                if (p == wav->sampleTop)
+                    xxxAdpcmWriteBlock(ft);
 
-	    }
-	    return total_len - len;
-	    break;
+            }
+            return total_len - len;
+            break;
 
 #ifdef ENABLE_GSM
-	case WAVE_FORMAT_GSM610:
-	    len = wavgsmwrite(ft, buf, len);
-	    wav->numSamples += len;
-	    return len;
-	    break;
+        case WAVE_FORMAT_GSM610:
+            len = wavgsmwrite(ft, buf, len);
+            wav->numSamples += len;
+            return len;
+            break;
 #endif
-	default:
-	    len = st_rawwrite(ft, buf, len);
-	    wav->numSamples += len; /* must later be divided by wChannels */
-	    return len;
-	}
+        default:
+            len = st_rawwrite(ft, buf, len);
+            wav->numSamples += len; /* must later be divided by wChannels */
+            return len;
+        }
 }
 
 int st_wavstopwrite(ft_t ft) 
 {
-	wav_t	wav = (wav_t) ft->priv;
+        wav_t   wav = (wav_t) ft->priv;
 
-	ft->st_errno = ST_SUCCESS;
+        ft->st_errno = ST_SUCCESS;
 
 
-	/* Call this to flush out any remaining data. */
-	switch (wav->formatTag)
-	{
-	case WAVE_FORMAT_IMA_ADPCM:
-	case WAVE_FORMAT_ADPCM:
-	    xxxAdpcmWriteBlock(ft);
-	    break;
+        /* Call this to flush out any remaining data. */
+        switch (wav->formatTag)
+        {
+        case WAVE_FORMAT_IMA_ADPCM:
+        case WAVE_FORMAT_ADPCM:
+            xxxAdpcmWriteBlock(ft);
+            break;
 #ifdef ENABLE_GSM
-	case WAVE_FORMAT_GSM610:
-	    wavgsmstopwrite(ft);
-	    break;
+        case WAVE_FORMAT_GSM610:
+            wavgsmstopwrite(ft);
+            break;
 #endif
-	}
-	if (wav->packet) free(wav->packet);
- 	if (wav->samples) free(wav->samples);
- 	if (wav->iCoefs) free(wav->iCoefs);
+        }
+        if (wav->packet) free(wav->packet);
+        if (wav->samples) free(wav->samples);
+        if (wav->iCoefs) free(wav->iCoefs);
 
-	/* Flush any remaining data */
-	if (wav->formatTag != WAVE_FORMAT_IMA_ADPCM &&
-	    wav->formatTag != WAVE_FORMAT_ADPCM &&
-	    wav->formatTag != WAVE_FORMAT_GSM610)
-	{
-	    st_rawstopwrite(ft);
-	}
+        /* Flush any remaining data */
+        if (wav->formatTag != WAVE_FORMAT_IMA_ADPCM &&
+            wav->formatTag != WAVE_FORMAT_ADPCM &&
+            wav->formatTag != WAVE_FORMAT_GSM610)
+        {
+            st_rawstopwrite(ft);
+        }
 
-	/* All samples are already written out. */
-	/* If file header needs fixing up, for example it needs the */
- 	/* the number of samples in a field, seek back and write them here. */
-	if (!ft->seekable)
-		return ST_EOF;
+        /* All samples are already written out. */
+        /* If file header needs fixing up, for example it needs the */
+        /* the number of samples in a field, seek back and write them here. */
+        if (!ft->seekable)
+                return ST_EOF;
 
-	if (fseek(ft->fp, 0L, SEEK_SET) != 0)
-	{
-		st_fail_errno(ft,ST_EOF,"Can't rewind output file to rewrite .wav header.");
-		return ST_EOF;
-	}
+        if (fseek(ft->fp, 0L, SEEK_SET) != 0)
+        {
+                st_fail_errno(ft,ST_EOF,"Can't rewind output file to rewrite .wav header.");
+                return ST_EOF;
+        }
 
-	return (wavwritehdr(ft, 1));
+        return (wavwritehdr(ft, 1));
 }
 
 /*
@@ -1573,72 +1583,72 @@
  */
 static char *wav_format_str(unsigned wFormatTag) 
 {
-	switch (wFormatTag)
-	{
-		case WAVE_FORMAT_UNKNOWN:
-			return "Microsoft Official Unknown";
-		case WAVE_FORMAT_PCM:
-			return "Microsoft PCM";
-		case WAVE_FORMAT_ADPCM:
-			return "Microsoft ADPCM";
-	        case WAVE_FORMAT_IEEE_FLOAT:
-		       return "IEEE Float";
-		case WAVE_FORMAT_ALAW:
-			return "Microsoft A-law";
-		case WAVE_FORMAT_MULAW:
-			return "Microsoft U-law";
-		case WAVE_FORMAT_OKI_ADPCM:
-			return "OKI ADPCM format.";
-		case WAVE_FORMAT_IMA_ADPCM:
-			return "IMA ADPCM";
-		case WAVE_FORMAT_DIGISTD:
-			return "Digistd format.";
-		case WAVE_FORMAT_DIGIFIX:
-			return "Digifix format.";
-		case WAVE_FORMAT_DOLBY_AC2:
-			return "Dolby AC2";
-		case WAVE_FORMAT_GSM610:
-			return "GSM 6.10";
-		case WAVE_FORMAT_ROCKWELL_ADPCM:
-			return "Rockwell ADPCM";
-		case WAVE_FORMAT_ROCKWELL_DIGITALK:
-			return "Rockwell DIGITALK";
-		case WAVE_FORMAT_G721_ADPCM:
-			return "G.721 ADPCM";
-		case WAVE_FORMAT_G728_CELP:
-			return "G.728 CELP";
-		case WAVE_FORMAT_MPEG:
-			return "MPEG";
-		case WAVE_FORMAT_MPEGLAYER3:
-			return "MPEG Layer 3";
-		case WAVE_FORMAT_G726_ADPCM:
-			return "G.726 ADPCM";
-		case WAVE_FORMAT_G722_ADPCM:
-			return "G.722 ADPCM";
-		default:
-			return "Unknown";
-	}
+        switch (wFormatTag)
+        {
+                case WAVE_FORMAT_UNKNOWN:
+                        return "Microsoft Official Unknown";
+                case WAVE_FORMAT_PCM:
+                        return "Microsoft PCM";
+                case WAVE_FORMAT_ADPCM:
+                        return "Microsoft ADPCM";
+                case WAVE_FORMAT_IEEE_FLOAT:
+                       return "IEEE Float";
+                case WAVE_FORMAT_ALAW:
+                        return "Microsoft A-law";
+                case WAVE_FORMAT_MULAW:
+                        return "Microsoft U-law";
+                case WAVE_FORMAT_OKI_ADPCM:
+                        return "OKI ADPCM format.";
+                case WAVE_FORMAT_IMA_ADPCM:
+                        return "IMA ADPCM";
+                case WAVE_FORMAT_DIGISTD:
+                        return "Digistd format.";
+                case WAVE_FORMAT_DIGIFIX:
+                        return "Digifix format.";
+                case WAVE_FORMAT_DOLBY_AC2:
+                        return "Dolby AC2";
+                case WAVE_FORMAT_GSM610:
+                        return "GSM 6.10";
+                case WAVE_FORMAT_ROCKWELL_ADPCM:
+                        return "Rockwell ADPCM";
+                case WAVE_FORMAT_ROCKWELL_DIGITALK:
+                        return "Rockwell DIGITALK";
+                case WAVE_FORMAT_G721_ADPCM:
+                        return "G.721 ADPCM";
+                case WAVE_FORMAT_G728_CELP:
+                        return "G.728 CELP";
+                case WAVE_FORMAT_MPEG:
+                        return "MPEG";
+                case WAVE_FORMAT_MPEGLAYER3:
+                        return "MPEG Layer 3";
+                case WAVE_FORMAT_G726_ADPCM:
+                        return "G.726 ADPCM";
+                case WAVE_FORMAT_G722_ADPCM:
+                        return "G.722 ADPCM";
+                default:
+                        return "Unknown";
+        }
 }
 
 int st_wavseek(ft_t ft, st_size_t offset) 
 {
-	wav_t	wav = (wav_t) ft->priv;
+        wav_t   wav = (wav_t) ft->priv;
 
-	switch (wav->formatTag)
-	{
-	case WAVE_FORMAT_IMA_ADPCM:
-	case WAVE_FORMAT_ADPCM:
+        switch (wav->formatTag)
+        {
+        case WAVE_FORMAT_IMA_ADPCM:
+        case WAVE_FORMAT_ADPCM:
 #ifdef ENABLE_GSM
-	case WAVE_FORMAT_GSM610:
+        case WAVE_FORMAT_GSM610:
 #endif
-		st_fail_errno(ft,ST_ENOTSUP,"Only PCM Supported");
-	    break;
-	default:
-		ft->st_errno = st_seek(ft,offset*ft->info.size + wav->dataStart, SEEK_SET);
-	}
+                st_fail_errno(ft,ST_ENOTSUP,"Only PCM Supported");
+            break;
+        default:
+                ft->st_errno = st_seek(ft,offset*ft->info.size + wav->dataStart, SEEK_SET);
+        }
 
-	if( ft->st_errno == ST_SUCCESS )
-		wav->numSamples = ft->length - offset;
+        if( ft->st_errno == ST_SUCCESS )
+                wav->numSamples = ft->length - offset;
 
-	return(ft->st_errno);
+        return(ft->st_errno);
 }