shithub: sox

Download patch

ref: 59d54efc058e23c417e51d7b739c9d5e03a037de
parent: b763f63edd01b4a22c2a122810f60009beafd40c
author: robs <robs>
date: Wed Aug 20 10:43:17 EDT 2008

quash warnings on 64-bit arch

--- a/src/8svx.c
+++ b/src/8svx.c
@@ -13,7 +13,7 @@
   FILE * ch[4];
 } priv_t;
 
-static void svxwriteheader(sox_format_t *, sox_size_t);
+static void svxwriteheader(sox_format_t *, size_t);
 
 /*======================================================================*/
 /*                         8SVXSTARTREAD                                */
@@ -43,13 +43,13 @@
         channels = 1;
 
         /* read FORM chunk */
-        if (lsx_reads(ft, buf, 4) == SOX_EOF || strncmp(buf, "FORM", 4) != 0)
+        if (lsx_reads(ft, buf, (size_t)4) == SOX_EOF || strncmp(buf, "FORM", (size_t)4) != 0)
         {
                 lsx_fail_errno(ft, SOX_EHDR, "Header did not begin with magic word 'FORM'");
                 return(SOX_EOF);
         }
         lsx_readdw(ft, &totalsize);
-        if (lsx_reads(ft, buf, 4) == SOX_EOF || strncmp(buf, "8SVX", 4) != 0)
+        if (lsx_reads(ft, buf, (size_t)4) == SOX_EOF || strncmp(buf, "8SVX", (size_t)4) != 0)
         {
                 lsx_fail_errno(ft, SOX_EHDR, "'FORM' chunk does not specify '8SVX' as type");
                 return(SOX_EOF);
@@ -56,8 +56,8 @@
         }
 
         /* read chunks until 'BODY' (or end) */
-        while (lsx_reads(ft, buf, 4) == SOX_SUCCESS && strncmp(buf,"BODY",4) != 0) {
-                if (strncmp(buf,"VHDR",4) == 0) {
+        while (lsx_reads(ft, buf, (size_t)4) == SOX_SUCCESS && strncmp(buf,"BODY",(size_t)4) != 0) {
+                if (strncmp(buf,"VHDR",(size_t)4) == 0) {
                         lsx_readdw(ft, &chunksize);
                         if (chunksize != 20)
                         {
@@ -64,24 +64,24 @@
                                 lsx_fail_errno(ft, SOX_EHDR, "VHDR chunk has bad size");
                                 return(SOX_EOF);
                         }
-                        lsx_seeki(ft,12,SEEK_CUR);
+                        lsx_seeki(ft,(size_t)12,SEEK_CUR);
                         lsx_readw(ft, &rate);
-                        lsx_seeki(ft,1,SEEK_CUR);
-                        lsx_readbuf(ft, buf,1);
+                        lsx_seeki(ft,(size_t)1,SEEK_CUR);
+                        lsx_readbuf(ft, buf,(size_t)1);
                         if (buf[0] != 0)
                         {
                                 lsx_fail_errno(ft, SOX_EFMT, "Unsupported data compression");
                                 return(SOX_EOF);
                         }
-                        lsx_seeki(ft,4,SEEK_CUR);
+                        lsx_seeki(ft,(size_t)4,SEEK_CUR);
                         continue;
                 }
 
-                if (strncmp(buf,"ANNO",4) == 0) {
+                if (strncmp(buf,"ANNO",(size_t)4) == 0) {
                         lsx_readdw(ft, &chunksize);
                         if (chunksize & 1)
                                 chunksize++;
-                        chunk_buf = lsx_malloc(chunksize + 2);
+                        chunk_buf = lsx_malloc(chunksize + (size_t)2);
                         if (lsx_readbuf(ft, chunk_buf,(size_t)chunksize)
                                         != chunksize)
                         {
@@ -95,11 +95,11 @@
                         continue;
                 }
 
-                if (strncmp(buf,"NAME",4) == 0) {
+                if (strncmp(buf,"NAME",(size_t)4) == 0) {
                         lsx_readdw(ft, &chunksize);
                         if (chunksize & 1)
                                 chunksize++;
-                        chunk_buf = lsx_malloc(chunksize + 1);
+                        chunk_buf = lsx_malloc(chunksize + (size_t)1);
                         if (lsx_readbuf(ft, chunk_buf,(size_t)chunksize)
                                         != chunksize)
                         {
@@ -113,7 +113,7 @@
                         continue;
                 }
 
-                if (strncmp(buf,"CHAN",4) == 0) {
+                if (strncmp(buf,"CHAN",(size_t)4) == 0) {
                         lsx_readdw(ft, &chunksize);
                         if (chunksize != 4)
                         {
@@ -133,7 +133,7 @@
                 lsx_readdw(ft, &chunksize);
                 if (chunksize & 1)
                         chunksize++;
-                lsx_seeki(ft,(int32_t)chunksize,SEEK_CUR);
+                lsx_seeki(ft,(ptrdiff_t)chunksize,SEEK_CUR);
                 continue;
 
         }
@@ -143,7 +143,7 @@
                 lsx_fail_errno(ft, SOX_ERATE, "Invalid sample rate");
                 return(SOX_EOF);
         }
-        if (strncmp(buf,"BODY",4) != 0)
+        if (strncmp(buf,"BODY",(size_t)4) != 0)
         {
                 lsx_fail_errno(ft, SOX_EHDR, "BODY chunk not found");
                 return(SOX_EOF);
@@ -186,7 +186,7 @@
 /*======================================================================*/
 /*                         8SVXREAD                                     */
 /*======================================================================*/
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t nsamp)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t nsamp)
 {
         unsigned char datum;
         size_t done = 0, i;
@@ -243,7 +243,7 @@
 
         /* write header (channel 0) */
         p->nsamples = 0;
-        svxwriteheader(ft, p->nsamples);
+        svxwriteheader(ft, (size_t) p->nsamples);
         return(SOX_SUCCESS);
 }
 
@@ -251,7 +251,7 @@
 /*                         8SVXWRITE                                    */
 /*======================================================================*/
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
         priv_t * p = (priv_t * ) ft->priv;
 
@@ -287,13 +287,13 @@
         for (i = 1; i < ft->signal.channels; i++) {
                 if (fseeko(p->ch[i], (off_t)0, 0))
                 {
-                        lsx_fail_errno (ft,errno,"Can't rewind channel output file %d",i);
+                        lsx_fail_errno (ft,errno,"Can't rewind channel output file %lu",(unsigned long)i);
                         return(SOX_EOF);
                 }
                 while (!feof(p->ch[i])) {
-                        len = fread(svxbuf, 1, 512, p->ch[i]);
-                        if (fwrite (svxbuf, 1, len, p->ch[0]) != len) {
-                          lsx_fail_errno (ft,errno,"Can't write channel output file %d",i);
+                        len = fread(svxbuf, (size_t) 1, (size_t) 512, p->ch[i]);
+                        if (fwrite (svxbuf, (size_t) 1, len, p->ch[0]) != len) {
+                          lsx_fail_errno (ft,errno,"Can't write channel output file %lu",(unsigned long)i);
                           return SOX_EOF;
                         }
                 }
@@ -305,12 +305,12 @@
             lsx_writeb(ft, '\0');
 
         /* fixup file sizes in header */
-        if (lsx_seeki(ft, 0, 0) != 0)
+        if (lsx_seeki(ft, (size_t)0, 0) != 0)
         {
                 lsx_fail_errno(ft,errno,"can't rewind output file to rewrite 8SVX header");
                 return(SOX_EOF);
         }
-        svxwriteheader(ft, p->nsamples);
+        svxwriteheader(ft, (size_t) p->nsamples);
         return(SOX_SUCCESS);
 }
 
@@ -318,20 +318,20 @@
 /*                         8SVXWRITEHEADER                              */
 /*======================================================================*/
 #define SVXHEADERSIZE 100
-static void svxwriteheader(sox_format_t * ft, sox_size_t nsamples)
+static void svxwriteheader(sox_format_t * ft, size_t nsamples)
 {
-        sox_size_t formsize =  nsamples + SVXHEADERSIZE - 8;
+        size_t formsize =  nsamples + SVXHEADERSIZE - 8;
 
         /* FORM size must be even */
         if(formsize % 2 != 0) formsize++;
 
         lsx_writes(ft, "FORM");
-        lsx_writedw(ft, formsize);  /* size of file */
+        lsx_writedw(ft, (unsigned) formsize);  /* size of file */
         lsx_writes(ft, "8SVX"); /* File type */
 
         lsx_writes(ft, "VHDR");
         lsx_writedw(ft, 20); /* number of bytes to follow */
-        lsx_writedw(ft, nsamples/ft->signal.channels);  /* samples, 1-shot */
+        lsx_writedw(ft, (unsigned) nsamples/ft->signal.channels);  /* samples, 1-shot */
         lsx_writedw(ft, 0);  /* samples, repeat */
         lsx_writedw(ft, 0);  /* samples per repeat cycle */
         lsx_writew(ft, min(65535, (unsigned)(ft->signal.rate + .5)));
@@ -349,7 +349,7 @@
                    (ft->signal.channels == 4) ? 15u : 2u);
 
         lsx_writes(ft, "BODY");
-        lsx_writedw(ft, nsamples); /* samples in file */
+        lsx_writedw(ft, (unsigned) nsamples); /* samples in file */
 }
 
 SOX_FORMAT_HANDLER(svx)
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,7 +13,7 @@
   else(${ver} LESS 403)
     add_definitions(-Wtraditional-conversion)
   endif(${ver} LESS 403)
-  add_definitions(-Werror)
+  #add_definitions(-Werror)
 endif(CMAKE_COMPILER_IS_GNUCC)
 
 if (NOT EXTERNAL_GSM)
--- a/src/adpcm.c
+++ b/src/adpcm.c
@@ -326,13 +326,13 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing usage.
  */
-sox_size_t lsx_ms_adpcm_samples_in(
-        sox_size_t dataLen,
-        sox_size_t chans,
-        sox_size_t blockAlign,
-        sox_size_t samplesPerBlock
+size_t lsx_ms_adpcm_samples_in(
+        size_t dataLen,
+        size_t chans,
+        size_t blockAlign,
+        size_t samplesPerBlock
 ){
-        sox_size_t m, n;
+        size_t m, n;
 
         if (samplesPerBlock) {
                 n = (dataLen / blockAlign) * samplesPerBlock;
@@ -350,15 +350,15 @@
         return n;
 }
 
-sox_size_t lsx_ms_adpcm_bytes_per_block(
-        sox_size_t chans,
-        sox_size_t samplesPerBlock
+size_t lsx_ms_adpcm_bytes_per_block(
+        size_t chans,
+        size_t samplesPerBlock
 )
 {
-        sox_size_t n;
+        size_t n;
         n = 7*chans;  /* header */
         if (samplesPerBlock > 2)
-                n += (((sox_size_t)samplesPerBlock-2)*chans + 1)/2;
+                n += (((size_t)samplesPerBlock-2)*chans + 1)/2;
         return n;
 }
 
--- a/src/adpcm.h
+++ b/src/adpcm.h
@@ -58,19 +58,19 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing usage.
  */
-extern sox_size_t lsx_ms_adpcm_samples_in(
-	sox_size_t dataLen,
-	sox_size_t chans,
-	sox_size_t blockAlign,
-	sox_size_t samplesPerBlock
+extern size_t lsx_ms_adpcm_samples_in(
+	size_t dataLen,
+	size_t chans,
+	size_t blockAlign,
+	size_t samplesPerBlock
 );
 
 /*
- * sox_size_t lsx_ms_adpcm_bytes_per_block(chans, samplesPerBlock)
+ * size_t lsx_ms_adpcm_bytes_per_block(chans, samplesPerBlock)
  *   return minimum blocksize which would be required
  *   to encode number of chans with given samplesPerBlock
  */
-extern sox_size_t lsx_ms_adpcm_bytes_per_block(
-	sox_size_t chans,
-	sox_size_t samplesPerBlock
+extern size_t lsx_ms_adpcm_bytes_per_block(
+	size_t chans,
+	size_t samplesPerBlock
 );
--- a/src/adpcms.c
+++ b/src/adpcms.c
@@ -181,9 +181,9 @@
  * Notes      :
  ******************************************************************************/
 
-sox_size_t sox_adpcm_read(sox_format_t * ft, adpcm_io_t * state, sox_sample_t * buffer, sox_size_t len)
+size_t sox_adpcm_read(sox_format_t * ft, adpcm_io_t * state, sox_sample_t * buffer, size_t len)
 {
-  sox_size_t n = 0;
+  size_t n = 0;
   uint8_t byte;
   int16_t word;
 
@@ -193,7 +193,7 @@
     state->store.flag = 0;
     ++n;
   }
-  while (n < len && lsx_read_b_buf(ft, &byte, 1) == 1) {
+  while (n < len && lsx_read_b_buf(ft, &byte, (size_t) 1) == 1) {
     word = lsx_adpcm_decode(byte >> 4, &state->encoder);
     *buffer++ = SOX_SIGNED_16BIT_TO_SAMPLE(word, ft->clips);
 
@@ -243,9 +243,9 @@
  * Notes      :
  ******************************************************************************/
 
-sox_size_t sox_adpcm_write(sox_format_t * ft, adpcm_io_t * state, const sox_sample_t * buffer, sox_size_t length)
+size_t sox_adpcm_write(sox_format_t * ft, adpcm_io_t * state, const sox_sample_t * buffer, size_t length)
 {
-  sox_size_t count = 0;
+  size_t count = 0;
   uint8_t byte = state->store.byte;
   uint8_t flag = state->store.flag;
   short word;
--- a/src/adpcms.h
+++ b/src/adpcms.h
@@ -48,8 +48,8 @@
 void sox_adpcm_reset(adpcm_io_t * state, sox_encoding_t type);
 int sox_adpcm_oki_start(sox_format_t * ft, adpcm_io_t * state);
 int sox_adpcm_ima_start(sox_format_t * ft, adpcm_io_t * state);
-sox_size_t sox_adpcm_read(sox_format_t * ft, adpcm_io_t * state, sox_sample_t *buffer, sox_size_t len);
+size_t sox_adpcm_read(sox_format_t * ft, adpcm_io_t * state, sox_sample_t *buffer, size_t len);
 int sox_adpcm_stopread(sox_format_t * ft, adpcm_io_t * state);
-sox_size_t sox_adpcm_write(sox_format_t * ft, adpcm_io_t * state, const sox_sample_t *buffer, sox_size_t length);
+size_t sox_adpcm_write(sox_format_t * ft, adpcm_io_t * state, const sox_sample_t *buffer, size_t length);
 void sox_adpcm_flush(sox_format_t * ft, adpcm_io_t * state);
 int sox_adpcm_stopwrite(sox_format_t * ft, adpcm_io_t * state);
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -26,8 +26,8 @@
 
 /* forward declarations */
 static double read_ieee_extended(sox_format_t *);
-static int aiffwriteheader(sox_format_t *, sox_size_t);
-static int aifcwriteheader(sox_format_t *, sox_size_t);
+static int aiffwriteheader(sox_format_t *, size_t);
+static int aifcwriteheader(sox_format_t *, size_t);
 static void write_ieee_extended(sox_format_t *, double);
 static double ConvertFromIeeeExtended(unsigned char*);
 static void ConvertToIeeeExtended(double, char *);
@@ -38,11 +38,11 @@
 /* Private data used by writer */
 typedef aiff_priv_t priv_t;
 
-int sox_aiffseek(sox_format_t * ft, sox_size_t offset)
+int sox_aiffseek(sox_format_t * ft, size_t offset)
 {
     priv_t * aiff = (priv_t *) ft->priv;
-    sox_size_t new_offset, channel_block, alignment;
-    sox_size_t size = ft->encoding.bits_per_sample >> 3;
+    size_t new_offset, channel_block, alignment;
+    size_t size = ft->encoding.bits_per_sample >> 3;
 
     new_offset = offset * size;
     /* Make sure request aligns to a channel block (ie left+right) */
@@ -56,7 +56,7 @@
         new_offset += (channel_block - alignment);
     new_offset += aiff->dataStart;
 
-    ft->sox_errno = lsx_seeki(ft, (sox_ssize_t)new_offset, SEEK_SET);
+    ft->sox_errno = lsx_seeki(ft, (ptrdiff_t)new_offset, SEEK_SET);
 
     if (ft->sox_errno == SOX_SUCCESS)
         aiff->nsamples = ft->signal.length - (new_offset / size);
@@ -87,8 +87,8 @@
         unsigned short nmarks = 0;
         unsigned short sustainLoopBegin = 0, sustainLoopEnd = 0,
                        releaseLoopBegin = 0, releaseLoopEnd = 0;
-        sox_ssize_t seekto = 0;
-        sox_size_t ssndsize = 0;
+        ptrdiff_t seekto = 0;
+        size_t ssndsize = 0;
         char *annotation;
         char *author;
         char *comment = NULL;
@@ -102,14 +102,14 @@
         int rc;
 
         /* FORM chunk */
-        if (lsx_reads(ft, buf, 4) == SOX_EOF || strncmp(buf, "FORM", 4) != 0)
+        if (lsx_reads(ft, buf, (size_t)4) == SOX_EOF || strncmp(buf, "FORM", (size_t)4) != 0)
         {
                 lsx_fail_errno(ft,SOX_EHDR,"AIFF header does not begin with magic word 'FORM'");
                 return(SOX_EOF);
         }
         lsx_readdw(ft, &totalsize);
-        if (lsx_reads(ft, buf, 4) == SOX_EOF || (strncmp(buf, "AIFF", 4) != 0 &&
-            strncmp(buf, "AIFC", 4) != 0))
+        if (lsx_reads(ft, buf, (size_t)4) == SOX_EOF || (strncmp(buf, "AIFF", (size_t)4) != 0 &&
+            strncmp(buf, "AIFC", (size_t)4) != 0))
         {
                 lsx_fail_errno(ft,SOX_EHDR,"AIFF 'FORM' chunk does not specify 'AIFF' or 'AIFC' as type");
                 return(SOX_EOF);
@@ -119,7 +119,7 @@
         /* Skip everything but the COMM chunk and the SSND chunk */
         /* The SSND chunk must be the last in the file */
         while (1) {
-                if (lsx_reads(ft, buf, 4) == SOX_EOF)
+                if (lsx_reads(ft, buf, (size_t)4) == SOX_EOF)
                 {
                         if (ssndsize > 0)
                         {
@@ -131,7 +131,7 @@
                                 return(SOX_EOF);
                         }
                 }
-                if (strncmp(buf, "COMM", 4) == 0) {
+                if (strncmp(buf, "COMM", (size_t)4) == 0) {
                         /* COMM chunk */
                         lsx_readdw(ft, &chunksize);
                         lsx_readw(ft, &channels);
@@ -141,15 +141,15 @@
                         chunksize -= 18;
                         if (chunksize > 0)
                         {
-                            lsx_reads(ft, buf, 4);
+                            lsx_reads(ft, buf, (size_t)4);
                             chunksize -= 4;
-                            if (strncmp(buf, "sowt", 4) == 0)
+                            if (strncmp(buf, "sowt", (size_t)4) == 0)
                             {
                                 /* CD audio as read on Mac OS machines */
                                 /* Need to endian swap all the data */
                                 is_sowt = 1;
                             }
-                            else if (strncmp(buf, "NONE", 4) != 0)
+                            else if (strncmp(buf, "NONE", (size_t)4) != 0)
                             {
                                 buf[4] = 0;
                                 lsx_fail_errno(ft,SOX_EHDR,"AIFC files that contain compressed data are not supported: %s",buf);
@@ -160,7 +160,7 @@
                             lsx_readb(ft, &trash8);
                         foundcomm = 1;
                 }
-                else if (strncmp(buf, "SSND", 4) == 0) {
+                else if (strncmp(buf, "SSND", (size_t)4) == 0) {
                         /* SSND chunk */
                         lsx_readdw(ft, &chunksize);
                         lsx_readdw(ft, &offset);
@@ -176,9 +176,9 @@
                                 break;
                         /* else, seek to end of sound and hunt for more */
                         seekto = lsx_tell(ft);
-                        lsx_seeki(ft, (sox_ssize_t)chunksize, SEEK_CUR);
+                        lsx_seeki(ft, (ptrdiff_t)chunksize, SEEK_CUR);
                 }
-                else if (strncmp(buf, "MARK", 4) == 0) {
+                else if (strncmp(buf, "MARK", (size_t)4) == 0) {
                         /* MARK chunk */
                         lsx_readdw(ft, &chunksize);
                         if (chunksize >= sizeof(nmarks)) {
@@ -239,7 +239,7 @@
                         while(chunksize-- > 0)
                             lsx_readb(ft, &trash8);
                 }
-                else if (strncmp(buf, "INST", 4) == 0) {
+                else if (strncmp(buf, "INST", (size_t)4) == 0) {
                         /* INST chunk */
                         lsx_readdw(ft, &chunksize);
                         lsx_readsb(ft, &(ft->oob.instr.MIDInote));
@@ -262,7 +262,7 @@
 
                         foundinstr = 1;
                 }
-                else if (strncmp(buf, "APPL", 4) == 0) {
+                else if (strncmp(buf, "APPL", (size_t)4) == 0) {
                         lsx_readdw(ft, &chunksize);
                         /* word-align chunksize in case it wasn't
                          * done by writing application already.
@@ -271,7 +271,7 @@
                         while(chunksize-- > 0)
                             lsx_readb(ft, &trash8);
                 }
-                else if (strncmp(buf, "ALCH", 4) == 0) {
+                else if (strncmp(buf, "ALCH", (size_t)4) == 0) {
                         /* I think this is bogus and gets grabbed by APPL */
                         /* INST chunk */
                         lsx_readdw(ft, &trash32);                /* ENVS - jeez! */
@@ -279,7 +279,7 @@
                         while(chunksize-- > 0)
                             lsx_readb(ft, &trash8);
                 }
-                else if (strncmp(buf, "ANNO", 4) == 0) {
+                else if (strncmp(buf, "ANNO", (size_t)4) == 0) {
                   rc = textChunk(&annotation, "Annotation:", ft);
                   if (rc)
                   {
@@ -290,7 +290,7 @@
                     sox_append_comments(&ft->oob.comments, annotation);
                   free(annotation);
                 }
-                else if (strncmp(buf, "COMT", 4) == 0) {
+                else if (strncmp(buf, "COMT", (size_t)4) == 0) {
                   rc = commentChunk(&comment, "Comment:", ft);
                   if (rc) {
                     /* Fail already called in function */
@@ -300,7 +300,7 @@
                     sox_append_comments(&ft->oob.comments, comment);
                   free(comment);
                 }
-                else if (strncmp(buf, "AUTH", 4) == 0) {
+                else if (strncmp(buf, "AUTH", (size_t)4) == 0) {
                   /* Author chunk */
                   rc = textChunk(&author, "Author:", ft);
                   if (rc)
@@ -310,7 +310,7 @@
                   }
                   free(author);
                 }
-                else if (strncmp(buf, "NAME", 4) == 0) {
+                else if (strncmp(buf, "NAME", (size_t)4) == 0) {
                   /* Name chunk */
                   rc = textChunk(&nametext, "Name:", ft);
                   if (rc)
@@ -320,7 +320,7 @@
                   }
                   free(nametext);
                 }
-                else if (strncmp(buf, "(c) ", 4) == 0) {
+                else if (strncmp(buf, "(c) ", (size_t)4) == 0) {
                   /* Copyright chunk */
                   rc = textChunk(&copyright, "Copyright:", ft);
                   if (rc)
@@ -485,9 +485,9 @@
     sox_report("AIFF Loop markers:");
   for(loopNum  = 0; loopNum < ft->oob.instr.nloops; loopNum++) {
     if (ft->oob.loops[loopNum].count) {
-      sox_report("Loop %d: start: %6d", loopNum, ft->oob.loops[loopNum].start);
-      sox_report(" end:   %6d",
-              ft->oob.loops[loopNum].start + ft->oob.loops[loopNum].length);
+      sox_report("Loop %d: start: %6lu", loopNum, (unsigned long)ft->oob.loops[loopNum].start);
+      sox_report(" end:   %6lu",
+              (unsigned long)(ft->oob.loops[loopNum].start + ft->oob.loops[loopNum].length));
       sox_report(" count: %6d", ft->oob.loops[loopNum].count);
       sox_report(" type:  ");
       switch(ft->oob.loops[loopNum].type & ~SOX_LOOP_SUSTAIN_DECAY) {
@@ -509,7 +509,7 @@
   lsx_readdw(ft, &chunksize);
   /* allocate enough memory to hold the text including a terminating \0 */
   *text = lsx_malloc((size_t) chunksize + 1);
-  if (lsx_readbuf(ft, *text, chunksize) != chunksize)
+  if (lsx_readbuf(ft, *text, (size_t) chunksize) != chunksize)
   {
     lsx_fail_errno(ft,SOX_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
     return(SOX_EOF);
@@ -519,7 +519,7 @@
         {
                 /* Read past pad byte */
                 char c;
-                if (lsx_readbuf(ft, &c, 1) != 1)
+                if (lsx_readbuf(ft, &c, (size_t)1) != 1)
                 {
                 lsx_fail_errno(ft,SOX_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
                         return(SOX_EOF);
@@ -564,7 +564,7 @@
       *text = lsx_realloc(*text, (size_t) totalCommentLength + 1);
     }
 
-    if (lsx_readbuf(ft, *text + totalCommentLength - commentLength, commentLength) != commentLength) {
+    if (lsx_readbuf(ft, *text + totalCommentLength - commentLength, (size_t) commentLength) != commentLength) {
         lsx_fail_errno(ft,SOX_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
         return(SOX_EOF);
     }
@@ -573,7 +573,7 @@
     if (commentLength % 2) {
         /* Read past pad byte */
         char c;
-        if (lsx_readbuf(ft, &c, 1) != 1) {
+        if (lsx_readbuf(ft, &c, (size_t)1) != 1) {
             lsx_fail_errno(ft,SOX_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
             return(SOX_EOF);
         }
@@ -585,17 +585,17 @@
        size_t i;
        char c;
        for (i=0; i < chunksize - totalReadLength; i++ )
-           lsx_readbuf(ft, &c, 1);
+           lsx_readbuf(ft, &c, (size_t)1);
   }
   return(SOX_SUCCESS);
 }
 
-sox_size_t sox_aiffread(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+size_t sox_aiffread(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
         priv_t * aiff = (priv_t *) ft->priv;
-        sox_ssize_t done;
+        ptrdiff_t done;
 
-        if ((sox_size_t)len > aiff->nsamples)
+        if ((size_t)len > aiff->nsamples)
                 len = aiff->nsamples;
         done = lsx_rawread(ft, buf, len);
         if (done == 0 && aiff->nsamples != 0)
@@ -614,7 +614,7 @@
         {
             while (! lsx_eof(ft))
             {
-                if (lsx_readbuf(ft, buf, 4) != 4)
+                if (lsx_readbuf(ft, buf, (size_t)4) != 4)
                         break;
 
                 lsx_readdw(ft, &chunksize);
@@ -663,10 +663,10 @@
            At 48 kHz, 16 bits stereo, this gives ~3 hours of audio.
            Sorry, the AIFF format does not provide for an indefinite
            number of samples. */
-        return(aiffwriteheader(ft, 0x7f000000 / ((ft->encoding.bits_per_sample>>3)*ft->signal.channels)));
+        return(aiffwriteheader(ft, (size_t) 0x7f000000 / ((ft->encoding.bits_per_sample>>3)*ft->signal.channels)));
 }
 
-sox_size_t sox_aiffwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+size_t sox_aiffwrite(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
         priv_t * aiff = (priv_t *) ft->priv;
         aiff->nsamples += len;
@@ -683,7 +683,7 @@
         if (aiff->nsamples % 2 == 1 && ft->encoding.bits_per_sample == 8 && ft->signal.channels == 1)
         {
             sox_sample_t buf = 0;
-            lsx_rawwrite(ft, &buf, 1);
+            lsx_rawwrite(ft, &buf, (size_t) 1);
         }
 
         if (!ft->seekable)
@@ -691,7 +691,7 @@
             lsx_fail_errno(ft,SOX_EOF,"Non-seekable file.");
             return(SOX_EOF);
         }
-        if (lsx_seeki(ft, 0, SEEK_SET) != 0)
+        if (lsx_seeki(ft, (size_t)0, SEEK_SET) != 0)
         {
                 lsx_fail_errno(ft,errno,"can't rewind output file to rewrite AIFF header");
                 return(SOX_EOF);
@@ -699,7 +699,7 @@
         return(aiffwriteheader(ft, aiff->nsamples / ft->signal.channels));
 }
 
-static int aiffwriteheader(sox_format_t * ft, sox_size_t nframes)
+static int aiffwriteheader(sox_format_t * ft, size_t nframes)
 {
         int hsize =
                 8 /*COMM hdr*/ + 18 /*COMM chunk*/ +
@@ -706,8 +706,8 @@
                 8 /*SSND hdr*/ + 12 /*SSND chunk*/;
         unsigned bits = 0;
         unsigned i;
-        sox_size_t padded_comment_size = 0, comment_size = 0;
-        sox_size_t comment_chunk_size = 0;
+        size_t padded_comment_size = 0, comment_size = 0;
+        size_t comment_chunk_size = 0;
         char * comment = sox_cat_comments(ft->oob.comments);
 
         /* MARK and INST chunks */
@@ -751,7 +751,7 @@
 
         lsx_writes(ft, "FORM"); /* IFF header */
         /* file size */
-        lsx_writedw(ft, hsize + nframes * (ft->encoding.bits_per_sample >> 3) * ft->signal.channels);
+        lsx_writedw(ft, (unsigned) (hsize + nframes * (ft->encoding.bits_per_sample >> 3) * ft->signal.channels));
         lsx_writes(ft, "AIFF"); /* File type */
 
         /* Now we write the COMT comment chunk using the precomputed sizes */
@@ -758,7 +758,7 @@
         if (ft->oob.comments)
         {
           lsx_writes(ft, "COMT");
-          lsx_writedw(ft, comment_chunk_size);
+          lsx_writedw(ft, (unsigned) comment_chunk_size);
 
           /* one comment */
           lsx_writew(ft, 1);
@@ -772,7 +772,7 @@
           lsx_writew(ft, 0);
 
           /* now write the count and the bytes of text */
-          lsx_writew(ft, padded_comment_size);
+          lsx_writew(ft, (unsigned) padded_comment_size);
           lsx_writes(ft, comment);
           if (comment_size != padded_comment_size)
                 lsx_writes(ft, " ");
@@ -783,7 +783,7 @@
         lsx_writes(ft, "COMM");
         lsx_writedw(ft, 18); /* COMM chunk size */
         lsx_writew(ft, ft->signal.channels); /* nchannels */
-        lsx_writedw(ft, nframes); /* number of frames */
+        lsx_writedw(ft, (unsigned) nframes); /* number of frames */
         lsx_writew(ft, bits); /* sample width, in bits */
         write_ieee_extended(ft, (double)ft->signal.rate);
 
@@ -797,11 +797,11 @@
 
                 for(i = 0; i < ft->oob.instr.nloops; i++) {
                         lsx_writew(ft, i + 1);
-                        lsx_writedw(ft, ft->oob.loops[i].start);
+                        lsx_writedw(ft, (unsigned) ft->oob.loops[i].start);
                         lsx_writeb(ft, 0);
                         lsx_writeb(ft, 0);
                         lsx_writew(ft, i*2 + 1);
-                        lsx_writedw(ft, ft->oob.loops[i].start + ft->oob.loops[i].length);
+                        lsx_writedw(ft, (unsigned) (ft->oob.loops[i].start + ft->oob.loops[i].length));
                         lsx_writeb(ft, 0);
                         lsx_writeb(ft, 0);
                 }
@@ -836,7 +836,7 @@
         /* SSND chunk -- describes data */
         lsx_writes(ft, "SSND");
         /* chunk size */
-        lsx_writedw(ft, 8 + nframes * ft->signal.channels * (ft->encoding.bits_per_sample >> 3));
+        lsx_writedw(ft, (unsigned) (8 + nframes * ft->signal.channels * (ft->encoding.bits_per_sample >> 3)));
         lsx_writedw(ft, 0); /* offset */
         lsx_writedw(ft, 0); /* block size */
         return(SOX_SUCCESS);
@@ -860,7 +860,7 @@
            At 48 kHz, 16 bits stereo, this gives ~3 hours of music.
            Sorry, the AIFC format does not provide for an "infinite"
            number of samples. */
-        return(aifcwriteheader(ft, 0x7f000000 / ((ft->encoding.bits_per_sample >> 3)*ft->signal.channels)));
+        return(aifcwriteheader(ft, (size_t) 0x7f000000 / ((ft->encoding.bits_per_sample >> 3)*ft->signal.channels)));
 }
 
 int sox_aifcstopwrite(sox_format_t * ft)
@@ -872,7 +872,7 @@
         if (aiff->nsamples % 2 == 1 && ft->encoding.bits_per_sample == 8 && ft->signal.channels == 1)
         {
             sox_sample_t buf = 0;
-            lsx_rawwrite(ft, &buf, 1);
+            lsx_rawwrite(ft, &buf, (size_t) 1);
         }
 
         if (!ft->seekable)
@@ -880,7 +880,7 @@
             lsx_fail_errno(ft,SOX_EOF,"Non-seekable file.");
             return(SOX_EOF);
         }
-        if (lsx_seeki(ft, 0, SEEK_SET) != 0)
+        if (lsx_seeki(ft, (size_t)0, SEEK_SET) != 0)
         {
                 lsx_fail_errno(ft,errno,"can't rewind output file to rewrite AIFC header");
                 return(SOX_EOF);
@@ -888,7 +888,7 @@
         return(aifcwriteheader(ft, aiff->nsamples / ft->signal.channels));
 }
 
-static int aifcwriteheader(sox_format_t * ft, sox_size_t nframes)
+static int aifcwriteheader(sox_format_t * ft, size_t nframes)
 {
         unsigned hsize =
                 12 /*FVER*/ + 8 /*COMM hdr*/ + 18+4+1+15 /*COMM chunk*/ +
@@ -915,7 +915,7 @@
 
         lsx_writes(ft, "FORM"); /* IFF header */
         /* file size */
-        lsx_writedw(ft, hsize + nframes * (ft->encoding.bits_per_sample >> 3) * ft->signal.channels);
+        lsx_writedw(ft, (unsigned) (hsize + nframes * (ft->encoding.bits_per_sample >> 3) * ft->signal.channels));
         lsx_writes(ft, "AIFC"); /* File type */
 
         /* FVER chunk */
@@ -927,7 +927,7 @@
         lsx_writes(ft, "COMM");
         lsx_writedw(ft, 18+4+1+15); /* COMM chunk size */
         lsx_writew(ft, ft->signal.channels); /* nchannels */
-        lsx_writedw(ft, nframes); /* number of frames */
+        lsx_writedw(ft, (unsigned) nframes); /* number of frames */
         lsx_writew(ft, bits); /* sample width, in bits */
         write_ieee_extended(ft, (double)ft->signal.rate);
 
@@ -939,7 +939,7 @@
         /* SSND chunk -- describes data */
         lsx_writes(ft, "SSND");
         /* chunk size */
-        lsx_writedw(ft, 8 + nframes * ft->signal.channels * (ft->encoding.bits_per_sample >> 3));
+        lsx_writedw(ft, (unsigned) (8 + nframes * ft->signal.channels * (ft->encoding.bits_per_sample >> 3)));
         lsx_writedw(ft, 0); /* offset */
         lsx_writedw(ft, 0); /* block size */
 
@@ -950,7 +950,7 @@
 static double read_ieee_extended(sox_format_t * ft)
 {
         unsigned char buf[10];
-        if (lsx_readbuf(ft, buf, 10) != 10)
+        if (lsx_readbuf(ft, buf, (size_t)10) != 10)
         {
                 lsx_fail_errno(ft,SOX_EOF,"EOF while reading IEEE extended number");
                 return(SOX_EOF);
@@ -966,7 +966,7 @@
                 x,
                 buf[0], buf[1], buf[2], buf[3], buf[4],
                 buf[5], buf[6], buf[7], buf[8], buf[9]);
-        (void)lsx_writebuf(ft, buf, 10);
+        (void)lsx_writebuf(ft, buf, (size_t) 10);
 }
 
 
--- a/src/aiff.h
+++ b/src/aiff.h
@@ -15,17 +15,17 @@
  */
 
 typedef struct {
-    sox_size_t nsamples;  /* number of 1-channel samples read or written */
+    size_t nsamples;  /* number of 1-channel samples read or written */
                          /* Decrements for read increments for write */
-    sox_size_t dataStart; /* need to for seeking */
+    size_t dataStart; /* need to for seeking */
 } aiff_priv_t;
 
-int sox_aiffseek(sox_format_t * ft, sox_size_t offset);
+int sox_aiffseek(sox_format_t * ft, size_t offset);
 int sox_aiffstartread(sox_format_t * ft);
-sox_size_t sox_aiffread(sox_format_t * ft, sox_sample_t *buf, sox_size_t len);
+size_t sox_aiffread(sox_format_t * ft, sox_sample_t *buf, size_t len);
 int sox_aiffstopread(sox_format_t * ft);
 int sox_aiffstartwrite(sox_format_t * ft);
-sox_size_t sox_aiffwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len);
+size_t sox_aiffwrite(sox_format_t * ft, const sox_sample_t *buf, size_t len);
 int sox_aiffstopwrite(sox_format_t * ft);
 int sox_aifcstartwrite(sox_format_t * ft);
 int sox_aifcstopwrite(sox_format_t * ft);
--- a/src/alsa.c
+++ b/src/alsa.c
@@ -14,7 +14,7 @@
 typedef struct {
   snd_pcm_t *pcm_handle;
   char *buf;
-  sox_size_t buf_size;
+  size_t buf_size;
   snd_pcm_uframes_t period_size;
   snd_pcm_uframes_t frames_this_period;
 } priv_t;
@@ -428,19 +428,19 @@
     return setup(ft, SND_PCM_STREAM_CAPTURE);
 }
 
-static void ub_read_buf(sox_sample_t *buf1, char const * buf2, sox_size_t len, sox_bool swap UNUSED, sox_size_t * clips UNUSED)
+static void ub_read_buf(sox_sample_t *buf1, char const * buf2, size_t len, sox_bool swap UNUSED, size_t * clips UNUSED)
 {
     while (len--)
         *buf1++ = SOX_UNSIGNED_8BIT_TO_SAMPLE(*((unsigned char *)buf2++),);
 }
 
-static void sb_read_buf(sox_sample_t *buf1, char const * buf2, sox_size_t len, sox_bool swap UNUSED, sox_size_t * clips UNUSED)
+static void sb_read_buf(sox_sample_t *buf1, char const * buf2, size_t len, sox_bool swap UNUSED, size_t * clips UNUSED)
 {
     while (len--)
         *buf1++ = SOX_SIGNED_8BIT_TO_SAMPLE(*((int8_t *)buf2++),);
 }
 
-static void uw_read_buf(sox_sample_t *buf1, char const * buf2, sox_size_t len, sox_bool swap, sox_size_t * clips UNUSED)
+static void uw_read_buf(sox_sample_t *buf1, char const * buf2, size_t len, sox_bool swap, size_t * clips UNUSED)
 {
     while (len--)
     {
@@ -453,7 +453,7 @@
     }
 }
 
-static void sw_read_buf(sox_sample_t *buf1, char const * buf2, sox_size_t len, sox_bool swap, sox_size_t * clips UNUSED)
+static void sw_read_buf(sox_sample_t *buf1, char const * buf2, size_t len, sox_bool swap, size_t * clips UNUSED)
 {
     while (len--)
     {
@@ -466,11 +466,11 @@
     }
 }
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t nsamp)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t nsamp)
 {
     priv_t * alsa = (priv_t *)ft->priv;
-    void (*read_buf)(sox_sample_t *, char const *, sox_size_t, sox_bool, sox_size_t *) = 0;
-    sox_size_t len;
+    void (*read_buf)(sox_sample_t *, char const *, size_t, sox_bool, size_t *) = 0;
+    size_t len;
 
     switch(ft->encoding.bits_per_sample) {
       case 8:
@@ -502,7 +502,7 @@
 
     len = 0;
     while (len < nsamp) {
-      sox_size_t n = snd_pcm_readi(alsa->pcm_handle, alsa->buf,
+      size_t n = snd_pcm_readi(alsa->pcm_handle, alsa->buf,
           (nsamp - len)/ft->signal.channels); /* ALSA takes "frame" counts. */
       if ((int)n < 0) {
         if (xrun_recovery(alsa->pcm_handle, (int)n) < 0) {
@@ -534,19 +534,19 @@
     return setup(ft, SND_PCM_STREAM_PLAYBACK);
 }
 
-static void sox_ub_write_buf(char* buf1, sox_sample_t const * buf2, sox_size_t len, sox_bool swap UNUSED, sox_size_t * clips)
+static void sox_ub_write_buf(char* buf1, sox_sample_t const * buf2, size_t len, sox_bool swap UNUSED, size_t * clips)
 {
     while (len--)
         *(uint8_t *)buf1++ = SOX_SAMPLE_TO_UNSIGNED_8BIT(*buf2++, *clips);
 }
 
-static void sox_sb_write_buf(char *buf1, sox_sample_t const * buf2, sox_size_t len, sox_bool swap UNUSED, sox_size_t * clips)
+static void sox_sb_write_buf(char *buf1, sox_sample_t const * buf2, size_t len, sox_bool swap UNUSED, size_t * clips)
 {
     while (len--)
         *(int8_t *)buf1++ = SOX_SAMPLE_TO_SIGNED_8BIT(*buf2++, *clips);
 }
 
-static void sox_uw_write_buf(char *buf1, sox_sample_t const * buf2, sox_size_t len, sox_bool swap, sox_size_t * clips)
+static void sox_uw_write_buf(char *buf1, sox_sample_t const * buf2, size_t len, sox_bool swap, size_t * clips)
 {
     while (len--)
     {
@@ -558,7 +558,7 @@
     }
 }
 
-static void sox_sw_write_buf(char *buf1, sox_sample_t const * buf2, sox_size_t len, sox_bool swap, sox_size_t * clips)
+static void sox_sw_write_buf(char *buf1, sox_sample_t const * buf2, size_t len, sox_bool swap, size_t * clips)
 {
     while (len--)
     {
@@ -570,11 +570,11 @@
     }
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t nsamp)
 {
-    sox_size_t osamp, done;
+    size_t osamp, done;
     priv_t * alsa = (priv_t *)ft->priv;
-    void (*write_buf)(char *, const sox_sample_t *, sox_size_t, sox_bool, sox_size_t *) = 0;
+    void (*write_buf)(char *, const sox_sample_t *, size_t, sox_bool, size_t *) = 0;
 
     switch(ft->encoding.bits_per_sample) {
         case 8:
@@ -612,7 +612,7 @@
 
     for (done = 0; done < nsamp; done += osamp) {
       int err;
-      sox_size_t len;
+      size_t len;
 
       osamp = min(nsamp - done, alsa->buf_size / (ft->encoding.bits_per_sample >> 3));
       write_buf(alsa->buf, buf, osamp, ft->encoding.reverse_bytes, &ft->clips);
@@ -646,7 +646,7 @@
   priv_t * alsa = (priv_t *)ft->priv;
 
   /* Pad to hardware period: */
-  sox_size_t npad = (alsa->period_size - alsa->frames_this_period) * ft->signal.channels;
+  size_t npad = (alsa->period_size - alsa->frames_this_period) * ft->signal.channels;
   sox_sample_t * buf = lsx_calloc(npad, sizeof(*buf)); /* silent samples */
   write_samples(ft, buf, npad);
   free(buf);
--- a/src/amr.h
+++ b/src/amr.h
@@ -22,16 +22,16 @@
   void * state;
   unsigned mode;
   short pcm[AMR_FRAME];
-  sox_size_t pcm_index;
+  size_t pcm_index;
 } priv_t;
 
-static sox_size_t decode_1_frame(sox_format_t * ft)
+static size_t decode_1_frame(sox_format_t * ft)
 {
   priv_t * p = (priv_t *)ft->priv;
   size_t n_1;
   UWord8 coded[AMR_CODED_MAX];
 
-  if (lsx_readbuf(ft, &coded[0], 1) != 1)
+  if (lsx_readbuf(ft, &coded[0], (size_t)1) != 1)
     return AMR_FRAME;
   n_1 = block_size[(coded[0] >> 3) & 0x0F] - 1;
   if (lsx_readbuf(ft, &coded[1], n_1) != n_1)
@@ -45,7 +45,7 @@
   priv_t * p = (priv_t *)ft->priv;
   UWord8 coded[AMR_CODED_MAX];
 #include "amr1.h"
-  sox_bool result = lsx_writebuf(ft, coded, (unsigned)n) == (unsigned)n;
+  sox_bool result = lsx_writebuf(ft, coded, (size_t) (size_t) (unsigned)n) == (unsigned)n;
   if (!result)
     lsx_fail_errno(ft, errno, "write error");
   return result;
@@ -71,10 +71,10 @@
   return SOX_SUCCESS;
 }
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t * buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t * buf, size_t len)
 {
   priv_t * p = (priv_t *)ft->priv;
-  sox_size_t done;
+  size_t done;
 
   for (done = 0; done < len; done++) {
     if (p->pcm_index >= AMR_FRAME)
@@ -111,10 +111,10 @@
   return SOX_SUCCESS;
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t * buf, sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t * buf, size_t len)
 {
   priv_t * p = (priv_t *)ft->priv;
-  sox_size_t done;
+  size_t done;
 
   for (done = 0; done < len; ++done) {
     p->pcm[p->pcm_index++] = SOX_SAMPLE_TO_SIGNED_16BIT(*buf++, ft->clips);
--- a/src/ao.c
+++ b/src/ao.c
@@ -28,7 +28,7 @@
   ao_device *device;
   ao_sample_format format;
   char *buf;
-  sox_size_t buf_size;
+  size_t buf_size;
 } priv_t;
 
 static int startwrite(sox_format_t * ft)
@@ -75,7 +75,7 @@
   return SOX_SUCCESS;
 }
 
-static void sox_sw_write_buf(char *buf1, sox_sample_t const * buf2, sox_size_t len, sox_bool swap, sox_size_t * clips)
+static void sox_sw_write_buf(char *buf1, sox_sample_t const * buf2, size_t len, sox_bool swap, size_t * clips)
 {
     while (len--)
     {
@@ -87,10 +87,10 @@
     }
 }
 
-static sox_size_t write_samples(sox_format_t *ft, const sox_sample_t *buf, sox_size_t len)
+static size_t write_samples(sox_format_t *ft, const sox_sample_t *buf, size_t len)
 {
   priv_t * ao = (priv_t *)ft->priv;
-  sox_size_t aobuf_size;
+  uint_32 aobuf_size;
 
   if (len > ao->buf_size / (ft->encoding.bits_per_sample >> 3))
       len = ao->buf_size / (ft->encoding.bits_per_sample >> 3);
--- a/src/au.c
+++ b/src/au.c
@@ -97,7 +97,7 @@
   unsigned char           in_byte;
 
   if (p->in_bits < (int)ft->encoding.bits_per_sample) {
-    if (lsx_read_b_buf(ft, &in_byte, 1) != 1) {
+    if (lsx_read_b_buf(ft, &in_byte, (size_t) 1) != 1) {
       *code = 0;
       return -1;
     }
@@ -110,11 +110,11 @@
   return p->in_bits > 0;
 }
 
-static sox_size_t dec_read(sox_format_t *ft, sox_sample_t *buf, sox_size_t samp)
+static size_t dec_read(sox_format_t *ft, sox_sample_t *buf, size_t samp)
 {
   priv_t * p = (priv_t *)ft->priv;
   unsigned char code;
-  sox_size_t done;
+  size_t done;
 
   for (done = 0; samp > 0 && unpack_input(ft, &code) >= 0; ++done, --samp)
     *buf++ = SOX_SIGNED_16BIT_TO_SAMPLE(
@@ -201,8 +201,8 @@
   int i = ft->encoding.reverse_bytes == MACHINE_IS_BIGENDIAN? 2 : 0;
   sox_bool error  = sox_false
   ||lsx_writechars(ft, id[i].str, sizeof(id[i].str))
-  ||lsx_writedw(ft, FIXED_HDR + info_len)
-  ||lsx_writedw(ft, size? size*(ft->encoding.bits_per_sample >> 3) : SUN_UNSPEC)
+  ||lsx_writedw(ft, FIXED_HDR + (unsigned)info_len)
+  ||lsx_writedw(ft, (unsigned) (size? size*(ft->encoding.bits_per_sample >> 3) : SUN_UNSPEC))
   ||lsx_writedw(ft, ft_enc(ft->encoding.bits_per_sample, ft->encoding.encoding))
   ||lsx_writedw(ft, (unsigned)(ft->signal.rate + .5))
   ||lsx_writedw(ft, ft->signal.channels)
--- a/src/avr.c
+++ b/src/avr.c
@@ -65,9 +65,9 @@
   priv_t * avr = (priv_t *)ft->priv;
   int rc;
 
-  lsx_reads(ft, avr->magic, 4);
+  lsx_reads(ft, avr->magic, (size_t)4);
 
-  if (strncmp (avr->magic, AVR_MAGIC, 4)) {
+  if (strncmp (avr->magic, AVR_MAGIC, (size_t)4)) {
     lsx_fail_errno(ft,SOX_EHDR,"AVR: unknown header");
     return(SOX_EOF);
   }
@@ -243,7 +243,7 @@
   return(SOX_SUCCESS);
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t nsamp)
 {
   priv_t * avr = (priv_t *)ft->priv;
 
@@ -259,11 +259,11 @@
   unsigned size = avr->size / ft->signal.channels;
 
   /* Fix size */
-  lsx_seeki(ft, 26, SEEK_SET);
+  lsx_seeki(ft, (size_t)26, SEEK_SET);
   lsx_writedw (ft, size);
 
   /* Fix lend */
-  lsx_seeki(ft, 34, SEEK_SET);
+  lsx_seeki(ft, (size_t)34, SEEK_SET);
   lsx_writedw (ft, size);
 
   return(SOX_SUCCESS);
--- a/src/biquad.c
+++ b/src/biquad.c
@@ -112,10 +112,10 @@
 
 
 int sox_biquad_flow(sox_effect_t * effp, const sox_sample_t *ibuf,
-    sox_sample_t *obuf, sox_size_t *isamp, sox_size_t *osamp)
+    sox_sample_t *obuf, size_t *isamp, size_t *osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t len = *isamp = *osamp = min(*isamp, *osamp);
+  size_t len = *isamp = *osamp = min(*isamp, *osamp);
   while (len--) {
     double o0 = *ibuf*p->b0 + p->i1*p->b1 + p->i2*p->b2 - p->o1*p->a1 - p->o2*p->a2;
     p->i2 = p->i1, p->i1 = *ibuf++;
--- a/src/biquad.h
+++ b/src/biquad.h
@@ -71,7 +71,7 @@
     char const * allowed_width_types, filter_t filter_type);
 int sox_biquad_start(sox_effect_t * effp);
 int sox_biquad_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                        sox_size_t *isamp, sox_size_t *osamp);
+                        size_t *isamp, size_t *osamp);
 
 #undef sox_fail
 #define sox_fail sox_globals.subsystem=effp->handler.name,sox_fail
--- a/src/cdr.c
+++ b/src/cdr.c
@@ -25,8 +25,8 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-  sox_size_t const sector_num_samples = 588 * ft->signal.channels;
-  sox_size_t i = ft->olength % sector_num_samples;
+  size_t const sector_num_samples = 588 * ft->signal.channels;
+  size_t i = ft->olength % sector_num_samples;
 
   if (i) while (i++ < sector_num_samples)    /* Pad with silence to multiple */
     lsx_writew(ft, 0);                       /* of 1/75th of a second. */
--- a/src/chorus.c
+++ b/src/chorus.c
@@ -201,10 +201,10 @@
 
                 if (chorus->modulation[i] == MOD_SINE)
                   lsx_generate_wave_table(SOX_WAVE_SINE, SOX_INT, chorus->lookup_tab[i],
-                                         (unsigned)chorus->length[i], 0., (double)chorus->depth_samples[i], 0.);
+                                         (size_t)chorus->length[i], 0., (double)chorus->depth_samples[i], 0.);
                 else
                   lsx_generate_wave_table(SOX_WAVE_TRIANGLE, SOX_INT, chorus->lookup_tab[i],
-                                         (unsigned)chorus->length[i],
+                                         (size_t)chorus->length[i],
                                          (double)(chorus->samples[i] - 1 - 2 * chorus->depth_samples[i]),
                                          (double)(chorus->samples[i] - 1), 3 * M_PI_2);
                 chorus->phase[i] = 0;
@@ -235,13 +235,13 @@
  * Return number of samples processed.
  */
 static int sox_chorus_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                   sox_size_t *isamp, sox_size_t *osamp)
+                   size_t *isamp, size_t *osamp)
 {
         priv_t * chorus = (priv_t *) effp->priv;
         int i;
         float d_in, d_out;
         sox_sample_t out;
-        sox_size_t len = min(*isamp, *osamp);
+        size_t len = min(*isamp, *osamp);
         *isamp = *osamp = len;
 
         while (len--) {
@@ -272,10 +272,10 @@
 /*
  * Drain out reverb lines.
  */
-static int sox_chorus_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_chorus_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
         priv_t * chorus = (priv_t *) effp->priv;
-        sox_size_t done;
+        size_t done;
         int i;
 
         float d_in, d_out;
--- a/src/compand.c
+++ b/src/compand.c
@@ -54,9 +54,9 @@
                                individually when = 1 and input not mono */
   double delay;             /* Delay to apply before companding */
   sox_sample_t *delay_buf;   /* Old samples, used for delay processing */
-  sox_ssize_t delay_buf_size;/* Size of delay_buf in samples */
-  sox_ssize_t delay_buf_index; /* Index into delay_buf */
-  sox_ssize_t delay_buf_cnt; /* No. of active entries in delay_buf */
+  ptrdiff_t delay_buf_size;/* Size of delay_buf in samples */
+  ptrdiff_t delay_buf_index; /* Index into delay_buf */
+  ptrdiff_t delay_buf_cnt; /* No. of active entries in delay_buf */
   int delay_buf_full;       /* Shows buffer situation (important for drain) */
 } priv_t;
 
@@ -150,7 +150,7 @@
   /* Allocate the delay buffer */
   l->delay_buf_size = l->delay * effp->out_signal.rate * effp->out_signal.channels;
   if (l->delay_buf_size > 0)
-    l->delay_buf = lsx_calloc((sox_size_t)l->delay_buf_size, sizeof(*l->delay_buf));
+    l->delay_buf = lsx_calloc((size_t)l->delay_buf_size, sizeof(*l->delay_buf));
   l->delay_buf_index = 0;
   l->delay_buf_cnt = 0;
   l->delay_buf_full= 0;
@@ -174,7 +174,7 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                    sox_size_t *isamp, sox_size_t *osamp)
+                    size_t *isamp, size_t *osamp)
 {
   priv_t * l = (priv_t *) effp->priv;
   int len =  (*isamp > *osamp) ? *osamp : *isamp;
@@ -234,10 +234,10 @@
   return (SOX_SUCCESS);
 }
 
-static int drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
   priv_t * l = (priv_t *) effp->priv;
-  sox_size_t chan, done = 0;
+  size_t chan, done = 0;
 
   if (l->delay_buf_full == 0)
     l->delay_buf_index = 0;
--- a/src/contrast.c
+++ b/src/contrast.c
@@ -29,10 +29,10 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t len = *isamp = *osamp = min(*isamp, *osamp);
+  size_t len = *isamp = *osamp = min(*isamp, *osamp);
   while (len--) {
     double d = *ibuf++ * (-M_PI_2 / SOX_SAMPLE_MIN);
     *obuf++ = sin(d + p->contrast * sin(d * 4)) * SOX_SAMPLE_MAX;
--- a/src/cvsd.c
+++ b/src/cvsd.c
@@ -182,15 +182,15 @@
 
 /* ---------------------------------------------------------------------- */
 
-sox_size_t sox_cvsdread(sox_format_t * ft, sox_sample_t *buf, sox_size_t nsamp)
+size_t sox_cvsdread(sox_format_t * ft, sox_sample_t *buf, size_t nsamp)
 {
         priv_t *p = (priv_t *) ft->priv;
-        sox_size_t done = 0;
+        size_t done = 0;
         float oval;
 
         while (done < nsamp) {
                 if (!p->bit.cnt) {
-                        if (lsx_read_b_buf(ft, &(p->bit.shreg), 1) != 1)
+                        if (lsx_read_b_buf(ft, &(p->bit.shreg), (size_t) 1) != 1)
                                 return done;
                         p->bit.cnt = 8;
                         p->bit.mask = 1;
@@ -238,10 +238,10 @@
 
 /* ---------------------------------------------------------------------- */
 
-sox_size_t sox_cvsdwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp)
+size_t sox_cvsdwrite(sox_format_t * ft, const sox_sample_t *buf, size_t nsamp)
 {
         priv_t *p = (priv_t *) ft->priv;
-        sox_size_t done = 0;
+        size_t done = 0;
         float inval;
 
         for(;;) {
@@ -338,7 +338,7 @@
         time_t        Unixtime;
         unsigned      Usender;
         unsigned      Ureceiver;
-        sox_size_t     Length;
+        size_t     Length;
         unsigned      Srate;
         unsigned      Days;
         unsigned      Custom1;
@@ -412,7 +412,7 @@
         put32_le(&pch, (unsigned)hdr->Unixtime);
         put16_le(&pch, hdr->Usender);
         put16_le(&pch, hdr->Ureceiver);
-        put32_le(&pch, hdr->Length);
+        put32_le(&pch, (unsigned) hdr->Length);
         put16_le(&pch, hdr->Srate);
         put16_le(&pch, hdr->Days);
         put16_le(&pch, hdr->Custom1);
@@ -425,7 +425,7 @@
                 sum += *pchs++;
         hdr->Crc = sum;
         put16_le(&pch, hdr->Crc);
-        if (lsx_seeki(ft, 0, SEEK_SET) < 0)
+        if (lsx_seeki(ft, (size_t)0, SEEK_SET) < 0)
         {
                 sox_report("seek failed\n: %s",strerror(errno));
                 return (SOX_EOF);
@@ -486,7 +486,7 @@
         sox_debug("  time      %s", ctime(&hdr.Unixtime)); /* ctime generates lf */
         sox_debug("  usender   %u", hdr.Usender);
         sox_debug("  ureceiver %u", hdr.Ureceiver);
-        sox_debug("  length    %u", hdr.Length);
+        sox_debug("  length    %lu", (unsigned long)hdr.Length);
         sox_debug("  srate     %u", hdr.Srate);
         sox_debug("  days      %u", hdr.Days);
         sox_debug("  custom1   %u", hdr.Custom1);
@@ -540,7 +540,7 @@
             sox_warn("File not seekable");
             return (SOX_EOF);
         }
-        if (lsx_seeki(ft, 0, 0) != 0)
+        if (lsx_seeki(ft, (size_t)0, 0) != 0)
         {
                 lsx_fail_errno(ft,errno,"Can't rewind output file to rewrite DVMS header.");
                 return(SOX_EOF);
--- a/src/cvsd.h
+++ b/src/cvsd.h
@@ -54,8 +54,8 @@
 
 int sox_cvsdstartread(sox_format_t * ft);
 int sox_cvsdstartwrite(sox_format_t * ft);
-sox_size_t sox_cvsdread(sox_format_t * ft, sox_sample_t *buf, sox_size_t nsamp);
-sox_size_t sox_cvsdwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp);
+size_t sox_cvsdread(sox_format_t * ft, sox_sample_t *buf, size_t nsamp);
+size_t sox_cvsdwrite(sox_format_t * ft, const sox_sample_t *buf, size_t nsamp);
 int sox_cvsdstopread(sox_format_t * ft);
 int sox_cvsdstopwrite(sox_format_t * ft);
 
--- a/src/dat.c
+++ b/src/dat.c
@@ -12,7 +12,7 @@
 #include "sox_i.h"
 #include <string.h>
 
-#define LINEWIDTH 256
+#define LINEWIDTH (size_t)256
 
 /* Private data for dat file */
 typedef struct {
@@ -41,7 +41,7 @@
     }
     /* Hold a copy of the last line we read (first non-comment) */
     if (status != SOX_EOF) {
-      strncpy(((priv_t *)ft->priv)->prevline, inpstr, LINEWIDTH);
+      strncpy(((priv_t *)ft->priv)->prevline, inpstr, (size_t)LINEWIDTH);
       ((priv_t *)ft->priv)->buffered = 1;
     } else {
       ((priv_t *)ft->priv)->buffered = 0;
@@ -72,7 +72,7 @@
     return (SOX_SUCCESS);
 }
 
-static sox_size_t sox_datread(sox_format_t * ft, sox_sample_t *buf, sox_size_t nsamp)
+static size_t sox_datread(sox_format_t * ft, sox_sample_t *buf, size_t nsamp)
 {
     char inpstr[LINEWIDTH];
     int  inpPtr = 0;
@@ -80,8 +80,8 @@
     double sampval = 0.0;
     int retc = 0;
     char sc = 0;
-    sox_size_t done = 0;
-    sox_size_t i=0;
+    size_t done = 0;
+    size_t i=0;
 
     /* Always read a complete set of channels */
     nsamp -= (nsamp % ft->signal.channels);
@@ -90,7 +90,7 @@
 
       /* Read a line or grab the buffered first line */
       if (((priv_t *)ft->priv)->buffered) {
-        strncpy(inpstr, ((priv_t *)ft->priv)->prevline, LINEWIDTH);
+        strncpy(inpstr, ((priv_t *)ft->priv)->prevline, (size_t)LINEWIDTH);
         ((priv_t *)ft->priv)->buffered=0;
       } else {
         lsx_reads(ft, inpstr, LINEWIDTH-1);
@@ -119,13 +119,13 @@
     return (done);
 }
 
-static sox_size_t sox_datwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp)
+static size_t sox_datwrite(sox_format_t * ft, const sox_sample_t *buf, size_t nsamp)
 {
     priv_t * dat = (priv_t *) ft->priv;
-    sox_size_t done = 0;
+    size_t done = 0;
     double sampval=0.0;
     char s[LINEWIDTH];
-    sox_size_t i=0;
+    size_t i=0;
 
     /* Always write a complete set of channels */
     nsamp -= (nsamp % ft->signal.channels);
--- a/src/dcshift.c
+++ b/src/dcshift.c
@@ -76,7 +76,7 @@
  * Process data.
  */
 static int sox_dcshift_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                    sox_size_t *isamp, sox_size_t *osamp)
+                    size_t *isamp, size_t *osamp)
 {
     priv_t * dcs = (priv_t *) effp->priv;
     double dcshift = dcs->dcshift;
@@ -83,7 +83,7 @@
     double limitergain = dcs->limitergain;
     double limiterthreshhold = dcs->limiterthreshhold;
     double sample;
-    sox_size_t len;
+    size_t len;
 
     len = min(*osamp, *isamp);
 
--- a/src/delay.c
+++ b/src/delay.c
@@ -21,7 +21,7 @@
 typedef struct {
   size_t argc;
   char * * argv, * max_arg;
-  sox_size_t delay, pad, buffer_size, buffer_index;
+  size_t delay, pad, buffer_size, buffer_index;
   sox_sample_t * buffer;
 } priv_t;
 
@@ -39,7 +39,7 @@
 static int create(sox_effect_t * effp, int argc, char * * argv)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t delay, max_samples = 0;
+  size_t delay, max_samples = 0;
   unsigned i;
 
   p->argv = lsx_calloc(p->argc = argc, sizeof(*p->argv));
@@ -67,7 +67,7 @@
 static int start(sox_effect_t * effp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t max_delay;
+  size_t max_delay;
 
   if (!p->max_arg)
     return SOX_EFF_NULL;
@@ -81,10 +81,10 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t len = *isamp = *osamp = min(*isamp, *osamp);
+  size_t len = *isamp = *osamp = min(*isamp, *osamp);
 
   if (!p->buffer_size)
     memcpy(obuf, ibuf, len * sizeof(*obuf));
@@ -101,10 +101,10 @@
   return SOX_SUCCESS;
 }
 
-static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
+static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t len = *osamp = min(p->delay + p->pad, *osamp);
+  size_t len = *osamp = min(p->delay + p->pad, *osamp);
 
   for (; p->delay && len; --p->delay, --len) {
     *obuf++ = p->buffer[p->buffer_index++];
--- a/src/dither.c
+++ b/src/dither.c
@@ -33,10 +33,10 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t len = *isamp = *osamp = min(*isamp, *osamp);
+  size_t len = *isamp = *osamp = min(*isamp, *osamp);
 
   while (len--) {   /* 16 signed bits of triangular noise: */
     int tri16 = ((rand() % 32768) + (rand() % 32768)) - 32767;
--- a/src/earwax.c
+++ b/src/earwax.c
@@ -66,10 +66,10 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-                sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+                sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t i, len = *isamp = *osamp = min(*isamp, *osamp);
+  size_t i, len = *isamp = *osamp = min(*isamp, *osamp);
 
   while (len--) {       /* update taps and calculate output */
     sox_sample_t output = 0;
--- a/src/echo.c
+++ b/src/echo.c
@@ -57,8 +57,8 @@
         double  *delay_buf;
         float   in_gain, out_gain;
         float   delay[MAX_ECHOS], decay[MAX_ECHOS];
-        sox_ssize_t samples[MAX_ECHOS], maxsamples;
-        sox_size_t fade_out;
+        ptrdiff_t samples[MAX_ECHOS], maxsamples;
+        size_t fade_out;
 } priv_t;
 
 /* Private data for SKEL file */
@@ -125,7 +125,7 @@
                     sox_fail("echo: delay must be positive!");
                     return (SOX_EOF);
                 }
-                if ( echo->samples[i] > (sox_ssize_t)DELAY_BUFSIZ )
+                if ( echo->samples[i] > (ptrdiff_t)DELAY_BUFSIZ )
                 {
                         sox_fail("echo: delay must be less than %g seconds!",
                                 DELAY_BUFSIZ / effp->in_signal.rate );
@@ -163,13 +163,13 @@
  * Return number of samples processed.
  */
 static int sox_echo_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                 sox_size_t *isamp, sox_size_t *osamp)
+                 size_t *isamp, size_t *osamp)
 {
         priv_t * echo = (priv_t *) effp->priv;
         int j;
         double d_in, d_out;
         sox_sample_t out;
-        sox_size_t len = min(*isamp, *osamp);
+        size_t len = min(*isamp, *osamp);
         *isamp = *osamp = len;
 
         while (len--) {
@@ -198,13 +198,13 @@
 /*
  * Drain out reverb lines.
  */
-static int sox_echo_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_echo_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
         priv_t * echo = (priv_t *) effp->priv;
         double d_in, d_out;
         sox_sample_t out;
         int j;
-        sox_size_t done;
+        size_t done;
 
         done = 0;
         /* drain out delay samples */
--- a/src/echos.c
+++ b/src/echos.c
@@ -53,8 +53,8 @@
         double  *delay_buf;
         float   in_gain, out_gain;
         float   delay[MAX_ECHOS], decay[MAX_ECHOS];
-        sox_ssize_t samples[MAX_ECHOS], pointer[MAX_ECHOS];
-        sox_size_t sumsamples;
+        ptrdiff_t samples[MAX_ECHOS], pointer[MAX_ECHOS];
+        size_t sumsamples;
 } priv_t;
 
 /* Private data for SKEL file */
@@ -123,7 +123,7 @@
                     sox_fail("echos: delay must be positive!");
                     return (SOX_EOF);
                 }
-                if ( echos->samples[i] > (sox_ssize_t)DELAY_BUFSIZ )
+                if ( echos->samples[i] > (ptrdiff_t)DELAY_BUFSIZ )
                 {
                         sox_fail("echos: delay must be less than %g seconds!",
                                 DELAY_BUFSIZ / effp->in_signal.rate );
@@ -160,13 +160,13 @@
  * Return number of samples processed.
  */
 static int sox_echos_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                sox_size_t *isamp, sox_size_t *osamp)
+                size_t *isamp, size_t *osamp)
 {
         priv_t * echos = (priv_t *) effp->priv;
         int j;
         double d_in, d_out;
         sox_sample_t out;
-        sox_size_t len = min(*isamp, *osamp);
+        size_t len = min(*isamp, *osamp);
         *isamp = *osamp = len;
 
         while (len--) {
@@ -201,13 +201,13 @@
 /*
  * Drain out reverb lines.
  */
-static int sox_echos_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_echos_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
         priv_t * echos = (priv_t *) effp->priv;
         double d_in, d_out;
         sox_sample_t out;
         int j;
-        sox_size_t done;
+        size_t done;
 
         done = 0;
         /* drain out delay samples */
--- a/src/effects.c
+++ b/src/effects.c
@@ -42,7 +42,7 @@
 }
 
 /* Pass through samples verbatim */
-static int default_flow(sox_effect_t * effp UNUSED, const sox_sample_t *ibuf UNUSED, sox_sample_t *obuf UNUSED, sox_size_t *isamp, sox_size_t *osamp)
+static int default_flow(sox_effect_t * effp UNUSED, const sox_sample_t *ibuf UNUSED, sox_sample_t *obuf UNUSED, size_t *isamp, size_t *osamp)
 {
   *isamp = *osamp = min(*isamp, *osamp);
   memcpy(obuf, ibuf, *isamp * sizeof(*obuf));
@@ -50,7 +50,7 @@
 }
 
 /* Inform no more samples to drain */
-static int default_drain(sox_effect_t * effp UNUSED, sox_sample_t *obuf UNUSED, sox_size_t *osamp)
+static int default_drain(sox_effect_t * effp UNUSED, sox_sample_t *obuf UNUSED, size_t *osamp)
 {
   *osamp = 0;
   return SOX_EOF;
@@ -95,7 +95,7 @@
 }
 
 /* Effect can call in start() or flow() to set minimum input size to flow() */
-int sox_effect_set_imin(sox_effect_t * effp, sox_size_t imin)
+int sox_effect_set_imin(sox_effect_t * effp, size_t imin)
 {
   if (imin > sox_globals.bufsiz / effp->flows) {
     sox_fail("sox_bufsiz not big enough");
@@ -177,18 +177,18 @@
   return SOX_SUCCESS;
 }
 
-static int flow_effect(sox_effects_chain_t * chain, unsigned n)
+static int flow_effect(sox_effects_chain_t * chain, size_t n)
 {
   sox_effect_t * effp1 = &chain->effects[n - 1][0];
   sox_effect_t * effp = &chain->effects[n][0];
   int effstatus = SOX_SUCCESS;
-  sox_size_t i, f;
+  size_t i, f;
   const sox_sample_t *ibuf;
-  sox_size_t idone = effp1->oend - effp1->obeg;
-  sox_size_t obeg = sox_globals.bufsiz - effp->oend;
+  size_t idone = effp1->oend - effp1->obeg;
+  size_t obeg = sox_globals.bufsiz - effp->oend;
 #if DEBUG_EFFECTS_CHAIN
-  sox_size_t pre_idone = idone;
-  sox_size_t pre_odone = obeg;
+  size_t pre_idone = idone;
+  size_t pre_odone = obeg;
 #endif
 
   if (effp->flows == 1)       /* Run effect on all channels at once */
@@ -196,7 +196,7 @@
                                    &effp->obuf[effp->oend], &idone, &obeg);
   else {                 /* Run effect on each channel individually */
     sox_sample_t *obuf = &effp->obuf[effp->oend];
-    sox_size_t idone_last = 0, odone_last = 0; /* Initialised to prevent warning */
+    size_t idone_last = 0, odone_last = 0; /* Initialised to prevent warning */
 
     ibuf = &effp1->obuf[effp1->obeg];
     for (i = 0; i < idone; i += effp->flows)
@@ -204,8 +204,8 @@
         chain->ibufc[f][i / effp->flows] = *ibuf++;
 
     for (f = 0; f < effp->flows; ++f) {
-      sox_size_t idonec = idone / effp->flows;
-      sox_size_t odonec = obeg / effp->flows;
+      size_t idonec = idone / effp->flows;
+      size_t odonec = obeg / effp->flows;
       int eff_status_c = effp->handler.flow(&chain->effects[n][f],
           chain->ibufc[f], chain->obufc[f], &idonec, &odonec);
       if (f && (idonec != idone_last || odonec != odone_last)) {
@@ -244,14 +244,14 @@
 }
 
 /* The same as flow_effect but with no input */
-static int drain_effect(sox_effects_chain_t * chain, unsigned n)
+static int drain_effect(sox_effects_chain_t * chain, size_t n)
 {
   sox_effect_t * effp = &chain->effects[n][0];
   int effstatus = SOX_SUCCESS;
-  sox_size_t i, f;
-  sox_size_t obeg = sox_globals.bufsiz - effp->oend;
+  size_t i, f;
+  size_t obeg = sox_globals.bufsiz - effp->oend;
 #if DEBUG_EFFECTS_CHAIN
-  sox_size_t pre_odone = obeg;
+  size_t pre_odone = obeg;
 #endif
 
   if (effp->flows == 1)   /* Run effect on all channels at once */
@@ -258,10 +258,10 @@
     effstatus = effp->handler.drain(effp, &effp->obuf[effp->oend], &obeg);
   else {                         /* Run effect on each channel individually */
     sox_sample_t *obuf = &effp->obuf[effp->oend];
-    sox_size_t odone_last = 0; /* Initialised to prevent warning */
+    size_t odone_last = 0; /* Initialised to prevent warning */
 
     for (f = 0; f < effp->flows; ++f) {
-      sox_size_t odonec = obeg / effp->flows;
+      size_t odonec = obeg / effp->flows;
       int eff_status_c = effp->handler.drain(&chain->effects[n][f], chain->obufc[f], &odonec);
       if (f && (odonec != odone_last)) {
         sox_fail("drained asymmetrically!");
@@ -293,8 +293,8 @@
 int sox_flow_effects(sox_effects_chain_t * chain, int (* callback)(sox_bool all_done))
 {
   int flow_status = SOX_SUCCESS;
-  sox_size_t e, source_e = 0;               /* effect indices */
-  sox_size_t f, max_flows = 0;
+  size_t e, source_e = 0;               /* effect indices */
+  size_t f, max_flows = 0;
   sox_bool draining = sox_true;
 
   for (e = 0; e < chain->length; ++e) {
@@ -352,10 +352,10 @@
   return flow_status;
 }
 
-sox_size_t sox_effects_clips(sox_effects_chain_t * chain)
+size_t sox_effects_clips(sox_effects_chain_t * chain)
 {
   unsigned i, f;
-  sox_size_t clips = 0;
+  size_t clips = 0;
   for (i = 1; i < chain->length - 1; ++i)
     for (f = 0; f < chain->effects[i][0].flows; ++f)
       clips += chain->effects[i][f].clips;
@@ -362,10 +362,10 @@
   return clips;
 }
 
-sox_size_t sox_stop_effect(sox_effect_t *effp)
+size_t sox_stop_effect(sox_effect_t *effp)
 {
   unsigned f;
-  sox_size_t clips = 0;
+  size_t clips = 0;
 
   for (f = 0; f < effp->flows; ++f) {
     effp[f].handler.stop(&effp[f]);
@@ -380,7 +380,7 @@
  */
 static void sox_delete_effect(sox_effect_t *effp)
 {
-    sox_size_t clips;
+    size_t clips;
     unsigned f;
 
     if ((clips = sox_stop_effect(effp)) != 0)
@@ -400,7 +400,7 @@
  */
 void sox_delete_effects(sox_effects_chain_t * chain)
 {
-  sox_size_t e;
+  size_t e;
 
   for (e = 0; e < chain->length; ++e) {
     sox_delete_effect(chain->effects[e]);
--- a/src/effects_i.c
+++ b/src/effects_i.c
@@ -34,7 +34,7 @@
 }
 
 /* here for linear interp.  might be useful for other things */
-sox_sample_t lsx_gcd(sox_sample_t a, sox_sample_t b)
+unsigned lsx_gcd(unsigned a, unsigned b)
 {
   if (b == 0)
     return a;
@@ -42,9 +42,9 @@
     return lsx_gcd(b, a % b);
 }
 
-sox_sample_t lsx_lcm(sox_sample_t a, sox_sample_t b)
+unsigned lsx_lcm(unsigned a, unsigned b)
 {
-  /* parenthesize this way to avoid sox_sample_t overflow in product term */
+  /* parenthesize this way to avoid unsigned overflow in product term */
   return a * (b / lsx_gcd(a, b));
 }
 
@@ -57,7 +57,7 @@
     lsx_wave_t wave_type,
     sox_data_t data_type,
     void *table,
-    uint32_t table_size,
+    size_t table_size,
     double min,
     double max,
     double phase)
@@ -141,7 +141,7 @@
  * # of samples.
  * Returns NULL on error, pointer to next char to parse otherwise.
  */
-char const * lsx_parsesamples(sox_rate_t rate, const char *str, sox_size_t *samples, int def)
+char const * lsx_parsesamples(sox_rate_t rate, const char *str, size_t *samples, int def)
 {
     int found_samples = 0, found_time = 0;
     int time = 0;
--- a/src/example1.c
+++ b/src/example1.c
@@ -31,7 +31,7 @@
  * In a different application, they might be generated or come from a different
  * part of the application. */
 static int input_drain(
-    sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
+    sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
 {
   (void)effp;   /* This parameter is not needed in this example */
 
@@ -55,7 +55,7 @@
  * In a different application, they might perhaps be analysed in some way,
  * or displayed as a wave-form */
 static int output_flow(sox_effect_t *effp UNUSED, sox_sample_t const * ibuf,
-    sox_sample_t * obuf UNUSED, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf UNUSED, size_t * isamp, size_t * osamp)
 {
   /* Write out *isamp samples */
   size_t len = sox_write(out, ibuf, *isamp);
--- a/src/example2.c
+++ b/src/example2.c
@@ -40,7 +40,7 @@
   static const double block_period = 0.025; /* seconds */
   double start_secs = 0, period = 2;
   char dummy;
-  sox_size_t seek;
+  size_t seek;
 
   /* All libSoX applications must start by initialising the SoX library */
   assert(sox_format_init() == SOX_SUCCESS);
--- a/src/fade.c
+++ b/src/fade.c
@@ -24,7 +24,7 @@
 
 /* Private data for fade file */
 typedef struct { /* These are measured as samples */
-    sox_size_t in_start, in_stop, out_start, out_stop, samplesdone;
+    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;
     char do_out;
@@ -32,7 +32,7 @@
 } priv_t;
 
 /* prototypes */
-static double fade_gain(sox_size_t index, sox_size_t range, int fadetype);
+static double fade_gain(size_t index, size_t range, int fadetype);
 
 /*
  * Process options
@@ -170,7 +170,7 @@
     fade->samplesdone = fade->in_start;
     fade->endpadwarned = 0;
 
-    sox_debug("fade: in_start = %d in_stop = %d out_start = %d out_stop = %d", fade->in_start, fade->in_stop, fade->out_start, fade->out_stop);
+    sox_debug("fade: in_start = %lu in_stop = %lu out_start = %lu out_stop = %lu", (unsigned long)fade->in_start, (unsigned long)fade->in_stop, (unsigned long)fade->out_start, (unsigned long)fade->out_stop);
 
     if (fade->in_start == fade->in_stop && fade->out_start == fade->out_stop)
       return SOX_EFF_NULL;
@@ -183,13 +183,13 @@
  * Return number of samples processed.
  */
 static int sox_fade_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                 sox_size_t *isamp, sox_size_t *osamp)
+                 size_t *isamp, size_t *osamp)
 {
     priv_t * fade = (priv_t *) effp->priv;
     /* len is total samples, chcnt counts channels */
     int len = 0, t_output = 1, more_output = 1;
     sox_sample_t t_ibuf;
-    sox_size_t chcnt = 0;
+    size_t chcnt = 0;
 
     len = ((*isamp > *osamp) ? *osamp : *isamp);
 
@@ -263,11 +263,11 @@
 /*
  * Drain out remaining samples if the effect generates any.
  */
-static int sox_fade_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_fade_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
     priv_t * fade = (priv_t *) effp->priv;
     int len;
-    sox_size_t t_chan = 0;
+    size_t t_chan = 0;
 
     len = *osamp;
     *osamp = 0;
@@ -317,7 +317,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(sox_size_t index, sox_size_t range, int type)
+static double fade_gain(size_t index, size_t range, int type)
 {
     double retval = 0.0, findex = 0.0;
 
--- a/src/ffmpeg.c
+++ b/src/ffmpeg.c
@@ -46,11 +46,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
-#if HAVE_LIBAVFORMAT_AVFORMAT_H
-#include <libavformat/avformat.h>
-#else
-#include <ffmpeg/avformat.h>
-#endif
+#include "ffmpeg.h"
 
 /* Private data for ffmpeg files */
 typedef struct {
@@ -154,7 +150,7 @@
   int ret;
   int i;
 
-  ffmpeg->audio_buf = lsx_calloc(1, AVCODEC_MAX_AUDIO_FRAME_SIZE);
+  ffmpeg->audio_buf = lsx_calloc(1, (size_t)AVCODEC_MAX_AUDIO_FRAME_SIZE);
 
   /* Signal audio stream not found */
   ffmpeg->audio_index = -1;
@@ -211,12 +207,12 @@
  * Read up to len samples of type sox_sample_t from file into buf[].
  * Return number of samples read.
  */
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
   priv_t * ffmpeg = (priv_t *)ft->priv;
   AVPacket *pkt = &ffmpeg->audio_pkt;
   int ret;
-  sox_size_t nsamp = 0, nextra;
+  size_t nsamp = 0, nextra;
 
   /* Read data repeatedly until buf is full or no more can be read */
   do {
@@ -301,7 +297,7 @@
     return SOX_EOF;
   }
 
-  ffmpeg->audio_buf = lsx_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
+  ffmpeg->audio_buf = lsx_malloc((size_t)AVCODEC_MAX_AUDIO_FRAME_SIZE);
 
   /* ugly hack for PCM codecs (will be removed ASAP with new PCM
      support to compute the input frame size in samples */
@@ -396,10 +392,10 @@
  * Write up to len samples of type sox_sample_t from buf[] into file.
  * Return number of samples written.
  */
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
   priv_t * ffmpeg = (priv_t *)ft->priv;
-  sox_size_t nread = 0, nwritten = 0;
+  size_t nread = 0, nwritten = 0;
 
   /* Write data repeatedly until buf is empty */
   do {
--- /dev/null
+++ b/src/ffmpeg.h
@@ -1,0 +1,34 @@
+/* This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#if defined __GNUC__
+  #pragma GCC system_header
+#elif defined __SUNPRO_C
+  #pragma disable_warn
+#elif defined _MSC_VER
+  #pragma warning(push, 1)
+#endif
+
+#if HAVE_LIBAVFORMAT_AVFORMAT_H
+#include <libavformat/avformat.h>
+#else
+#include <ffmpeg/avformat.h>
+#endif
+
+#if defined __SUNPRO_C
+  #pragma enable_warn
+#elif defined _MSC_VER
+  #pragma warning(pop)
+#endif
--- a/src/fifo.h
+++ b/src/fifo.h
@@ -101,7 +101,7 @@
   return ret;
 }
 
-#define fifo_read_ptr(f) fifo_read(f, 0, NULL)
+#define fifo_read_ptr(f) fifo_read(f, (FIFO_SIZE_T)0, NULL)
 
 UNUSED static void fifo_delete(fifo_t * f)
 {
--- a/src/filter.c
+++ b/src/filter.c
@@ -248,7 +248,7 @@
         Fp0 = lsx_malloc(sizeof(double) * (Xh + 2));
         ++Fp0;
         if (f->freq0 > (sox_sample_t)f->rate/200) {
-                Xh0 = lsx_makeFilter(Fp0, Xh, 2.0*(double)f->freq0/f->rate, f->beta, 1, 0);
+                Xh0 = lsx_makeFilter(Fp0, Xh, 2.0*(double)f->freq0/f->rate, f->beta, (size_t) 1, 0);
                 if (Xh0 <= 1)
                 {
                         sox_fail("filter: Unable to make low filter");
@@ -261,7 +261,7 @@
         ++Fp1;
         /* need Fp[-1] and Fp[Xh] for lsx_makeFilter */
         if (f->freq1 < (sox_sample_t)f->rate/2) {
-                Xh1 = lsx_makeFilter(Fp1, Xh, 2.0*(double)f->freq1/f->rate, f->beta, 1, 0);
+                Xh1 = lsx_makeFilter(Fp1, Xh, 2.0*(double)f->freq1/f->rate, f->beta, (size_t) 1, 0);
                 if (Xh1 <= 1)
                 {
                         sox_fail("filter: Unable to make high filter");
@@ -305,10 +305,10 @@
  * Return number of samples processed.
  */
 static int sox_filter_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                   sox_size_t *isamp, sox_size_t *osamp)
+                   size_t *isamp, size_t *osamp)
 {
         priv_t * f = (priv_t *) effp->priv;
-        sox_size_t Nx;
+        size_t Nx;
         long i, Nproc;
 
         /* constrain amount we actually process */
@@ -357,7 +357,7 @@
 /*
  * Process tail of input samples.
  */
-static int sox_filter_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_filter_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
         priv_t * f = (priv_t *) effp->priv;
         long isamp_res, osamp_res;
@@ -370,7 +370,7 @@
         osamp_res = *osamp;
         Obuf = obuf;
         while (isamp_res>0 && osamp_res>0) {
-                sox_size_t Isamp, Osamp;
+                size_t Isamp, Osamp;
                 Isamp = isamp_res;
                 Osamp = osamp_res;
                 sox_filter_flow(effp, NULL, Obuf, &Isamp, &Osamp);
--- a/src/flac.c
+++ b/src/flac.c
@@ -189,7 +189,7 @@
 }
 
 
-static sox_size_t read_samples(sox_format_t * const ft, sox_sample_t * sampleBuffer, sox_size_t const requested)
+static size_t read_samples(sox_format_t * const ft, sox_sample_t * sampleBuffer, size_t const requested)
 {
   priv_t * p = (priv_t *)ft->priv;
   size_t actual = 0;
@@ -254,7 +254,7 @@
   (void) encoder;
   if (!ft->seekable)
     return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
-  else if (lsx_seeki(ft, (sox_ssize_t)absolute_byte_offset, SEEK_SET) != SOX_SUCCESS)
+  else if (lsx_seeki(ft, (ptrdiff_t)absolute_byte_offset, SEEK_SET) != SOX_SUCCESS)
     return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
   else
     return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
@@ -377,8 +377,8 @@
 #if FLAC_API_VERSION_CURRENT >= 8
       if (!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(p->metadata[p->num_metadata], (unsigned)(10 * ft->signal.rate + .5), (FLAC__uint64)(ft->signal.length/ft->signal.channels))) {
 #else
-      sox_size_t samples = 10 * ft->signal.rate;
-      sox_size_t total_samples = ft->signal.length/ft->signal.channels;
+      size_t samples = 10 * ft->signal.rate;
+      size_t total_samples = ft->signal.length/ft->signal.channels;
       if (!FLAC__metadata_object_seektable_template_append_spaced_points(p->metadata[p->num_metadata], total_samples / samples + (total_samples % samples != 0), (FLAC__uint64)total_samples)) {
 #endif
         lsx_fail_errno(ft, SOX_ENOMEM, "FLAC ERROR creating the encoder seek table points");
@@ -430,7 +430,7 @@
 
 
 
-static sox_size_t write_samples(sox_format_t * const ft, sox_sample_t const * const sampleBuffer, sox_size_t const len)
+static size_t write_samples(sox_format_t * const ft, sox_sample_t const * const sampleBuffer, size_t const len)
 {
   priv_t * p = (priv_t *)ft->priv;
   unsigned i;
@@ -454,7 +454,7 @@
         break;
     }
   }
-  FLAC__stream_encoder_process_interleaved(p->encoder, p->decoded_samples, len / ft->signal.channels);
+  FLAC__stream_encoder_process_interleaved(p->encoder, p->decoded_samples, (unsigned) len / ft->signal.channels);
   return FLAC__stream_encoder_get_state(p->encoder) == FLAC__STREAM_ENCODER_OK ? len : 0;
 }
 
@@ -484,7 +484,7 @@
  * N.B.  Do not call this function with offset=0 when file-pointer
  * is already 0 or a block of decoded FLAC data will be discarded.
  */
-static int seek(sox_format_t * ft, sox_size_t offset)
+static int seek(sox_format_t * ft, size_t offset)
 {
   priv_t * p = (priv_t *)ft->priv;
   int result = ft->mode == 'r' && FLAC__stream_decoder_seek_absolute(p->decoder, (FLAC__uint64)(offset / ft->signal.channels)) ?  SOX_SUCCESS : SOX_EOF;
--- a/src/flanger.c
+++ b/src/flanger.c
@@ -76,14 +76,14 @@
 
   /* Delay buffers */
   double *   delay_bufs[MAX_CHANNELS];
-  sox_size_t  delay_buf_length;
-  sox_size_t  delay_buf_pos;
+  size_t  delay_buf_length;
+  size_t  delay_buf_pos;
   double     delay_last[MAX_CHANNELS];
 
   /* Low Frequency Oscillator */
   float *    lfo;
-  sox_size_t  lfo_length;
-  sox_size_t  lfo_pos;
+  size_t  lfo_length;
+  size_t  lfo_pos;
 
   /* Balancing */
   double     in_gain;
@@ -186,12 +186,12 @@
       SOX_FLOAT,
       f->lfo,
       f->lfo_length,
-      (double)(sox_size_t)(f->delay_min / 1000 * effp->in_signal.rate + .5),
+      (double)(size_t)(f->delay_min / 1000 * effp->in_signal.rate + .5),
       (double)(f->delay_buf_length - 2),
       3 * M_PI_2);  /* Start the sweep at minimum delay (for mono at least) */
 
-  sox_debug("delay_buf_length=%u lfo_length=%u\n",
-      f->delay_buf_length, f->lfo_length);
+  sox_debug("delay_buf_length=%lu lfo_length=%lu\n",
+      (unsigned long)f->delay_buf_length, (unsigned long)f->lfo_length);
 
   return SOX_SUCCESS;
 }
@@ -199,11 +199,11 @@
 
 
 static int sox_flanger_flow(sox_effect_t * effp, sox_sample_t const * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * f = (priv_t *) effp->priv;
   int c, channels = effp->in_signal.channels;
-  sox_size_t len = (*isamp > *osamp ? *osamp : *isamp) / channels;
+  size_t len = (*isamp > *osamp ? *osamp : *isamp) / channels;
 
   *isamp = *osamp = len * channels;
 
@@ -214,10 +214,10 @@
       double delayed_0, delayed_1;
       double delayed;
       double in, out;
-      sox_size_t channel_phase = c * f->lfo_length * f->channel_phase + .5;
+      size_t channel_phase = c * f->lfo_length * f->channel_phase + .5;
       double delay = f->lfo[(f->lfo_pos + channel_phase) % f->lfo_length];
       double frac_delay = modf(delay, &delay);
-      sox_size_t int_delay = (size_t)delay;
+      size_t int_delay = (size_t)delay;
 
       in = *ibuf++;
       f->delay_bufs[c][f->delay_buf_pos] = in + f->delay_last[c] * f->feedback_gain;
--- a/src/formats.c
+++ b/src/formats.c
@@ -38,7 +38,7 @@
   char data[256];
   size_t len = lsx_readbuf(ft, data, sizeof(data));
   #define MAGIC(type, p2, l2, d2, p1, l1, d1) if (len >= p1 + l1 && \
-      !memcmp(data + p1, d1, l1) && !memcmp(data + p2, d2, l2)) return #type;
+      !memcmp(data + p1, d1, (size_t)l1) && !memcmp(data + p2, d2, (size_t)l2)) return #type;
   MAGIC(voc   , 0, 0, ""     , 0, 20, "Creative Voice File\x1a")
   MAGIC(smp   , 0, 0, ""     , 0, 17, "SOUND SAMPLE DATA")
   MAGIC(wve   , 0, 0, ""     , 0, 15, "ALawSoundFile**")
@@ -387,7 +387,7 @@
   }
 
   if (!(ft->handler.flags & SOX_FILE_NOSTDIO)) {
-    sox_size_t   input_bufsiz = sox_globals.input_bufsiz?
+    size_t   input_bufsiz = sox_globals.input_bufsiz?
         sox_globals.input_bufsiz : sox_globals.bufsiz;
 
     if (!strcmp(path, "-")) { /* Use stdin if the filename is "-" */
@@ -783,15 +783,15 @@
   return NULL;
 }
 
-sox_size_t sox_read(sox_format_t * ft, sox_sample_t * buf, sox_size_t len)
+size_t sox_read(sox_format_t * ft, sox_sample_t * buf, size_t len)
 {
-  sox_size_t actual = ft->handler.read? (*ft->handler.read)(ft, buf, len) : 0;
+  size_t actual = ft->handler.read? (*ft->handler.read)(ft, buf, len) : 0;
   return (actual > len? 0 : actual);
 }
 
-sox_size_t sox_write(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+size_t sox_write(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
-  sox_size_t ret = ft->handler.write? (*ft->handler.write)(ft, buf, len) : 0;
+  size_t ret = ft->handler.write? (*ft->handler.write)(ft, buf, len) : 0;
   ft->olength += ret;
   return ret;
 }
@@ -805,7 +805,7 @@
   else {
     if (ft->handler.flags & SOX_FILE_REWIND) {
       if (ft->olength != ft->signal.length && ft->seekable) {
-        rc = lsx_seeki(ft, 0, 0);
+        rc = lsx_seeki(ft, (size_t)0, 0);
         if (rc == SOX_SUCCESS)
           rc = ft->handler.stopwrite? (*ft->handler.stopwrite)(ft)
              : ft->handler.startwrite?(*ft->handler.startwrite)(ft) : SOX_SUCCESS;
@@ -824,7 +824,7 @@
   return rc;
 }
 
-int sox_seek(sox_format_t * ft, sox_size_t offset, int whence)
+int sox_seek(sox_format_t * ft, size_t offset, int whence)
 {
     /* FIXME: Implement SOX_SEEK_CUR and SOX_SEEK_END. */
     if (whence != SOX_SEEK_SET)
@@ -898,7 +898,7 @@
       text[end] = '\0';
       if (is_pls) {
         char dummy;
-        if (!strncasecmp(text, "file", 4) && sscanf(text + 4, "%*u=%c", &dummy) == 1)
+        if (!strncasecmp(text, "file", (size_t) 4) && sscanf(text + 4, "%*u=%c", &dummy) == 1)
           begin = strchr(text + 5, '=') - text + 1;
         else end = 0;
       }
@@ -934,7 +934,7 @@
 
 #include <ltdl.h>
 #define MAX_FORMATS 256 /* FIXME: Use a vector, not a fixed-size array */
-#define MAX_NAME_LEN 1024 /* FIXME: Use vasprintf */
+#define MAX_NAME_LEN (size_t)1024 /* FIXME: Use vasprintf */
 
 static sox_bool plugins_initted = sox_false;
 
@@ -952,8 +952,8 @@
 
   (void)data;
   if (start && (start += sizeof(prefix) - 1) < end) {
-    int ret = snprintf(fnname, MAX_NAME_LEN, "sox_%.*s_format_fn", end - start, start);
-    if (ret > 0 && ret < MAX_NAME_LEN) {
+    int ret = snprintf(fnname, MAX_NAME_LEN, "sox_%.*s_format_fn", (int)(end - start), start);
+    if (ret > 0 && ret < (int)MAX_NAME_LEN) {
       union {sox_format_fn_t fn; lt_ptr ptr;} ltptr;
       ltptr.ptr = lt_dlsym(lth, fnname);
       sox_debug("opening format plugin `%s': library %p, entry point %p\n", fnname, (void *)lth, ltptr.ptr);
@@ -1016,7 +1016,7 @@
  */
 sox_format_handler_t const * sox_find_format(char const * name, sox_bool no_dev)
 {
-  sox_size_t f, n;
+  size_t f, n;
 
   if (name) for (f = 0; sox_format_fns[f].fn; ++f) {
     sox_format_handler_t const * handler = sox_format_fns[f].fn();
--- a/src/formats_i.c
+++ b/src/formats_i.c
@@ -95,9 +95,9 @@
 /* Read in a buffer of data of length len bytes.
  * Returns number of bytes read.
  */
-size_t lsx_readbuf(sox_format_t * ft, void *buf, sox_size_t len)
+size_t lsx_readbuf(sox_format_t * ft, void *buf, size_t len)
 {
-  size_t ret = fread(buf, 1, len, ft->fp);
+  size_t ret = fread(buf, (size_t) 1, len, ft->fp);
   if (ret != len && ferror(ft->fp))
     lsx_fail_errno(ft, errno, "lsx_readbuf");
   ft->tell_off += ret;
@@ -105,7 +105,7 @@
 }
 
 /* Skip input without seeking. */
-int lsx_skipbytes(sox_format_t * ft, sox_size_t n)
+int lsx_skipbytes(sox_format_t * ft, size_t n)
 {
   unsigned char trash;
 
@@ -117,7 +117,7 @@
 }
 
 /* Pad output. */
-int lsx_padbytes(sox_format_t * ft, sox_size_t n)
+int lsx_padbytes(sox_format_t * ft, size_t n)
 {
   while (n--)
     if (lsx_writeb(ft, '\0') == SOX_EOF)
@@ -129,9 +129,9 @@
 /* Write a buffer of data of length bytes.
  * Returns number of bytes written.
  */
-size_t lsx_writebuf(sox_format_t * ft, void const * buf, sox_size_t len)
+size_t lsx_writebuf(sox_format_t * ft, void const * buf, size_t len)
 {
-  size_t ret = fwrite(buf, 1, len, ft->fp);
+  size_t ret = fwrite(buf, (size_t) 1, len, ft->fp);
   if (ret != len) {
     lsx_fail_errno(ft, errno, "error writing output file");
     clearerr(ft->fp); /* Allows us to seek back to write header */
@@ -140,12 +140,12 @@
   return ret;
 }
 
-sox_size_t lsx_filelength(sox_format_t * ft)
+size_t lsx_filelength(sox_format_t * ft)
 {
   struct stat st;
   int ret = fstat(fileno(ft->fp), &st);
 
-  return ret? 0 : (sox_size_t)st.st_size;
+  return ret? 0 : (size_t)st.st_size;
 }
 
 int lsx_flush(sox_format_t * ft)
@@ -153,9 +153,9 @@
   return fflush(ft->fp);
 }
 
-sox_ssize_t lsx_tell(sox_format_t * ft)
+ptrdiff_t lsx_tell(sox_format_t * ft)
 {
-  return ft->seekable? (sox_ssize_t)ftello(ft->fp) : ft->tell_off;
+  return ft->seekable? (ptrdiff_t)ftello(ft->fp) : ft->tell_off;
 }
 
 int lsx_eof(sox_format_t * ft)
@@ -189,7 +189,7 @@
  *
  * N.B. Can only seek forwards on non-seekable streams!
  */
-int lsx_seeki(sox_format_t * ft, sox_ssize_t offset, int whence)
+int lsx_seeki(sox_format_t * ft, ptrdiff_t offset, int whence)
 {
     if (ft->seekable == 0) {
         /* If a stream peel off chars else EPERM */
@@ -214,12 +214,12 @@
     return ft->sox_errno;
 }
 
-int lsx_offset_seek(sox_format_t * ft, off_t byte_offset, sox_size_t to_sample)
+int lsx_offset_seek(sox_format_t * ft, off_t byte_offset, size_t to_sample)
 {
   double wide_sample = to_sample - (to_sample % ft->signal.channels);
   double to_d = wide_sample * ft->encoding.bits_per_sample / 8;
   off_t to = to_d;
-  return (to != to_d)? SOX_EOF : lsx_seeki(ft, (sox_ssize_t)(byte_offset + to), SEEK_SET);
+  return (to != to_d)? SOX_EOF : lsx_seeki(ft, (ptrdiff_t)(byte_offset + to), SEEK_SET);
 }
 
 /* Read and write known datatypes in "machine format".  Swap if indicated.
@@ -228,7 +228,7 @@
 /* Read n-char string (and possibly null-terminating).
  * Stop reading and null-terminate string if either a 0 or \n is reached.
  */
-int lsx_reads(sox_format_t * ft, char *c, sox_size_t len)
+int lsx_reads(sox_format_t * ft, char *c, size_t len)
 {
     char *sc;
     char in;
@@ -236,7 +236,7 @@
     sc = c;
     do
     {
-        if (lsx_readbuf(ft, &in, 1) != 1)
+        if (lsx_readbuf(ft, &in, (size_t)1) != 1)
         {
             *sc = 0;
             return (SOX_EOF);
@@ -273,9 +273,9 @@
 }
 
 /* generic swap routine. Swap l and place in to f (datatype length = n) */
-static void swap(char const * l, char * f, int n)
+static void swap(char const * l, char * f, size_t n)
 {
-    register int i;
+    size_t i;
 
     for (i= 0; i< n; i++)
         f[i]= l[n-i-1];
@@ -284,7 +284,7 @@
 static double lsx_swapdf(double df)
 {
     double sdf;
-    swap((char *)&df, (char *)&sdf, sizeof(double));
+    swap((char *)&df, (char *)&sdf, (size_t) sizeof(double));
     return (sdf);
 }
 
@@ -334,10 +334,10 @@
 /* N.B. This macro doesn't work for unaligned types (e.g. 3-byte
    types). */
 #define READ_FUNC(type, size, ctype, twiddle) \
-  sox_size_t lsx_read_ ## type ## _buf( \
-      sox_format_t * ft, ctype *buf, sox_size_t len) \
+  size_t lsx_read_ ## type ## _buf( \
+      sox_format_t * ft, ctype *buf, size_t len) \
   { \
-    sox_size_t n, nread; \
+    size_t n, nread; \
     nread = lsx_readbuf(ft, buf, len * size) / size; \
     for (n = 0; n < nread; n++) \
       twiddle(buf[n], type); \
@@ -352,10 +352,10 @@
 /* This (slower) macro works for unaligned types (e.g. 3-byte types)
    that need to be unpacked. */
 #define READ_FUNC_UNPACK(type, size, ctype, twiddle) \
-  sox_size_t lsx_read_ ## type ## _buf( \
-      sox_format_t * ft, ctype *buf, sox_size_t len) \
+  size_t lsx_read_ ## type ## _buf( \
+      sox_format_t * ft, ctype *buf, size_t len) \
   { \
-    sox_size_t n, nread; \
+    size_t n, nread; \
     uint8_t *data = lsx_malloc(size * len); \
     nread = lsx_readbuf(ft, data, len * size) / size; \
     for (n = 0; n < nread; n++) \
@@ -373,7 +373,7 @@
 
 #define READ1_FUNC(type, ctype) \
 int lsx_read ## type(sox_format_t * ft, ctype * datum) { \
-  if (lsx_read_ ## type ## _buf(ft, datum, 1) == 1) \
+  if (lsx_read_ ## type ## _buf(ft, datum, (size_t)1) == 1) \
     return SOX_SUCCESS; \
   if (!lsx_error(ft)) \
     lsx_fail_errno(ft, errno, premature_eof); \
@@ -389,7 +389,7 @@
 READ1_FUNC(f,  float)
 READ1_FUNC(df, double)
 
-int lsx_readchars(sox_format_t * ft, char * chars, sox_size_t len)
+int lsx_readchars(sox_format_t * ft, char * chars, size_t len)
 {
   size_t ret = lsx_readbuf(ft, chars, len);
   if (ret == len)
@@ -402,10 +402,10 @@
 /* N.B. This macro doesn't work for unaligned types (e.g. 3-byte
    types). */
 #define WRITE_FUNC(type, size, ctype, twiddle) \
-  sox_size_t lsx_write_ ## type ## _buf( \
-      sox_format_t * ft, ctype *buf, sox_size_t len) \
+  size_t lsx_write_ ## type ## _buf( \
+      sox_format_t * ft, ctype *buf, size_t len) \
   { \
-    sox_size_t n, nwritten; \
+    size_t n, nwritten; \
     for (n = 0; n < len; n++) \
       twiddle(buf[n], type); \
     nwritten = lsx_writebuf(ft, buf, len * size); \
@@ -421,10 +421,10 @@
 /* This (slower) macro works for unaligned types (e.g. 3-byte types)
    that need to be packed. */
 #define WRITE_FUNC_PACK(type, size, ctype, twiddle) \
-  sox_size_t lsx_write_ ## type ## _buf( \
-      sox_format_t * ft, ctype *buf, sox_size_t len) \
+  size_t lsx_write_ ## type ## _buf( \
+      sox_format_t * ft, ctype *buf, size_t len) \
   { \
-    sox_size_t n, nwritten; \
+    size_t n, nwritten; \
     uint8_t *data = lsx_malloc(size * len); \
     for (n = 0; n < len; n++) \
       sox_pack ## size(data + n * size, buf[n]); \
@@ -443,19 +443,19 @@
 #define WRITE1U_FUNC(type, ctype) \
   int lsx_write ## type(sox_format_t * ft, unsigned d) \
   { ctype datum = (ctype)d; \
-    return lsx_write_ ## type ## _buf(ft, &datum, 1) == 1 ? SOX_SUCCESS : SOX_EOF; \
+    return lsx_write_ ## type ## _buf(ft, &datum, (size_t)1) == 1 ? SOX_SUCCESS : SOX_EOF; \
   }
 
 #define WRITE1S_FUNC(type, ctype) \
   int lsx_writes ## type(sox_format_t * ft, signed d) \
   { ctype datum = (ctype)d; \
-    return lsx_write_ ## type ## _buf(ft, &datum, 1) == 1 ? SOX_SUCCESS : SOX_EOF; \
+    return lsx_write_ ## type ## _buf(ft, &datum, (size_t)1) == 1 ? SOX_SUCCESS : SOX_EOF; \
   }
 
 #define WRITE1_FUNC(type, ctype) \
   int lsx_write ## type(sox_format_t * ft, ctype datum) \
   { \
-    return lsx_write_ ## type ## _buf(ft, &datum, 1) == 1 ? SOX_SUCCESS : SOX_EOF; \
+    return lsx_write_ ## type ## _buf(ft, &datum, (size_t)1) == 1 ? SOX_SUCCESS : SOX_EOF; \
   }
 
 WRITE1U_FUNC(b, uint8_t)
@@ -469,5 +469,5 @@
 int lsx_writef(sox_format_t * ft, double datum)
 {
   float f = datum;
-  return lsx_write_f_buf(ft, &f, 1) == 1 ? SOX_SUCCESS : SOX_EOF;
+  return lsx_write_f_buf(ft, &f, (size_t) 1) == 1 ? SOX_SUCCESS : SOX_EOF;
 }
--- a/src/gsm.c
+++ b/src/gsm.c
@@ -44,7 +44,7 @@
 #define MAXCHANS 16
 
 /* sizeof(gsm_frame) */
-#define FRAMESIZE 33
+#define FRAMESIZE (size_t)33
 /* samples per gsm_frame */
 #define BLOCKSIZE 160
 
@@ -109,7 +109,7 @@
  * Return number of samples read.
  */
 
-static sox_size_t sox_gsmread(sox_format_t * ft, sox_sample_t *buf, sox_size_t samp)
+static size_t sox_gsmread(sox_format_t * ft, sox_sample_t *buf, size_t samp)
 {
         size_t done = 0, r;
         int ch, chans;
@@ -188,7 +188,7 @@
         return (SOX_SUCCESS);
 }
 
-static sox_size_t sox_gsmwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t samp)
+static size_t sox_gsmwrite(sox_format_t * ft, const sox_sample_t *buf, size_t samp)
 {
         size_t done = 0;
         priv_t *p = (priv_t *) ft->priv;
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -69,8 +69,8 @@
 
   /* Private data used by writer */
   unsigned char *data;          /* Buffer allocated with lsx_malloc */
-  sox_size_t size;               /* Size of allocated buffer */
-  sox_size_t pos;                /* Where next byte goes */
+  size_t size;               /* Size of allocated buffer */
+  size_t pos;                /* Where next byte goes */
 } priv_t;
 
 static int startread(sox_format_t * ft)
@@ -85,12 +85,12 @@
 
 
         /* Skip first 65 bytes of header */
-        rc = lsx_skipbytes(ft, 65);
+        rc = lsx_skipbytes(ft, (size_t) 65);
         if (rc)
             return rc;
 
         /* Check the file type (bytes 65-68) */
-        if (lsx_reads(ft, buf, 4) == SOX_EOF || strncmp(buf, "FSSD", 4) != 0)
+        if (lsx_reads(ft, buf, (size_t)4) == SOX_EOF || strncmp(buf, "FSSD", (size_t)4) != 0)
         {
                 lsx_fail_errno(ft,SOX_EHDR,"Mac header type is not FSSD");
                 return (SOX_EOF);
@@ -97,7 +97,7 @@
         }
 
         /* Skip to byte 83 */
-        rc = lsx_skipbytes(ft, 83-69);
+        rc = lsx_skipbytes(ft, (size_t) 83-69);
         if (rc)
             return rc;
 
@@ -106,12 +106,12 @@
         lsx_readdw(ft, &rsrcsize); /* bytes 87-90 */
 
         /* Skip the rest of the header (total 128 bytes) */
-        rc = lsx_skipbytes(ft, 128-91);
+        rc = lsx_skipbytes(ft, (size_t) 128-91);
         if (rc != 0)
             return rc;
 
         /* The data fork must contain a "HCOM" header */
-        if (lsx_reads(ft, buf, 4) == SOX_EOF || strncmp(buf, "HCOM", 4) != 0)
+        if (lsx_reads(ft, buf, (size_t)4) == SOX_EOF || strncmp(buf, "HCOM", (size_t)4) != 0)
         {
                 lsx_fail_errno(ft,SOX_EHDR,"Mac data fork is not HCOM");
                 return (SOX_EOF);
@@ -151,7 +151,7 @@
                        p->dictionary[i].dict_leftson,
                        p->dictionary[i].dict_rightson);
         }
-        rc = lsx_skipbytes(ft, 1); /* skip pad byte */
+        rc = lsx_skipbytes(ft, (size_t) 1); /* skip pad byte */
         if (rc)
             return rc;
 
@@ -168,7 +168,7 @@
         return (SOX_SUCCESS);
 }
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
         register priv_t *p = (priv_t *) ft->priv;
         int done = 0;
@@ -262,11 +262,11 @@
   return SOX_SUCCESS;
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
   priv_t *p = (priv_t *) ft->priv;
   sox_sample_t datum;
-  sox_size_t i;
+  size_t i;
 
   if (len == 0)
     return 0;
@@ -391,7 +391,7 @@
   l = (((l + 31) >> 5) << 2) + 24 + dictsize * 4;
   sox_debug("  Original size: %6d bytes", *dl);
   sox_debug("Compressed size: %6d bytes", l);
-  datafork = lsx_malloc((unsigned)l);
+  datafork = lsx_malloc((size_t)l);
   ddf = datafork + 22;
   for(i = 0; i < dictsize; i++) {
     put16_be(&ddf, newdict[i].dict_leftson);
@@ -409,7 +409,7 @@
     codesize[0] = 32 - p->nbits;
     putcode(ft, codes, codesize, 0, &ddf);
   }
-  memcpy(datafork, "HCOM", 4);
+  memcpy(datafork, "HCOM", (size_t)4);
   dfp = datafork + 4;
   put32_be(&dfp, *dl);
   put32_be(&dfp, p->new_checksum);
@@ -427,7 +427,7 @@
 {
   priv_t *p = (priv_t *) ft->priv;
   unsigned char *compressed_data = p->data;
-  sox_size_t compressed_len = p->pos;
+  size_t compressed_len = p->pos;
   int rc = SOX_SUCCESS;
 
   /* Compress it all at once */
@@ -436,13 +436,13 @@
   free(p->data);
 
   /* Write the header */
-  lsx_writebuf(ft, "\000\001A", 3); /* Dummy file name "A" */
-  lsx_padbytes(ft, 65-3);
+  lsx_writebuf(ft, "\000\001A", (size_t) 3); /* Dummy file name "A" */
+  lsx_padbytes(ft, (size_t) 65-3);
   lsx_writes(ft, "FSSD");
-  lsx_padbytes(ft, 83-69);
-  lsx_writedw(ft, compressed_len); /* compressed_data size */
+  lsx_padbytes(ft, (size_t) 83-69);
+  lsx_writedw(ft, (unsigned) compressed_len); /* compressed_data size */
   lsx_writedw(ft, 0); /* rsrc size */
-  lsx_padbytes(ft, 128 - 91);
+  lsx_padbytes(ft, (size_t) 128 - 91);
   if (lsx_error(ft)) {
     lsx_fail_errno(ft, errno, "write error in HCOM header");
     rc = SOX_EOF;
--- a/src/htk.c
+++ b/src/htk.c
@@ -52,8 +52,8 @@
 
   if (!ft->olength && floor(period_100ns) != period_100ns)
     sox_warn("rounding sample period %f (x 100ns) to nearest integer", period_100ns);
-  return lsx_writedw(ft, ft->olength? ft->olength:ft->signal.length)
-      || lsx_writedw(ft, (uint32_t)(period_100ns + .5))
+  return lsx_writedw(ft, (unsigned)(ft->olength? ft->olength:ft->signal.length))
+      || lsx_writedw(ft, (unsigned)(period_100ns + .5))
       || lsx_writew(ft, ft->encoding.bits_per_sample >> 3)
       || lsx_writew(ft, Waveform) ? SOX_EOF : SOX_SUCCESS;
 }
--- a/src/ima_rw.c
+++ b/src/ima_rw.c
@@ -318,14 +318,14 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing.
  */
-sox_size_t lsx_ima_samples_in(
-  sox_size_t dataLen,
-  sox_size_t chans,
-  sox_size_t blockAlign,
-  sox_size_t samplesPerBlock
+size_t lsx_ima_samples_in(
+  size_t dataLen,
+  size_t chans,
+  size_t blockAlign,
+  size_t samplesPerBlock
 )
 {
-  sox_size_t m, n;
+  size_t m, n;
 
   if (samplesPerBlock) {
     n = (dataLen / blockAlign) * samplesPerBlock;
@@ -334,7 +334,7 @@
     n = 0;
     m = blockAlign;
   }
-  if (m >= (sox_size_t)4*chans) {
+  if (m >= (size_t)4*chans) {
     m -= 4*chans;    /* number of bytes beyond block-header */
     m /= 4*chans;    /* number of 4-byte blocks/channel beyond header */
     m = 8*m + 1;     /* samples/chan beyond header + 1 in header */
@@ -346,21 +346,21 @@
 }
 
 /*
- * sox_size_t lsx_ima_bytes_per_block(chans, samplesPerBlock)
+ * size_t lsx_ima_bytes_per_block(chans, samplesPerBlock)
  *   return minimum blocksize which would be required
  *   to encode number of chans with given samplesPerBlock
  */
-sox_size_t lsx_ima_bytes_per_block(
-  sox_size_t chans,
-  sox_size_t samplesPerBlock
+size_t lsx_ima_bytes_per_block(
+  size_t chans,
+  size_t samplesPerBlock
 )
 {
-  sox_size_t n;
+  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 = ((sox_size_t)samplesPerBlock + 14)/8 * 4 * chans;
+  n = ((size_t)samplesPerBlock + 14)/8 * 4 * chans;
   return n;
 }
--- a/src/ima_rw.h
+++ b/src/ima_rw.h
@@ -65,20 +65,20 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing usage.
  */
-extern sox_size_t lsx_ima_samples_in(
-	sox_size_t dataLen,
-	sox_size_t chans,
-	sox_size_t blockAlign,
-	sox_size_t samplesPerBlock
+extern size_t lsx_ima_samples_in(
+	size_t dataLen,
+	size_t chans,
+	size_t blockAlign,
+	size_t samplesPerBlock
 );
 
 /*
- * sox_size_t lsx_ima_bytes_per_block(chans, samplesPerBlock)
+ * size_t lsx_ima_bytes_per_block(chans, samplesPerBlock)
  *   return minimum blocksize which would be required
  *   to encode number of chans with given samplesPerBlock
  */
-extern sox_size_t lsx_ima_bytes_per_block(
-	sox_size_t chans,
-	sox_size_t samplesPerBlock
+extern size_t lsx_ima_bytes_per_block(
+	size_t chans,
+	size_t samplesPerBlock
 );
 
--- a/src/input.c
+++ b/src/input.c
@@ -28,7 +28,7 @@
 }
 
 static int drain(
-    sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
+    sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
 
--- a/src/ladspa.c
+++ b/src/ladspa.c
@@ -115,18 +115,18 @@
   }
 
   /* If no plugins in this module, complain */
-  if (ltptr.fn(0) == NULL) {
+  if (ltptr.fn(0UL) == NULL) {
     sox_fail("no plugins found");
     return SOX_EOF;
   }
 
   /* Get first plugin descriptor */
-  l_st->desc = ltptr.fn(0);
+  l_st->desc = ltptr.fn(0UL);
   assert(l_st->desc);           /* We already know this will work */
 
   /* If more than one plugin, or first argument is not a number, try
      to use first argument as plugin label. */
-  if (n > 0 && (ltptr.fn(1) != NULL || !sscanf(argv[0], "%lf", &arg))) {
+  if (n > 0 && (ltptr.fn(1UL) != NULL || !sscanf(argv[0], "%lf", &arg))) {
     while (l_st->desc && strcmp(l_st->desc->Label, argv[0]) != 0)
       l_st->desc = ltptr.fn(++index);
     if (l_st->desc == NULL) {
@@ -221,10 +221,10 @@
  * Process one bufferful of data.
  */
 static int sox_ladspa_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                           sox_size_t *isamp, sox_size_t *osamp)
+                           size_t *isamp, size_t *osamp)
 {
   priv_t * l_st = (priv_t *)effp->priv;
-  sox_size_t i, len = min(*isamp, *osamp);
+  size_t i, len = min(*isamp, *osamp);
 
   *osamp = *isamp = len;
 
@@ -264,7 +264,7 @@
 /*
  * Nothing to do.
  */
-static int sox_ladspa_drain(sox_effect_t * effp UNUSED, sox_sample_t *obuf UNUSED, sox_size_t *osamp)
+static int sox_ladspa_drain(sox_effect_t * effp UNUSED, sox_sample_t *obuf UNUSED, size_t *osamp)
 {
   *osamp = 0;
 
--- a/src/libsox.c
+++ b/src/libsox.c
@@ -55,7 +55,7 @@
   char const * slash_pos = LAST_SLASH(filename);
   char const * base_name = slash_pos? slash_pos + 1 : filename;
   char const * dot_pos   = strrchr(base_name, '.');
-  fprintf(file, "%.*s: ", dot_pos? dot_pos - base_name : -1, base_name);
+  fprintf(file, "%.*s: ", dot_pos? (int)(dot_pos - base_name) : -1, base_name);
   vfprintf(file, fmt, ap);
 }
 
--- a/src/lpc10.c
+++ b/src/lpc10.c
@@ -108,7 +108,7 @@
   /* Unpack the array bits into coded_frame. */
   for (i = 0; i < len; i++) {
     if (i % 8 == 0) {
-      lsx_read_b_buf(ft, &c, 1);
+      lsx_read_b_buf(ft, &c, (size_t) 1);
       if (lsx_eof(ft)) {
         return (i);
       }
@@ -147,10 +147,10 @@
   return SOX_SUCCESS;
 }
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
   priv_t * lpc = (priv_t *)ft->priv;
-  sox_size_t nread = 0;
+  size_t nread = 0;
 
   while (nread < len) {
     /* Read more data if buffer is empty */
@@ -171,10 +171,10 @@
   return nread;
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
   priv_t * lpc = (priv_t *)ft->priv;
-  sox_size_t nwritten = 0;
+  size_t nwritten = 0;
 
   while (len > 0) {
     while (len > 0 && lpc->samples < LPC10_SAMPLES_PER_FRAME) {
--- a/src/maud.c
+++ b/src/maud.c
@@ -52,7 +52,7 @@
             return rc;
 
         /* read FORM chunk */
-        if (lsx_reads(ft, buf, 4) == SOX_EOF || strncmp(buf, "FORM", 4) != 0)
+        if (lsx_reads(ft, buf, (size_t)4) == SOX_EOF || strncmp(buf, "FORM", (size_t)4) != 0)
         {
                 lsx_fail_errno(ft,SOX_EHDR,"MAUD: header does not begin with magic word 'FORM'");
                 return (SOX_EOF);
@@ -60,7 +60,7 @@
 
         lsx_readdw(ft, &trash32); /* totalsize */
 
-        if (lsx_reads(ft, buf, 4) == SOX_EOF || strncmp(buf, "MAUD", 4) != 0)
+        if (lsx_reads(ft, buf, (size_t)4) == SOX_EOF || strncmp(buf, "MAUD", (size_t)4) != 0)
         {
                 lsx_fail_errno(ft,SOX_EHDR,"MAUD: 'FORM' chunk does not specify 'MAUD' as type");
                 return(SOX_EOF);
@@ -68,7 +68,7 @@
 
         /* read chunks until 'BODY' (or end) */
 
-        while (lsx_reads(ft, buf, 4) == SOX_SUCCESS && strncmp(buf,"MDAT",4) != 0) {
+        while (lsx_reads(ft, buf, (size_t)4) == SOX_SUCCESS && strncmp(buf,"MDAT",(size_t)4) != 0) {
 
                 /*
                 buf[4] = 0;
@@ -75,7 +75,7 @@
                 sox_debug("chunk %s",buf);
                 */
 
-                if (strncmp(buf,"MHDR",4) == 0) {
+                if (strncmp(buf,"MHDR",(size_t)4) == 0) {
 
                         lsx_readdw(ft, &chunksize);
                         if (chunksize != 8*4)
@@ -156,12 +156,12 @@
                         continue;
                 }
 
-                if (strncmp(buf,"ANNO",4) == 0) {
+                if (strncmp(buf,"ANNO",(size_t)4) == 0) {
                         lsx_readdw(ft, &chunksize);
                         if (chunksize & 1)
                                 chunksize++;
-                        chunk_buf = lsx_malloc(chunksize + 1);
-                        if (lsx_readbuf(ft, chunk_buf, chunksize)
+                        chunk_buf = lsx_malloc(chunksize + (size_t)1);
+                        if (lsx_readbuf(ft, chunk_buf, (size_t)chunksize)
                             != chunksize)
                         {
                                 lsx_fail_errno(ft,SOX_EOF,"MAUD: Unexpected EOF in ANNO header");
@@ -178,12 +178,12 @@
                 lsx_readdw(ft, &chunksize);
                 if (chunksize & 1)
                         chunksize++;
-                lsx_seeki(ft, (sox_ssize_t)chunksize, SEEK_CUR);
+                lsx_seeki(ft, (ptrdiff_t)chunksize, SEEK_CUR);
                 continue;
 
         }
 
-        if (strncmp(buf,"MDAT",4) != 0)
+        if (strncmp(buf,"MDAT",(size_t)4) != 0)
         {
             lsx_fail_errno(ft,SOX_EFMT,"MAUD: MDAT chunk not found");
             return(SOX_EOF);
@@ -214,7 +214,7 @@
         return (SOX_SUCCESS);
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
         priv_t * p = (priv_t *) ft->priv;
 
@@ -227,7 +227,7 @@
 {
         /* All samples are already written out. */
 
-        if (lsx_seeki(ft, 0, 0) != 0)
+        if (lsx_seeki(ft, (size_t)0, 0) != 0)
         {
             lsx_fail_errno(ft,errno,"can't rewind output file to rewrite MAUD header");
             return(SOX_EOF);
--- a/src/mcompand.c
+++ b/src/mcompand.c
@@ -91,7 +91,7 @@
   double bandwidth;
 } butterworth_crossover_t;
 
-static int lowpass_setup (butterworth_crossover_t * butterworth, double frequency, sox_rate_t rate, sox_size_t nchan) {
+static int lowpass_setup (butterworth_crossover_t * butterworth, double frequency, sox_rate_t rate, size_t nchan) {
   double c;
 
   butterworth->xy_low = lsx_calloc(nchan, sizeof(struct xy));
@@ -124,12 +124,12 @@
   return (SOX_SUCCESS);
 }
 
-static int lowpass_flow(sox_effect_t * effp, butterworth_crossover_t * butterworth, sox_size_t nChan, sox_sample_t *ibuf, sox_sample_t *lowbuf, sox_sample_t *highbuf,
-                         sox_size_t len) {
-  sox_size_t chan;
+static int lowpass_flow(sox_effect_t * effp, butterworth_crossover_t * butterworth, size_t nChan, sox_sample_t *ibuf, sox_sample_t *lowbuf, sox_sample_t *highbuf,
+                         size_t len) {
+  size_t chan;
   double in, out;
 
-  sox_size_t done;
+  size_t done;
 
   sox_sample_t *ibufptr, *lowbufptr, *highbufptr;
 
@@ -193,7 +193,7 @@
 typedef struct {
   sox_compandt_t transfer_fn;
 
-  sox_size_t expectedChannels; /* Also flags that channels aren't to be treated
+  size_t expectedChannels; /* Also flags that channels aren't to be treated
                            individually when = 1 and input not mono */
   double *attackRate;   /* An array of attack rates */
   double *decayRate;    /*    ... and of decay rates */
@@ -202,16 +202,16 @@
   double topfreq;       /* upper bound crossover frequency */
   butterworth_crossover_t filter;
   sox_sample_t *delay_buf;   /* Old samples, used for delay processing */
-  sox_size_t delay_size;    /* lookahead for this band (in samples) - function of delay, above */
-  sox_ssize_t delay_buf_ptr; /* Index into delay_buf */
-  sox_size_t delay_buf_cnt; /* No. of active entries in delay_buf */
+  size_t delay_size;    /* lookahead for this band (in samples) - function of delay, above */
+  ptrdiff_t delay_buf_ptr; /* Index into delay_buf */
+  size_t delay_buf_cnt; /* No. of active entries in delay_buf */
 } comp_band_t;
 
 typedef struct {
-  sox_size_t nBands;
+  size_t nBands;
   sox_sample_t *band_buf1, *band_buf2, *band_buf3;
-  sox_size_t band_buf_len;
-  sox_size_t delay_buf_size;/* Size of delay_buf in samples */
+  size_t band_buf_len;
+  size_t delay_buf_size;/* Size of delay_buf in samples */
   comp_band_t *bands;
 } priv_t;
 
@@ -221,10 +221,10 @@
  * Don't do initialization now.
  * The 'info' fields are not yet filled in.
  */
-static int sox_mcompand_getopts_1(comp_band_t * l, sox_size_t n, char **argv)
+static int sox_mcompand_getopts_1(comp_band_t * l, size_t n, char **argv)
 {
       char *s;
-      sox_size_t rates, i, commas;
+      size_t rates, i, commas;
 
       /* Start by checking the attack and decay rates */
 
@@ -272,7 +272,7 @@
     return (SOX_SUCCESS);
 }
 
-static int parse_subarg(char *s, char **subargv, sox_size_t *subargc) {
+static int parse_subarg(char *s, char **subargv, size_t *subargc) {
   char **ap;
   char *s_p;
 
@@ -304,7 +304,7 @@
 static int getopts(sox_effect_t * effp, int n, char **argv)
 {
   char *subargv[6], *cp;
-  sox_size_t subargc, i, len;
+  size_t subargc, i, len;
 
   priv_t * c = (priv_t *) effp->priv;
 
@@ -353,8 +353,8 @@
 {
   priv_t * c = (priv_t *) effp->priv;
   comp_band_t * l;
-  sox_size_t i;
-  sox_size_t band;
+  size_t i;
+  size_t band;
 
   for (band=0;band<c->nBands;++band) {
     l = &c->bands[band];
@@ -387,7 +387,7 @@
     l->delay_buf_cnt = 0;
 
     if (l->topfreq != 0)
-      lowpass_setup(&l->filter, l->topfreq, effp->out_signal.rate, effp->out_signal.channels);
+      lowpass_setup(&l->filter, l->topfreq, effp->out_signal.rate, (size_t) effp->out_signal.channels);
   }
   return (SOX_SUCCESS);
 }
@@ -397,7 +397,7 @@
  * value, the attack rate and decay rate
  */
 
-static void doVolume(double *v, double samp, comp_band_t * l, sox_size_t chan)
+static void doVolume(double *v, double samp, comp_band_t * l, size_t chan)
 {
   double s = samp/(~((sox_sample_t)1<<31));
   double delta = s - *v;
@@ -408,9 +408,9 @@
     *v += delta * l->decayRate[chan];
 }
 
-static int sox_mcompand_flow_1(sox_effect_t * effp, priv_t * c, comp_band_t * l, const sox_sample_t *ibuf, sox_sample_t *obuf, sox_size_t len, sox_size_t filechans)
+static int sox_mcompand_flow_1(sox_effect_t * effp, priv_t * c, comp_band_t * l, const sox_sample_t *ibuf, sox_sample_t *obuf, size_t len, size_t filechans)
 {
-  sox_size_t done, chan;
+  size_t done, chan;
 
   for (done = 0; done < len; ibuf += filechans) {
 
@@ -424,7 +424,7 @@
         if (rect > maxsamp)
           maxsamp = rect;
       }
-      doVolume(&l->volume[0], maxsamp, l, 0);
+      doVolume(&l->volume[0], maxsamp, l, (size_t) 0);
     } else {
       for (chan = 0; chan < filechans; ++chan)
         doVolume(&l->volume[chan], fabs((double)ibuf[chan]), l, chan);
@@ -479,11 +479,11 @@
  * Return number of samples processed.
  */
 static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                     sox_size_t *isamp, sox_size_t *osamp) {
+                     size_t *isamp, size_t *osamp) {
   priv_t * c = (priv_t *) effp->priv;
   comp_band_t * l;
-  sox_size_t len = min(*isamp, *osamp);
-  sox_size_t band, i;
+  size_t len = min(*isamp, *osamp);
+  size_t band, i;
   sox_sample_t *abuf, *bbuf, *cbuf, *oldabuf, *ibuf_copy;
   double out;
 
@@ -504,7 +504,7 @@
     l = &c->bands[band];
 
     if (l->topfreq)
-      lowpass_flow(effp, &l->filter, effp->out_signal.channels, abuf, bbuf, cbuf, len);
+      lowpass_flow(effp, &l->filter, (size_t) effp->out_signal.channels, abuf, bbuf, cbuf, len);
     else {
       bbuf = abuf;
       abuf = cbuf;
@@ -511,7 +511,7 @@
     }
     if (abuf == ibuf_copy)
       abuf = c->band_buf3;
-    (void)sox_mcompand_flow_1(effp, c,l,bbuf,abuf,len,effp->out_signal.channels);
+    (void)sox_mcompand_flow_1(effp, c,l,bbuf,abuf,len, (size_t)effp->out_signal.channels);
     for (i=0;i<len;++i)
     {
       out = obuf[i] + abuf[i];
@@ -530,9 +530,9 @@
   return SOX_SUCCESS;
 }
 
-static int sox_mcompand_drain_1(sox_effect_t * effp, priv_t * c, comp_band_t * l, sox_sample_t *obuf, sox_size_t maxdrain)
+static int sox_mcompand_drain_1(sox_effect_t * effp, priv_t * c, comp_band_t * l, sox_sample_t *obuf, size_t maxdrain)
 {
-  sox_size_t done;
+  size_t done;
   double out;
 
   /*
@@ -554,9 +554,9 @@
 /*
  * Drain out compander delay lines.
  */
-static int drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
-  sox_size_t band, drained, mostdrained = 0;
+  size_t band, drained, mostdrained = 0;
   priv_t * c = (priv_t *)effp->priv;
   comp_band_t * l;
 
@@ -583,7 +583,7 @@
 {
   priv_t * c = (priv_t *) effp->priv;
   comp_band_t * l;
-  sox_size_t band;
+  size_t band;
 
   free(c->band_buf1);
   c->band_buf1 = NULL;
@@ -608,7 +608,7 @@
 {
   priv_t * c = (priv_t *) effp->priv;
   comp_band_t * l;
-  sox_size_t band;
+  size_t band;
 
   for (band = 0; band < c->nBands; band++) {
     l = &c->bands[band];
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -500,10 +500,10 @@
  */
 
 static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                sox_size_t *isamp, sox_size_t *osamp)
+                size_t *isamp, size_t *osamp)
 {
     priv_t * mixer = (priv_t *) effp->priv;
-    sox_size_t len, done;
+    size_t len, done;
     int ichan, ochan;
     int i, j;
     double samp;
@@ -541,7 +541,7 @@
 static int oops_getopts(sox_effect_t * effp, int argc, char * * argv UNUSED)
 {
   char * args[] = {"1,1,-1,-1"};
-  return argc? lsx_usage(effp) : sox_mixer_effect_fn()->getopts(effp, array_length(args), args);
+  return argc? lsx_usage(effp) : sox_mixer_effect_fn()->getopts(effp, (int)array_length(args), args);
 }
 
 sox_effect_handler_t const * sox_oops_effect_fn(void)
--- a/src/mp3-duration.h
+++ b/src/mp3-duration.h
@@ -94,14 +94,14 @@
   t->fraction = (d - t->seconds) * MAD_TIMER_RESOLUTION + .5;
 }
 
-static sox_size_t mp3_duration_ms(FILE * fp, unsigned char *buffer)
+static size_t mp3_duration_ms(FILE * fp, unsigned char *buffer)
 {
   struct mad_stream   mad_stream;
   struct mad_header   mad_header;
   struct mad_frame    mad_frame;
   mad_timer_t         time = mad_timer_zero;
-  sox_size_t          initial_bitrate = 0; /* Initialised to prevent warning */
-  sox_size_t          tagsize = 0, consumed = 0, frames = 0;
+  size_t          initial_bitrate = 0; /* Initialised to prevent warning */
+  size_t          tagsize = 0, consumed = 0, frames = 0;
   sox_bool            vbr = sox_false, depadded = sox_false;
 
   mad_stream_init(&mad_stream);
@@ -113,9 +113,9 @@
     size_t leftover = mad_stream.bufend - mad_stream.next_frame;
 
     memcpy(buffer, mad_stream.this_frame, leftover);
-    read = fread(buffer + leftover, 1, INPUT_BUFFER_SIZE - leftover, fp);
+    read = fread(buffer + leftover, (size_t) 1, INPUT_BUFFER_SIZE - leftover, fp);
     if (read <= 0) {
-      sox_debug("got exact duration by scan to EOF (frames=%u leftover=%u)", frames, leftover);
+      sox_debug("got exact duration by scan to EOF (frames=%lu leftover=%lu)", (unsigned long)frames, (unsigned long)leftover);
       break;
     }
     for (; !depadded && padding < read && !buffer[padding]; ++padding);
@@ -133,7 +133,7 @@
         }
         if (mad_stream.error == MAD_ERROR_LOSTSYNC) {
           unsigned available = (mad_stream.bufend - mad_stream.this_frame);
-          tagsize = tagtype(mad_stream.this_frame, available);
+          tagsize = tagtype(mad_stream.this_frame, (size_t) available);
           if (tagsize) {   /* It's some ID3 tags, so just skip */
             if (tagsize >= available) {
               fseeko(fp, (off_t)(tagsize - available), SEEK_CUR);
@@ -162,7 +162,7 @@
           }
         if ((frames = xing_frames(mad_stream.anc_ptr, mad_stream.anc_bitlen))) {
           mad_timer_multiply(&time, (signed long)frames);
-          sox_debug("got exact duration from XING frame count (%u)", frames);
+          sox_debug("got exact duration from XING frame count (%lu)", (unsigned long)frames);
           break;
         }
       }
--- a/src/mp3.c
+++ b/src/mp3.c
@@ -38,8 +38,8 @@
         struct mad_synth        Synth;
         mad_timer_t             Timer;
         unsigned char           *InputBuffer;
-        sox_ssize_t             cursamp;
-        sox_size_t              FrameCount;
+        ptrdiff_t             cursamp;
+        size_t              FrameCount;
 #endif /*HAVE_MAD_H*/
 #ifdef HAVE_LAME_LAME_H
         lame_global_flags       *gfp;
@@ -258,15 +258,16 @@
  * Place in buf[].
  * Return number of samples read.
  */
-static sox_size_t sox_mp3read(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t sox_mp3read(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
     priv_t *p = (priv_t *) ft->priv;
-    sox_size_t donow,i,done=0;
+    size_t donow,i,done=0;
     mad_fixed_t sample;
     size_t chan;
 
     do {
-        donow=min(len,(p->Synth.pcm.length - p->cursamp)*ft->signal.channels);
+        size_t x = (p->Synth.pcm.length - p->cursamp)*ft->signal.channels;
+        donow=min(len, x);
         i=0;
         while(i<donow){
             for(chan=0;chan<ft->signal.channels;chan++){
@@ -397,16 +398,16 @@
   return(SOX_SUCCESS);
 }
 
-static sox_size_t sox_mp3write(sox_format_t * ft, const sox_sample_t *buf, sox_size_t samp)
+static size_t sox_mp3write(sox_format_t * ft, const sox_sample_t *buf, size_t samp)
 {
     priv_t *p = (priv_t *)ft->priv;
     unsigned char *mp3buffer;
-    sox_size_t mp3buffer_size;
+    size_t mp3buffer_size;
     short signed int *buffer_l, *buffer_r = NULL;
     int nsamples = samp/ft->signal.channels;
     int i,j;
-    sox_ssize_t done = 0;
-    sox_size_t written;
+    ptrdiff_t done = 0;
+    size_t written;
 
     /* NOTE: This logic assumes that "short int" is 16-bits
      * on all platforms.  It happens to be for all that I know
--- a/src/noiseprof.c
+++ b/src/noiseprof.c
@@ -36,7 +36,7 @@
     FILE* output_file;
 
     chandata_t *chandata;
-    sox_size_t bufdata;
+    size_t bufdata;
 } priv_t;
 
 /*
@@ -112,14 +112,14 @@
  * Grab what we can from ibuf, and process if we have a whole window.
  */
 static int sox_noiseprof_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                    sox_size_t *isamp, sox_size_t *osamp)
+                    size_t *isamp, size_t *osamp)
 {
     priv_t * data = (priv_t *) effp->priv;
-    sox_size_t samp = min(*isamp, *osamp);
-    sox_size_t tracks = effp->in_signal.channels;
-    sox_size_t track_samples = samp / tracks;
+    size_t samp = min(*isamp, *osamp);
+    size_t tracks = effp->in_signal.channels;
+    size_t track_samples = samp / tracks;
     int ncopy = 0;
-    sox_size_t i;
+    size_t i;
 
     /* FIXME: Make this automatic for all effects */
     assert(effp->in_signal.channels == effp->out_signal.channels);
@@ -154,7 +154,7 @@
  * Finish off the last window.
  */
 
-static int sox_noiseprof_drain(sox_effect_t * effp, sox_sample_t *obuf UNUSED, sox_size_t *osamp)
+static int sox_noiseprof_drain(sox_effect_t * effp, sox_sample_t *obuf UNUSED, size_t *osamp)
 {
     priv_t * data = (priv_t *) effp->priv;
     int tracks = effp->in_signal.channels;
@@ -186,13 +186,13 @@
 static int sox_noiseprof_stop(sox_effect_t * effp)
 {
     priv_t * data = (priv_t *) effp->priv;
-    sox_size_t i;
+    size_t i;
 
     for (i = 0; i < effp->in_signal.channels; i ++) {
         int j;
         chandata_t* chan = &(data->chandata[i]);
 
-        fprintf(data->output_file, "Channel %d: ", i);
+        fprintf(data->output_file, "Channel %lu: ", (unsigned long)i);
 
         for (j = 0; j < FREQCOUNT; j ++) {
             double r = chan->profilecount[j] != 0 ?
--- a/src/noisered.c
+++ b/src/noisered.c
@@ -28,7 +28,7 @@
     float threshold;
 
     chandata_t *chandata;
-    sox_size_t bufdata;
+    size_t bufdata;
 } priv_t;
 
 /*
@@ -60,9 +60,9 @@
 static int sox_noisered_start(sox_effect_t * effp)
 {
     priv_t * data = (priv_t *) effp->priv;
-    sox_size_t fchannels = 0;
-    sox_size_t channels = effp->in_signal.channels;
-    sox_size_t i;
+    size_t fchannels = 0;
+    size_t channels = effp->in_signal.channels;
+    size_t i;
     FILE* ifp;
 
     data->chandata = lsx_calloc(channels, sizeof(*(data->chandata)));
@@ -89,13 +89,15 @@
     }
 
     while (1) {
-        sox_size_t i1;
+        unsigned long i1_ul;
+        size_t i1;
         float f1;
-        if (2 != fscanf(ifp, " Channel %u: %f", &i1, &f1))
+        if (2 != fscanf(ifp, " Channel %lu: %f", &i1_ul, &f1))
             break;
+        i1 = i1_ul;
         if (i1 != fchannels) {
-            sox_fail("noisered: Got channel %d, expected channel %d.",
-                    i1, fchannels);
+            sox_fail("noisered: Got channel %lu, expected channel %lu.",
+                    (unsigned long)i1, (unsigned long)fchannels);
             return SOX_EOF;
         }
 
@@ -102,8 +104,8 @@
         data->chandata[fchannels].noisegate[0] = f1;
         for (i = 1; i < FREQCOUNT; i ++) {
             if (1 != fscanf(ifp, ", %f", &f1)) {
-                sox_fail("noisered: Not enough datums for channel %d "
-                        "(expected %d, got %d)", fchannels, FREQCOUNT, i);
+                sox_fail("noisered: Not enough datums for channel %lu "
+                        "(expected %d, got %lu)", (unsigned long)fchannels, FREQCOUNT, (unsigned long)i);
                 return SOX_EOF;
             }
             data->chandata[fchannels].noisegate[i] = f1;
@@ -111,8 +113,8 @@
         fchannels ++;
     }
     if (fchannels != channels) {
-        sox_fail("noisered: channel mismatch: %d in input, %d in profile.",
-                channels, fchannels);
+        sox_fail("noisered: channel mismatch: %lu in input, %lu in profile.",
+                (unsigned long)channels, (unsigned long)fchannels);
         return SOX_EOF;
     }
     if (ifp != stdin)
@@ -238,16 +240,16 @@
  * Read in windows, and call process_window once we get a whole one.
  */
 static int sox_noisered_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                    sox_size_t *isamp, sox_size_t *osamp)
+                    size_t *isamp, size_t *osamp)
 {
     priv_t * data = (priv_t *) effp->priv;
-    sox_size_t samp = min(*isamp, *osamp);
-    sox_size_t tracks = effp->in_signal.channels;
-    sox_size_t track_samples = samp / tracks;
-    sox_size_t ncopy = min(track_samples, WINDOWSIZE-data->bufdata);
-    sox_size_t whole_window = (ncopy + data->bufdata == WINDOWSIZE);
+    size_t samp = min(*isamp, *osamp);
+    size_t tracks = effp->in_signal.channels;
+    size_t track_samples = samp / tracks;
+    size_t ncopy = min(track_samples, WINDOWSIZE-data->bufdata);
+    size_t whole_window = (ncopy + data->bufdata == WINDOWSIZE);
     int oldbuf = data->bufdata;
-    sox_size_t i;
+    size_t i;
 
     /* FIXME: Make this automatic for all effects */
     assert(effp->in_signal.channels == effp->out_signal.channels);
@@ -260,7 +262,7 @@
     /* Reduce noise on every channel. */
     for (i = 0; i < tracks; i ++) {
         chandata_t* chan = &(data->chandata[i]);
-        sox_size_t j;
+        size_t j;
 
         if (chan->window == NULL)
             chan->window = lsx_calloc(WINDOWSIZE, sizeof(float));
@@ -272,7 +274,7 @@
         if (!whole_window)
             continue;
         else
-            process_window(effp, data, i, tracks, obuf, oldbuf + ncopy);
+            process_window(effp, data, (unsigned) i, (unsigned) tracks, obuf, (unsigned) (oldbuf + ncopy));
     }
 
     *isamp = tracks*ncopy;
@@ -288,13 +290,13 @@
  * We have up to half a window left to dump.
  */
 
-static int sox_noisered_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_noisered_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
     priv_t * data = (priv_t *)effp->priv;
     unsigned i;
     unsigned tracks = effp->in_signal.channels;
     for (i = 0; i < tracks; i ++)
-        *osamp = process_window(effp, data, i, tracks, obuf, data->bufdata);
+        *osamp = process_window(effp, data, i, tracks, obuf, (unsigned) data->bufdata);
 
     /* FIXME: This is very picky.  osamp needs to be big enough to get all
      * remaining data or it will be discarded.
@@ -308,7 +310,7 @@
 static int sox_noisered_stop(sox_effect_t * effp)
 {
     priv_t * data = (priv_t *) effp->priv;
-    sox_size_t i;
+    size_t i;
 
     for (i = 0; i < effp->in_signal.channels; i ++) {
         chandata_t* chan = &(data->chandata[i]);
--- a/src/normalise.c
+++ b/src/normalise.c
@@ -50,10 +50,10 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t len;
+  size_t len;
 
   if (fwrite(ibuf, sizeof(*ibuf), *isamp, p->tmp_file) != *isamp) {
     sox_fail("error writing temporary file: %s", strerror(errno));
@@ -67,10 +67,10 @@
   return SOX_SUCCESS;
 }
 
-static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
+static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t len;
+  size_t len;
   int result = SOX_SUCCESS;
 
   if (!p->norm0) {
--- a/src/nulfile.c
+++ b/src/nulfile.c
@@ -31,7 +31,7 @@
   return SOX_SUCCESS;
 }
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t * buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t * buf, size_t len)
 {
   /* Reading from null generates silence i.e. (sox_sample_t)0. */
   (void)ft;
@@ -39,8 +39,8 @@
   return len; /* Return number of samples "read". */
 }
 
-static sox_size_t write_samples(
-    sox_format_t * ft, sox_sample_t const * buf, sox_size_t len)
+static size_t write_samples(
+    sox_format_t * ft, sox_sample_t const * buf, size_t len)
 {
   /* Writing to null just discards the samples */
   (void)ft, (void)buf;
--- a/src/oss.c
+++ b/src/oss.c
@@ -89,7 +89,7 @@
 
     if (ft->signal.channels > 2) ft->signal.channels = 2;
 
-    if (ioctl(fileno(ft->fp), SNDCTL_DSP_RESET, 0) < 0)
+    if (ioctl(fileno(ft->fp), (size_t) SNDCTL_DSP_RESET, 0) < 0)
     {
         lsx_fail_errno(ft,SOX_EOF,"Unable to reset OSS driver.  Possibly accessing an invalid file/device");
         return(SOX_EOF);
@@ -188,7 +188,7 @@
     file->size = 0;
     ioctl (fileno(ft->fp), SNDCTL_DSP_GETBLKSIZE, &file->size);
     if (file->size < 4 || file->size > 65536) {
-            lsx_fail_errno(ft,SOX_EOF,"Invalid audio buffer size %d", file->size);
+            lsx_fail_errno(ft,SOX_EOF,"Invalid audio buffer size %lu", (unsigned long)file->size);
             return (SOX_EOF);
     }
     file->count = 0;
@@ -195,7 +195,7 @@
     file->pos = 0;
     file->buf = lsx_malloc(file->size);
 
-    if (ioctl(fileno(ft->fp), SNDCTL_DSP_SYNC, NULL) < 0) {
+    if (ioctl(fileno(ft->fp), (size_t) SNDCTL_DSP_SYNC, NULL) < 0) {
         lsx_fail_errno(ft,SOX_EOF,"Unable to sync dsp");
         return (SOX_EOF);
     }
--- a/src/output.c
+++ b/src/output.c
@@ -28,7 +28,7 @@
 }
 
 static int flow(sox_effect_t *effp, sox_sample_t const * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
   /* Write out *isamp samples */
--- a/src/pad.c
+++ b/src/pad.c
@@ -21,13 +21,13 @@
   unsigned npads;     /* Number of pads requested */
   struct {
     char * str;       /* Command-line argument to parse for this pad */
-    sox_size_t start; /* Start padding when in_pos equals this */
-    sox_size_t pad;   /* Number of samples to pad */
+    size_t start; /* Start padding when in_pos equals this */
+    size_t pad;   /* Number of samples to pad */
   } * pads;
 
-  sox_size_t in_pos;  /* Number of samples read from the input stream */
+  size_t in_pos;  /* Number of samples read from the input stream */
   unsigned pads_pos;  /* Number of pads completed so far */
-  sox_size_t pad_pos; /* Number of samples through the current pad */
+  size_t pad_pos; /* Number of samples through the current pad */
 } priv_t;
 
 static int parse(sox_effect_t * effp, char * * argv, sox_rate_t rate)
@@ -76,10 +76,10 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t c, idone = 0, odone = 0;
+  size_t c, idone = 0, odone = 0;
   *isamp /= effp->in_signal.channels;
   *osamp /= effp->in_signal.channels;
 
@@ -104,10 +104,10 @@
   return SOX_SUCCESS;
 }
 
-static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
+static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  static sox_size_t isamp = 0;
+  static size_t isamp = 0;
   if (p->pads_pos != p->npads && p->in_pos != p->pads[p->pads_pos].start)
     p->in_pos = SOX_SIZE_MAX;  /* Invoke the final pad (with no given start) */
   return flow(effp, 0, obuf, &isamp, osamp);
--- a/src/pan.c
+++ b/src/pan.c
@@ -70,10 +70,10 @@
  * Process either isamp or osamp samples, whichever is smaller.
  */
 static int sox_pan_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                sox_size_t *isamp, sox_size_t *osamp)
+                size_t *isamp, size_t *osamp)
 {
     priv_t * pan = (priv_t *) effp->priv;
-    sox_size_t len, done;
+    size_t len, done;
     sox_sample_t *ibuf_copy;
     char ich, och;
     double left, right, direction, hdir;
--- a/src/phaser.c
+++ b/src/phaser.c
@@ -70,9 +70,9 @@
         float   in_gain, out_gain;
         float   delay, decay;
         float   speed;
-        sox_size_t length;
+        size_t length;
         int     *lookup_tab;
-        sox_size_t maxsamples, fade_out;
+        size_t maxsamples, fade_out;
 } priv_t;
 
 /*
@@ -155,10 +155,10 @@
         phaser->lookup_tab = lsx_malloc(sizeof (int) * phaser->length);
 
         if (phaser->modulation == MOD_SINE)
-          lsx_generate_wave_table(SOX_WAVE_SINE, SOX_INT, phaser->lookup_tab,
+          lsx_generate_wave_table(SOX_WAVE_SINE, SOX_INT, phaser->lookup_tab, (size_t)
               phaser->length, 0., (double)(phaser->maxsamples - 1), 0.);
         else
-          lsx_generate_wave_table(SOX_WAVE_TRIANGLE, SOX_INT, phaser->lookup_tab,
+          lsx_generate_wave_table(SOX_WAVE_TRIANGLE, SOX_INT, phaser->lookup_tab, (size_t)
               phaser->length, 0., (double)(2 * (phaser->maxsamples - 1)), 3 * M_PI_2);
         phaser->counter = 0;
         phaser->phase = 0;
@@ -171,12 +171,12 @@
  * Return number of samples processed.
  */
 static int sox_phaser_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                   sox_size_t *isamp, sox_size_t *osamp)
+                   size_t *isamp, size_t *osamp)
 {
         priv_t * phaser = (priv_t *) effp->priv;
         double d_in, d_out;
         sox_sample_t out;
-        sox_size_t len = min(*isamp, *osamp);
+        size_t len = min(*isamp, *osamp);
         *isamp = *osamp = len;
 
         while (len--) {
@@ -204,10 +204,10 @@
 /*
  * Drain out reverb lines.
  */
-static int sox_phaser_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_phaser_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
         priv_t * phaser = (priv_t *) effp->priv;
-        sox_size_t done;
+        size_t done;
 
         double d_in, d_out;
         sox_sample_t out;
--- a/src/pitch.c
+++ b/src/pitch.c
@@ -110,7 +110,7 @@
 
     unsigned int iacc;   /* part of acc already output */
 
-    sox_size_t size;      /* size of buffer for processing chunks. */
+    size_t size;      /* size of buffer for processing chunks. */
     unsigned int index;  /* index of next empty input item. */
     sox_sample_t *buf;    /* bufferize input */
 
@@ -177,8 +177,8 @@
  */
 static void interpolation(
   priv_t * pitch,
-  const sox_sample_t *ibuf, sox_size_t ilen,
-  double * out, sox_size_t olen,
+  const sox_sample_t *ibuf, size_t ilen,
+  double * out, size_t olen,
   double rate) /* signed */
 {
     register int i, size;
@@ -234,8 +234,8 @@
 
     /* forwards sweep */
     interpolation(pitch,
-                  pitch->buf+pitch->overlap, pitch->step+pitch->overlap,
-                  pitch->tmp, pitch->step,
+                  pitch->buf+pitch->overlap, (size_t)(pitch->step+pitch->overlap),
+                  pitch->tmp, (size_t)pitch->step,
                   pitch->rate);
 
     for (i=0; i<len; i++)
@@ -243,8 +243,8 @@
 
     /* backwards sweep */
     interpolation(pitch,
-                  pitch->buf, pitch->step+pitch->overlap,
-                  pitch->tmp, pitch->step,
+                  pitch->buf, (size_t)(pitch->step+pitch->overlap),
+                  pitch->tmp, (size_t)pitch->step,
                   -pitch->rate);
 
     for (i=0; i<len; i++)
@@ -423,11 +423,11 @@
 /* Processes input.
  */
 static int sox_pitch_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                sox_size_t *isamp, sox_size_t *osamp)
+                size_t *isamp, size_t *osamp)
 {
     priv_t * pitch = (priv_t *) effp->priv;
     int i, size;
-    sox_size_t len, iindex, oindex;
+    size_t len, iindex, oindex;
 
     size = pitch->size;
     /* size to process */
@@ -499,10 +499,10 @@
 
 /* at the end...
  */
-static int sox_pitch_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_pitch_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
     priv_t * pitch = (priv_t *) effp->priv;
-    sox_size_t i;
+    size_t i;
 
     if (pitch->state == pi_input)
     {
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -47,7 +47,7 @@
   unsigned inskip, outskip;     /* LCM increments for I & O rates */
   double Factor;                 /* out_rate/in_rate               */
   unsigned long total;           /* number of filter stages        */
-  sox_size_t oskip;               /* output samples to skip at start*/
+  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 */
   int win_type;
@@ -349,8 +349,8 @@
 
     effp->out_signal.channels = effp->in_signal.channels;
 
-    rate->lcmrate = lsx_lcm((sox_sample_t)effp->in_signal.rate,
-                           (sox_sample_t)effp->out_signal.rate);
+    rate->lcmrate = lsx_lcm((unsigned)effp->in_signal.rate,
+                           (unsigned)effp->out_signal.rate);
 
     /* Cursory check for LCM overflow.
      * If both rates are below 65k, there should be no problem.
@@ -427,7 +427,7 @@
       s->filt_array = NULL;
       s->window = lsx_malloc(sizeof(Float) * size);
     }
-    sox_debug("Poly:  output samples %d, oskip %d",size, rate->oskip);
+    sox_debug("Poly:  output samples %d, oskip %lu",size, (unsigned long)rate->oskip);
     return (SOX_SUCCESS);
 }
 
@@ -487,7 +487,7 @@
 }
 
 static int sox_poly_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                 sox_size_t *isamp, sox_size_t *osamp)
+                 size_t *isamp, size_t *osamp)
 {
   priv_t * rate = (priv_t *) effp->priv;
   polystage *s0,*s1;
@@ -497,7 +497,7 @@
   s0 = rate->stage[0];            /* the first stage */
   s1 = rate->stage[rate->total];  /* the 'last' stage is output buffer */
   {
-    sox_size_t in_size, gap, k;
+    size_t in_size, gap, k;
 
     in_size = *isamp;
     gap = s0->size - s0->held; /* space available in this 'input' buffer */
@@ -521,7 +521,7 @@
   }
 
   if (s0->held == s0->size && s1->held == 0) {
-    sox_size_t k;
+    size_t k;
     /* input buffer full, output buffer empty, so do process */
 
     for(k=0; k<rate->total; k++) {
@@ -547,10 +547,10 @@
 
   {
     sox_sample_t *q;
-    sox_size_t out_size;
-    sox_size_t oskip;
+    size_t out_size;
+    size_t oskip;
     Float *out_buf;
-    sox_size_t k;
+    size_t k;
 
     oskip = rate->oskip;
                 out_size = s1->held;
@@ -589,9 +589,9 @@
 /*
  * Process tail of input samples.
  */
-static int sox_poly_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_poly_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
-  sox_size_t in_size;
+  size_t in_size;
   /* Call "flow" with NULL input. */
   sox_poly_flow(effp, NULL, obuf, &in_size, osamp);
   return (SOX_SUCCESS);
@@ -604,7 +604,7 @@
 static int sox_poly_stop(sox_effect_t * effp)
 {
     priv_t * rate = (priv_t *)effp->priv;
-    sox_size_t k;
+    size_t k;
 
     for (k = 0; k <= rate->total; k++) {
       free(rate->stage[k]->window);
--- a/src/prc.c
+++ b/src/prc.c
@@ -68,7 +68,7 @@
 
 static void prcwriteheader(sox_format_t * ft);
 
-static int seek(sox_format_t * ft, sox_size_t offset)
+static int seek(sox_format_t * ft, size_t offset)
 {
   priv_t * p = (priv_t *)ft->priv;
   if (ft->encoding.encoding == SOX_ENCODING_ALAW)
@@ -145,8 +145,8 @@
 
   byte >>= 2;
   assert(byte < 64);
-  lsx_reads(ft, appname, byte);
-  if (strncasecmp(appname, "record.app", byte) != 0) {
+  lsx_reads(ft, appname, (size_t)byte);
+  if (strncasecmp(appname, "record.app", (size_t) byte) != 0) {
     lsx_fail_errno(ft, SOX_EHDR, "Invalid application name string %.63s", appname);
     return SOX_EOF;
   }
@@ -243,7 +243,7 @@
   return a;
 }
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t samp)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t samp)
 {
   priv_t * p = (priv_t *)ft->priv;
 
@@ -250,7 +250,7 @@
   sox_debug_more("length now = %d", p->nsamp);
 
   if (ft->encoding.encoding == SOX_ENCODING_IMA_ADPCM) {
-    sox_size_t nsamp, read;
+    size_t nsamp, read;
 
     if (p->frame_samp == 0) {
       unsigned framelen = read_cardinal(ft);
@@ -357,21 +357,21 @@
   }
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t nsamp)
 {
   priv_t * p = (priv_t *)ft->priv;
   /* Psion Record seems not to be able to handle frames > 800 samples */
-  sox_size_t written = 0;
+  size_t written = 0;
   sox_debug_more("length now = %d", p->nsamp);
   if (ft->encoding.encoding == SOX_ENCODING_IMA_ADPCM) while (written < nsamp) {
-    sox_size_t written1, samp = min(nsamp - written, 800);
+    size_t written1, samp = min(nsamp - written, 800);
 
-    write_cardinal(ft, samp);
+    write_cardinal(ft, (unsigned) samp);
     /* Write compressed length */
-    write_cardinal(ft, (samp / 2) + (samp % 2) + 4);
+    write_cardinal(ft, (unsigned) ((samp / 2) + (samp % 2) + 4));
     /* Write length again (seems to be a BListL) */
-    sox_debug_more("list length %d", samp);
-    lsx_writedw(ft, samp);
+    sox_debug_more("list length %lu", (unsigned long)samp);
+    lsx_writedw(ft, (unsigned) samp);
     sox_adpcm_reset(&p->adpcm, ft->encoding.encoding);
     written1 = sox_adpcm_write(ft, &p->adpcm, buf, samp);
     if (written1 != samp)
@@ -395,7 +395,7 @@
       return SOX_SUCCESS;
   }
 
-  if (lsx_seeki(ft, 0, 0) != 0) {
+  if (lsx_seeki(ft, (size_t)0, 0) != 0) {
       lsx_fail_errno(ft,errno,"Can't rewind output file to rewrite Psion header.");
       return(SOX_EOF);
   }
--- a/src/rabbit.c
+++ b/src/rabbit.c
@@ -31,7 +31,7 @@
   double out_rate;
   SRC_STATE *state;             /* SRC state struct */
   SRC_DATA *data;               /* SRC_DATA control struct */
-  sox_size_t i_alloc, o_alloc;  /* Samples allocated in data->data_{in,out} */
+  size_t i_alloc, o_alloc;  /* Samples allocated in data->data_{in,out} */
 } priv_t;
 
 /*
@@ -105,15 +105,15 @@
  * Read, convert, return data.
  */
 static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf UNUSED,
-                   sox_size_t *isamp, sox_size_t *osamp)
+                   size_t *isamp, size_t *osamp)
 {
   priv_t * r = (priv_t *) effp->priv;
   SRC_DATA *d = r->data;
   unsigned int channels = effp->in_signal.channels;
-  sox_size_t i;
-  sox_size_t isamples0 = d->input_frames * channels;
-  sox_size_t isamples = isamples0 + *isamp;
-  sox_size_t osamples = isamples * (d->src_ratio + 0.01) + 8;
+  size_t i;
+  size_t isamples0 = d->input_frames * channels;
+  size_t isamples = isamples0 + *isamp;
+  size_t osamples = isamples * (d->src_ratio + 0.01) + 8;
 
   if (osamples > *osamp) {
     osamples = *osamp;
@@ -147,7 +147,7 @@
        memmove(d->data_in, d->data_in + d->input_frames_used * sizeof(float),
            d->input_frames * sizeof(float));
 
-    for (i = 0; i < (sox_size_t)d->output_frames_gen * channels; i++)
+    for (i = 0; i < (size_t)d->output_frames_gen * channels; i++)
       obuf[i] = SOX_FLOAT_32BIT_TO_SAMPLE(d->data_out[i], effp->clips);
     *osamp += i;
 
@@ -161,10 +161,10 @@
 /*
  * Process samples and write output.
  */
-static int drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
   priv_t * r = (priv_t *) effp->priv;
-  static sox_size_t isamp = 0;
+  static size_t isamp = 0;
   r->data->end_of_input = 1;
   return flow(effp, NULL, obuf, &isamp, osamp);
 }
--- a/src/rate.c
+++ b/src/rate.c
@@ -412,7 +412,7 @@
       s->pre_post = 2 * (array_length(half_fir_coefs_25) - 1);
       s->preload = s->pre = s->pre_post >> 1;
     }
-    fifo_create(&s->fifo, sizeof(sample_t));
+    fifo_create(&s->fifo, (int)sizeof(sample_t));
     memset(fifo_reserve(&s->fifo, s->preload), 0, sizeof(sample_t)*s->preload);
     if (i < p->output_stage_num)
       sox_debug("stage=%-3ipre_post=%-3ipre=%-3ipreload=%i",
@@ -451,7 +451,7 @@
 
   if ((int)remaining > 0) {
     while ((size_t)fifo_occupancy(fifo) < remaining) {
-      rate_input(p, buff, 1024);
+      rate_input(p, buff, (size_t) 1024);
       rate_process(p);
     }
     fifo_trim_to(fifo, (int)remaining);
@@ -526,11 +526,10 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-                sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+                sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t i;
-  size_t odone = *osamp; /* See comment in tempo.c */
+  size_t i, odone = *osamp;
 
   sample_t const * s = rate_output(&p->rate, NULL, &odone);
   for (i = 0; i < odone; ++i) *obuf++ = TO_SOX(*s++, effp->clips);
@@ -545,10 +544,10 @@
   return SOX_SUCCESS;
 }
 
-static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
+static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  static sox_size_t isamp = 0;
+  static size_t isamp = 0;
   rate_flush(&p->rate);
   return flow(effp, 0, obuf, &isamp, osamp);
 }
--- a/src/raw.c
+++ b/src/raw.c
@@ -15,7 +15,7 @@
 #define SOX_SAMPLE_TO_ULAW_BYTE(d,c) sox_14linear2ulaw(SOX_SAMPLE_TO_SIGNED_16BIT(d,c) >> 2)
 #define SOX_SAMPLE_TO_ALAW_BYTE(d,c) sox_13linear2alaw(SOX_SAMPLE_TO_SIGNED_16BIT(d,c) >> 3)
 
-int lsx_rawseek(sox_format_t * ft, sox_size_t offset)
+int lsx_rawseek(sox_format_t * ft, size_t offset)
 {
   return lsx_offset_seek(ft, (off_t)ft->data_start, offset);
 }
@@ -63,10 +63,10 @@
 }
 
 #define READ_SAMPLES_FUNC(type, size, sign, ctype, uctype, cast) \
-  static sox_size_t sox_read_ ## sign ## type ## _samples( \
-      sox_format_t * ft, sox_sample_t *buf, sox_size_t len) \
+  static size_t sox_read_ ## sign ## type ## _samples( \
+      sox_format_t * ft, sox_sample_t *buf, size_t len) \
   { \
-    sox_size_t n, nread; \
+    size_t n, nread; \
     ctype *data = lsx_malloc(sizeof(ctype) * len); \
     nread = lsx_read_ ## type ## _buf(ft, (uctype *)data, len); \
     for (n = 0; n < nread; n++) \
@@ -89,10 +89,10 @@
 READ_SAMPLES_FUNC(df, sizeof(double), su, double, double, SOX_FLOAT_64BIT_TO_SAMPLE)
 
 #define WRITE_SAMPLES_FUNC(type, size, sign, ctype, uctype, cast) \
-  static sox_size_t sox_write_ ## sign ## type ## _samples( \
-      sox_format_t * ft, sox_sample_t const * buf, sox_size_t len) \
+  static size_t sox_write_ ## sign ## type ## _samples( \
+      sox_format_t * ft, sox_sample_t const * buf, size_t len) \
   { \
-    sox_size_t n, nwritten; \
+    size_t n, nwritten; \
     ctype *data = lsx_malloc(sizeof(ctype) * len); \
     for (n = 0; n < len; n++) \
       data[n] = cast(buf[n], ft->clips); \
@@ -156,13 +156,13 @@
   lsx_fail_errno(ft, SOX_EFMT, "this encoding is not supported for this data size"); \
   return NULL; }
 
-typedef sox_size_t(ft_read_fn)
-  (sox_format_t * ft, sox_sample_t * buf, sox_size_t len);
+typedef size_t(ft_read_fn)
+  (sox_format_t * ft, sox_sample_t * buf, size_t len);
 
 GET_FORMAT(read)
 
 /* Read a stream of some type into SoX's internal buffer format. */
-sox_size_t lsx_rawread(sox_format_t * ft, sox_sample_t * buf, sox_size_t nsamp)
+size_t lsx_rawread(sox_format_t * ft, sox_sample_t * buf, size_t nsamp)
 {
   ft_read_fn * read_buf = read_fn(ft);
 
@@ -171,14 +171,14 @@
   return 0;
 }
 
-typedef sox_size_t(ft_write_fn)
-  (sox_format_t * ft, sox_sample_t const * buf, sox_size_t len);
+typedef size_t(ft_write_fn)
+  (sox_format_t * ft, sox_sample_t const * buf, size_t len);
 
 GET_FORMAT(write)
 
 /* Writes SoX's internal buffer format to buffer of various data types. */
-sox_size_t lsx_rawwrite(
-    sox_format_t * ft, sox_sample_t const * buf, sox_size_t nsamp)
+size_t lsx_rawwrite(
+    sox_format_t * ft, sox_sample_t const * buf, size_t nsamp)
 {
   ft_write_fn * write_buf = write_fn(ft);
 
--- a/src/remix.c
+++ b/src/remix.c
@@ -120,7 +120,7 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
   unsigned i, j, len;
--- a/src/repeat.c
+++ b/src/repeat.c
@@ -24,8 +24,8 @@
 typedef struct {
   FILE * tmp_file;
   int first_drain;
-  sox_size_t total;
-  sox_size_t remaining;
+  size_t total;
+  size_t remaining;
   int repeats;
 } priv_t;
 
@@ -51,7 +51,7 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
   if (fwrite(ibuf, sizeof(*ibuf), *isamp, p->tmp_file) != *isamp) {
@@ -62,13 +62,13 @@
   return SOX_SUCCESS;
 }
 
-static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
+static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
   size_t read = 0;
   sox_sample_t *buf;
-  sox_size_t samp;
-  sox_size_t done;
+  size_t samp;
+  size_t done;
 
   if (p->first_drain == 1) {
     p->first_drain = 0;
--- a/src/resample.c
+++ b/src/resample.c
@@ -193,7 +193,7 @@
 
   r->Factor = effp->out_signal.rate / effp->in_signal.rate;
 
-  gcdrate = lsx_gcd((long) effp->in_signal.rate, (long) effp->out_signal.rate);
+  gcdrate = lsx_gcd((unsigned) effp->in_signal.rate, (unsigned) effp->out_signal.rate);
   r->a = effp->in_signal.rate / gcdrate;
   r->b = effp->out_signal.rate / gcdrate;
 
@@ -266,12 +266,12 @@
  * Return number of samples processed.
  */
 static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                     sox_size_t *isamp, sox_size_t *osamp)
+                     size_t *isamp, size_t *osamp)
 {
         priv_t * r = (priv_t *) effp->priv;
         long i, last, Nout, Nx, Nproc;
 
-        sox_debug_more("Xp %li, Xread %li, isamp %d, ",r->Xp, r->Xread,*isamp);
+        sox_debug_more("Xp %li, Xread %li, isamp %lu, ",r->Xp, r->Xread,(unsigned long)*isamp);
 
         /* constrain amount we actually process */
         Nproc = r->Xsize - r->Xp;
@@ -370,7 +370,7 @@
 /*
  * Process tail of input samples.
  */
-static int drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
         priv_t * r = (priv_t *) effp->priv;
         long isamp_res, osamp_res;
@@ -384,20 +384,20 @@
         osamp_res = *osamp;
         Obuf = obuf;
         while (isamp_res>0 && osamp_res>0) {
-                sox_size_t Isamp, Osamp;
+                size_t Isamp, Osamp;
                 Isamp = isamp_res;
                 Osamp = osamp_res;
                 rc = flow(effp, NULL, Obuf, &Isamp, &Osamp);
                 if (rc)
                     return rc;
-                sox_debug("DRAIN isamp,osamp  (%li,%li) -> (%d,%d)",
-                         isamp_res,osamp_res,Isamp,Osamp);
+                sox_debug("DRAIN isamp,osamp  (%li,%li) -> (%lu,%lu)",
+                         isamp_res,osamp_res,(unsigned long)Isamp,(unsigned long)Osamp);
                 Obuf += Osamp;
                 osamp_res -= Osamp;
                 isamp_res -= Isamp;
         }
         *osamp -= osamp_res;
-        sox_debug("DRAIN osamp %d", *osamp);
+        sox_debug("DRAIN osamp %lu", (unsigned long)*osamp);
         if (isamp_res)
                 sox_warn("drain overran obuf by %li", isamp_res);
         /* FIXME: This is very picky.  IF obuf is not big enough to
@@ -512,9 +512,9 @@
       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 */
+      v = (*prodUD)(r->Imp, Xp, -1L, T, r->dhb, r->Xh); /* needs Np*Nmult in 31 bits */
       /* Future inner product: */
-      v += (*prodUD)(r->Imp, Xp+1, 1, (1.0-T), r->dhb, r->Xh); /* prefer even total */
+      v += (*prodUD)(r->Imp, Xp+1, 1L, (1.0-T), r->dhb, r->Xh); /* prefer even total */
 
       if (Factor < 1) v *= Factor;
       *Y++ = v;              /* Deposit output */
@@ -566,9 +566,9 @@
         Xp = r->X + (time/b);      /* Ptr to current input sample */
 
         /* Past  inner product: */
-        v = prodEX(r->Imp, Xp, -1, T, b, r->Xh);
+        v = prodEX(r->Imp, Xp, -1L, T, b, r->Xh);
         /* Future inner product: */
-        v += prodEX(r->Imp, Xp+1, 1, b-T, b, r->Xh);
+        v += prodEX(r->Imp, Xp+1, 1L, b-T, b, r->Xh);
 
         if (Factor < 1) v *= Factor;
         *Y++ = v;             /* Deposit output */
--- a/src/reverb.c
+++ b/src/reverb.c
@@ -215,10 +215,10 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-                sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+                sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t c, i, w, len = min(*isamp / p->ichannels, *osamp / p->ochannels);
+  size_t c, i, w, len = min(*isamp / p->ichannels, *osamp / p->ochannels);
 
   *isamp = len * p->ichannels, *osamp = len * p->ochannels;
   for (c = 0; c < p->ichannels; ++c)
--- a/src/reverse.c
+++ b/src/reverse.c
@@ -31,7 +31,7 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
   if (fwrite(ibuf, sizeof(*ibuf), *isamp, p->tmp_file) != *isamp) {
@@ -42,7 +42,7 @@
   return SOX_SUCCESS;
 }
 
-static int drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
   size_t i, j;
--- a/src/sf.c
+++ b/src/sf.c
@@ -99,7 +99,7 @@
       return SOX_EOF;
     if (code == SF_COMMENT) {
       char * buf = lsx_calloc(1, (size_t)size + 1); /* +1 ensures null-terminated */
-      if (lsx_readchars(ft, buf, size) != SOX_SUCCESS) {
+      if (lsx_readchars(ft, buf, (size_t) size) != SOX_SUCCESS) {
         free(buf);
         return SOX_EOF;
       }
@@ -106,10 +106,10 @@
       sox_append_comments(&ft->oob.comments, buf);
       free(buf);
     }
-    else if (lsx_skipbytes(ft, size))
+    else if (lsx_skipbytes(ft, (size_t) size))
       return SOX_EOF;
   } while (code);
-  if (lsx_skipbytes(ft, FIXED_HDR - (sox_size_t)lsx_tell(ft)))
+  if (lsx_skipbytes(ft, FIXED_HDR - (size_t)lsx_tell(ft)))
     return SOX_EOF;
 
   return lsx_check_read_params(ft, channels, rate, encoding, bits_per_sample, (off_t)0);
@@ -127,7 +127,7 @@
   ||lsx_writedw(ft, ft->signal.channels)
   ||lsx_writedw(ft, ft_enc(ft->encoding.bits_per_sample, ft->encoding.encoding))
   ||lsx_writew(ft, SF_COMMENT)
-  ||lsx_writew(ft, info_len)
+  ||lsx_writew(ft, (unsigned) info_len)
   ||lsx_writechars(ft, comment, len)
   ||lsx_padbytes(ft, FIXED_HDR - 20 - len);
   free(comment);
--- a/src/silence.c
+++ b/src/silence.c
@@ -29,32 +29,32 @@
     char        start;
     int         start_periods;
     char        *start_duration_str;
-    sox_size_t   start_duration;
+    size_t   start_duration;
     double      start_threshold;
     char        start_unit; /* "d" for decibels or "%" for percent. */
     int         restart;
 
     sox_sample_t *start_holdoff;
-    sox_size_t   start_holdoff_offset;
-    sox_size_t   start_holdoff_end;
+    size_t   start_holdoff_offset;
+    size_t   start_holdoff_end;
     int         start_found_periods;
 
     char        stop;
     int         stop_periods;
     char        *stop_duration_str;
-    sox_size_t   stop_duration;
+    size_t   stop_duration;
     double      stop_threshold;
     char        stop_unit;
 
     sox_sample_t *stop_holdoff;
-    sox_size_t   stop_holdoff_offset;
-    sox_size_t   stop_holdoff_end;
+    size_t   stop_holdoff_offset;
+    size_t   stop_holdoff_end;
     int         stop_found_periods;
 
     double      *window;
     double      *window_current;
     double      *window_end;
-    sox_size_t   window_size;
+    size_t   window_size;
     double      rms_sum;
 
     char        leave_silence;
@@ -288,7 +288,7 @@
             break;
         case 32:
             value = SOX_SAMPLE_TO_SIGNED_32BIT(value,);
-            ratio = (double)labs(value) / (double)SOX_INT32_MAX;
+            ratio = (double)abs(value) / (double)SOX_INT32_MAX;
             break;
         default:
             ratio = 0;
@@ -334,12 +334,12 @@
 /* Process signed long samples from ibuf to obuf. */
 /* Return number of samples processed in isamp and osamp. */
 static int sox_silence_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                    sox_size_t *isamp, sox_size_t *osamp)
+                    size_t *isamp, size_t *osamp)
 {
     priv_t * silence = (priv_t *) effp->priv;
     int threshold;
-    sox_size_t i, j;
-    sox_size_t nrOfTicks, nrOfInSamplesRead, nrOfOutSamplesWritten;
+    size_t i, j;
+    size_t nrOfTicks, nrOfInSamplesRead, nrOfOutSamplesWritten;
 
     nrOfInSamplesRead = 0;
     nrOfOutSamplesWritten = 0;
@@ -620,11 +620,11 @@
         return (SOX_SUCCESS);
 }
 
-static int sox_silence_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_silence_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
     priv_t * silence = (priv_t *) effp->priv;
-    sox_size_t i;
-    sox_size_t nrOfTicks, nrOfOutSamplesWritten = 0;
+    size_t i;
+    size_t nrOfTicks, nrOfOutSamplesWritten = 0;
 
     /* Only if in flush mode will there be possible samples to write
      * out during drain() call.
--- a/src/skeleff.c
+++ b/src/skeleff.c
@@ -58,10 +58,10 @@
  * Return number of samples processed.
  */
 static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                           sox_size_t *isamp, sox_size_t *osamp)
+                           size_t *isamp, size_t *osamp)
 {
   priv_t * UNUSED p = (priv_t *)effp->priv;
-  sox_size_t len, done;
+  size_t len, done;
 
   switch (effp->out_signal.channels) {
   case 2:
@@ -90,7 +90,7 @@
 /*
  * Drain out remaining samples if the effect generates any.
  */
-static int drain(sox_effect_t UNUSED * effp, sox_sample_t UNUSED *obuf, sox_size_t *osamp)
+static int drain(sox_effect_t UNUSED * effp, sox_sample_t UNUSED *obuf, size_t *osamp)
 {
   *osamp = 0;
   /* Return SOX_EOF when drain
--- a/src/skelform.c
+++ b/src/skelform.c
@@ -23,7 +23,7 @@
 
 /* Private data for SKEL file */
 typedef struct {
-  sox_size_t remaining_samples;
+  size_t remaining_samples;
 } priv_t;
 
 /* Note that if any of your methods doesn't need to do anything, you
@@ -39,7 +39,7 @@
 static int startread(sox_format_t * ft)
 {
   priv_t * sk = (priv_t *)ft->priv;
-  sox_size_t samples_in_file;
+  size_t samples_in_file;
 
   /* If you need to seek around the input file. */
   if (!ft->seekable) {
@@ -75,10 +75,10 @@
  * Read up to len samples of type sox_sample_t from file into buf[].
  * Return number of samples read, or 0 if at end of file.
  */
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
   priv_t * UNUSED sk = (priv_t *)ft->priv;
-  sox_size_t done;
+  size_t done;
   unsigned char sample;
 
   for (done = 0; done < len; done++) {
@@ -150,10 +150,10 @@
  * Write len samples of type sox_sample_t from buf[] to file.
  * Return number of samples written.
  */
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
   priv_t * sk = (priv_t *)ft->priv;
-  sox_size_t done = 0;
+  size_t done = 0;
 
   (void)sk;
   switch (ft->encoding.bits_per_sample) {
@@ -183,7 +183,7 @@
   return SOX_SUCCESS;
 }
 
-static int seek(sox_format_t UNUSED * ft, sox_size_t UNUSED offset)
+static int seek(sox_format_t UNUSED * ft, size_t UNUSED offset)
 {
   /* Seek relative to current position. */
   return SOX_SUCCESS;
--- a/src/smp.c
+++ b/src/smp.c
@@ -22,7 +22,7 @@
 #define NAMELEN    30           /* Size of Samplevision name */
 #define COMMENTLEN 60           /* Size of Samplevision comment, not shared */
 #define MIDI_UNITY 60           /* MIDI note number to play sample at unity */
-#define MARKERLEN  10           /* Size of Marker name */
+#define MARKERLEN  (size_t)10           /* Size of Marker name */
 
 /* The header preceeding the sample data */
 struct smpheader {
@@ -61,7 +61,7 @@
 /* Private data for SMP file */
 typedef struct {
   uint32_t NoOfSamps;           /* Sample data count in words */
-  sox_size_t dataStart;
+  size_t dataStart;
   /* comment memory resides in private data because it's small */
   char comment[COMMENTLEN + NAMELEN + 3];
 } priv_t;
@@ -168,9 +168,9 @@
         return(SOX_SUCCESS);
 }
 
-static int sox_smpseek(sox_format_t * ft, sox_size_t offset)
+static int sox_smpseek(sox_format_t * ft, size_t offset)
 {
-    sox_size_t new_offset, channel_block, alignment;
+    size_t new_offset, channel_block, alignment;
     priv_t * smp = (priv_t *) ft->priv;
 
     new_offset = offset * (ft->encoding.bits_per_sample >> 3);
@@ -185,7 +185,7 @@
         new_offset += (channel_block - alignment);
     new_offset += smp->dataStart;
 
-    ft->sox_errno = lsx_seeki(ft, (sox_ssize_t)new_offset, SEEK_SET);
+    ft->sox_errno = lsx_seeki(ft, (ptrdiff_t)new_offset, SEEK_SET);
 
     if( ft->sox_errno == SOX_SUCCESS )
         smp->NoOfSamps = ft->signal.length - (new_offset / (ft->encoding.bits_per_sample >> 3));
@@ -203,7 +203,7 @@
 {
         priv_t * smp = (priv_t *) ft->priv;
         int namelen, commentlen;
-        sox_size_t samplestart, i;
+        size_t samplestart, i;
         struct smpheader header;
         struct smptrailer trailer;
 
@@ -220,12 +220,12 @@
                 lsx_fail_errno(ft,SOX_EHDR,"unexpected EOF in SMP header");
                 return(SOX_EOF);
         }
-        if (strncmp(header.Id, SVmagic, 17) != 0)
+        if (strncmp(header.Id, SVmagic, (size_t)17) != 0)
         {
                 lsx_fail_errno(ft,SOX_EHDR,"SMP header does not begin with magic word %s", SVmagic);
                 return(SOX_EOF);
         }
-        if (strncmp(header.version, SVvers, 4) != 0)
+        if (strncmp(header.version, SVvers, (size_t)4) != 0)
         {
                 lsx_fail_errno(ft,SOX_EHDR,"SMP header is not version %s", SVvers);
                 return(SOX_EOF);
@@ -251,7 +251,7 @@
 
         /* seek from the current position (the start of sample data) by */
         /* NoOfSamps * sizeof(int16_t) */
-        if (lsx_seeki(ft, (sox_ssize_t)(smp->NoOfSamps * 2), 1) == -1)
+        if (lsx_seeki(ft, (ptrdiff_t)(smp->NoOfSamps * 2), 1) == -1)
         {
                 lsx_fail_errno(ft,errno,"SMP unable to seek to trailer");
                 return(SOX_EOF);
@@ -263,7 +263,7 @@
         }
 
         /* seek back to the beginning of the data */
-        if (lsx_seeki(ft, (sox_ssize_t)samplestart, 0) == -1)
+        if (lsx_seeki(ft, (ptrdiff_t)samplestart, 0) == -1)
         {
                 lsx_fail_errno(ft,errno,"SMP unable to seek back to start of sample data");
                 return(SOX_EOF);
@@ -278,7 +278,7 @@
 
         sox_report("SampleVision trailer:");
         for(i = 0; i < 8; i++) if (1 || trailer.loops[i].count) {
-                sox_report("Loop %d: start: %6d", i, trailer.loops[i].start);
+                sox_report("Loop %lu: start: %6d", (unsigned long)i, trailer.loops[i].start);
                 sox_report(" end:   %6d", trailer.loops[i].end);
                 sox_report(" count: %6d", trailer.loops[i].count);
                 switch(trailer.loops[i].type) {
@@ -316,11 +316,11 @@
  * Place in buf[].
  * Return number of samples read.
  */
-static sox_size_t sox_smpread(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t sox_smpread(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
         priv_t * smp = (priv_t *) ft->priv;
         unsigned short datum;
-        sox_size_t done = 0;
+        size_t done = 0;
 
         for(; done < len && smp->NoOfSamps; done++, smp->NoOfSamps--) {
                 lsx_readw(ft, &datum);
@@ -361,11 +361,11 @@
         return(SOX_SUCCESS);
 }
 
-static sox_size_t sox_smpwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+static size_t sox_smpwrite(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
         priv_t * smp = (priv_t *) ft->priv;
         int datum;
-        sox_size_t done = 0;
+        size_t done = 0;
 
         while(done < len) {
                 datum = (int) SOX_SAMPLE_TO_SIGNED_16BIT(*buf++, ft->clips);
@@ -385,7 +385,7 @@
         /* Assign the trailer data */
         settrailer(ft, &trailer, ft->signal.rate);
         writetrailer(ft, &trailer);
-        if (lsx_seeki(ft, 112, 0) == -1)
+        if (lsx_seeki(ft, (size_t)112, 0) == -1)
         {
                 lsx_fail_errno(ft,errno,"SMP unable to seek back to save size");
                 return(SOX_EOF);
--- a/src/sndfile.c
+++ b/src/sndfile.c
@@ -57,10 +57,10 @@
     if (!strncmp(sf->log_buffer_ptr, warning_prefix, strlen(warning_prefix))) {
       sf->log_buffer_ptr += strlen(warning_prefix);
       sox_warn("`%s': %.*s",
-          ft->filename, end - sf->log_buffer_ptr, sf->log_buffer_ptr);
+          ft->filename, (int)(end - sf->log_buffer_ptr), sf->log_buffer_ptr);
     } else
       sox_debug("`%s': %.*s",
-          ft->filename, end - sf->log_buffer_ptr, sf->log_buffer_ptr);
+          ft->filename, (int)(end - sf->log_buffer_ptr), sf->log_buffer_ptr);
     sf->log_buffer_ptr = end;
     if (*sf->log_buffer_ptr == '\n')
       ++sf->log_buffer_ptr;
@@ -185,7 +185,7 @@
 static int name_to_format(const char *name)
 {
   int k;
-#define FILE_TYPE_BUFLEN 15
+#define FILE_TYPE_BUFLEN (size_t)15
   char buffer[FILE_TYPE_BUFLEN + 1], *cptr;
 
   if ((cptr = strrchr(name, '.')) != NULL) {
@@ -209,7 +209,7 @@
 {
   priv_t * sf = (priv_t *)ft->priv;
   int subtype = ft_enc(ft->encoding.bits_per_sample? ft->encoding.bits_per_sample : ft->signal.precision, ft->encoding.encoding);
-  sf->log_buffer_ptr = sf->log_buffer = lsx_malloc(LOG_MAX);
+  sf->log_buffer_ptr = sf->log_buffer = lsx_malloc((size_t)LOG_MAX);
   sf->sf_info = lsx_calloc(1, sizeof(SF_INFO));
 
   /* Copy format info */
@@ -299,11 +299,11 @@
  * Read up to len samples of type sox_sample_t from file into buf[].
  * Return number of samples read.
  */
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
   priv_t * sf = (priv_t *)ft->priv;
   /* FIXME: We assume int == sox_sample_t here */
-  return (sox_size_t)sf_read_int(sf->sf_file, (int *)buf, (sf_count_t)len);
+  return (size_t)sf_read_int(sf->sf_file, (int *)buf, (sf_count_t)len);
 }
 
 /*
@@ -327,10 +327,10 @@
     SF_FORMAT_INFO format_info;
     int i, count;
 
-    sf_command(sf->sf_file, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof(int));
+    sf_command(sf->sf_file, SFC_GET_SIMPLE_FORMAT_COUNT, &count, (int) sizeof(int));
     for (i = 0; i < count; i++) {
       format_info.format = i;
-      sf_command(sf->sf_file, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof(format_info));
+      sf_command(sf->sf_file, SFC_GET_SIMPLE_FORMAT, &format_info, (int) sizeof(format_info));
       if ((format_info.format & SF_FORMAT_TYPEMASK) == (sf->sf_info->format & SF_FORMAT_TYPEMASK)) {
         sf->sf_info->format = format_info.format;
         /* FIXME: Print out exactly what we chose, needs sndfile ->
@@ -365,11 +365,11 @@
  * Write len samples of type sox_sample_t from buf[] to file.
  * Return number of samples written.
  */
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
   priv_t * sf = (priv_t *)ft->priv;
   /* FIXME: We assume int == sox_sample_t here */
-  return (sox_size_t)sf_write_int(sf->sf_file, (int *)buf, (sf_count_t)len);
+  return (size_t)sf_write_int(sf->sf_file, (int *)buf, (sf_count_t)len);
 }
 
 /*
@@ -384,7 +384,7 @@
   return SOX_SUCCESS;
 }
 
-static int seek(sox_format_t * ft, sox_size_t offset)
+static int seek(sox_format_t * ft, size_t offset)
 {
   priv_t * sf = (priv_t *)ft->priv;
   sf_seek(sf->sf_file, (sf_count_t)(offset / ft->signal.channels), SEEK_CUR);
--- a/src/sounder.c
+++ b/src/sounder.c
@@ -22,7 +22,7 @@
 {
   uint16_t type, rate;
 
-  if (lsx_readw(ft, &type) || lsx_readw(ft, &rate) || lsx_skipbytes(ft, 4))
+  if (lsx_readw(ft, &type) || lsx_readw(ft, &rate) || lsx_skipbytes(ft, (size_t) 4))
     return SOX_EOF;
   if (type) {
     lsx_fail_errno(ft, SOX_EHDR, "invalid Sounder header");
--- a/src/soundtool.c
+++ b/src/soundtool.c
@@ -20,7 +20,7 @@
 #include <string.h>
 
 static char const ID1[6] = "SOUND\x1a";
-#define text_field_len 96  /* Includes null-terminator */
+#define text_field_len (size_t)96  /* Includes null-terminator */
 
 static int start_read(sox_format_t * ft)
 {
@@ -29,8 +29,8 @@
   uint16_t rate;
 
   if (lsx_readchars(ft, id1, sizeof(ID1)) ||
-      lsx_skipbytes(ft, 10) || lsx_readdw(ft, &nsamples) ||
-      lsx_readw(ft, &rate) || lsx_skipbytes(ft, 6) ||
+      lsx_skipbytes(ft, (size_t) 10) || lsx_readdw(ft, &nsamples) ||
+      lsx_readw(ft, &rate) || lsx_skipbytes(ft, (size_t) 6) ||
       lsx_readchars(ft, comments, text_field_len))
     return SOX_EOF;
   if (memcmp(ID1, id1, sizeof(id1))) {
@@ -46,7 +46,7 @@
 {
   char * comment = sox_cat_comments(ft->oob.comments);
   char text_buf[text_field_len];
-  sox_size_t length = ft->olength? ft->olength:ft->signal.length;
+  size_t length = ft->olength? ft->olength:ft->signal.length;
 
   memset(text_buf, 0, sizeof(text_buf));
   strncpy(text_buf, comment, text_field_len - 1);
@@ -53,9 +53,9 @@
   free(comment);
   return lsx_writechars(ft, ID1, sizeof(ID1))
       || lsx_writew  (ft, 0)      /* GSound: not used */
-      || lsx_writedw (ft, length) /* length of complete sample */
+      || lsx_writedw (ft, (unsigned) length) /* length of complete sample */
       || lsx_writedw (ft, 0)      /* first byte to play from sample */
-      || lsx_writedw (ft, length) /* first byte NOT to play from sample */
+      || lsx_writedw (ft, (unsigned) length) /* first byte NOT to play from sample */
       || lsx_writew  (ft, min(65535, (unsigned)(ft->signal.rate + .5)))
       || lsx_writew  (ft, 0)      /* sample size/type */
       || lsx_writew  (ft, 10)     /* speaker driver volume */
--- a/src/sox.c
+++ b/src/sox.c
@@ -105,7 +105,7 @@
   sox_oob_t oob;
 
   sox_format_t * ft;  /* libSoX file descriptor */
-  sox_size_t volume_clips;
+  size_t volume_clips;
   rg_mode replay_gain_mode;
 } file_t;
 
@@ -139,7 +139,7 @@
 
 static sox_signalinfo_t combiner_signal, ofile_signal_options;
 static sox_encodinginfo_t combiner_encoding, ofile_encoding_options;
-static sox_size_t mixing_clips = 0;
+static size_t mixing_clips = 0;
 static size_t current_input = 0;
 static unsigned long input_wide_samples = 0;
 static unsigned long read_wide_samples = 0;
@@ -196,7 +196,7 @@
   FILE * const output = sox_mode == sox_soxi? stdout : stderr;
   char const * text;
   char buffer[30];
-  sox_size_t ws = ft->signal.length / ft->signal.channels;
+  size_t ws = ft->signal.length / ft->signal.channels;
   (void)full;
 
   fprintf(output, "\n");
@@ -278,12 +278,12 @@
     ft->signal.precision);
 
   if (ft->signal.length && ft->signal.channels && ft->signal.rate) {
-    sox_size_t ws = ft->signal.length / ft->signal.channels;
+    size_t ws = ft->signal.length / ft->signal.channels;
     fprintf(output,
-      "Duration       : %s = %u samples %c %g CDDA sectors\n",
+      "Duration       : %s = %lu samples %c %g CDDA sectors\n",
       str_time((double)ws / ft->signal.rate),
-      ws, "~="[ft->signal.rate == 44100],
-      (double)ws/ ft->signal.rate * 44100 / 588);
+      (unsigned long)ws, "~="[ft->signal.rate == 44100],
+      (double)ws / ft->signal.rate * 44100 / 588);
   }
   if (ft->encoding.encoding) {
     char buffer[20] = {'\0'};
@@ -367,9 +367,9 @@
 
 /* Read up to max `wide' samples.  A wide sample contains one sample per channel
  * from the input audio. */
-static sox_size_t sox_read_wide(sox_format_t * ft, sox_sample_t * buf, sox_size_t max)
+static size_t sox_read_wide(sox_format_t * ft, sox_sample_t * buf, size_t max)
 {
-  sox_size_t len = max / combiner_signal.channels;
+  size_t len = max / combiner_signal.channels;
   len = sox_read(ft, buf, len * ft->signal.channels) / ft->signal.channels;
   if (!len && ft->sox_errno)
     display_error(ft);
@@ -376,9 +376,9 @@
   return len;
 }
 
-static void balance_input(sox_sample_t * buf, sox_size_t ws, file_t * f)
+static void balance_input(sox_sample_t * buf, size_t ws, file_t * f)
 {
-  sox_size_t s = ws * f->ft->signal.channels;
+  size_t s = ws * f->ft->signal.channels;
 
   if (f->volume != 1)
     while (s--) {
@@ -396,7 +396,7 @@
 static int combiner_start(sox_effect_t *effp)
 {
   input_combiner_t * z = (input_combiner_t *) effp->priv;
-  sox_size_t ws, i;
+  size_t ws, i;
 
   if (is_serial(combine_method))
     progress_to_next_input_file(files[current_input]);
@@ -412,7 +412,7 @@
   return SOX_SUCCESS;
 }
 
-static sox_bool can_segue(sox_size_t i)
+static sox_bool can_segue(size_t i)
 {
   return
     files[i]->ft->signal.channels == files[i - 1]->ft->signal.channels &&
@@ -419,12 +419,12 @@
     files[i]->ft->signal.rate     == files[i - 1]->ft->signal.rate;
 }
 
-static int combiner_drain(sox_effect_t *effp, sox_sample_t * obuf, sox_size_t * osamp)
+static int combiner_drain(sox_effect_t *effp, sox_sample_t * obuf, size_t * osamp)
 {
   input_combiner_t * z = (input_combiner_t *) effp->priv;
-  sox_size_t ws, s, i;
-  sox_size_t ilen[MAX_INPUT_FILES];
-  sox_size_t olen = 0;
+  size_t ws, s, i;
+  size_t ilen[MAX_INPUT_FILES];
+  size_t olen = 0;
 
   if (is_serial(combine_method)) while (sox_true) {
     if (!user_skip)
@@ -485,7 +485,7 @@
 static int combiner_stop(sox_effect_t *effp)
 {
   input_combiner_t * z = (input_combiner_t *) effp->priv;
-  sox_size_t i;
+  size_t i;
 
   if (is_parallel(combine_method))
     /* Free input buffers now that they are not used */
@@ -505,7 +505,7 @@
 }
 
 static int output_flow(sox_effect_t *effp, sox_sample_t const * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   size_t len;
 
@@ -610,10 +610,10 @@
   }
 }
 
-static sox_size_t total_clips(void)
+static size_t total_clips(void)
 {
   unsigned i;
-  sox_size_t clips = 0;
+  size_t clips = 0;
   for (i = 0; i < file_count; ++i)
     clips += files[i]->ft->clips + files[i]->volume_clips;
   return clips + mixing_clips + sox_effects_clips(&ofile_effects_chain);
@@ -713,7 +713,7 @@
    * managable chunks.  */
   if (input_count == 1 && ofile_effects_chain.length > 1 && strcmp(ofile_effects_chain.effects[1][0].handler.name, "trim") == 0) {
     if (files[0]->ft->handler.seek && files[0]->ft->seekable){
-      sox_size_t offset = sox_trim_get_start(&ofile_effects_chain.effects[1][0]);
+      size_t offset = sox_trim_get_start(&ofile_effects_chain.effects[1][0]);
       if (offset && sox_seek(files[0]->ft, offset, SOX_SEEK_SET) == SOX_SUCCESS) {
         read_wide_samples = offset / files[0]->ft->signal.channels;
         /* Assuming a failed seek stayed where it was.  If the seek worked then
@@ -742,7 +742,7 @@
   return c == 'y' || c == 'Y';
 }
 
-static char *fndup_with_count(const char *filename, int count)
+static char *fndup_with_count(const char *filename, size_t count)
 {
     char *expand_fn, *efn;
     const char *fn, *ext, *end;
@@ -750,7 +750,7 @@
 
     fn = filename;
 
-    efn = expand_fn = malloc(1024);
+    efn = expand_fn = malloc((size_t)1024);
 
     /* Find extension in case user didn't specify a substitution
      * marker.
@@ -780,7 +780,7 @@
     {
         efn -= strlen (ext);
 
-        sprintf(efn, "%04d", count);
+        sprintf(efn, "%04lu", (unsigned long)count);
         efn = efn + 4;
         strcat(efn, ext);
     }
@@ -854,7 +854,7 @@
 static void calculate_combiner_and_output_signal_parameters(void)
 {
   sox_bool known_length = combine_method != sox_sequence;
-  sox_size_t i, olen = 0;
+  size_t i, olen = 0;
 
   /* Set the combiner output signal attributes to those of the 1st/next input
    * file.  If we are in sox_sequence mode then we don't need to check the
@@ -869,11 +869,11 @@
     if (!current_input) for (i = 0; i < input_count; i++)
       report_file_info(files[i]);
   } else {
-    sox_size_t total_channels = 0;
-    sox_size_t min_channels = SOX_SIZE_MAX;
-    sox_size_t max_channels = 0;
-    sox_size_t min_rate = SOX_SIZE_MAX;
-    sox_size_t max_rate = 0;
+    size_t total_channels = 0;
+    size_t min_channels = SOX_SIZE_MAX;
+    size_t max_channels = 0;
+    size_t min_rate = SOX_SIZE_MAX;
+    size_t max_rate = 0;
 
     /* Report all input files and gather info on differing rates & numbers of
      * channels, and on the resulting output audio length: */
@@ -941,7 +941,7 @@
 
   if (!known_length)
     olen = 0;
-  ofile->signal.length = (sox_size_t)(olen * ofile->signal.channels * ofile->signal.rate / combiner_signal.rate + .5);
+  ofile->signal.length = (size_t)(olen * ofile->signal.channels * ofile->signal.rate / combiner_signal.rate + .5);
 }
 
 static void set_combiner_and_output_encoding_parameters(void)
@@ -1031,9 +1031,12 @@
 #elif defined __SUNPRO_C
     fprintf(file, "sun c: %x\n", __SUNPRO_C);
 #endif
-    fprintf(file, "arch:  %u%u%u%u %u%u %u%u %c\n", sizeof(char), sizeof(short),
-        sizeof(long), sizeof(off_t), sizeof(float), sizeof(double),
-        sizeof(int *), sizeof(int (*)(void)), "LB"[MACHINE_IS_BIGENDIAN]);
+    fprintf(file, "arch:  %lu%lu%lu%lu %lu%lu %lu%lu %c\n",
+        (unsigned long)sizeof(char), (unsigned long)sizeof(short),
+        (unsigned long)sizeof(long), (unsigned long)sizeof(off_t),
+        (unsigned long)sizeof(float), (unsigned long)sizeof(double),
+        (unsigned long)sizeof(int *), (unsigned long)sizeof(int (*)(void)),
+        "LB"[MACHINE_IS_BIGENDIAN]);
   }
 }
 
@@ -1364,7 +1367,7 @@
 {
   enum_item const * p = find_enum_text(optarg, items);
   if (p == NULL) {
-    unsigned len = 1;
+    size_t len = 1;
     char * set = lsx_malloc(len);
     *set = 0;
     for (p = items; p->text; ++p) {
@@ -1699,7 +1702,7 @@
 
 static int soxi1(soxi_t * type, char * filename)
 {
-  sox_size_t ws;
+  size_t ws;
   sox_format_t * ft = sox_open_read(filename, NULL, NULL, NULL);
 
   if (!ft)
@@ -1708,7 +1711,7 @@
   switch (*type) {
     case rate: printf("%g\n", ft->signal.rate); break;
     case channels: printf("%u\n", ft->signal.channels); break;
-    case samples: printf("%u\n", ws); break;
+    case samples: printf("%lu\n", (unsigned long)ws); break;
     case duration: printf("%s\n", str_time((double)ws / max(ft->signal.rate, 1))); break;
     case bits: printf("%u\n", ft->encoding.bits_per_sample); break;
     case encoding: printf("%s\n", sox_encodings_info[ft->encoding.encoding].desc); break;
@@ -1945,19 +1948,19 @@
 
   for (i = 0; i < file_count; ++i)
     if (files[i]->ft->clips != 0)
-      sox_warn(i < input_count?"%s: input clipped %u samples" :
-                              "%s: output clipped %u samples; decrease volume?",
+      sox_warn(i < input_count?"%s: input clipped %lu samples" :
+                              "%s: output clipped %lu samples; decrease volume?",
           (files[i]->ft->handler.flags & SOX_FILE_DEVICE)?
                        files[i]->ft->handler.names[0] : files[i]->ft->filename,
-          files[i]->ft->clips);
+          (unsigned long)files[i]->ft->clips);
 
   if (mixing_clips > 0)
-    sox_warn("mix-combining clipped %u samples; decrease volume?", mixing_clips);
+    sox_warn("mix-combining clipped %lu samples; decrease volume?", (unsigned long)mixing_clips);
 
   for (i = 0; i < file_count; i++)
     if (files[i]->volume_clips > 0)
-      sox_warn("%s: balancing clipped %u samples; decrease volume?",
-          files[i]->filename, files[i]->volume_clips);
+      sox_warn("%s: balancing clipped %lu samples; decrease volume?",
+          files[i]->filename, (unsigned long)files[i]->volume_clips);
 
   if (show_progress) {
     if (user_abort)
--- a/src/sox.h
+++ b/src/sox.h
@@ -166,9 +166,7 @@
 
 
 #include <stddef.h>
-#define sox_size_t size_t
-#define SOX_SIZE_MAX (sox_size_t)(-sizeof(char))
-#define sox_ssize_t ptrdiff_t
+#define SOX_SIZE_MAX (size_t)(-sizeof(char))
 
 typedef void (*sox_output_message_handler_t)(unsigned level, const char *filename, const char *fmt, va_list ap);
 
@@ -181,7 +179,7 @@
  * to perform file I/O.  It can be useful to pass in similar sized
  * data to get max performance.
  */
-  sox_size_t   bufsiz, input_bufsiz;
+  size_t   bufsiz, input_bufsiz;
 
 /* private: */
   char const * stdin_in_use_by;
@@ -196,7 +194,7 @@
   sox_rate_t       rate;         /* sampling rate */
   unsigned         channels;     /* number of sound channels */
   unsigned         precision;    /* in bits */
-  sox_size_t       length;       /* samples * chans in file; 0 if unknown */
+  size_t       length;       /* samples * chans in file; 0 if unknown */
 } sox_signalinfo_t;
 
 typedef enum {
@@ -273,8 +271,8 @@
 /* Loop parameters */
 
 typedef struct {
-  sox_size_t    start;          /* first sample */
-  sox_size_t    length;         /* length */
+  size_t    start;          /* first sample */
+  size_t    length;         /* length */
   unsigned int  count;          /* number of repeats, 0=forever */
   unsigned char type;           /* 0=no, 1=forward, 2=forward/back */
 } sox_loopinfo_t;
@@ -320,12 +318,12 @@
   char         const * const * names;
   unsigned int flags;
   int          (*startread)(sox_format_t * ft);
-  sox_size_t   (*read)(sox_format_t * ft, sox_sample_t *buf, sox_size_t len);
+  size_t   (*read)(sox_format_t * ft, sox_sample_t *buf, size_t len);
   int          (*stopread)(sox_format_t * ft);
   int          (*startwrite)(sox_format_t * ft);
-  sox_size_t   (*write)(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len);
+  size_t   (*write)(sox_format_t * ft, const sox_sample_t *buf, size_t len);
   int          (*stopwrite)(sox_format_t * ft);
-  int          (*seek)(sox_format_t * ft, sox_size_t offset);
+  int          (*seek)(sox_format_t * ft, size_t offset);
   unsigned     const * write_formats;
   sox_rate_t   const * write_rates;
   size_t       priv_size;
@@ -364,8 +362,8 @@
   sox_oob_t        oob;             /* Out Of Band data */
   sox_bool         seekable;        /* Can seek on this file */
   char             mode;            /* Read or write mode ('r' or 'w') */
-  sox_size_t       olength;         /* Samples * chans written to file */
-  sox_size_t       clips;           /* Incremented if clipping occurs */
+  size_t       olength;         /* Samples * chans written to file */
+  size_t       clips;           /* Incremented if clipping occurs */
   int              sox_errno;       /* Failure error code */
   char             sox_errstr[256]; /* Failure error text */
   FILE             * fp;            /* File stream pointer */
@@ -410,12 +408,12 @@
     char               const * filetype,
     sox_oob_t          const * oob,
     sox_bool           (*overwrite_permitted)(const char *filename));
-sox_size_t sox_read(sox_format_t * ft, sox_sample_t *buf, sox_size_t len);
-sox_size_t sox_write(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len);
+size_t sox_read(sox_format_t * ft, sox_sample_t *buf, size_t len);
+size_t sox_write(sox_format_t * ft, const sox_sample_t *buf, size_t len);
 int sox_close(sox_format_t * ft);
 
 #define SOX_SEEK_SET 0
-int sox_seek(sox_format_t * ft, sox_size_t offset, int whence);
+int sox_seek(sox_format_t * ft, size_t offset, int whence);
 
 sox_format_handler_t const * sox_find_format(char const * name, sox_bool no_dev);
 int sox_gettype(sox_format_t *, sox_bool);
@@ -453,8 +451,8 @@
   int (*getopts)(sox_effect_t * effp, int argc, char *argv[]);
   int (*start)(sox_effect_t * effp);
   int (*flow)(sox_effect_t * effp, const sox_sample_t *ibuf,
-      sox_sample_t *obuf, sox_size_t *isamp, sox_size_t *osamp);
-  int (*drain)(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp);
+      sox_sample_t *obuf, size_t *isamp, size_t *osamp);
+  int (*drain)(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp);
   int (*stop)(sox_effect_t * effp);
   int (*kill)(sox_effect_t * effp);
   size_t       priv_size;
@@ -468,11 +466,11 @@
   sox_encodinginfo_t       const * out_encoding;
   sox_effect_handler_t     handler;
   sox_sample_t             * obuf;        /* output buffer */
-  sox_size_t               obeg, oend;    /* consumed, total length */
-  sox_size_t               imin;          /* minimum input buffer size */
-  sox_size_t               clips;         /* increment if clipping occurs */
-  sox_size_t               flows;         /* 1 if MCHAN, # chans otherwise */
-  sox_size_t               flow;          /* flow # */
+  size_t               obeg, oend;    /* consumed, total length */
+  size_t               imin;          /* minimum input buffer size */
+  size_t               clips;         /* increment if clipping occurs */
+  size_t               flows;         /* 1 if MCHAN, # chans otherwise */
+  size_t               flow;          /* flow # */
   void                     * priv;        /* Effect's private data area */
 };
 
@@ -483,7 +481,7 @@
 
 typedef const sox_effect_handler_t *(*sox_effect_fn_t)(void);
 extern sox_effect_fn_t sox_effect_fns[];
-int sox_effect_set_imin(sox_effect_t * effp, sox_size_t imin);
+int sox_effect_set_imin(sox_effect_t * effp, size_t imin);
 
 struct sox_effects_chain {
   sox_effect_t * effects[SOX_MAX_EFFECTS];
@@ -499,8 +497,8 @@
     sox_encodinginfo_t const * out_enc);
 int sox_add_effect( sox_effects_chain_t * chain, sox_effect_t * effp, sox_signalinfo_t * in, sox_signalinfo_t const * out);
 int sox_flow_effects(sox_effects_chain_t *, int (* callback)(sox_bool all_done));
-sox_size_t sox_effects_clips(sox_effects_chain_t *);
-sox_size_t sox_stop_effect(sox_effect_t *effp);
+size_t sox_effects_clips(sox_effects_chain_t *);
+size_t sox_stop_effect(sox_effect_t *effp);
 void sox_delete_effects(sox_effects_chain_t *);
 
 /* The following routines are unique to the trim effect.
@@ -512,7 +510,7 @@
  * wants to trim and use a sox_seek() operation instead.  After
  * sox_seek()'ing, you should set the trim option to 0.
  */
-sox_size_t sox_trim_get_start(sox_effect_t * effp);
+size_t sox_trim_get_start(sox_effect_t * effp);
 void sox_trim_clear_start(sox_effect_t * effp);
 
 typedef int (* sox_playlist_callback_t)(void *, char *);
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -36,6 +36,14 @@
 assert_static(sizeof(off_t) == _FILE_OFFSET_BITS >> 3, OFF_T_BUILD_PROBLEM);
 #endif
 
+#if defined __GNUC__
+#define FMT_size_t "zu"
+#elif defined _MSC_VER
+#define FMT_size_t "Iu"
+#else
+#define FMT_size_t "lu"
+#endif
+
 /* Digitise one cycle of a wave and store it as
  * a table of samples of a specified data-type.
  */
@@ -43,15 +51,15 @@
     lsx_wave_t wave_type,
     sox_data_t data_type,
     void * table,       /* Really of type indicated by data_type. */
-    uint32_t table_size,/* Number of points on the x-axis. */
+    size_t table_size,  /* Number of points on the x-axis. */
     double min,         /* Minimum value on the y-axis. (e.g. -1) */
     double max,         /* Maximum value on the y-axis. (e.g. +1) */
     double phase);      /* Phase at 1st point; 0..2pi. (e.g. pi/2 for cosine) */
-char const * lsx_parsesamples(sox_rate_t rate, const char *str, sox_size_t *samples, int def);
+char const * lsx_parsesamples(sox_rate_t rate, const char *str, size_t *samples, int def);
 double lsx_parse_frequency(char const * text, char * * end_ptr);
 
-sox_sample_t lsx_gcd(sox_sample_t a, sox_sample_t b);
-sox_sample_t lsx_lcm(sox_sample_t a, sox_sample_t b);
+unsigned lsx_gcd(unsigned a, unsigned b);
+unsigned lsx_lcm(unsigned a, unsigned b);
 
 double bessel_I_0(double x);
 
@@ -74,32 +82,32 @@
 /*------------------------ Implemented in libsoxio.c -------------------------*/
 
 /* Read and write basic data types from "ft" stream. */
-size_t lsx_readbuf(sox_format_t * ft, void *buf, sox_size_t len);
-int lsx_skipbytes(sox_format_t * ft, sox_size_t n);
-int lsx_padbytes(sox_format_t * ft, sox_size_t n);
-size_t lsx_writebuf(sox_format_t * ft, void const *buf, sox_size_t len);
-int lsx_reads(sox_format_t * ft, char *c, sox_size_t len);
+size_t lsx_readbuf(sox_format_t * ft, void *buf, size_t len);
+int lsx_skipbytes(sox_format_t * ft, size_t n);
+int lsx_padbytes(sox_format_t * ft, size_t n);
+size_t lsx_writebuf(sox_format_t * ft, void const *buf, size_t len);
+int lsx_reads(sox_format_t * ft, char *c, size_t len);
 int lsx_writes(sox_format_t * ft, char const * c);
 void lsx_set_signal_defaults(sox_signalinfo_t * signal);
 #define lsx_writechars(ft, chars, len) (lsx_writebuf(ft, chars, len) == len? SOX_SUCCESS : SOX_EOF)
 
-sox_size_t lsx_read_3_buf(sox_format_t * ft, uint24_t *buf, sox_size_t len);
-sox_size_t lsx_read_b_buf(sox_format_t * ft, uint8_t *buf, sox_size_t len);
-sox_size_t lsx_read_df_buf(sox_format_t * ft, double *buf, sox_size_t len);
-sox_size_t lsx_read_dw_buf(sox_format_t * ft, uint32_t *buf, sox_size_t len);
-sox_size_t lsx_read_f_buf(sox_format_t * ft, float *buf, sox_size_t len);
-sox_size_t lsx_read_w_buf(sox_format_t * ft, uint16_t *buf, sox_size_t len);
+size_t lsx_read_3_buf(sox_format_t * ft, uint24_t *buf, size_t len);
+size_t lsx_read_b_buf(sox_format_t * ft, uint8_t *buf, size_t len);
+size_t lsx_read_df_buf(sox_format_t * ft, double *buf, size_t len);
+size_t lsx_read_dw_buf(sox_format_t * ft, uint32_t *buf, size_t len);
+size_t lsx_read_f_buf(sox_format_t * ft, float *buf, size_t len);
+size_t lsx_read_w_buf(sox_format_t * ft, uint16_t *buf, size_t len);
 
-sox_size_t lsx_write_3_buf(sox_format_t * ft, uint24_t *buf, sox_size_t len);
-sox_size_t lsx_write_b_buf(sox_format_t * ft, uint8_t *buf, sox_size_t len);
-sox_size_t lsx_write_df_buf(sox_format_t * ft, double *buf, sox_size_t len);
-sox_size_t lsx_write_dw_buf(sox_format_t * ft, uint32_t *buf, sox_size_t len);
-sox_size_t lsx_write_f_buf(sox_format_t * ft, float *buf, sox_size_t len);
-sox_size_t lsx_write_w_buf(sox_format_t * ft, uint16_t *buf, sox_size_t len);
+size_t lsx_write_3_buf(sox_format_t * ft, uint24_t *buf, size_t len);
+size_t lsx_write_b_buf(sox_format_t * ft, uint8_t *buf, size_t len);
+size_t lsx_write_df_buf(sox_format_t * ft, double *buf, size_t len);
+size_t lsx_write_dw_buf(sox_format_t * ft, uint32_t *buf, size_t len);
+size_t lsx_write_f_buf(sox_format_t * ft, float *buf, size_t len);
+size_t lsx_write_w_buf(sox_format_t * ft, uint16_t *buf, size_t len);
 
 int lsx_read3(sox_format_t * ft, uint24_t * u3);
 int lsx_readb(sox_format_t * ft, uint8_t * ub);
-int lsx_readchars(sox_format_t * ft, char * chars, sox_size_t len);
+int lsx_readchars(sox_format_t * ft, char * chars, size_t len);
 int lsx_readdf(sox_format_t * ft, double * d);
 int lsx_readdw(sox_format_t * ft, uint32_t * udw);
 int lsx_readf(sox_format_t * ft, float * f);
@@ -123,14 +131,14 @@
 int lsx_eof(sox_format_t * ft);
 int lsx_error(sox_format_t * ft);
 int lsx_flush(sox_format_t * ft);
-int lsx_seeki(sox_format_t * ft, sox_ssize_t offset, int whence);
+int lsx_seeki(sox_format_t * ft, ptrdiff_t offset, int whence);
 int lsx_unreadb(sox_format_t * ft, unsigned ub);
-sox_size_t lsx_filelength(sox_format_t * ft);
-sox_ssize_t lsx_tell(sox_format_t * ft);
+size_t lsx_filelength(sox_format_t * ft);
+ptrdiff_t lsx_tell(sox_format_t * ft);
 void lsx_clearerr(sox_format_t * ft);
 void lsx_rewind(sox_format_t * ft);
 
-int lsx_offset_seek(sox_format_t * ft, off_t byte_offset, sox_size_t to_sample);
+int lsx_offset_seek(sox_format_t * ft, off_t byte_offset, size_t to_sample);
 
 void lsx_fail_errno(sox_format_t *, int, const char *, ...)
 #ifdef __GNUC__
@@ -158,11 +166,11 @@
 
 /* Raw I/O */
 int lsx_rawstartread(sox_format_t * ft);
-sox_size_t lsx_rawread(sox_format_t * ft, sox_sample_t *buf, sox_size_t nsamp);
+size_t lsx_rawread(sox_format_t * ft, sox_sample_t *buf, size_t nsamp);
 int lsx_rawstopread(sox_format_t * ft);
 int lsx_rawstartwrite(sox_format_t * ft);
-sox_size_t lsx_rawwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp);
-int lsx_rawseek(sox_format_t * ft, sox_size_t offset);
+size_t lsx_rawwrite(sox_format_t * ft, const sox_sample_t *buf, size_t nsamp);
+int lsx_rawseek(sox_format_t * ft, size_t offset);
 int lsx_rawstart(sox_format_t * ft, sox_bool default_rate, sox_bool default_channels, sox_bool default_length, sox_encoding_t encoding, unsigned size);
 #define lsx_rawstartread(ft) lsx_rawstart(ft, sox_false, sox_false, sox_false, SOX_ENCODING_UNKNOWN, 0)
 #define lsx_rawstartwrite lsx_rawstartread
--- a/src/sox_sample_test.h
+++ b/src/sox_sample_test.h
@@ -158,7 +158,7 @@
   int24_t int24_2;
 
   sox_sample_t sample;
-  sox_size_t clips = 0;
+  size_t clips = 0;
 
   double d;
 
--- a/src/spectrogram.c
+++ b/src/spectrogram.c
@@ -130,7 +130,7 @@
 {
   enum_item const * p = find_enum_text(optarg, items);
   if (p == NULL) {
-    unsigned len = 1;
+    size_t len = 1;
     char * set = lsx_malloc(len);
     *set = 0;
     for (p = items; p->text; ++p) {
@@ -253,10 +253,10 @@
 
 static int flow(sox_effect_t * effp,
     const sox_sample_t * ibuf, sox_sample_t * obuf,
-    sox_size_t * isamp, sox_size_t * osamp)
+    size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t len = min(*isamp, *osamp), dummy = 0; /* No need to clip count */
+  size_t len = min(*isamp, *osamp), dummy = 0; /* No need to clip count */
   int i;
 
   memcpy(obuf, ibuf, len * sizeof(*obuf)); /* Pass on audio unaffected */
@@ -288,7 +288,7 @@
   return SOX_SUCCESS;
 }
 
-static int drain(sox_effect_t * effp, sox_sample_t * obuf_, sox_size_t * osamp)
+static int drain(sox_effect_t * effp, sox_sample_t * obuf_, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
 
@@ -295,7 +295,7 @@
   if (!p->truncated) {
     sox_sample_t * ibuf = calloc(p->dft_size, sizeof(*ibuf));
     sox_sample_t * obuf = calloc(p->dft_size, sizeof(*obuf));
-    sox_size_t isamp = (p->dft_size - p->step_size) / 2;
+    size_t isamp = (p->dft_size - p->step_size) / 2;
     int left_over = (isamp + p->read) % p->step_size;
 
     if (left_over >= p->step_size >> 1)
@@ -328,15 +328,15 @@
   int i;
 
   if (p->light_background) {
-    memcpy(palette++, (p->monochrome)? "\337\337\337":"\335\330\320", 3);
-    memcpy(palette++, "\0\0\0"      , 3);
-    memcpy(palette++, "\077\077\077", 3);
-    memcpy(palette++, "\077\077\077", 3);
+    memcpy(palette++, (p->monochrome)? "\337\337\337":"\335\330\320", (size_t)3);
+    memcpy(palette++, "\0\0\0"      , (size_t)3);
+    memcpy(palette++, "\077\077\077", (size_t)3);
+    memcpy(palette++, "\077\077\077", (size_t)3);
   } else {
-    memcpy(palette++, "\0\0\0"      , 3);
-    memcpy(palette++, "\377\377\377", 3);
-    memcpy(palette++, "\277\277\277", 3);
-    memcpy(palette++, "\177\177\177", 3);
+    memcpy(palette++, "\0\0\0"      , (size_t)3);
+    memcpy(palette++, "\377\377\377", (size_t)3);
+    memcpy(palette++, "\277\277\277", (size_t)3);
+    memcpy(palette++, "\177\177\177", (size_t)3);
   }
   for (i = 0; i < p->spectrum_points; ++i) {
     double c[3], x = (double)i / (p->spectrum_points - 1);
--- a/src/sphere.c
+++ b/src/sphere.c
@@ -24,9 +24,10 @@
 
 static int start_read(sox_format_t * ft)
 {
+  unsigned long header_size_ul = 0, num_samples_ul = 0;
   sox_encoding_t encoding = SOX_ENCODING_SIGN2;
-  sox_size_t     header_size, bytes_read;
-  sox_size_t     num_samples = 0;
+  size_t     header_size, bytes_read;
+  size_t     num_samples = 0;
   unsigned       bytes_per_sample = 0;
   unsigned       channels = 1;
   unsigned       rate = 16000;
@@ -34,19 +35,19 @@
   char           * buf;
 
   /* Magic header */
-  if (lsx_reads(ft, fldname, 8) || strncmp(fldname, "NIST_1A", 7) != 0) {
+  if (lsx_reads(ft, fldname, (size_t)8) || strncmp(fldname, "NIST_1A", (size_t)7) != 0) {
     lsx_fail_errno(ft, SOX_EHDR, "Sphere header does not begin with magic word 'NIST_1A'");
     return (SOX_EOF);
   }
 
-  if (lsx_reads(ft, fldsval, 8)) {
+  if (lsx_reads(ft, fldsval, (size_t)8)) {
     lsx_fail_errno(ft, SOX_EHDR, "Error reading Sphere header");
     return (SOX_EOF);
   }
 
   /* Determine header size, and allocate a buffer large enough to hold it. */
-  sscanf(fldsval, "%u", &header_size);
-  buf = lsx_malloc(header_size);
+  sscanf(fldsval, "%lu", &header_size_ul);
+  buf = lsx_malloc(header_size = header_size_ul);
 
   /* Skip what we have read so far */
   header_size -= 16;
@@ -59,16 +60,16 @@
 
   header_size -= (strlen(buf) + 1);
 
-  while (strncmp(buf, "end_head", 8) != 0) {
-    if (strncmp(buf, "sample_n_bytes", 14) == 0)
+  while (strncmp(buf, "end_head", (size_t)8) != 0) {
+    if (strncmp(buf, "sample_n_bytes", (size_t)14) == 0)
       sscanf(buf, "%63s %15s %u", fldname, fldtype, &bytes_per_sample);
-    else if (strncmp(buf, "channel_count", 13) == 0)
+    else if (strncmp(buf, "channel_count", (size_t)13) == 0)
       sscanf(buf, "%63s %15s %u", fldname, fldtype, &channels);
-    else if (strncmp(buf, "sample_count ", 13) == 0)
-      sscanf(buf, "%53s %15s %u", fldname, fldtype, &num_samples);
-    else if (strncmp(buf, "sample_rate ", 12) == 0)
+    else if (strncmp(buf, "sample_count ", (size_t)13) == 0)
+      sscanf(buf, "%53s %15s %lu", fldname, fldtype, &num_samples_ul);
+    else if (strncmp(buf, "sample_rate ", (size_t)12) == 0)
       sscanf(buf, "%53s %15s %u", fldname, fldtype, &rate);
-    else if (strncmp(buf, "sample_coding", 13) == 0) {
+    else if (strncmp(buf, "sample_coding", (size_t)13) == 0) {
       sscanf(buf, "%63s %15s %127s", fldname, fldtype, fldsval);
       if (!strcasecmp(fldsval, "ulaw") || !strcasecmp(fldsval, "mu-law"))
         encoding = SOX_ENCODING_ULAW;
@@ -80,7 +81,7 @@
         return SOX_EOF;
       }
     }
-    else if (strncmp(buf, "sample_byte_format", 18) == 0) {
+    else if (strncmp(buf, "sample_byte_format", (size_t)18) == 0) {
       sscanf(buf, "%53s %15s %127s", fldname, fldtype, fldsval);
       if (strcmp(fldsval, "01") == 0)         /* Data is little endian. */
         ft->encoding.reverse_bytes = MACHINE_IS_BIGENDIAN;
@@ -121,7 +122,7 @@
 
     if (lsx_readchars(ft, shorten_check, sizeof(shorten_check)))
       return SOX_EOF;
-    lsx_seeki(ft, -(sox_ssize_t)sizeof(shorten_check), SEEK_CUR);
+    lsx_seeki(ft, -(ptrdiff_t)sizeof(shorten_check), SEEK_CUR);
 
     if (!memcmp(shorten_check, "ajkg", sizeof(shorten_check))) {
       lsx_fail_errno(ft, SOX_EFMT,
@@ -130,6 +131,7 @@
     }
   }
 
+  num_samples = num_samples_ul;
   return lsx_check_read_params(ft, channels, (sox_rate_t)rate, encoding,
       bytes_per_sample << 3, (off_t)(num_samples * channels));
 }
@@ -170,7 +172,7 @@
 
   lsx_writes(ft, "end_head\n");
 
-  lsx_padbytes(ft, 1024 - (sox_size_t)lsx_tell(ft));
+  lsx_padbytes(ft, 1024 - (size_t)lsx_tell(ft));
   return SOX_SUCCESS;
 }
 
--- a/src/splice.c
+++ b/src/splice.c
@@ -31,7 +31,7 @@
 
 /* Find where the two segments are most alike over the overlap period. */
 static size_t best_overlap_position(float const * f1, float const * f2,
-    sox_size_t overlap, sox_size_t search, sox_size_t channels)
+    size_t overlap, size_t search, size_t channels)
 {
   size_t i, best_pos = 0;
   float diff, least_diff = difference(f2, f1, channels * overlap);
@@ -45,7 +45,7 @@
 }
 
 static void splice(const float * in1, const float * in2,
-    float * output, sox_size_t overlap, sox_size_t channels)
+    float * output, size_t overlap, size_t channels)
 {
   size_t i, j, k = 0;
   float fade_step = 1.0f / (float) overlap;
@@ -58,7 +58,7 @@
   }
 }
 
-static sox_size_t do_splice(float * f, sox_size_t overlap, sox_size_t search, sox_size_t channels)
+static size_t do_splice(float * f, size_t overlap, size_t search, size_t channels)
 {
   size_t offset = search? best_overlap_position(
       f, f + overlap * channels, overlap, search, channels) : 0;
@@ -71,15 +71,15 @@
   unsigned nsplices;     /* Number of splices requested */
   struct {
     char * str;          /* Command-line argument to parse for this splice */
-    sox_size_t overlap;  /* Number of samples to overlap */
-    sox_size_t search;   /* Number of samples to search */
-    sox_size_t start;    /* Start splicing when in_pos equals this */
+    size_t overlap;  /* Number of samples to overlap */
+    size_t search;   /* Number of samples to search */
+    size_t start;    /* Start splicing when in_pos equals this */
   } * splices;
 
-  sox_size_t in_pos;     /* Number of samples read from the input stream */
+  size_t in_pos;     /* Number of samples read from the input stream */
   unsigned splices_pos;  /* Number of splices completed so far */
-  sox_size_t buffer_pos; /* Number of samples through the current splice */
-  sox_size_t max_buffer_size;
+  size_t buffer_pos; /* Number of samples through the current splice */
+  size_t max_buffer_size;
   float * buffer;
   unsigned state;
 } priv_t;
@@ -88,7 +88,7 @@
 {
   priv_t * p = (priv_t *)effp->priv;
   char const * next;
-  sox_size_t i, buffer_size;
+  size_t i, buffer_size;
 
   p->max_buffer_size = 0;
   for (i = 0; i < p->nsplices; ++i) {
@@ -148,10 +148,10 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t c, idone = 0, odone = 0;
+  size_t c, idone = 0, odone = 0;
   *isamp /= effp->in_signal.channels;
   *osamp /= effp->in_signal.channels;
 
@@ -171,13 +171,13 @@
 
 buffering:
     if (p->state == 1) {
-      sox_size_t buffer_size = (2 * p->splices[p->splices_pos].overlap + p->splices[p->splices_pos].search) * effp->in_signal.channels;
+      size_t buffer_size = (2 * p->splices[p->splices_pos].overlap + p->splices[p->splices_pos].search) * effp->in_signal.channels;
       for (; idone < *isamp; ++idone, ++p->in_pos) {
         if (p->buffer_pos == buffer_size) {
           p->buffer_pos = do_splice(p->buffer,
               p->splices[p->splices_pos].overlap,
               p->splices[p->splices_pos].search,
-              effp->in_signal.channels) * effp->in_signal.channels;
+              (size_t)effp->in_signal.channels) * effp->in_signal.channels;
           p->state = 2;
           goto flushing;
           break;
@@ -190,7 +190,7 @@
 
 flushing:
     if (p->state == 2) {
-      sox_size_t buffer_size = (2 * p->splices[p->splices_pos].overlap + p->splices[p->splices_pos].search) * effp->in_signal.channels;
+      size_t buffer_size = (2 * p->splices[p->splices_pos].overlap + p->splices[p->splices_pos].search) * effp->in_signal.channels;
       for (; odone < *osamp; ++odone) {
         if (p->buffer_pos == buffer_size) {
           p->buffer_pos = 0;
@@ -210,9 +210,9 @@
   return SOX_SUCCESS;
 }
 
-static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
+static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
 {
-  sox_size_t isamp = 0;
+  size_t isamp = 0;
   return flow(effp, 0, obuf, &isamp, osamp);
 }
 
--- a/src/stat.c
+++ b/src/stat.c
@@ -26,7 +26,7 @@
   double dsum1, dsum2;          /* deltas */
   double scale;                 /* scale-factor */
   double last;                  /* previous sample */
-  sox_size_t read;               /* samples processed */
+  size_t read;               /* samples processed */
   int volume;
   int srms;
   int fft;
@@ -129,7 +129,7 @@
  * Return number of samples processed.
  */
 static int sox_stat_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                        sox_size_t *isamp, sox_size_t *osamp)
+                        size_t *isamp, size_t *osamp)
 {
   priv_t * stat = (priv_t *) effp->priv;
   int done, x, len = min(*isamp, *osamp);
@@ -145,7 +145,7 @@
 
         if (stat->fft_offset >= stat->fft_size) {
           stat->fft_offset = 0;
-          print_power_spectrum(stat->fft_size, effp->in_signal.rate, stat->re_in, stat->re_out);
+          print_power_spectrum((unsigned) stat->fft_size, effp->in_signal.rate, stat->re_in, stat->re_out);
         }
 
       }
@@ -200,7 +200,7 @@
 /*
  * Process tail of input samples.
  */
-static int sox_stat_drain(sox_effect_t * effp, sox_sample_t *obuf UNUSED, sox_size_t *osamp)
+static int sox_stat_drain(sox_effect_t * effp, sox_sample_t *obuf UNUSED, size_t *osamp)
 {
   priv_t * stat = (priv_t *) effp->priv;
 
@@ -214,7 +214,7 @@
     for (x = stat->fft_offset; x < stat->fft_size; x++)
       stat->re_in[x] = 0;
 
-    print_power_spectrum(stat->fft_size, effp->in_signal.rate, stat->re_in, stat->re_out);
+    print_power_spectrum((unsigned) stat->fft_size, effp->in_signal.rate, stat->re_in, stat->re_out);
   }
 
   *osamp = 0;
@@ -264,7 +264,7 @@
   if (stat->volume == 2)
     fprintf(stderr, "\n\n");
   /* print out the info */
-  fprintf(stderr, "Samples read:      %12u\n", stat->read);
+  fprintf(stderr, "Samples read:      %12lu\n", (unsigned long)stat->read);
   fprintf(stderr, "Length (seconds):  %12.6f\n", (double)stat->read/effp->in_signal.rate/effp->in_signal.channels);
   if (stat->srms)
     fprintf(stderr, "Scaled by rms:     %12.6f\n", rms);
--- a/src/stretch.c
+++ b/src/stretch.c
@@ -51,16 +51,16 @@
   /* internal stuff */
   stretch_status_t state; /* automaton status */
 
-  sox_size_t size;         /* buffer size */
-  sox_size_t index;        /* next available element */
+  size_t size;         /* buffer size */
+  size_t index;        /* next available element */
   sox_sample_t *ibuf;      /* input buffer */
-  sox_size_t ishift;       /* input shift */
+  size_t ishift;       /* input shift */
 
-  sox_size_t oindex;       /* next evailable element */
+  size_t oindex;       /* next evailable element */
   double * obuf;   /* output buffer */
-  sox_size_t oshift;       /* output shift */
+  size_t oshift;       /* output shift */
 
-  sox_size_t fsize;        /* fading size */
+  size_t fsize;        /* fading size */
   double * fbuf;   /* fading, 1.0 -> 0.0 */
 
 } priv_t;
@@ -141,7 +141,7 @@
 static int sox_stretch_start(sox_effect_t * effp)
 {
   priv_t * stretch = (priv_t *)effp->priv;
-  sox_size_t i;
+  size_t i;
 
   if (stretch->factor == 1)
     return SOX_EFF_NULL;
@@ -187,10 +187,11 @@
     stretch->fbuf[0] = 1.0;
 
   sox_debug("start: (f=%.2f w=%.2f r=%.2f f=%.2f)"
-           " st=%d s=%d ii=%d is=%d oi=%d os=%d fs=%d\n",
-           stretch->factor, stretch->window, stretch->shift, stretch->fading,
-           stretch->state, stretch->size, stretch->index, stretch->ishift,
-           stretch->oindex, stretch->oshift, stretch->fsize);
+           " st=%d s=%lu ii=%lu is=%lu oi=%lu os=%lu fs=%lu\n", stretch->factor,
+      stretch->window, stretch->shift, stretch->fading, stretch->state,
+      (unsigned long)stretch->size, (unsigned long)stretch->index,
+      (unsigned long)stretch->ishift, (unsigned long)stretch->oindex,
+      (unsigned long)stretch->oshift, (unsigned long)stretch->fsize);
 
   return SOX_SUCCESS;
 }
@@ -220,15 +221,15 @@
  * Processes flow.
  */
 static int sox_stretch_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                    sox_size_t *isamp, sox_size_t *osamp)
+                    size_t *isamp, size_t *osamp)
 {
   priv_t * stretch = (priv_t *) effp->priv;
-  sox_size_t iindex = 0, oindex = 0;
-  sox_size_t i;
+  size_t iindex = 0, oindex = 0;
+  size_t i;
 
   while (iindex<*isamp && oindex<*osamp) {
     if (stretch->state == input_state) {
-      sox_size_t tocopy = min(*isamp-iindex,
+      size_t tocopy = min(*isamp-iindex,
                              stretch->size-stretch->index);
 
       memcpy(stretch->ibuf + stretch->index, ibuf + iindex, tocopy * sizeof(sox_sample_t));
@@ -286,11 +287,11 @@
  * Drain buffer at the end
  * maybe not correct ? end might be artificially faded?
  */
-static int sox_stretch_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int sox_stretch_drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
   priv_t * stretch = (priv_t *) effp->priv;
-  sox_size_t i;
-  sox_size_t oindex = 0;
+  size_t i;
+  size_t oindex = 0;
 
   if (stretch->state == input_state) {
     for (i=stretch->index; i<stretch->size; i++)
--- a/src/sunaudio.c
+++ b/src/sunaudio.c
@@ -45,7 +45,7 @@
 static int sox_sunstartread(sox_format_t * ft)
 {
     priv_t *file = (priv_t *)ft->priv;
-    sox_size_t samplesize, encoding;
+    size_t samplesize, encoding;
     audio_info_t audio_if;
 #ifdef __SVR4
     audio_device_t audio_dev;
@@ -181,7 +181,7 @@
 static int sox_sunstartwrite(sox_format_t * ft)
 {
     priv_t *file = (priv_t *)ft->priv;
-    sox_size_t samplesize, encoding;
+    size_t samplesize, encoding;
     audio_info_t audio_if;
 #ifdef __SVR4
     audio_device_t audio_dev;
--- a/src/swap.c
+++ b/src/swap.c
@@ -128,7 +128,7 @@
  * Return number of samples processed.
  */
 static int sox_swap_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                 sox_size_t *isamp, sox_size_t *osamp)
+                 size_t *isamp, size_t *osamp)
 {
     priv_t * swap = (priv_t *) effp->priv;
     int len, done;
--- a/src/synth.c
+++ b/src/synth.c
@@ -168,12 +168,12 @@
 typedef struct {
   char *        length_str;
   channel_t     getopts_channels;
-  sox_size_t    getopts_nchannels;
+  size_t    getopts_nchannels;
   sox_sample_t  max;
-  sox_size_t    samples_done;
-  sox_size_t    samples_to_do;
+  size_t    samples_done;
+  size_t    samples_to_do;
   channel_t     channels;
-  sox_size_t    number_of_channels;
+  size_t    number_of_channels;
 } priv_t;
 
 
@@ -387,11 +387,11 @@
           (log(chan->freq2) - log(chan->freq)) / synth->samples_to_do : 1;
         break;
     }
-    sox_debug("type=%s, combine=%s, samples_to_do=%u, f1=%g, f2=%g, "
+    sox_debug("type=%s, combine=%s, samples_to_do=%lu, f1=%g, f2=%g, "
               "offset=%g, phase=%g, p1=%g, p2=%g, p3=%g mult=%g",
         find_enum_value(chan->type, synth_type)->text,
         find_enum_value(chan->combine, combine_type)->text,
-        synth->samples_to_do, chan->freq, chan->freq2,
+        (unsigned long)synth->samples_to_do, chan->freq, chan->freq2,
         chan->offset, chan->phase, chan->p1, chan->p2, chan->p3, chan->mult);
   }
   return SOX_SUCCESS;
@@ -403,7 +403,7 @@
 #define elapsed_time_s synth->samples_done / effp->in_signal.rate
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, sox_sample_t * obuf,
-    sox_size_t * isamp, sox_size_t * osamp)
+    size_t * isamp, size_t * osamp)
 {
   priv_t * synth = (priv_t *) effp->priv;
   unsigned len = min(*isamp, *osamp) / effp->in_signal.channels;
--- a/src/tempo.c
+++ b/src/tempo.c
@@ -154,7 +154,7 @@
 
   if ((int)remaining > 0) {
     while (fifo_occupancy(&t->output_fifo) < remaining) {
-      tempo_input(t, buff, 128);
+      tempo_input(t, buff, (size_t) 128);
       tempo_process(t);
     }
     fifo_trim_to(&t->output_fifo, remaining);
@@ -229,7 +229,7 @@
   if (p->factor == 1)
     return SOX_EFF_NULL;
 
-  p->tempo = tempo_create(effp->in_signal.channels);
+  p->tempo = tempo_create((size_t)effp->in_signal.channels);
   tempo_setup(p->tempo, effp->in_signal.rate, p->quick_search, p->factor,
       p->segment_ms, p->search_ms, p->overlap_ms);
   return SOX_SUCCESS;
@@ -236,12 +236,10 @@
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
-                sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+                sox_sample_t * obuf, size_t * isamp, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  sox_size_t i;
-  /* odone must be size_t 'cos tempo_output arg. is. (!= sox_size_t on amd64) */
-  size_t odone = *osamp /= effp->in_signal.channels;
+  size_t i, odone = *osamp /= effp->in_signal.channels;
   float const * s = tempo_output(p->tempo, NULL, &odone);
 
   for (i = 0; i < odone * effp->in_signal.channels; ++i)
@@ -259,10 +257,10 @@
   return SOX_SUCCESS;
 }
 
-static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
+static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  static sox_size_t isamp = 0;
+  static size_t isamp = 0;
   tempo_flush(p->tempo);
   return flow(effp, 0, obuf, &isamp, osamp);
 }
--- a/src/tremolo.c
+++ b/src/tremolo.c
@@ -32,7 +32,7 @@
   args[2] = argv[0];
   sprintf(offset, "%g", 100 - depth / 2);
   args[3] = offset;
-  return sox_synth_effect_fn()->getopts(effp, array_length(args), args);
+  return sox_synth_effect_fn()->getopts(effp, (int)array_length(args), args);
 }
 
 sox_effect_handler_t const * sox_tremolo_effect_fn(void)
--- a/src/trim.c
+++ b/src/trim.c
@@ -15,12 +15,12 @@
     char *length_str;
 
     /* options converted to values */
-    sox_size_t start;
-    sox_size_t length;
+    size_t start;
+    size_t length;
 
     /* internal stuff */
-    sox_size_t index;
-    sox_size_t trimmed;
+    size_t index;
+    size_t trimmed;
 } priv_t;
 
 /*
@@ -92,7 +92,7 @@
  * Return number of samples read.
  */
 static int sox_trim_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                 sox_size_t *isamp, sox_size_t *osamp)
+                 size_t *isamp, size_t *osamp)
 {
     int result = SOX_SUCCESS;
     int start_trim = 0;
@@ -156,7 +156,7 @@
     return (SOX_SUCCESS);
 }
 
-sox_size_t sox_trim_get_start(sox_effect_t * effp)
+size_t sox_trim_get_start(sox_effect_t * effp)
 {
     priv_t * trim = (priv_t *)effp->priv;
     return trim->start;
--- a/src/tx16w.c
+++ b/src/tx16w.c
@@ -41,9 +41,9 @@
 
 /* Private data for TX16 file */
 typedef struct {
-  sox_size_t   samples_out;
-  sox_size_t   bytes_out;
-  sox_size_t   rest;                 /* bytes remaining in sample file */
+  size_t   samples_out;
+  size_t   bytes_out;
+  size_t   rest;                 /* bytes remaining in sample file */
   sox_sample_t odd;
   sox_bool     odd_flag;
 } priv_t;
@@ -76,7 +76,7 @@
     char filetype[7];
     int8_t format;
     unsigned char sample_rate;
-    sox_size_t num_samp_bytes = 0;
+    size_t num_samp_bytes = 0;
     unsigned char gunk[8];
     int blewIt;
     uint8_t trash;
@@ -90,10 +90,10 @@
     }
 
     /* This is dumb but portable, just count the bytes til EOF */
-    while (lsx_read_b_buf(ft, &trash, 1) == 1)
+    while (lsx_read_b_buf(ft, &trash, (size_t) 1) == 1)
         num_samp_bytes++;
     num_samp_bytes -= 32;         /* calculate num samples by sub header size */
-    lsx_seeki(ft, 0, 0);           /* rewind file */
+    lsx_seeki(ft, (size_t)0, 0);           /* rewind file */
     sk->rest = num_samp_bytes;    /* set how many sample bytes to read */
 
     /* first 6 bytes are file type ID LM8953 */
@@ -177,10 +177,10 @@
  * Return number of samples read.
  */
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
     priv_t * sk = (priv_t *) ft->priv;
-    sox_size_t done = 0;
+    size_t done = 0;
     unsigned char uc1,uc2,uc3;
     unsigned short s1,s2;
 
@@ -246,15 +246,15 @@
     /* dummy numbers, just for place holder, real header is written
        at end of processing, since byte count is needed */
 
-    lsx_writebuf(ft, &WH, 32);
+    lsx_writebuf(ft, &WH, (size_t) 32);
     sk->bytes_out = 32;
     return(SOX_SUCCESS);
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len0)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t len0)
 {
   priv_t * sk = (priv_t *) ft->priv;
-  sox_size_t last_i, i = 0, len = min(len0, TXMAXLEN - sk->samples_out);
+  size_t last_i, i = 0, len = min(len0, TXMAXLEN - sk->samples_out);
   sox_sample_t w1, w2;
 
   while (i < len) {
@@ -292,7 +292,7 @@
 
     if (sk->odd_flag) {
       sox_sample_t pad = 0;
-      write_samples(ft, &pad, 1);
+      write_samples(ft, &pad, (size_t) 1);
     }
 
     /* All samples are already written out. */
@@ -302,7 +302,7 @@
     sox_debug("tx16w:output finished");
 
     memset(&WH, 0, sizeof(struct WaveHeader_));
-    strncpy(WH.filetype,"LM8953",6);
+    strncpy(WH.filetype,"LM8953",(size_t)6);
     for (i=0;i<10;i++) WH.nulls[i]=0;
     for (i=0;i<6;i++)  WH.dummy_aeg[i]=0;
     for (i=0;i<2;i++)  WH.unused[i]=0;
@@ -362,7 +362,7 @@
         magic2[WH.sample_rate];
 
     lsx_rewind(ft);
-    lsx_writebuf(ft, &WH, 32);
+    lsx_writebuf(ft, &WH, (size_t) 32);
 
     return(SOX_SUCCESS);
 }
--- a/src/util.h
+++ b/src/util.h
@@ -69,7 +69,7 @@
 #define assert_static(e,f) enum {assert_static__##f = 1/(e)}
 #define range_limit(x, lower, upper) (min(max(x, lower), upper))
 #define array_length(a) (sizeof(a)/sizeof(a[0]))
-#define field_offset(type, field) ((unsigned)&(((type *)0)->field))
+#define field_offset(type, field) ((size_t)&(((type *)0)->field))
 #define sqr(a) ((a) * (a))
 
 #define dB_to_linear(x) exp((x) * M_LN10 * 0.05)
--- a/src/voc.c
+++ b/src/voc.c
@@ -166,7 +166,7 @@
   long rate;                    /* rate code (byte) of this chunk */
   int silent;                   /* sound or silence? */
   long srate;                   /* rate code (byte) of silence */
-  sox_size_t blockseek;         /* start of current output block */
+  size_t blockseek;         /* start of current output block */
   long samples;                 /* number of samples output */
   uint16_t format;              /* VOC audio format */
   int size;                     /* word length of data */
@@ -220,11 +220,11 @@
   int ii;                       /* for getting rid of lseek */
   unsigned char uc;
 
-  if (lsx_readbuf(ft, header, 20) != 20) {
+  if (lsx_readbuf(ft, header, (size_t)20) != 20) {
     lsx_fail_errno(ft, SOX_EHDR, "unexpected EOF in VOC header");
     return (SOX_EOF);
   }
-  if (strncmp(header, "Creative Voice File\032", 19)) {
+  if (strncmp(header, "Creative Voice File\032", (size_t)19)) {
     lsx_fail_errno(ft, SOX_EHDR, "VOC file header incorrect");
     return (SOX_EOF);
   }
@@ -309,11 +309,11 @@
  * ANN:  Major changes here to support multi-part files and files
  *       that do not have audio in block 9's.
  *-----------------------------------------------------------------*/
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t * buf,
-                               sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t * buf,
+                               size_t len)
 {
   priv_t * v = (priv_t *) ft->priv;
-  sox_size_t done = 0;
+  size_t done = 0;
   int rc = 0;
   int16_t sw;
   unsigned char uc;
@@ -331,7 +331,7 @@
     for (; v->block_remaining && (done < len); v->block_remaining--, done++)
       *buf++ = 0;       /* Fill in silence */
   } else {      /* not silence; read len samples of audio from the file */
-    sox_size_t per = max(1, 9 / v->size);
+    size_t per = max(1, 9 / v->size);
 
     for (; (done + per <= len); done += per) {
       if (v->block_remaining == 0) {    /* IF no more in this block, get another */
@@ -474,13 +474,13 @@
 /*-----------------------------------------------------------------
  * write() -- write a VOC file
  *-----------------------------------------------------------------*/
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t * buf,
-                                sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t * buf,
+                                size_t len)
 {
   priv_t * v = (priv_t *) ft->priv;
   unsigned char uc;
   int16_t sw;
-  sox_size_t done = 0;
+  size_t done = 0;
 
   if (len && v->samples == 0) {
     /* No silence packing yet. */
@@ -511,14 +511,14 @@
   sox_sample_t datum;
 
   lsx_writeb(ft, 0);    /* End of file block code */
-  lsx_seeki(ft, (sox_ssize_t) v->blockseek, 0); /* seek back to block length */
-  lsx_seeki(ft, 1, 1);  /* seek forward one */
+  lsx_seeki(ft, (ptrdiff_t) v->blockseek, 0); /* seek back to block length */
+  lsx_seeki(ft, (size_t)1, 1);  /* seek forward one */
   if (v->silent) {
-    lsx_writesw(ft, v->samples);
+    lsx_writesw(ft, (signed)v->samples);
   } else {
     if (ft->encoding.bits_per_sample == 8) {
       if (ft->signal.channels > 1) {
-        lsx_seeki(ft, 8, 1);    /* forward 7 + 1 for new block header */
+        lsx_seeki(ft, (size_t)8, 1);    /* forward 7 + 1 for new block header */
       }
     }
     v->samples += 2;    /* adjustment: SBDK pp. 3-5 */
@@ -617,7 +617,7 @@
         v->size = uc;
         lsx_readb(ft, &(v->channels));
         lsx_readw(ft, &(v->format));    /* ANN: added format */
-        lsx_skipbytes(ft, 4);
+        lsx_skipbytes(ft, (size_t) 4);
         v->block_remaining = sblen - 12;
         return (SOX_SUCCESS);
       case VOC_CONT:
@@ -677,7 +677,7 @@
       case VOC_LOOP:
       case VOC_LOOPEND:
         sox_debug("skipping repeat loop");
-        lsx_skipbytes(ft, sblen);
+        lsx_skipbytes(ft, (size_t) sblen);
         break;
       case VOC_EXTENDED:
         /* An Extended block is followed by a data block */
@@ -708,7 +708,7 @@
         continue;
       default:
         sox_debug("skipping unknown block code %d", block);
-        lsx_skipbytes(ft, sblen);
+        lsx_skipbytes(ft, (size_t) sblen);
     }
   }
   return SOX_SUCCESS;
@@ -726,7 +726,7 @@
     lsx_writeb(ft, VOC_SILENCE);        /* Silence block code */
     lsx_writeb(ft, 0);  /* Period length */
     lsx_writeb(ft, 0);  /* Period length */
-    lsx_writesb(ft, v->rate);   /* Rate code */
+    lsx_writesb(ft, (signed)v->rate);   /* Rate code */
   } else {
     if (ft->encoding.bits_per_sample == 8) {
       /* 8-bit sample section.  By always setting the correct     */
@@ -741,7 +741,7 @@
         lsx_writeb(ft, 0);      /* block length = 4 */
         lsx_writeb(ft, 0);      /* block length = 4 */
         v->rate = 65536 - (256000000.0 / (2 * ft->signal.rate)) + .5;
-        lsx_writesw(ft, v->rate);       /* Rate code */
+        lsx_writesw(ft, (signed) v->rate);       /* Rate code */
         lsx_writeb(ft, 0);      /* File is not packed */
         lsx_writeb(ft, 1);      /* samples are in stereo */
       }
@@ -750,7 +750,7 @@
       lsx_writeb(ft, 0);        /* block length (for now) */
       lsx_writeb(ft, 0);        /* block length (for now) */
       v->rate = 256 - (1000000.0 / ft->signal.rate) + .5;
-      lsx_writesb(ft, v->rate); /* Rate code */
+      lsx_writesb(ft, (signed) v->rate); /* Rate code */
       lsx_writeb(ft, 0);        /* 8-bit raw data */
     } else {
       lsx_writeb(ft, VOC_DATA_16);      /* Voice Data block code */
--- a/src/vol.c
+++ b/src/vol.c
@@ -107,13 +107,13 @@
  * Process data.
  */
 static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
-                sox_size_t *isamp, sox_size_t *osamp)
+                size_t *isamp, size_t *osamp)
 {
     priv_t * vol = (priv_t *) effp->priv;
     register double gain = vol->gain;
     register double limiterthreshhold = vol->limiterthreshhold;
     register double sample;
-    register sox_size_t len;
+    register size_t len;
 
     len = min(*osamp, *isamp);
 
@@ -189,7 +189,7 @@
   if (argc != 1)
     return lsx_usage(effp);
   args[0] = argv[0];
-  return sox_vol_effect_fn()->getopts(effp, array_length(args), args);
+  return sox_vol_effect_fn()->getopts(effp, (int)array_length(args), args);
 }
 
 sox_effect_handler_t const * sox_gain_effect_fn(void)
--- a/src/vorbis.c
+++ b/src/vorbis.c
@@ -51,9 +51,9 @@
   /* Decoding data */
   OggVorbis_File *vf;
   char *buf;
-  sox_size_t buf_len;
-  sox_size_t start;
-  sox_size_t end;     /* Unsent data samples in buf[start] through buf[end-1] */
+  size_t buf_len;
+  size_t start;
+  size_t end;     /* Unsent data samples in buf[start] through buf[end-1] */
   int current_section;
   int eof;
 
@@ -104,7 +104,7 @@
   vb->vf = lsx_malloc(sizeof(OggVorbis_File));
 
   /* Init the decoder */
-  if (ov_open_callbacks(ft->fp, vb->vf, NULL, 0, callbacks) < 0) {
+  if (ov_open_callbacks(ft->fp, vb->vf, NULL, (size_t) 0, callbacks) < 0) {
     lsx_fail_errno(ft, SOX_EHDR, "Input not an Ogg Vorbis audio stream");
     return (SOX_EOF);
   }
@@ -175,10 +175,10 @@
  * Return number of samples read.
  */
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t * buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t * buf, size_t len)
 {
   priv_t * vb = (priv_t *) ft->priv;
-  sox_size_t i;
+  size_t i;
   int ret;
   sox_sample_t l;
 
@@ -223,8 +223,8 @@
 {
   int written;
 
-  written = lsx_writebuf(ft, page->header, (sox_size_t) page->header_len);
-  written += lsx_writebuf(ft, page->body, (sox_size_t) page->body_len);
+  written = lsx_writebuf(ft, page->header, (size_t) page->header_len);
+  written += lsx_writebuf(ft, page->body, (size_t) page->body_len);
 
   return written;
 }
@@ -316,14 +316,14 @@
   return (SOX_SUCCESS);
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t * buf,
-                        sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t * buf,
+                        size_t len)
 {
   priv_t * vb = (priv_t *) ft->priv;
   vorbis_enc_t *ve = vb->vorbis_enc_data;
-  sox_size_t samples = len / ft->signal.channels;
+  size_t samples = len / ft->signal.channels;
   float **buffer = vorbis_analysis_buffer(&ve->vd, (int) samples);
-  sox_size_t i, j;
+  size_t i, j;
   int ret;
   int eos = 0;
 
@@ -373,7 +373,7 @@
   vorbis_enc_t *ve = vb->vorbis_enc_data;
 
   /* Close out the remaining data */
-  write_samples(ft, NULL, 0);
+  write_samples(ft, NULL, (size_t) 0);
 
   ogg_stream_clear(&ve->os);
   vorbis_block_clear(&ve->vb);
@@ -383,7 +383,7 @@
   return (SOX_SUCCESS);
 }
 
-static int seek(sox_format_t * ft, sox_size_t offset)
+static int seek(sox_format_t * ft, size_t offset)
 {
   priv_t * vb = (priv_t *) ft->priv;
 
--- a/src/vox.c
+++ b/src/vox.c
@@ -26,7 +26,7 @@
   return sox_adpcm_ima_start(ft, (adpcm_io_t *)ft->priv);
 }
 
-sox_size_t sox_vox_read(sox_format_t * ft, sox_sample_t *buffer, sox_size_t len)
+size_t sox_vox_read(sox_format_t * ft, sox_sample_t *buffer, size_t len)
 {
   return sox_adpcm_read(ft, (adpcm_io_t *)ft->priv, buffer, len);
 }
@@ -36,7 +36,7 @@
   return sox_adpcm_stopread(ft, (adpcm_io_t *)ft->priv);
 }
 
-sox_size_t sox_vox_write(sox_format_t * ft, const sox_sample_t *buffer, sox_size_t length)
+size_t sox_vox_write(sox_format_t * ft, const sox_sample_t *buffer, size_t length)
 {
   return sox_adpcm_write(ft, (adpcm_io_t *)ft->priv, buffer, length);
 }
--- a/src/vox.h
+++ b/src/vox.h
@@ -17,7 +17,7 @@
 
 int sox_vox_start(sox_format_t * ft);
 int sox_ima_start(sox_format_t * ft);
-sox_size_t sox_vox_read(sox_format_t * ft, sox_sample_t *buffer, sox_size_t len);
+size_t sox_vox_read(sox_format_t * ft, sox_sample_t *buffer, size_t len);
 int sox_vox_stopread(sox_format_t * ft);
-sox_size_t sox_vox_write(sox_format_t * ft, const sox_sample_t *buffer, sox_size_t length);
+size_t sox_vox_write(sox_format_t * ft, const sox_sample_t *buffer, size_t length);
 int sox_vox_stopwrite(sox_format_t * ft);
--- a/src/wav.c
+++ b/src/wav.c
@@ -53,17 +53,17 @@
 #define WAVE_FORMAT_EXTENSIBLE          (0xfffeU)
 
 /* To allow padding to samplesPerBlock. Works, but currently never true. */
-static sox_size_t pad_nsamps = sox_false;
+static size_t pad_nsamps = sox_false;
 
 /* Private data for .wav file */
 typedef struct {
-    sox_size_t      numSamples;     /* samples/channel reading: starts at total count and decremented  */
+    size_t      numSamples;     /* samples/channel reading: starts at total count and decremented  */
                                     /* writing: starts at 0 and counts samples written */
-    sox_size_t      dataLength;     /* needed for ADPCM writing */
+    size_t      dataLength;     /* needed for ADPCM writing */
     unsigned short formatTag;       /* What type of encoding file is using */
     unsigned short samplesPerBlock;
     unsigned short blockAlign;
-    sox_size_t dataStart;           /* need to for seeking */
+    size_t dataStart;           /* need to for seeking */
     char           * comment;
     int ignoreSize;                 /* ignoreSize allows us to process 32-bit WAV files that are
                                      * greater then 2 Gb and can't be represented by the
@@ -84,7 +84,7 @@
     gsm            gsmhandle;
     gsm_signal     *gsmsample;
     int            gsmindex;
-    sox_size_t      gsmbytecount;    /* counts bytes written to data block */
+    size_t      gsmbytecount;    /* counts bytes written to data block */
 } priv_t;
 
 static char *wav_format_str(unsigned wFormatTag);
@@ -108,7 +108,7 @@
     int samplesThisBlock;
 
     /* Pull in the packet and check the header */
-    bytesRead = lsx_readbuf(ft, wav->packet, wav->blockAlign);
+    bytesRead = lsx_readbuf(ft, wav->packet, (size_t)wav->blockAlign);
     samplesThisBlock = wav->samplesPerBlock;
     if (bytesRead < wav->blockAlign)
     {
@@ -115,7 +115,7 @@
         /* If it looks like a valid header is around then try and */
         /* work with partial blocks.  Specs say it should be null */
         /* padded but I guess this is better than trailing quiet. */
-        samplesThisBlock = lsx_ima_samples_in(0, ft->signal.channels, bytesRead, 0);
+        samplesThisBlock = lsx_ima_samples_in((size_t)0, (size_t)ft->signal.channels, bytesRead, (size_t) 0);
         if (samplesThisBlock == 0)
         {
             sox_warn("Premature EOF on .wav input file");
@@ -149,7 +149,7 @@
     const char *errmsg;
 
     /* Pull in the packet and check the header */
-    bytesRead = lsx_readbuf(ft, wav->packet, wav->blockAlign);
+    bytesRead = lsx_readbuf(ft, wav->packet, (size_t) wav->blockAlign);
     samplesThisBlock = wav->samplesPerBlock;
     if (bytesRead < wav->blockAlign)
     {
@@ -156,7 +156,7 @@
         /* If it looks like a valid header is around then try and */
         /* work with partial blocks.  Specs say it should be null */
         /* padded but I guess this is better than trailing quiet. */
-        samplesThisBlock = lsx_ms_adpcm_samples_in(0, ft->signal.channels, bytesRead, 0);
+        samplesThisBlock = lsx_ms_adpcm_samples_in((size_t)0, (size_t)ft->signal.channels, bytesRead, (size_t)0);
         if (samplesThisBlock == 0)
         {
             sox_warn("Premature EOF on .wav input file");
@@ -179,7 +179,7 @@
 static int xxxAdpcmWriteBlock(sox_format_t * ft)
 {
     priv_t * wav = (priv_t *) ft->priv;
-    sox_size_t chans, ct;
+    size_t chans, ct;
     short *p;
 
     chans = ft->signal.channels;
@@ -190,12 +190,12 @@
         for (p = wav->samplePtr; p < wav->sampleTop; p++) *p=0;
         /* compress the samples to wav->packet */
         if (wav->formatTag == WAVE_FORMAT_ADPCM) {
-            lsx_ms_adpcm_block_mash_i(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, wav->blockAlign);
+            lsx_ms_adpcm_block_mash_i((unsigned) chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, wav->blockAlign);
         }else{ /* WAVE_FORMAT_IMA_ADPCM */
-            lsx_ima_block_mash_i(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, 9);
+            lsx_ima_block_mash_i((unsigned) chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, 9);
         }
         /* write the compressed packet */
-        if (lsx_writebuf(ft, wav->packet, wav->blockAlign) != wav->blockAlign)
+        if (lsx_writebuf(ft, wav->packet, (size_t) wav->blockAlign) != wav->blockAlign)
         {
             lsx_fail_errno(ft,SOX_EOF,"write error");
             return (SOX_EOF);
@@ -245,7 +245,7 @@
     free(wav->gsmsample);
 }
 
-static sox_size_t wavgsmread(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t wavgsmread(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
     priv_t *       wav = (priv_t *) ft->priv;
     size_t done=0;
@@ -261,7 +261,7 @@
   /* read and decode loop, possibly leaving some samples in wav->gsmsample */
     while (done < len) {
         wav->gsmindex=0;
-        bytes = lsx_readbuf(ft, frame, 65);
+        bytes = lsx_readbuf(ft, frame, (size_t)65);
         if (bytes <=0)
             return done;
         if (bytes<65) {
@@ -302,7 +302,7 @@
     gsm_encode(wav->gsmhandle, wav->gsmsample, frame);
     /*encode the odd half long (33 byte) frame */
     gsm_encode(wav->gsmhandle, wav->gsmsample+160, frame+32);
-    if (lsx_writebuf(ft, frame, 65) != 65)
+    if (lsx_writebuf(ft, frame, (size_t) 65) != 65)
     {
         lsx_fail_errno(ft,SOX_EOF,"write error");
         return (SOX_EOF);
@@ -313,7 +313,7 @@
     return (SOX_SUCCESS);
 }
 
-static sox_size_t wavgsmwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+static size_t wavgsmwrite(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
     priv_t * wav = (priv_t *) ft->priv;
     size_t done = 0;
@@ -360,12 +360,12 @@
 /****************************************************************************/
 /* General Sox WAV file code                                                */
 /****************************************************************************/
-static int findChunk(sox_format_t * ft, const char *Label, sox_size_t *len)
+static int findChunk(sox_format_t * ft, const char *Label, uint32_t *len)
 {
     char magic[5];
     for (;;)
     {
-        if (lsx_reads(ft, magic, 4) == SOX_EOF)
+        if (lsx_reads(ft, magic, (size_t)4) == SOX_EOF)
         {
             lsx_fail_errno(ft, SOX_EHDR, "WAVE file has missing %s chunk",
                           Label);
@@ -379,11 +379,11 @@
             return SOX_EOF;
         }
 
-        if (strncmp(Label, magic, 4) == 0)
+        if (strncmp(Label, magic, (size_t)4) == 0)
             break; /* Found the given chunk */
 
         /* skip to next chunk */
-        if (*len == 0 || lsx_seeki(ft, (sox_ssize_t)(*len), SEEK_CUR) != SOX_SUCCESS)
+        if (*len == 0 || lsx_seeki(ft, (ptrdiff_t)(*len), SEEK_CUR) != SOX_SUCCESS)
         {
             lsx_fail_errno(ft,SOX_EHDR,
                           "WAV chunk appears to have invalid size %d.", *len);
@@ -423,7 +423,7 @@
     uint16_t wExtSize = 0;    /* extended field for non-PCM */
 
     uint32_t      dwDataLength;    /* length of sound data in bytes */
-    sox_size_t    bytesPerBlock = 0;
+    size_t    bytesPerBlock = 0;
     int    bytespersample;          /* bytes per sample (per channel */
     char text[256];
     uint32_t      dwLoopPos;
@@ -431,8 +431,8 @@
     ft->sox_errno = SOX_SUCCESS;
     wav->ignoreSize = 0;
 
-    if (lsx_reads(ft, magic, 4) == SOX_EOF || (strncmp("RIFF", magic, 4) != 0 &&
-                                             strncmp("RIFX", magic, 4) != 0))
+    if (lsx_reads(ft, magic, (size_t)4) == SOX_EOF || (strncmp("RIFF", magic, (size_t)4) != 0 &&
+                                             strncmp("RIFX", magic, (size_t)4) != 0))
     {
         lsx_fail_errno(ft,SOX_EHDR,"WAVE: RIFF header not found");
         return SOX_EOF;
@@ -439,7 +439,7 @@
     }
 
     /* RIFX is a Big-endian RIFF */
-    if (strncmp("RIFX", magic, 4) == 0)
+    if (strncmp("RIFX", magic, (size_t)4) == 0)
     {
         sox_debug("Found RIFX header");
         ft->encoding.reverse_bytes = MACHINE_IS_LITTLEENDIAN;
@@ -448,7 +448,7 @@
 
     lsx_readdw(ft, &dwRiffLength);
 
-    if (lsx_reads(ft, magic, 4) == SOX_EOF || strncmp("WAVE", magic, 4))
+    if (lsx_reads(ft, magic, (size_t)4) == SOX_EOF || strncmp("WAVE", magic, (size_t)4))
     {
         lsx_fail_errno(ft,SOX_EHDR,"WAVE header not found");
         return SOX_EOF;
@@ -646,7 +646,7 @@
         }
 
         lsx_readw(ft, &(wav->samplesPerBlock));
-        bytesPerBlock = lsx_ms_adpcm_bytes_per_block(ft->signal.channels, wav->samplesPerBlock);
+        bytesPerBlock = lsx_ms_adpcm_bytes_per_block((size_t) ft->signal.channels, (size_t) wav->samplesPerBlock);
         if (bytesPerBlock > wav->blockAlign)
         {
             lsx_fail_errno(ft,SOX_EOF,"format[%s]: samplesPerBlock(%d) incompatible with blockAlign(%d)",
@@ -659,7 +659,7 @@
             lsx_fail_errno(ft,SOX_EOF,"ADPCM file nCoefs (%.4hx) makes no sense", wav->nCoefs);
             return SOX_EOF;
         }
-        wav->packet = lsx_malloc(wav->blockAlign);
+        wav->packet = lsx_malloc((size_t)wav->blockAlign);
 
         len -= 4;
 
@@ -702,7 +702,7 @@
         }
 
         lsx_readw(ft, &(wav->samplesPerBlock));
-        bytesPerBlock = lsx_ima_bytes_per_block(ft->signal.channels, wav->samplesPerBlock);
+        bytesPerBlock = lsx_ima_bytes_per_block((size_t) ft->signal.channels, (size_t) wav->samplesPerBlock);
         if (bytesPerBlock > wav->blockAlign || wav->samplesPerBlock%8 != 1)
         {
             lsx_fail_errno(ft,SOX_EOF,"format[%s]: samplesPerBlock(%d) incompatible with blockAlign(%d)",
@@ -710,7 +710,7 @@
             return SOX_EOF;
         }
 
-        wav->packet = lsx_malloc(wav->blockAlign);
+        wav->packet = lsx_malloc((size_t)wav->blockAlign);
         len -= 2;
 
         wav->samples = lsx_malloc(wChannels*wav->samplesPerBlock*sizeof(short));
@@ -774,7 +774,7 @@
     }
 
     /* Skip anything left over from fmt chunk */
-    lsx_seeki(ft, (sox_ssize_t)len, SEEK_CUR);
+    lsx_seeki(ft, (ptrdiff_t)len, SEEK_CUR);
 
     /* for non-PCM formats, there's a 'fact' chunk before
      * the upcoming 'data' chunk */
@@ -795,9 +795,9 @@
 
     case WAVE_FORMAT_ADPCM:
         wav->numSamples =
-            lsx_ms_adpcm_samples_in(dwDataLength, ft->signal.channels,
-                           wav->blockAlign, wav->samplesPerBlock);
-        sox_debug_more("datalen %d, numSamples %d",dwDataLength, wav->numSamples);
+            lsx_ms_adpcm_samples_in((size_t)dwDataLength, (size_t)ft->signal.channels,
+                           (size_t)wav->blockAlign, (size_t)wav->samplesPerBlock);
+        sox_debug_more("datalen %d, numSamples %lu",dwDataLength, (unsigned long)wav->numSamples);
         wav->blockSamplesRemaining = 0;        /* Samples left in buffer */
         ft->signal.length = wav->numSamples*ft->signal.channels;
         break;
@@ -806,9 +806,9 @@
         /* Compute easiest part of number of samples.  For every block, there
            are samplesPerBlock samples to read. */
         wav->numSamples =
-            lsx_ima_samples_in(dwDataLength, ft->signal.channels,
-                         wav->blockAlign, wav->samplesPerBlock);
-        sox_debug_more("datalen %d, numSamples %d",dwDataLength, wav->numSamples);
+            lsx_ima_samples_in((size_t)dwDataLength, (size_t)ft->signal.channels,
+                         (size_t)wav->blockAlign, (size_t)wav->samplesPerBlock);
+        sox_debug_more("datalen %d, numSamples %lu",dwDataLength, (unsigned long)wav->numSamples);
         wav->blockSamplesRemaining = 0;        /* Samples left in buffer */
         lsx_ima_init_table();
         ft->signal.length = wav->numSamples*ft->signal.channels;
@@ -835,24 +835,24 @@
     switch (wav->formatTag)
     {
         case WAVE_FORMAT_ADPCM:
-            sox_debug("        %d Extsize, %d Samps/block, %d bytes/block %d Num Coefs, %d Samps/chan",
-                      wExtSize,wav->samplesPerBlock,bytesPerBlock,wav->nCoefs,
-                      wav->numSamples);
+            sox_debug("        %d Extsize, %d Samps/block, %lu bytes/block %d Num Coefs, %lu Samps/chan",
+                      wExtSize,wav->samplesPerBlock,(unsigned long)bytesPerBlock,wav->nCoefs,
+                      (unsigned long)wav->numSamples);
             break;
 
         case WAVE_FORMAT_IMA_ADPCM:
-            sox_debug("        %d Extsize, %d Samps/block, %d bytes/block %d Samps/chan",
-                      wExtSize, wav->samplesPerBlock, bytesPerBlock,
-                      wav->numSamples);
+            sox_debug("        %d Extsize, %d Samps/block, %lu bytes/block %lu Samps/chan",
+                      wExtSize, wav->samplesPerBlock, (unsigned long)bytesPerBlock,
+                      (unsigned long)wav->numSamples);
             break;
 
         case WAVE_FORMAT_GSM610:
-            sox_debug("GSM .wav: %d Extsize, %d Samps/block, %d Samples/chan",
-                      wExtSize, wav->samplesPerBlock, wav->numSamples);
+            sox_debug("GSM .wav: %d Extsize, %d Samps/block, %lu Samples/chan",
+                      wExtSize, wav->samplesPerBlock, (unsigned long)wav->numSamples);
             break;
 
         default:
-            sox_debug("        %d Samps/chans", wav->numSamples);
+            sox_debug("        %lu Samps/chans", (unsigned long)wav->numSamples);
     }
 
     /* Horrible way to find Cool Edit marker points. Taken from Quake source*/
@@ -862,15 +862,15 @@
          * doubt any machine writing Cool Edit Chunks writes them at an odd
          * offset */
         len = (len + 1) & ~1u;
-        if (lsx_seeki(ft, (sox_ssize_t)len, SEEK_CUR) == SOX_SUCCESS &&
+        if (lsx_seeki(ft, (ptrdiff_t)len, SEEK_CUR) == SOX_SUCCESS &&
             findChunk(ft, "LIST", &len) != SOX_EOF)
         {
-            wav->comment = lsx_malloc(256);
+            wav->comment = lsx_malloc((size_t)256);
             /* Initialize comment to a NULL string */
             wav->comment[0] = 0;
             while(!lsx_eof(ft))
             {
-                if (lsx_reads(ft,magic,4) == SOX_EOF)
+                if (lsx_reads(ft,magic,(size_t)4) == SOX_EOF)
                     break;
 
                 /* First look for type fields for LIST Chunk and
@@ -878,12 +878,12 @@
                  * of Chunks, treat the remaining data as Chunks
                  * again.
                  */
-                if (strncmp(magic, "INFO", 4) == 0)
+                if (strncmp(magic, "INFO", (size_t)4) == 0)
                 {
                     /*Skip*/
                     sox_debug("Type INFO");
                 }
-                else if (strncmp(magic, "adtl", 4) == 0)
+                else if (strncmp(magic, "adtl", (size_t)4) == 0)
                 {
                     /* Skip */
                     sox_debug("Type adtl");
@@ -892,7 +892,7 @@
                 {
                     if (lsx_readdw(ft,&len) == SOX_EOF)
                         break;
-                    if (strncmp(magic,"ICRD",4) == 0)
+                    if (strncmp(magic,"ICRD",(size_t)4) == 0)
                     {
                         sox_debug("Chunk ICRD");
                         if (len > 254)
@@ -900,7 +900,7 @@
                             sox_warn("Possible buffer overflow hack attack (ICRD)!");
                             break;
                         }
-                        lsx_reads(ft,text,len);
+                        lsx_reads(ft,text, (size_t)len);
                         if (strlen(wav->comment) + strlen(text) < 254)
                         {
                             if (wav->comment[0] != 0)
@@ -909,9 +909,9 @@
                             strcat(wav->comment,text);
                         }
                         if (strlen(text) < len)
-                           lsx_seeki(ft, (sox_ssize_t)(len - strlen(text)), SEEK_CUR);
+                           lsx_seeki(ft, (ptrdiff_t)(len - strlen(text)), SEEK_CUR);
                     }
-                    else if (strncmp(magic,"ISFT",4) == 0)
+                    else if (strncmp(magic,"ISFT",(size_t)4) == 0)
                     {
                         sox_debug("Chunk ISFT");
                         if (len > 254)
@@ -919,7 +919,7 @@
                             sox_warn("Possible buffer overflow hack attack (ISFT)!");
                             break;
                         }
-                        lsx_reads(ft,text,len);
+                        lsx_reads(ft,text, (size_t)len);
                         if (strlen(wav->comment) + strlen(text) < 254)
                         {
                             if (wav->comment[0] != 0)
@@ -928,34 +928,34 @@
                             strcat(wav->comment,text);
                         }
                         if (strlen(text) < len)
-                           lsx_seeki(ft, (sox_ssize_t)(len - strlen(text)), SEEK_CUR);
+                           lsx_seeki(ft, (ptrdiff_t)(len - strlen(text)), SEEK_CUR);
                     }
-                    else if (strncmp(magic,"cue ",4) == 0)
+                    else if (strncmp(magic,"cue ",(size_t)4) == 0)
                     {
                         sox_debug("Chunk cue ");
-                        lsx_seeki(ft,(sox_ssize_t)(len-4),SEEK_CUR);
+                        lsx_seeki(ft,(ptrdiff_t)(len-4),SEEK_CUR);
                         lsx_readdw(ft,&dwLoopPos);
                         ft->oob.loops[0].start = dwLoopPos;
                     }
-                    else if (strncmp(magic,"ltxt",4) == 0)
+                    else if (strncmp(magic,"ltxt",(size_t)4) == 0)
                     {
                         sox_debug("Chunk ltxt");
                         lsx_readdw(ft,&dwLoopPos);
                         ft->oob.loops[0].length = dwLoopPos - ft->oob.loops[0].start;
                         if (len > 4)
-                           lsx_seeki(ft, (sox_ssize_t)(len - 4), SEEK_CUR);
+                           lsx_seeki(ft, (ptrdiff_t)(len - 4), SEEK_CUR);
                     }
                     else
                     {
                         sox_debug("Attempting to seek beyond unsupported chunk '%c%c%c%c' of length %d bytes", magic[0], magic[1], magic[2], magic[3], len);
                         len = (len + 1) & ~1u;
-                        lsx_seeki(ft, (sox_ssize_t)len, SEEK_CUR);
+                        lsx_seeki(ft, (ptrdiff_t)len, SEEK_CUR);
                     }
                 }
             }
         }
         lsx_clearerr(ft);
-        lsx_seeki(ft,(sox_ssize_t)wav->dataStart,SEEK_SET);
+        lsx_seeki(ft,(ptrdiff_t)wav->dataStart,SEEK_SET);
     }
     return lsx_rawstartread(ft);
 }
@@ -968,10 +968,10 @@
  * Return number of samples read.
  */
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
         priv_t *   wav = (priv_t *) ft->priv;
-        sox_size_t done;
+        size_t done;
 
         ft->sox_errno = SOX_SUCCESS;
 
@@ -1130,7 +1130,7 @@
             for (ch=0; ch<ft->signal.channels; ch++)
                 wav->state[ch] = 0;
             sbsize = ft->signal.channels * wav->samplesPerBlock;
-            wav->packet = lsx_malloc(wav->blockAlign);
+            wav->packet = lsx_malloc((size_t)wav->blockAlign);
             wav->samples = lsx_malloc(sbsize*sizeof(short));
             wav->sampleTop = wav->samples + sbsize;
             wav->samplePtr = wav->samples;
@@ -1272,7 +1272,7 @@
             wBlockAlign = wChannels * 256; /* reasonable default */
             wBitsPerSample = 4;
             wExtSize = 2;
-            wSamplesPerBlock = lsx_ima_samples_in(0, wChannels, wBlockAlign, 0);
+            wSamplesPerBlock = lsx_ima_samples_in((size_t) 0, (size_t) wChannels, (size_t) wBlockAlign, (size_t) 0);
             break;
         case SOX_ENCODING_MS_ADPCM:
             if (wChannels>16)
@@ -1285,7 +1285,7 @@
             wBlockAlign = max(wBlockAlign, 1) * wChannels * 256;
             wBitsPerSample = 4;
             wExtSize = 4+4*7;      /* Ext fmt data length */
-            wSamplesPerBlock = lsx_ms_adpcm_samples_in(0, wChannels, wBlockAlign, 0);
+            wSamplesPerBlock = lsx_ms_adpcm_samples_in((size_t) 0, (size_t) wChannels, (size_t) wBlockAlign, (size_t) 0);
             break;
         case SOX_ENCODING_GSM:
             if (wChannels!=1)
@@ -1369,7 +1369,7 @@
       lsx_writew(ft, wBitsPerSample); /* No padding in container */
       lsx_writedw(ft, 0);             /* Speaker mapping not specified */
       lsx_writew(ft, wFormatTag);
-      lsx_writebuf(ft, guids[!strcmp(ft->filetype, "amb")], 14);
+      lsx_writebuf(ft, guids[!strcmp(ft->filetype, "amb")], (size_t)14);
     }
     else
     /* if not PCM, we need to write out wExtSize even if wExtSize=0 */
@@ -1414,14 +1414,14 @@
         sox_debug("        %d byte/sec, %d block align, %d bits/samp",
                 dwAvgBytesPerSec, wBlockAlign, wBitsPerSample);
     } else {
-        sox_debug("Finished writing Wave file, %u data bytes %u samples",
-                dwDataLength,wav->numSamples);
+        sox_debug("Finished writing Wave file, %u data bytes %lu samples",
+                dwDataLength,(unsigned long)wav->numSamples);
         if (wFormatTag == WAVE_FORMAT_GSM610){
             sox_debug("GSM6.10 format: %li blocks %u padded samples %u padded data bytes",
                     blocksWritten, dwSamplesWritten, dwDataLength);
             if (wav->gsmbytecount != dwDataLength)
-                sox_warn("help ! internal inconsistency - data_written %u gsmbytecount %u",
-                        dwDataLength, wav->gsmbytecount);
+                sox_warn("help ! internal inconsistency - data_written %u gsmbytecount %lu",
+                        dwDataLength, (unsigned long)wav->gsmbytecount);
 
         }
     }
@@ -1428,10 +1428,10 @@
     return SOX_SUCCESS;
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t len)
 {
         priv_t *   wav = (priv_t *) ft->priv;
-        sox_ssize_t total_len = len;
+        ptrdiff_t total_len = len;
 
         ft->sox_errno = SOX_SUCCESS;
 
@@ -1499,7 +1499,7 @@
         if (!ft->seekable)
           return SOX_EOF;
 
-        if (lsx_seeki(ft, 0, SEEK_SET) != 0)
+        if (lsx_seeki(ft, (ptrdiff_t)0, SEEK_SET) != 0)
         {
                 lsx_fail_errno(ft,SOX_EOF,"Can't rewind output file to rewrite .wav header.");
                 return SOX_EOF;
@@ -1560,7 +1560,7 @@
         }
 }
 
-static int seek(sox_format_t * ft, sox_size_t offset)
+static int seek(sox_format_t * ft, size_t offset)
 {
   priv_t *   wav = (priv_t *) ft->priv;
 
@@ -1568,7 +1568,7 @@
     lsx_fail_errno(ft, SOX_ENOTSUP, "seeking not supported with this encoding");
   else if (wav->formatTag == WAVE_FORMAT_GSM610) {
     int new_offset, alignment;
-    sox_size_t gsmoff;
+    size_t gsmoff;
 
     /* rounding bytes to blockAlign so that we
      * don't have to decode partial block. */
@@ -1576,7 +1576,7 @@
              wav->blockAlign * ft->signal.channels / 2;
     gsmoff -= gsmoff % (wav->blockAlign * ft->signal.channels);
 
-    ft->sox_errno = lsx_seeki(ft, (sox_ssize_t)(gsmoff + wav->dataStart), SEEK_SET);
+    ft->sox_errno = lsx_seeki(ft, (ptrdiff_t)(gsmoff + wav->dataStart), SEEK_SET);
     if (ft->sox_errno == SOX_SUCCESS) {
       /* offset is in samples */
       new_offset = offset;
@@ -1589,9 +1589,9 @@
     double wide_sample = offset - (offset % ft->signal.channels);
     double to_d = wide_sample * ft->encoding.bits_per_sample / 8;
     off_t to = to_d;
-    ft->sox_errno = (to != to_d)? SOX_EOF : lsx_seeki(ft, (sox_ssize_t)wav->dataStart + (sox_ssize_t)to, SEEK_SET);
+    ft->sox_errno = (to != to_d)? SOX_EOF : lsx_seeki(ft, (ptrdiff_t)wav->dataStart + (ptrdiff_t)to, SEEK_SET);
     if (ft->sox_errno == SOX_SUCCESS)
-      wav->numSamples -= (sox_size_t)wide_sample / ft->signal.channels;
+      wav->numSamples -= (size_t)wide_sample / ft->signal.channels;
   }
 
   return ft->sox_errno;
--- a/src/wavpack.c
+++ b/src/wavpack.c
@@ -20,17 +20,17 @@
 
 typedef struct {
   WavpackContext * codec;
-  sox_size_t first_block_size;
+  size_t first_block_size;
 } priv_t;
 
 static int32_t ft_read_b_buf(void * ft, void * buf, int32_t len) {
-  return (int32_t)lsx_read_b_buf((sox_format_t *)ft, buf, (sox_size_t)len);}
+  return (int32_t)lsx_read_b_buf((sox_format_t *)ft, buf, (size_t)len);}
 static uint32_t ft_tell(void * ft) {
   return lsx_tell((sox_format_t *)ft);}
 static int ft_seek_abs(void * ft, uint32_t offset) {
-  return lsx_seeki((sox_format_t *)ft, (sox_ssize_t)offset, SEEK_SET);}
+  return lsx_seeki((sox_format_t *)ft, (ptrdiff_t)offset, SEEK_SET);}
 static int ft_seek_rel(void * ft, int32_t offset, int mode) {
-  return lsx_seeki((sox_format_t *)ft, offset, mode);}
+  return lsx_seeki((sox_format_t *)ft, (ptrdiff_t)offset, mode);}
 static int ft_unreadb(void * ft, int b) {
   return lsx_unreadb((sox_format_t *)ft, (unsigned)b);}
 static uint32_t ft_filelength(void * ft) {
@@ -41,7 +41,7 @@
   priv_t * p = (priv_t *)((sox_format_t *)ft)->priv;
   if (!p->first_block_size)
     p->first_block_size = len;
-  return (int32_t)lsx_write_b_buf((sox_format_t *)ft, buf, (sox_size_t)len);}
+  return (int32_t)lsx_write_b_buf((sox_format_t *)ft, buf, (size_t)len);}
 
 static WavpackStreamReader io_fns = {
   ft_read_b_buf, ft_tell, ft_seek_abs, ft_seek_rel,
@@ -66,10 +66,10 @@
   return SOX_SUCCESS;
 }
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t * buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t * buf, size_t len)
 {
   priv_t * p = (priv_t *)ft->priv;
-  size_t i, actual = WavpackUnpackSamples(p->codec, buf, len / ft->signal.channels) * ft->signal.channels;
+  size_t i, actual = WavpackUnpackSamples(p->codec, buf, (uint32_t) len / ft->signal.channels) * ft->signal.channels;
   for (i = 0; i < actual; ++i) switch (ft->encoding.bits_per_sample) {
     case  8: buf[i] = SOX_SIGNED_8BIT_TO_SAMPLE(buf[i],); break;
     case 16: buf[i] = SOX_SIGNED_16BIT_TO_SAMPLE(buf[i],); break;
@@ -103,7 +103,7 @@
   config.num_channels      = ft->signal.channels;
   config.sample_rate       = (int32_t)(ft->signal.rate + .5);
   config.flags = CONFIG_VERY_HIGH_FLAG;
-  if (!WavpackSetConfiguration(p->codec, &config, ft->signal.length? ft->signal.length / ft->signal.channels : (uint32_t)-1)) {
+  if (!WavpackSetConfiguration(p->codec, &config, ft->signal.length? (uint32_t) ft->signal.length / ft->signal.channels : (uint32_t)-1)) {
     lsx_fail_errno(ft, SOX_EHDR, WavpackGetErrorMessage(p->codec));
     return SOX_EOF;
   }
@@ -111,7 +111,7 @@
   return SOX_SUCCESS;
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t * buf, sox_size_t len)
+static size_t write_samples(sox_format_t * ft, const sox_sample_t * buf, size_t len)
 {
   priv_t * p = (priv_t *)ft->priv;
   size_t i;
@@ -128,7 +128,7 @@
       SOX_SAMPLE_TO_SIGNED_32BIT(buf[i], ft->clips);
       break;
   }
-  result = WavpackPackSamples(p->codec, obuf, len / ft->signal.channels);
+  result = WavpackPackSamples(p->codec, obuf, (uint32_t) len / ft->signal.channels);
   free(obuf);
   return result? len : 0;
 }
@@ -145,7 +145,7 @@
     char * buf = lsx_malloc(p->first_block_size);
     lsx_rewind(ft);
     lsx_readchars(ft, buf, p->first_block_size);
-    if (!memcmp(buf, "wvpk", 4))
+    if (!memcmp(buf, "wvpk", (size_t)4))
       WavpackUpdateNumSamples(p->codec, buf);
   }
   p->codec = WavpackCloseFile(p->codec);
@@ -152,11 +152,11 @@
   return SOX_SUCCESS;
 }
 
-static int seek(sox_format_t * ft, sox_size_t offset)
+static int seek(sox_format_t * ft, size_t offset)
 {
   priv_t * p = (priv_t *)ft->priv;
 
-  return WavpackSeekSample(p->codec, (offset / ft->signal.channels))? SOX_SUCCESS : SOX_EOF;
+  return WavpackSeekSample(p->codec, (uint32_t) (offset / ft->signal.channels))? SOX_SUCCESS : SOX_EOF;
 }
 
 SOX_FORMAT_HANDLER(wavpack)
--- a/src/wve.c
+++ b/src/wve.c
@@ -41,7 +41,7 @@
 static int write_header(sox_format_t * ft)
 {
   return lsx_writechars(ft, ID1, sizeof(ID1))
-      || lsx_writedw(ft, ft->olength? ft->olength:ft->signal.length)
+      || lsx_writedw(ft, (unsigned)(ft->olength? ft->olength:ft->signal.length))
       || lsx_writechars(ft, ID2, sizeof(ID2))? SOX_EOF:SOX_SUCCESS;
 }
 
--- a/src/xa.c
+++ b/src/xa.c
@@ -88,10 +88,10 @@
     char *magic = xa->header.magic;
 
     /* Check for the magic value */
-    if (lsx_readbuf(ft, xa->header.magic, 4) != 4 ||
-        (memcmp("XA\0\0", xa->header.magic, 4) != 0 &&
-         memcmp("XAI\0", xa->header.magic, 4) != 0 &&
-         memcmp("XAJ\0", xa->header.magic, 4) != 0))
+    if (lsx_readbuf(ft, xa->header.magic, (size_t)4) != 4 ||
+        (memcmp("XA\0\0", xa->header.magic, (size_t)4) != 0 &&
+         memcmp("XAI\0", xa->header.magic, (size_t)4) != 0 &&
+         memcmp("XAJ\0", xa->header.magic, (size_t)4) != 0))
     {
         lsx_fail_errno(ft, SOX_EHDR, "XA: Header not found");
         return SOX_EOF;
@@ -172,7 +172,7 @@
     xa->bufPos = xa->blockSize;
 
     /* Allocate memory for the block buffer */
-    xa->buf = lsx_calloc(1, xa->blockSize);
+    xa->buf = lsx_calloc(1, (size_t)xa->blockSize);
 
     /* Allocate memory for the state */
     xa->state = lsx_calloc(sizeof(xa_state_t), ft->signal.channels);
@@ -187,7 +187,7 @@
  * Read up to len samples from a file, converted to signed longs.
  * Return the number of samples read.
  */
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
+static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
     priv_t * xa = (priv_t *) ft->priv;
     int32_t sample;
@@ -199,7 +199,7 @@
     while (done < len) {
         if (xa->bufPos >= xa->blockSize) {
             /* Read the next block */
-            bytes = lsx_readbuf(ft, xa->buf, xa->blockSize);
+            bytes = lsx_readbuf(ft, xa->buf, (size_t) xa->blockSize);
             if (bytes < xa->blockSize) {
                 if (lsx_eof(ft)) {
                     if (done > 0) {