shithub: sox

Download patch

ref: 13b765c1d1fc4a58c2bc494534fa4f5c8dab5605
parent: 1176b451913eea3407a08f925d8c23926aaf2915
author: cbagwell <cbagwell>
date: Thu Nov 22 22:42:57 EST 2001

Change LONG/ULONG to st_sample_t/st_size_t

--- a/Changelog
+++ b/Changelog
@@ -28,11 +28,12 @@
     the headers did not contain the correct length or encoding type.
   o Seperated st.h into 2 files.  st.h for libst users and st_i.h for
     internal use.
+  o Added new types used extensively by libst: st_sample_t & st_size_t.
+    This allows for more deterministic behavior on 64-bit machines and
+    also allows sox to possibly work with much larger file sizes.
   o SoX was some times getting confused and thinking an EOF was an
     error case when reading audio files.  Removed unneeded aborts
     when EOF was OK.
-  o Change libst to use two new data types: st_sample_t and st_size_t.
-    This allows for better support and maintaince on 64-bit machines.
   o Silence effect was broken on stereo files.  Also, made thresholds
     relative to original bit percision of audio data.  When 16-bit audio
     is scaled up to 32-bits, a little bit of noise starts to look like a
--- a/TODO
+++ b/TODO
@@ -5,6 +5,8 @@
 
   o Make a global version of MIN/MAX instead of sprinkled min/max/MIN/MAX
 
+  o Make a global version of clip() instead of sprinked in all files.
+
   o Add support to all file handlers to handle 32-bit and float
     data types since raw functions can handle them.
 
--- a/nul.c
+++ b/nul.c
@@ -69,7 +69,7 @@
 {
 	nul_t sk = (nul_t) ft->priv;
 	int done = 0;
-	LONG l;
+	st_sample_t l;
 	for(; done < len; done++) {
 	    if (ft->file.eof)
 		break;
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -359,7 +359,7 @@
 #define SVXHEADERSIZE 100
 static void svxwriteheader(ft_t ft, st_ssize_t nsamples)
 {
-	LONG formsize =  nsamples + SVXHEADERSIZE - 8;
+	int32_t formsize =  nsamples + SVXHEADERSIZE - 8;
 
 	/* FORM size must be even */
 	if(formsize % 2 != 0) formsize++;
@@ -369,10 +369,10 @@
 	st_writes(ft, "8SVX"); /* File type */
 
 	st_writes(ft, "VHDR");
-	st_writedw(ft, (LONG) 20); /* number of bytes to follow */
+	st_writedw(ft, 20); /* number of bytes to follow */
 	st_writedw(ft, nsamples);  /* samples, 1-shot */
-	st_writedw(ft, (LONG) 0);  /* samples, repeat */
-	st_writedw(ft, (LONG) 0);  /* samples per repeat cycle */
+	st_writedw(ft, 0);  /* samples, repeat */
+	st_writedw(ft, 0);  /* samples per repeat cycle */
 	st_writew(ft, (int) ft->info.rate); /* samples per second */
 	st_writeb(ft,1); /* number of octabes */
 	st_writeb(ft,0); /* data compression (none) */
@@ -379,13 +379,13 @@
 	st_writew(ft,1); st_writew(ft,0); /* volume */
 
 	st_writes(ft, "ANNO");
-	st_writedw(ft, (LONG) 32); /* length of block */
+	st_writedw(ft, 32); /* length of block */
 	st_writes(ft, "File created by Sound Exchange  ");
 
 	st_writes(ft, "CHAN");
-	st_writedw(ft, (LONG) 4);
-	st_writedw(ft, (ft->info.channels == 2) ? (LONG) 6 :
-		   (ft->info.channels == 4) ? (LONG) 15 : (LONG) 2);
+	st_writedw(ft, 4);
+	st_writedw(ft, (ft->info.channels == 2) ? 6 :
+		   (ft->info.channels == 4) ? 15 : 2);
 
 	st_writes(ft, "BODY");
 	st_writedw(ft, nsamples); /* samples in file */
--- a/src/adpcm.c
+++ b/src/adpcm.c
@@ -38,7 +38,7 @@
 #include "adpcm.h"
 
 typedef struct MsState {
-	LONG  step;	/* step size */
+	st_sample_t  step;	/* step size */
 	short iCoef[2];
 } MsState_t;
 
@@ -52,7 +52,7 @@
  * 1.0 is scaled to 0x100
  */
 static const
-LONG stepAdjustTable[] = {
+st_sample_t stepAdjustTable[] = {
 	230, 230, 230, 230, 307, 409, 512, 614,
 	768, 614, 512, 409, 307, 230, 230, 230
 };
@@ -71,25 +71,17 @@
 			{ 392,-232}
 };
 
-#if 0
-static LONG AdpcmDecode(LONG, MsState_t*, LONG, LONG)__attribute__((regparm(3)));
-#endif
-
-#ifdef __GNUC__
-inline
-#endif
-static LONG AdpcmDecode(c, state, sample1, sample2)
-LONG c, sample1, sample2;
-MsState_t *state;
+inline static st_sample_t AdpcmDecode(st_sample_t c, MsState_t *state, 
+	                              st_sample_t sample1, st_sample_t sample2)
 {
-	LONG vlin;
-	LONG sample;
-	LONG step;
+	st_sample_t vlin;
+	st_sample_t sample;
+	st_sample_t step;
 
 	/** Compute next step value **/
 	step = state->step;
 	{
-		LONG nstep;
+		st_sample_t nstep;
 		nstep = (stepAdjustTable[c] * step) >> 8;
 		state->step = (nstep < 16)? 16:nstep;
 	}
@@ -402,14 +394,14 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing usage.
  */
-ULONG AdpcmSamplesIn(
-	ULONG dataLen,
+st_size_t AdpcmSamplesIn(
+	st_size_t dataLen,
 	unsigned short chans,
 	unsigned short blockAlign,
 	unsigned short samplesPerBlock
 )
 {
-	ULONG m, n;
+	st_size_t m, n;
 
 	if (samplesPerBlock) {
 		n = (dataLen / blockAlign) * samplesPerBlock;
@@ -428,15 +420,15 @@
 	/* wSamplesPerBlock = 2*(wBlockAlign - 7*wChannels)/wChannels + 2; */
 }
 
-ULONG AdpcmBytesPerBlock(
+st_size_t AdpcmBytesPerBlock(
 	unsigned short chans,
 	unsigned short samplesPerBlock
 )
 {
-	ULONG n;
+	st_size_t n;
 	n = 7*chans;  /* header */ 
 	if (samplesPerBlock > 2)
-		n += (((ULONG)samplesPerBlock-2)*chans + 1)/2;
+		n += (((st_size_t)samplesPerBlock-2)*chans + 1)/2;
 	return n;
 }
 
--- a/src/adpcm.h
+++ b/src/adpcm.h
@@ -40,8 +40,8 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing usage.
  */
-extern ULONG AdpcmSamplesIn(
-	ULONG dataLen,
+extern st_size_t AdpcmSamplesIn(
+	st_size_t dataLen,
 	unsigned short chans,
 	unsigned short blockAlign,
 	unsigned short samplesPerBlock
@@ -48,11 +48,11 @@
 );
 
 /*
- * ULONG AdpcmBytesPerBlock(chans, samplesPerBlock)
+ * st_size_t AdpcmBytesPerBlock(chans, samplesPerBlock)
  *   return minimum blocksize which would be required
  *   to encode number of chans with given samplesPerBlock
  */
-extern ULONG AdpcmBytesPerBlock(
+extern st_size_t AdpcmBytesPerBlock(
 	unsigned short chans,
 	unsigned short samplesPerBlock
 );
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -56,14 +56,14 @@
 
 /* Private data used by writer */
 typedef struct aiffpriv {
-	ULONG nsamples;	/* number of 1-channel samples read or written */
-					/*Decrements for read increments for write */
-    LONG dataStart;  /* need to for seeking */
+    st_size_t nsamples;  /* number of 1-channel samples read or written */
+			 /* Decrements for read increments for write */
+    st_size_t dataStart; /* need to for seeking */
 } *aiff_t;
 
 /* forward declarations */
 static double read_ieee_extended(ft_t);
-static int aiffwriteheader(ft_t, LONG);
+static int aiffwriteheader(ft_t, st_size_t);
 static void write_ieee_extended(ft_t, double);
 static double ConvertFromIeeeExtended(unsigned char*);
 static void ConvertToIeeeExtended(double, char *);
@@ -71,7 +71,7 @@
 static int commentChunk(char **text, char *chunkDescription, ft_t ft);
 static void reportInstrument(ft_t ft);
 
-int st_aiffseek(ft_t ft,st_size_t offset) 
+int st_aiffseek(ft_t ft, st_size_t offset) 
 {
 	aiff_t aiff = (aiff_t ) ft->priv;
 
@@ -106,7 +106,7 @@
 	unsigned short nmarks = 0;
 	unsigned short sustainLoopBegin = 0, sustainLoopEnd = 0,
 	     	       releaseLoopBegin = 0, releaseLoopEnd = 0;
-	LONG seekto = 0L, ssndsize = 0L;
+	st_size_t seekto = 0L, ssndsize = 0L;
 	char *author;
 	char *copyright;
 	char *nametext;
@@ -352,7 +352,7 @@
 		st_fail_errno(ft,ST_EHDR,"AIFF header specifies nonzero blocksize?!?!");
 		return(ST_EOF);
 	}
-	while ((LONG) (--offset) >= 0) {
+	while (offset-- > 0) {
 		if (st_readb(ft, (unsigned char *)&trash8) == ST_EOF)
 		{
 			st_fail_errno(ft,errno,"unexpected EOF while skipping AIFF offset");
@@ -574,7 +574,7 @@
 st_ssize_t st_aiffread(ft_t ft, st_sample_t *buf, st_ssize_t len)
 {
 	aiff_t aiff = (aiff_t ) ft->priv;
-	LONG done;
+	st_ssize_t done;
 
 	/* just read what's left of SSND chunk */
 	if (len > aiff->nsamples)
@@ -590,7 +590,7 @@
 {
 	char buf[5];
 	uint32_t chunksize;
-	ULONG trash;
+	uint32_t trash;
 
 	if (!ft->seekable)
 	{
@@ -607,7 +607,7 @@
 			buf, chunksize);
 		if (! strcmp(buf, "MARK") || ! strcmp(buf, "INST"))
 			st_warn("	You're stripping MIDI/loop info!\n");
-		while ((LONG) (--chunksize) >= 0) 
+		while (chunksize-- > 0) 
 		{
 			if (st_readb(ft, (unsigned char *)&trash) == ST_EOF)
 				break;
@@ -697,7 +697,7 @@
 	return(aiffwriteheader(ft, aiff->nsamples / ft->info.channels));
 }
 
-static int aiffwriteheader(ft_t ft, LONG nframes)
+static int aiffwriteheader(ft_t ft, st_size_t nframes)
 {
 	int hsize =
 		8 /*COMM hdr*/ + 18 /*COMM chunk*/ +
@@ -706,7 +706,7 @@
 	int i;
 	int padded_comment_size = 0;
 	int comment_size = 0;
-	LONG comment_chunk_size = 0L;
+	st_size_t comment_chunk_size = 0L;
 
 	/* MARK and INST chunks */
 	if (ft->instr.nloops) {
@@ -737,7 +737,7 @@
 	  padded_comment_size = ((comment_size % 2) == 0) ?
 				comment_size : comment_size + 1;
 	  /* one comment, timestamp, marker ID and text count */
-	  comment_chunk_size = (LONG) (2 + 4 + 2 + 2 + padded_comment_size);
+	  comment_chunk_size = (2L + 4 + 2 + 2 + padded_comment_size);
 	  hsize += 8 /* COMT hdr */ + comment_chunk_size; 
 	}
 
@@ -757,7 +757,7 @@
 
 	  /* time stamp of comment, Unix knows of time from 1/1/1970,
 	     Apple knows time from 1/1/1904 */
-	  st_writedw(ft, (LONG) ((LONG) time(NULL)) + 2082844800L);
+	  st_writedw(ft, ((int32_t) time(NULL)) + 2082844800L);
 
 	  /* A marker ID of 0 indicates the comment is not associated
 	     with a marker */
@@ -772,7 +772,7 @@
 
 	/* COMM chunk -- describes encoding (and #frames) */
 	st_writes(ft, "COMM");
-	st_writedw(ft, (LONG) 18); /* COMM chunk size */
+	st_writedw(ft, 18); /* COMM chunk size */
 	st_writew(ft, ft->info.channels); /* nchannels */
 	st_writedw(ft, nframes); /* number of frames */
 	st_writew(ft, bits); /* sample width, in bits */
@@ -828,8 +828,8 @@
 	st_writes(ft, "SSND");
 	/* chunk size */
 	st_writedw(ft, 8 + nframes * ft->info.channels * ft->info.size); 
-	st_writedw(ft, (LONG) 0); /* offset */
-	st_writedw(ft, (LONG) 0); /* block size */
+	st_writedw(ft, 0); /* offset */
+	st_writedw(ft, 0); /* block size */
 	return(ST_SUCCESS);
 }
 
@@ -897,7 +897,7 @@
 # define HUGE_VAL HUGE
 #endif /*HUGE_VAL*/
 
-# define FloatToUnsigned(f)      ((ULONG)(((LONG)(f - 2147483648.0)) + 2147483647L) + 1)
+# define FloatToUnsigned(f) ((uint32_t)(((int32_t)(f - 2147483648.0)) + 2147483647L) + 1)
 
 static void ConvertToIeeeExtended(double num, char *bytes)
 {
@@ -904,7 +904,7 @@
     int    sign;
     int expon;
     double fMant, fsMant;
-    ULONG hiMant, loMant;
+    uint32_t hiMant, loMant;
 
     if (num < 0) {
         sign = 0x8000;
@@ -990,7 +990,7 @@
 # define HUGE_VAL HUGE
 #endif /*HUGE_VAL*/
 
-# define UnsignedToFloat(u)         (((double)((LONG)(u - 2147483647L - 1))) + 2147483648.0)
+# define UnsignedToFloat(u)         (((double)((int32_t)(u - 2147483647L - 1))) + 2147483648.0)
 
 /****************************************************************
  * Extended precision IEEE floating-point conversion routine.
@@ -1000,17 +1000,17 @@
 {
     double    f;
     int    expon;
-    ULONG hiMant, loMant;
+    uint32_t hiMant, loMant;
     
     expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
-    hiMant    =    ((ULONG)(bytes[2] & 0xFF) << 24)
-            |    ((ULONG)(bytes[3] & 0xFF) << 16)
-            |    ((ULONG)(bytes[4] & 0xFF) << 8)
-            |    ((ULONG)(bytes[5] & 0xFF));
-    loMant    =    ((ULONG)(bytes[6] & 0xFF) << 24)
-            |    ((ULONG)(bytes[7] & 0xFF) << 16)
-            |    ((ULONG)(bytes[8] & 0xFF) << 8)
-            |    ((ULONG)(bytes[9] & 0xFF));
+    hiMant    =    ((uint32_t)(bytes[2] & 0xFF) << 24)
+            |    ((uint32_t)(bytes[3] & 0xFF) << 16)
+            |    ((uint32_t)(bytes[4] & 0xFF) << 8)
+            |    ((uint32_t)(bytes[5] & 0xFF));
+    loMant    =    ((uint32_t)(bytes[6] & 0xFF) << 24)
+            |    ((uint32_t)(bytes[7] & 0xFF) << 16)
+            |    ((uint32_t)(bytes[8] & 0xFF) << 8)
+            |    ((uint32_t)(bytes[9] & 0xFF));
 
     if (expon == 0 && hiMant == 0 && loMant == 0) {
         f = 0;
--- a/src/au.c
+++ b/src/au.c
@@ -50,9 +50,9 @@
 /* Private data */
 typedef struct aupriv {
 	/* For writer: size in bytes */
-	ULONG data_size;
+	st_size_t data_size;
 	/* For seeking */
-	LONG dataStart;
+	st_size_t dataStart;
 	/* For G72x decoding: */
 	struct g72x_state state;
 	int (*dec_routine)();
@@ -61,7 +61,7 @@
 	int in_bits;
 } *au_t;
 
-static void auwriteheader(ft_t ft, ULONG data_size);
+static void auwriteheader(ft_t ft, st_size_t data_size);
 
 static int st_auencodingandsize(int sun_encoding, char *encoding, char *size)
 {
@@ -381,11 +381,11 @@
 
 static void auwriteheader(ft_t ft, st_size_t data_size)
 {
-	ULONG magic;
-	ULONG hdr_size;
-	ULONG encoding;
-	ULONG sample_rate;
-	ULONG channels;
+	uint32_t magic;
+	uint32_t hdr_size;
+	uint32_t encoding;
+	uint32_t sample_rate;
+	uint32_t channels;
 	int   x;
 	int   comment_size;
 
--- a/src/avr.c
+++ b/src/avr.c
@@ -262,9 +262,7 @@
   return(ST_SUCCESS);
 }
 
-LONG st_avrwrite(ft, buf, nsamp) 
-ft_t ft;
-LONG *buf, nsamp;
+st_ssize_t st_avrwrite(ft_t ft, st_sample_t *buf, st_ssize_t nsamp) 
 {
   avr_t	avr = (avr_t)ft->priv;
 
@@ -273,10 +271,7 @@
   return (st_rawwrite (ft, buf, nsamp));
 }
 
-
-
-int st_avrstopwrite(ft) 
-ft_t ft;
+int st_avrstopwrite(ft_t ft) 
 {
   avr_t	avr = (avr_t)ft->priv;
   int rc;
--- a/src/band.c
+++ b/src/band.c
@@ -118,7 +118,7 @@
 	band_t band = (band_t) effp->priv;
 	int len, done;
 	double d;
-	LONG l;
+	st_sample_t l;
 
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
 
--- a/src/cdr.c
+++ b/src/cdr.c
@@ -28,7 +28,7 @@
 
 /* Private data for SKEL file */
 typedef struct cdrstuff {
-	LONG	samples;	/* number of samples written */
+	st_size_t samples;	/* number of samples written */
 } *cdr_t;
 
 /*
--- a/src/chorus.c
+++ b/src/chorus.c
@@ -76,12 +76,12 @@
 	int	num_chorus;
 	int	modulation[MAX_CHORUS];
 	int	counter;			
-	LONG	phase[MAX_CHORUS];
+	long	phase[MAX_CHORUS];
 	float	*chorusbuf;
 	float	in_gain, out_gain;
 	float	delay[MAX_CHORUS], decay[MAX_CHORUS];
 	float	speed[MAX_CHORUS], depth[MAX_CHORUS];
-	LONG	length[MAX_CHORUS];
+	long	length[MAX_CHORUS];
 	int	*lookup_tab[MAX_CHORUS];
 	int	depth_samples[MAX_CHORUS], samples[MAX_CHORUS];
 	int	maxsamples, fade_out;
@@ -260,7 +260,7 @@
 	int i;
 	
 	float d_in, d_out;
-	LONG out;
+	st_sample_t out;
 
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
 	for(done = 0; done < len; done++) {
@@ -274,7 +274,7 @@
 			chorus->maxsamples] * chorus->decay[i];
 		/* Adjust the output volume and size to 24 bit */
 		d_out = d_out * chorus->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		/* Mix decay of delay and input */
 		chorus->chorusbuf[chorus->counter] = d_in;
@@ -298,7 +298,7 @@
 	int i;
 	
 	float d_in, d_out;
-	LONG out;
+	st_sample_t out;
 
 	done = 0;
 	while ( ( done < *osamp ) && ( done < chorus->fade_out ) ) {
@@ -311,7 +311,7 @@
 		chorus->maxsamples] * chorus->decay[i];
 		/* Adjust the output volume and size to 24 bit */
 		d_out = d_out * chorus->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		/* Mix decay of delay and input */
 		chorus->chorusbuf[chorus->counter] = d_in;
--- a/src/compand.c
+++ b/src/compand.c
@@ -56,10 +56,10 @@
   double *volume;       /* Current "volume" of each channel */
   double outgain;       /* Post processor gain */
   double delay;		/* Delay to apply before companding */
-  LONG   *delay_buf;	/* Old samples, used for delay processing */
-  LONG	 delay_buf_size; /* Size of delay_buf in samples */
-  LONG	 delay_buf_ptr; /* Index into delay_buf */
-  LONG	 delay_buf_cnt;	/* No. of active entries in delay_buf */
+  st_sample_t *delay_buf;   /* Old samples, used for delay processing */
+  st_ssize_t delay_buf_size;/* Size of delay_buf in samples */
+  st_ssize_t delay_buf_ptr; /* Index into delay_buf */
+  st_ssize_t delay_buf_cnt; /* No. of active entries in delay_buf */
 } *compand_t;
 
 /*
@@ -258,7 +258,7 @@
 
 static void doVolume(double *v, double samp, compand_t l, int chan)
 {
-  double s = samp/(~((LONG)1<<31));
+  double s = samp/(~((st_sample_t)1<<31));
   double delta = s - *v;
 
   if (delta > 0.0) /* increase volume according to attack rate */
--- a/src/copy.c
+++ b/src/copy.c
@@ -49,7 +49,7 @@
 	int done;
 	
 	done = ((*isamp < *osamp) ? *isamp : *osamp);
-	memcpy(obuf, ibuf, done * sizeof(LONG));
+	memcpy(obuf, ibuf, done * sizeof(st_sample_t));
 	*isamp = *osamp = done;
 	return (ST_SUCCESS);
 }
--- a/src/cvsd.c
+++ b/src/cvsd.c
@@ -34,7 +34,6 @@
 
 /* ---------------------------------------------------------------------- */
 
-#include <limits.h>
 #include <math.h>
 #include <string.h>
 #include <time.h>
@@ -315,7 +314,7 @@
 				p->com.v_max = oval;
 			if (oval < p->com.v_min)
 				p->com.v_min = oval;
-			*buf++ = (oval * ((float)LONG_MAX));
+			*buf++ = (oval * ((float)ST_SAMPLE_MAX));
 			done++;
 		}
 		p->com.phase &= 3;
@@ -359,7 +358,7 @@
 			memmove(p->c.enc.input_filter+1, p->c.enc.input_filter,
 				sizeof(p->c.enc.input_filter)-sizeof(float));
 			p->c.enc.input_filter[0] = (*buf++) / 
-				((float)LONG_MAX);
+				((float)ST_SAMPLE_MAX);
 			done++;
 		}
 		p->com.phase &= 3;
@@ -418,7 +417,7 @@
 	time_t        Unixtime;
 	unsigned      Usender;
 	unsigned      Ureceiver;
-	ULONG	      Length;
+	st_size_t     Length;
 	unsigned      Srate;
 	unsigned      Days;
 	unsigned      Custom1;
@@ -432,15 +431,15 @@
 
 /* ---------------------------------------------------------------------- */
 /* FIXME: Move these to misc.c */
-static ULONG get32(unsigned char **p)
+static uint32_t get32(unsigned char **p)
 {
-	ULONG val = (((*p)[3]) << 24) | (((*p)[2]) << 16) | 
+	uint32_t val = (((*p)[3]) << 24) | (((*p)[2]) << 16) | 
 		(((*p)[1]) << 8) | (**p);
 	(*p) += 4;
 	return val;
 }
 
-static unsigned get16(unsigned char **p)
+static uint16_t get16(unsigned char **p)
 {
 	unsigned val = (((*p)[1]) << 8) | (**p);
 	(*p) += 2;
@@ -447,7 +446,7 @@
 	return val;
 }
 
-static void put32(unsigned char **p, ULONG val)
+static void put32(unsigned char **p, uint32_t val)
 {
 	*(*p)++ = val & 0xff;
 	*(*p)++ = (val >> 8) & 0xff;
@@ -455,7 +454,7 @@
 	*(*p)++ = (val >> 24) & 0xff;
 }
 
-static void put16(unsigned char **p, unsigned val)
+static void put16(unsigned char **p, int16_t val)
 {
 	*(*p)++ = val & 0xff;
 	*(*p)++ = (val >> 8) & 0xff;
--- a/src/dat.c
+++ b/src/dat.c
@@ -28,7 +28,7 @@
 } *dat_t;
 
 /* FIXME: Move this to misc.c */
-static LONG roundoff(double x)
+static st_sample_t roundoff(double x)
 {
     if (x < 0.0) return(x - 0.5);
     else return(x + 0.5);
--- a/src/dcshift.c
+++ b/src/dcshift.c
@@ -14,7 +14,6 @@
 #include "st_i.h"
 
 #include <math.h>   /* exp(), sqrt() */
-#include <limits.h> /* LONG_MAX */
 
 /* type used for computations.
  */
@@ -76,10 +75,13 @@
         }
 
         dcs->uselimiter = 1; /* ok, we'll use it */
-        /* The following equation is derived so that there is no discontinuity in output amplitudes */
-        /* and a LONG_MAX input always maps to a LONG_MAX output when the limiter is activated. */
-        /* (NOTE: There **WILL** be a discontinuity in the slope of the output amplitudes when using the limiter.) */
-        dcs->limiterthreshhold = LONG_MAX * (ONE - (fabs(dcs->dcshift) - dcs->limitergain));
+        /* The following equation is derived so that there is no 
+	 * discontinuity in output amplitudes */
+        /* and a ST_SAMPLE_MAX input always maps to a ST_SAMPLE_MAX output 
+	 * when the limiter is activated. */
+        /* (NOTE: There **WILL** be a discontinuity in the slope of the 
+	 * output amplitudes when using the limiter.) */
+        dcs->limiterthreshhold = ST_SAMPLE_MAX * (ONE - (fabs(dcs->dcshift) - dcs->limitergain));
     }
 
     return ST_SUCCESS;
@@ -116,20 +118,20 @@
  * this could be a function on its own, with clip count and report
  * handled by eff_t and caller.
  */
-static LONG clip(dcs_t dcs, const DCSHIFT_FLOAT v)
+static st_sample_t clip(dcs_t dcs, const DCSHIFT_FLOAT v)
 {
-    if (v > LONG_MAX)
+    if (v > ST_SAMPLE_MAX)
     {
          dcs->clipped++;
-         return LONG_MAX;
+         return ST_SAMPLE_MAX;
     }
-    else if (v < -LONG_MAX)
+    else if (v < -ST_SAMPLE_MAX)
     {
         dcs->clipped++;
-        return -LONG_MAX;
+        return -ST_SAMPLE_MAX;
     }
     /* else */
-    return (LONG) v;
+    return (st_sample_t) v;
 }
 
 #ifndef MIN
@@ -147,7 +149,7 @@
     register DCSHIFT_FLOAT limitergain = dcs->limitergain;
     register DCSHIFT_FLOAT limiterthreshhold = dcs->limiterthreshhold;
     register DCSHIFT_FLOAT sample;
-    register LONG len;
+    register st_size_t len;
 
     len = MIN(*osamp, *isamp);
 
@@ -164,17 +166,17 @@
 
                 if (sample > limiterthreshhold && dcshift > 0)
                 {
-                        sample =  (sample - limiterthreshhold) * limitergain / (LONG_MAX - limiterthreshhold) + limiterthreshhold + dcshift;
+                        sample =  (sample - limiterthreshhold) * limitergain / (ST_SAMPLE_MAX - limiterthreshhold) + limiterthreshhold + dcshift;
                         dcs->limited++;
                 }
                 else if (sample < -limiterthreshhold && dcshift < 0)
                 {
-                        sample =  (sample + limiterthreshhold) * limitergain / (LONG_MAX - limiterthreshhold) - limiterthreshhold + dcshift;
+                        sample =  (sample + limiterthreshhold) * limitergain / (ST_SAMPLE_MAX - limiterthreshhold) - limiterthreshhold + dcshift;
                         dcs->limited++;
                 }
                 else
                 {
-                        sample = dcshift * LONG_MAX + sample;
+                        sample = dcshift * ST_SAMPLE_MAX + sample;
                 }
 
                 *obuf++ = clip(dcs, sample);
@@ -184,7 +186,7 @@
     {
         /* quite basic, with clipping */
         for (;len>0; len--)
-                *obuf++ = clip(dcs, dcshift * LONG_MAX + *ibuf++);
+                *obuf++ = clip(dcs, dcshift * ST_SAMPLE_MAX + *ibuf++);
     }
     return ST_SUCCESS;
 }
--- a/src/deemphas.c
+++ b/src/deemphas.c
@@ -103,8 +103,8 @@
 
 /* Private data for deemph file */
 typedef struct deemphstuff {
-     LONG lastin;
-     double    lastout;
+     st_sample_t lastin;
+     double      lastout;
 } *deemph_t;
 
 /*
--- a/src/earwax.c
+++ b/src/earwax.c
@@ -32,44 +32,45 @@
 /* A stereo fir filter. One side filters as if the signal was from
    30 degrees from the ear, the other as if 330 degrees. */
 /*                           30   330  */
-static const LONG filt[]    ={4,  -6,
-			      4,  -11,
-			      -1, -5,
-			      3,  3,
-			      -2, 5,
-			      -5, 0,
-			      9,  1,
-			      6,  3,
-			      -4, -1,
-			      -5, -3, 
-			      -2, -5,
-			      -7,  1,
-			      6,   -7,
-			      30,  -29,
-			      12,  -3,
-			      -11,  4,
-			      -3,   7,
-			      -20,  23,
-			      2,    0,
-			      1,    -6,
-			      -14,  -5,
-			      15,   -18,
-			      6,    7,
-			      15,   -10,
-			      -14,  22,
-			      -7,   -2,
-			      -4,   9,
-			      6,    -12,
-			      6,    -6,
-			      0,    -11,
-			      0,    -5, 
-			      4,     0};   
+static const st_sample_t filt[]    =
+{   4,  -6,
+    4,  -11,
+    -1,  -5,
+    3,   3,
+    -2,   5,
+    -5, 0,
+    9,  1,
+    6,  3,
+    -4, -1,
+    -5, -3, 
+    -2, -5,
+    -7,  1,
+    6,   -7,
+    30,  -29,
+    12,  -3,
+    -11,  4,
+    -3,   7,
+    -20,  23,
+    2,    0,
+    1,    -6,
+    -14,  -5,
+    15,   -18,
+    6,    7,
+    15,   -10,
+    -14,  22,
+    -7,   -2,
+    -4,   9,
+    6,    -12,
+    6,    -6,
+    0,    -11,
+    0,    -5, 
+    4,     0};   
 
 /* 32 tap stereo FIR filter needs 64 taps */
 #define EARWAX_NUMTAPS  64
 
 typedef struct earwaxstuff {
-  LONG *tap; /* taps are z^-1 delays for the FIR filter */
+  st_sample_t *tap; /* taps are z^-1 delays for the FIR filter */
 } *earwax_t;
 
 /*
@@ -102,10 +103,10 @@
   }
 
   /* allocate tap memory */
-  earwax->tap = (LONG*)malloc( sizeof(LONG) * EARWAX_NUMTAPS );
+  earwax->tap = (st_sample_t*)malloc( sizeof(st_sample_t) * EARWAX_NUMTAPS );
   if( !earwax->tap ){
     st_fail("earwax: Cannot malloc %d bytes!\n", 
-	    sizeof(LONG) * EARWAX_NUMTAPS );
+	    sizeof(st_sample_t) * EARWAX_NUMTAPS );
     return (ST_EOF);
   }
 
@@ -128,7 +129,7 @@
   earwax_t earwax = (earwax_t) effp->priv;
   int len, done;
   int i;
-  LONG output;
+  st_sample_t output;
 
   len = ((*isamp > *osamp) ? *osamp : *isamp);
 
@@ -158,7 +159,7 @@
 {
   earwax_t earwax = (earwax_t) effp->priv;
   int i,j;
-  LONG output;  
+  st_sample_t output;  
 
   for(i = EARWAX_NUMTAPS-1; i >= 0; i--){
     output = 0;
--- a/src/echo.c
+++ b/src/echo.c
@@ -70,7 +70,7 @@
 	double	*delay_buf;
 	float	in_gain, out_gain;
 	float	delay[MAX_ECHOS], decay[MAX_ECHOS];
-	LONG	samples[MAX_ECHOS], maxsamples, fade_out;
+	st_ssize_t samples[MAX_ECHOS], maxsamples, fade_out;
 } *echo_t;
 
 /* Private data for SKEL file */
@@ -190,7 +190,7 @@
 	int j;
 	
 	double d_in, d_out;
-	LONG out;
+	st_sample_t out;
 
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
 	for(done = 0; done < len; done++) {
@@ -205,7 +205,7 @@
 		}
 		/* Adjust the output volume and size to 24 bit */
 		d_out = d_out * echo->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		/* Store input in delay buffer */
 		echo->delay_buf[echo->counter] = d_in;
@@ -223,7 +223,7 @@
 {
 	echo_t echo = (echo_t) effp->priv;
 	double d_in, d_out;
-	LONG out;
+	st_sample_t out;
 	int j;
 	long done;
 
@@ -239,7 +239,7 @@
 		}
 		/* Adjust the output volume and size to 24 bit */
 		d_out = d_out * echo->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		/* Store input in delay buffer */
 		echo->delay_buf[echo->counter] = d_in;
--- a/src/echos.c
+++ b/src/echos.c
@@ -61,7 +61,7 @@
 	double	*delay_buf;
 	float	in_gain, out_gain;
 	float	delay[MAX_ECHOS], decay[MAX_ECHOS];
-	LONG	samples[MAX_ECHOS], pointer[MAX_ECHOS], sumsamples;
+	st_ssize_t samples[MAX_ECHOS], pointer[MAX_ECHOS], sumsamples;
 } *echos_t;
 
 /* Private data for SKEL file */
@@ -182,7 +182,7 @@
 	int j;
 	
 	double d_in, d_out;
-	LONG out;
+	st_sample_t out;
 
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
 	for(done = 0; done < len; done++) {
@@ -195,7 +195,7 @@
 		}
 		/* Adjust the output volume and size to 24 bit */
 		d_out = d_out * echos->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		/* Mix decay of delays and input */
 		for ( j = 0; j < echos->num_delays; j++ ) {
@@ -221,7 +221,7 @@
 {
 	echos_t echos = (echos_t) effp->priv;
 	double d_in, d_out;
-	LONG out;
+	st_sample_t out;
 	int j;
 	long done;
 
@@ -235,7 +235,7 @@
 		}
 		/* Adjust the output volume and size to 24 bit */
 		d_out = d_out * echos->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		/* Mix decay of delays and input */
 		for ( j = 0; j < echos->num_delays; j++ ) {
--- a/src/fade.c
+++ b/src/fade.c
@@ -27,7 +27,7 @@
 /* Private data for fade file */
 typedef struct fadestuff
 { /* These are measured as samples */
-    ULONG in_start,  in_stop, out_start, out_stop, samplesdone;
+    st_size_t in_start,  in_stop, out_start, out_stop, samplesdone;
     char *in_stop_str, *out_start_str, *out_stop_str;
     char in_fadetype, out_fadetype;
     int endpadwarned;
@@ -36,7 +36,7 @@
 #define FADE_USAGE "Usage: fade [ type ] fade-in-length [ stop-time [ fade-out-length ] ]\nTimes in seconds.\nFade type one of q, h, t, l or p.\n"
 
 /* prototypes */
-static double fade_gain(ULONG index, ULONG range, char fadetype);
+static double fade_gain(st_size_t index, st_size_t range, char fadetype);
 
 /*
  * Process options
@@ -216,7 +216,7 @@
     fade_t fade = (fade_t) effp->priv;
     /* len is total samples, chcnt counts channels */
     int len = 0, chcnt = 0, t_output = 0;
-    LONG t_ibuf;
+    st_sample_t t_ibuf;
 
     len = ((*isamp > *osamp) ? *osamp : *isamp);
 
@@ -337,7 +337,7 @@
 /* Function returns gain value 0.0 - 1.0 according index / range ratio
 * and -1.0 if  type is invalid
 * todo: to optimize performance calculate gain every now and then and interpolate */
-static double fade_gain(ULONG index, ULONG range, char type)
+static double fade_gain(st_size_t index, st_size_t range, char type)
 {
     double retval = 0.0, findex = 0.0;
 
--- a/src/filter.c
+++ b/src/filter.c
@@ -39,22 +39,22 @@
 
 /* Private data for Lerp via LCM file */
 typedef struct filterstuff {
-	LONG rate;
-	LONG freq0;										/* low  corner freq */
-	LONG freq1;										/* high corner freq */
-	double beta;   								/* >2 is kaiser window beta, <=2 selects nuttall window */
-	LONG Nwin;
-	Float *Fp;										/* [Xh+1] Filter coefficients */
-	LONG Xh;											/* number of past/future samples needed by filter  */
-	LONG Xt;											/* target to enter new data into X */
-	Float *X, *Y;									/* I/O buffers */
+	st_rate_t rate;
+	st_sample_t freq0;/* low  corner freq */
+	st_sample_t freq1;/* high corner freq */
+	double beta;/* >2 is kaiser window beta, <=2 selects nuttall window */
+	long Nwin;
+	Float *Fp;/* [Xh+1] Filter coefficients */
+	long Xh;/* number of past/future samples needed by filter  */
+	long Xt;/* target to enter new data into X */
+	Float *X, *Y;/* I/O buffers */
 } *filter_t;
 
 /* makeFilter() declared in resample.c */
 extern int 
-makeFilter(Float Fp[], LONG Nwing, double Froll, double Beta, LONG Num, int Normalize);
+makeFilter(Float Fp[], long Nwing, double Froll, double Beta, long Num, int Normalize);
 
-static void FiltWin(filter_t f, LONG Nx);
+static void FiltWin(filter_t f, long Nx);
 
 /*
  * Process options
@@ -86,7 +86,7 @@
 		return (ST_EOF);
 	}
 
-	if ((n >= 2) && !sscanf(argv[1], "%d", &f->Nwin))
+	if ((n >= 2) && !sscanf(argv[1], "%ld", &f->Nwin))
 	{
 		st_fail("Usage: filter low-high [ windowlength ]");
 		return (ST_EOF);
@@ -113,7 +113,7 @@
 {
 	filter_t f = (filter_t) effp->priv;
 	Float *Fp0, *Fp1;
-	LONG Xh0, Xh1, Xh;
+	long Xh0, Xh1, Xh;
 	int i;
 
 	f->rate = effp->ininfo.rate;
@@ -191,7 +191,7 @@
                    st_size_t *isamp, st_size_t *osamp)
 {
 	filter_t f = (filter_t) effp->priv;
-	LONG i, Nx, Nproc;
+	long i, Nx, Nproc;
 
 	/* constrain amount we actually process */
 	/* fprintf(stderr,"Xh %d, Xt %d, isamp %d, ",f->Xh, f->Xt, *isamp);fflush(stderr); */
@@ -242,7 +242,8 @@
 int st_filter_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
 {
 	filter_t f = (filter_t) effp->priv;
-	LONG isamp_res, *Obuf, osamp_res;
+	long isamp_res, osamp_res;
+	st_sample_t *Obuf;
 
 	/* fprintf(stderr,"Xh %d, Xt %d  <--- DRAIN\n",f->Xh, f->Xt); */
 
@@ -251,7 +252,7 @@
 	osamp_res = *osamp;
 	Obuf = obuf;
 	while (isamp_res>0 && osamp_res>0) {
-		LONG Isamp, Osamp;
+		st_sample_t Isamp, Osamp;
 		Isamp = isamp_res;
 		Osamp = osamp_res;
 		st_filter_flow(effp, NULL, Obuf, &Isamp, &Osamp);
@@ -281,7 +282,7 @@
 	return (ST_SUCCESS);
 }
 
-static double jprod(const Float *Fp, const Float *Xp, LONG ct)
+static double jprod(const Float *Fp, const Float *Xp, long ct)
 {
 	const Float *fp, *xp, *xq;
 	double v = 0;
@@ -297,7 +298,7 @@
 	return v;
 }
 
-static void FiltWin(filter_t f, LONG Nx)
+static void FiltWin(filter_t f, long Nx)
 {
 	Float *Y;
 	Float *X, *Xend;
--- a/src/flanger.c
+++ b/src/flanger.c
@@ -69,9 +69,9 @@
 	float	in_gain, out_gain;
 	float	delay, decay;
 	float	speed;
-	LONG	length;
+	st_size_t length;
 	int	*lookup_tab;
-	LONG	maxsamples, fade_out;
+	st_size_t maxsamples, fade_out;
 } *flanger_t;
 
 /* Private data for SKEL file */
@@ -212,7 +212,7 @@
 	int len, done;
 	
 	double d_in, d_out;
-	LONG out;
+	st_sample_t out;
 
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
 	for(done = 0; done < len; done++) {
@@ -225,7 +225,7 @@
 	flanger->maxsamples] * flanger->decay;
 		/* Adjust the output volume and size to 24 bit */
 		d_out = d_out * flanger->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		/* Mix decay of delay and input */
 		flanger->flangerbuf[flanger->counter] = d_in;
@@ -246,7 +246,7 @@
 	int done;
 	
 	double d_in, d_out;
-	LONG out;
+	st_sample_t out;
 
 	done = 0;
 	while ( ( done < *osamp ) && ( done < flanger->fade_out ) ) {
@@ -258,7 +258,7 @@
 	flanger->maxsamples] * flanger->decay;
 		/* Adjust the output volume and size to 24 bit */
 		d_out = d_out * flanger->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		/* Mix decay of delay and input */
 		flanger->flangerbuf[flanger->counter] = d_in;
--- a/src/g72x.h
+++ b/src/g72x.h
@@ -47,7 +47,7 @@
  * included in this Recommendation.
  */
 struct g72x_state {
-	LONG yl;	/* Locked or steady state step size multiplier. */
+	long yl;	/* Locked or steady state step size multiplier. */
 	short yu;	/* Unlocked or non-steady state step size multiplier. */
 	short dms;	/* Short term energy estimate. */
 	short dml;	/* Long term energy estimate. */
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -30,7 +30,7 @@
 
 /* Dictionary entry for Huffman (de)compression */
 typedef struct {
-	LONG frequ;
+	long frequ;
 	short dict_leftson;
 	short dict_rightson;
 } dictent;
@@ -39,11 +39,11 @@
 struct readpriv {
 	/* Static data from the header */
 	dictent *dictionary;
-	LONG checksum;
+	int32_t checksum;
 	int deltacompression;
 	/* Engine state */
-	LONG huffcount;
-	LONG cksum;
+	long huffcount;
+	long cksum;
 	int dictentry;
 	int nrbits;
 	uint32_t current;
@@ -310,8 +310,8 @@
 st_ssize_t st_hcomwrite(ft_t ft, st_sample_t *buf, st_ssize_t len)
 {
 	register struct writepriv *p = (struct writepriv *) ft->priv;
-	LONG datum;
-	LONG save_len = len;
+	st_sample_t datum;
+	st_ssize_t save_len = len;
 
 	if (len == 0)
 	    return (0);
@@ -348,9 +348,9 @@
 
 static dictent dictionary[511];
 static dictent *de;
-static LONG codes[256];
-static LONG codesize[256];
-static LONG checksum;
+static long codes[256];
+static long codesize[256];
+static int32_t checksum;
 
 static void makecodes(int e, int c, int s, int b)
 {
@@ -363,11 +363,11 @@
   }
 }
 
-static LONG curword;
 static int nbits;
+static int32_t curword;
 
 /* FIXME: Place in misc.c */
-static void putlong(unsigned char *c, LONG v)
+static void putlong(unsigned char *c, int32_t v)
 {
   *c++ = (v >> 24) & 0xff;
   *c++ = (v >> 16) & 0xff;
@@ -384,8 +384,9 @@
 
 static void putcode(unsigned char c, unsigned char **df)
 {
-LONG code, size;
+long code, size;
 int i;
+
   code = codes[c];
   size = codesize[c];
   for(i = 0; i < size; i++) {
@@ -403,9 +404,9 @@
   }
 }
 
-static int compress(unsigned char **df, LONG *dl, float fr)
+static int compress(unsigned char **df, int32_t *dl, float fr)
 {
-  LONG samplerate;
+  int32_t samplerate;
   unsigned char *datafork = *df;
   unsigned char *ddf;
   short dictsize;
@@ -503,7 +504,7 @@
   putlong(datafork + 4, *dl);
   putlong(datafork + 8, checksum);
   putlong(datafork + 12, 1L);
-  samplerate = 22050 / (LONG)fr;
+  samplerate = 22050 / (int32_t)fr;
   putlong(datafork + 16, samplerate);
   putshort(datafork + 20, dictsize);
   *df = datafork;		/* reassign passed pointer to new datafork */
@@ -526,7 +527,7 @@
 {
 	register struct writepriv *p = (struct writepriv *) ft->priv;
 	unsigned char *compressed_data = p->data;
-	LONG compressed_len = p->pos;
+	uint32_t compressed_len = p->pos;
 	int rc;
 
 	/* Compress it all at once */
@@ -543,8 +544,8 @@
 	padbytes(ft, 65-3);
 	st_writes(ft, "FSSD");
 	padbytes(ft, 83-69);
-	st_writedw(ft, (ULONG) compressed_len); /* compressed_data size */
-	st_writedw(ft, (ULONG) 0); /* rsrc size */
+	st_writedw(ft, (uint32_t) compressed_len); /* compressed_data size */
+	st_writedw(ft, (uint32_t) 0); /* rsrc size */
 	padbytes(ft, 128 - 91);
 	if (ferror(ft->fp))
 	{
--- a/src/highp.c
+++ b/src/highp.c
@@ -84,7 +84,7 @@
 	highp_t highp = (highp_t) effp->priv;
 	int len, done;
 	double d;
-	LONG l;
+	st_sample_t l;
 
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
 
--- a/src/ima_rw.c
+++ b/src/ima_rw.c
@@ -335,14 +335,14 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing.
  */
-ULONG ImaSamplesIn(
-  ULONG dataLen,
+st_size_t ImaSamplesIn(
+  st_size_t dataLen,
   unsigned short chans,
   unsigned short blockAlign,
   unsigned short samplesPerBlock
 )
 {
-  ULONG m, n;
+  st_size_t m, n;
 
   if (samplesPerBlock) {
     n = (dataLen / blockAlign) * samplesPerBlock;
@@ -363,22 +363,22 @@
 }
 
 /*
- * ULONG ImaBytesPerBlock(chans, samplesPerBlock)
+ * st_size_t ImaBytesPerBlock(chans, samplesPerBlock)
  *   return minimum blocksize which would be required
  *   to encode number of chans with given samplesPerBlock
  */
-ULONG ImaBytesPerBlock(
+st_size_t ImaBytesPerBlock(
   unsigned short chans,
   unsigned short samplesPerBlock
 )
 {
-  ULONG n;
+  st_size_t n;
   /* per channel, ima has blocks of len 4, the 1st has 1st sample, the others
    * up to 8 samples per block,
    * so number of later blocks is (nsamp-1 + 7)/8, total blocks/chan is
    * (nsamp-1+7)/8 + 1 = (nsamp+14)/8
    */
-  n = ((ULONG)samplesPerBlock + 14)/8 * 4 * chans;
+  n = ((st_size_t)samplesPerBlock + 14)/8 * 4 * chans;
   return n;
 }
 
--- a/src/ima_rw.h
+++ b/src/ima_rw.h
@@ -77,8 +77,8 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing usage.
  */
-extern ULONG ImaSamplesIn(
-	ULONG dataLen,
+extern st_size_t ImaSamplesIn(
+	st_size_t dataLen,
 	unsigned short chans,
 	unsigned short blockAlign,
 	unsigned short samplesPerBlock
@@ -85,11 +85,11 @@
 );
 
 /*
- * ULONG ImaBytesPerBlock(chans, samplesPerBlock)
+ * st_size_t ImaBytesPerBlock(chans, samplesPerBlock)
  *   return minimum blocksize which would be required
  *   to encode number of chans with given samplesPerBlock
  */
-extern ULONG ImaBytesPerBlock(
+extern st_size_t ImaBytesPerBlock(
 	unsigned short chans,
 	unsigned short samplesPerBlock
 );
--- a/src/lowp.c
+++ b/src/lowp.c
@@ -80,7 +80,7 @@
 	lowp_t lowp = (lowp_t) effp->priv;
 	int len, done;
 	double d;
-	LONG l;
+	st_sample_t l;
 
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
 
--- a/src/mask.c
+++ b/src/mask.c
@@ -49,8 +49,8 @@
 {
 	int len, done;
 	
-	LONG l;
-	LONG tri16;	/* 16 signed bits of triangular noise */
+	st_sample_t l;
+	st_sample_t tri16;	/* 16 signed bits of triangular noise */
 
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
 	switch (effp->outinfo.encoding) {
--- a/src/maud.c
+++ b/src/maud.c
@@ -323,8 +323,8 @@
 	st_writes(ft, "MAUD"); /* File type */
 	
 	st_writes(ft, "MHDR");
-	st_writedw(ft, (LONG) 8*4); /* number of bytes to follow */
-	st_writedw(ft, (LONG) (p->nsamples ));  /* number of samples stored in MDAT */
+	st_writedw(ft,  8*4); /* number of bytes to follow */
+	st_writedw(ft, p->nsamples);  /* number of samples stored in MDAT */
 	
 	switch (ft->info.encoding) {
 		
@@ -346,7 +346,7 @@
 		
 	}
 	
-	st_writedw(ft, (LONG) ft->info.rate); /* clock source frequency */
+	st_writedw(ft, ft->info.rate); /* clock source frequency */
 	st_writew(ft, (int) 1); /* clock devide */
 	
 	if (ft->info.channels == 1) {
@@ -375,12 +375,12 @@
 		
 	}
 	
-	st_writedw(ft, (LONG) 0); /* reserved */
-	st_writedw(ft, (LONG) 0); /* reserved */
-	st_writedw(ft, (LONG) 0); /* reserved */
+	st_writedw(ft, 0); /* reserved */
+	st_writedw(ft, 0); /* reserved */
+	st_writedw(ft, 0); /* reserved */
 	
 	st_writes(ft, "ANNO");
-	st_writedw(ft, (LONG) 30); /* length of block */
+	st_writedw(ft, 30); /* length of block */
 	st_writes(ft, "file create by Sound eXchange ");
 	
 	st_writes(ft, "MDAT");
--- a/src/misc.c
+++ b/src/misc.c
@@ -312,7 +312,7 @@
 
 st_sample_t st_lcm(st_sample_t a, st_sample_t b)
 {
-    /* parenthesize this way to avoid LONG overflow in the product term */
+    /* parenthesize this way to avoid st_sample_t overflow in product term */
     return a * (b / st_gcd(a, b));
 }
 
@@ -466,5 +466,5 @@
 
     fstat(fileno(ft->fp), &st);
 
-    return (LONG)st.st_size;
+    return (st_size_t)st.st_size;
 }
--- a/src/pan.c
+++ b/src/pan.c
@@ -18,9 +18,6 @@
 
 #include "st_i.h"
 
-/* should be taken care in st.h? */
-#include <limits.h> /* LONG_MAX */
-
 /* type for computations.
    float mantissa is okay for 8 or 16 bits signals.
    maybe a little bit short for 24 bits.
@@ -100,20 +97,20 @@
  * Okay, it might be quite slow to have such a function for so small
  * a task. Hopefully the function can be inlined by the compiler?
  */
-static LONG clip(pan_t pan, PAN_FLOAT value)
+static st_sample_t clip(pan_t pan, PAN_FLOAT value)
 {
-    if (value < -LONG_MAX) 
+    if (value < -ST_SAMPLE_MAX) 
     {
 	pan->clipped++;
-	return -LONG_MAX;
+	return -ST_SAMPLE_MAX;
     }
-    else if (value > LONG_MAX) 
+    else if (value > ST_SAMPLE_MAX) 
     {
 	pan->clipped++;
-	return LONG_MAX;
+	return ST_SAMPLE_MAX;
     } /* else */
 
-    return (LONG) value;
+    return (st_sample_t) value;
 }
 
 #ifndef MIN
@@ -131,7 +128,7 @@
                 st_size_t *isamp, st_size_t *osamp)
 {
     pan_t pan = (pan_t) effp->priv;
-    register LONG len;
+    register st_size_t len;
     register int done, ich, och;
     register PAN_FLOAT left, right, dir, hdir;
     
--- a/src/phaser.c
+++ b/src/phaser.c
@@ -71,9 +71,9 @@
 	float	in_gain, out_gain;
 	float	delay, decay;
 	float	speed;
-	LONG    length;
+	st_size_t length;
 	int	*lookup_tab;
-	LONG	maxsamples, fade_out;
+	st_size_t maxsamples, fade_out;
 } *phaser_t;
 
 /*
@@ -199,7 +199,7 @@
 	int len, done;
 	
 	double d_in, d_out;
-	LONG out;
+	st_sample_t out;
 
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
 	for(done = 0; done < len; done++) {
@@ -212,7 +212,7 @@
 	phaser->maxsamples] * phaser->decay * -1.0;
 		/* Adjust the output volume and size to 24 bit */
 		d_out = d_in * phaser->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		/* Mix decay of delay and input */
 		phaser->phaserbuf[phaser->counter] = d_in;
@@ -233,7 +233,7 @@
 	int done;
 	
 	double d_in, d_out;
-	LONG out;
+	st_sample_t out;
 
 	done = 0;
 	while ( ( done < *osamp ) && ( done < phaser->fade_out ) ) {
@@ -245,7 +245,7 @@
 	phaser->maxsamples] * phaser->decay * -1.0;
 		/* Adjust the output volume and size to 24 bit */
 		d_out = d_in * phaser->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		/* Mix decay of delay and input */
 		phaser->phaserbuf[phaser->counter] = d_in;
--- a/src/pitch.c
+++ b/src/pitch.c
@@ -41,7 +41,6 @@
 #include <string.h> /* memcpy() */
 
 #include <math.h>   /* cos(), pow() */
-#include <limits.h> /* LONG_MAX */
 
 #ifndef MIN
 #define MIN(a,b) (((a)<(b))?(a):(b))
@@ -132,9 +131,9 @@
 
     int iacc;            /* part of acc already output */
 
-    LONG size;           /* size of buffer for processing chunks. */
+    st_size_t size;      /* size of buffer for processing chunks. */
     int index;           /* index of next empty input item. */
-    LONG * buf;          /* bufferize input */
+    st_sample_t *buf;    /* bufferize input */
 
     pitch_state_t state; /* buffer management status. */
 
@@ -202,7 +201,7 @@
  */
 static void interpolation(
   pitch_t pitch,
-  LONG * ibuf, int ilen, 
+  st_sample_t *ibuf, int ilen, 
   PITCH_FLOAT * out, int olen,
   PITCH_FLOAT rate) /* signed */
 {
@@ -276,20 +275,20 @@
 	pitch->acc[i] += pitch->fade[pitch->step-i-1]*pitch->tmp[i];
 }
 
-static LONG clip(pitch_t pitch, PITCH_FLOAT v)
+static st_sample_t clip(pitch_t pitch, PITCH_FLOAT v)
 {
-    if (v < -LONG_MAX)
+    if (v < -ST_SAMPLE_MAX)
     {
 	pitch->clipped++;
-	return -LONG_MAX;
+	return -ST_SAMPLE_MAX;
     }
-    else if (v > LONG_MAX)
+    else if (v > ST_SAMPLE_MAX)
     {
 	pitch->clipped++;
-	return LONG_MAX;
+	return ST_SAMPLE_MAX;
     }
     else
-	return (LONG) v;
+	return (st_sample_t) v;
 }
 
 /*
@@ -427,7 +426,7 @@
     pitch->fade = (PITCH_FLOAT *) malloc(pitch->step*sizeof(PITCH_FLOAT));
     pitch->tmp  = (PITCH_FLOAT *) malloc(pitch->step*sizeof(PITCH_FLOAT));
     pitch->acc  = (PITCH_FLOAT *) malloc(pitch->step*sizeof(PITCH_FLOAT));
-    pitch->buf  = (LONG *) malloc(pitch->size*sizeof(LONG));
+    pitch->buf  = (st_sample_t *) malloc(pitch->size*sizeof(st_sample_t));
 
     if (!pitch->fade || !pitch->tmp || !pitch->acc || !pitch->buf)
     {
@@ -519,7 +518,7 @@
 	{
 	    register int tocopy = MIN(pitch->size-pitch->index, len);
 
-	    memcpy(pitch->buf+pitch->index, ibuf+iindex, tocopy*sizeof(LONG));
+	    memcpy(pitch->buf+pitch->index, ibuf+iindex, tocopy*sizeof(st_sample_t));
 
 	    len -= tocopy;
 	    pitch->index += tocopy;
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -31,7 +31,6 @@
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <limits.h>
 #include <string.h>
 #include "st_i.h"
 
@@ -51,11 +50,11 @@
 
 typedef struct polyphase {
 
-  ULONG lcmrate;       		 /* least common multiple of rates */
-  ULONG 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        */
-  ULONG oskip;   	         /* output samples to skip at start*/
+  ulong 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 */
 
@@ -201,8 +200,8 @@
   
   for (k=ct; k>1; ) {
     int tmp;
-    ULONG j;
-    j = (ULONG)(rand()%32768L) + ((ULONG)(rand()%32768L)<<13); /* reasonably big */
+    unsigned long j;
+    j = (rand()%32768L) + ((rand()%32768L)<<13); /* reasonably big */
     j = j % k; /* non-negative! */
     k--;
     if (j != k) {
@@ -387,7 +386,7 @@
     poly_t rate = (poly_t) effp->priv;
     static int l1[MF], l2[MF];
     double skip = 0;
-		int total, size, uprate;
+    int total, size, uprate;
     int k;
 
     if (effp->ininfo.rate == effp->outinfo.rate)
@@ -398,7 +397,8 @@
 
     st_initrand();
 
-    rate->lcmrate = st_lcm((LONG)effp->ininfo.rate, (LONG)effp->outinfo.rate);
+    rate->lcmrate = st_lcm((st_sample_t)effp->ininfo.rate, 
+	                   (st_sample_t)effp->outinfo.rate);
 
     /* Cursory check for LCM overflow.  
      * If both rate are below 65k, there should be no problem.
@@ -535,14 +535,12 @@
 
 }
 
-static Float FLONG_MAX = LONG_MAX;
-
-static LONG clipfloat(Float sample)
+static st_sample_t clipfloat(Float sample)
 {
-	if (sample > FLONG_MAX)
-	return LONG_MAX;
-	if (sample < -FLONG_MAX)
-	return -LONG_MAX;
+	if (sample > ST_SAMPLE_MAX)
+	return ST_SAMPLE_MAX;
+	if (sample < -ST_SAMPLE_MAX)
+	return -ST_SAMPLE_MAX;
 	return sample;
 }
 
@@ -606,9 +604,9 @@
   }
 
   {
-    LONG *q;
-    LONG out_size;
-    LONG oskip;
+    st_sample_t *q;
+    st_size_t out_size;
+    st_size_t oskip;
     Float *out_buf;
     int k;
 
@@ -646,7 +644,7 @@
  */
 int st_poly_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
 {
-  LONG in_size;
+  st_size_t in_size;
   /* Call "flow" with NULL input. */
   st_poly_flow(effp, NULL, obuf, &in_size, osamp);
   return (ST_SUCCESS);
--- a/src/rate.c
+++ b/src/rate.c
@@ -39,15 +39,15 @@
 
 /* Private data */
 typedef struct ratestuff {
-        ULONG opos_frac;  /* fractional position of the output stream in input stream unit */
-        ULONG opos;
+        unsigned long opos_frac;  /* fractional position of the output stream in input stream unit */
+        unsigned long opos;
 
-        ULONG opos_inc_frac;  /* fractional position increment in the output stream */
-        ULONG opos_inc; 
+        unsigned long opos_inc_frac;  /* fractional position increment in the output stream */
+        unsigned long opos_inc; 
 
-        ULONG ipos;      /* position in the input stream (integer) */
+        unsigned long ipos;      /* position in the input stream (integer) */
 
-        LONG ilast; /* last sample in the input stream */
+        st_sample_t ilast; /* last sample in the input stream */
 } *rate_t;
 
 /*
@@ -69,7 +69,7 @@
 int st_rate_start(eff_t effp)
 {
 	rate_t rate = (rate_t) effp->priv;
-        ULONG incr;
+        unsigned long incr;
 
 	if (effp->ininfo.rate == effp->outinfo.rate)
 	{
@@ -92,7 +92,7 @@
         rate->opos=0;
 
         /* increment */
-        incr=(ULONG)((double)effp->ininfo.rate / (double)effp->outinfo.rate * 
+        incr=(unsigned long)((double)effp->ininfo.rate / (double)effp->outinfo.rate * 
                    (double) ((unsigned long) 1 << FRAC_BITS));
 
         rate->opos_inc_frac = incr & (((unsigned long) 1 << FRAC_BITS)-1);
@@ -112,10 +112,10 @@
                  st_size_t *isamp, st_size_t *osamp)
 {
 	rate_t rate = (rate_t) effp->priv;
-	LONG *istart,*iend;
-	LONG *ostart,*oend;
-	LONG ilast,icur,out;
-        ULONG tmp;
+	st_sample_t *istart,*iend;
+	st_sample_t *ostart,*oend;
+	st_sample_t ilast,icur,out;
+        unsigned long tmp;
         double t;
 
         ilast=rate->ilast;
@@ -148,7 +148,7 @@
 
                 /* output sample & increment position */
                 
-                *obuf++=(LONG) out;
+                *obuf++=(st_sample_t) out;
                 
                 tmp = rate->opos_frac + rate->opos_inc_frac;
                 rate->opos = rate->opos + rate->opos_inc + (tmp >> FRAC_BITS);
@@ -226,11 +226,11 @@
 
 /* Private data for Lerp via LCM file */
 typedef struct ratestuff {
-	ULONG	lcmrate;		/* least common multiple of rates */
-	ULONG	inskip, outskip;	/* LCM increments for I & O rates */
-	ULONG	total;
-	ULONG	intot, outtot;		/* total samples in LCM basis */
-	LONG	lastsamp;		/* history */
+	st_rate_t lcmrate;		/* least common multiple of rates */
+	unsigned long inskip, outskip;	/* LCM increments for I & O rates */
+	unsigned long total;
+	unsigned long intot, outtot;	/* total samples in LCM basis */
+	st_sample_t lastsamp;		/* history */
 } *rate_t;
 
 /*
@@ -253,7 +253,7 @@
 {
 	rate_t rate = (rate_t) effp->priv;
 	
-	rate->lcmrate = lcm((LONG)effp->ininfo.rate, (LONG)effp->outinfo.rate);
+	rate->lcmrate = st_lcm((st_sample_t)effp->ininfo.rate, (st_sample_t)effp->outinfo.rate);
 	/* 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.
@@ -274,8 +274,8 @@
 {
 	rate_t rate = (rate_t) effp->priv;
 	int len, done;
-	LONG *istart = ibuf;
-	LONG last;
+	st_sample_t *istart = ibuf;
+	st_sample_t last;
 
 	done = 0;
 	if (rate->total == 0) {
--- a/src/resampl.h
+++ b/src/resampl.h
@@ -54,7 +54,7 @@
  *    the input array (X), and to the right, it is interpreted as a number
  *    between 0 and 1 sample of the input X.  The default value of 23 is
  *    about right.  There is a constraint that the filter window must be
- *    "addressable" in a LONG int, more precisely, if Nmult is the number
+ *    "addressable" in a int32_t, more precisely, if Nmult is the number
  *    of sinc zero-crossings in the right wing of the filter window, then
  *    (Nwing<<Lp) must be expressible in 31 bits.
  *
--- a/src/resample.c
+++ b/src/resample.c
@@ -73,41 +73,41 @@
    double rolloff;    /* roll-off frequency */
    double beta;       /* passband/stopband tuning magic */
    int quadr;         /* non-zero to use qprodUD quadratic interpolation */
-   LONG Nmult;
-   LONG Nwing;
-   LONG Nq;
+   long Nmult;
+   long Nwing;
+   long Nq;
    Float *Imp;        /* impulse [Nwing+1] Filter coefficients */
 
    double Time;       /* Current time/pos in input sample */
-   LONG dhb;
+   long dhb;
 
-   LONG a,b;          /* gcd-reduced input,output rates   */
-   LONG t;            /* Current time/pos for exact-coeff's method */
+   long a,b;          /* gcd-reduced input,output rates   */
+   long t;            /* Current time/pos for exact-coeff's method */
 
-   LONG Xh;           /* number of past/future samples needed by filter  */
-   LONG Xoff;         /* Xh plus some room for creep  */
-   LONG Xread;        /* X[Xread] is start-position to enter new samples */
-   LONG Xp;           /* X[Xp] is position to start filter application   */
-   LONG Xsize,Ysize;  /* size (Floats) of X[],Y[]         */
+   long Xh;           /* number of past/future samples needed by filter  */
+   long Xoff;         /* Xh plus some room for creep  */
+   long Xread;        /* X[Xread] is start-position to enter new samples */
+   long Xp;           /* X[Xp] is position to start filter application   */
+   long Xsize,Ysize;  /* size (Floats) of X[],Y[]         */
    Float *X, *Y;      /* I/O buffers */
 } *resample_t;
 
 static void LpFilter(double c[],
-		     LONG N,
+		     long N,
 		     double frq,
 		     double Beta,
-		     LONG Num);
+		     long Num);
 
 /* makeFilter is used by filter.c */
 int makeFilter(Float Imp[],
-	       LONG Nwing,
+	       long Nwing,
 	       double Froll,
 	       double Beta,
-	       LONG Num,
+	       long Num,
 	       int Normalize);
 
-static LONG SrcUD(resample_t r, LONG Nx);
-static LONG SrcEX(resample_t r, LONG Nx);
+static long SrcUD(resample_t r, long Nx);
+static long SrcEX(resample_t r, long Nx);
 
 
 /*
@@ -174,9 +174,8 @@
 int st_resample_start(eff_t effp)
 {
 	resample_t r = (resample_t) effp->priv;
-	LONG Xoff, gcdrate;
+	long Xoff, gcdrate;
 	int i;
-	extern LONG st_gcd(LONG a,LONG b);
 
 	if (effp->ininfo.rate == effp->outinfo.rate)
 	{
@@ -186,7 +185,7 @@
 		
 	r->Factor = (double)effp->outinfo.rate / (double)effp->ininfo.rate;
 
-	gcdrate = st_gcd((LONG)effp->ininfo.rate, (LONG)effp->outinfo.rate);
+	gcdrate = st_gcd((long)effp->ininfo.rate, (long)effp->outinfo.rate);
 	r->a = effp->ininfo.rate / gcdrate;
 	r->b = effp->outinfo.rate / gcdrate;
 
@@ -270,7 +269,7 @@
                      st_size_t *isamp, st_size_t *osamp)
 {
 	resample_t r = (resample_t) effp->priv;
-	LONG i, last, Nout, Nx, Nproc;
+	long i, last, Nout, Nx, Nproc;
 
 	/* constrain amount we actually process */
 	/*fprintf(stderr,"Xp %d, Xread %d, isamp %d, ",r->Xp, r->Xread,*isamp);*/
@@ -309,7 +308,7 @@
 		return (ST_SUCCESS);
 	}
 	if (r->quadr < 0) { /* exact coeff's method */
-		LONG creep; 
+		long creep; 
 		Nout = SrcEX(r, Nproc);
 		/*fprintf(stderr,"Nproc %d --> %d\n",Nproc,Nout);*/
 		/* Move converter Nproc samples back in time */
@@ -325,7 +324,7 @@
 		  /*fprintf(stderr,"Nproc %ld, creep %ld\n",Nproc,creep);*/
 		}
 	} else { /* approx coeff's method */
-		LONG creep; 
+		long creep; 
 		Nout = SrcUD(r, Nproc);
 		/*fprintf(stderr,"Nproc %d --> %d\n",Nproc,Nout);*/
 		/* Move converter Nproc samples back in time */
@@ -343,7 +342,7 @@
 	}
 
 	{
-	LONG i,k;
+	long i,k;
 	/* Copy back portion of input signal that must be re-used */
 	k = r->Xp - r->Xoff;
 	/*fprintf(stderr,"k %d, last %d\n",k,last);*/
@@ -370,7 +369,8 @@
 int st_resample_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
 {
 	resample_t r = (resample_t) effp->priv;
-	LONG isamp_res, *Obuf, osamp_res;
+	long isamp_res, osamp_res;
+	st_sample_t *Obuf;
 	int rc;
 
 	/* fprintf(stderr,"Xoff %d, Xt %d  <--- DRAIN\n",r->Xoff, r->Xt); */
@@ -380,7 +380,7 @@
 	osamp_res = *osamp;
 	Obuf = obuf;
 	while (isamp_res>0 && osamp_res>0) {
-		LONG Isamp, Osamp;
+		st_sample_t Isamp, Osamp;
 		Isamp = isamp_res;
 		Osamp = osamp_res;
 		rc = st_resample_flow(effp, NULL, Obuf, &Isamp, &Osamp);
@@ -415,12 +415,12 @@
 
 /* over 90% of CPU time spent in this iprodUD() function */
 /* quadratic interpolation */
-static double qprodUD(const Float Imp[], const Float *Xp, LONG Inc, double T0, 
-	              LONG dhb, LONG ct)
+static double qprodUD(const Float Imp[], const Float *Xp, long Inc, double T0, 
+	              long dhb, long ct)
 {
   const double f = 1.0/(1<<La);
   double v;
-  LONG Ho;
+  long Ho;
 
   Ho = T0 * dhb;
   Ho += (ct-1)*dhb; /* so Float sum starts with smallest coef's */
@@ -428,7 +428,7 @@
   v = 0;
   do {
     Float coef;
-    LONG Hoh;
+    long Hoh;
     Hoh = Ho>>La;
     coef = Imp[Hoh];
     {
@@ -447,12 +447,12 @@
 }
 
 /* linear interpolation */
-static double iprodUD(const Float Imp[], const Float *Xp, LONG Inc, 
-	              double T0, LONG dhb, LONG ct)
+static double iprodUD(const Float Imp[], const Float *Xp, long Inc, 
+	              double T0, long dhb, long ct)
 {
   const double f = 1.0/(1<<La);
   double v;
-  LONG Ho;
+  long Ho;
 
   Ho = T0 * dhb;
   Ho += (ct-1)*dhb; /* so Float sum starts with smallest coef's */
@@ -460,7 +460,7 @@
   v = 0;
   do {
     Float coef;
-    LONG Hoh;
+    long Hoh;
     Hoh = Ho>>La;
     /* if (Hoh >= End) break; */
     coef = Imp[Hoh] + (Imp[Hoh+1]-Imp[Hoh]) * (Ho & Amask) * f;
@@ -475,7 +475,7 @@
 /* From resample:filters.c */
 /* Sampling rate conversion subroutine */
 
-static LONG SrcUD(resample_t r, LONG Nx)
+static long SrcUD(resample_t r, long Nx)
 {
    Float *Ystart, *Y;
    double Factor;
@@ -503,7 +503,7 @@
       double v;
       double T;
       T = time-floor(time);        /* fractional part of Time */
-      Xp = r->X + (LONG)time;      /* Ptr to current input sample */
+      Xp = r->X + (long)time;      /* Ptr to current input sample */
 
       /* Past  inner product: */
       v = (*prodUD)(r->Imp, Xp, -1, T, r->dhb, r->Xh); /* needs Np*Nmult in 31 bits */
@@ -521,7 +521,7 @@
 
 /* exact coeff's */
 static double prodEX(const Float Imp[], const Float *Xp, 
-	             LONG Inc, LONG T0, LONG dhb, LONG ct)
+	             long Inc, long T0, long dhb, long ct)
 {
   double v;
   const Float *Cp;
@@ -537,12 +537,12 @@
   return v;
 }
 
-static LONG SrcEX(resample_t r, LONG Nx)
+static long SrcEX(resample_t r, long Nx)
 {
    Float *Ystart, *Y;
    double Factor;
-   LONG a,b;
-   LONG time;
+   long a,b;
+   long time;
    int n;
 
    Factor = r->Factor;
@@ -555,7 +555,7 @@
       {
 	Float *Xp;
 	double v;
-	LONG T;
+	long T;
 	T = time % b;              /* fractional part of Time */
 	Xp = r->X + (time/b);      /* Ptr to current input sample */
 
@@ -572,11 +572,11 @@
    return (Y - Ystart);        /* Return the number of output samples */
 }
 
-int makeFilter(Float Imp[], LONG Nwing, double Froll, double Beta, 
-	       LONG Num, int Normalize)
+int makeFilter(Float Imp[], long Nwing, double Froll, double Beta, 
+	       long Num, int Normalize)
 {
    double *ImpR;
-   LONG Mwing, i;
+   long Mwing, i;
 
    if (Nwing > MAXNWING)                      /* Check for valid parameters */
       return(-1);
@@ -595,7 +595,7 @@
    LpFilter(ImpR, Mwing, Froll, Beta, Num);
 
    if (Normalize) { /* 'correct' the DC gain of the lowpass filter */
-      LONG Dh;
+      long Dh;
       double DCgain;
       DCgain = 0;
       Dh = Num;                  /* Filter sampling period for factors>=1 */
@@ -663,7 +663,7 @@
 static double Izero(double x)
 {
    double sum, u, halfx, temp;
-   LONG n;
+   long n;
 
    sum = u = n = 1;
    halfx = x/2.0;
@@ -677,9 +677,9 @@
    return(sum);
 }
 
-static void LpFilter(double *c, LONG N, double frq, double Beta, LONG Num)
+static void LpFilter(double *c, long N, double frq, double Beta, long Num)
 {
-   LONG i;
+   long i;
 
    /* Calculate filter coeffs: */
    c[0] = frq;
--- a/src/reverb.c
+++ b/src/reverb.c
@@ -107,7 +107,7 @@
 	float	in_gain, out_gain, time;
 	float	delay[MAXREVERBS], decay[MAXREVERBS];
 	long	samples[MAXREVERBS], maxsamples;
-	LONG	pl, ppl, pppl;
+	st_sample_t pl, ppl, pppl;
 } *reverb_t;
 
 /*
@@ -214,7 +214,7 @@
 	int i, j;
 	
 	float d_in, d_out;
-	LONG out;
+	st_sample_t out;
 
 	i = reverb->counter;
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
@@ -227,7 +227,7 @@
 			d_in +=
 reverb->reverbbuf[(i + reverb->maxsamples - reverb->samples[j]) % reverb->maxsamples] * reverb->decay[j];
 		d_out = d_in * reverb->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		*obuf++ = out * 256;
 		reverb->reverbbuf[i] = d_in;
 		i++;		/* XXX need a % maxsamples here ? */
@@ -245,7 +245,7 @@
 {
 	reverb_t reverb = (reverb_t) effp->priv;
 	float d_in, d_out;
-	LONG out, l;
+	st_sample_t out, l;
 	int i, j, done;
 
 	i = reverb->counter;
@@ -258,10 +258,10 @@
 			d_in += 
 reverb->reverbbuf[(i + reverb->maxsamples - reverb->samples[j]) % reverb->maxsamples] * reverb->decay[j];
 		d_out = d_in * reverb->out_gain;
-		out = st_clip24((LONG) d_out);
+		out = st_clip24((st_sample_t) d_out);
 		obuf[done++] = out * 256;
 		reverb->reverbbuf[i] = d_in;
-		l = st_clip24((LONG) d_in);
+		l = st_clip24((st_sample_t) d_in);
 		reverb->pppl = reverb->ppl;
 		reverb->ppl = reverb->pl;
 		reverb->pl = l;
--- a/src/reverse.c
+++ b/src/reverse.c
@@ -23,7 +23,7 @@
 /* Private data */
 typedef struct reversestuff {
 	FILE *fp;
-	LONG pos;
+	st_size_t pos;
 	int phase;
 } *reverse_t;
 
@@ -75,7 +75,7 @@
 		st_fail("Internal error: reverse_flow called in wrong phase");
 		return(ST_EOF);
 	}
-	if (fwrite((char *)ibuf, sizeof(LONG), *isamp, reverse->fp)
+	if (fwrite((char *)ibuf, sizeof(st_sample_t), *isamp, reverse->fp)
 	    != *isamp)
 	{
 		st_fail("Reverse effect write error on temporary file\n");
@@ -94,13 +94,13 @@
 	reverse_t reverse = (reverse_t) effp->priv;
 	int len, nbytes;
 	register int i, j;
-	LONG temp;
+	st_sample_t temp;
 
 	if (reverse->phase == WRITING) {
 		fflush(reverse->fp);
 		fseek(reverse->fp, 0L, SEEK_END);
 		reverse->pos = ftell(reverse->fp);
-		if (reverse->pos % sizeof(LONG) != 0)
+		if (reverse->pos % sizeof(st_sample_t) != 0)
 		{
 			st_fail("Reverse effect finds odd temporary file\n");
 			return(ST_EOF);
@@ -108,14 +108,14 @@
 		reverse->phase = READING;
 	}
 	len = *osamp;
-	nbytes = len * sizeof(LONG);
+	nbytes = len * sizeof(st_sample_t);
 	if (reverse->pos < nbytes) {
 		nbytes = reverse->pos;
-		len = nbytes / sizeof(LONG);
+		len = nbytes / sizeof(st_sample_t);
 	}
 	reverse->pos -= nbytes;
 	fseek(reverse->fp, reverse->pos, SEEK_SET);
-	if (fread((char *)obuf, sizeof(LONG), len, reverse->fp) != len)
+	if (fread((char *)obuf, sizeof(st_sample_t), len, reverse->fp) != len)
 	{
 		st_fail("Reverse effect read error from temporary file\n");
 		return(ST_EOF);
--- a/src/sf.c
+++ b/src/sf.c
@@ -27,7 +27,7 @@
 typedef struct sfstuff {
         struct sfinfo info;
         /* needed for seek */
-        LONG dataStart;
+        st_size_t dataStart;
 } *sf_t;
 
 /*
--- a/src/sfircam.h
+++ b/src/sfircam.h
@@ -24,19 +24,19 @@
 #define SF_NEXT 4
 #ifdef vax
 #define SF_MACHINE SF_VAX
-#define SF_MAGIC ((LONG)(SF_MAGIC1 | SF_MAGIC2 << 8 | SF_MACHINE << 16))
+#define SF_MAGIC ((uint32_t)(SF_MAGIC1 | SF_MAGIC2 << 8 | SF_MACHINE << 16))
 #endif
 #ifdef sun
 #define SF_MACHINE SF_SUN
-#define SF_MAGIC ((LONG)(SF_MAGIC1 << 24 | SF_MAGIC2 << 16 | SF_MACHINE << 8))
+#define SF_MAGIC ((uint32_t)(SF_MAGIC1 << 24 | SF_MAGIC2 << 16 | SF_MACHINE << 8))
 #endif
 #ifdef mips
 #define SF_MACHINE SF_MIPS
-#define SF_MAGIC ((LONG)(SF_MAGIC1 | SF_MAGIC2 << 8 | SF_MACHINE << 16))
+#define SF_MAGIC ((uint32_t)(SF_MAGIC1 | SF_MAGIC2 << 8 | SF_MACHINE << 16))
 #endif
 #ifdef NeXT
 #define SF_MACHINE SF_NEXT
-#define SF_MAGIC ((LONG)(SF_MAGIC1 << 24 | SF_MAGIC2 << 16 | SF_MACHINE << 8))
+#define SF_MAGIC ((uint32_t)(SF_MAGIC1 << 24 | SF_MAGIC2 << 16 | SF_MACHINE << 8))
 #endif
 
 
@@ -54,12 +54,12 @@
  *
  * Possible values of sf_packmode:
  */
-#define SF_CHAR  ((LONG) sizeof(char))
-#define SF_ALAW  ((LONG) sizeof(char) | 0x10000)
-#define SF_ULAW  ((LONG) sizeof(char) | 0x20000)
-#define SF_SHORT ((LONG) sizeof(short))
-#define SF_LONG  ((LONG) sizeof(LONG) | 0x40000)
-#define SF_FLOAT ((LONG) sizeof(float))
+#define SF_CHAR  ((uint32_t) sizeof(char))
+#define SF_ALAW  ((uint32_t) sizeof(char) | 0x10000)
+#define SF_ULAW  ((uint32_t) sizeof(char) | 0x20000)
+#define SF_SHORT ((uint32_t) sizeof(short))
+#define SF_LONG  ((uint32_t) sizeof(long) | 0x40000)
+#define SF_FLOAT ((uint32_t) sizeof(float))
 
 /* For marking data after fixed section of soundfile header -- see man (3carl)
  * sfcodes and defintions of SFCODE and related structures, below.
@@ -89,11 +89,11 @@
 				unsigned char sf_machine; /* 3 */
 				unsigned char sf_param;	  /* 4 */
 				} _magic_bytes;
-			LONG sf_magic;			  /* magic as a 4-byte long */
+			uint32_t sf_magic;			  /* magic as a 4-byte long */
 			} magic_union;
 		float	  sf_srate;
-		LONG	  sf_chans;
-		LONG	  sf_packmode;
+		uint32_t	  sf_chans;
+		uint32_t	  sf_packmode;
 		char	  sf_codes;
 	} sfinfo;
 	char	filler[SIZEOF_HEADER];
@@ -117,8 +117,8 @@
 
 typedef struct Sfmaxamp {
 	float	value[SF_MAXCHAN];
-	LONG	samploc[SF_MAXCHAN];
-	LONG	timetag;
+	uint32_t samploc[SF_MAXCHAN];
+	uint32_t timetag;
 } SFMAXAMP;
 
 typedef struct sfcomment {
--- a/src/silence.c
+++ b/src/silence.c
@@ -292,7 +292,7 @@
 	else
 	    silence->mode = SILENCE_COPY;
 
-	silence->start_holdoff = malloc(sizeof(LONG)*silence->start_duration);
+	silence->start_holdoff = malloc(sizeof(st_sample_t)*silence->start_duration);
 	if (!silence->start_holdoff)
 	{
 	    st_fail("Could not allocate memory");
@@ -302,7 +302,7 @@
 	silence->start_holdoff_end = 0;
 	silence->start_found_periods = 0;
 
-	silence->stop_holdoff = malloc(sizeof(LONG)*silence->stop_duration);
+	silence->stop_holdoff = malloc(sizeof(st_sample_t)*silence->stop_duration);
 	if (!silence->stop_holdoff)
 	{
 	    st_fail("Could not allocate memory");
@@ -380,7 +380,7 @@
 {
     silence_t silence = (silence_t) effp->priv;
     int	threshold, i, j;
-    ULONG nrOfTicks, nrOfInSamplesRead, nrOfOutSamplesWritten;
+    st_size_t nrOfTicks, nrOfInSamplesRead, nrOfOutSamplesWritten;
 
     nrOfInSamplesRead = 0;
     nrOfOutSamplesWritten = 0;
@@ -611,7 +611,7 @@
 {
     silence_t silence = (silence_t) effp->priv;
     int i;
-    LONG nrOfTicks, nrOfOutSamplesWritten = 0;
+    st_size_t nrOfTicks, nrOfOutSamplesWritten = 0;
 
     /* Only if in flush mode will there be possible samples to write
      * out during drain() call.
--- a/src/skel.c
+++ b/src/skel.c
@@ -59,18 +59,8 @@
 st_ssize_t st_skelread(ft_t ft, st_sample_t *buf, st_ssize_t len) 
 {
 	skel_t sk = (skel_t) ft->priv;
-	int abs;
-	float amp;
 	int done = 0;
-	
-	char c;
-	unsigned char uc;
-	short s;
-	unsigned short us;
-	LONG l;
-	ULONG ul;
-	float f;
-	double d;
+	st_sample_t l;
 
 	for(; done < len; done++) {
 		if no more samples
--- a/src/smp.c
+++ b/src/smp.c
@@ -63,7 +63,7 @@
 /* Private data for SMP file */
 typedef struct smpstuff {
   uint32_t NoOfSamps;		/* Sample data count in words */
-  LONG dataStart;
+  st_size_t dataStart;
   /* comment memory resides in private data because it's small */
   char comment[COMMENTLEN + NAMELEN + 3];
 } *smp_t;
@@ -77,7 +77,7 @@
 static int readtrailer(ft_t ft, struct smptrailer *trailer)
 {
 	int i;
-	ULONG trash;
+	int32_t trash;
 
 	st_readw(ft, (unsigned short *)&trash);	/* read reserved word */
 	for(i = 0; i < 8; i++) {	/* read the 8 loops */
@@ -109,7 +109,7 @@
 /*
  * set the trailer data - loops and markers, to reasonably benign values
  */
-static void settrailer(ft_t ft, struct smptrailer *trailer, ULONG rate)
+static void settrailer(ft_t ft, struct smptrailer *trailer, st_rate_t rate)
 {
 	int i;
 
@@ -192,7 +192,7 @@
 	smp_t smp = (smp_t) ft->priv;
 	int i;
 	int namelen, commentlen;
-	LONG samplestart;
+	long samplestart;
 	struct smpheader header;
 	struct smptrailer trailer;
 
@@ -386,7 +386,7 @@
 {
 	smp_t smp = (smp_t) ft->priv;
 	register int datum;
-	LONG done = 0;
+	st_ssize_t done = 0;
 
 	while(done < len) {
 		datum = (int) RIGHT(*buf++, 16);
--- a/src/sndrtool.c
+++ b/src/sndrtool.c
@@ -21,8 +21,8 @@
 
 /* Private data used by writer */
 typedef struct sndpriv {
-        ULONG nsamples;
-		LONG dataStart;
+        st_size_t nsamples;
+	st_size_t dataStart;
 } *snd_t;
 
 #ifndef	SEEK_CUR
@@ -29,7 +29,7 @@
 #define	SEEK_CUR	1
 #endif
 
-static void  sndtwriteheader(ft_t ft,LONG nsamples);
+static void  sndtwriteheader(ft_t ft, st_size_t nsamples);
 
 int st_sndseek(ft_t ft, st_size_t offset) 
 {
@@ -224,7 +224,7 @@
 /*======================================================================*/
 /*                         SNDTWRITEHEADER                              */
 /*======================================================================*/
-static void sndtwriteheader(ft_t ft, st_ssize_t nsamples)
+static void sndtwriteheader(ft_t ft, st_size_t nsamples)
 {
 char name_buf[97];
 
@@ -231,9 +231,9 @@
 /* sndtool header */
 st_writes(ft, "SOUND"); /* magic */
 st_writeb(ft, 0x1a);
-st_writew (ft,(LONG)0);  /* hGSound */
+st_writew (ft,0);  /* hGSound */
 st_writedw (ft,nsamples);
-st_writedw (ft,(LONG)0);
+st_writedw (ft,0);
 st_writedw (ft,nsamples);
 st_writew (ft,(int) ft->info.rate);
 st_writew (ft,0);
--- a/src/sox.c
+++ b/src/sox.c
@@ -64,10 +64,10 @@
 static int writing = 0;         /* are we writing to a file? */
 static int soxpreview = 0;      /* preview mode */
 
-static LONG ibufl[BUFSIZ/2];    /* Left/right interleave buffers */
-static LONG ibufr[BUFSIZ/2];
-static LONG obufl[BUFSIZ/2];
-static LONG obufr[BUFSIZ/2];
+static st_sample_t ibufl[BUFSIZ/2];    /* Left/right interleave buffers */
+static st_sample_t ibufr[BUFSIZ/2];
+static st_sample_t obufl[BUFSIZ/2];
+static st_sample_t obufr[BUFSIZ/2];
 
 /* local forward declarations */
 static void doopts(ft_t, int, char **);
@@ -79,7 +79,7 @@
 static int filetype(int);
 static void process(void);
 static void statistics(void);
-static LONG volumechange(LONG *buf, LONG ct, double vol);
+static st_sample_t volumechange(st_sample_t *buf, st_ssize_t ct, double vol);
 static void checkeffect(void);
 static int flow_effect_out(void);
 static int flow_effect(int);
@@ -544,8 +544,8 @@
     int e, f, flowstatus;
 #ifdef SOXMIX
     int s;
-    ULONG ilen[MAX_INPUT_FILES];
-    LONG *ibuf[MAX_INPUT_FILES];
+    st_ssize_t ilen[MAX_INPUT_FILES];
+    st_sample_t *ibuf[MAX_INPUT_FILES];
 #endif
 
     for (f = 0; f < input_count; f++)
@@ -744,7 +744,7 @@
 
             if (writing&&efftab[neffects-1].olen > 0)
                 (* outformat->h->write)(outformat, efftab[neffects-1].obuf,
-                                       (LONG) efftab[neffects-1].olen);
+                                       (st_ssize_t) efftab[neffects-1].olen);
 
             if (efftab[f].olen != BUFSIZ)
                 break;
@@ -836,7 +836,7 @@
 static int flow_effect(e)
 int e;
 {
-    st_size_t i, done, idone, odone, idonel, odonel, idoner, odoner;
+    st_ssize_t i, done, idone, odone, idonel, odonel, idoner, odoner;
     st_sample_t *ibuf, *obuf;
     int effstatus;
 
@@ -905,8 +905,8 @@
 static int drain_effect(e)
 int e;
 {
-    LONG i, olen, olenl, olenr;
-    LONG *obuf;
+    st_ssize_t i, olen, olenl, olenr;
+    st_sample_t *obuf;
 
     if (! efftabR[e].name) {
         efftab[e].olen = BUFSIZ;
@@ -1113,14 +1113,12 @@
                 st_report("Volume change clipped %d samples", clipped);
 }
 
-static LONG volumechange(buf, ct, vol)
-LONG *buf;
-LONG ct;
-double vol;
+static st_sample_t volumechange(st_sample_t *buf, st_ssize_t ct, 
+	                        double vol)
 {
         double y;
-        LONG *p,*top;
-        LONG clips=0;
+        st_sample_t *p,*top;
+        st_ssize_t clips=0;
 
         p = buf;
         top = buf+ct;
--- a/src/speed.c
+++ b/src/speed.c
@@ -13,7 +13,6 @@
 
 #include "st_i.h"
 
-#include <limits.h> /* LONG_MAX */
 #include <math.h> /* pow */
 #include <string.h>
 
@@ -54,7 +53,7 @@
 
     int compression;      /* integer compression of the signal. */
     int index;            /* how much of the input buffer is filled */
-    LONG * ibuf;          /* small internal input buffer for compression */
+    st_sample_t *ibuf;    /* small internal input buffer for compression */
 
     SPEED_FLOAT cbuf[4];  /* computation buffer for interpolation */
     SPEED_FLOAT frac;     /* current index position in cbuf */
@@ -94,20 +93,20 @@
 }
 
 /* clip if necessary, and report. */
-static LONG clip(speed_t speed, SPEED_FLOAT v)
+static st_sample_t clip(speed_t speed, SPEED_FLOAT v)
 {
-    if (v < -LONG_MAX)
+    if (v < -ST_SAMPLE_MAX)
     {
 	speed->clipped++;
-	return -LONG_MAX;
+	return -ST_SAMPLE_MAX;
     }
-    else if (v > LONG_MAX)
+    else if (v > ST_SAMPLE_MAX)
     {
 	speed->clipped++;
-	return LONG_MAX;
+	return ST_SAMPLE_MAX;
     }
     else
-	return (LONG) v;
+	return (st_sample_t) v;
 }
 
 /* get options. */
@@ -157,7 +156,8 @@
 	speed->rate = speed->factor;
     }
 
-    speed->ibuf   = (LONG*) malloc(speed->compression*sizeof(LONG));
+    speed->ibuf   = (st_sample_t *) malloc(speed->compression*
+	                                   sizeof(st_sample_t));
     speed->index  = 0;
 
     speed->state = sp_input;
--- a/src/sphere.c
+++ b/src/sphere.c
@@ -18,8 +18,8 @@
 
 /* Private data for SKEL file */
 typedef struct spherestuff {
-	char	shorten_check[4];
-	ULONG   numSamples;
+	char	  shorten_check[4];
+	st_size_t numSamples;
 } *sphere_t;
 
 /*
--- a/src/st.h
+++ b/src/st.h
@@ -73,14 +73,6 @@
 #define ST_SSIZE_MAX 0x7fffffffL
 #define ST_SSIZE_MIN (-ST_SSIZE_MAX - 1L)
 
-/* FIXME:  Remove from usage by libst */
-#define LONG    int32_t
-#define ULONG   uint32_t
-
-/* FIXME: Get rid of this and usage of LONG_MAX */
-#define MAXLONG 0x7fffffffL
-#define MAXULONG 0xffffffffL
-
 /* Signal parameters */
 
 typedef struct  st_signalinfo
--- a/src/st_i.h
+++ b/src/st_i.h
@@ -37,12 +37,12 @@
 #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);
+st_sample_t st_clip24(st_sample_t) REGPARM(1);
+void st_sine(int *buf, st_ssize_t len, int max, int depth);
+void st_triangle(int *buf, st_ssize_t len, int max, int depth);
 
-LONG st_gcd(LONG,LONG) REGPARM(2);
-LONG st_lcm(LONG,LONG) REGPARM(2);
+st_sample_t st_gcd(st_sample_t a, st_sample_t b) REGPARM(2);
+st_sample_t st_lcm(st_sample_t a, st_sample_t b) REGPARM(2);
 
 #ifndef HAVE_RAND
 int rand(void);
@@ -79,7 +79,7 @@
 #ifdef HAVE_BYTESWAP_H
 #define st_swapw(x) bswap_16(x)
 #define st_swapdw(x) bswap_32(x)
-#define st_swapf(x) (float)bswap_32((ULONG)(x))
+#define st_swapf(x) (float)bswap_32((uint32_t)(x))
 #else
 uint16_t st_swapw(uint16_t uw);
 uint32_t st_swapdw(uint32_t udw);
--- a/src/stat.c
+++ b/src/stat.c
@@ -29,16 +29,16 @@
 	double	dsum1, dsum2;	/* deltas */
 	double	scale;		/* scale-factor    */
 	double	last;		/* previous sample */
-	ULONG	read;		/* samples processed */
+	st_size_t read;		/* samples processed */
 	int	volume;
 	int	srms;
 	int	fft;
-	ULONG   bin[4];
+	ulong   bin[4];
 	double  *re;
 	double  *im;
-	ULONG   fft_bits;
-	ULONG   fft_size;
-	ULONG   fft_offset;
+	ulong   fft_bits;
+	ulong   fft_size;
+	ulong   fft_offset;
 } *stat_t;
 
 
@@ -49,7 +49,7 @@
 {
 	stat_t stat = (stat_t) effp->priv;
 
-	stat->scale = MAXLONG;
+	stat->scale = ST_SAMPLE_MAX;
 	stat->volume = 0;
 	stat->srms = 0;
 	stat->fft = 0;
@@ -107,7 +107,7 @@
 {
 	stat_t stat = (stat_t) effp->priv;
 	int i;
-	LONG  bitmask;
+	ulong  bitmask;
 
 	stat->min = stat->max = stat->mid = 0;
 	stat->asum = 0;
@@ -344,7 +344,7 @@
 
 	/* Just print the volume adjustment */
 	if (stat->volume == 1 && amp > 0) {
-		fprintf(stderr, "%.3f\n", MAXLONG/(amp*scale));
+		fprintf(stderr, "%.3f\n", ST_SAMPLE_MAX/(amp*scale));
 		return (ST_SUCCESS);
 	}
 	if (stat->volume == 2) {
@@ -371,7 +371,7 @@
 	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", MAXLONG/(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");
--- a/src/stretch.c
+++ b/src/stretch.c
@@ -22,7 +22,6 @@
 #include "st_i.h"
 
 #include <stdlib.h> /* malloc and free */
-#include <limits.h> /* LONG_MAX */
 #include <string.h> /* memcpy() */
 
 #ifndef MIN
@@ -80,7 +79,7 @@
 
     int size;               /* buffer size */
     int index;              /* next available element */
-    LONG * ibuf;            /* input buffer */
+    st_sample_t *ibuf;      /* input buffer */
     int ishift;             /* input shift */
 
     int oindex;             /* next evailable element */
@@ -106,21 +105,21 @@
 
 /* clip amplitudes and count number of clipped values.
  */
-static LONG clip(stretch_t stretch, STRETCH_FLOAT v)
+static st_sample_t clip(stretch_t stretch, STRETCH_FLOAT v)
 {
-    if (v < -LONG_MAX)
+    if (v < -ST_SAMPLE_MAX)
     {
 	stretch->clipped++;
-	return -LONG_MAX;
+	return -ST_SAMPLE_MAX;
     }
-    else if (v > LONG_MAX)
+    else if (v > ST_SAMPLE_MAX)
     {
 	stretch->clipped++;
-	return LONG_MAX;
+	return ST_SAMPLE_MAX;
     }
     else
     {
-	return (LONG) v;
+	return (st_sample_t) v;
     }
 }
 
@@ -231,7 +230,8 @@
     stretch->size = (int)(effp->outinfo.rate * ONETHOUSANDS * stretch->window);
     /* start in the middle of an input to avoid initial fading... */
     stretch->index = stretch->size/2;
-    stretch->ibuf  = (LONG *) malloc(stretch->size * sizeof(LONG));
+    stretch->ibuf  = (st_sample_t *) malloc(stretch->size * 
+	                                    sizeof(st_sample_t));
 
     /* the shift ratio deal with the longest of ishift/oshift
        hence ishift<=size and oshift<=size. should be asserted.
@@ -328,7 +328,7 @@
 				      stretch->size-stretch->index);
 
 	    memcpy(stretch->ibuf+stretch->index, 
-		   ibuf+iindex, tocopy*sizeof(LONG));
+		   ibuf+iindex, tocopy*sizeof(st_sample_t));
 
 	    iindex += tocopy;
 	    stretch->index += tocopy; 
--- a/src/synth.c
+++ b/src/synth.c
@@ -12,7 +12,6 @@
 
 #include <signal.h>
 #include <string.h>
-#include <limits.h>
 #include <math.h>
 #include <ctype.h>
 #include "st_i.h"
@@ -161,10 +160,10 @@
     double par[MAXCHAN][5];
 
     /* internal stuff */
-    LONG max;
-    ULONG samples_done;
+    st_sample_t max;
+    st_size_t samples_done;
     int rate;
-    ULONG length; /* length in number of samples */
+    st_size_t length; /* length in number of samples */
     double h[MAXCHAN]; /* store values necessary for  creation */
     PinkNoise pinkn[MAXCHAN];
 } *synth_t;
@@ -243,7 +242,7 @@
     /* set default parameters */
     synth->length = 0; /* use length of input file */
     synth->length_str = 0;
-    synth->max = LONG_MAX;
+    synth->max = ST_SAMPLE_MAX;
     for(c=0;c<MAXCHAN;c++){
 	synth->freq[c] = 440.0;
 	synth->freq2[c] = 440.0;
@@ -515,8 +514,8 @@
 
 
 
-static LONG do_synth(LONG iv, synth_t synth, int c){
-    LONG ov=iv;
+static st_sample_t do_synth(st_sample_t iv, synth_t synth, int c){
+    st_sample_t ov=iv;
     double r=0.0; /* -1 .. +1 */
     double f;
     double om;
@@ -674,7 +673,7 @@
 	    ov = iv/2 + r*synth->max/2;
 	    break;
 	case SYNTH_AMOD:
-	    ov = (LONG)(0.5*(r+1.0)*(double)iv);
+	    ov = (st_sample_t)(0.5*(r+1.0)*(double)iv);
 	    break;
 	case SYNTH_FMOD:
 	    ov = iv * r ;
--- a/src/trim.c
+++ b/src/trim.c
@@ -26,12 +26,12 @@
     char *length_str;
 
     /* options converted to values */
-    ULONG start;
-    ULONG length;
+    st_size_t start;
+    st_size_t length;
 
     /* internal stuff */
-    ULONG index;
-    ULONG trimmed;
+    st_size_t index;
+    st_size_t trimmed;
     int done;
 } * trim_t;
 
@@ -191,7 +191,7 @@
 	trim->trimmed += done;
     }
 
-    memcpy(obuf, ibuf+offset, done * sizeof(LONG));
+    memcpy(obuf, ibuf+offset, done * sizeof(st_sample_t));
     *osamp = done;
     return (ST_SUCCESS);
 }
--- a/src/tx16w.c
+++ b/src/tx16w.c
@@ -45,7 +45,7 @@
 
 /* Private data for TX16 file */
 typedef struct txwstuff {
-	LONG	rest;			/* bytes remaining in sample file */
+	st_size_t rest;			/* bytes remaining in sample file */
 } *txw_t;
 
 struct WaveHeader_ {
@@ -64,8 +64,8 @@
 static const unsigned char magic2[4] = {0, 0x52, 0x00, 0x52};
 
 /* SJB: dangerous static variables */
-static LONG tx16w_len=0;
-static LONG writedone=0;
+static st_size_t tx16w_len=0;
+static st_size_t writedone=0;
 
 /*
  * Do anything required before you start reading samples.
@@ -80,10 +80,10 @@
   char filetype[7];
   char format;
   char sample_rate;
-  LONG num_samp_bytes = 0;
+  st_size_t num_samp_bytes = 0;
   char gunk[8];
   int blewIt;
-  ULONG trash;
+  int32_t trash;
 
   txw_t sk = (txw_t) ft->priv;
   /* If you need to seek around the input file. */
@@ -181,7 +181,7 @@
 
 /*
  * Read up to len samples from file.
- * Convert to signed LONGs.
+ * Convert to st_sample_ts.
  * Place in buf[].
  * Return number of samples read.
  */
@@ -211,9 +211,9 @@
 	 * two unsigned short samples. 
 	 * TCC 3.0 appeared to do unwanted things, so we really specify
 	 *  exactly what we want to happen.
-	 * Convert unsigned short to LONG then shift up the result
+	 * Convert unsigned short to st_sample_t then shift up the result
 	 *  so that the 12-bit sample lives in the most significant
-	 *  12-bits of the LONG.
+	 *  12-bits of the st_sample_t.
 	 * This gets our two samples into the internal format which we
 	 * deposit into the given buffer and adjust our counts respectivly.
          */
@@ -225,10 +225,10 @@
 	    sk->rest -= 3; /* adjust remaining for bytes we just read */
 	    s1 = (unsigned short) (uc1 << 4) | (((uc2 >> 4) & 017));
 	    s2 = (unsigned short) (uc3 << 4) | (( uc2 & 017 ));
-	    *buf = (LONG) s1;
+	    *buf = (st_sample_t) s1;
             *buf = (*buf << 20);
 	    buf++; /* sample one is done */
-	    *buf = (LONG) s2;
+	    *buf = (st_sample_t) s2;
             *buf = (*buf << 20);
 	    buf++; /* sample two is done */
 	    done += 2; /* adjust converted & stored sample count */
--- a/src/util.c
+++ b/src/util.c
@@ -468,7 +468,7 @@
  * # of samples.
  * Returns ST_EOF on error.
  */
-int st_parsesamples(ULONG rate, char *str, ULONG *samples, char def)
+int st_parsesamples(st_rate_t rate, char *str, st_size_t *samples, char def)
 {
     int found_samples = 0, found_time = 0;
     int time;
--- a/src/vibro.c
+++ b/src/vibro.c
@@ -109,7 +109,7 @@
 	register int counter, tablen;
 	int len, done;
 	short *sinetab;
-	LONG l;
+	st_sample_t l;
 
 	len = ((*isamp > *osamp) ? *osamp : *isamp);
 
--- a/src/voc.c
+++ b/src/voc.c
@@ -143,12 +143,12 @@
 
 /* Private data for VOC file */
 typedef struct vocstuff {
-        LONG    rest;                   /* bytes remaining in current block */
-        LONG    rate;                   /* rate code (byte) of this chunk */
+        long rest;                      /* bytes remaining in current block */
+        long rate;                      /* rate code (byte) of this chunk */
         int             silent;         /* sound or silence? */
-        LONG    srate;                  /* rate code (byte) of silence */
-        LONG    blockseek;              /* start of current output block */
-        LONG    samples;                /* number of samples output */
+        long    srate;                  /* rate code (byte) of silence */
+        long    blockseek;              /* start of current output block */
+        long    samples;                /* number of samples output */
         int             size;           /* word length of data */
         unsigned char   channels;       /* number of sound channels */
         int     extended;       /* Has an extended block been read? */
@@ -337,7 +337,7 @@
         vs_t v = (vs_t) ft->priv;
         unsigned char uc;
         int sw;
-        LONG done = 0;
+        st_ssize_t done = 0;
 
         if (v->samples == 0) {
           /* No silence packing yet. */
@@ -372,11 +372,11 @@
 {
         vs_t v = (vs_t) ft->priv;
         unsigned char uc, block;
-        ULONG sblen;
+        uint32_t sblen;
         uint16_t new_rate_16;
         uint32_t new_rate_32;
         int i;
-        ULONG trash;
+        uint32_t trash;
 
         v->silent = 0;
         while (v->rest == 0) {
@@ -395,9 +395,9 @@
                 st_readb(ft, &uc);
                 sblen = uc;
                 st_readb(ft, &uc);
-                sblen |= ((LONG) uc) << 8;
+                sblen |= ((uint32_t) uc) << 8;
                 st_readb(ft, &uc);
-                sblen |= ((LONG) uc) << 16;
+                sblen |= ((uint32_t) uc) << 16;
                 switch(block) {
                 case VOC_DATA:
                         st_readb(ft, &uc);
@@ -612,7 +612,7 @@
 static void blockstop(ft_t ft) 
 {
         vs_t v = (vs_t) ft->priv;
-        LONG datum;
+        st_sample_t datum;
 
         st_writeb(ft, 0);                       /* End of file block code */
         fseek(ft->fp, v->blockseek, 0);         /* seek back to block length */
--- a/src/vol.c
+++ b/src/vol.c
@@ -11,7 +11,6 @@
 #include "st_i.h"
 
 #include <math.h>   /* exp(), sqrt() */
-#include <limits.h> /* LONG_MAX */
 
 /* type used for computations. 
  */
@@ -94,10 +93,13 @@
     	}
     	
     	vol->uselimiter = 1; /* ok, we'll use it */
-    	/* The following equation is derived so that there is no discontinuity in output amplitudes */
-    	/* and a LONG_MAX input always maps to a LONG_MAX output when the limiter is activated. */
-    	/* (NOTE: There **WILL** be a discontinuity in the slope of the output amplitudes when using the limiter.) */
-    	vol->limiterthreshhold = LONG_MAX * (ONE - vol->limitergain) / (fabs(vol->gain) - vol->limitergain);
+    	/* The following equation is derived so that there is no 
+	 * discontinuity in output amplitudes */
+    	/* and a ST_SAMPLE_MAX input always maps to a ST_SAMPLE_MAX output 
+	 * when the limiter is activated. */
+    	/* (NOTE: There **WILL** be a discontinuity in the slope 
+	 * of the output amplitudes when using the limiter.) */
+    	vol->limiterthreshhold = ST_SAMPLE_MAX * (ONE - vol->limitergain) / (fabs(vol->gain) - vol->limitergain);
     }
     
 
@@ -135,20 +137,20 @@
  * this could be a function on its own, with clip count and report
  * handled by eff_t and caller.
  */
-static LONG clip(vol_t vol, const VOL_FLOAT v)
+static st_sample_t clip(vol_t vol, const VOL_FLOAT v)
 {
-    if (v > LONG_MAX)
+    if (v > ST_SAMPLE_MAX)
     {
 	 vol->clipped++;
-	 return LONG_MAX;
+	 return ST_SAMPLE_MAX;
     }
-    else if (v < -LONG_MAX)
+    else if (v < -ST_SAMPLE_MAX)
     {
 	vol->clipped++;
-	return -LONG_MAX;
+	return -ST_SAMPLE_MAX;
     }
     /* else */
-    return (LONG) v;
+    return (st_sample_t) v;
 }
 
 #ifndef MIN
@@ -165,7 +167,7 @@
     register VOL_FLOAT gain = vol->gain;
     register VOL_FLOAT limiterthreshhold = vol->limiterthreshhold;
     register VOL_FLOAT sample;
-    register LONG len;
+    register st_size_t len;
     
     len = MIN(*osamp, *isamp);
 
@@ -182,12 +184,12 @@
 	    	
 	    	if (sample > limiterthreshhold)
 	    	{
-	    		sample =  (LONG_MAX - vol->limitergain * (LONG_MAX - sample));
+	    		sample =  (ST_SAMPLE_MAX - vol->limitergain * (ST_SAMPLE_MAX - sample));
 	    		vol->limited++;
 	    	}
 	    	else if (sample < -limiterthreshhold)
 	    	{
-	    		sample = -(LONG_MAX - vol->limitergain * (LONG_MAX + sample));
+	    		sample = -(ST_SAMPLE_MAX - vol->limitergain * (ST_SAMPLE_MAX + sample));
 	    		vol->limited++;
 	    	}
 	    	else
--- a/src/vorbis.c
+++ b/src/vorbis.c
@@ -221,7 +221,7 @@
 	vorbis_t vb = (vorbis_t) ft->priv;
 	int i;
 	int ret;
-	LONG l;
+	st_sample_t l;
 
 
 	for(i = 0; i < len; i++) {
@@ -359,9 +359,9 @@
 {
 	vorbis_t vb = (vorbis_t) ft->priv;
 	vorbis_enc_t *ve = vb->vorbis_enc_data;
-	LONG samples = len / ft->info.channels;	
+	st_ssize_t samples = len / ft->info.channels;	
 	float **buffer = vorbis_analysis_buffer(&ve->vd, samples);
-	LONG i, j;
+	st_ssize_t i, j;
 	int ret;
 	int eos = 0;
 
--- a/src/wav.c
+++ b/src/wav.c
@@ -80,13 +80,13 @@
 
 /* Private data for .wav file */
 typedef struct wavstuff {
-    LONG	   numSamples;     /* samples/channel reading: starts at total count and decremented  */
+    st_size_t	   numSamples;     /* samples/channel reading: starts at total count and decremented  */
     		                   /* writing: starts at 0 and counts samples written */
-    ULONG	   dataLength;     /* needed for ADPCM writing */
+    st_size_t	   dataLength;     /* needed for ADPCM writing */
     unsigned short formatTag;	   /* What type of encoding file is using */
     unsigned short samplesPerBlock;
     unsigned short blockAlign;
-    LONG dataStart;  /* need to for seeking */
+    st_size_t dataStart;  /* need to for seeking */
     
     /* following used by *ADPCM wav files */
     unsigned short nCoefs;	    /* ADPCM: number of coef sets */
@@ -435,13 +435,13 @@
     unsigned short wChannels;	    /* number of channels */
     uint32_t      dwSamplesPerSecond; /* samples per second per channel */
     uint32_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 */
+    uint16_t wBitsPerSample;  /* bits per sample */
+    uint32_t wFmtSize;
+    uint16_t wExtSize = 0;    /* extended field for non-PCM */
 
     uint32_t      dwDataLength;    /* length of sound data in bytes */
-    ULONG    bytesPerBlock = 0;
-    ULONG    bytespersample;	    /* bytes per sample (per channel */
+    st_size_t    bytesPerBlock = 0;
+    int    bytespersample;	    /* bytes per sample (per channel */
     char text[256];
     uint32_t      dwLoopPos;
 
@@ -629,7 +629,6 @@
 
     switch (wav->formatTag)
     {
-    /* ULONG max_spb; */
     case WAVE_FORMAT_ADPCM:
 	if (wExtSize < 4)
 	{
@@ -966,7 +965,7 @@
 st_ssize_t st_wavread(ft_t ft, st_sample_t *buf, st_ssize_t len) 
 {
 	wav_t	wav = (wav_t) ft->priv;
-	LONG	done;
+	st_ssize_t done;
 
 	ft->st_errno = ST_SUCCESS;
 	
@@ -1001,7 +1000,7 @@
 		    wav->samplePtr = wav->samples;
 		}
 
-		/* Copy interleaved data into buf, converting short to LONG */
+		/* Copy interleaved data into buf, converting to st_sample_t */
 		{
 		    short *p, *top;
 		    int ct;
@@ -1175,8 +1174,8 @@
 ULAW, ALAW formats:
 36 - 37    wExtSize = 0  the length of the format extension
 38 - 41    'fact'
-42 - 45    wFactSize = 4  length of the fact chunk minus 8 byte header
-46 - 49    wSamplesWritten   actual number of samples written out
+42 - 45    dwFactSize = 4  length of the fact chunk minus 8 byte header
+46 - 49    dwSamplesWritten   actual number of samples written out
 50 - 53    'data'
 54 - 57     dwDataLength  length of data chunk minus 8 byte header
 58 - (dwDataLength + 57)  the data
@@ -1186,8 +1185,8 @@
 36 - 37    wExtSize = 2 the length in bytes of the format-dependent extension
 38 - 39    320           number of samples per  block 
 40 - 43    'fact'
-44 - 47    wFactSize = 4  length of the fact chunk minus 8 byte header
-48 - 51    wSamplesWritten   actual number of samples written out
+44 - 47    dwFactSize = 4  length of the fact chunk minus 8 byte header
+48 - 51    dwSamplesWritten   actual number of samples written out
 52 - 55    'data'
 56 - 59     dwDataLength  length of data chunk minus 8 byte header
 60 - (dwDataLength + 59)  the data
@@ -1200,7 +1199,7 @@
 and padded compressed formats:
 
 wRiffLength -      (riff header) the length of the file, minus 8 
-wSamplesWritten  -  (fact header) the number of samples written (after padding
+dwSamplesWritten - (fact header) the number of samples written (after padding
                    to a complete block eg for GSM)
 dwDataLength     - (data chunk header) the number of (valid) data bytes written
 
@@ -1208,273 +1207,273 @@
 
 static int wavwritehdr(ft_t ft, int second_header) 
 {
-	wav_t	wav = (wav_t) ft->priv;
+    wav_t	wav = (wav_t) ft->priv;
 
-	/* variables written to wav file header */
-	/* RIFF header */    
-	ULONG wRiffLength ;                 /* length of file after 8 byte riff header */
-	/* fmt chunk */
-	ULONG wFmtSize = 16;                /* size field of the fmt chunk */
-	unsigned short wFormatTag = 0;      /* data format */
-	unsigned short wChannels;           /* number of channels */
-	ULONG  dwSamplesPerSecond;          /* samples per second per channel*/
-	uint32_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) */
-	unsigned short wExtSize=0;          /* extra bytes in the format extension */
-	unsigned short wSamplesPerBlock;    /* samples per channel per block */
-	/* wSamplesPerBlock and other things may go into format extension */
+    /* variables written to wav file header */
+    /* RIFF header */    
+    uint32_t wRiffLength ;  /* length of file after 8 byte riff header */
+    /* fmt chunk */
+    uint16_t wFmtSize = 16;       /* size field of the fmt chunk */
+    uint16_t wFormatTag = 0;      /* data format */
+    uint16_t wChannels;           /* number of channels */
+    uint32_t dwSamplesPerSecond;  /* samples per second per channel*/
+    uint32_t dwAvgBytesPerSec=0;  /* estimate of bytes per second needed */
+    uint16_t wBlockAlign=0;       /* byte alignment of a basic sample block */
+    uint16_t wBitsPerSample=0;    /* bits per sample */
+    /* fmt chunk extension (not PCM) */
+    uint16_t wExtSize=0;          /* extra bytes in the format extension */
+    uint16_t wSamplesPerBlock;    /* samples per channel per block */
+    /* wSamplesPerBlock and other things may go into format extension */
 
-	/* fact chunk (not PCM) */
-	ULONG wFactSize=4;		/* length of the fact chunk */
-	ULONG wSamplesWritten=0;	/* windows doesnt seem to use this*/
+    /* fact chunk (not PCM) */
+    uint32_t dwFactSize=4;	  /* length of the fact chunk */
+    uint32_t dwSamplesWritten=0;  /* windows doesnt seem to use this*/
 
-	/* data chunk */
-	uint32_t  dwDataLength=0x7ffff000L;	/* length of sound data in bytes */
-	/* end of variables written to header */
+    /* data chunk */
+    uint32_t  dwDataLength=0x7ffff000L;	/* length of sound data in bytes */
+    /* end of variables written to header */
 
-	/* internal variables, intermediate values etc */
-	ULONG bytespersample; 		/* (uncompressed) bytes per sample (per channel) */
-	ULONG blocksWritten = 0;
+    /* internal variables, intermediate values etc */
+    int bytespersample; /* (uncompressed) bytes per sample (per channel) */
+    long blocksWritten = 0;
 
-	dwSamplesPerSecond = ft->info.rate;
-	wChannels = ft->info.channels;
+    dwSamplesPerSecond = ft->info.rate;
+    wChannels = ft->info.channels;
 
-	/* Check to see if encoding is ADPCM or not.  If ADPCM
-	 * possibly override the size to be bytes.  It isn't needed
-	 * by this routine will look nicer (and more correct)
-	 * on verbose output.
-	 */
-	if ((ft->info.encoding == ST_ENCODING_ADPCM ||
-	     ft->info.encoding == ST_ENCODING_IMA_ADPCM ||
-	     ft->info.encoding == ST_ENCODING_GSM) &&
-	    ft->info.size != ST_SIZE_BYTE)
-	{
-	    st_warn("Overriding output size to bytes for compressed data.");
-	    ft->info.size = ST_SIZE_BYTE;
-	}
+    /* Check to see if encoding is ADPCM or not.  If ADPCM
+     * possibly override the size to be bytes.  It isn't needed
+     * by this routine will look nicer (and more correct)
+     * on verbose output.
+     */
+    if ((ft->info.encoding == ST_ENCODING_ADPCM ||
+	 ft->info.encoding == ST_ENCODING_IMA_ADPCM ||
+	 ft->info.encoding == ST_ENCODING_GSM) &&
+	 ft->info.size != ST_SIZE_BYTE)
+    {
+	st_warn("Overriding output size to bytes for compressed data.");
+	ft->info.size = ST_SIZE_BYTE;
+    }
 
-	switch (ft->info.size)
-	{
-		case ST_SIZE_BYTE:
-		        wBitsPerSample = 8;
-			if (ft->info.encoding != ST_ENCODING_UNSIGNED &&
-			    ft->info.encoding != ST_ENCODING_ULAW &&
-			    ft->info.encoding != ST_ENCODING_ALAW &&
-			    ft->info.encoding != ST_ENCODING_GSM &&
-			    ft->info.encoding != ST_ENCODING_ADPCM &&
-			    ft->info.encoding != ST_ENCODING_IMA_ADPCM)
-			{
-				st_warn("Do not support %s with 8-bit data.  Forcing to unsigned",st_encodings_str[(unsigned char)ft->info.encoding]);
-				ft->info.encoding = ST_ENCODING_UNSIGNED;
-			}
-			break;
-		case ST_SIZE_WORD:
-			wBitsPerSample = 16;
-			if (ft->info.encoding != ST_ENCODING_SIGN2)
-			{
-				st_warn("Do not support %s with 16-bit data.  Forcing to Signed.",st_encodings_str[(unsigned char)ft->info.encoding]);
-				ft->info.encoding = ST_ENCODING_SIGN2;
-			}
-			break;
-		case ST_SIZE_DWORD:
-			wBitsPerSample = 32;
-			if (ft->info.encoding != ST_ENCODING_SIGN2)
-			{
-				st_warn("Do not support %s with 16-bit data.  Forcing to Signed.",st_encodings_str[(unsigned char)ft->info.encoding]);
-				ft->info.encoding = ST_ENCODING_SIGN2;
-			}
+    switch (ft->info.size)
+    {
+	case ST_SIZE_BYTE:
+	    wBitsPerSample = 8;
+	    if (ft->info.encoding != ST_ENCODING_UNSIGNED &&
+		    ft->info.encoding != ST_ENCODING_ULAW &&
+		    ft->info.encoding != ST_ENCODING_ALAW &&
+		    ft->info.encoding != ST_ENCODING_GSM &&
+		    ft->info.encoding != ST_ENCODING_ADPCM &&
+		    ft->info.encoding != ST_ENCODING_IMA_ADPCM)
+	    {
+		st_warn("Do not support %s with 8-bit data.  Forcing to unsigned",st_encodings_str[(unsigned char)ft->info.encoding]);
+		ft->info.encoding = ST_ENCODING_UNSIGNED;
+	    }
+	    break;
+	case ST_SIZE_WORD:
+	    wBitsPerSample = 16;
+	    if (ft->info.encoding != ST_ENCODING_SIGN2)
+	    {
+		st_warn("Do not support %s with 16-bit data.  Forcing to Signed.",st_encodings_str[(unsigned char)ft->info.encoding]);
+		ft->info.encoding = ST_ENCODING_SIGN2;
+	    }
+	    break;
+	case ST_SIZE_DWORD:
+	    wBitsPerSample = 32;
+	    if (ft->info.encoding != ST_ENCODING_SIGN2)
+	    {
+		st_warn("Do not support %s with 16-bit data.  Forcing to Signed.",st_encodings_str[(unsigned char)ft->info.encoding]);
+		ft->info.encoding = ST_ENCODING_SIGN2;
+	    }
 
-			break;
-		default:
-			st_warn("Do not support %s in WAV files.  Forcing to Signed Words.",st_sizes_str[(unsigned char)ft->info.size]);
-			ft->info.encoding = ST_ENCODING_SIGN2;
-			ft->info.size = ST_SIZE_WORD;
-			wBitsPerSample = 16;
-			break;
-	}
+	    break;
+	default:
+	    st_warn("Do not support %s in WAV files.  Forcing to Signed Words.",st_sizes_str[(unsigned char)ft->info.size]);
+	    ft->info.encoding = ST_ENCODING_SIGN2;
+	    ft->info.size = ST_SIZE_WORD;
+	    wBitsPerSample = 16;
+	    break;
+    }
 
-	wSamplesPerBlock = 1;	/* common default for PCM data */
+    wSamplesPerBlock = 1;	/* common default for PCM data */
 
-	switch (ft->info.encoding)
-	{
-		case ST_ENCODING_UNSIGNED:
-		case ST_ENCODING_SIGN2:
-			wFormatTag = WAVE_FORMAT_PCM;
-	    		bytespersample = (wBitsPerSample + 7)/8;
-	    		wBlockAlign = wChannels * bytespersample;
-			break;
-		case ST_ENCODING_ALAW:
-			wFormatTag = WAVE_FORMAT_ALAW;
-	    		wBlockAlign = wChannels;
-			break;
-		case ST_ENCODING_ULAW:
-			wFormatTag = WAVE_FORMAT_MULAW;
-	    		wBlockAlign = wChannels;
-			break;
-		case ST_ENCODING_IMA_ADPCM:
-			if (wChannels>16)
-			{
-			    st_fail_errno(ft,ST_EOF,"Channels(%d) must be <= 16\n",wChannels);
-			    return ST_EOF;
-			}
-			wFormatTag = WAVE_FORMAT_IMA_ADPCM;
-			wBlockAlign = wChannels * 256; /* reasonable default */
-			wBitsPerSample = 4;
-	    		wExtSize = 2;
-			wSamplesPerBlock = ImaSamplesIn(0, wChannels, wBlockAlign, 0);
-			break;
-		case ST_ENCODING_ADPCM:
-			if (wChannels>16)
-			{
-			    st_fail_errno(ft,ST_EOF,"Channels(%d) must be <= 16\n",wChannels);
-			    return ST_EOF;
-			}
-			wFormatTag = WAVE_FORMAT_ADPCM;
-			wBlockAlign = wChannels * 128; /* reasonable default */
-			wBitsPerSample = 4;
-	    		wExtSize = 4+4*7;      /* Ext fmt data length */
-			wSamplesPerBlock = AdpcmSamplesIn(0, wChannels, wBlockAlign, 0);
-			break;
-		case ST_ENCODING_GSM:
+    switch (ft->info.encoding)
+    {
+	case ST_ENCODING_UNSIGNED:
+	case ST_ENCODING_SIGN2:
+	    wFormatTag = WAVE_FORMAT_PCM;
+	    bytespersample = (wBitsPerSample + 7)/8;
+	    wBlockAlign = wChannels * bytespersample;
+	    break;
+	case ST_ENCODING_ALAW:
+	    wFormatTag = WAVE_FORMAT_ALAW;
+	    wBlockAlign = wChannels;
+	    break;
+	case ST_ENCODING_ULAW:
+	    wFormatTag = WAVE_FORMAT_MULAW;
+	    wBlockAlign = wChannels;
+	    break;
+	case ST_ENCODING_IMA_ADPCM:
+	    if (wChannels>16)
+	    {
+		st_fail_errno(ft,ST_EOF,"Channels(%d) must be <= 16\n",wChannels);
+		return ST_EOF;
+	    }
+	    wFormatTag = WAVE_FORMAT_IMA_ADPCM;
+	    wBlockAlign = wChannels * 256; /* reasonable default */
+	    wBitsPerSample = 4;
+	    wExtSize = 2;
+	    wSamplesPerBlock = ImaSamplesIn(0, wChannels, wBlockAlign, 0);
+	    break;
+	case ST_ENCODING_ADPCM:
+	    if (wChannels>16)
+	    {
+		st_fail_errno(ft,ST_EOF,"Channels(%d) must be <= 16\n",wChannels);
+		return ST_EOF;
+	    }
+	    wFormatTag = WAVE_FORMAT_ADPCM;
+	    wBlockAlign = wChannels * 128; /* reasonable default */
+	    wBitsPerSample = 4;
+	    wExtSize = 4+4*7;      /* Ext fmt data length */
+	    wSamplesPerBlock = AdpcmSamplesIn(0, wChannels, wBlockAlign, 0);
+	    break;
+	case ST_ENCODING_GSM:
 #ifdef ENABLE_GSM
-		    if (wChannels!=1)
-		    {
-			st_warn("Overriding GSM audio from %d channel to 1\n",wChannels);
-			wChannels = ft->info.channels = 1;
-		    }
-		    wFormatTag = WAVE_FORMAT_GSM610;
-		    /* dwAvgBytesPerSec = 1625*(dwSamplesPerSecond/8000.)+0.5; */
-		    wBlockAlign=65;
-		    wBitsPerSample=0;  /* not representable as int   */
-		    wExtSize=2;        /* length of format extension */
-		    wSamplesPerBlock = 320;
+	    if (wChannels!=1)
+	    {
+		st_warn("Overriding GSM audio from %d channel to 1\n",wChannels);
+		wChannels = ft->info.channels = 1;
+	    }
+	    wFormatTag = WAVE_FORMAT_GSM610;
+	    /* dwAvgBytesPerSec = 1625*(dwSamplesPerSecond/8000.)+0.5; */
+	    wBlockAlign=65;
+	    wBitsPerSample=0;  /* not representable as int   */
+	    wExtSize=2;        /* length of format extension */
+	    wSamplesPerBlock = 320;
 #else
-		    st_fail_errno(ft,ST_EOF,"sorry, no GSM6.10 support, recompile sox with gsm library");
-		    return ST_EOF;
+	    st_fail_errno(ft,ST_EOF,"sorry, no GSM6.10 support, recompile sox with gsm library");
+	    return ST_EOF;
 #endif
-		    break;
-	}
-	wav->formatTag = wFormatTag;
-	wav->blockAlign = wBlockAlign;
-	wav->samplesPerBlock = wSamplesPerBlock;
+	    break;
+    }
+    wav->formatTag = wFormatTag;
+    wav->blockAlign = wBlockAlign;
+    wav->samplesPerBlock = wSamplesPerBlock;
 
-	if (!second_header) { 	/* adjust for blockAlign */
-	    blocksWritten = dwDataLength/wBlockAlign;
-	    dwDataLength = blocksWritten * wBlockAlign;
-	    wSamplesWritten = blocksWritten * wSamplesPerBlock;
-	} else { 	/* fixup with real length */
-	    wSamplesWritten = wav->numSamples;
-	    switch(wFormatTag)
-		{
-	    	case WAVE_FORMAT_ADPCM:
-	    	case WAVE_FORMAT_IMA_ADPCM:
-		    dwDataLength = wav->dataLength;
-		    break;
+    if (!second_header) { 	/* adjust for blockAlign */
+	blocksWritten = dwDataLength/wBlockAlign;
+	dwDataLength = blocksWritten * wBlockAlign;
+	dwSamplesWritten = blocksWritten * wSamplesPerBlock;
+    } else { 	/* fixup with real length */
+	dwSamplesWritten = wav->numSamples;
+	switch(wFormatTag)
+	{
+	    case WAVE_FORMAT_ADPCM:
+	    case WAVE_FORMAT_IMA_ADPCM:
+		dwDataLength = wav->dataLength;
+		break;
 #ifdef ENABLE_GSM
-		case WAVE_FORMAT_GSM610:
-		    /* intentional case fallthrough! */
+	    case WAVE_FORMAT_GSM610:
+		/* intentional case fallthrough! */
 #endif
-		default:
-		    wSamplesWritten /= wChannels; /* because how rawwrite()'s work */
-		    blocksWritten = (wSamplesWritten+wSamplesPerBlock-1)/wSamplesPerBlock;
-		    dwDataLength = blocksWritten * wBlockAlign;
-		}
+	    default:
+		dwSamplesWritten /= wChannels; /* because how rawwrite()'s work */
+		blocksWritten = (dwSamplesWritten+wSamplesPerBlock-1)/wSamplesPerBlock;
+		dwDataLength = blocksWritten * wBlockAlign;
 	}
+    }
 
 #ifdef ENABLE_GSM
-	if (wFormatTag == WAVE_FORMAT_GSM610)
-	    dwDataLength = (dwDataLength+1) & ~1; /*round up to even */
+    if (wFormatTag == WAVE_FORMAT_GSM610)
+	dwDataLength = (dwDataLength+1) & ~1; /*round up to even */
 #endif
 
-	if (wFormatTag != WAVE_FORMAT_PCM)
-	    wFmtSize += 2+wExtSize; /* plus ExtData */
+    if (wFormatTag != WAVE_FORMAT_PCM)
+	wFmtSize += 2+wExtSize; /* plus ExtData */
 
-	wRiffLength = 4 + (8+wFmtSize) + (8+dwDataLength); 
-	if (wFormatTag != WAVE_FORMAT_PCM) /* PCM omits the "fact" chunk */
-	    wRiffLength += (8+wFactSize);
-	
-	/* dwAvgBytesPerSec <-- this is BEFORE compression, isn't it? guess not. */
-	dwAvgBytesPerSec = (double)wBlockAlign*ft->info.rate / (double)wSamplesPerBlock + 0.5;
+    wRiffLength = 4 + (8+wFmtSize) + (8+dwDataLength); 
+    if (wFormatTag != WAVE_FORMAT_PCM) /* PCM omits the "fact" chunk */
+	wRiffLength += (8+dwFactSize);
 
-	/* figured out header info, so write it */
-	st_writes(ft, "RIFF");
-	st_writedw(ft, wRiffLength);
-	st_writes(ft, "WAVE");
-	st_writes(ft, "fmt ");
-	st_writedw(ft, wFmtSize);
-	st_writew(ft, wFormatTag);
-	st_writew(ft, wChannels);
-	st_writedw(ft, dwSamplesPerSecond);
-	st_writedw(ft, dwAvgBytesPerSec);
-	st_writew(ft, wBlockAlign);
-	st_writew(ft, wBitsPerSample); /* end info common to all fmts */
+    /* dwAvgBytesPerSec <-- this is BEFORE compression, isn't it? guess not. */
+    dwAvgBytesPerSec = (double)wBlockAlign*ft->info.rate / (double)wSamplesPerBlock + 0.5;
 
-	/* if not PCM, we need to write out wExtSize even if wExtSize=0 */
-	if (wFormatTag != WAVE_FORMAT_PCM)
-	    st_writew(ft,wExtSize);
+    /* figured out header info, so write it */
+    st_writes(ft, "RIFF");
+    st_writedw(ft, wRiffLength);
+    st_writes(ft, "WAVE");
+    st_writes(ft, "fmt ");
+    st_writedw(ft, wFmtSize);
+    st_writew(ft, wFormatTag);
+    st_writew(ft, wChannels);
+    st_writedw(ft, dwSamplesPerSecond);
+    st_writedw(ft, dwAvgBytesPerSec);
+    st_writew(ft, wBlockAlign);
+    st_writew(ft, wBitsPerSample); /* end info common to all fmts */
 
-	switch (wFormatTag)
-	{
+    /* if not PCM, we need to write out wExtSize even if wExtSize=0 */
+    if (wFormatTag != WAVE_FORMAT_PCM)
+	st_writew(ft,wExtSize);
+
+    switch (wFormatTag)
+    {
 	int i;
 	case WAVE_FORMAT_IMA_ADPCM:
-	    st_writew(ft, wSamplesPerBlock);
-	    break;
+	st_writew(ft, wSamplesPerBlock);
+	break;
 	case WAVE_FORMAT_ADPCM:
-	    st_writew(ft, wSamplesPerBlock);
-	    st_writew(ft, 7); /* nCoefs */
-	    for (i=0; i<7; i++) {
-	      st_writew(ft, iCoef[i][0]);
-	      st_writew(ft, iCoef[i][1]);
-	    }
-	    break;
+	st_writew(ft, wSamplesPerBlock);
+	st_writew(ft, 7); /* nCoefs */
+	for (i=0; i<7; i++) {
+	    st_writew(ft, iCoef[i][0]);
+	    st_writew(ft, iCoef[i][1]);
+	}
+	break;
 #ifdef ENABLE_GSM
 	case WAVE_FORMAT_GSM610:
-	    st_writew(ft, wSamplesPerBlock);
-	    break;
+	st_writew(ft, wSamplesPerBlock);
+	break;
 #endif
 	default:
-	    break;
-	}
+	break;
+    }
 
-	/* if not PCM, write the 'fact' chunk */
-	if (wFormatTag != WAVE_FORMAT_PCM){
-	    st_writes(ft, "fact");
-	    st_writedw(ft,wFactSize); 
-	    st_writedw(ft,wSamplesWritten);
-	}
+    /* if not PCM, write the 'fact' chunk */
+    if (wFormatTag != WAVE_FORMAT_PCM){
+	st_writes(ft, "fact");
+	st_writedw(ft,dwFactSize); 
+	st_writedw(ft,dwSamplesWritten);
+    }
 
-	st_writes(ft, "data");
-	st_writedw(ft, dwDataLength);		/* data chunk size */
+    st_writes(ft, "data");
+    st_writedw(ft, dwDataLength);		/* data chunk size */
 
-	if (!second_header) {
-		st_report("Writing Wave file: %s format, %d channel%s, %d samp/sec",
-	        	wav_format_str(wFormatTag), wChannels,
-	        	wChannels == 1 ? "" : "s", dwSamplesPerSecond);
-		st_report("        %d byte/sec, %d block align, %d bits/samp",
-	                dwAvgBytesPerSec, wBlockAlign, wBitsPerSample);
-	} else {
-		st_report("Finished writing Wave file, %u data bytes %u samples\n",
-			dwDataLength,wav->numSamples);
+    if (!second_header) {
+	st_report("Writing Wave file: %s format, %d channel%s, %d samp/sec",
+		wav_format_str(wFormatTag), wChannels,
+		wChannels == 1 ? "" : "s", dwSamplesPerSecond);
+	st_report("        %d byte/sec, %d block align, %d bits/samp",
+		dwAvgBytesPerSec, wBlockAlign, wBitsPerSample);
+    } else {
+	st_report("Finished writing Wave file, %u data bytes %u samples\n",
+		dwDataLength,wav->numSamples);
 #ifdef ENABLE_GSM
-		if (wFormatTag == WAVE_FORMAT_GSM610){
-		    st_report("GSM6.10 format: %u blocks %u padded samples %u padded data bytes\n",
-			blocksWritten, wSamplesWritten, dwDataLength);
-		    if (wav->gsmbytecount != dwDataLength)
-			st_warn("help ! internal inconsistency - data_written %u gsmbytecount %u",
-				dwDataLength, wav->gsmbytecount);
+	if (wFormatTag == WAVE_FORMAT_GSM610){
+	    st_report("GSM6.10 format: %u blocks %u padded samples %u padded data bytes\n",
+		    blocksWritten, dwSamplesWritten, dwDataLength);
+	    if (wav->gsmbytecount != dwDataLength)
+		st_warn("help ! internal inconsistency - data_written %u gsmbytecount %u",
+			dwDataLength, wav->gsmbytecount);
 
-		}
-#endif
 	}
-	return ST_SUCCESS;
+#endif
+    }
+    return ST_SUCCESS;
 }
 
 st_ssize_t st_wavwrite(ft_t ft, st_sample_t *buf, st_ssize_t len) 
 {
 	wav_t	wav = (wav_t) ft->priv;
-	LONG	total_len = len;
+	st_ssize_t total_len = len;
 
 	ft->st_errno = ST_SUCCESS;
 
--- a/src/wve.c
+++ b/src/wve.c
@@ -22,7 +22,7 @@
     short padding;
     short repeats;
 /* For seeking */
-	LONG dataStart;
+	st_size_t dataStart;
     } *wve_t;
 
 static void wvewriteheader(ft_t ft);
@@ -41,7 +41,7 @@
 	short version;
 	int rc;
 
-	ULONG trash;
+	uint32_t trash;
 
 	/* Needed for rawread() */
 	rc = st_rawstartread(ft);