shithub: sox

Download patch

ref: 89f56e2cec3a5c82fd524f02799e81a79ad5f429
parent: b7c61db0a37cbc49d9195233143c640aad1b01d9
author: cbagwell <cbagwell>
date: Wed Oct 31 09:12:27 EST 2001

Adding st_i.h... More 64-bit changes

--- a/src/8svx.c
+++ b/src/8svx.c
@@ -16,7 +16,7 @@
 
 /* Private data used by writer */
 typedef struct svxpriv {
-	st_size_t nsamples;
+	u_int32_t nsamples;
 	FILE *ch[4];
 }*svx_t;
 
@@ -33,10 +33,10 @@
 	char buf[12];
 	char *chunk_buf;
  
-	st_size_t totalsize;
-	st_size_t chunksize;
+	u_int32_t totalsize;
+	u_int32_t chunksize;
 
-	ULONG channels;
+	u_int32_t channels;
 	unsigned short rate;
 	int i;
 
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -86,18 +86,18 @@
 {
 	aiff_t aiff = (aiff_t ) ft->priv;
 	char buf[5];
-	ULONG totalsize;
-	LONG chunksize;
+	u_int32_t totalsize;
+	u_int32_t chunksize;
 	unsigned short channels = 0;
-	ULONG frames;
+	u_int32_t frames;
 	unsigned short bits = 0;
 	double rate = 0.0;
-	ULONG offset = 0;
-	ULONG blocksize = 0;
+	u_int32_t offset = 0;
+	u_int32_t blocksize = 0;
 	int foundcomm = 0, foundmark = 0, foundinstr = 0;
 	struct mark {
 		unsigned short id;
-		ULONG position;
+		u_int32_t position;
 		char name[40]; 
 	} marks[32];
 	unsigned short looptype;
@@ -110,7 +110,9 @@
 	char *copyright;
 	char *nametext;
 
-	ULONG trash;
+	u_int8_t trash8;
+	u_int16_t trash16;
+	u_int32_t trash32;
 
 	int rc;
 
@@ -169,7 +171,7 @@
 			    }
 			}
 			while(chunksize-- > 0)
-			    st_readb(ft, (unsigned char *)&trash);
+			    st_readb(ft, (unsigned char *)&trash8);
 			foundcomm = 1;
 		}
 		else if (strncmp(buf, "SSND", 4) == 0) {
@@ -214,7 +216,7 @@
 				marks[i].name[j] = 0;
 				if ((len & 1) == 0) {
 					chunksize--;
-					st_readb(ft, (unsigned char *)&trash);
+					st_readb(ft, (unsigned char *)&trash8);
 				}
 			}
 			/* HA HA!  Sound Designer (and others) makes */
@@ -221,20 +223,20 @@
 			/* bogus files. It spits out bogus chunksize */
 			/* for MARK field */
 			while(chunksize-- > 0)
-			    st_readb(ft, (unsigned char *)&trash);
+			    st_readb(ft, (unsigned char *)&trash8);
 		}
 		else if (strncmp(buf, "INST", 4) == 0) {
 			/* INST chunk */
 			st_readdw(ft, &chunksize);
 			st_readb(ft, &(ft->instr.MIDInote));
-			st_readb(ft, (unsigned char *)&trash);
+			st_readb(ft, (unsigned char *)&trash8);
 			st_readb(ft, &(ft->instr.MIDIlow));
 			st_readb(ft, &(ft->instr.MIDIhi));
 			/* Low  velocity */
-			st_readb(ft, (unsigned char *)&trash);
+			st_readb(ft, (unsigned char *)&trash8);
 			/* Hi  velocity */
-			st_readb(ft, (unsigned char *)&trash);
-			st_readw(ft, (unsigned short *)&trash);	/* gain */
+			st_readb(ft, (unsigned char *)&trash8);
+			st_readw(ft, (unsigned short *)&trash16);/* gain */
 			st_readw(ft, &looptype); /* sustain loop */
 			ft->loops[0].type = looptype;
 			st_readw(ft, &sustainLoopBegin); /* begin marker */
@@ -249,15 +251,15 @@
 		else if (strncmp(buf, "APPL", 4) == 0) {
 			st_readdw(ft, &chunksize);
 			while(chunksize-- > 0)
-			    st_readb(ft, (unsigned char *)&trash);
+			    st_readb(ft, (unsigned char *)&trash8);
 		}
 		else if (strncmp(buf, "ALCH", 4) == 0) {
 			/* I think this is bogus and gets grabbed by APPL */
 			/* INST chunk */
-			st_readdw(ft, &trash);		/* ENVS - jeez! */
+			st_readdw(ft, &trash32);		/* ENVS - jeez! */
 			st_readdw(ft, &chunksize);
 			while(chunksize-- > 0)
-			    st_readb(ft, (unsigned char *)&trash);
+			    st_readb(ft, (unsigned char *)&trash8);
 		}
 		else if (strncmp(buf, "ANNO", 4) == 0) {
 			rc = textChunk(&(ft->comment), "Annotation:", ft);
@@ -321,7 +323,7 @@
 			/* Skip the chunk using st_readb() so we may read
 			   from a pipe */
 			while (chunksize-- > 0) {
-			    if (st_readb(ft, (unsigned char *)&trash) == ST_EOF)
+			    if (st_readb(ft, (unsigned char *)&trash8) == ST_EOF)
 					break;
 			}
 		}
@@ -350,7 +352,7 @@
 		return(ST_EOF);
 	}
 	while ((LONG) (--offset) >= 0) {
-		if (st_readb(ft, (unsigned char *)&trash) == ST_EOF)
+		if (st_readb(ft, (unsigned char *)&trash8) == ST_EOF)
 		{
 			st_fail_errno(ft,errno,"unexpected EOF while skipping AIFF offset");
 			return(ST_EOF);
@@ -488,7 +490,7 @@
 /* Process a text chunk, allocate memory, display it if verbose and return */
 static int textChunk(char **text, char *chunkDescription, ft_t ft) 
 {
-  LONG chunksize;
+  u_int32_t chunksize;
   st_readdw(ft, &chunksize);
   /* allocate enough memory to hold the text including a terminating \0 */
   *text = (char *) malloc((size_t) chunksize + 1);
@@ -522,9 +524,9 @@
  */
 static int commentChunk(char **text, char *chunkDescription, ft_t ft)
 {
-  LONG chunksize;
+  u_int32_t chunksize;
   unsigned short numComments;
-  LONG timeStamp;
+  u_int32_t timeStamp;
   unsigned short markerId;
   unsigned short totalCommentLength = 0;
   unsigned int commentIndex;
@@ -586,7 +588,7 @@
 int st_aiffstopread(ft_t ft) 
 {
 	char buf[5];
-	ULONG chunksize;
+	u_int32_t chunksize;
 	ULONG trash;
 
 	if (!ft->seekable)
--- a/src/au.c
+++ b/src/au.c
@@ -118,12 +118,12 @@
 	   Any extra bytes (totalling hdr_size - 24) are an
 	   "info" field of unspecified nature, usually a string.
 	   By convention the header size is a multiple of 4. */
-	ULONG magic;
-	ULONG hdr_size;
-	ULONG data_size;
-	ULONG encoding;
-	ULONG sample_rate;
-	ULONG channels;
+	u_int32_t magic;
+	u_int32_t hdr_size;
+	u_int32_t data_size;
+	u_int32_t encoding;
+	u_int32_t sample_rate;
+	u_int32_t channels;
 
 	register int i;
 	char *buf;
--- a/src/avr.c
+++ b/src/avr.c
@@ -38,11 +38,11 @@
   unsigned short midi; /* 0xffff = no MIDI note assigned,
 			  0xffXX = single key note assignment
 			  0xLLHH = key split, low/hi note */
-  ULONG rate;	       /* sample frequency in hertz */
-  ULONG size;	       /* sample length in bytes or words (see rez) */
-  ULONG lbeg;	       /* offset to start of loop in bytes or words.
+  u_int32_t rate;       /* sample frequency in hertz */
+  u_int32_t size;       /* sample length in bytes or words (see rez) */
+  u_int32_t lbeg;       /* offset to start of loop in bytes or words.
 			  set to zero if unused. */
-  ULONG lend;	       /* offset to end of loop in bytes or words.
+  u_int32_t lend;       /* offset to end of loop in bytes or words.
 			  set to sample length if unused. */
   unsigned short res1; /* Reserved, MIDI keyboard split */
   unsigned short res2; /* Reserved, sample compression */
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -44,7 +44,7 @@
 	LONG cksum;
 	int dictentry;
 	int nrbits;
-	ULONG current;
+	u_int32_t current;
 	short sample;
 };
 
@@ -55,8 +55,8 @@
 	struct readpriv *p = (struct readpriv *) ft->priv;
 	int i;
 	char buf[5];
-	ULONG datasize, rsrcsize;
-	ULONG huffcount, checksum, compresstype, divisor;
+	u_int32_t datasize, rsrcsize;
+	u_int32_t huffcount, checksum, compresstype, divisor;
 	unsigned short dictsize;
 	int rc;
 
--- a/src/maud.c
+++ b/src/maud.c
@@ -29,7 +29,7 @@
 
 /* Private data for MAUD file */
 struct maudstuff { /* max. 100 bytes!!!! */
-	ULONG nsamples;
+	u_int32_t nsamples;
 };
 
 static void maudwriteheader(ft_t);
@@ -49,12 +49,12 @@
 	char *chunk_buf;
 	
 	unsigned short bitpersam;
-	ULONG nom;
+	u_int32_t nom;
 	unsigned short denom;
 	unsigned short chaninf;
 	
-	ULONG chunksize;
-	ULONG trash;
+	u_int32_t chunksize;
+	u_int32_t trash32;
 	int rc;
 
 	/* Needed for rawread() */
@@ -77,7 +77,7 @@
 		return (ST_EOF);
 	}
 	
-	st_readdw(ft, &trash); /* totalsize */
+	st_readdw(ft, &trash32); /* totalsize */
 	
 	if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "MAUD", 4) != 0)
 	{
@@ -112,7 +112,7 @@
 			st_readw(ft, &bitpersam);
 
 			/* number of bits per sample after decompression */
-			st_readw(ft, (unsigned short *)&trash);
+			st_readw(ft, (unsigned short *)&trash32);
 
 			st_readdw(ft, &nom);         /* clock source frequency */
 			st_readw(ft, &denom);       /* clock devide           */
@@ -146,9 +146,9 @@
 			
 			st_readw(ft, &chaninf); /* compression type */
 			
-			st_readdw(ft, &trash); /* rest of chunk, unused yet */
-			st_readdw(ft, &trash);
-			st_readdw(ft, &trash);
+			st_readdw(ft, &trash32); /* rest of chunk, unused yet */
+			st_readdw(ft, &trash32);
+			st_readdw(ft, &trash32);
 			
 			if (bitpersam == 8 && chaninf == 0) {
 				ft->info.size = ST_SIZE_BYTE;
--- a/src/misc.c
+++ b/src/misc.c
@@ -60,11 +60,7 @@
  * Returns number of elements read, not bytes read.
  */
 
-LONG st_read(ft, buf, size, len)
-ft_t ft;
-void *buf;
-int size;
-LONG len;
+st_ssize_t st_read(ft_t ft, void *buf, size_t size, st_ssize_t len)
 {
     return fread(buf, size, len, ft->fp);
 }
@@ -73,11 +69,7 @@
  * Returns number of elements writen, not bytes writen.
  */
 
-LONG st_write(ft, buf, size, len)
-ft_t ft;
-void *buf;
-int size;
-LONG len;
+st_ssize_t st_write(ft_t ft, void *buf, size_t size, st_ssize_t len)
 {
     return fwrite(buf, size, len, ft->fp);
 }
@@ -88,11 +80,7 @@
 /* Read n-char string (and possibly null-terminating). 
  * Stop reading and null-terminate string if either a 0 or \n is reached. 
  */
-int
-st_reads(ft, c, len)
-ft_t ft;
-char *c;
-int len;
+int st_reads(ft_t ft, char *c, st_ssize_t len)
 {
     char *sc;
     char in;
@@ -119,10 +107,7 @@
 }
 
 /* Write null-terminated string (without \0). */
-int
-st_writes(ft, c)
-ft_t ft;
-char *c;
+int st_writes(ft_t ft, char *c)
 {
 	if (fwrite(c, 1, strlen(c), ft->fp) != strlen(c))
 	{
@@ -133,12 +118,9 @@
 }
 
 /* Read byte. */
-int
-st_readb(ft, uc)
-ft_t ft;
-unsigned char *uc;
+int st_readb(ft_t ft, u_int8_t *ub)
 {
-	if (fread(uc, 1, 1, ft->fp) != 1)
+	if (fread(ub, 1, 1, ft->fp) != 1)
 	{
 		st_fail_errno(ft,errno,readerr);
 	    return(ST_EOF);
@@ -147,12 +129,9 @@
 }
 
 /* Write byte. */
-int
-st_writeb(ft, uc)
-ft_t ft;
-unsigned char uc;
+int st_writeb(ft_t ft, u_int8_t ub)
 {
-	if (fwrite(&uc, 1, 1, ft->fp) != 1)
+	if (fwrite(&ub, 1, 1, ft->fp) != 1)
 	{
 		st_fail_errno(ft,errno,writerr);
 		return(ST_EOF);
@@ -161,30 +140,24 @@
 }
 
 /* Read word. */
-int
-st_readw(ft, us)
-ft_t ft;
-unsigned short *us;
+int st_readw(ft_t ft, u_int16_t *uw)
 {
-	if (fread(us, 2, 1, ft->fp) != 1)
+	if (fread(uw, 2, 1, ft->fp) != 1)
 	{
 		st_fail_errno(ft,errno,readerr);
 	    return (ST_EOF);
 	}
 	if (ft->swap)
-		*us = st_swapw(*us);
+		*uw = st_swapw(*uw);
 	return ST_SUCCESS;
 }
 
 /* Write word. */
-int
-st_writew(ft, us)
-ft_t ft;
-unsigned short us;
+int st_writew(ft_t ft, u_int16_t uw)
 {
 	if (ft->swap)
-		us = st_swapw(us);
-	if (fwrite(&us, 2, 1, ft->fp) != 1)
+		uw = st_swapw(uw);
+	if (fwrite(&uw, 2, 1, ft->fp) != 1)
 	{
 		st_fail_errno(ft,errno,writerr);
 		return (ST_EOF);
@@ -193,30 +166,24 @@
 }
 
 /* Read double word. */
-int
-st_readdw(ft, ul)
-ft_t ft;
-ULONG *ul;
+int st_readdw(ft_t ft, u_int32_t *udw)
 {
-	if (fread(ul, 4, 1, ft->fp) != 1)
+	if (fread(udw, 4, 1, ft->fp) != 1)
 	{
 		st_fail_errno(ft,errno,readerr);
 	    return (ST_EOF);
 	}
 	if (ft->swap)
-		*ul = st_swapl(*ul);
+		*udw = st_swapl(*udw);
 	return ST_SUCCESS;
 }
 
 /* Write double word. */
-int
-st_writedw(ft, ul)
-ft_t ft;
-ULONG ul;
+int st_writedw(ft_t ft, u_int32_t udw)
 {
 	if (ft->swap)
-		ul = st_swapl(ul);
-	if (fwrite(&ul, 4, 1, ft->fp) != 1)
+		udw = st_swapl(udw);
+	if (fwrite(&udw, 4, 1, ft->fp) != 1)
 	{
 		st_fail_errno(ft,errno,writerr);
 		return (ST_EOF);
@@ -225,10 +192,7 @@
 }
 
 /* Read float. */
-int
-st_readf(ft, f)
-ft_t ft;
-float *f;
+int st_readf(ft_t ft, float *f)
 {
 	if (fread(f, sizeof(float), 1, ft->fp) != 1)
 	{
@@ -240,10 +204,7 @@
 }
 
 /* Write float. */
-int
-st_writef(ft, f)
-ft_t ft;
-float f;
+int st_writef(ft_t ft, float f)
 {
 	float t = f;
 
@@ -258,10 +219,7 @@
 }
 
 /* Read double. */
-int
-st_readdf(ft, d)
-ft_t ft;
-double *d;
+int st_readdf(ft_t ft, double *d)
 {
 	if (fread(d, sizeof(double), 1, ft->fp) != 1)
 	{
@@ -273,10 +231,7 @@
 }
 
 /* Write double. */
-int
-st_writedf(ft, d)
-ft_t ft;
-double d;
+int st_writedf(ft_t ft, double d)
 {
 	if (ft->swap)
 		d = st_swapd(d);
@@ -289,13 +244,11 @@
 }
 
 /* generic swap routine. Swap l and place in to f (datatype length = n) */
-static void
-st_swapb(l, f, n)
-char *l, *f;
-int n;
-{    register int i;
+void st_swapb(char *l, char *f, int n)
+{    
+    register int i;
 
-     for (i= 0; i< n; i++)
+    for (i= 0; i< n; i++)
 	f[i]= l[n-i-1];
 }
 
@@ -303,43 +256,36 @@
 /* Byte swappers, use libc optimized macro's if possible */
 #ifndef HAVE_BYTESWAP_H
 
-unsigned short
-st_swapw(us)
-unsigned short us;
+u_int16_t st_swapw(u_int16_t uw)
 {
-	return ((us >> 8) | (us << 8)) & 0xffff;
+    return ((uw >> 8) | (uw << 8)) & 0xffff;
 }
 
-ULONG
-st_swapl(ul)
-ULONG ul;
+u_int32_t st_swapdw(u_int32_t udw)
 {
-	return (ul >> 24) | ((ul >> 8) & 0xff00) | ((ul << 8) & 0xff0000L) | (ul << 24);
+    return (udw >> 24) | ((udw >> 8) & 0xff00) | ((udw << 8) & 0xff0000L) | (udw << 24);
 }
 
 /* return swapped 32-bit float */
-float
-st_swapf(float f)
+float st_swapf(float f)
 {
-	union {
-	    ULONG l;
-	    float f;
-	} u;
+    union {
+	u_int32_t dw;
+	float f;
+    } u;
 
-	u.f= f;
-	u.l= (u.l>>24) | ((u.l>>8)&0xff00) | ((u.l<<8)&0xff0000L) | (u.l<<24);
-	return u.f;
+    u.f= f;
+    u.dw= (u.dw>>24) | ((u.dw>>8)&0xff00) | ((u.dw<<8)&0xff0000L) | (u.dw<<24);
+    return u.f;
 }
 
 #endif
 
-double
-st_swapd(df)
-double df;
+double st_swapd(double df)
 {
-	double sdf;
-	st_swapb(&df, &sdf, sizeof(double));
-	return (sdf);
+    double sdf;
+    st_swapb((char *)&df, (char *)&sdf, sizeof(double));
+    return (sdf);
 }
 
 
@@ -353,8 +299,7 @@
 int st_effect_nothing_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp) { *osamp = 0; return(ST_SUCCESS); }
 
 /* here for linear interp.  might be useful for other things */
-LONG st_gcd(a, b) 
-LONG a, b;
+st_sample_t st_gcd(st_sample_t a, st_sample_t b) 
 {
 	if (b == 0)
 		return a;
@@ -362,8 +307,7 @@
 		return st_gcd(b, a % b);
 }
 
-LONG st_lcm(a, b)
-LONG a, b;
+st_sample_t st_lcm(st_sample_t a, st_sample_t b)
 {
     /* parenthesize this way to avoid LONG overflow in the product term */
     return a * (b / st_gcd(a, b));
@@ -375,35 +319,33 @@
  * Don't ask me why not all C libraries include it.
  */
 
-static ULONG rand_seed = 1;
+static long rand_seed = 1;
 
-int rand() {
-	rand_seed = (rand_seed * 1103515245L) + 12345L;
-	return ((unsigned int)(rand_seed/65536L) % 32768L);
+int rand(void) {
+    rand_seed = (rand_seed * 1103515245L) + 12345L;
+    return ((unsigned int)(rand_seed/65536L) % 32768L);
 }
 
-void srand(seed) 
-unsigned int seed;
+void srand(unsigned int seed) 
 {
-	rand_seed = seed;
+    rand_seed = seed;
 }
 #endif
 
 /* Util to set initial seed so that we are a little less non-random */
 void st_initrand(void) {
-	time_t t;
+    time_t t;
 
-	time(&t);
-	srand(t);
+    time(&t);
+    srand(t);
 }
 
-LONG st_clip24(l)
-LONG l;
+st_sample_t st_clip24(st_sample_t l)
 {
-    if (l >= ((LONG)1 << 23))
-	return ((LONG)1 << 23) - 1;
-    else if (l <= -((LONG)1 << 23))
-        return -((LONG)1 << 23) + 1;
+    if (l >= ((st_sample_t)1 << 23))
+	return ((st_sample_t)1 << 23) - 1;
+    else if (l <= -((st_sample_t)1 << 23))
+        return -((st_sample_t)1 << 23) + 1;
     else
         return l;
 }
@@ -410,61 +352,51 @@
 
 /* This was very painful.  We need a sine library. */
 
-void st_sine(buf, len, max, depth)
-int *buf;
-LONG len;
-int max;
-int depth;
+void st_sine(int *buf, st_ssize_t len, int max, int depth)
 {
-	long i;
-	int offset;
-	double val;
+    st_ssize_t i;
+    int offset;
+    double val;
 
-	offset = max - depth;
-	for (i = 0; i < len; i++) {
-		val = sin((double)i/(double)len * 2.0 * M_PI);
-		buf[i] = (int) ((1.0 + val) * depth / 2.0);
-	}
+    offset = max - depth;
+    for (i = 0; i < len; i++) {
+	val = sin((double)i/(double)len * 2.0 * M_PI);
+	buf[i] = (int) ((1.0 + val) * depth / 2.0);
+    }
 }
 
-void st_triangle(buf, len, max, depth)
-int *buf;
-LONG len;
-int max;
-int depth;
+void st_triangle(int *buf, st_ssize_t len, int max, int depth)
 {
-	LONG i;
-	int offset;
-	double val;
+    st_ssize_t i;
+    int offset;
+    double val;
 
-	offset = max - 2 * depth;
-	for (i = 0; i < len / 2; i++) {
-		val = i * 2.0 / len;
-		buf[i] = offset + (int) (val * 2.0 * (double)depth);
-	}
-	for (i = len / 2; i < len ; i++) {
-		val = (len - i) * 2.0 / len;
-		buf[i] = offset + (int) (val * 2.0 * (double)depth);
-	}
+    offset = max - 2 * depth;
+    for (i = 0; i < len / 2; i++) {
+	val = i * 2.0 / len;
+	buf[i] = offset + (int) (val * 2.0 * (double)depth);
+    }
+    for (i = len / 2; i < len ; i++) {
+	val = (len - i) * 2.0 / len;
+	buf[i] = offset + (int) (val * 2.0 * (double)depth);
+    }
 }
 
-const char *
-st_version()
+const char *st_version()
 {
-	static char versionstr[20];
-	
-	sprintf(versionstr, "Version %d.%d.%d", 
-		(ST_LIB_VERSION_CODE & 0xff0000) >> 16, 
-		(ST_LIB_VERSION_CODE & 0x00ff00) >> 8,
-		(ST_LIB_VERSION_CODE & 0x0000ff));
-	return(versionstr);
+    static char versionstr[20];
+
+    sprintf(versionstr, "Version %d.%d.%d", 
+	    (ST_LIB_VERSION_CODE & 0xff0000) >> 16, 
+	    (ST_LIB_VERSION_CODE & 0x00ff00) >> 8,
+	    (ST_LIB_VERSION_CODE & 0x0000ff));
+    return(versionstr);
 }
 
 
 #ifndef	HAVE_STRERROR
 /* strerror function */
-char *strerror(errcode)
-int errcode;
+char *strerror(int errcode)
 {
 	static char  nomesg[30];
 	extern int sys_nerr;
@@ -483,57 +415,53 @@
 /* Sets file offset
  * offset in bytes 
  */
-int st_seek(ft,offset,whence) 
-ft_t ft;
-LONG offset;
-int whence;
+int st_seek(ft_t ft, st_size_t offset, int whence) 
 {
-	if( ft->seekable == 0 ){
-/* 
- * If a stream peel off chars else 
- * EPERM 	"Operation not permitted" 
- */
-		if(whence == SEEK_CUR ){
-			if( offset < 0 ){
-				st_fail_errno(ft,ST_EINVAL,"Can't seek backwards in pipe");
-			} else {
-    			while ( offset > 0 && !feof(ft->fp) )
-    			{
-					getc(ft->fp);
-					offset--;
-    			}
-				if(offset)
-					st_fail_errno(ft,ST_EOF,"offset past eof");
-				else 
-					ft->st_errno = ST_SUCCESS;
-			}
-		} else {
-			st_fail_errno(ft,ST_EPERM,"File not seekable");
+    if( ft->seekable == 0 ){
+	/* 
+	 * If a stream peel off chars else 
+	 * EPERM 	"Operation not permitted" 
+	 */
+	if(whence == SEEK_CUR ){
+	    if( offset < 0 ){
+		st_fail_errno(ft,ST_EINVAL,"Can't seek backwards in pipe");
+	    } else {
+		while ( offset > 0 && !feof(ft->fp) )
+		{
+		    getc(ft->fp);
+		    offset--;
 		}
+		if(offset)
+		    st_fail_errno(ft,ST_EOF,"offset past eof");
+		else 
+		    ft->st_errno = ST_SUCCESS;
+	    }
 	} else {
-		if( fseek(ft->fp,offset,whence) == -1 )
-			st_fail_errno(ft,errno,strerror(errno));
-		else
-			ft->st_errno = ST_SUCCESS;
-	}	
-		 
-/* Empty the st file buffer */
-	if( ft->st_errno == ST_SUCCESS ){
-		ft->file.count = 0;
-		ft->file.pos = 0;
-		ft->file.eof = 0;
+	    st_fail_errno(ft,ST_EPERM,"File not seekable");
 	}
+    } else {
+	if( fseek(ft->fp,offset,whence) == -1 )
+	    st_fail_errno(ft,errno,strerror(errno));
+	else
+	    ft->st_errno = ST_SUCCESS;
+    }	
 
-	return(ft->st_errno);
+    /* Empty the st file buffer */
+    if( ft->st_errno == ST_SUCCESS ){
+	ft->file.count = 0;
+	ft->file.pos = 0;
+	ft->file.eof = 0;
+    }
+
+    return(ft->st_errno);
 }
 
-LONG st_filelength(ft)
-ft_t ft;
+st_size_t st_filelength(ft_t ft)
 {
-	
-	struct stat st;
 
-	fstat(fileno(ft->fp), &st);
+    struct stat st;
 
-	return (LONG)st.st_size;
+    fstat(fileno(ft->fp), &st);
+
+    return (LONG)st.st_size;
 }
--- a/src/raw.c
+++ b/src/raw.c
@@ -97,7 +97,7 @@
 }
 
 /* Util to reverse the n chars starting at p. */
-/* FIXME: Move to misc.c */
+/* FIXME: This is already in misc.c */
 static void swapn(char *p, int n)
 {
 	char *q;
@@ -119,9 +119,8 @@
 
 	datum = *((unsigned char *)buf2);
         buf2++;
-	datum ^= 0x80;
 
-	*buf1++ = LEFT(datum,24);
+	*buf1++ = ST_UNSIGNED_BYTE_TO_SAMPLE(datum);
 	len--;
     }
 }
@@ -135,7 +134,7 @@
 	datum = *((unsigned char *)buf2);
         buf2++;
 
-	*buf1++ = LEFT(datum,24);
+	*buf1++ = ST_SIGNED_BYTE_TO_SAMPLE(datum);
 	len--;
     }
 }
@@ -149,7 +148,7 @@
 	datum = *((unsigned char *)buf2);
         buf2++;
 
-	*buf1++ = LEFT(st_ulaw_to_linear(datum),16);
+	*buf1++ = ST_ULAW_BYTE_TO_SAMPLE(datum);
 	len--;
     }
 }
@@ -163,7 +162,7 @@
 	datum = *((unsigned char *)buf2);
         buf2++;
 
-	*buf1++ = LEFT(st_Alaw_to_linear(datum),16);
+	*buf1++ = ST_ALAW_BYTE_TO_SAMPLE(datum);
 	len--;
     }
 }
@@ -178,9 +177,8 @@
         buf2++; buf2++;
 	if (swap)
 	    datum = st_swapw(datum);
-	datum ^= 0x8000;
 
-	*buf1++ = LEFT(datum,16);
+	*buf1++ = ST_UNSIGNED_WORD_TO_SAMPLE(datum);
 	len--;
     }
 }
@@ -196,12 +194,12 @@
 	if (swap)
 	    datum = st_swapw(datum);
 
-	*buf1++ = LEFT(datum,16);
+	*buf1++ = ST_SIGNED_WORD_TO_SAMPLE(datum);
 	len--;
     }
 }
 
-void st_ul_copy_buf(LONG *buf1, char *buf2, ULONG len, char swap)
+void st_udw_copy_buf(LONG *buf1, char *buf2, ULONG len, char swap)
 {
     while (len)
     {
@@ -212,9 +210,7 @@
 	if (swap)
 	    datum = st_swapl(datum);
 
-	datum ^= 0x80000000L;
-
-	*buf1++ = datum;
+	*buf1++ = ST_UNSIGNED_DWORD_TO_SAMPLE(datum);
 	len--;
     }
 }
@@ -230,7 +226,7 @@
 	if (swap)
 	    datum = st_swapl(datum);
 
-	*buf1++ = datum;
+	*buf1++ = ST_SIGNED_DWORD_TO_SAMPLE(datum);
 	len--;
     }
 }
@@ -246,7 +242,7 @@
 	if (swap)
 	    datum = st_swapf(datum);
 
-	*buf1++ = datum;
+	*buf1++ = ST_FLOAT_DWORD_TO_SAMPLE(datum);
 	len--;
     }
 }
@@ -263,7 +259,7 @@
 	if (swap)
 	    datum = st_swapd(datum);
 
-	*buf1++ = datum;
+	*buf1++ = ST_FLOAT_DDWORD_TO_SAMPLE(datum);
 	len--;
     }
 }
@@ -326,7 +322,7 @@
 		    copy_buf = st_sl_copy_buf;
 		    break;
 		case ST_ENCODING_UNSIGNED:
-		    copy_buf = st_ul_copy_buf;
+		    copy_buf = st_udw_copy_buf;
 		    break;
 		default:
 		    st_fail_errno(ft,ST_EFMT,"Do not support this encoding for this data size.");
@@ -517,7 +513,8 @@
 				while(done < nsamp) {
 					int datum;
 					/* scale signed up to long's range */
-					datum = (int) RIGHT(*buf++, 24);
+					datum = 
+					    ST_SAMPLE_TO_SIGNED_BYTE(*buf++);
 					blockputc(ft, datum);
 					done++;
 				}
@@ -526,9 +523,9 @@
 				while(done < nsamp) {
 					int datum;
 					/* scale signed up to long's range */
-					datum = (int) RIGHT(*buf++, 24);
+					datum = 
+					    ST_SAMPLE_TO_UNSIGNED_BYTE(*buf++);
 					/* Convert to unsigned */
-					datum ^= 128;
 					blockputc(ft, datum);
 					done++;
 				}
@@ -537,8 +534,8 @@
 				while(done < nsamp) {
 					short datum;
 					/* scale signed up to long's range */
-					datum = (short) RIGHT(*buf++, 16);
-					datum = st_linear_to_ulaw(datum);
+					datum = 
+					    ST_SAMPLE_TO_ULAW_BYTE(*buf++);
 					blockputc(ft, datum);
 					done++;
 				}
@@ -547,10 +544,8 @@
 				while(done < nsamp) {
 					int datum;
 					/* scale signed up to long's range */
-					datum = (int) RIGHT(*buf++, 16);
-					/* round up to 12 bits of data */
-					datum += 0x8;	/* + 0b1000 */
-					datum = st_linear_to_Alaw(datum);
+					datum =
+					    ST_SAMPLE_TO_ALAW_BYTE(*buf++);
 					blockputc(ft, datum);
 					done++;
 				}
@@ -564,13 +559,11 @@
 				return blockw_sw(ft,buf,nsamp);
 			case ST_ENCODING_UNSIGNED:
 				while(done < nsamp) {
-					int datum;
-					unsigned short s;
+					u_int16_t s;
 					/* scale signed up to long's range */
-					datum = *buf++; 
-					s = RIGHT(datum, 16) ^ 0x8000;
+					s = ST_SAMPLE_TO_UNSIGNED_WORD(*buf++);
 					/* Convert to unsigned */
-					blockw(&s, sizeof(short),ft);
+					blockw(&s, sizeof(u_int16_t),ft);
 					done++;
 				}
 				return done;
@@ -588,7 +581,7 @@
 			case ST_ENCODING_SIGN2:
 				while(done < nsamp) {
 					/* scale signed up to long's range */
-					blockw(buf, sizeof(LONG), ft);
+					blockw(buf, sizeof(u_int32_t), ft);
 					buf++;
 					done++;
 				}
--- a/src/smp.c
+++ b/src/smp.c
@@ -35,8 +35,8 @@
 
 /* Samplevision loop definition structure */
 struct loop {
-	ULONG start; /* Sample count into sample data, not byte count */
-	ULONG end;   /* end point */
+	u_int32_t start; /* Sample count into sample data, not byte count */
+	u_int32_t end;   /* end point */
 	char type;   /* 0 = loop off, 1 = forward, 2 = forw/back */
 	short count;	     /* No of times to loop */
 };
@@ -44,7 +44,7 @@
 /* Samplevision marker definition structure */
 struct marker {
 	char name[10];		/* Ascii Marker name */
-	ULONG position;	/* Sample Number, not byte number */
+	u_int32_t position;	/* Sample Number, not byte number */
 };
 
 /* The trailer following the sample data */
@@ -52,16 +52,16 @@
 	struct loop loops[8];		/* loops */
 	struct marker markers[8];	/* markers */
 	char MIDInote;			/* for unity pitch playback */
-	ULONG rate;			/* in hertz */
-	ULONG SMPTEoffset;		/* in subframes - huh? */
-	ULONG CycleSize;		/* sample count in one cycle of the */
+	u_int32_t rate;			/* in hertz */
+	u_int32_t SMPTEoffset;		/* in subframes - huh? */
+	u_int32_t CycleSize;		/* sample count in one cycle of the */
 					/* sampled sound -1 if unknown */
 };
 
 /* Private data for SMP file */
 typedef struct smpstuff {
-  ULONG NoOfSamps;		/* Sample data count in words */
-	LONG dataStart;
+  u_int32_t NoOfSamps;		/* Sample data count in words */
+  LONG dataStart;
   /* comment memory resides in private data because it's small */
   char comment[COMMENTLEN + NAMELEN + 3];
 } *smp_t;
--- a/src/st.h
+++ b/src/st.h
@@ -42,6 +42,29 @@
 #define ST_SAMPLE_MAX 0x7fffffffL
 #define ST_SAMPLE_MIN (-ST_SAMPLE_MAX - 1L)
 
+#define ST_UNSIGNED_BYTE_TO_SAMPLE(d) (((d) ^ 0x80) << 24)
+#define ST_SIGNED_BYTE_TO_SAMPLE(d) ((d) << 24)
+#define ST_ULAW_BYTE_TO_SAMPLE(d) (st_ulaw_to_linear((d)) << 16)
+#define ST_ALAW_BYTE_TO_SAMPLE(d) (st_Alaw_to_linear((d)) << 16)
+#define ST_UNSIGNED_WORD_TO_SAMPLE(d) (((d) ^ 0x8000) << 16)
+#define ST_SIGNED_WORD_TO_SAMPLE(d) ((d) << 16)
+#define ST_UNSIGNED_DWORD_TO_SAMPLE(d) ((d) ^ 0x80000000L)
+#define ST_SIGNED_DWORD_TO_SAMPLE(d) (d)
+#define ST_FLOAT_DWORD_TO_SAMPLE(d) (d)
+#define ST_FLOAT_DDWORD_TO_SAMPLE(d) (d)
+
+#define ST_SAMPLE_TO_UNSIGNED_BYTE(d) (((d) >> 24) ^ 0x80)
+#define ST_SAMPLE_TO_SIGNED_BYTE(d) (((d) >> 24))
+#define ST_SAMPLE_TO_ULAW_BYTE(d) (st_linear_to_ulaw(((d) >> 16)))
+#define ST_SAMPLE_TO_ALAW_BYTE(d) (st_linear_to_Alaw(((d) >> 16)+0x08))
+#define ST_SAMPLE_TO_UNSIGNED_WORD(d) (((d) >> 16) ^ 0x8000)
+#define ST_SAMPLE_TO_SIGNED_WORD(d) ((d) >> 16)
+#define ST_SAMPLE_TO_UNSIGNED_DWORD(d) ((d) ^ 0x80000000L)
+#define ST_SAMPLE_TO_SIGNED_DWORD(d) (d)
+#define ST_SAMPLE_TO_FLOAT_DWORD(d) (d)
+#define ST_SAMPLE_TO_FLOAT_DDWORD(d) (d)
+
+
 /* Maximum value size type can hold. (Minimum is 0). */
 #define ST_SIZE_MAX 0xffffffffL
 
--- /dev/null
+++ b/src/st_i.h
@@ -1,0 +1,577 @@
+#ifndef ST_I_H
+#define ST_I_H
+/*
+ * Sound Tools Interal - October 11, 2001
+ *
+ *   This file is meant for libst internal use only
+ *
+ * Copyright 2001 Chris Bagwell
+ *
+ * This source code is freely redistributable and may be used for
+ * any purpose.  This copyright notice must be maintained.
+ * Chris Bagwell And Sundry Contributors are not responsible for
+ * the consequences of using this software.
+ */
+
+#include "st.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef HAVE_BYTESWAP_H
+#include <byteswap.h>
+#endif
+
+/* various gcc optimizations and portablity defines */
+#ifdef __GNUC__
+#define NORET __attribute__((noreturn))
+#define INLINE inline
+#else
+#define NORET
+#define INLINE
+#endif
+
+#ifdef USE_REGPARM
+#define REGPARM(n) __attribute__((regparm(n)))
+#else
+#define REGPARM(n)
+#endif
+
+/* declared in misc.c */
+LONG st_clip24(LONG) REGPARM(1);
+void st_sine(int *, LONG, int, int);
+void st_triangle(int *, LONG, int, int);
+
+LONG st_gcd(LONG,LONG) REGPARM(2);
+LONG st_lcm(LONG,LONG) REGPARM(2);
+
+#ifndef HAVE_RAND
+int rand(void);
+void srand(unsigned int seed);
+#endif
+void st_initrand(void);
+
+#ifndef HAVE_STRERROR
+char *strerror(int errorcode);
+#endif
+
+/* Read and write basic data types from "ft" stream.  Uses ft->swap for
+ * possible byte swapping.
+ */
+/* declared in misc.c */
+st_ssize_t st_read(ft_t ft, void *buf, size_t size, st_ssize_t len);
+st_ssize_t st_write(ft_t ft, void *buf, size_t size, st_ssize_t len);
+int st_reads(ft_t ft, char *c, st_ssize_t len);
+int st_writes(ft_t ft, char *c);
+int st_readb(ft_t ft, u_int8_t *ub);
+int st_writeb(ft_t ft, u_int8_t ub);
+int st_readw(ft_t ft, u_int16_t *uw);
+int st_writew(ft_t ft, u_int16_t uw);
+int st_readdw(ft_t ft, u_int32_t *udw);
+int st_writedw(ft_t ft, u_int32_t udw);
+int st_readf(ft_t ft, float *f);
+int st_writef(ft_t ft, float f);
+int st_readdf(ft_t ft, double *d);
+int st_writedf(ft_t ft, double d);
+int st_seek(ft_t ft, st_size_t offset, int whence);
+st_size_t st_filelength(ft_t ft);
+
+/* Utilities to byte-swap values, use libc optimized macro's if possible  */
+#ifdef HAVE_BYTESWAP_H
+#define st_swapw(x) bswap_16(x)
+#define st_swapl(x) bswap_32(x)
+#define st_swapf(x) (float)bswap_32((ULONG)(x))
+#else
+u_int16_t st_swapw(u_int16_t uw);
+u_int32_t st_swapdw(u_int32_t udw);
+float st_swapf(float f);
+#endif
+double st_swapd(double d);
+
+/* util.c */
+void st_report(const char *, ...);
+void st_warn(const char *, ...);
+void st_fail(const char *, ...) NORET;
+void st_fail_errno(ft_t, int, const char *, ...);
+
+int st_is_bigendian(void);
+int st_is_littleendian(void);
+
+#ifdef WORDS_BIGENDIAN
+#define ST_IS_BIGENDIAN 1
+#define ST_IS_LITTLEENDIAN 0
+#else
+#define ST_IS_BIGENDIAN st_is_bigendian()
+#define ST_IS_LITTLEENDIAN st_is_littleendian()
+#endif
+
+/* Warning, this is a MAX value used in the library.  Each format and
+ * effect may have its own limitations of rate.
+ */
+#define ST_MAXRATE      50L * 1024 /* maximum sample rate in library */
+
+#define RIGHT(datum, bits)      ((datum) >> bits)
+#define LEFT(datum, bits)       ((datum) << bits)
+
+#ifndef M_PI
+#define M_PI    3.14159265358979323846
+#endif
+#ifndef M_PI_2
+#define M_PI_2  1.57079632679489661923  /* pi/2 */
+#endif
+
+/*=============================================================================
+ * File Handlers
+ *=============================================================================
+ */
+
+/* The following functions can be used to simply return success if
+ * a file handler or effect doesn't need to do anything special
+ */
+int st_format_nothing(ft_t ft);
+st_ssize_t st_format_nothing_io(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_format_nothing_seek(ft_t ft, st_size_t offset);
+int st_effect_nothing(eff_t effp);
+int st_effect_nothing_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+
+int st_aiffstartread(ft_t ft);
+st_ssize_t st_aiffread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_aiffstopread(ft_t ft);
+int st_aiffstartwrite(ft_t ft);
+st_ssize_t st_aiffwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_aiffstopwrite(ft_t ft);
+int st_aiffseek(ft_t ft, st_size_t offset);
+
+int st_alstartread(ft_t ft);
+int st_alstartwrite(ft_t ft);
+
+#ifdef ALSA_PLAYER
+int st_alsastartread(ft_t ft);
+int st_alsastartwrite(ft_t ft);
+#endif
+
+int st_austartread(ft_t ft);
+st_ssize_t st_auread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_austartwrite(ft_t ft);
+st_ssize_t st_auwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_austopwrite(ft_t ft);
+int st_auseek(ft_t ft, st_size_t offset);
+
+int st_autostartread(ft_t ft);
+int st_autostartwrite(ft_t ft);
+
+int st_avrstartread(ft_t ft);
+int st_avrstartwrite(ft_t ft);
+st_ssize_t st_avrwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_avrstopwrite(ft_t ft);
+
+int st_cdrstartread(ft_t ft);
+st_ssize_t st_cdrread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_cdrstopread(ft_t ft);
+int st_cdrstartwrite(ft_t ft);
+st_ssize_t st_cdrwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_cdrstopwrite(ft_t ft);
+
+int st_cvsdstartread(ft_t ft);
+st_ssize_t st_cvsdread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_cvsdstopread(ft_t ft);
+int st_cvsdstartwrite(ft_t ft);
+st_ssize_t st_cvsdwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_cvsdstopwrite(ft_t ft);
+
+int st_datstartread(ft_t ft);
+st_ssize_t st_datread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_datstartwrite(ft_t ft);
+st_ssize_t st_datwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+
+int st_dvmsstartread(ft_t ft);
+int st_dvmsstartwrite(ft_t ft);
+int st_dvmsstopwrite(ft_t ft);
+
+#ifdef HAVE_LIBGSM
+int st_gsmstartread(ft_t ft);
+st_ssize_t st_gsmread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_gsmstopread(ft_t ft);
+int st_gsmstartwrite(ft_t ft);
+st_ssize_t st_gsmwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_gsmstopwrite(ft_t ft);
+#endif
+
+int st_hcomstartread(ft_t ft);
+st_ssize_t st_hcomread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_hcomstopread(ft_t ft);
+int st_hcomstartwrite(ft_t ft);
+st_ssize_t st_hcomwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_hcomstopwrite(ft_t ft);
+
+int st_maudstartread(ft_t ft);
+st_ssize_t st_maudread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_maudstopread(ft_t ft);
+st_ssize_t st_maudwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_maudstartwrite(ft_t ft);
+int st_maudstopwrite(ft_t ft);
+
+int st_nulstartread(ft_t ft);
+st_ssize_t st_nulread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_nulstopread(ft_t ft);
+int st_nulstartwrite(ft_t ft);
+st_ssize_t st_nulwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_nulstopwrite(ft_t ft);
+
+#ifdef OSS_PLAYER
+int st_ossdspstartread(ft_t ft);
+int st_ossdspstartwrite(ft_t ft);
+#endif
+
+int st_rawstartread(ft_t ft);
+st_ssize_t st_rawread(ft_t ft, st_sample_t *buf, st_ssize_t nsamp);
+int st_rawstopread(ft_t ft);
+int st_rawstartwrite(ft_t ft);
+st_ssize_t st_rawwrite(ft_t ft, st_sample_t *buf, st_ssize_t nsamp);
+int st_rawstopwrite(ft_t ft);
+int st_rawseek(ft_t ft, st_size_t offset);
+
+int st_sbstartread(ft_t ft);
+int st_sbstartwrite(ft_t ft);
+
+int st_sfstartread(ft_t ft);
+int st_sfstartwrite(ft_t ft);
+int st_sfseek(ft_t ft, st_size_t offset);
+
+int st_slstartread(ft_t ft);
+int st_slstartwrite(ft_t ft);
+
+int st_smpstartread(ft_t ft);
+st_ssize_t st_smpread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_smpstartwrite(ft_t ft);
+st_ssize_t st_smpwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_smpstopwrite(ft_t ft);
+int st_smpseek(ft_t ft, st_size_t offset);
+
+int st_sndtstartread(ft_t ft);
+int st_sndtstartwrite(ft_t ft);
+st_ssize_t st_sndtwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_sndtstopwrite(ft_t ft);
+int st_sndseek(ft_t ft, st_size_t offset);
+
+int st_spherestartread(ft_t ft);
+st_ssize_t st_sphereread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_spherestartwrite(ft_t ft);
+st_ssize_t st_spherewrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_spherestopwrite(ft_t ft);
+
+#ifdef SUNAUDIO_PLAYER
+int st_sunstartread(ft_t ft);
+int st_sunstartwrite(ft_t ft);
+#endif
+
+int st_svxstartread(ft_t ft);
+st_ssize_t st_svxread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_svxstopread(ft_t ft);
+int st_svxstartwrite(ft_t ft);
+st_ssize_t st_svxwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_svxstopwrite(ft_t ft);
+
+int st_swstartread(ft_t ft);
+int st_swstartwrite(ft_t ft);
+
+int st_txwstartread(ft_t ft);
+st_ssize_t st_txwread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_txwstopread(ft_t ft);
+int st_txwstartwrite(ft_t ft);
+st_ssize_t st_txwwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_txwstopwrite(ft_t ft);
+
+int st_ubstartread(ft_t ft);
+int st_ubstartwrite(ft_t ft);
+
+int st_ulstartread(ft_t ft);
+int st_ulstartwrite(ft_t ft);
+
+int st_uwstartread(ft_t ft);
+int st_uwstartwrite(ft_t ft);
+
+int st_vocstartread(ft_t ft);
+st_ssize_t st_vocread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_vocstopread(ft_t ft);
+int st_vocstartwrite(ft_t ft);
+st_ssize_t st_vocwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_vocstopwrite(ft_t ft);
+
+#ifdef HAVE_LIBVORBIS
+int st_vorbisstartread(ft_t ft);
+st_ssize_t st_vorbisread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_vorbisstopread(ft_t ft);
+int st_vorbisstartwrite(ft_t ft);
+st_ssize_t st_vorbiswrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_vorbisstopwrite(ft_t ft);
+#endif
+
+int st_wavstartread(ft_t ft);
+st_ssize_t st_wavread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_wavstartwrite(ft_t ft);
+st_ssize_t st_wavwrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_wavstopwrite(ft_t ft);
+int st_wavseek(ft_t ft, st_size_t offset);
+
+int st_wvestartread(ft_t ft);
+st_ssize_t st_wveread(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_wvestartwrite(ft_t ft);
+st_ssize_t st_wvewrite(ft_t ft, st_sample_t *buf, st_ssize_t len);
+int st_wvestopwrite(ft_t ft);
+int st_wveseek(ft_t ft, st_size_t offset);
+
+/*=============================================================================
+ * Effects
+ *=============================================================================
+ */
+int st_avg_getopts(eff_t effp, int argc, char **argv);
+int st_avg_start(eff_t effp);
+int st_avg_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	        st_size_t *isamp, st_size_t *osamp);
+int st_avg_stop(eff_t effp);
+
+int st_band_getopts(eff_t effp, int argc, char **argv);
+int st_band_start(eff_t effp);
+int st_band_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+int st_band_stop(eff_t effp); 
+int st_bandpass_getopts(eff_t effp, int argc, char **argv);
+int st_bandpass_start(eff_t effp);
+
+int st_bandreject_getopts(eff_t effp, int argc, char **argv);
+int st_bandreject_start(eff_t effp);
+
+int st_chorus_getopts(eff_t effp, int argc, char **argv);
+int st_chorus_start(eff_t effp);
+int st_chorus_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	           st_size_t *isamp, st_size_t *osamp);
+int st_chorus_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_chorus_stop(eff_t effp);
+
+int st_compand_getopts(eff_t effp, int argc, char **argv);
+int st_compand_start(eff_t effp);
+int st_compand_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	            st_size_t *isamp, st_size_t *osamp);
+int st_compand_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_compand_stop(eff_t effp);
+
+int st_copy_getopts(eff_t effp, int argc, char **argv); 
+int st_copy_start(eff_t effp);
+int st_copy_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+int st_copy_stop(eff_t effp);
+
+int st_dcshift_getopts(eff_t effp, int argc, char **argv);
+int st_dcshift_start(eff_t effp);
+int st_dcshift_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	            st_size_t *isamp, st_size_t *osamp);
+int st_dcshift_stop(eff_t effp);
+
+int st_deemph_getopts(eff_t effp, int argc, char **argv);
+int st_deemph_start(eff_t effp);
+int st_deemph_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
+	           st_size_t *isamp, st_size_t *osamp);
+int st_deemph_stop(eff_t effp);
+
+int st_earwax_getopts(eff_t effp, int argc, char **argv);
+int st_earwax_start(eff_t effp);
+int st_earwax_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	           st_size_t *isamp, st_size_t *osamp);
+int st_earwax_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_earwax_stop(eff_t effp);
+
+int st_echo_getopts(eff_t effp, int argc, char **argv);
+int st_echo_start(eff_t effp);
+int st_echo_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+int st_echo_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_echo_stop(eff_t effp);
+
+int st_echos_getopts(eff_t effp, int argc, char **argv);
+int st_echos_start(eff_t effp);
+int st_echos_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	          st_size_t *isamp, st_size_t *osamp);
+int st_echos_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_echos_stop(eff_t effp);
+
+int st_fade_getopts(eff_t effp, int argc, char **argv);
+int st_fade_start(eff_t effp);
+int st_fade_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+int st_fade_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_fade_stop(eff_t effp);
+
+int st_filter_getopts(eff_t effp, int argc, char **argv);
+int st_filter_start(eff_t effp);
+int st_filter_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	           st_size_t *isamp, st_size_t *osamp);
+int st_filter_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_filter_stop(eff_t effp);
+
+int st_flanger_getopts(eff_t effp, int argc, char **argv);
+int st_flanger_start(eff_t effp);
+int st_flanger_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	            st_size_t *isamp, st_size_t *osamp);
+int st_flanger_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_flanger_stop(eff_t effp);
+
+int st_highp_getopts(eff_t effp, int argc, char **argv);
+int st_highp_start(eff_t effp);
+int st_highp_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	          st_size_t *isamp, st_size_t *osamp);
+int st_highp_stop(eff_t effp);
+
+int st_highpass_getopts(eff_t effp, int argc, char **argv);
+int st_highpass_start(eff_t effp);
+
+int st_lowp_getopts(eff_t effp, int argc, char **argv);
+int st_lowp_start(eff_t effp);
+int st_lowp_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+int st_lowp_stop(eff_t effp);
+
+int st_lowpass_getopts(eff_t effp, int argc, char **argv);
+int st_lowpass_start(eff_t effp);
+
+int st_map_getopts(eff_t effp, int argc, char **argv);
+int st_map_start(eff_t effp);
+int st_map_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	        st_size_t *isamp, st_size_t *osamp);
+
+int st_mask_getopts(eff_t effp, int argc, char **argv);
+int st_mask_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+
+int st_pan_getopts(eff_t effp, int argc, char **argv);
+int st_pan_start(eff_t effp);
+int st_pan_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	        st_size_t *isamp, st_size_t *osamp);
+int st_pan_stop(eff_t effp);
+
+int st_phaser_getopts(eff_t effp, int argc, char **argv);
+int st_phaser_start(eff_t effp);
+int st_phaser_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	           st_size_t *isamp, st_size_t *osamp);
+int st_phaser_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_phaser_stop(eff_t effp);
+
+int st_pick_getopts(eff_t effp, int argc, char **argv);
+int st_pick_start(eff_t effp);
+int st_pick_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+int st_pick_stop(eff_t effp);
+
+int st_pitch_getopts(eff_t effp, int argc, char **argv);
+int st_pitch_start(eff_t effp);
+int st_pitch_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	          st_size_t *isamp, st_size_t *osamp);
+int st_pitch_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_pitch_stop(eff_t effp);
+
+int st_poly_getopts(eff_t effp, int argc, char **argv);
+int st_poly_start(eff_t effp);
+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_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_poly_stop(eff_t effp);
+
+int st_rate_getopts(eff_t effp, int argc, char **argv);
+int st_rate_start(eff_t effp);
+int st_rate_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+int st_rate_stop(eff_t effp);
+
+int st_resample_getopts(eff_t effp, int argc, char **argv);
+int st_resample_start(eff_t effp);
+int st_resample_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	             st_size_t *isamp, st_size_t *osamp);
+int st_resample_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_resample_stop(eff_t effp);
+
+int st_reverb_getopts(eff_t effp, int argc, char **argv);
+int st_reverb_start(eff_t effp);
+int st_reverb_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	           st_size_t *isamp, st_size_t *osamp);
+int st_reverb_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_reverb_stop(eff_t effp);
+
+int st_reverse_getopts(eff_t effp, int argc, char **argv);
+int st_reverse_start(eff_t effp);
+int st_reverse_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
+	            st_size_t *isamp, st_size_t *osamp);
+int st_reverse_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_reverse_stop(eff_t effp);
+
+int st_silence_getopts(eff_t effp, int argc, char **argv);
+int st_silence_start(eff_t effp);
+int st_silence_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	            st_size_t *isamp, st_size_t *osamp);
+int st_silence_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_silence_stop(eff_t effp);
+
+int st_speed_getopts(eff_t effp, int argc, char **argv);
+int st_speed_start(eff_t effp);
+int st_speed_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	          st_size_t *isamp, st_size_t *osamp);
+int st_speed_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_speed_stop(eff_t effp);
+
+int st_split_getopts(eff_t effp, int argc, char **argv);
+int st_split_start(eff_t effp);
+int st_split_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	          st_size_t *isamp, st_size_t *osamp);
+int st_split_stop(eff_t effp);
+
+int st_stat_getopts(eff_t effp, int argc, char **argv);
+int st_stat_start(eff_t effp);
+int st_stat_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+int st_stat_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_stat_stop(eff_t effp);
+
+int st_stretch_getopts(eff_t effp, int argc, char **argv);
+int st_stretch_start(eff_t effp);
+int st_stretch_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	            st_size_t *isamp, st_size_t *osamp);
+int st_stretch_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_stretch_stop(eff_t effp);
+
+int st_swap_getopts(eff_t effp, int argc, char **argv);
+int st_swap_start(eff_t effp);
+int st_swap_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+int st_swap_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_swap_stop(eff_t effp);
+
+int st_synth_getopts(eff_t effp, int argc, char **argv); 
+int st_synth_start(eff_t effp);
+int st_synth_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	          st_size_t *isamp, st_size_t *osamp);
+int st_synth_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_synth_stop(eff_t effp);
+
+int st_trim_getopts(eff_t effp, int argc, char **argv); 
+int st_trim_start(eff_t effp);
+int st_trim_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	         st_size_t *isamp, st_size_t *osamp);
+int st_trim_stop(eff_t effp);
+
+int st_vibro_getopts(eff_t effp, int argc, char **argv);
+int st_vibro_start(eff_t effp);
+int st_vibro_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	          st_size_t *isamp, st_size_t *osamp);
+int st_vibro_stop(eff_t effp);
+
+int st_vol_getopts(eff_t effp, int argc, char **argv);
+int st_vol_start(eff_t effp);
+int st_vol_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, 
+	        st_size_t *isamp, st_size_t *osamp);
+int st_vol_stop(eff_t effp);
+
+#ifdef __cplusplus
+} /* end of extern "C" */
+#endif
+
+#endif
--- a/src/tests.sh
+++ b/src/tests.sh
@@ -20,6 +20,16 @@
 fi
 rm -f raw1.sb raw2.ub
 
+./sox $noise -r 8012 -c 1 raw1.ub raw1.al
+./sox $noise -r 8012 -c 1 raw1.al raw2.ub
+if cmp -s raw1.ub raw2.ub
+then
+    echo "Conversion between unsigned bytes and alaw bytes was successful"
+else
+    echo "Error converting between alaw and unsigned bytes"
+fi
+rm -f raw1.al raw2.ub
+
 ./sox $noise -r 8012 -c 1 raw1.ub raw1.sw
 ./sox $noise -r 8012 -c 1 raw1.sw raw2.ub
 if cmp -s raw1.ub raw2.ub
--- a/src/voc.c
+++ b/src/voc.c
@@ -373,8 +373,8 @@
         vs_t v = (vs_t) ft->priv;
         unsigned char uc, block;
         ULONG sblen;
-        unsigned short new_rate_short;
-        ULONG new_rate_long;
+        u_int16_t new_rate_16;
+        u_int32_t new_rate_32;
         int i;
         ULONG trash;
 
@@ -431,20 +431,20 @@
                         v->size = ST_SIZE_BYTE;
                         return (ST_SUCCESS);
                 case VOC_DATA_16:
-                        st_readdw(ft, &new_rate_long);
-                        if (new_rate_long == 0)
+                        st_readdw(ft, &new_rate_32);
+                        if (new_rate_32 == 0)
                         {
                             st_fail_errno(ft,ST_EFMT,"File %s: Sample rate is zero?",ft->filename);
                             return(ST_EOF);
                         }
-                        if ((v->rate != -1) && (new_rate_long != v->rate))
+                        if ((v->rate != -1) && (new_rate_32 != v->rate))
                         {
                             st_fail_errno(ft,ST_EFMT,"File %s: sample rate codes differ: %d != %d",
-                                ft->filename, v->rate, new_rate_long);
+                                ft->filename, v->rate, new_rate_32);
                             return(ST_EOF);
                         }
-                        v->rate = new_rate_long;
-                        ft->info.rate = new_rate_long;
+                        v->rate = new_rate_32;
+                        ft->info.rate = new_rate_32;
                         st_readb(ft, &uc);
                         switch (uc)
                         {
@@ -514,19 +514,19 @@
                         /* value from the extended block and not the     */
                         /* data block.                                   */
                         v->extended = 1;
-                        st_readw(ft, &new_rate_short);
-                        if (new_rate_short == 0)
+                        st_readw(ft, &new_rate_16);
+                        if (new_rate_16 == 0)
                         {
                            st_fail_errno(ft,ST_EFMT,"File %s: Sample rate is zero?");
                            return(ST_EOF);
                         }
-                        if ((v->rate != -1) && (new_rate_short != v->rate))
+                        if ((v->rate != -1) && (new_rate_16 != v->rate))
                         {
                            st_fail_errno(ft,ST_EFMT,"File %s: sample rate codes differ: %d != %d",
-                                        ft->filename, v->rate, new_rate_short);
+                                        ft->filename, v->rate, new_rate_16);
                            return(ST_EOF);
                         }
-                        v->rate = new_rate_short;
+                        v->rate = new_rate_16;
                         st_readb(ft, &uc);
                         if (uc != 0)
                         {
--- a/src/wav.c
+++ b/src/wav.c
@@ -394,10 +394,10 @@
 /* General Sox WAV file code                                                */
 /****************************************************************************/
 
-static ULONG findChunk(ft_t ft, const char *Label)
+static u_int32_t findChunk(ft_t ft, const char *Label)
 {
     char magic[5];
-    ULONG len;
+    u_int32_t len;
     for (;;)
     {
 	if (st_reads(ft, magic, 4) == ST_EOF)
@@ -427,22 +427,23 @@
 {
     wav_t	wav = (wav_t) ft->priv;
     char	magic[5];
-    ULONG	len;
+    u_int32_t	len;
     int		rc;
 
     /* wave file characteristics */
-    ULONG    wRiffLength;
+    u_int32_t      dwRiffLength;
     unsigned short wChannels;	    /* number of channels */
-    ULONG    wSamplesPerSecond;     /* samples per second per channel */
-    ULONG    wAvgBytesPerSec;	    /* estimate of bytes per second needed */
+    u_int32_t      dwSamplesPerSecond; /* samples per second per channel */
+    u_int32_t      dwAvgBytesPerSec;/* estimate of bytes per second needed */
     unsigned short wBitsPerSample;  /* bits per sample */
     unsigned short wFmtSize;
     unsigned short wExtSize = 0;    /* extended field for non-PCM */
 
-    ULONG    wDataLength;	    /* length of sound data in bytes */
+    u_int32_t      dwDataLength;    /* length of sound data in bytes */
     ULONG    bytesPerBlock = 0;
     ULONG    bytespersample;	    /* bytes per sample (per channel */
-	char text[256];
+    char text[256];
+    u_int32_t      dwLoopPos;
 
 	ft->st_errno = ST_SUCCESS;
 
@@ -454,7 +455,7 @@
 	return ST_EOF;
     }
 
-    st_readdw(ft, &wRiffLength);
+    st_readdw(ft, &dwRiffLength);
 
     if (st_reads(ft, magic, 4) == ST_EOF || strncmp("WAVE", magic, 4))
     {
@@ -474,8 +475,8 @@
 
     st_readw(ft, &(wav->formatTag));
     st_readw(ft, &wChannels);
-    st_readdw(ft, &wSamplesPerSecond);
-    st_readdw(ft, &wAvgBytesPerSec);	/* Average bytes/second */
+    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 */
     len -= 16;
@@ -600,8 +601,8 @@
     else
 	st_report("User options overriding channels read in .wav header");
 
-    if (ft->info.rate == 0 || ft->info.rate == wSamplesPerSecond)
-	ft->info.rate = wSamplesPerSecond;
+    if (ft->info.rate == 0 || ft->info.rate == dwSamplesPerSecond)
+	ft->info.rate = dwSamplesPerSecond;
     else
 	st_report("User options overriding rate read in .wav header");
     
@@ -823,7 +824,7 @@
      * the upcoming 'data' chunk */
 
     /* Now look for the wave data chunk */
-    wDataLength = len = findChunk(ft, "data");
+    dwDataLength = len = findChunk(ft, "data");
     /* findChunk() only returns if chunk was found */
 
 	/* Data starts here */
@@ -834,8 +835,9 @@
 
     case WAVE_FORMAT_ADPCM:
 	wav->numSamples = 
-	    AdpcmSamplesIn(wDataLength, ft->info.channels, wav->blockAlign, wav->samplesPerBlock);
-	/*st_report("datalen %d, numSamples %d",wDataLength, 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;
@@ -844,8 +846,9 @@
 	/* Compute easiest part of number of samples.  For every block, there
 	   are samplesPerBlock samples to read. */
 	wav->numSamples = 
-	    ImaSamplesIn(wDataLength, ft->info.channels, wav->blockAlign, wav->samplesPerBlock);
-	/*st_report("datalen %d, numSamples %d",wDataLength, 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;
@@ -853,7 +856,7 @@
 
 #ifdef HAVE_LIBGSM
     case WAVE_FORMAT_GSM610:
-	wav->numSamples = (((wDataLength / wav->blockAlign) * wav->samplesPerBlock) * ft->info.channels);
+	wav->numSamples = (((dwDataLength / wav->blockAlign) * wav->samplesPerBlock) * ft->info.channels);
 	wavgsminit(ft);
 	ft->length = wav->numSamples;
 	break;
@@ -860,7 +863,7 @@
 #endif
 
     default:
-	wav->numSamples = wDataLength/ft->info.size;	/* total samples */
+	wav->numSamples = dwDataLength/ft->info.size;	/* total samples */
 	ft->length = wav->numSamples;
 
     }
@@ -867,9 +870,9 @@
 
     st_report("Reading Wave file: %s format, %d channel%s, %d samp/sec",
 	   wav_format_str(wav->formatTag), ft->info.channels,
-	   wChannels == 1 ? "" : "s", wSamplesPerSecond);
+	   wChannels == 1 ? "" : "s", dwSamplesPerSecond);
     st_report("        %d byte/sec, %d block align, %d bits/samp, %u data bytes",
-	   wAvgBytesPerSec, wav->blockAlign, wBitsPerSample, wDataLength);
+	   dwAvgBytesPerSec, wav->blockAlign, wBitsPerSample, dwDataLength);
 
     /* Can also report extended fmt information */
     switch (wav->formatTag)
@@ -925,7 +928,8 @@
 			st_readdw(ft,&len);
 			len = (len + 1) & ~1;
 			st_seek(ft,len-4,SEEK_CUR);
-			st_readdw(ft,(ULONG*)&ft->loops[0].start); 
+			st_readdw(ft,&dwLoopPos);
+			ft->loops[0].start = dwLoopPos;
 		} else if(strncmp(magic,"note",4) == 0){
 			/*Skip*/
 			st_readdw(ft,&len);
@@ -935,8 +939,8 @@
 			/*Skip*/
 		} else if(strncmp(magic,"ltxt",4) == 0){
 			st_seek(ft,4,SEEK_CUR);
-			st_readdw(ft,(ULONG*)&ft->loops[0].length); 
-			ft->loops[0].length = ft->loops[0].length - ft->loops[0].start;
+			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);
@@ -1156,15 +1160,15 @@
 16 - 19    wFmtSize       length of format chunk minus 8 byte header 
 20 - 21    wFormatTag     identifies PCM, ULAW etc
 22 - 23    wChannels      
-24 - 27    wSamplesPerSecond   samples per second per channel
-28 - 31    wAvgBytesPerSec     non-trivial for compressed formats
+24 - 27    dwSamplesPerSecond  samples per second per channel
+28 - 31    dwAvgBytesPerSec    non-trivial for compressed formats
 32 - 33    wBlockAlign         basic block size
 34 - 35    wBitsPerSample      non-trivial for compressed formats
 
 PCM formats then go straight to the data chunk:
 36 - 39    'data'
-40 - 43     wDataLength   length of data chunk minus 8 byte header
-44 - (wDataLength + 43)    the data
+40 - 43     dwDataLength   length of data chunk minus 8 byte header
+44 - (dwDataLength + 43)   the data
 
 non-PCM formats must write an extended format chunk and a fact chunk:
 
@@ -1174,8 +1178,8 @@
 42 - 45    wFactSize = 4  length of the fact chunk minus 8 byte header
 46 - 49    wSamplesWritten   actual number of samples written out
 50 - 53    'data'
-54 - 57     wDataLength   length of data chunk minus 8 byte header
-58 - (wDataLength + 57)    the data
+54 - 57     dwDataLength  length of data chunk minus 8 byte header
+58 - (dwDataLength + 57)  the data
 
 
 GSM6.10  format:
@@ -1185,9 +1189,9 @@
 44 - 47    wFactSize = 4  length of the fact chunk minus 8 byte header
 48 - 51    wSamplesWritten   actual number of samples written out
 52 - 55    'data'
-56 - 59     wDataLength   length of data chunk minus 8 byte header
-60 - (wDataLength + 59)     the data
-(+ a padding byte if wDataLength is odd) 
+56 - 59     dwDataLength  length of data chunk minus 8 byte header
+60 - (dwDataLength + 59)  the data
+(+ a padding byte if dwDataLength is odd) 
 
 
 note that header contains (up to) 3 separate ways of describing the
@@ -1198,7 +1202,7 @@
 wRiffLength -      (riff header) the length of the file, minus 8 
 wSamplesWritten  -  (fact header) the number of samples written (after padding
                    to a complete block eg for GSM)
-wDataLength     -   (data chunk header) the number of (valid) data bytes written
+dwDataLength     - (data chunk header) the number of (valid) data bytes written
 
 */
 
@@ -1213,8 +1217,8 @@
 	ULONG wFmtSize = 16;                /* size field of the fmt chunk */
 	unsigned short wFormatTag = 0;      /* data format */
 	unsigned short wChannels;           /* number of channels */
-	ULONG  wSamplesPerSecond;           /* samples per second per channel*/
-	ULONG  wAvgBytesPerSec=0;           /* estimate of bytes per second needed */
+	ULONG  dwSamplesPerSecond;          /* samples per second per channel*/
+	u_int32_t dwAvgBytesPerSec=0;       /* estimate of bytes per second needed */
 	unsigned short wBlockAlign=0;       /* byte alignment of a basic sample block */
 	unsigned short wBitsPerSample=0;    /* bits per sample */
 	/* fmt chunk extension (not PCM) */
@@ -1227,7 +1231,7 @@
 	ULONG wSamplesWritten=0;	/* windows doesnt seem to use this*/
 
 	/* data chunk */
-	ULONG  wDataLength=0x7ffff000L;	/* length of sound data in bytes */
+	u_int32_t  dwDataLength=0x7ffff000L;	/* length of sound data in bytes */
 	/* end of variables written to header */
 
 	/* internal variables, intermediate values etc */
@@ -1234,7 +1238,7 @@
 	ULONG bytespersample; 		/* (uncompressed) bytes per sample (per channel) */
 	ULONG blocksWritten = 0;
 
-	wSamplesPerSecond = ft->info.rate;
+	dwSamplesPerSecond = ft->info.rate;
 	wChannels = ft->info.channels;
 
 	/* Check to see if encoding is ADPCM or not.  If ADPCM
@@ -1341,7 +1345,7 @@
 			wChannels = ft->info.channels = 1;
 		    }
 		    wFormatTag = WAVE_FORMAT_GSM610;
-		    /* wAvgBytesPerSec = 1625*(wSamplesPerSecond/8000.)+0.5; */
+		    /* dwAvgBytesPerSec = 1625*(dwSamplesPerSecond/8000.)+0.5; */
 		    wBlockAlign=65;
 		    wBitsPerSample=0;  /* not representable as int   */
 		    wExtSize=2;        /* length of format extension */
@@ -1357,8 +1361,8 @@
 	wav->samplesPerBlock = wSamplesPerBlock;
 
 	if (!second_header) { 	/* adjust for blockAlign */
-	    blocksWritten = wDataLength/wBlockAlign;
-	    wDataLength = blocksWritten * wBlockAlign;
+	    blocksWritten = dwDataLength/wBlockAlign;
+	    dwDataLength = blocksWritten * wBlockAlign;
 	    wSamplesWritten = blocksWritten * wSamplesPerBlock;
 	} else { 	/* fixup with real length */
 	    wSamplesWritten = wav->numSamples;
@@ -1366,7 +1370,7 @@
 		{
 	    	case WAVE_FORMAT_ADPCM:
 	    	case WAVE_FORMAT_IMA_ADPCM:
-		    wDataLength = wav->dataLength;
+		    dwDataLength = wav->dataLength;
 		    break;
 #ifdef HAVE_LIBGSM
 		case WAVE_FORMAT_GSM610:
@@ -1375,24 +1379,24 @@
 		default:
 		    wSamplesWritten /= wChannels; /* because how rawwrite()'s work */
 		    blocksWritten = (wSamplesWritten+wSamplesPerBlock-1)/wSamplesPerBlock;
-		    wDataLength = blocksWritten * wBlockAlign;
+		    dwDataLength = blocksWritten * wBlockAlign;
 		}
 	}
 
 #ifdef HAVE_LIBGSM
 	if (wFormatTag == WAVE_FORMAT_GSM610)
-	    wDataLength = (wDataLength+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 */
 
-	wRiffLength = 4 + (8+wFmtSize) + (8+wDataLength); 
+	wRiffLength = 4 + (8+wFmtSize) + (8+dwDataLength); 
 	if (wFormatTag != WAVE_FORMAT_PCM) /* PCM omits the "fact" chunk */
 	    wRiffLength += (8+wFactSize);
 	
-	/* wAvgBytesPerSec <-- this is BEFORE compression, isn't it? guess not. */
-	wAvgBytesPerSec = (double)wBlockAlign*ft->info.rate / (double)wSamplesPerBlock + 0.5;
+	/* dwAvgBytesPerSec <-- this is BEFORE compression, isn't it? guess not. */
+	dwAvgBytesPerSec = (double)wBlockAlign*ft->info.rate / (double)wSamplesPerBlock + 0.5;
 
 	/* figured out header info, so write it */
 	st_writes(ft, "RIFF");
@@ -1402,8 +1406,8 @@
 	st_writedw(ft, wFmtSize);
 	st_writew(ft, wFormatTag);
 	st_writew(ft, wChannels);
-	st_writedw(ft, wSamplesPerSecond);
-	st_writedw(ft, wAvgBytesPerSec);
+	st_writedw(ft, dwSamplesPerSecond);
+	st_writedw(ft, dwAvgBytesPerSec);
 	st_writew(ft, wBlockAlign);
 	st_writew(ft, wBitsPerSample); /* end info common to all fmts */
 
@@ -1442,24 +1446,24 @@
 	}
 
 	st_writes(ft, "data");
-	st_writedw(ft, wDataLength);		/* 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", wSamplesPerSecond);
+	        	wChannels == 1 ? "" : "s", dwSamplesPerSecond);
 		st_report("        %d byte/sec, %d block align, %d bits/samp",
-	                wAvgBytesPerSec, wBlockAlign, wBitsPerSample);
+	                dwAvgBytesPerSec, wBlockAlign, wBitsPerSample);
 	} else {
 		st_report("Finished writing Wave file, %u data bytes %u samples\n",
-			wDataLength,wav->numSamples);
+			dwDataLength,wav->numSamples);
 #ifdef HAVE_LIBGSM
 		if (wFormatTag == WAVE_FORMAT_GSM610){
 		    st_report("GSM6.10 format: %u blocks %u padded samples %u padded data bytes\n",
-			blocksWritten, wSamplesWritten, wDataLength);
-		    if (wav->gsmbytecount != wDataLength)
+			blocksWritten, wSamplesWritten, dwDataLength);
+		    if (wav->gsmbytecount != dwDataLength)
 			st_warn("help ! internal inconsistency - data_written %u gsmbytecount %u",
-				wDataLength, wav->gsmbytecount);
+				dwDataLength, wav->gsmbytecount);
 
 		}
 #endif
--- a/src/wve.c
+++ b/src/wve.c
@@ -16,7 +16,7 @@
 
 typedef struct wvepriv
     {
-    ULONG length;
+    u_int32_t length;
     short padding;
     short repeats;
 /* For seeking */