shithub: sox

Download patch

ref: b5f2e419a4aab441c61f6c21142e57d469a1ffda
parent: 1a8314ff7545cc3b13e31a071cb92a13ada78427
author: robs <robs>
date: Sat Feb 16 11:43:22 EST 2008

fixing warnings

diff: cannot open a/src/amr-wb-vectors//null: file does not exist: 'a/src/amr-wb-vectors//null'
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -181,7 +181,7 @@
                     sox_fail_errno (ft,errno,"Can't position channel %d",i);
                     return(SOX_EOF);
                 }
-                if (fseeko(p->ch[i],(off_t)p->nsamples/channels*i,SEEK_CUR))
+                if (fseeko(p->ch[i],(off_t)(p->nsamples/channels*i),SEEK_CUR))
                 {
                     sox_fail_errno (ft,errno,"Can't seek channel %d",i);
                     return(SOX_EOF);
@@ -302,7 +302,10 @@
                 }
                 while (!feof(p->ch[i])) {
                         len = fread(svxbuf, 1, 512, p->ch[i]);
-                        fwrite (svxbuf, 1, len, p->ch[0]);
+                        if (fwrite (svxbuf, 1, len, p->ch[0]) != len) {
+                          sox_fail_errno (ft,errno,"Can't write channel output file %d",i);
+                          return SOX_EOF;
+                        }
                 }
                 fclose (p->ch[i]);
         }
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -3,7 +3,7 @@
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
 if(CMAKE_COMPILER_IS_GNUCC)
-#  add_definitions(-Wconversion)
+  add_definitions(-Wconversion)
 endif(CMAKE_COMPILER_IS_GNUCC)
 
 if (NOT EXTERNAL_GSM)
--- a/src/FFT.h
+++ b/src/FFT.h
@@ -78,9 +78,9 @@
 /*
  * Applies a windowing function to the data in place
  */
-typedef enum {RECTANGULAR = 0, /* no window */
-              BARTLETT = 1,    /* triangular */
-              HAMMING = 2,
-              HANNING = 3} windowfunc_t;
+typedef enum {RECTANGULAR, /* no window */
+              BARTLETT,    /* triangular */
+              HAMMING,
+              HANNING} windowfunc_t;
 
 void WindowFunc(windowfunc_t whichFunction, int NumSamples, float *data);
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,7 @@
 RM = rm -f 
 
 AM_CPPFLAGS = -DLADSPA_PATH="\"@LADSPA_PATH@\"" -DPKGLIBDIR="\"$(pkglibdir)\""
-AM_CFLAGS = #-Wconversion
+AM_CFLAGS = -Wconversion #-Werror
 
 # Pass flags from --enable-silent-libtool
 LIBTOOL = @LIBTOOL@ @LIBTOOLFLAGS@
@@ -20,7 +20,7 @@
 sox_LDADD = libsox.la libsfx.la
 example1_SOURCES = example1.c
 example1_LDADD = libsox.la libsfx.la
-sox_sample_test_SOURCES = sox_sample_test.c
+sox_sample_test_SOURCES = sox_sample_test.c sox_sample_test.h
 
 #############################################
 # libsox Dynamic Libraries for File Formats #
@@ -143,12 +143,12 @@
 pkglib_LTLIBRARIES += libsox_fmt_sndfile.la
 endif
 if HAVE_AMRWB
-libsox_fmt_amr_wb_la_SOURCES = amr-wb.c amr.h
+libsox_fmt_amr_wb_la_SOURCES = amr-wb.c amr.h amr1.h amr2.h
 libsox_fmt_amr_wb_la_LIBADD = libsox.la @AMR_WB_LIBS@
 pkglib_LTLIBRARIES += libsox_fmt_amr_wb.la
 endif
 if HAVE_AMRNB
-libsox_fmt_amr_nb_la_SOURCES = amr-nb.c amr.h
+libsox_fmt_amr_nb_la_SOURCES = amr-nb.c amr.h amr1.h amr2.h
 libsox_fmt_amr_nb_la_LIBADD = libsox.la @AMR_NB_LIBS@
 pkglib_LTLIBRARIES += libsox_fmt_amr_nb.la
 endif
@@ -158,7 +158,7 @@
 pkglib_LTLIBRARIES += libsox_fmt_mp3.la
 endif
 if HAVE_OGG_VORBIS
-libsox_fmt_vorbis_la_SOURCES = vorbis.c
+libsox_fmt_vorbis_la_SOURCES = vorbis.c vorbis1.h
 libsox_fmt_vorbis_la_LIBADD = libsox.la @OGG_LIBS@
 pkglib_LTLIBRARIES += libsox_fmt_vorbis.la
 endif
@@ -245,12 +245,12 @@
     sox_LDADD += @SNDFILE_LIBS@
 endif
 if HAVE_AMRWB
-    libsox_la_SOURCES += amr-wb.c amr.h
+    libsox_la_SOURCES += amr-wb.c amr.h amr1.h amr2.h
     libsox_la_LIBADD += @AMR_WB_LIBS@
     sox_LDADD += @AMR_WB_LIBS@
 endif
 if HAVE_AMRNB
-    libsox_la_SOURCES += amr-nb.c amr.h
+    libsox_la_SOURCES += amr-nb.c amr.h amr1.h amr2.h
     libsox_la_LIBADD += @AMR_NB_LIBS@
     sox_LDADD += @AMR_NB_LIBS@
 endif
@@ -260,7 +260,7 @@
     sox_LDADD += @MP3_LIBS@
 endif
 if HAVE_OGG_VORBIS
-    libsox_la_SOURCES += vorbis.c
+    libsox_la_SOURCES += vorbis.c vorbis1.h
     libsox_la_LIBADD += @OGG_LIBS@
     sox_LDADD += @OGG_LIBS@
 endif
@@ -286,7 +286,9 @@
 #end !HAVE_LIBLTDL
 endif
 
-EXTRA_DIST = tests.sh testall.sh tests.bat testall.bat monkey.au monkey.wav sox_sample_test.c amr-wb-test CMakeLists.txt soxstdint.h.cmake soxconfig.h.cmake example1.c test-comments
+EXTRA_DIST = tests.sh testall.sh tests.bat testall.bat test-comments \
+	     monkey.au monkey.wav \
+	     amr-wb-test CMakeLists.txt soxstdint.h.cmake soxconfig.h.cmake
 
 all: sox$(EXEEXT) play rec soxi sox_sample_test$(EXEEXT) example1$(EXEEXT)
 
--- a/src/amr-wb-test
+++ /dev/null
@@ -1,30 +1,0 @@
-#!/bin/sh
-
-exit 0 # FIXME: temporarily disabled whilst tring out new amr source
-
-testv=amr-wb-vectors
-
-test() {
-  c=coded-$compression-$input.amr-wb
-  d=decoded-$compression-$input.au
-  ./sox $testv/input-$input.au -C$compression $c
-  cmp $c $testv/$c || exit 1
-  ./sox $c --comment= $d
-  cmp $d $testv/$d || exit 1
-  rm $c $d
-}
-
-input=sing
-compression=8
-while [ $compression \-ge 0 ]; do
-  output=tst_m$compression
-  test
-  compression=`expr $compression \- 1`
-done
-
-input=dtx
-compression=2
-output=coded
-test
-
-exit 0
binary files a/src/amr-wb-vectors/coded-0-sing.amr-wb /dev/null differ
binary files a/src/amr-wb-vectors/coded-1-sing.amr-wb /dev/null differ
binary files a/src/amr-wb-vectors/coded-2-dtx.amr-wb /dev/null differ
binary files a/src/amr-wb-vectors/coded-2-sing.amr-wb /dev/null differ
binary files a/src/amr-wb-vectors/coded-3-sing.amr-wb /dev/null differ
binary files a/src/amr-wb-vectors/coded-4-sing.amr-wb /dev/null differ
binary files a/src/amr-wb-vectors/coded-5-sing.amr-wb /dev/null differ
binary files a/src/amr-wb-vectors/coded-6-sing.amr-wb /dev/null differ
binary files a/src/amr-wb-vectors/coded-7-sing.amr-wb /dev/null differ
binary files a/src/amr-wb-vectors/coded-8-sing.amr-wb /dev/null differ
binary files a/src/amr-wb-vectors/decoded-0-sing.au /dev/null differ
binary files a/src/amr-wb-vectors/decoded-1-sing.au /dev/null differ
binary files a/src/amr-wb-vectors/decoded-2-dtx.au /dev/null differ
binary files a/src/amr-wb-vectors/decoded-2-sing.au /dev/null differ
binary files a/src/amr-wb-vectors/decoded-3-sing.au /dev/null differ
binary files a/src/amr-wb-vectors/decoded-4-sing.au /dev/null differ
binary files a/src/amr-wb-vectors/decoded-5-sing.au /dev/null differ
binary files a/src/amr-wb-vectors/decoded-6-sing.au /dev/null differ
binary files a/src/amr-wb-vectors/decoded-7-sing.au /dev/null differ
binary files a/src/amr-wb-vectors/decoded-8-sing.au /dev/null differ
binary files a/src/amr-wb-vectors/input-dtx.au /dev/null differ
binary files a/src/amr-wb-vectors/input-sing.au /dev/null differ
--- a/src/amr.h
+++ b/src/amr.h
@@ -45,11 +45,15 @@
   return 0;
 }
 
-static void encode_1_frame(sox_format_t * ft)
+static sox_bool encode_1_frame(sox_format_t * ft)
 {
   amr_t amr = (amr_t) ft->priv;
   UWord8 coded[AMR_CODED_MAX];
-  fwrite(coded, 1, (unsigned)E_IF_encode(amr->state, amr->mode, amr->pcm, coded, 1), ft->fp);
+#include "amr1.h"
+  sox_bool result = fwrite(coded, (unsigned)n, 1, ft->fp) == 1;
+  if (!result)
+    sox_fail_errno(ft, errno, "write error");
+  return result;
 }
 
 static void set_format(sox_format_t * ft)
@@ -63,18 +67,19 @@
 static int startread(sox_format_t * ft)
 {
   amr_t amr = (amr_t) ft->priv;
-  char buffer[sizeof(magic)];
+  char buffer[sizeof(magic) - 1];
 
   amr->pcm_index = AMR_FRAME;
-
   amr->state = D_IF_init();
 
-  fread(buffer, sizeof(char), sizeof(buffer) - 1, ft->fp);
-  buffer[sizeof(buffer) - 1] = 0;
-  if (strcmp(buffer, magic)) {
-    sox_fail("Invalid magic number");
+  if (fread(buffer, sizeof(buffer), 1, ft->fp) != 1) {
+    sox_fail_errno(ft, errno, "read error");
     return SOX_EOF;
   }
+  if (memcmp(buffer, magic, sizeof(buffer))) {
+    sox_fail_errno(ft, SOX_EHDR, "invalid magic number");
+    return SOX_EOF;
+  }
   set_format(ft);
   return SOX_SUCCESS;
 }
@@ -115,7 +120,7 @@
   else amr->mode = 0;
 
   set_format(ft);
-  amr->state = E_IF_init();
+#include "amr2.h"
   sox_writes(ft, magic);
   amr->pcm_index = 0;
   return SOX_SUCCESS;
@@ -130,7 +135,8 @@
     amr->pcm[amr->pcm_index++] = SOX_SAMPLE_TO_SIGNED_16BIT(*buf++, ft->clips);
     if (amr->pcm_index == AMR_FRAME) {
       amr->pcm_index = 0;
-      encode_1_frame(ft);
+      if (!encode_1_frame(ft))
+        return 0;
     }
   }
   return done;
@@ -139,15 +145,17 @@
 static int stopwrite(sox_format_t * ft)
 {
   amr_t amr = (amr_t) ft->priv;
+  int result = SOX_SUCCESS;
 
   if (amr->pcm_index) {
     do {
       amr->pcm[amr->pcm_index++] = 0;
     } while (amr->pcm_index < AMR_FRAME);
-    encode_1_frame(ft);
+    if (!encode_1_frame(ft))
+      result = SOX_EOF;
   }
   E_IF_exit(amr->state);
-  return SOX_SUCCESS;
+  return result;
 }
 
 const sox_format_handler_t *AMR_FORMAT_FN(void);
--- /dev/null
+++ b/src/amr1.h
@@ -1,0 +1,15 @@
+#if defined __GNUC__ 
+  #pragma GCC system_header 
+#elif defined __SUNPRO_CC 
+  #pragma disable_warn 
+#elif defined _MSC_VER 
+  #pragma warning(push, 1) 
+#endif 
+
+  int n = E_IF_encode(amr->state, amr->mode, amr->pcm, coded, 1);
+
+#if defined __SUNPRO_CC 
+  #pragma enable_warn 
+#elif defined _MSC_VER 
+  #pragma warning(pop) 
+#endif 
--- /dev/null
+++ b/src/amr2.h
@@ -1,0 +1,15 @@
+#if defined __GNUC__ 
+  #pragma GCC system_header 
+#elif defined __SUNPRO_CC 
+  #pragma disable_warn 
+#elif defined _MSC_VER 
+  #pragma warning(push, 1) 
+#endif 
+
+  amr->state = E_IF_init();
+
+#if defined __SUNPRO_CC 
+  #pragma enable_warn 
+#elif defined _MSC_VER 
+  #pragma warning(pop) 
+#endif 
--- a/src/au.c
+++ b/src/au.c
@@ -382,7 +382,7 @@
         return(SOX_SUCCESS);
 }
 
-static unsigned sox_ausunencoding(int size, sox_encoding_t encoding)
+static unsigned sox_ausunencoding(unsigned size, sox_encoding_t encoding)
 {
         unsigned sun_encoding;
 
--- a/src/avr.c
+++ b/src/avr.c
@@ -211,7 +211,7 @@
   sox_writew (ft, 0xffff);
 
   /* rate */
-  sox_writedw (ft, ft->signal.rate);
+  sox_writedw(ft, (unsigned)(ft->signal.rate + .5));
 
   /* size */
   /* Don't know the size yet. */
--- a/src/effects.h
+++ b/src/effects.h
@@ -43,8 +43,8 @@
   EFFECT(rabbit)
 #endif
   EFFECT(rate)
-  EFFECT(repeat)
   EFFECT(remix)
+  EFFECT(repeat)
   EFFECT(resample)
   EFFECT(reverb)
   EFFECT(reverse)
--- a/src/flac.c
+++ b/src/flac.c
@@ -273,7 +273,7 @@
   (void) encoder;
   if (!ft->seekable)
     return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
-  else if (sox_seeki(ft, (sox_size_t)absolute_byte_offset, SEEK_SET) != SOX_SUCCESS)
+  else if (sox_seeki(ft, (sox_ssize_t)absolute_byte_offset, SEEK_SET) != SOX_SUCCESS)
     return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
   else
     return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
@@ -400,7 +400,7 @@
     }
     {
 #if FLAC_API_VERSION_CURRENT >= 8
-      if (!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(encoder->metadata[encoder->num_metadata], 10 * ft->signal.rate, (FLAC__uint64)(ft->length/ft->signal.channels))) {
+      if (!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(encoder->metadata[encoder->num_metadata], (unsigned)(10 * ft->signal.rate + .5), (FLAC__uint64)(ft->length/ft->signal.channels))) {
 #else
       sox_size_t samples = 10 * ft->signal.rate;
       sox_size_t total_samples = ft->length/ft->signal.channels;
--- a/src/ladspa.c
+++ b/src/ladspa.c
@@ -87,7 +87,7 @@
 {
   ladspa_t l_st = (ladspa_t)effp->priv;
   char *path;
-  LADSPA_Descriptor_Function l_fn;
+  union {LADSPA_Descriptor_Function fn; lt_ptr ptr;} ltptr;
   unsigned long index = 0, i;
   double arg;
 
@@ -111,26 +111,26 @@
   }
 
   /* Get descriptor function */
-  if ((l_fn = (LADSPA_Descriptor_Function)lt_dlsym(l_st->lth, "ladspa_descriptor")) == NULL) {
+  if ((ltptr.ptr = lt_dlsym(l_st->lth, "ladspa_descriptor")) == NULL) {
     sox_fail("could not find ladspa_descriptor");
     return SOX_EOF;
   }
 
   /* If no plugins in this module, complain */
-  if (l_fn(0) == NULL) {
+  if (ltptr.fn(0) == NULL) {
     sox_fail("no plugins found");
     return SOX_EOF;
   }
 
   /* Get first plugin descriptor */
-  l_st->desc = l_fn(0);
+  l_st->desc = ltptr.fn(0);
   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 && (l_fn(1) != NULL || !sscanf(argv[0], "%lf", &arg))) {
+  if (n > 0 && (ltptr.fn(1) != NULL || !sscanf(argv[0], "%lf", &arg))) {
     while (l_st->desc && strcmp(l_st->desc->Label, argv[0]) != 0)
-      l_st->desc = l_fn(++index);
+      l_st->desc = ltptr.fn(++index);
     if (l_st->desc == NULL) {
       sox_fail("no plugin called `%s' found", argv[0]);
       return SOX_EOF;
--- a/src/maud.c
+++ b/src/maud.c
@@ -276,35 +276,35 @@
         switch (ft->signal.encoding) {
                 
         case SOX_ENCODING_UNSIGNED:
-                sox_writew(ft, (int) 8); /* number of bits per sample as stored in MDAT */
-                sox_writew(ft, (int) 8); /* number of bits per sample after decompression */
-                break;
+          sox_writew(ft, 8); /* number of bits per sample as stored in MDAT */
+          sox_writew(ft, 8); /* number of bits per sample after decompression */
+          break;
                 
         case SOX_ENCODING_SIGN2:
-                sox_writew(ft, (int) 16); /* number of bits per sample as stored in MDAT */
-                sox_writew(ft, (int) 16); /* number of bits per sample after decompression */
-                break;
+          sox_writew(ft, 16); /* number of bits per sample as stored in MDAT */
+          sox_writew(ft, 16); /* number of bits per sample after decompression */
+          break;
                 
         case SOX_ENCODING_ALAW:
         case SOX_ENCODING_ULAW:
-                sox_writew(ft, (int) 8); /* number of bits per sample as stored in MDAT */
-                sox_writew(ft, (int) 16); /* number of bits per sample after decompression */
-                break;
+          sox_writew(ft, 8); /* number of bits per sample as stored in MDAT */
+          sox_writew(ft, 16); /* number of bits per sample after decompression */
+          break;
 
         default:
-                break;
+          break;
         }
         
-        sox_writedw(ft, ft->signal.rate); /* clock source frequency */
+        sox_writedw(ft, (unsigned)(ft->signal.rate + .5)); /* sample rate, Hz */
         sox_writew(ft, (int) 1); /* clock devide */
         
         if (ft->signal.channels == 1) {
-                sox_writew(ft, (int) 0); /* channel information */
-                sox_writew(ft, (int) 1); /* number of channels (mono: 1, stereo: 2, ...) */
+          sox_writew(ft, 0); /* channel information */
+          sox_writew(ft, 1); /* number of channels (mono: 1, stereo: 2, ...) */
         }
         else {
-                sox_writew(ft, (int) 1);
-                sox_writew(ft, (int) 2);
+          sox_writew(ft, 1);
+          sox_writew(ft, 2);
         }
         
         switch (ft->signal.encoding) {
@@ -311,19 +311,19 @@
                 
         case SOX_ENCODING_UNSIGNED:
         case SOX_ENCODING_SIGN2:
-                sox_writew(ft, (int) 0); /* no compression */
-                break;
+          sox_writew(ft, 0); /* no compression */
+          break;
                 
         case SOX_ENCODING_ULAW:
-                sox_writew(ft, (int) 3);
-                break;
+          sox_writew(ft, 3);
+          break;
                 
         case SOX_ENCODING_ALAW:
-                sox_writew(ft, (int) 2);
-                break;
+          sox_writew(ft, 2);
+          break;
 
         default:
-                break;
+          break;
         }
         
         sox_writedw(ft, 0); /* reserved */
--- a/src/misc.c
+++ b/src/misc.c
@@ -285,7 +285,7 @@
 }
 
 /* return swapped 32-bit float */
-float sox_swapf(float f)
+void sox_swapf(float * f)
 {
     union {
         uint32_t dw;
@@ -292,9 +292,9 @@
         float f;
     } u;
 
-    u.f= f;
+    u.f= *f;
     u.dw= (u.dw>>24) | ((u.dw>>8)&0xff00) | ((u.dw<<8)&0xff0000) | (u.dw<<24);
-    return u.f;
+    *f = u.f;
 }
 
 uint32_t sox_swap3(uint24_t udw)
@@ -526,7 +526,7 @@
   return result;
 }
 
-enum_item const * find_enum_value(int value, enum_item const * enum_items)
+enum_item const * find_enum_value(unsigned value, enum_item const * enum_items)
 {
   for (;enum_items->text; ++enum_items)
     if (value == enum_items->value)
@@ -541,11 +541,11 @@
 
 sox_bool is_uri(char const * text)
 {
-  if (!isalpha(*text))
+  if (!isalpha((int)*text))
     return sox_false;
   ++text;
   do {
-    if (!isalnum(*text) && !strchr("+-.", *text))
+    if (!isalnum((int)*text) && !strchr("+-.", *text))
       return sox_false;
     ++text;
   } while (*text && *text != ':');
--- a/src/rabbit.c
+++ b/src/rabbit.c
@@ -93,7 +93,7 @@
   r->data = (SRC_DATA *)xcalloc(1, sizeof(SRC_DATA));
   r->data->src_ratio = out_rate / effp->ininfo.rate;
   r->i_alloc = r->o_alloc = 0;
-  r->state = src_new(r->converter_type, effp->ininfo.channels, &err);
+  r->state = src_new(r->converter_type, (int)effp->ininfo.channels, &err);
   if (err) {
     free(r->data);
     sox_fail("cannot initialise rabbit: %s", src_strerror(err));
--- a/src/sf.c
+++ b/src/sf.c
@@ -102,7 +102,7 @@
         }
         memcpy(&sf->info, &sfhead.sfinfo, sizeof(struct sfinfo));
         if (ft->signal.reverse_bytes) {
-                sf->info.sf_srate = sox_swapf(sf->info.sf_srate);
+                sox_swapf(&sf->info.sf_srate);
                 sf->info.sf_packmode = sox_swapdw(sf->info.sf_packmode);
                 sf->info.sf_chans = sox_swapdw(sf->info.sf_chans);
         }
--- a/src/sndfile.c
+++ b/src/sndfile.c
@@ -77,9 +77,9 @@
    is encoding if conversion was made, or SOX_ENCODING_UNKNOWN for
    invalid input. If the libsndfile subtype can't be represented in
    SoX types, use 16-bit signed. */
-static sox_encoding_t sox_encoding_and_size(int format, unsigned * size)
+static sox_encoding_t sox_encoding_and_size(unsigned format, unsigned * size)
 {
-  *size = -1;                   /* Default */
+  *size = 0;                   /* Default */
   format &= SF_FORMAT_SUBMASK;
   
   switch (format) {
@@ -208,7 +208,7 @@
 }
 
 /* Make libsndfile subtype from sample encoding and size */
-static int sndfile_format(sox_encoding_t encoding, int size)
+static int sndfile_format(sox_encoding_t encoding, unsigned size)
 {
   if (encoding < SOX_ENCODING_SIZE_IS_WORD) {
     switch (encoding) {
@@ -304,7 +304,7 @@
   }
 
   /* Copy format info */
-  ft->signal.encoding = sox_encoding_and_size(sf->sf_info->format, &ft->signal.size);
+  ft->signal.encoding = sox_encoding_and_size((unsigned)sf->sf_info->format, &ft->signal.size);
   ft->signal.channels = sf->sf_info->channels;
   ft->length = sf->sf_info->frames * sf->sf_info->channels;
 
--- a/src/sndrtool.c
+++ b/src/sndrtool.c
@@ -31,7 +31,7 @@
   sox_writedw(ft, nsamples);
   sox_writedw(ft, 0);
   sox_writedw(ft, nsamples);
-  sox_writew(ft, ft->signal.rate);
+  sox_writew(ft, (unsigned)(ft->signal.rate + .5));
   sox_writew(ft, 0);
   sox_writew(ft, 10);
   sox_writew(ft, 4);
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -82,11 +82,11 @@
 
 /* declared in misc.c */
 char const * find_file_extension(char const * pathname);
-typedef struct {char const *text; int value;} enum_item;
+typedef struct {char const *text; unsigned value;} enum_item;
 #define ENUM_ITEM(prefix, item) {#item, prefix##item},
 enum_item const * find_enum_text(
     char const * text, enum_item const * enum_items);
-enum_item const * find_enum_value(int value, enum_item const * enum_items);
+enum_item const * find_enum_value(unsigned value, enum_item const * enum_items);
 typedef enum {SOX_SHORT, SOX_INT, SOX_FLOAT, SOX_DOUBLE} sox_data_t;
 typedef enum {SOX_WAVE_SINE, SOX_WAVE_TRIANGLE} sox_wave_t;
 extern enum_item const sox_wave_enum[];
@@ -163,13 +163,15 @@
 sox_size_t sox_write_df_buf(sox_format_t * ft, double *buf, sox_size_t len);
 
 #define sox_readb(ft, ub) (sox_read_b_buf(ft, ub, 1) == 1 ? SOX_SUCCESS : SOX_EOF)
-int sox_writeb(sox_format_t * ft, uint8_t ub);
+int sox_writeb(sox_format_t * ft, unsigned ub);
 #define sox_readw(ft, uw) (sox_read_w_buf(ft, uw, 1) == 1 ? SOX_SUCCESS : SOX_EOF)
-int sox_writew(sox_format_t * ft, uint16_t uw);
+int sox_writew(sox_format_t * ft, unsigned uw);
+int sox_writesb(sox_format_t * ft, signed);
+int sox_writesw(sox_format_t * ft, signed);
 #define sox_read3(ft, u3) (sox_read_3_buf(ft, u3, 1) == 1 ? SOX_SUCCESS : SOX_EOF)
-int sox_write3(sox_format_t * ft, uint24_t u3);
+int sox_write3(sox_format_t * ft, unsigned u3);
 #define sox_readdw(ft, udw) (sox_read_dw_buf(ft, udw, 1) == 1 ? SOX_SUCCESS : SOX_EOF)
-int sox_writedw(sox_format_t * ft, uint32_t udw);
+int sox_writedw(sox_format_t * ft, unsigned udw);
 #define sox_readf(ft, f) (sox_read_f_buf(ft, f, 1) == 1 ? SOX_SUCCESS : SOX_EOF)
 int sox_writef(sox_format_t * ft, float f);
 #define sox_readdf(ft, d) (sox_read_df_buf(ft, d, 1) == 1 ? SOX_SUCCESS : SOX_EOF)
@@ -199,7 +201,7 @@
 #define sox_swapw(uw) (((uw >> 8) | (uw << 8)) & 0xffff)
 #define sox_swapdw(udw) ((udw >> 24) | ((udw >> 8) & 0xff00) | ((udw << 8) & 0xff0000) | (udw << 24))
 #endif
-float sox_swapf(float f);
+void sox_swapf(float * f);
 uint32_t sox_swap3(uint32_t udw);
 double sox_swapdf(double d);
 
--- a/src/sox_sample_test.c
+++ b/src/sox_sample_test.c
@@ -1,173 +1,1 @@
-#define DEBUG
-#include <assert.h>
-#include "sox.h"
-
-#define TEST_UINT(bits) \
-  uint##bits = 0; \
-  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
-  assert(sample == SOX_SAMPLE_MIN); \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == 0 && clips == 0); \
- \
-  uint##bits = 1; \
-  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
-  assert(sample > SOX_SAMPLE_MIN && sample < 0); \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == 1 && clips == 0); \
- \
-  uint##bits = SOX_INT_MAX(bits); \
-  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
-  assert(sample * SOX_INT_MAX(bits) == SOX_UNSIGNED_TO_SAMPLE(bits,1)); \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == SOX_INT_MAX(bits) && clips == 0); \
- \
-  sample =SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2; \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == 1 && clips == 0); \
- \
-  sample = SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2-1; \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == 0 && clips == 0); \
- \
-  uint##bits = (0^SOX_INT_MIN(bits)); \
-  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
-  assert(sample == 0); \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == (0^SOX_INT_MIN(bits)) && clips == 0); \
- \
-  uint##bits = ((0^SOX_INT_MIN(bits))+1); \
-  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
-  assert(sample > 0 && sample < SOX_SAMPLE_MAX); \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == ((0^SOX_INT_MIN(bits))+1) && clips == 0); \
- \
-  uint##bits = SOX_UINT_MAX(bits); \
-  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
-  assert(sample == SOX_INT_MAX(bits) * SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))); \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == SOX_UINT_MAX(bits) && clips == 0); \
- \
-  sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2-1; \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == SOX_UINT_MAX(bits) && clips == 0); \
- \
-  sample = SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2; \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == SOX_UINT_MAX(bits) && --clips == 0); \
- \
-  sample = SOX_SAMPLE_MAX; \
-  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
-  assert(uint##bits == SOX_UINT_MAX(bits) && --clips == 0); \
-
-#define TEST_SINT(bits) \
-  int##bits = SOX_INT_MIN(bits); \
-  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
-  assert(sample == SOX_SAMPLE_MIN); \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && clips == 0); \
- \
-  int##bits = SOX_INT_MIN(bits)+1; \
-  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
-  assert(sample > SOX_SAMPLE_MIN && sample < 0); \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && clips == 0); \
- \
-  int##bits = SOX_UINT_MAX(bits) /* i.e. -1 */; \
-  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
-  assert(sample * SOX_INT_MAX(bits) == SOX_SIGNED_TO_SAMPLE(bits,SOX_INT_MIN(bits)+1)); \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && clips == 0); \
- \
-  int##bits = SOX_INT_MIN(bits)+1; \
-  sample =SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2; \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && clips == 0); \
- \
-  int##bits = SOX_INT_MIN(bits); \
-  sample = SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2-1; \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && clips == 0); \
- \
-  int##bits = 0; \
-  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
-  assert(sample == 0); \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && clips == 0); \
- \
-  int##bits = 1; \
-  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
-  assert(sample > 0 && sample < SOX_SAMPLE_MAX); \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && clips == 0); \
- \
-  int##bits = SOX_INT_MAX(bits); \
-  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
-  assert(sample == SOX_INT_MAX(bits) * SOX_SIGNED_TO_SAMPLE(bits,1)); \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && clips == 0); \
- \
-  sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2-1; \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && clips == 0); \
- \
-  sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2; \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && --clips == 0); \
- \
-  sample = SOX_SAMPLE_MAX; \
-  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
-  assert(int##bits##_2 == int##bits && --clips == 0);
-
-int main()
-{
-  int8_t int8;
-  int16_t int16;
-  int24_t int24;
-
-  uint8_t uint8;
-  uint16_t uint16;
-  uint24_t uint24;
-
-  int8_t int8_2;
-  int16_t int16_2;
-  int24_t int24_2;
-
-  sox_sample_t sample;
-  sox_size_t clips = 0;
-
-  double d;
-
-  TEST_UINT(8)
-  TEST_UINT(16)
-  TEST_UINT(24)
-
-  TEST_SINT(8)
-  TEST_SINT(16)
-  TEST_SINT(24)
-
-  d = -1.0000000001;
-  sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips);
-  assert(sample == -SOX_SAMPLE_MAX && --clips == 0);
-
-  d = -1;
-  sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips);
-  assert(sample == -SOX_SAMPLE_MAX && clips == 0);
-  d = SOX_SAMPLE_TO_FLOAT_64BIT(sample,clips);
-  assert(d == -1 && clips == 0);
-
-  --sample;
-  d = SOX_SAMPLE_TO_FLOAT_64BIT(sample,clips);
-  assert(d == -1 && --clips == 0);
-
-  d = 1;
-  sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips);
-  assert(sample == SOX_SAMPLE_MAX && clips == 0);
-  d = SOX_SAMPLE_TO_FLOAT_64BIT(sample,clips);
-  assert(d == 1 && clips == 0);
-
-  d = 1.0000000001;
-  sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips);
-  assert(sample == SOX_SAMPLE_MAX && --clips == 0);
-
-  return 0;
-}
+#include "sox_sample_test.h"
--- /dev/null
+++ b/src/sox_sample_test.h
@@ -1,0 +1,187 @@
+#define DEBUG
+#include <assert.h>
+#include "sox.h"
+
+#define TEST_UINT(bits) \
+  uint##bits = 0; \
+  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
+  assert(sample == SOX_SAMPLE_MIN); \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == 0 && clips == 0); \
+ \
+  uint##bits = 1; \
+  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
+  assert(sample > SOX_SAMPLE_MIN && sample < 0); \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == 1 && clips == 0); \
+ \
+  uint##bits = SOX_INT_MAX(bits); \
+  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
+  assert(sample * SOX_INT_MAX(bits) == SOX_UNSIGNED_TO_SAMPLE(bits,1)); \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == SOX_INT_MAX(bits) && clips == 0); \
+ \
+  sample =SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2; \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == 1 && clips == 0); \
+ \
+  sample = SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2-1; \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == 0 && clips == 0); \
+ \
+  uint##bits = (0^SOX_INT_MIN(bits)); \
+  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
+  assert(sample == 0); \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == (0^SOX_INT_MIN(bits)) && clips == 0); \
+ \
+  uint##bits = ((0^SOX_INT_MIN(bits))+1); \
+  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
+  assert(sample > 0 && sample < SOX_SAMPLE_MAX); \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == ((0^SOX_INT_MIN(bits))+1) && clips == 0); \
+ \
+  uint##bits = SOX_UINT_MAX(bits); \
+  sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \
+  assert(sample == SOX_INT_MAX(bits) * SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))); \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == SOX_UINT_MAX(bits) && clips == 0); \
+ \
+  sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2-1; \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == SOX_UINT_MAX(bits) && clips == 0); \
+ \
+  sample = SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2; \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == SOX_UINT_MAX(bits) && --clips == 0); \
+ \
+  sample = SOX_SAMPLE_MAX; \
+  uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \
+  assert(uint##bits == SOX_UINT_MAX(bits) && --clips == 0); \
+
+#define TEST_SINT(bits) \
+  int##bits = SOX_INT_MIN(bits); \
+  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
+  assert(sample == SOX_SAMPLE_MIN); \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && clips == 0); \
+ \
+  int##bits = SOX_INT_MIN(bits)+1; \
+  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
+  assert(sample > SOX_SAMPLE_MIN && sample < 0); \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && clips == 0); \
+ \
+  int##bits = SOX_UINT_MAX(bits) /* i.e. -1 */; \
+  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
+  assert(sample * SOX_INT_MAX(bits) == SOX_SIGNED_TO_SAMPLE(bits,SOX_INT_MIN(bits)+1)); \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && clips == 0); \
+ \
+  int##bits = SOX_INT_MIN(bits)+1; \
+  sample =SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2; \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && clips == 0); \
+ \
+  int##bits = SOX_INT_MIN(bits); \
+  sample = SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2-1; \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && clips == 0); \
+ \
+  int##bits = 0; \
+  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
+  assert(sample == 0); \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && clips == 0); \
+ \
+  int##bits = 1; \
+  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
+  assert(sample > 0 && sample < SOX_SAMPLE_MAX); \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && clips == 0); \
+ \
+  int##bits = SOX_INT_MAX(bits); \
+  sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \
+  assert(sample == SOX_INT_MAX(bits) * SOX_SIGNED_TO_SAMPLE(bits,1)); \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && clips == 0); \
+ \
+  sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2-1; \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && clips == 0); \
+ \
+  sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2; \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && --clips == 0); \
+ \
+  sample = SOX_SAMPLE_MAX; \
+  int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \
+  assert(int##bits##_2 == int##bits && --clips == 0);
+
+#if defined __GNUC__ 
+  #pragma GCC system_header 
+#elif defined __SUNPRO_CC 
+  #pragma disable_warn 
+#elif defined _MSC_VER 
+  #pragma warning(push, 1) 
+#endif 
+
+int main()
+{
+  int8_t int8;
+  int16_t int16;
+  int24_t int24;
+
+  uint8_t uint8;
+  uint16_t uint16;
+  uint24_t uint24;
+
+  int8_t int8_2;
+  int16_t int16_2;
+  int24_t int24_2;
+
+  sox_sample_t sample;
+  sox_size_t clips = 0;
+
+  double d;
+
+  TEST_UINT(8)
+  TEST_UINT(16)
+  TEST_UINT(24)
+
+  TEST_SINT(8)
+  TEST_SINT(16)
+  TEST_SINT(24)
+
+  d = -1.0000000001;
+  sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips);
+  assert(sample == -SOX_SAMPLE_MAX && --clips == 0);
+
+  d = -1;
+  sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips);
+  assert(sample == -SOX_SAMPLE_MAX && clips == 0);
+  d = SOX_SAMPLE_TO_FLOAT_64BIT(sample,clips);
+  assert(d == -1 && clips == 0);
+
+  --sample;
+  d = SOX_SAMPLE_TO_FLOAT_64BIT(sample,clips);
+  assert(d == -1 && --clips == 0);
+
+  d = 1;
+  sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips);
+  assert(sample == SOX_SAMPLE_MAX && clips == 0);
+  d = SOX_SAMPLE_TO_FLOAT_64BIT(sample,clips);
+  assert(d == 1 && clips == 0);
+
+  d = 1.0000000001;
+  sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips);
+  assert(sample == SOX_SAMPLE_MAX && --clips == 0);
+
+  return 0;
+}
+
+#if defined __SUNPRO_CC 
+  #pragma enable_warn 
+#elif defined _MSC_VER 
+  #pragma warning(pop) 
+#endif 
--- a/src/soxio.c
+++ b/src/soxio.c
@@ -50,8 +50,10 @@
   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) {
-      sox_format_fns[sox_formats].fn = (sox_format_fn_t)lt_dlsym(lth, fnname);
-      sox_debug("opening format plugin `%s': library %p, entry point %p\n", fnname, (void *)lth, (void *)sox_format_fns[sox_formats].fn);
+      union {sox_format_fn_t fn; lt_ptr ptr;} ltptr;
+      ltptr.ptr = lt_dlsym(lth, fnname);
+      sox_format_fns[sox_formats].fn = ltptr.fn;
+      sox_debug("opening format plugin `%s': library %p, entry point %p\n", fnname, (void *)lth, ltptr.ptr);
       if (sox_format_fns[sox_formats].fn)
         sox_formats++;
     }
@@ -422,6 +424,10 @@
   if (ft->signal.reverse_bytes) \
     uw = sox_swap ## type(uw);
 
+#define TWIDDLE_FLOAT(f, type) \
+  if (ft->signal.reverse_bytes) \
+    sox_swapf(&f);
+
 /* N.B. This macro doesn't work for unaligned types (e.g. 3-byte
    types). */
 #define READ_FUNC(type, size, ctype, twiddle) \
@@ -464,7 +470,7 @@
 READ_FUNC(w, 2, uint16_t, TWIDDLE_WORD)
 READ_FUNC_UNPACK(3, 3, uint24_t, TWIDDLE_WORD)
 READ_FUNC(dw, 4, uint32_t, TWIDDLE_WORD)
-READ_FUNC(f, sizeof(float), float, TWIDDLE_WORD)
+READ_FUNC(f, sizeof(float), float, TWIDDLE_FLOAT)
 READ_FUNC(df, sizeof(double), double, TWIDDLE_WORD)
 
 /* N.B. This macro doesn't work for unaligned types (e.g. 3-byte
@@ -510,21 +516,35 @@
 WRITE_FUNC(w, 2, uint16_t, TWIDDLE_WORD)
 WRITE_FUNC_PACK(3, 3, uint24_t, TWIDDLE_WORD)
 WRITE_FUNC(dw, 4, uint32_t, TWIDDLE_WORD)
-WRITE_FUNC(f, sizeof(float), float, TWIDDLE_WORD)
+WRITE_FUNC(f, sizeof(float), float, TWIDDLE_FLOAT)
 WRITE_FUNC(df, sizeof(double), double, TWIDDLE_WORD)
 
-#define WRITE1_FUNC(type, sign, ctype) \
+#define WRITE1U_FUNC(type, ctype) \
+  int sox_write ## type(sox_format_t * ft, unsigned d) \
+  { ctype datum = (ctype)d; \
+    return sox_write_ ## type ## _buf(ft, &datum, 1) == 1 ? SOX_SUCCESS : SOX_EOF; \
+  }
+
+#define WRITE1S_FUNC(type, ctype) \
+  int sox_writes ## type(sox_format_t * ft, signed d) \
+  { ctype datum = (ctype)d; \
+    return sox_write_ ## type ## _buf(ft, &datum, 1) == 1 ? SOX_SUCCESS : SOX_EOF; \
+  }
+
+#define WRITE1_FUNC(type, ctype) \
   int sox_write ## type(sox_format_t * ft, ctype datum) \
   { \
     return sox_write_ ## type ## _buf(ft, &datum, 1) == 1 ? SOX_SUCCESS : SOX_EOF; \
   }
 
-WRITE1_FUNC(b, u, uint8_t)
-WRITE1_FUNC(w, u, uint16_t)
-WRITE1_FUNC(3, u, uint24_t)
-WRITE1_FUNC(dw, u, uint32_t)
-WRITE1_FUNC(f, su, float)
-WRITE1_FUNC(df, su, double)
+WRITE1U_FUNC(b, uint8_t)
+WRITE1U_FUNC(w, uint16_t)
+WRITE1U_FUNC(3, uint24_t)
+WRITE1U_FUNC(dw, uint32_t)
+WRITE1S_FUNC(b, uint8_t)
+WRITE1S_FUNC(w, uint16_t)
+WRITE1_FUNC(f, float)
+WRITE1_FUNC(df, double)
 
 /* N.B. The file (if any) may already have been deleted. */
 int sox_close(sox_format_t * ft)
--- a/src/synth.c
+++ b/src/synth.c
@@ -84,9 +84,9 @@
 } PinkNoise;
 
 /* Setup PinkNoise structure for N rows of generators. */
-static void InitializePinkNoise(PinkNoise * pink, int numRows)
+static void InitializePinkNoise(PinkNoise * pink, size_t numRows)
 {
-  int i;
+  size_t i;
   long pmax;
 
   pink->pink_Index = 0;
@@ -227,7 +227,7 @@
 
 
 
-static void set_default_parameters(channel_t chan, int c)
+static void set_default_parameters(channel_t chan, size_t c)
 {
   switch (chan->type) {
     case synth_square:    /* p1 is pulse width */
@@ -286,7 +286,7 @@
   int argn = 0;
 
   /* Get duration if given (if first arg starts with digit) */
-  if (argc && (isdigit(argv[argn][0]) || argv[argn][0] == '.')) {
+  if (argc && (isdigit((int)argv[argn][0]) || argv[argn][0] == '.')) {
     synth->length_str = xmalloc(strlen(argv[argn]) + 1);
     strcpy(synth->length_str, argv[argn]);
     /* Do a dummy parse of to see if it will fail */
@@ -384,7 +384,7 @@
 static int start(sox_effect_t * effp)
 {
   synth_t synth = (synth_t) effp->priv;
-  unsigned i;
+  size_t i;
   int shift_for_max = (4 - min(effp->outinfo.size, 4)) << 3;
 
   synth->max = (SOX_SAMPLE_MAX >> shift_for_max) << shift_for_max;
@@ -412,7 +412,7 @@
 
 
 
-static sox_sample_t do_synth(sox_sample_t synth_input, synth_t synth, int c, double rate)
+static sox_sample_t do_synth(sox_sample_t synth_input, synth_t synth, unsigned c, double rate)
 {
   channel_t chan = &synth->channels[c];
   double synth_out;              /* [-1, 1] */
@@ -559,7 +559,8 @@
 {
   synth_t synth = (synth_t) effp->priv;
   unsigned len = min(*isamp, *osamp) / effp->ininfo.channels;
-  unsigned c, done, result = SOX_SUCCESS;
+  unsigned c, done;
+  int result = SOX_SUCCESS;
 
   for (done = 0; done < len && result == SOX_SUCCESS; ++done) {
     for (c = 0; c < effp->ininfo.channels; c++)
--- a/src/test-comments
+++ b/src/test-comments
@@ -1,29 +1,20 @@
-#!/bin/sh -x
+#!/bin/sh
 
 tmp=/tmp/`basename $0`-$$
 
+check_file () {
+  ./soxi -a $1 > $tmp.comments
+  cmp $tmp.comments $2 || exit 1
+}
+
 check () {
   f=$1; shift
   : > $tmp.expected
-  lines=0
   while [ $# != 0 ]; do
     echo "$1" >> $tmp.expected
     shift
-    lines=`expr $lines + 1`
   done
-  ./sox -V $f -n 2> $tmp.info
-  if [ $lines -eq 1 ]; then
-    grep "^Comment " $tmp.info|sed "s/[^']*'//"|sed "s/'$//" > $tmp.comments
-  else
-    head -n -1 $tmp.info|tac|head -n -`grep -n ^Comments $tmp.info|sed "s/:.*//"`|tac>$tmp.comments
-  fi
-  cmp $tmp.comments $tmp.expected || exit 1
-}
-
-check_file () {
-  ./sox -V $1 -n 2> $tmp.info
-  head -n -1 $tmp.info|tac|head -n -`grep -n ^Comments $tmp.info|sed "s/:.*//"`|tac>$tmp.comments
-  cmp $tmp.comments $2 || exit 1
+  check_file $f $tmp.expected
 }
 
 com0="Processed by SoX"
--- a/src/tests.sh
+++ b/src/tests.sh
@@ -181,12 +181,11 @@
 
 # Run tests
 
-make sox_sample_test
 ${builddir}/sox_sample_test || exit 1
 
 # Don't test unsupported stuff
-${bindir}/sox --help | grep -q "^SUPPORTED.*\<flac\>" || skip="flac $skip"
-${bindir}/sox --help | grep -q "^SUPPORTED.*\<caf\>" || skip="caf $skip"
+${bindir}/sox --help | grep -q "^AUDIO FILE.*\<flac\>" || skip="flac $skip"
+${bindir}/sox --help | grep -q "^AUDIO FILE.*\<caf\>" || skip="caf $skip"
 
 rate=44100
 samples=23493
@@ -209,18 +208,14 @@
 fi
 do_singlechannel_formats
 
-${srcdir}/amr-wb-test
+${srcdir}/test-comments
 if [ $? -eq 0 ]; then
-  echo "ok     amr-wb"
+  echo "ok     comments"
 else
-  echo "*FAIL* amr-wb"
+  echo "*FAIL* comments"
   exit 1
 fi
 
-channels=2
-samples=10000000
-timeIO s1 u1 s2 u2 s3 u3 s4 u4 raw Raw au wav aiff aifc caf sph # FIXME?: flac dat
-
 ${bindir}/sox -c 1 -r 44100 -n output.u1 synth .01 vol .5
 if [ `wc -c <output.u1` = 441 ]; then
   echo "ok     synth size"
@@ -228,6 +223,10 @@
   echo "*FAIL* synth size"
 fi
 rm output.u1
+
+channels=2
+samples=10000000
+timeIO s1 u1 s2 u2 s3 u3 s4 u4 raw Raw au wav aiff aifc caf sph # FIXME?: flac dat
 
 test -n "$skip" && echo "Skipped: $skip"
 
--- a/src/tx16w.c
+++ b/src/tx16w.c
@@ -278,9 +278,9 @@
         else {
             w2 =  *buf++ >> 20;
         }
-        sox_writeb(ft, (w1 >> 4) & 0xFF);
-        sox_writeb(ft, (((w1 & 0x0F) << 4) | (w2 & 0x0F)) & 0xFF);
-        sox_writeb(ft, (w2 >> 4) & 0xFF);
+        sox_writesb(ft, (w1 >> 4) & 0xFF);
+        sox_writesb(ft, (((w1 & 0x0F) << 4) | (w2 & 0x0F)) & 0xFF);
+        sox_writesb(ft, (w2 >> 4) & 0xFF);
         writedone += 3;
     }
     return(len);
--- a/src/voc.c
+++ b/src/voc.c
@@ -460,7 +460,7 @@
             sox_writeb(ft, uc);
           } else {
             sw = (int) SOX_SAMPLE_TO_SIGNED_16BIT(*buf++, ft->clips);
-            sox_writew(ft,sw);
+            sox_writesw(ft,sw);
           }
           done++;
         }
@@ -480,7 +480,7 @@
         sox_seeki(ft, (sox_ssize_t)v->blockseek, 0); /* seek back to block length */
         sox_seeki(ft, 1, 1);                    /* seek forward one */
         if (v->silent) {
-                sox_writew(ft, v->samples);
+                sox_writesw(ft, v->samples);
         } else {
           if (ft->signal.size == SOX_SIZE_BYTE) {
             if (ft->signal.channels > 1) {
@@ -489,11 +489,11 @@
           }
                 v->samples += 2;                /* adjustment: SBDK pp. 3-5 */
                 datum = (v->samples * ft->signal.size) & 0xff;
-                sox_writeb(ft, (int)datum);       /* low byte of length */
+                sox_writesb(ft, datum);       /* low byte of length */
                 datum = ((v->samples * ft->signal.size) >> 8) & 0xff;
-                sox_writeb(ft, (int)datum);  /* middle byte of length */
+                sox_writesb(ft, datum);  /* middle byte of length */
                 datum = ((v->samples  * ft->signal.size)>> 16) & 0xff;
-                sox_writeb(ft, (int)datum); /* high byte of length */
+                sox_writesb(ft, datum); /* high byte of length */
         }
 }
 
@@ -749,7 +749,7 @@
                 sox_writeb(ft, VOC_SILENCE);     /* Silence block code */
                 sox_writeb(ft, 0);               /* Period length */
                 sox_writeb(ft, 0);               /* Period length */
-                sox_writeb(ft, v->rate);         /* Rate code */
+                sox_writesb(ft, v->rate);         /* Rate code */
         } else {
           if (ft->signal.size == SOX_SIZE_BYTE) {
             /* 8-bit sample section.  By always setting the correct     */
@@ -764,7 +764,7 @@
               sox_writeb(ft, 0);                /* block length = 4 */
               sox_writeb(ft, 0);                /* block length = 4 */
                   v->rate = 65536 - (256000000.0/(2*(float)ft->signal.rate));
-              sox_writew(ft,v->rate);    /* Rate code */
+              sox_writesw(ft,v->rate);    /* Rate code */
               sox_writeb(ft, 0);         /* File is not packed */
               sox_writeb(ft, 1);         /* samples are in stereo */
             }
@@ -773,7 +773,7 @@
             sox_writeb(ft, 0);           /* block length (for now) */
             sox_writeb(ft, 0);           /* block length (for now) */
             v->rate = 256 - (1000000.0/(float)ft->signal.rate);
-            sox_writeb(ft, (int) v->rate);/* Rate code */
+            sox_writesb(ft, (int) v->rate);/* Rate code */
             sox_writeb(ft, 0);           /* 8-bit raw data */
         } else {
             sox_writeb(ft, VOC_DATA_16); /* Voice Data block code */
@@ -783,7 +783,7 @@
             v->rate = ft->signal.rate;
             sox_writedw(ft, (unsigned)v->rate);    /* Rate code */
             sox_writeb(ft, 16);          /* Sample Size */
-            sox_writeb(ft, (signed)ft->signal.channels);   /* Sample Size */
+            sox_writeb(ft, ft->signal.channels);   /* Sample Size */
             sox_writew(ft, 0x0004);      /* Encoding */
             sox_writeb(ft, 0);           /* Unused */
             sox_writeb(ft, 0);           /* Unused */
--- a/src/vorbis.c
+++ b/src/vorbis.c
@@ -71,7 +71,7 @@
 
 static int _fseeko64_wrap(FILE * f, ogg_int64_t off, int whence)
 {
-  int ret = fseeko(f, off, whence);
+  int ret = fseeko(f, (off_t)off, whence);
 
   if (ret == EBADF)
     ret = -1;
@@ -245,8 +245,8 @@
   memset(&vc, 0, sizeof(vc));
   vc.comments = num_comments(ft->comments);
   if (vc.comments) {     /* Make the comment structure */
-    vc.comment_lengths = xcalloc(vc.comments, sizeof(*vc.comment_lengths));
-    vc.user_comments = xcalloc(vc.comments, sizeof(*vc.user_comments));
+    vc.comment_lengths = xcalloc((size_t)vc.comments, sizeof(*vc.comment_lengths));
+    vc.user_comments = xcalloc((size_t)vc.comments, sizeof(*vc.user_comments));
     for (i = 0; i < vc.comments; ++i) {
       static const char prepend[] = "Comment=";
       char * text = xcalloc(strlen(prepend) + strlen(ft->comments[i]) + 1, sizeof(*text));
@@ -304,8 +304,7 @@
     }
     quality = ft->signal.compression;
   }
-  vorbis_encode_init_vbr(&ve->vi, (int) ft->signal.channels,
-                         (int) ft->signal.rate, (float) (quality / 10));
+#include "vorbis1.h"
 
   vorbis_analysis_init(&ve->vd, &ve->vi);
   vorbis_block_init(&ve->vd, &ve->vb);
@@ -392,7 +391,7 @@
 {
   vorbis_t vb = (vorbis_t) ft->priv;
 
-  return ov_pcm_seek(vb->vf, offset / ft->signal.channels)? SOX_EOF:SOX_SUCCESS;
+  return ov_pcm_seek(vb->vf, (ogg_int64_t)(offset / ft->signal.channels))? SOX_EOF:SOX_SUCCESS;
 }
 
 const sox_format_handler_t *sox_vorbis_format_fn(void);
--- /dev/null
+++ b/src/vorbis1.h
@@ -1,0 +1,16 @@
+#if defined __GNUC__ 
+  #pragma GCC system_header 
+#elif defined __SUNPRO_CC 
+  #pragma disable_warn 
+#elif defined _MSC_VER 
+  #pragma warning(push, 1) 
+#endif 
+
+  vorbis_encode_init_vbr(
+      &ve->vi, ft->signal.channels, ft->signal.rate + .5, quality / 10);
+
+#if defined __SUNPRO_CC 
+  #pragma enable_warn 
+#elif defined _MSC_VER 
+  #pragma warning(pop) 
+#endif 
--- a/src/wve.c
+++ b/src/wve.c
@@ -188,15 +188,15 @@
     /* Null terminate string */
     sox_writeb(ft, 0);
 
-    sox_writew(ft, version);
+    sox_writesw(ft, version);
 
     sox_writedw(ft, p->length);
-    sox_writew(ft, p->padding);
-    sox_writew(ft, p->repeats);
+    sox_writesw(ft, p->padding);
+    sox_writesw(ft, p->repeats);
 
-    sox_writew(ft, zero);
-    sox_writew(ft, zero);
-    sox_writew(ft, zero);
+    sox_writesw(ft, zero);
+    sox_writesw(ft, zero);
+    sox_writesw(ft, zero);
 }
 
 /* Psion .wve */