shithub: sox

Download patch

ref: 10bfbe260ac55bf7d8430fdf7564673947da966f
parent: 42cf355479ef3554a06d39c0d578da803678a118
author: cbagwell <cbagwell>
date: Fri Nov 23 18:48:15 EST 2001

Removing invalid "ulong"'s.  Flush out extra data before updating header in WVE files.

--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -50,11 +50,11 @@
 
 typedef struct polyphase {
 
-  st_rate_t lcmrate;   		 /* least common multiple of rates */
-  st_rate_t inskip, outskip;	 /* LCM increments for I & O rates */
+  st_rate_t lcmrate;             /* least common multiple of rates */
+  st_rate_t inskip, outskip;     /* LCM increments for I & O rates */
   double Factor;                 /* out_rate/in_rate               */
-  ulong total;          	 /* number of filter stages        */
-  st_size_t oskip;   	         /* output samples to skip at start*/
+  unsigned long total;           /* number of filter stages        */
+  st_size_t oskip;               /* output samples to skip at start*/
   double inpipe;                 /* output samples 'in the pipe'   */
   polystage *stage[MF];          /* array of pointers to polystage structs */
 
@@ -64,7 +64,7 @@
  * Process options
  */
 
-/* Options:  
+/* Options:
 
    -w <nut / ham>        :  window type
    -width <short / long> :  window width
@@ -71,7 +71,7 @@
                             short = 128 samples
                             long  = 1024 samples
    <num>                    num:  explicit number
- 
+
    -cutoff <float>       :  frequency cutoff for base bandwidth.
                             Default = 0.95 = 95%
 */
@@ -79,8 +79,8 @@
 static int win_type  = 0;
 static int win_width = 1024;
 static Float cutoff = 0.95;
-   
-int st_poly_getopts(eff_t effp, int n, char **argv) 
+
+int st_poly_getopts(eff_t effp, int n, char **argv)
 {
   /* 0: nuttall
      1: hamming */
@@ -194,10 +194,10 @@
   int *q;
 
   p=l; q=m;
-  while (ct1>ct) { *q++=1; ct++;} 
+  while (ct1>ct) { *q++=1; ct++;}
   while ((*q++=*p++)) ;
   if (ct<=1) return ct;
-  
+
   for (k=ct; k>1; ) {
     int tmp;
     unsigned long j;
@@ -278,7 +278,7 @@
        memcpy(b2,m2,u*sizeof(int));
       }
      fail:
-      	;;
+        ;;
     }
     if (u_min) break;
   }
@@ -313,9 +313,9 @@
   N1 = length/2;
 
   for(j = 0; j < length; j++) {
-    buffer[j] = 0.36335819 + 
+    buffer[j] = 0.36335819 +
       0.4891775 * cos(2*PI*1*(j - N1) / N) +
-      0.1365995 * cos(2*PI*2*(j - N1) / N) + 
+      0.1365995 * cos(2*PI*2*(j - N1) / N) +
       0.0106411 * cos(2*PI*3*(j - N1) / N);
   }
 }
@@ -332,7 +332,7 @@
       st_fail("Illegal buffer %p or length %d to hamming.\n",buffer,length);
 
     N1 = length/2;
-    for(j=0;j<length;j++) 
+    for(j=0;j<length;j++)
       buffer[j] = 0.5 - 0.46 * cos(PI*j/N1);
 }
 
@@ -339,7 +339,7 @@
 /* Calculate the sinc function properly */
 
 static Float sinc(Float value)
-{   
+{
     return(fabs(value) < 1E-50 ? 1.0 : sin(value) / value);
 }
 
@@ -358,7 +358,7 @@
       st_fail("Illegal buffer %p, length %d, or cutoff %f.\n",buffer,length,cutoff);
 
     /* Use the user-option of window type */
-    if(win_type == 0) 
+    if(win_type == 0)
       nuttall(buffer, length); /* Design Nuttall window:  ** dB cutoff */
     else
       hamming(buffer,length);  /* Design Hamming window:  43 dB cutoff */
@@ -378,7 +378,7 @@
     }
     /* st_report("# end\n\n"); */
 }
- 
+
 #define RIBLEN 2048
 
 int st_poly_start(eff_t effp)
@@ -391,24 +391,24 @@
 
     if (effp->ininfo.rate == effp->outinfo.rate)
     {
-	st_fail("Input and Output rate must not be the same to use polyphase effect");
-	return(ST_EOF);
+        st_fail("Input and Output rate must not be the same to use polyphase effect");
+        return(ST_EOF);
     }
 
     st_initrand();
 
-    rate->lcmrate = st_lcm((st_sample_t)effp->ininfo.rate, 
-	                   (st_sample_t)effp->outinfo.rate);
+    rate->lcmrate = st_lcm((st_sample_t)effp->ininfo.rate,
+                           (st_sample_t)effp->outinfo.rate);
 
-    /* Cursory check for LCM overflow.  
+    /* Cursory check for LCM overflow.
      * If both rate are below 65k, there should be no problem.
      * 16 bits x 16 bits = 32 bits, which we can handle.
      */
 
     rate->inskip = rate->lcmrate / effp->ininfo.rate;
-    rate->outskip = rate->lcmrate / effp->outinfo.rate; 
-    rate->Factor = (double)rate->inskip / (double)rate->outskip; 
-    rate->inpipe = 0; 
+    rate->outskip = rate->lcmrate / effp->outinfo.rate;
+    rate->Factor = (double)rate->inskip / (double)rate->outskip;
+    rate->inpipe = 0;
     {
       int f = RIBLEN/max(rate->inskip,rate->outskip);
       if (f == 0) f = 1;
@@ -458,14 +458,14 @@
       fir_design(s->filt_array, f_len, cutoff/f_cutoff);
       /* s->filt_array[f_len-1]=0; */
 
-			skip *= s->up;
-			skip += f_len;
-			skip /= s->down;
+                        skip *= s->up;
+                        skip += f_len;
+                        skip /= s->down;
 
-			size = (size * s->up) / s->down;  /* this is integer */
+                        size = (size * s->up) / s->down;  /* this is integer */
     }
     rate->oskip = skip/2;
-		{ /* bogus last stage is for output buffering */
+                { /* bogus last stage is for output buffering */
       polystage *s;
       rate->stage[k] = s = (polystage*) malloc(sizeof(polystage));
       s->up = s->down = 0;
@@ -498,7 +498,7 @@
   }
   return sum;
 }
-    
+
 static void polyphase(Float *output, polystage *s)
 {
   int mm;
@@ -537,15 +537,15 @@
 
 static st_sample_t clipfloat(Float sample)
 {
-	if (sample > ST_SAMPLE_MAX)
-	return ST_SAMPLE_MAX;
-	if (sample < -ST_SAMPLE_MAX)
-	return -ST_SAMPLE_MAX;
-	return sample;
+        if (sample > ST_SAMPLE_MAX)
+        return ST_SAMPLE_MAX;
+        if (sample < -ST_SAMPLE_MAX)
+        return -ST_SAMPLE_MAX;
+        return sample;
 }
 
-int st_poly_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
-	         st_size_t *isamp, st_size_t *osamp)
+int st_poly_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
+                 st_size_t *isamp, st_size_t *osamp)
 {
   poly_t rate = (poly_t) effp->priv;
   polystage *s0,*s1;
@@ -556,7 +556,7 @@
   s1 = rate->stage[rate->total];  /* the 'last' stage is output buffer */
   {
     int in_size, gap, k;
-    
+
     in_size = *isamp;
     gap = s0->size - s0->held; /* space available in this 'input' buffer */
     if ((in_size > gap) || (ibuf==NULL)) {
@@ -564,10 +564,10 @@
     }
     if (in_size > 0) {
       Float *q;
-			q = s0->window + s0->hsize;
+                        q = s0->window + s0->hsize;
       if (s0!=s1) q += s0->held;  /* the last (output) buffer doesn't shift history */
       if (ibuf != NULL) {
-				rate->inpipe += rate->Factor * in_size;
+                                rate->inpipe += rate->Factor * in_size;
         for (k=0; k<in_size; k++)
           *q++ = (Float)ibuf[k] / ISCALE;
       } else { /* ibuf==NULL is draining */
@@ -585,14 +585,14 @@
     for(k=0; k<rate->total; k++) {
       polystage *s;
       Float *out;
-  
+
       s = rate->stage[k];
-  
+
       out = rate->stage[k+1]->window + rate->stage[k+1]->hsize;
-  
+
       /* st_report("k=%d  insize=%d\n",k,in_size); fflush(stderr); */
       polyphase(out, s);
-   
+
       /* copy input history into lower portion of rate->window[k] */
       update_hist(s->window, s->hsize, s->size);
       s->held = 0;
@@ -611,24 +611,24 @@
     int k;
 
     oskip = rate->oskip;
-		out_size = s1->held;
-		out_buf = s1->window + s1->hsize;
+                out_size = s1->held;
+                out_buf = s1->window + s1->hsize;
 
     if(ibuf == NULL && out_size > ceil(rate->inpipe)) {
       out_size = ceil(rate->inpipe);
     }
 
-		if (out_size > oskip + *osamp) out_size = oskip + *osamp;
+                if (out_size > oskip + *osamp) out_size = oskip + *osamp;
 
     for(q=obuf, k=oskip; k < out_size; k++)
       *q++ = clipfloat(out_buf[k] * ISCALE); /* should clip-limit */
 
-		*osamp = q-obuf;
-		rate->inpipe -= *osamp;
-		oskip -= out_size - *osamp;
-		rate->oskip = oskip;
+                *osamp = q-obuf;
+                rate->inpipe -= *osamp;
+                oskip -= out_size - *osamp;
+                rate->oskip = oskip;
 
-		s1->hsize += out_size;
+                s1->hsize += out_size;
     s1->held -= out_size;
     if (s1->held == 0) {
       s1->hsize = 0;
@@ -651,8 +651,8 @@
 }
 
 /*
- * Do anything required when you stop reading samples.  
- * Don't close input file! 
+ * Do anything required when you stop reading samples.
+ * Don't close input file!
  */
 int st_poly_stop(eff_t effp)
 {
--- a/src/raw.c
+++ b/src/raw.c
@@ -48,14 +48,14 @@
 int st_rawseek(ft_t ft, st_size_t offset)
 {
     switch(ft->info.size) {
-	case ST_SIZE_BYTE:
-	case ST_SIZE_WORD:
-	case ST_SIZE_DWORD:
-	case ST_SIZE_DDWORD:
-	    break;
-	default:
-	    st_fail_errno(ft,ST_ENOTSUP,"Can't seek this data size");
-	    return(ft->st_errno);
+        case ST_SIZE_BYTE:
+        case ST_SIZE_WORD:
+        case ST_SIZE_DWORD:
+        case ST_SIZE_DDWORD:
+            break;
+        default:
+            st_fail_errno(ft,ST_ENOTSUP,"Can't seek this data size");
+            return(ft->st_errno);
     }
 
     ft->st_errno = st_seek(ft,offset*ft->info.size,SEEK_SET);
@@ -68,8 +68,8 @@
     ft->file.buf = malloc(BUFSIZ);
     if (!ft->file.buf)
     {
-	st_fail_errno(ft,ST_ENOMEM,"Unable to alloc resources");
-	return(ST_EOF);
+        st_fail_errno(ft,ST_ENOMEM,"Unable to alloc resources");
+        return(ST_EOF);
     }
     ft->file.size = BUFSIZ;
     ft->file.count = 0;
@@ -84,8 +84,8 @@
     ft->file.buf = malloc(BUFSIZ);
     if (!ft->file.buf)
     {
-	st_fail_errno(ft,ST_ENOMEM,"Unable to alloc resources");
-	return(ST_EOF);
+        st_fail_errno(ft,ST_ENOMEM,"Unable to alloc resources");
+        return(ST_EOF);
     }
     ft->file.size = BUFSIZ;
     ft->file.pos = 0;
@@ -98,13 +98,13 @@
 {
     while (len)
     {
-	uint8_t datum;
+        uint8_t datum;
 
-	datum = *((unsigned char *)buf2);
-	buf2++;
+        datum = *((unsigned char *)buf2);
+        buf2++;
 
-	*buf1++ = ST_UNSIGNED_BYTE_TO_SAMPLE(datum);
-	len--;
+        *buf1++ = ST_UNSIGNED_BYTE_TO_SAMPLE(datum);
+        len--;
     }
 }
 
@@ -122,8 +122,8 @@
     }
 }
 
-void st_ulaw_read_buf(st_sample_t *buf1, char *buf2, st_ssize_t len, 
-	              char swap)
+void st_ulaw_read_buf(st_sample_t *buf1, char *buf2, st_ssize_t len,
+                      char swap)
 {
     while (len)
     {
@@ -137,8 +137,8 @@
     }
 }
 
-void st_alaw_read_buf(st_sample_t *buf1, char *buf2, st_ssize_t len, 
-	              char swap)
+void st_alaw_read_buf(st_sample_t *buf1, char *buf2, st_ssize_t len,
+                      char swap)
 {
     while (len)
     {
@@ -311,7 +311,7 @@
                     break;
                 case ST_ENCODING_FLOAT:
                     read_buf = st_f32_read_buf;
-		    break;
+                    break;
                 default:
                     st_fail_errno(ft,ST_EFMT,"Do not support this encoding for this data size");
                     return(0);
@@ -391,8 +391,8 @@
 {
     while (len)
     {
-	*(uint8_t *)buf1++ = ST_SAMPLE_TO_UNSIGNED_BYTE(*buf2++);
-	len--;
+        *(uint8_t *)buf1++ = ST_SAMPLE_TO_UNSIGNED_BYTE(*buf2++);
+        len--;
     }
 }
 
@@ -400,28 +400,28 @@
 {
     while (len)
     {
-	*(int8_t *)buf1++ = ST_SAMPLE_TO_SIGNED_BYTE(*buf2++);
-	len--;
+        *(int8_t *)buf1++ = ST_SAMPLE_TO_SIGNED_BYTE(*buf2++);
+        len--;
     }
 }
 
-void st_ulaw_write_buf(char *buf1, st_sample_t *buf2, st_ssize_t len, 
-    	               char swap)
+void st_ulaw_write_buf(char *buf1, st_sample_t *buf2, st_ssize_t len,
+                       char swap)
 {
     while (len)
     {
-	*(uint8_t *)buf1++ = ST_SAMPLE_TO_ULAW_BYTE(*buf2++);
-	len--;
+        *(uint8_t *)buf1++ = ST_SAMPLE_TO_ULAW_BYTE(*buf2++);
+        len--;
     }
 }
 
-void st_alaw_write_buf(char *buf1, st_sample_t *buf2, st_ssize_t len, 
-	               char swap)
+void st_alaw_write_buf(char *buf1, st_sample_t *buf2, st_ssize_t len,
+                       char swap)
 {
     while (len)
     {
-	*(uint8_t *)buf1++ = ST_SAMPLE_TO_ALAW_BYTE(*buf2++);
-	len--;
+        *(uint8_t *)buf1++ = ST_SAMPLE_TO_ALAW_BYTE(*buf2++);
+        len--;
     }
 }
 
@@ -431,7 +431,7 @@
     {
         uint16_t datum;
 
-	datum = ST_SAMPLE_TO_UNSIGNED_WORD(*buf2++);
+        datum = ST_SAMPLE_TO_UNSIGNED_WORD(*buf2++);
         if (swap)
             datum = st_swapw(datum);
         *(uint16_t *)buf1 = datum;
@@ -447,7 +447,7 @@
     {
         int16_t datum;
 
-	datum = ST_SAMPLE_TO_SIGNED_WORD(*buf2++);
+        datum = ST_SAMPLE_TO_SIGNED_WORD(*buf2++);
         if (swap)
             datum = st_swapw(datum);
         *(int16_t *)buf1 = datum;
@@ -463,7 +463,7 @@
     {
         uint32_t datum;
 
-	datum = ST_SAMPLE_TO_UNSIGNED_DWORD(*buf2++);
+        datum = ST_SAMPLE_TO_UNSIGNED_DWORD(*buf2++);
         if (swap)
             datum = st_swapdw(datum);
         *(uint32_t *)buf1 = datum;
@@ -479,7 +479,7 @@
     {
         int32_t datum;
 
-	datum = ST_SAMPLE_TO_SIGNED_DWORD(*buf2++);
+        datum = ST_SAMPLE_TO_SIGNED_DWORD(*buf2++);
         if (swap)
             datum = st_swapdw(datum);
         *(int32_t *)buf1 = datum;
@@ -495,7 +495,7 @@
     {
         float datum;
 
-	datum = ST_SAMPLE_TO_FLOAT_DWORD(*buf2++);
+        datum = ST_SAMPLE_TO_FLOAT_DWORD(*buf2++);
         if (swap)
             datum = st_swapf(datum);
         *(float *)buf1 = datum;
@@ -511,7 +511,7 @@
     {
         double datum;
 
-	datum = ST_SAMPLE_TO_FLOAT_DDWORD(*buf2++);
+        datum = ST_SAMPLE_TO_FLOAT_DDWORD(*buf2++);
         if (swap)
             datum = st_swapf(datum);
         *(double *)buf1 = datum;
@@ -527,7 +527,7 @@
 {
         if (fwrite(ft->file.buf, 1, ft->file.pos, ft->fp) != ft->file.pos)
         {
-	    ft->file.eof = ST_EOF;
+            ft->file.eof = ST_EOF;
         }
         ft->file.pos = 0;
 }
@@ -593,7 +593,7 @@
                     break;
                 case ST_ENCODING_FLOAT:
                     write_buf = st_f32_write_buf;
-		    break;
+                    break;
                 default:
                     st_fail_errno(ft,ST_EFMT,"Do not support this encoding for this data size");
                     return(0);
@@ -618,15 +618,15 @@
 
     while (done < nsamp && !ft->file.eof)
     {
-	if (ft->file.pos > (ft->file.size-ft->info.size))
-	{
-	    writeflush(ft);
-	}
+        if (ft->file.pos > (ft->file.size-ft->info.size))
+        {
+            writeflush(ft);
+        }
 
-    	len = MIN(nsamp,(ft->file.size-ft->file.pos)/ft->info.size);
+        len = MIN(nsamp-done,(ft->file.size-ft->file.pos)/ft->info.size);
         if (len)
         {
-    	    write_buf(ft->file.buf + ft->file.pos, buf+done, len, ft->swap);
+            write_buf(ft->file.buf + ft->file.pos, buf+done, len, ft->swap);
             ft->file.pos += (len*ft->info.size);
             done += len;
         }
--- a/src/stat.c
+++ b/src/stat.c
@@ -2,8 +2,8 @@
  * July 5, 1991
  * Copyright 1991 Lance Norskog And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Lance Norskog And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Lance Norskog And Sundry Contributors are not responsible for
  * the consequences of using this software.
  */
 
@@ -22,23 +22,23 @@
 
 /* Private data for STAT effect */
 typedef struct statstuff {
-	double	min, max, mid;
-	double	asum;
-	double	sum1, sum2;	/* amplitudes */
-	double	dmin, dmax;
-	double	dsum1, dsum2;	/* deltas */
-	double	scale;		/* scale-factor    */
-	double	last;		/* previous sample */
-	st_size_t read;		/* samples processed */
-	int	volume;
-	int	srms;
-	int	fft;
-	ulong   bin[4];
-	double  *re;
-	double  *im;
-	ulong   fft_bits;
-	ulong   fft_size;
-	ulong   fft_offset;
+        double  min, max, mid;
+        double  asum;
+        double  sum1, sum2;     /* amplitudes */
+        double  dmin, dmax;
+        double  dsum1, dsum2;   /* deltas */
+        double  scale;          /* scale-factor    */
+        double  last;           /* previous sample */
+        st_size_t read;         /* samples processed */
+        int     volume;
+        int     srms;
+        int     fft;
+        unsigned long   bin[4];
+        double  *re;
+        double  *im;
+        unsigned long   fft_bits;
+        unsigned long   fft_size;
+        unsigned long   fft_offset;
 } *stat_t;
 
 
@@ -45,60 +45,60 @@
 /*
  * Process options
  */
-int st_stat_getopts(eff_t effp, int n, char **argv) 
+int st_stat_getopts(eff_t effp, int n, char **argv)
 {
-	stat_t stat = (stat_t) effp->priv;
+        stat_t stat = (stat_t) effp->priv;
 
-	stat->scale = ST_SAMPLE_MAX;
-	stat->volume = 0;
-	stat->srms = 0;
-	stat->fft = 0;
+        stat->scale = ST_SAMPLE_MAX;
+        stat->volume = 0;
+        stat->srms = 0;
+        stat->fft = 0;
 
-	while (n>0)
-	{
-		if (!(strcmp(argv[0], "-v"))) 
-		{
-			stat->volume = 1;
-		}
-		else if (!(strcmp(argv[0], "-s"))) 
-		{
-			double scale;
+        while (n>0)
+        {
+                if (!(strcmp(argv[0], "-v")))
+                {
+                        stat->volume = 1;
+                }
+                else if (!(strcmp(argv[0], "-s")))
+                {
+                        double scale;
 
-			if (n <= 1) 
-			{
-			  st_fail("-s option: invalid argument");
-			  return (ST_EOF);
-			}
-			if (!sscanf(argv[1], "%lf", &scale))
-			{
-			  st_fail("-s option: invalid argument");
-			  return (ST_EOF);
-			}
-			stat->scale = scale;
+                        if (n <= 1)
+                        {
+                          st_fail("-s option: invalid argument");
+                          return (ST_EOF);
+                        }
+                        if (!sscanf(argv[1], "%lf", &scale))
+                        {
+                          st_fail("-s option: invalid argument");
+                          return (ST_EOF);
+                        }
+                        stat->scale = scale;
 
-			/* Two option argument.  Account for this */
-	                --n; ++argv;
-		}
-		else if (!(strcmp(argv[0], "-rms"))) 
-		{
-			stat->srms = 1;
-		}
-		else if (!(strcmp(argv[0], "-freq"))) 
-		{
-			stat->fft = 1;
-		}
-		else if (!(strcmp(argv[0], "-d"))) {
-			stat->volume = 2;
-		}
-		else
-		{
-			st_fail("Summary effect: unknown option");
-			return(ST_EOF);
-		}
-	        --n; ++argv;
-	}
-	return (ST_SUCCESS);
-}
+                        /* Two option argument.  Account for this */
+                        --n; ++argv;
+                }
+                else if (!(strcmp(argv[0], "-rms")))
+                {
+                        stat->srms = 1;
+                }
+                else if (!(strcmp(argv[0], "-freq")))
+                {
+                        stat->fft = 1;
+                }
+                else if (!(strcmp(argv[0], "-d"))) {
+                        stat->volume = 2;
+                }
+                else
+                {
+                        st_fail("Summary effect: unknown option");
+                        return(ST_EOF);
+                }
+                --n; ++argv;
+        }
+        return (ST_SUCCESS);
+}
 
 /*
  * Prepare processing.
@@ -105,55 +105,55 @@
  */
 int st_stat_start(eff_t effp)
 {
-	stat_t stat = (stat_t) effp->priv;
-	int i;
-	ulong  bitmask;
+        stat_t stat = (stat_t) effp->priv;
+        int i;
+        unsigned long  bitmask;
 
-	stat->min = stat->max = stat->mid = 0;
-	stat->asum = 0;
-	stat->sum1 = stat->sum2 = 0;
+        stat->min = stat->max = stat->mid = 0;
+        stat->asum = 0;
+        stat->sum1 = stat->sum2 = 0;
 
-	stat->dmin = stat->dmax = 0;
-	stat->dsum1 = stat->dsum2 = 0;
+        stat->dmin = stat->dmax = 0;
+        stat->dsum1 = stat->dsum2 = 0;
 
-	stat->last = 0;
-	stat->read = 0;
+        stat->last = 0;
+        stat->read = 0;
 
-	for (i = 0; i < 4; i++)
-		stat->bin[i] = 0;
+        for (i = 0; i < 4; i++)
+                stat->bin[i] = 0;
 
-	stat->fft_size = 4096;
-	stat->re = 0;
-	stat->im = 0;
+        stat->fft_size = 4096;
+        stat->re = 0;
+        stat->im = 0;
 
-	if (stat->fft)
-	{
-	    bitmask = 0x80000000L;
-	    stat->fft_bits = 31;
-	    stat->fft_offset = 0;
-	    while (bitmask && !(stat->fft_size & bitmask))
-	    {
-		bitmask = bitmask >> 1;
-		stat->fft_bits--;
-	    }
+        if (stat->fft)
+        {
+            bitmask = 0x80000000L;
+            stat->fft_bits = 31;
+            stat->fft_offset = 0;
+            while (bitmask && !(stat->fft_size & bitmask))
+            {
+                bitmask = bitmask >> 1;
+                stat->fft_bits--;
+            }
 
-	    if (bitmask && (stat->fft_size & ~bitmask))
-	    {
-		st_fail("FFT can only use sample buffers of 2^n. Buffer size used is %ld\n",stat->fft_size);
-		return(ST_EOF);
-	    }
+            if (bitmask && (stat->fft_size & ~bitmask))
+            {
+                st_fail("FFT can only use sample buffers of 2^n. Buffer size used is %ld\n",stat->fft_size);
+                return(ST_EOF);
+            }
 
-	    stat->re = malloc(sizeof(double) * stat->fft_size);
-	    stat->im = malloc(sizeof(double) * stat->fft_size);
+            stat->re = malloc(sizeof(double) * stat->fft_size);
+            stat->im = malloc(sizeof(double) * stat->fft_size);
 
-	    if (!stat->re || !stat->im)
-	    {
-		st_fail("Unable to allocate memory for FFT buffers.\n");
-		return (ST_EOF);
-	    }
-	}
+            if (!stat->re || !stat->im)
+            {
+                st_fail("Unable to allocate memory for FFT buffers.\n");
+                return (ST_EOF);
+            }
+        }
 
-	return (ST_SUCCESS);
+        return (ST_SUCCESS);
 }
 
 /*
@@ -163,100 +163,100 @@
 
 extern int FFT(short dir,long m,double *x,double *y);
 
-int st_stat_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+int st_stat_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
                  st_size_t *isamp, st_size_t *osamp)
 {
-	stat_t stat = (stat_t) effp->priv;
-	int len, done, x, x1;
-	short count;
+        stat_t stat = (stat_t) effp->priv;
+        int len, done, x, x1;
+        short count;
         float magnitude;
         float ffa;
 
-	count = 0;
-	len = ((*isamp > *osamp) ? *osamp : *isamp);
-	if (len==0) return (ST_SUCCESS);
+        count = 0;
+        len = ((*isamp > *osamp) ? *osamp : *isamp);
+        if (len==0) return (ST_SUCCESS);
 
-	if (stat->read == 0)	/* 1st sample */
-		stat->min = stat->max = stat->mid = stat->last = (*ibuf)/stat->scale;
+        if (stat->read == 0)    /* 1st sample */
+                stat->min = stat->max = stat->mid = stat->last = (*ibuf)/stat->scale;
 
-	if (stat->fft)
-	{
+        if (stat->fft)
+        {
             for (x = 0; x < len; x++)
             {
-		stat->re[stat->fft_offset] = ibuf[x];
-		stat->im[stat->fft_offset++] = 0;
+                stat->re[stat->fft_offset] = ibuf[x];
+                stat->im[stat->fft_offset++] = 0;
 
-		if (stat->fft_offset >= stat->fft_size)
-		{
-		    stat->fft_offset = 0;
-	            FFT(1,stat->fft_bits,stat->re,stat->im);
-	            ffa = (float)effp->ininfo.rate/stat->fft_size;
-	            for (x1= 0; x1 < stat->fft_size/2; x1++)
-	            {
-	                if (x1 == 0 || x1 == 1)
-	                {
-		            magnitude = 0.0; /* no DC */
-	                }
-	                else
-	                {
-		            magnitude = sqrt(stat->re[x1]*stat->re[x1] + stat->im[x1]*stat->im[x1]);
-		            if (x1 == (stat->fft_size/2) - 1)
-		                magnitude *= 2.0;
-	                }
-	                fprintf(stderr,"%f  %f\n",ffa*x1, magnitude);
-	            }
-		}
+                if (stat->fft_offset >= stat->fft_size)
+                {
+                    stat->fft_offset = 0;
+                    FFT(1,stat->fft_bits,stat->re,stat->im);
+                    ffa = (float)effp->ininfo.rate/stat->fft_size;
+                    for (x1= 0; x1 < stat->fft_size/2; x1++)
+                    {
+                        if (x1 == 0 || x1 == 1)
+                        {
+                            magnitude = 0.0; /* no DC */
+                        }
+                        else
+                        {
+                            magnitude = sqrt(stat->re[x1]*stat->re[x1] + stat->im[x1]*stat->im[x1]);
+                            if (x1 == (stat->fft_size/2) - 1)
+                                magnitude *= 2.0;
+                        }
+                        fprintf(stderr,"%f  %f\n",ffa*x1, magnitude);
+                    }
+                }
 
-	    }
-	}
+            }
+        }
 
 
-	for(done = 0; done < len; done++) {
-		long lsamp;
-		double samp, delta;
-		/* work in scaled levels for both sample and delta */
-		lsamp = *ibuf++;
-		samp = (double)lsamp/stat->scale;
-		stat->bin[RIGHT(lsamp,30)+2]++;
-		*obuf++ = lsamp;
+        for(done = 0; done < len; done++) {
+                long lsamp;
+                double samp, delta;
+                /* work in scaled levels for both sample and delta */
+                lsamp = *ibuf++;
+                samp = (double)lsamp/stat->scale;
+                stat->bin[RIGHT(lsamp,30)+2]++;
+                *obuf++ = lsamp;
 
 
-		if (stat->volume == 2)
-		{
-		    fprintf(stderr,"%08lx ",lsamp);
-		    if (count++ == 5)
-		    {
-			fprintf(stderr,"\n");
-			count = 0;
-		    }
-		}
+                if (stat->volume == 2)
+                {
+                    fprintf(stderr,"%08lx ",lsamp);
+                    if (count++ == 5)
+                    {
+                        fprintf(stderr,"\n");
+                        count = 0;
+                    }
+                }
 
-		/* update min/max */
-		if (stat->min > samp)
-			stat->min = samp;
-		else if (stat->max < samp)
-			stat->max = samp;
-		stat->mid = stat->min / 2 + stat->max / 2;
+                /* update min/max */
+                if (stat->min > samp)
+                        stat->min = samp;
+                else if (stat->max < samp)
+                        stat->max = samp;
+                stat->mid = stat->min / 2 + stat->max / 2;
 
-		stat->sum1 += samp;
-		stat->sum2 += samp*samp;
-		stat->asum += fabs(samp);
-		
-		delta = fabs(samp - stat->last);
-		if (delta < stat->dmin)
-			stat->dmin = delta;
-		else if (delta > stat->dmax)
-			stat->dmax = delta;
+                stat->sum1 += samp;
+                stat->sum2 += samp*samp;
+                stat->asum += fabs(samp);
 
-		stat->dsum1 += delta;
-		stat->dsum2 += delta*delta;
+                delta = fabs(samp - stat->last);
+                if (delta < stat->dmin)
+                        stat->dmin = delta;
+                else if (delta > stat->dmax)
+                        stat->dmax = delta;
 
-		stat->last = samp;
-	}
-	stat->read += len;
-	*isamp = *osamp = len;
-	/* Process all samples */
-	return (ST_SUCCESS);
+                stat->dsum1 += delta;
+                stat->dsum2 += delta*delta;
+
+                stat->last = samp;
+        }
+        stat->read += len;
+        *isamp = *osamp = len;
+        /* Process all samples */
+        return (ST_SUCCESS);
 }
 
 /*
@@ -276,31 +276,31 @@
 
     if (stat->fft && stat->fft_offset)
     {
-	/* When we run out of samples, then we need to pad buffer with
-	 * zeros and then run FFT one last time.  Only perform this
-	 * operation if there are at least 1 sample in the buffer.
-	 */
+        /* When we run out of samples, then we need to pad buffer with
+         * zeros and then run FFT one last time.  Only perform this
+         * operation if there are at least 1 sample in the buffer.
+         */
         for (x = stat->fft_offset; x < stat->fft_size; x++)
         {
-	    stat->re[x] = 0;
-	    stat->im[x] = 0;
+            stat->re[x] = 0;
+            stat->im[x] = 0;
         }
         FFT(1,stat->fft_bits,stat->re,stat->im);
-	ffa = (float)effp->ininfo.rate/stat->fft_size;
-	for (x=0; x < stat->fft_size/2; x++)
-	{
-	    if (x == 0 || x == 1)
-	    {
-		magnitude = 0.0; /* no DC */
-	    }
-	    else
-	    {
-		magnitude = sqrt(stat->re[x]*stat->re[x] + stat->im[x]*stat->im[x]);
-		if (x != (stat->fft_size/2) - 1)
-		    magnitude *= 2.0;
-	    }
-	    fprintf(stderr, "%f  %f\n",ffa*x, magnitude);
-	}
+        ffa = (float)effp->ininfo.rate/stat->fft_size;
+        for (x=0; x < stat->fft_size/2; x++)
+        {
+            if (x == 0 || x == 1)
+            {
+                magnitude = 0.0; /* no DC */
+            }
+            else
+            {
+                magnitude = sqrt(stat->re[x]*stat->re[x] + stat->im[x]*stat->im[x]);
+                if (x != (stat->fft_size/2) - 1)
+                    magnitude *= 2.0;
+            }
+            fprintf(stderr, "%f  %f\n",ffa*x, magnitude);
+        }
     }
 
     *osamp = 0;
@@ -308,70 +308,70 @@
 }
 
 /*
- * Do anything required when you stop reading samples.  
- * Don't close input file! 
+ * Do anything required when you stop reading samples.
+ * Don't close input file!
  */
 int st_stat_stop(eff_t effp)
 {
-	stat_t stat = (stat_t) effp->priv;
-	double amp, scale, rms = 0, freq;
-	double x, ct;
+        stat_t stat = (stat_t) effp->priv;
+        double amp, scale, rms = 0, freq;
+        double x, ct;
 
-	ct = stat->read;
+        ct = stat->read;
 
-	if (stat->srms) {  /* adjust results to units of rms */
-		double f;
-		rms = sqrt(stat->sum2/ct);
-		f = 1.0/rms;
-		stat->max *= f;
-		stat->min *= f;
-		stat->mid *= f;
-		stat->asum *= f;
-		stat->sum1 *= f;
-		stat->sum2 *= f*f;
-		stat->dmax *= f;
-		stat->dmin *= f;
-		stat->dsum1 *= f;
-		stat->dsum2 *= f*f;
-		stat->scale *= rms;
-	}
+        if (stat->srms) {  /* adjust results to units of rms */
+                double f;
+                rms = sqrt(stat->sum2/ct);
+                f = 1.0/rms;
+                stat->max *= f;
+                stat->min *= f;
+                stat->mid *= f;
+                stat->asum *= f;
+                stat->sum1 *= f;
+                stat->sum2 *= f*f;
+                stat->dmax *= f;
+                stat->dmin *= f;
+                stat->dsum1 *= f;
+                stat->dsum2 *= f*f;
+                stat->scale *= rms;
+        }
 
-	scale = stat->scale;
+        scale = stat->scale;
 
-	amp = -stat->min;
-	if (amp < stat->max)
-		amp = stat->max;
+        amp = -stat->min;
+        if (amp < stat->max)
+                amp = stat->max;
 
-	/* Just print the volume adjustment */
-	if (stat->volume == 1 && amp > 0) {
-		fprintf(stderr, "%.3f\n", ST_SAMPLE_MAX/(amp*scale));
-		return (ST_SUCCESS);
-	}
-	if (stat->volume == 2) {
-		fprintf(stderr, "\n\n");
-	}
-	/* print out the info */
-	fprintf(stderr, "Samples read:      %12u\n", stat->read);
-	fprintf(stderr, "Length (seconds):  %12.6f\n", (double)stat->read/effp->ininfo.rate/effp->ininfo.channels);
-	if (stat->srms)
-		fprintf(stderr, "Scaled by rms:     %12.6f\n", rms);
-	else
-		fprintf(stderr, "Scaled by:         %12.1f\n", scale);
-	fprintf(stderr, "Maximum amplitude: %12.6f\n", stat->max);
-	fprintf(stderr, "Minimum amplitude: %12.6f\n", stat->min);
-	fprintf(stderr, "Midline amplitude: %12.6f\n", stat->mid);
-	fprintf(stderr, "Mean    norm:      %12.6f\n", stat->asum/ct);
-	fprintf(stderr, "Mean    amplitude: %12.6f\n", stat->sum1/ct);
-	fprintf(stderr, "RMS     amplitude: %12.6f\n", sqrt(stat->sum2/ct));
+        /* Just print the volume adjustment */
+        if (stat->volume == 1 && amp > 0) {
+                fprintf(stderr, "%.3f\n", ST_SAMPLE_MAX/(amp*scale));
+                return (ST_SUCCESS);
+        }
+        if (stat->volume == 2) {
+                fprintf(stderr, "\n\n");
+        }
+        /* print out the info */
+        fprintf(stderr, "Samples read:      %12u\n", stat->read);
+        fprintf(stderr, "Length (seconds):  %12.6f\n", (double)stat->read/effp->ininfo.rate/effp->ininfo.channels);
+        if (stat->srms)
+                fprintf(stderr, "Scaled by rms:     %12.6f\n", rms);
+        else
+                fprintf(stderr, "Scaled by:         %12.1f\n", scale);
+        fprintf(stderr, "Maximum amplitude: %12.6f\n", stat->max);
+        fprintf(stderr, "Minimum amplitude: %12.6f\n", stat->min);
+        fprintf(stderr, "Midline amplitude: %12.6f\n", stat->mid);
+        fprintf(stderr, "Mean    norm:      %12.6f\n", stat->asum/ct);
+        fprintf(stderr, "Mean    amplitude: %12.6f\n", stat->sum1/ct);
+        fprintf(stderr, "RMS     amplitude: %12.6f\n", sqrt(stat->sum2/ct));
 
-	fprintf(stderr, "Maximum delta:     %12.6f\n", stat->dmax);
-	fprintf(stderr, "Minimum delta:     %12.6f\n", stat->dmin);
-	fprintf(stderr, "Mean    delta:     %12.6f\n", stat->dsum1/(ct-1));
-	fprintf(stderr, "RMS     delta:     %12.6f\n", sqrt(stat->dsum2/(ct-1)));
-	freq = sqrt(stat->dsum2/stat->sum2)*effp->ininfo.rate/(M_PI*2);
-	fprintf(stderr, "Rough   frequency: %12d\n", (int)freq);
+        fprintf(stderr, "Maximum delta:     %12.6f\n", stat->dmax);
+        fprintf(stderr, "Minimum delta:     %12.6f\n", stat->dmin);
+        fprintf(stderr, "Mean    delta:     %12.6f\n", stat->dsum1/(ct-1));
+        fprintf(stderr, "RMS     delta:     %12.6f\n", sqrt(stat->dsum2/(ct-1)));
+        freq = sqrt(stat->dsum2/stat->sum2)*effp->ininfo.rate/(M_PI*2);
+        fprintf(stderr, "Rough   frequency: %12d\n", (int)freq);
 
-	if (amp>0) fprintf(stderr, "Volume adjustment: %12.3f\n", ST_SAMPLE_MAX/(amp*scale));
+        if (amp>0) fprintf(stderr, "Volume adjustment: %12.3f\n", ST_SAMPLE_MAX/(amp*scale));
 
         if (stat->bin[2] == 0 && stat->bin[3] == 0)
                 fprintf(stderr, "\nProbably text, not sound\n");
@@ -380,54 +380,54 @@
                 x = (float)(stat->bin[0] + stat->bin[3]) / (float)(stat->bin[1] + stat->bin[2]);
 
                 if (x >= 3.0)                  /* use opposite encoding */
-		{
+                {
                         if (effp->ininfo.encoding == ST_ENCODING_UNSIGNED)
-			{
+                        {
                                 fprintf (stderr,"\nTry: -t raw -b -s \n");
-			}
+                        }
                         else
-			{
+                        {
                                 fprintf (stderr,"\nTry: -t raw -b -u \n");
-			}
+                        }
 
-		}
+                }
                 else if (x <= 1.0/3.0)
-		{ 
-		    ;;              /* correctly decoded */
-		}
+                {
+                    ;;              /* correctly decoded */
+                }
                 else if (x >= 0.5 && x <= 2.0)       /* use ULAW */
-		{
+                {
                         if (effp->ininfo.encoding == ST_ENCODING_ULAW)
-			{
+                        {
                                 fprintf (stderr,"\nTry: -t raw -b -u \n");
-			}
+                        }
                         else
-			{
+                        {
                                 fprintf (stderr,"\nTry: -t raw -b -U \n");
-			}
-		}
-                else    
-		{
+                        }
+                }
+                else
+                {
                         fprintf (stderr, "\nCan't guess the type\n");
-		}
+                }
         }
 
-	/* Release FFT memory if allocated */
-	if (stat->re)
-	    free((void *)stat->re);
-	if (stat->im)
-	    free((void *)stat->im);
+        /* Release FFT memory if allocated */
+        if (stat->re)
+            free((void *)stat->re);
+        if (stat->im)
+            free((void *)stat->im);
 
-	return (ST_SUCCESS);
+        return (ST_SUCCESS);
 
 }
 
 
 /*
-   This computes an in-place complex-to-complex FFT 
+   This computes an in-place complex-to-complex FFT
    x and y are the real and imaginary arrays of 2^(m-1) points.
    dir =  1 gives forward transform
-   dir = -1 gives reverse transform 
+   dir = -1 gives reverse transform
 */
 int FFT(dir,m,re,im)
 short dir;
@@ -439,7 +439,7 @@
 
    /* Calculate the number of points */
    n = 1;
-   for (i=0;i<m;i++) 
+   for (i=0;i<m;i++)
       n *= 2;
 
    /* Do the bit reversal */
@@ -465,13 +465,13 @@
    }
 
    /* Compute the FFT */
-   c1 = -1.0; 
+   c1 = -1.0;
    c2 = 0.0;
    l2 = 1;
    for (l=0;l<m;l++) {
       l1 = l2;
       l2 <<= 1;
-      u1 = 1.0; 
+      u1 = 1.0;
       u2 = 0.0;
       for (j=0;j<l1;j++) {
          for (i=j;i<n;i+=l2) {
@@ -478,7 +478,7 @@
             i1 = i + l1;
             t1 = u1 * re[i1] - u2 * im[i1];
             t2 = u1 * im[i1] + u2 * re[i1];
-            re[i1] = re[i] - t1; 
+            re[i1] = re[i] - t1;
             im[i1] = im[i] - t2;
             re[i] += t1;
             im[i] += t2;
@@ -488,7 +488,7 @@
          u1 = z;
       }
       c2 = sqrt((1.0 - c1) / 2.0);
-      if (dir == 1) 
+      if (dir == 1)
          c2 = -c2;
       c1 = sqrt((1.0 + c1) / 2.0);
    }
--- a/src/tests.sh
+++ b/src/tests.sh
@@ -217,30 +217,3 @@
 rm -f convert.$ext nmonkey1.wav monkey2.wav
 
 exit
-
-
-./sox $noise -r 8196 -u -b -c 1 ub2.raw -r 8196 ub2.voc 
-echo Comparing ub.raw to ub2.raw
-cmp -l ub.raw ub2.raw
-# skip checksum and rate byte
-echo Comparing $file.voc to ub2.voc, ignoring Comment field
-cmp -l $file.voc ub2.voc | grep -v '^    2[3456]' | grep -v '^    31'
-rm -f ub.raw sb.raw ub2.raw ub2.voc
-./sox $noise $file.au -u -r 8192 -u -b ub.raw
-./sox $noise -r 8192 -u -b ub.raw -U -b ub.au 
-./sox $noise ub.au -u ub2.raw 
-./sox $noise ub.au -w ub2.sf
-rm -f ub.raw ub.au ub2.raw ub.sf 
-./sox $noise ub2.sf ub2.aiff
-./sox $noise ub2.aiff ub3.sf
-echo Comparing ub2.sf to ub3.sf
-cmp -l ub2.sf ub3.sf
-rm -f ub2.sf ub2.aiff ub3.sf
-#
-# Cmp -l of stop.raw and stop2.raw will show that most of the 
-# bytes are 1 apart.  This is quantization error.
-#
-# rm -f stop.raw stop2.raw stop2.au
-# Bytes 23 - 26 are the revision level of VOC file utilities and checksum.
-# We may use different ones than Sound Blaster utilities do.
-# We use 0/1 for the major/minor, SB uses that on the 1.15 utility disk.
--- a/src/wve.c
+++ b/src/wve.c
@@ -14,7 +14,7 @@
 #define PSION_MAGIC     "ALawSoundFile**"
 #define PSION_VERSION   ((short)3856)
 #define PSION_INV_VERSION   ((short)4111)
-#define PSION_HDRSIZE	32
+#define PSION_HDRSIZE   32
 
 typedef struct wvepriv
     {
@@ -22,98 +22,98 @@
     short padding;
     short repeats;
 /* For seeking */
-	st_size_t dataStart;
+        st_size_t dataStart;
     } *wve_t;
 
 static void wvewriteheader(ft_t ft);
 
-int st_wveseek(ft_t ft, st_size_t offset) 
+int st_wveseek(ft_t ft, st_size_t offset)
 {
-	wve_t wve = (wve_t ) ft->priv;
+        wve_t wve = (wve_t ) ft->priv;
 
-	return st_seek(ft,offset*ft->info.size + wve->dataStart,SEEK_SET);
+        return st_seek(ft,offset*ft->info.size + wve->dataStart,SEEK_SET);
 }
 
-int st_wvestartread(ft_t ft) 
+int st_wvestartread(ft_t ft)
 {
-	wve_t p = (wve_t ) ft->priv;
-	char magic[16];
-	short version;
-	int rc;
+        wve_t p = (wve_t ) ft->priv;
+        char magic[16];
+        short version;
+        int rc;
 
-	uint32_t trash;
+        uint32_t trash;
 
-	/* Needed for rawread() */
-	rc = st_rawstartread(ft);
-	if (rc)
-	    return rc;
+        /* Needed for rawread() */
+        rc = st_rawstartread(ft);
+        if (rc)
+            return rc;
 
-	/* WVE is in big endian format.  Swap whats read in
-	 * on little endian machines.
-	 */
-	if (ST_IS_LITTLEENDIAN)
-	{
-		ft->swap = ft->swap ? 0 : 1;
-	}
+        /* WVE is in big endian format.  Swap whats read in
+         * on little endian machines.
+         */
+        if (ST_IS_LITTLEENDIAN)
+        {
+                ft->swap = ft->swap ? 0 : 1;
+        }
 
-	/* Check the magic word (null-terminated) */
+        /* Check the magic word (null-terminated) */
         st_reads(ft, magic, 16);
-	if (strncmp(magic, PSION_MAGIC, 15)==0) {
-		st_report("Found Psion magic word");
-	}
-	else
-	{
-		st_fail_errno(ft,ST_EHDR,"Psion header doesn't start with magic word\nTry the '.al' file type with '-t al -r 8000 filename'");
-		return (ST_EOF);
-	}
+        if (strncmp(magic, PSION_MAGIC, 15)==0) {
+                st_report("Found Psion magic word");
+        }
+        else
+        {
+                st_fail_errno(ft,ST_EHDR,"Psion header doesn't start with magic word\nTry the '.al' file type with '-t al -r 8000 filename'");
+                return (ST_EOF);
+        }
 
         st_readw(ft, &version);
 
-	/* Check for what type endian machine its read on */
-	if (version == PSION_INV_VERSION)
-	{
-		/* This is probably left over from a time before
-		 * testing for endianess was standardized.  Leaving since
-		 * it doesn't hurt.
-		 */
-		ft->swap = ft->swap ? 0 : 1;
-		st_report("Found inverted PSION magic word.  Swapping bytes.");
-	}
-	else if (version == PSION_VERSION)
-	{
-	    st_report("Found PSION magic word");
-	}
-	else
-	{
-	    st_fail_errno(ft,ST_EHDR,"Wrong version in Psion header");
-	    return(ST_EOF);
-	}
+        /* Check for what type endian machine its read on */
+        if (version == PSION_INV_VERSION)
+        {
+                /* This is probably left over from a time before
+                 * testing for endianess was standardized.  Leaving since
+                 * it doesn't hurt.
+                 */
+                ft->swap = ft->swap ? 0 : 1;
+                st_report("Found inverted PSION magic word.  Swapping bytes.");
+        }
+        else if (version == PSION_VERSION)
+        {
+            st_report("Found PSION magic word");
+        }
+        else
+        {
+            st_fail_errno(ft,ST_EHDR,"Wrong version in Psion header");
+            return(ST_EOF);
+        }
 
-     	st_readdw(ft, &(p->length));
+        st_readdw(ft, &(p->length));
 
-	st_readw(ft, &(p->padding));
+        st_readw(ft, &(p->padding));
 
-	st_readw(ft, &(p->repeats));
+        st_readw(ft, &(p->repeats));
 
- 	(void)st_readw(ft, (unsigned short *)&trash);
-  	(void)st_readw(ft, (unsigned short *)&trash);
-	(void)st_readw(ft, (unsigned short *)&trash);
-    
-	ft->info.encoding = ST_ENCODING_ALAW;
-	ft->info.size = ST_SIZE_BYTE;
+        (void)st_readw(ft, (unsigned short *)&trash);
+        (void)st_readw(ft, (unsigned short *)&trash);
+        (void)st_readw(ft, (unsigned short *)&trash);
 
-	if (ft->info.rate != 0)
-	    st_report("WVE must use 8000 sample rate.  Overriding");
-	ft->info.rate = 8000;
+        ft->info.encoding = ST_ENCODING_ALAW;
+        ft->info.size = ST_SIZE_BYTE;
 
-	if (ft->info.channels != -1 && ft->info.channels != 1)
-	    st_report("WVE must only supports 1 channel.  Overriding");
-	ft->info.channels = 1;
+        if (ft->info.rate != 0)
+            st_report("WVE must use 8000 sample rate.  Overriding");
+        ft->info.rate = 8000;
 
-	p->dataStart = ftell(ft->fp);
-	ft->length = p->length/ft->info.size;
+        if (ft->info.channels != -1 && ft->info.channels != 1)
+            st_report("WVE must only supports 1 channel.  Overriding");
+        ft->info.channels = 1;
 
-	return (ST_SUCCESS);
+        p->dataStart = ftell(ft->fp);
+        ft->length = p->length/ft->info.size;
+
+        return (ST_SUCCESS);
 }
 
 /* When writing, the header is supposed to contain the number of
@@ -125,71 +125,72 @@
    if it is not, the unspecified size remains in the header
    (this is illegal). */
 
-int st_wvestartwrite(ft_t ft) 
+int st_wvestartwrite(ft_t ft)
 {
-	wve_t p = (wve_t ) ft->priv;
-	int rc;
+        wve_t p = (wve_t ) ft->priv;
+        int rc;
 
-	/* Needed for rawwrite() */
-	rc = st_rawstartwrite(ft);
-	if (rc)
-	    return ST_EOF;
+        /* Needed for rawwrite() */
+        rc = st_rawstartwrite(ft);
+        if (rc)
+            return ST_EOF;
 
-	/* wve is in big endian format.  Swap whats read in
-	 * on little endian machines.
-	 */
-	if (ST_IS_LITTLEENDIAN)
-	{
-		ft->swap = ft->swap ? 0 : 1;
-	}
+        /* wve is in big endian format.  Swap whats read in
+         * on little endian machines.
+         */
+        if (ST_IS_LITTLEENDIAN)
+        {
+                ft->swap = ft->swap ? 0 : 1;
+        }
 
-	p->length = 0;
-	if (p->repeats == 0)
-	    p->repeats = 1;
+        p->length = 0;
+        if (p->repeats == 0)
+            p->repeats = 1;
 
-	if (ft->info.rate != 0)
-	    st_report("WVE must use 8000 sample rate.  Overriding");
+        if (ft->info.rate != 0)
+            st_report("WVE must use 8000 sample rate.  Overriding");
 
-	if (ft->info.channels != -1 && ft->info.channels != 1)
-	    st_report("WVE must only supports 1 channel.  Overriding");
+        if (ft->info.channels != -1 && ft->info.channels != 1)
+            st_report("WVE must only supports 1 channel.  Overriding");
 
-	ft->info.encoding = ST_ENCODING_ALAW;
-	ft->info.size = ST_SIZE_BYTE;
-	ft->info.rate = 8000;
+        ft->info.encoding = ST_ENCODING_ALAW;
+        ft->info.size = ST_SIZE_BYTE;
+        ft->info.rate = 8000;
 
-	wvewriteheader(ft);
-	return ST_SUCCESS;
+        wvewriteheader(ft);
+        return ST_SUCCESS;
 }
 
 st_ssize_t st_wveread(ft_t ft, st_sample_t *buf, st_ssize_t samp)
 {
-	return st_rawread(ft, buf, samp);
+        return st_rawread(ft, buf, samp);
 }
 
 st_ssize_t st_wvewrite(ft_t ft, st_sample_t *buf, st_ssize_t samp)
 {
-	wve_t p = (wve_t ) ft->priv;
-	p->length += samp * ft->info.size;
-	return st_rawwrite(ft, buf, samp);
+        wve_t p = (wve_t ) ft->priv;
+        p->length += samp * ft->info.size;
+        return st_rawwrite(ft, buf, samp);
 }
 
 int st_wvestopwrite(ft_t ft)
 {
-	if (!ft->seekable)
-	{
-	    st_warn("Header will be have invalid file length since file is not seekable");
-	    return ST_SUCCESS;
-	}
 
-	if (fseek(ft->fp, 0L, 0) != 0)
-	{
-		st_fail_errno(ft,errno,"Can't rewind output file to rewrite Psion header.");
-		return(ST_EOF);
-	}
-	wvewriteheader(ft);
+        /* Call before seeking to flush buffer */
+        return st_rawstopwrite(ft);
 
-	/* Needed for rawwrite() */
-	return st_rawstopwrite(ft);
+        if (!ft->seekable)
+        {
+            st_warn("Header will be have invalid file length since file is not seekable");
+            return ST_SUCCESS;
+        }
+
+        if (fseek(ft->fp, 0L, 0) != 0)
+        {
+                st_fail_errno(ft,errno,"Can't rewind output file to rewrite Psion header.");
+                return(ST_EOF);
+        }
+        wvewriteheader(ft);
 }
 
 static void wvewriteheader(ft_t ft)