shithub: sox

Download patch

ref: 5c8fa5080e75b62012e814232a617bf5c27b4f00
parent: 1eb8cd195857f2a1c67fcf37150bfe14d8a2ed54
author: cbagwell <cbagwell>
date: Wed Oct 8 17:54:32 EDT 2008

Change sox_seek() to use 64-bit offsets to allow seeking beyond 2G.

--- a/ChangeLog
+++ b/ChangeLog
@@ -62,6 +62,7 @@
   o Fix broken audio pass-through with noiseprof effect.  (robs)
   o Fix graph legend display when using --plot octave.  (robs)
   o Fix rare crash with `rate' effect.  (robs)
+  o Trim will now skip past 2G point correctly. (cbagwell)
 
 Other new features:
 
@@ -99,6 +100,7 @@
   o Retire old FFT routines (speeds up `noisered' effect).  (robs)
   o Allow effects to use getopt.  (robs)
   o Use libmagic for mp3.  (robs)
+  o Change sox_seek() offset to 64-bit to work with > 2G files (cbagwell)
 
 
 sox-14.1.0	2008-7-29
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -64,9 +64,9 @@
                                 lsx_fail_errno(ft, SOX_EHDR, "VHDR chunk has bad size");
                                 return(SOX_EOF);
                         }
-                        lsx_seeki(ft,(size_t)12,SEEK_CUR);
+                        lsx_seeki(ft,(off_t)12,SEEK_CUR);
                         lsx_readw(ft, &rate);
-                        lsx_seeki(ft,(size_t)1,SEEK_CUR);
+                        lsx_seeki(ft,(off_t)1,SEEK_CUR);
                         lsx_readbuf(ft, buf,(size_t)1);
                         if (buf[0] != 0)
                         {
@@ -73,7 +73,7 @@
                                 lsx_fail_errno(ft, SOX_EFMT, "Unsupported data compression");
                                 return(SOX_EOF);
                         }
-                        lsx_seeki(ft,(size_t)4,SEEK_CUR);
+                        lsx_seeki(ft,(off_t)4,SEEK_CUR);
                         continue;
                 }
 
@@ -133,7 +133,7 @@
                 lsx_readdw(ft, &chunksize);
                 if (chunksize & 1)
                         chunksize++;
-                lsx_seeki(ft,(ptrdiff_t)chunksize,SEEK_CUR);
+                lsx_seeki(ft,(off_t)chunksize,SEEK_CUR);
                 continue;
 
         }
@@ -305,7 +305,7 @@
             lsx_writeb(ft, '\0');
 
         /* fixup file sizes in header */
-        if (lsx_seeki(ft, (size_t)0, 0) != 0)
+        if (lsx_seeki(ft, (off_t)0, 0) != 0)
         {
                 lsx_fail_errno(ft,errno,"can't rewind output file to rewrite 8SVX header");
                 return(SOX_EOF);
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -38,7 +38,7 @@
 /* Private data used by writer */
 typedef aiff_priv_t priv_t;
 
-int sox_aiffseek(sox_format_t * ft, size_t offset)
+int sox_aiffseek(sox_format_t * ft, uint64_t offset)
 {
     priv_t * aiff = (priv_t *) ft->priv;
     size_t new_offset, channel_block, alignment;
@@ -56,7 +56,7 @@
         new_offset += (channel_block - alignment);
     new_offset += aiff->dataStart;
 
-    ft->sox_errno = lsx_seeki(ft, (ptrdiff_t)new_offset, SEEK_SET);
+    ft->sox_errno = lsx_seeki(ft, (off_t)new_offset, SEEK_SET);
 
     if (ft->sox_errno == SOX_SUCCESS)
         aiff->nsamples = ft->signal.length - (new_offset / size);
@@ -87,7 +87,7 @@
         unsigned short nmarks = 0;
         unsigned short sustainLoopBegin = 0, sustainLoopEnd = 0,
                        releaseLoopBegin = 0, releaseLoopEnd = 0;
-        ptrdiff_t seekto = 0;
+        off_t seekto = 0;
         size_t ssndsize = 0;
         char *annotation;
         char *author;
@@ -176,7 +176,7 @@
                                 break;
                         /* else, seek to end of sound and hunt for more */
                         seekto = lsx_tell(ft);
-                        lsx_seeki(ft, (ptrdiff_t)chunksize, SEEK_CUR);
+                        lsx_seeki(ft, (off_t)chunksize, SEEK_CUR);
                 }
                 else if (strncmp(buf, "MARK", (size_t)4) == 0) {
                         /* MARK chunk */
@@ -593,7 +593,7 @@
 size_t sox_aiffread(sox_format_t * ft, sox_sample_t *buf, size_t len)
 {
         priv_t * aiff = (priv_t *) ft->priv;
-        ptrdiff_t done;
+        off_t done;
 
         if ((size_t)len > aiff->nsamples)
                 len = aiff->nsamples;
@@ -691,7 +691,7 @@
             lsx_fail_errno(ft,SOX_EOF,"Non-seekable file.");
             return(SOX_EOF);
         }
-        if (lsx_seeki(ft, (size_t)0, SEEK_SET) != 0)
+        if (lsx_seeki(ft, (off_t)0, SEEK_SET) != 0)
         {
                 lsx_fail_errno(ft,errno,"can't rewind output file to rewrite AIFF header");
                 return(SOX_EOF);
@@ -880,7 +880,7 @@
             lsx_fail_errno(ft,SOX_EOF,"Non-seekable file.");
             return(SOX_EOF);
         }
-        if (lsx_seeki(ft, (size_t)0, SEEK_SET) != 0)
+        if (lsx_seeki(ft, (off_t)0, SEEK_SET) != 0)
         {
                 lsx_fail_errno(ft,errno,"can't rewind output file to rewrite AIFC header");
                 return(SOX_EOF);
--- a/src/aiff.h
+++ b/src/aiff.h
@@ -20,7 +20,7 @@
     size_t dataStart; /* need to for seeking */
 } aiff_priv_t;
 
-int sox_aiffseek(sox_format_t * ft, size_t offset);
+int sox_aiffseek(sox_format_t * ft, uint64_t offset);
 int sox_aiffstartread(sox_format_t * ft);
 size_t sox_aiffread(sox_format_t * ft, sox_sample_t *buf, size_t len);
 int sox_aiffstopread(sox_format_t * ft);
--- a/src/avr.c
+++ b/src/avr.c
@@ -259,11 +259,11 @@
   unsigned size = avr->size / ft->signal.channels;
 
   /* Fix size */
-  lsx_seeki(ft, (size_t)26, SEEK_SET);
+  lsx_seeki(ft, (off_t)26, SEEK_SET);
   lsx_writedw (ft, size);
 
   /* Fix lend */
-  lsx_seeki(ft, (size_t)34, SEEK_SET);
+  lsx_seeki(ft, (off_t)34, SEEK_SET);
   lsx_writedw (ft, size);
 
   return(SOX_SUCCESS);
--- a/src/cvsd.c
+++ b/src/cvsd.c
@@ -425,7 +425,7 @@
                 sum += *pchs++;
         hdr->Crc = sum;
         put16_le(&pch, hdr->Crc);
-        if (lsx_seeki(ft, (size_t)0, SEEK_SET) < 0)
+        if (lsx_seeki(ft, (off_t)0, SEEK_SET) < 0)
         {
                 sox_report("seek failed\n: %s",strerror(errno));
                 return (SOX_EOF);
@@ -540,7 +540,7 @@
             sox_warn("File not seekable");
             return (SOX_EOF);
         }
-        if (lsx_seeki(ft, (size_t)0, 0) != 0)
+        if (lsx_seeki(ft, (off_t)0, 0) != 0)
         {
                 lsx_fail_errno(ft,errno,"Can't rewind output file to rewrite DVMS header.");
                 return(SOX_EOF);
--- a/src/flac.c
+++ b/src/flac.c
@@ -254,7 +254,7 @@
   (void) encoder;
   if (!ft->seekable)
     return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
-  else if (lsx_seeki(ft, (ptrdiff_t)absolute_byte_offset, SEEK_SET) != SOX_SUCCESS)
+  else if (lsx_seeki(ft, (off_t)absolute_byte_offset, SEEK_SET) != SOX_SUCCESS)
     return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
   else
     return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
@@ -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, size_t offset)
+static int seek(sox_format_t * ft, uint64_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/formats.c
+++ b/src/formats.c
@@ -810,7 +810,7 @@
   else {
     if (ft->handler.flags & SOX_FILE_REWIND) {
       if (ft->olength != ft->signal.length && ft->seekable) {
-        rc = lsx_seeki(ft, (size_t)0, 0);
+        rc = lsx_seeki(ft, (off_t)0, 0);
         if (rc == SOX_SUCCESS)
           rc = ft->handler.stopwrite? (*ft->handler.stopwrite)(ft)
              : ft->handler.startwrite?(*ft->handler.startwrite)(ft) : SOX_SUCCESS;
@@ -829,7 +829,7 @@
   return rc;
 }
 
-int sox_seek(sox_format_t * ft, size_t offset, int whence)
+int sox_seek(sox_format_t * ft, uint64_t offset, int whence)
 {
     /* FIXME: Implement SOX_SEEK_CUR and SOX_SEEK_END. */
     if (whence != SOX_SEEK_SET)
--- a/src/formats_i.c
+++ b/src/formats_i.c
@@ -153,7 +153,7 @@
   return fflush(ft->fp);
 }
 
-ptrdiff_t lsx_tell(sox_format_t * ft)
+off_t lsx_tell(sox_format_t * ft)
 {
   return ft->seekable? (ptrdiff_t)ftello(ft->fp) : ft->tell_off;
 }
@@ -189,7 +189,7 @@
  *
  * N.B. Can only seek forwards on non-seekable streams!
  */
-int lsx_seeki(sox_format_t * ft, ptrdiff_t offset, int whence)
+int lsx_seeki(sox_format_t * ft, off_t offset, int whence)
 {
     if (ft->seekable == 0) {
         /* If a stream peel off chars else EPERM */
@@ -206,7 +206,7 @@
         } else
             lsx_fail_errno(ft,SOX_EPERM, "file not seekable");
     } else {
-        if (fseeko(ft->fp, (off_t)offset, whence) == -1)
+        if (fseeko(ft->fp, offset, whence) == -1)
             lsx_fail_errno(ft,errno,strerror(errno));
         else
             ft->sox_errno = SOX_SUCCESS;
@@ -214,12 +214,12 @@
     return ft->sox_errno;
 }
 
-int lsx_offset_seek(sox_format_t * ft, off_t byte_offset, size_t to_sample)
+int lsx_offset_seek(sox_format_t * ft, off_t byte_offset, off_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, (ptrdiff_t)(byte_offset + to), SEEK_SET);
+  return (to != to_d)? SOX_EOF : lsx_seeki(ft, (byte_offset + to), SEEK_SET);
 }
 
 /* Read and write known datatypes in "machine format".  Swap if indicated.
--- a/src/maud.c
+++ b/src/maud.c
@@ -178,7 +178,7 @@
                 lsx_readdw(ft, &chunksize);
                 if (chunksize & 1)
                         chunksize++;
-                lsx_seeki(ft, (ptrdiff_t)chunksize, SEEK_CUR);
+                lsx_seeki(ft, (off_t)chunksize, SEEK_CUR);
                 continue;
 
         }
@@ -227,7 +227,7 @@
 {
         /* All samples are already written out. */
 
-        if (lsx_seeki(ft, (size_t)0, 0) != 0)
+        if (lsx_seeki(ft, (off_t)0, 0) != 0)
         {
             lsx_fail_errno(ft,errno,"can't rewind output file to rewrite MAUD header");
             return(SOX_EOF);
--- a/src/prc.c
+++ b/src/prc.c
@@ -68,11 +68,11 @@
 
 static void prcwriteheader(sox_format_t * ft);
 
-static int seek(sox_format_t * ft, size_t offset)
+static int seek(sox_format_t * ft, uint64_t offset)
 {
   priv_t * p = (priv_t *)ft->priv;
   if (ft->encoding.encoding == SOX_ENCODING_ALAW)
-    return lsx_offset_seek(ft, p->data_start, offset);
+    return lsx_offset_seek(ft, (off_t)p->data_start, (off_t)offset);
   return SOX_EOF;
 }
 
@@ -397,7 +397,7 @@
       return SOX_SUCCESS;
   }
 
-  if (lsx_seeki(ft, (size_t)0, 0) != 0) {
+  if (lsx_seeki(ft, (off_t)0, 0) != 0) {
       lsx_fail_errno(ft,errno,"Can't rewind output file to rewrite Psion header.");
       return(SOX_EOF);
   }
--- a/src/raw.c
+++ b/src/raw.c
@@ -15,9 +15,9 @@
 #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, size_t offset)
+int lsx_rawseek(sox_format_t * ft, uint64_t offset)
 {
-  return lsx_offset_seek(ft, (off_t)ft->data_start, offset);
+  return lsx_offset_seek(ft, (off_t)ft->data_start, (off_t)offset);
 }
 
 /* Works nicely for starting read and write; lsx_rawstart{read,write}
--- a/src/skelform.c
+++ b/src/skelform.c
@@ -183,7 +183,7 @@
   return SOX_SUCCESS;
 }
 
-static int seek(sox_format_t UNUSED * ft, size_t UNUSED offset)
+static int seek(sox_format_t UNUSED * ft, uint64_t UNUSED offset)
 {
   /* Seek relative to current position. */
   return SOX_SUCCESS;
--- a/src/smp.c
+++ b/src/smp.c
@@ -168,7 +168,7 @@
         return(SOX_SUCCESS);
 }
 
-static int sox_smpseek(sox_format_t * ft, size_t offset)
+static int sox_smpseek(sox_format_t * ft, uint64_t offset)
 {
     size_t new_offset, channel_block, alignment;
     priv_t * smp = (priv_t *) ft->priv;
@@ -185,7 +185,7 @@
         new_offset += (channel_block - alignment);
     new_offset += smp->dataStart;
 
-    ft->sox_errno = lsx_seeki(ft, (ptrdiff_t)new_offset, SEEK_SET);
+    ft->sox_errno = lsx_seeki(ft, (off_t)new_offset, SEEK_SET);
 
     if( ft->sox_errno == SOX_SUCCESS )
         smp->NoOfSamps = ft->signal.length - (new_offset / (ft->encoding.bits_per_sample >> 3));
@@ -251,7 +251,7 @@
 
         /* seek from the current position (the start of sample data) by */
         /* NoOfSamps * sizeof(int16_t) */
-        if (lsx_seeki(ft, (ptrdiff_t)(smp->NoOfSamps * 2), 1) == -1)
+        if (lsx_seeki(ft, (off_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, (ptrdiff_t)samplestart, 0) == -1)
+        if (lsx_seeki(ft, (off_t)samplestart, 0) == -1)
         {
                 lsx_fail_errno(ft,errno,"SMP unable to seek back to start of sample data");
                 return(SOX_EOF);
@@ -385,7 +385,7 @@
         /* Assign the trailer data */
         settrailer(ft, &trailer, ft->signal.rate);
         writetrailer(ft, &trailer);
-        if (lsx_seeki(ft, (size_t)112, 0) == -1)
+        if (lsx_seeki(ft, (off_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
@@ -146,39 +146,39 @@
   int format;
 } format_map[] =
 {
-  { "aif",	SF_FORMAT_AIFF },
-  { "aiff",	SF_FORMAT_AIFF },
-  { "wav",	SF_FORMAT_WAV },
-  { "au",	SF_FORMAT_AU },
-  { "snd",	SF_FORMAT_AU },
+  { "aif",      SF_FORMAT_AIFF },
+  { "aiff",     SF_FORMAT_AIFF },
+  { "wav",      SF_FORMAT_WAV },
+  { "au",       SF_FORMAT_AU },
+  { "snd",      SF_FORMAT_AU },
 #ifdef HAVE_SNDFILE_1_0_12
-  { "caf",	SF_FORMAT_CAF },
-  { "flac",	SF_FORMAT_FLAC },
+  { "caf",      SF_FORMAT_CAF },
+  { "flac",     SF_FORMAT_FLAC },
 #endif
 #ifdef HAVE_SNDFILE_1_0_18
-  { "wve",	SF_FORMAT_WVE },
-  { "ogg",	SF_FORMAT_OGG },
+  { "wve",      SF_FORMAT_WVE },
+  { "ogg",      SF_FORMAT_OGG },
 #endif
-  { "svx",	SF_FORMAT_SVX },
+  { "svx",      SF_FORMAT_SVX },
   { "8svx",     SF_FORMAT_SVX },
-  { "paf",	SF_ENDIAN_BIG | SF_FORMAT_PAF },
-  { "fap",	SF_ENDIAN_LITTLE | SF_FORMAT_PAF },
-  { "gsm",	SF_FORMAT_RAW | SF_FORMAT_GSM610 },
-  { "nist", 	SF_FORMAT_NIST },
+  { "paf",      SF_ENDIAN_BIG | SF_FORMAT_PAF },
+  { "fap",      SF_ENDIAN_LITTLE | SF_FORMAT_PAF },
+  { "gsm",      SF_FORMAT_RAW | SF_FORMAT_GSM610 },
+  { "nist",     SF_FORMAT_NIST },
   { "sph",      SF_FORMAT_NIST },
-  { "ircam",	SF_FORMAT_IRCAM },
-  { "sf",	SF_FORMAT_IRCAM },
-  { "voc",	SF_FORMAT_VOC },
-  { "w64", 	SF_FORMAT_W64 },
-  { "raw",	SF_FORMAT_RAW },
-  { "mat4", 	SF_FORMAT_MAT4 },
-  { "mat5", 	SF_FORMAT_MAT5 },
-  { "mat",	SF_FORMAT_MAT4 },
-  { "pvf",	SF_FORMAT_PVF },
-  { "sds",	SF_FORMAT_SDS },
-  { "sd2",	SF_FORMAT_SD2 },
-  { "vox",	SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM },
-  { "xi",	SF_FORMAT_XI }
+  { "ircam",    SF_FORMAT_IRCAM },
+  { "sf",       SF_FORMAT_IRCAM },
+  { "voc",      SF_FORMAT_VOC },
+  { "w64",      SF_FORMAT_W64 },
+  { "raw",      SF_FORMAT_RAW },
+  { "mat4",     SF_FORMAT_MAT4 },
+  { "mat5",     SF_FORMAT_MAT5 },
+  { "mat",      SF_FORMAT_MAT4 },
+  { "pvf",      SF_FORMAT_PVF },
+  { "sds",      SF_FORMAT_SDS },
+  { "sd2",      SF_FORMAT_SD2 },
+  { "vox",      SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM },
+  { "xi",       SF_FORMAT_XI }
 };
 
 /* Convert file name or type to libsndfile format */
@@ -394,7 +394,7 @@
   return SOX_SUCCESS;
 }
 
-static int seek(sox_format_t * ft, size_t offset)
+static int seek(sox_format_t * ft, uint64_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/sox.c
+++ b/src/sox.c
@@ -1019,7 +1019,7 @@
    * managable chunks.  */
   if (input_count == 1 && effects_chain->length > 1 && strcmp(effects_chain->effects[1][0].handler.name, "trim") == 0) {
     if (files[0]->ft->handler.seek && files[0]->ft->seekable){
-      size_t offset = sox_trim_get_start(&effects_chain->effects[1][0]);
+      uint64_t offset = sox_trim_get_start(&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
--- a/src/sox.h
+++ b/src/sox.h
@@ -323,7 +323,7 @@
   int          (*startwrite)(sox_format_t * ft);
   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, size_t offset);
+  int          (*seek)(sox_format_t * ft, uint64_t offset);
   unsigned     const * write_formats;
   sox_rate_t   const * write_rates;
   size_t       priv_size;
@@ -413,7 +413,7 @@
 int sox_close(sox_format_t * ft);
 
 #define SOX_SEEK_SET 0
-int sox_seek(sox_format_t * ft, size_t offset, int whence);
+int sox_seek(sox_format_t * ft, uint64_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);
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -34,6 +34,7 @@
 #define off_t long
 #endif
 #endif
+
 #ifdef _FILE_OFFSET_BITS
 assert_static(sizeof(off_t) == _FILE_OFFSET_BITS >> 3, OFF_T_BUILD_PROBLEM);
 #endif
@@ -153,14 +154,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, ptrdiff_t offset, int whence);
+int lsx_seeki(sox_format_t * ft, off_t offset, int whence);
 int lsx_unreadb(sox_format_t * ft, unsigned ub);
 size_t lsx_filelength(sox_format_t * ft);
-ptrdiff_t lsx_tell(sox_format_t * ft);
+off_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, size_t to_sample);
+int lsx_offset_seek(sox_format_t * ft, off_t byte_offset, off_t to_sample);
 
 void lsx_fail_errno(sox_format_t *, int, const char *, ...)
 #ifdef __GNUC__
@@ -192,7 +193,7 @@
 int lsx_rawstopread(sox_format_t * ft);
 int lsx_rawstartwrite(sox_format_t * ft);
 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_rawseek(sox_format_t * ft, uint64_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/sphere.c
+++ b/src/sphere.c
@@ -122,7 +122,7 @@
 
     if (lsx_readchars(ft, shorten_check, sizeof(shorten_check)))
       return SOX_EOF;
-    lsx_seeki(ft, -(ptrdiff_t)sizeof(shorten_check), SEEK_CUR);
+    lsx_seeki(ft, -(off_t)sizeof(shorten_check), SEEK_CUR);
 
     if (!memcmp(shorten_check, "ajkg", sizeof(shorten_check))) {
       lsx_fail_errno(ft, SOX_EFMT,
--- a/src/tx16w.c
+++ b/src/tx16w.c
@@ -93,7 +93,7 @@
     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, (size_t)0, 0);           /* rewind file */
+    lsx_seeki(ft, (off_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 */
--- a/src/voc.c
+++ b/src/voc.c
@@ -511,14 +511,14 @@
   sox_sample_t datum;
 
   lsx_writeb(ft, 0);    /* End of file block code */
-  lsx_seeki(ft, (ptrdiff_t) v->blockseek, 0); /* seek back to block length */
-  lsx_seeki(ft, (size_t)1, 1);  /* seek forward one */
+  lsx_seeki(ft, (off_t) v->blockseek, 0); /* seek back to block length */
+  lsx_seeki(ft, (off_t)1, 1);  /* seek forward one */
   if (v->silent) {
     lsx_writesw(ft, (signed)v->samples);
   } else {
     if (ft->encoding.bits_per_sample == 8) {
       if (ft->signal.channels > 1) {
-        lsx_seeki(ft, (size_t)8, 1);    /* forward 7 + 1 for new block header */
+        lsx_seeki(ft, (off_t)8, 1);    /* forward 7 + 1 for new block header */
       }
     }
     v->samples += 2;    /* adjustment: SBDK pp. 3-5 */
--- a/src/vorbis.c
+++ b/src/vorbis.c
@@ -383,7 +383,7 @@
   return (SOX_SUCCESS);
 }
 
-static int seek(sox_format_t * ft, size_t offset)
+static int seek(sox_format_t * ft, uint64_t offset)
 {
   priv_t * vb = (priv_t *) ft->priv;
 
--- a/src/wav.c
+++ b/src/wav.c
@@ -383,7 +383,7 @@
             break; /* Found the given chunk */
 
         /* skip to next chunk */
-        if (*len == 0 || lsx_seeki(ft, (ptrdiff_t)(*len), SEEK_CUR) != SOX_SUCCESS)
+        if (*len == 0 || lsx_seeki(ft, (off_t)(*len), SEEK_CUR) != SOX_SUCCESS)
         {
             lsx_fail_errno(ft,SOX_EHDR,
                           "WAV chunk appears to have invalid size %d.", *len);
@@ -774,7 +774,7 @@
     }
 
     /* Skip anything left over from fmt chunk */
-    lsx_seeki(ft, (ptrdiff_t)len, SEEK_CUR);
+    lsx_seeki(ft, (off_t)len, SEEK_CUR);
 
     /* for non-PCM formats, there's a 'fact' chunk before
      * the upcoming 'data' chunk */
@@ -862,7 +862,7 @@
          * doubt any machine writing Cool Edit Chunks writes them at an odd
          * offset */
         len = (len + 1) & ~1u;
-        if (lsx_seeki(ft, (ptrdiff_t)len, SEEK_CUR) == SOX_SUCCESS &&
+        if (lsx_seeki(ft, (off_t)len, SEEK_CUR) == SOX_SUCCESS &&
             findChunk(ft, "LIST", &len) != SOX_EOF)
         {
             wav->comment = lsx_malloc((size_t)256);
@@ -909,7 +909,7 @@
                             strcat(wav->comment,text);
                         }
                         if (strlen(text) < len)
-                           lsx_seeki(ft, (ptrdiff_t)(len - strlen(text)), SEEK_CUR);
+                           lsx_seeki(ft, (off_t)(len - strlen(text)), SEEK_CUR);
                     }
                     else if (strncmp(magic,"ISFT",(size_t)4) == 0)
                     {
@@ -928,12 +928,12 @@
                             strcat(wav->comment,text);
                         }
                         if (strlen(text) < len)
-                           lsx_seeki(ft, (ptrdiff_t)(len - strlen(text)), SEEK_CUR);
+                           lsx_seeki(ft, (off_t)(len - strlen(text)), SEEK_CUR);
                     }
                     else if (strncmp(magic,"cue ",(size_t)4) == 0)
                     {
                         sox_debug("Chunk cue ");
-                        lsx_seeki(ft,(ptrdiff_t)(len-4),SEEK_CUR);
+                        lsx_seeki(ft,(off_t)(len-4),SEEK_CUR);
                         lsx_readdw(ft,&dwLoopPos);
                         ft->oob.loops[0].start = dwLoopPos;
                     }
@@ -943,19 +943,19 @@
                         lsx_readdw(ft,&dwLoopPos);
                         ft->oob.loops[0].length = dwLoopPos - ft->oob.loops[0].start;
                         if (len > 4)
-                           lsx_seeki(ft, (ptrdiff_t)(len - 4), SEEK_CUR);
+                           lsx_seeki(ft, (off_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, (ptrdiff_t)len, SEEK_CUR);
+                        lsx_seeki(ft, (off_t)len, SEEK_CUR);
                     }
                 }
             }
         }
         lsx_clearerr(ft);
-        lsx_seeki(ft,(ptrdiff_t)wav->dataStart,SEEK_SET);
+        lsx_seeki(ft,(off_t)wav->dataStart,SEEK_SET);
     }
     return lsx_rawstartread(ft);
 }
@@ -1499,7 +1499,7 @@
         if (!ft->seekable)
           return SOX_EOF;
 
-        if (lsx_seeki(ft, (ptrdiff_t)0, SEEK_SET) != 0)
+        if (lsx_seeki(ft, (off_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, size_t offset)
+static int seek(sox_format_t * ft, uint64_t offset)
 {
   priv_t *   wav = (priv_t *) ft->priv;
 
@@ -1576,7 +1576,7 @@
              wav->blockAlign * ft->signal.channels / 2;
     gsmoff -= gsmoff % (wav->blockAlign * ft->signal.channels);
 
-    ft->sox_errno = lsx_seeki(ft, (ptrdiff_t)(gsmoff + wav->dataStart), SEEK_SET);
+    ft->sox_errno = lsx_seeki(ft, (off_t)(gsmoff + wav->dataStart), SEEK_SET);
     if (ft->sox_errno == SOX_SUCCESS) {
       /* offset is in samples */
       new_offset = offset;
@@ -1589,7 +1589,7 @@
     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, (ptrdiff_t)wav->dataStart + (ptrdiff_t)to, SEEK_SET);
+    ft->sox_errno = (to != to_d)? SOX_EOF : lsx_seeki(ft, (off_t)wav->dataStart + (off_t)to, SEEK_SET);
     if (ft->sox_errno == SOX_SUCCESS)
       wav->numSamples -= (size_t)wide_sample / ft->signal.channels;
   }