shithub: sox

Download patch

ref: f0230901289e423cd58430d51b9e60951b3f1417
parent: 343be1a4a94d4f35f597ed3a5f0bc3e3eacdde4d
author: cbagwell <cbagwell>
date: Thu Apr 12 15:21:12 EDT 2001

Updates from Andreas Menke for speed effects and printf problems.

--- a/Makefile.gcc
+++ b/Makefile.gcc
@@ -38,7 +38,7 @@
           flanger.o highp.o highpass.o lowp.o lowpass.o map.o mask.o pan.o \
           phaser.o pick.o pitch.o polyphas.o rate.o resample.o reverb.o \
           reverse.o speed.o split.o stat.o stretch.o swap.o synth.o \
-	  trimo vibro.o vol.o
+	  trim.o vibro.o vol.o
 
 SOUNDLIB = libst.a
 LIBOBJS = $(FOBJ) $(EOBJ) handlers.o libst.o misc.o util.o getopt.o
@@ -72,7 +72,7 @@
 #
 # gcc's all understand this as do lots of standard compilers.  Try this one
 # first.
-# O		= -O2
+O		= -O2
 
 # getopt() support is defined here.  If you have a built-in
 # getopt() that is compatible with SVR5 then you don't need to
@@ -141,20 +141,24 @@
 #
 # If your sysetem has unistd.h then you'll most like need to add 
 # HAVE_UNISTD_H to your misd defines.
-# MISC_DEFINES = -DHAVE_UNISTD_H
+# MISC_DEFINES_UNI = -DHAVE_UNISTD_H
 #
 # If your system has malloc.h then you'll most likely need to add
 # HAVE_MALLOC_H to your misd defines.
-# MSIC_DEFINS = -DHAVE_UNISTD_H
+# MSIC_DEFINES_MALLOC = -DHAVE_UNISTD_H
 #
 # Testing new improved rate code.  You can use the older version if ther
 # are problems.
-# MISC_DEFINES	= -DUSE_OLD_RATE
+# MISC_DEFINES_OLDRATE	= -DUSE_OLD_RATE
 #
 # For an extra 32k memory, you can include u-law/a-law lookup
 # tables to speed compressiong/decompression of this type data.
-# MISC_DEFINES = -DFAST_ULAW_COMPRESSION -DFAST_ALAW_COMPRESSION 
+# MISC_DEFINES_COMP = -DFAST_ULAW_COMPRESSION -DFAST_ALAW_COMPRESSION 
 
+MISC_DEFINES = $(MISC_DEFINES_UNI) \
+	$(MISC_DEFINES_MALLOC) \
+	$(MISC_DEFINES_OLDRATE)\
+	$(MISC_DEFINES_COMP)
 
 ##############################################################################
 
@@ -203,7 +207,7 @@
 
 sox.o:		sox.c st.h
 
-$(LIBOBJS):	st.h version.h patchlvl.h
+$(LIBOBJS):	st.h
 
 man: sox.1 libst.3
 	$(RM) sox.txt libst.txt
--- a/sox.1
+++ b/sox.1
@@ -107,7 +107,7 @@
 .br
     \fBreverse\fR
 .br
-    \fBspeed\fR \fIfactor\fR
+    \fBspeed\fR [ -c ] \fIfactor\fR
 .br
     \fBsplit\fR
 .br
@@ -989,7 +989,7 @@
 Reverse the sound sample completely.
 Included for finding Satanic subliminals.
 .TP 10
-speed \fIfactor\fB
+speed [ -c ] \fIfactor\fB
 Speed up or down the sound, as a magnetic tape with a speed control. 
 It affects both pitch and time. A factor of 1.0 means no change, 
 and is the default. 
@@ -996,6 +996,7 @@
 2.0 doubles speed, thus time length is cut by a half and pitch 
 is one octave higher. 
 0.5 halves speed thus time length doubles and pitch is one octave lower. 
+If the optional -c parameter is used then the factor is specified in "cents".
 .TP 10
 split
 Turn a mono sample into a stereo sample by copying
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -445,8 +445,7 @@
 			ft->instr.nloops++;
 		} 
 	}
-	if (verbose)
-	  reportInstrument(ft);
+	reportInstrument(ft);
 
 	/* Needed because of st_rawread() */
 	rc = st_rawstartread(ft);
@@ -466,24 +465,24 @@
   int loopNum;
 
   if(ft->instr.nloops > 0)
-    fprintf(stderr, "AIFF Loop markers:\n");
+    st_report("AIFF Loop markers:\n");
   for(loopNum  = 0; loopNum < ft->instr.nloops; loopNum++) {
     if (ft->loops[loopNum].count) {
-      fprintf(stderr, "Loop %d: start: %6d", loopNum, ft->loops[loopNum].start);
-      fprintf(stderr, " end:   %6d", 
+      st_report("Loop %d: start: %6d", loopNum, ft->loops[loopNum].start);
+      st_report(" end:   %6d", 
 	      ft->loops[loopNum].start + ft->loops[loopNum].length);
-      fprintf(stderr, " count: %6d", ft->loops[loopNum].count);
-      fprintf(stderr, " type:  ");
+      st_report(" count: %6d", ft->loops[loopNum].count);
+      st_report(" type:  ");
       switch(ft->loops[loopNum].type & ~ST_LOOP_SUSTAIN_DECAY) {
-      case 0: fprintf(stderr, "off\n"); break;
-      case 1: fprintf(stderr, "forward\n"); break;
-      case 2: fprintf(stderr, "forward/backward\n"); break;
+      case 0: st_report("off\n"); break;
+      case 1: st_report("forward\n"); break;
+      case 2: st_report("forward/backward\n"); break;
       }
     }
   }
-  fprintf(stderr, "Unity MIDI Note: %d\n", ft->instr.MIDInote);
-  fprintf(stderr, "Low   MIDI Note: %d\n", ft->instr.MIDIlow);
-  fprintf(stderr, "High  MIDI Note: %d\n", ft->instr.MIDIhi);
+  st_report("Unity MIDI Note: %d\n", ft->instr.MIDInote);
+  st_report("Low   MIDI Note: %d\n", ft->instr.MIDIlow);
+  st_report("High  MIDI Note: %d\n", ft->instr.MIDIhi);
 }
 
 /* Process a text chunk, allocate memory, display it if verbose and return */
@@ -517,9 +516,7 @@
 			return(ST_EOF);
 		}
 	}
-  if(verbose) {
-    printf("%-10s   \"%s\"\n", chunkDescription, *text);
-  }
+  st_report("%-10s   \"%s\"\n", chunkDescription, *text);
   return(ST_SUCCESS);
 }
 
@@ -573,9 +570,7 @@
 	}
     }
   }
-  if(verbose) {
-    printf("%-10s   \"%s\"\n", chunkDescription, *text);
-  }
+  st_report("%-10s   \"%s\"\n", chunkDescription, *text);
   return(ST_SUCCESS);
 }
 
--- a/src/compand.c
+++ b/src/compand.c
@@ -206,21 +206,21 @@
 
 # ifdef DEBUG
   {
-    printf("Starting compand effect\n");
-    printf("\nRate %ld, size %d, encoding %d, output gain %g.\n",
+    fprintf(stderr, "Starting compand effect\n");
+    fprintf(stderr, "\nRate %ld, size %d, encoding %d, output gain %g.\n",
 	   effp->outinfo.rate, effp->outinfo.size, effp->outinfo.encoding,
 	   l->outgain);
-    printf("%d input channel(s) expected: actually %d\n",
+    fprintf(stderr, "%d input channel(s) expected: actually %d\n",
 	   l->expectedChannels, effp->outinfo.channels);
-    printf("\nAttack and decay rates\n"
+    fprintf(stderr, "\nAttack and decay rates\n"
 	     "======================\n");
     for (i = 0; i < l->expectedChannels; ++i)
-      printf("Channel %d: attack = %-12g decay = %-12g\n",
+      fprintf(stderr, "Channel %d: attack = %-12g decay = %-12g\n",
 	     i, l->attackRate[i], l->decayRate[i]);
-    printf("\nTransfer function (linear values)\n"
+    fprintf(stderr, "\nTransfer function (linear values)\n"
 	     "=================  =============\n");
     for (i = 0; i < l->transferPoints; ++i)
-      printf("%12g -> %-12g\n",
+      fprintf(stderr, "%12g -> %-12g\n",
 	     l->transferIns[i], l->transferOuts[i]);
   }
 # endif
--- a/src/dat.c
+++ b/src/dat.c
@@ -40,6 +40,7 @@
 {
    char inpstr[82];
    char sc;
+   long rate;
 
    while (ft->info.rate == 0) {
       fgets(inpstr, 82, ft->fp);
@@ -50,12 +51,12 @@
 	  st_fail_errno(ft,ST_EHDR,"Cannot determine sample rate.");
 	  return (ST_EOF);
       }
-#ifdef __alpha__
-      sscanf(inpstr," ; Sample Rate %d", &ft->info.rate);
-#else
-      sscanf(inpstr," ; Sample Rate %ld",&ft->info.rate);
-#endif
-      }
+      /* Store in system dependent long to get around cross platform
+       * problems.
+       */
+      sscanf(inpstr," ; Sample Rate %ld", &rate);
+      ft->info.rate = rate;
+   }
 
    if (ft->info.channels == -1)
        ft->info.channels = 1;
--- a/src/ima_rw.c
+++ b/src/ima_rw.c
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "ima_rw.h"
+#include "st.h"
 
 /*
  *
@@ -79,12 +80,11 @@
 	int i, val, state;
 
 	ip = ibuff + 4*ch;     /* input pointer to 4-byte block state-initializer   */
-	/* fprintf(stderr, "IMA_ADPCM ip %p op %p\n", ip,obuff); */
 	i_inc = 4*(chans-1);   /* amount by which to incr ip after each 4-byte read */
 	val = (short)(ip[0] + (ip[1]<<8)); /* need cast for sign-extend */
 	state = ip[2];
 	if (state > ISSTMAX) {
-		fprintf(stderr, "IMA_ADPCM block ch%d initial-state (%d) out of range\n", ch, state);
+		st_warn("IMA_ADPCM block ch%d initial-state (%d) out of range\n", ch, state);
 		fflush(stderr);
 		state = 0;
 	}
@@ -94,7 +94,6 @@
 	op = obuff;
 	*op = val;      /* 1st output sample for this channel */
 	op += o_inc;
-	/* fprintf(stderr, "ch%d val000 .... %.4x %2d\n", ch,val,state); */
 
 	for (i = 1; i < n; i++) {
 		int step,dp,c,cm;
@@ -133,9 +132,7 @@
 		}
 		*op = val;
 		op += o_inc;
-		/* fprintf(stderr, "ch%d val%3d %.4x %.4x %2d\n", ch,i,dp,val,state); */
 	}
-	/* fprintf(stderr, " -> ip %p op %p\n", ip,op); */
 	return;
 }
 
@@ -252,7 +249,6 @@
 	}
 	d2 /= n; /* be sure it's non-negative */
 	if (sho) {
-		fprintf(stderr, "n %d, st %d->%d, d %.1f\n", n, *st, state, sqrt(d2));
 		fflush(stderr);
 	}
 	*st = state;
@@ -315,8 +311,6 @@
 		*st = s0;
 	}
 	d = ImaMashS(ch, chans, ip[0], ip,n,st, obuff, 0);
-	/* printf("%4d %6d %6d\n", s0-s32, d0, d32-d0); */
-	/* printf("%5d %2d\n", AvgDelta(ch,O.chans,ip,32), s0); */
 }
 
 /* mash one block.  if you want to use opt>0, 9 is a reasonable value */
@@ -449,8 +443,6 @@
 #endif
 	*st = s0;
 	d = ImaMashS(ch, O.chans, ip[0], ip,n,st, O.packet, 0);
-	printf("%4d %6d %6d\n", s0-s32, d0, d32-d0);
-	/* printf("%5d %2d\n", AvgDelta(ch,O.chans,ip,32), s0); */
 }
 #endif
 
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -183,8 +183,8 @@
     n /= pr;
   }
   *q = 0;
-  for (pr=0; pr<q-q0; pr++) fprintf(stderr," %d",q0[pr]);
-  fprintf(stderr,"\n");
+  for (pr=0; pr<q-q0; pr++) st_report(" %d",q0[pr]);
+  st_report("\n");
   return (q-q0);
 }
 
@@ -222,8 +222,8 @@
   }
   if (n) *p++=n;
   *p = 0;
-  /*for (k=0; k<p-m; k++) fprintf(stderr," %d",m[k]);*/
-  /*fprintf(stderr,"\n");*/
+  /*for (k=0; k<p-m; k++) st_report(" %d",m[k]);*/
+  /*st_report("\n");*/
   return (p-m);
 }
 
@@ -249,9 +249,9 @@
       cost = 0;
       f = denom;
       u = min(ct1,ct2) + 1;
-      /*fprintf(stderr,"pfacts(%d): ", numer);*/
+      /*st_report("pfacts(%d): ", numer);*/
       u1 = permute(m1,l1,ct1,u,amalg);
-      /*fprintf(stderr,"pfacts(%d): ", denom);*/
+      /*st_report("pfacts(%d): ", denom);*/
       u2 = permute(m2,l2,ct2,u,amalg);
       u = max(u1,u2);
       for (j=0; j<u; j++) {
@@ -265,10 +265,10 @@
         c_min = cost;
         u_min = u;
 #       if 0
-        fprintf(stderr,"c_min %d, [%d-%d]:",c_min,numer,denom);
+        st_report("c_min %d, [%d-%d]:",c_min,numer,denom);
         for (j=0; j<u; j++)
-          fprintf(stderr," (%d,%d)",m1[j],m2[j]);
-        fprintf(stderr,"\n");
+          st_report(" (%d,%d)",m1[j],m2[j]);
+        st_report("\n");
 #       endif
        memcpy(b1,m1,u*sizeof(int));
        memcpy(b2,m2,u*sizeof(int));
@@ -359,12 +359,12 @@
     else
       hamming(buffer,length);  /* Design Hamming window:  43 dB cutoff */
 
-    /* printf("# fir_design length=%d, cutoff=%8.4f\n",length,cutoff); */
+    /* st_report("# fir_design length=%d, cutoff=%8.4f\n",length,cutoff); */
     /* Design filter:  windowed sinc function */
     sum = 0.0;
     for(j=0;j<length;j++) {
       buffer[j] *= sinc(PI*cutoff*(j-length/2)); /* center at length/2 */
-      /* printf("%.1f %.6f\n",(float)j,buffer[j]); */
+      /* st_report("%.1f %.6f\n",(float)j,buffer[j]); */
       sum += buffer[j];
     }
     sum = (double)1.0/sum;
@@ -372,7 +372,7 @@
     for(j=0;j<length;j++) {
       buffer[j] *= sum;
     }
-    /* printf("# end\n\n"); */
+    /* st_report("# end\n\n"); */
 }
  
 #define RIBLEN 2048
@@ -499,7 +499,7 @@
   Float *o_top;
 
   in = s->window + s->hsize;
-  /*for (mm=0; mm<s->filt_len; mm++) fprintf(stderr,"cf_%d %f\n",mm,s->filt_array[mm]);*/
+  /*for (mm=0; mm<s->filt_len; mm++) st_report("cf_%d %f\n",mm,s->filt_array[mm]);*/
   /* assumes s->size divisible by down (now true) */
   o_top = output + (s->size * up) / down;
   /*st_report(" isize %d, osize %d, up %d, down %d, N %d", s->size, o_top-output, up, down, f_len);*/
@@ -541,7 +541,7 @@
   polystage *s0,*s1;
 
   /* Sanity check:  how much can we tolerate? */
-  /* fprintf(stderr, "*isamp=%d *osamp=%d\n",*isamp,*osamp); fflush(stderr); */
+  /* st_report("*isamp=%d *osamp=%d\n",*isamp,*osamp); fflush(stderr); */
   s0 = rate->stage[0];            /* the first stage */
   s1 = rate->stage[rate->total];  /* the 'last' stage is output buffer */
   {
@@ -580,7 +580,7 @@
   
       out = rate->stage[k+1]->window + rate->stage[k+1]->hsize;
   
-      /* fprintf(stderr, "k=%d  insize=%d\n",k,in_size); fflush(stderr); */
+      /* 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] */
--- a/src/sox.c
+++ b/src/sox.c
@@ -84,6 +84,7 @@
 static void statistics(void);
 static LONG volumechange(LONG *buf, LONG ct, double vol);
 static void checkeffect(void);
+static int flow_effect_out(void);
 static int flow_effect(int);
 static int drain_effect(int);
 
@@ -399,7 +400,7 @@
  */
 
 static void process(void) {
-    int e, f, havedata, flowstatus;
+    int e, f, flowstatus;
 
     if( st_gettype(informat) )
 		st_fail("bad input format");	
@@ -521,79 +522,32 @@
     informat->st_errno = 0;
     outformat->st_errno = 0;
 
-    /* Prime while() loop by reading initial chunk of input data. */
-    efftab[0].olen = (*informat->h->read)(informat, 
-                                         efftab[0].obuf, (LONG) BUFSIZ);
+    /* Run input data through effects and get more until olen == 0 */
+    do {
+        efftab[0].olen = (*informat->h->read)(informat, 
+                                              efftab[0].obuf, (LONG) BUFSIZ);
+        efftab[0].odone = 0;
 
-    efftab[0].odone = 0;
+        if (efftab[0].olen == 0)
+	    break;
 
-    /* Change the volume of this initial input data if needed. */
-    if (dovolume)
-	clipped += volumechange(efftab[0].obuf, efftab[0].olen,
-		                volume);
+        /* Change the volume of this initial input data if needed. */
+        if (dovolume)
+	    clipped += volumechange(efftab[0].obuf, efftab[0].olen,
+		                    volume);
 
-    /* Run input data through effects and get more until olen == 0 */
-    while (efftab[0].olen > 0)
-    {
 	/* mark chain as empty */
 	for(e = 1; e < neffects; e++)
 	    efftab[e].odone = efftab[e].olen = 0;
 
-	flowstatus = 0;
+	flowstatus = flow_effect_out();
 
-	do {
-	    ULONG w;
-
-	    /* run entire chain BACKWARDS: pull, don't push.*/
-	    /* this is because buffering system isn't a nice queueing system */
-	    for(e = neffects - 1; e > 0; e--) {
-		flowstatus = flow_effect(e);
-		if (flowstatus)
-		    break;
-	    }
-
-	    /* If outputing and output data was generated then write it */
-	    if (writing&&(efftab[neffects-1].olen>efftab[neffects-1].odone)) 
-	    {
-		w = (* outformat->h->write)(outformat, 
-			                   efftab[neffects-1].obuf, 
-				           (LONG) efftab[neffects-1].olen);
-	        efftab[neffects-1].odone = efftab[neffects-1].olen;
-	    }
-
-	    if (outformat->st_errno)
-		st_fail(outformat->st_errstr);
-
-	    /* If any effect will never again produce data, give up.  This */
-	    /* works because of the pull status: the effect won't be able to */
-	    /* shut us down until all downstream buffers have been emptied. */
-	    if (flowstatus < 0)
-		break;
-
-	    /* if stuff still in pipeline, set up to flow effects again */
-	    havedata = 0;
-	    for(e = 0; e < neffects - 1; e++)
-		if (efftab[e].odone < efftab[e].olen) {
-		    havedata = 1;
-		    break;
-		}
-	} while (havedata);
-
 	/* Negative flowstatus says no more output will ever be generated. */
 	if (flowstatus < 0)
 	    break;
 
-        /* Read another chunk of input data. */
-        efftab[0].olen = (*informat->h->read)(informat, 
-                                             efftab[0].obuf, (LONG) BUFSIZ);
-        efftab[0].odone = 0;
+    } while (1); /* break; efftab[0].olen == 0 */
 
-        /* Change volume of these samples if needed. */
-        if (dovolume)
-	    clipped += volumechange(efftab[0].obuf, efftab[0].olen,
-		                    volume);
-    }
-
     if (informat->st_errno)
 	st_fail(informat->st_errstr);
 
@@ -639,6 +593,53 @@
     }
     if (writing)
         fclose(outformat->fp);
+}
+
+static int flow_effect_out(void)
+{
+    int e, havedata, flowstatus = 0;
+
+    do {
+      ULONG w;
+      
+      /* run entire chain BACKWARDS: pull, don't push.*/
+      /* this is because buffering system isn't a nice queueing system */
+      for(e = neffects - 1; e > 0; e--) 
+      {
+	  flowstatus = flow_effect(e);
+	  if (flowstatus)
+              break;
+      }
+      
+      /* If outputing and output data was generated then write it */
+      if (writing&&(efftab[neffects-1].olen>efftab[neffects-1].odone)) 
+      {
+          w = (* outformat->h->write)(outformat, 
+                                     efftab[neffects-1].obuf, 
+                                     (LONG) efftab[neffects-1].olen);
+          efftab[neffects-1].odone = efftab[neffects-1].olen;
+      }
+      
+      if (outformat->st_errno)
+          st_fail(outformat->st_errstr);
+
+      /* If any effect will never again produce data, give up.  This
+       * works because of the pull status: the effect won't be able to
+       * shut us down until all downstream buffers have been emptied.
+       */
+      if (flowstatus < 0)
+	  break;
+      
+      /* if stuff still in pipeline, set up to flow effects again */
+      havedata = 0;
+      for(e = 0; e < neffects - 1; e++)
+          if (efftab[e].odone < efftab[e].olen) {
+              havedata = 1;
+              break;
+          }
+    } while (havedata);
+
+    return flowstatus;
 }
 
 static int flow_effect(e)
--- a/src/speed.c
+++ b/src/speed.c
@@ -14,6 +14,8 @@
 #include "st.h"
 
 #include <limits.h> /* LONG_MAX */
+#include <math.h> /* pow */
+#include <string.h>
 
 /* type used for computations.
  */
@@ -30,7 +32,7 @@
 #define ONESIXTH           ((SPEED_FLOAT)(1.0e0/6.0e0))
 #define ZERO               ((SPEED_FLOAT)(0.0e0))
 
-#define SPEED_USAGE "speed factor (default 1.0, <1 slows)"
+#define SPEED_USAGE "speed [-c] factor (default 1.0, <1 slows, -c: factor in cent)"
 
 /* automaton status
  */
@@ -115,15 +117,28 @@
      char ** argv;
 {
     speed_t speed = (speed_t) effp->priv;
+    int cent = 0;
 
     speed->factor = ONE; /* default */
 
+    if (n>0 && !strcmp(argv[0], "-c"))
+    {
+	cent = 1;
+	argv++; n--;
+    }
+
     if (n && (!sscanf(argv[0], SPEED_FLOAT_SCAN, &speed->factor) ||
-	      speed->factor<=ZERO))
+	      (cent==0 && speed->factor<=ZERO)))
     {
+	printf("n = %d cent = %d speed = %f\n",n,cent,speed->factor);
 	st_fail(SPEED_USAGE);
 	return ST_EOF;
     }
+    else if (cent != 0) /* CONST==2**(1/1200) */
+    {
+	speed->factor = pow(1.00057778950655, speed->factor);
+	/* fprintf(stderr, "Speed factor: %f\n", speed->factor);*/
+    }
 
     return ST_SUCCESS;
 }
@@ -267,11 +282,23 @@
     transfer(speed);
 
     /* fix up trail by emptying cbuf */
-    for (oindex=0, i=0; i<3 && oindex<*osamp; i++)
+    for (oindex=0, i=0; i<2 && oindex<*osamp;)
     {
-	oindex += compute(speed, obuf+oindex, *osamp-oindex);
-	speed->cbuf[3] = ZERO;
-	speed->icbuf = 4;
+	if (speed->state==sp_input)
+	{
+          speed->ibuf[speed->index++] = ZERO;
+          i++;
+          if (speed->index==speed->compression)
+             speed->state = sp_transfer;
+      }
+
+      /* transfer to compute buffer. */
+      if (speed->state==sp_transfer)
+          transfer(speed);
+
+      /* compute interpolation. */
+      if (speed->state==sp_compute)
+          oindex += compute(speed, obuf+oindex, *osamp-oindex);
     }
 
     *osamp = oindex; /* report how much was generated. */
--- a/src/stat.c
+++ b/src/stat.c
@@ -307,7 +307,7 @@
 		if (x != (stat->fft_size/2) - 1)
 		    magnitude *= 2.0;
 	    }
-	    printf("%f  %f\n",ffa*x, magnitude);
+	    fprintf(stderr, "%f  %f\n",ffa*x, magnitude);
 	}
     }
 
--- a/src/wav.c
+++ b/src/wav.c
@@ -82,7 +82,7 @@
 typedef struct wavstuff {
     LONG	   numSamples;     /* samples/channel reading: starts at total count and decremented  */
     		                   /* writing: starts at 0 and counts samples written */
-    LONG	   dataLength;     /* needed for ADPCM writing */
+    ULONG	   dataLength;     /* needed for ADPCM writing */
     unsigned short formatTag;	   /* What type of encoding file is using */
     unsigned short samplesPerBlock;
     unsigned short blockAlign;
@@ -920,18 +920,18 @@
     default:
 	break;
     }
-/* Horrible way to find Cool Edit marker points. Taken from Quake source*/
-	ft->loops[0].start = -1;
-	if(ft->seekable){
-    /* Skip over data */
-/*Got this from the quake source.  I think it 32bit aligns the chunks 
- * doubt any machine writing Cool Edit Chunks writes them at an odd 
- * offset */
-	len = (len + 1) & ~1;
-    st_seek(ft, len, SEEK_CUR);
-    if( findChunk(ft, "LIST") != ST_EOF){
-	ft->comment = (char*)malloc(256);
-	while(!feof(ft->fp)){
+
+    /* Horrible way to find Cool Edit marker points. Taken from Quake source*/
+    ft->loops[0].start = -1;
+    if(ft->seekable){
+        /*Got this from the quake source.  I think it 32bit aligns the chunks 
+         * doubt any machine writing Cool Edit Chunks writes them at an odd 
+         * offset */
+        len = (len + 1) & ~1;
+        st_seek(ft, len, SEEK_CUR);
+        if( findChunk(ft, "LIST") != ST_EOF){
+	    ft->comment = (char*)malloc(256);
+	    while(!feof(ft->fp)){
 		st_reads(ft,magic,4);
 		if(strncmp(magic,"INFO",4) == 0){
 			/*Skip*/
@@ -969,11 +969,11 @@
 			len = (len + 1) & ~1;
 			st_seek(ft,len-4,SEEK_CUR);
 		}
-	}
-	}
-	clearerr(ft->fp);
-	st_seek(ft,wav->dataStart,SEEK_SET);
-	}	
+	    }
+        }
+        clearerr(ft->fp);
+        st_seek(ft,wav->dataStart,SEEK_SET);
+    }	
     return ST_SUCCESS;
 }