shithub: sox

Download patch

ref: 762f22b8f2afbb6c59cbd84023310402271b9886
parent: 1554fa4c7cd8ea8449a0c61ca57e948d9b089f89
author: robs <robs>
date: Sat Mar 29 16:10:20 EDT 2008

change priv structures to be malloc'd

--- a/src/8svx.c
+++ b/src/8svx.c
@@ -1,10 +1,7 @@
-/*
- * Amiga 8SVX format handler: W V Neisius, February 1992
- */
+/* Amiga 8SVX format handler: W V Neisius, February 1992 */
 
 #include "sox_i.h"
 
-#include <math.h>
 #include <errno.h>
 #include <string.h>
 #include <stdlib.h>
@@ -15,10 +12,10 @@
 #endif
 
 /* Private data used by writer */
-typedef struct svxpriv {
-        uint32_t nsamples;
-        FILE *ch[4];
-}*svx_t;
+typedef struct{
+  uint32_t nsamples;
+  FILE * ch[4];
+} priv_t;
 
 static void svxwriteheader(sox_format_t *, sox_size_t);
 
@@ -28,7 +25,7 @@
 
 static int startread(sox_format_t * ft)
 {
-        svx_t p = (svx_t ) ft->priv;
+        priv_t * p = (priv_t * ) ft->priv;
 
         char buf[12];
         char *chunk_buf;
@@ -157,7 +154,7 @@
         }
         lsx_readdw(ft, &(p->nsamples));
 
-        ft->length = p->nsamples;
+        ft->signal.length = p->nsamples;
         ft->signal.channels = channels;
         ft->signal.rate = rate;
         ft->encoding.encoding = SOX_ENCODING_SIGN2;
@@ -198,7 +195,7 @@
         unsigned char datum;
         size_t done = 0, i;
 
-        svx_t p = (svx_t ) ft->priv;
+        priv_t * p = (priv_t * ) ft->priv;
 
         while (done < nsamp) {
                 for (i = 0; i < ft->signal.channels; i++) {
@@ -221,7 +218,7 @@
 {
         size_t i;
 
-        svx_t p = (svx_t ) ft->priv;
+        priv_t * p = (priv_t * ) ft->priv;
 
         /* close channel files */
         for (i = 1; i < ft->signal.channels; i++) {
@@ -235,7 +232,7 @@
 /*======================================================================*/
 static int startwrite(sox_format_t * ft)
 {
-        svx_t p = (svx_t ) ft->priv;
+        priv_t * p = (priv_t * ) ft->priv;
         size_t i;
 
         /* open channel output files */
@@ -260,7 +257,7 @@
 
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-        svx_t p = (svx_t ) ft->priv;
+        priv_t * p = (priv_t * ) ft->priv;
 
         unsigned char datum;
         size_t done = 0, i;
@@ -284,7 +281,7 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-        svx_t p = (svx_t ) ft->priv;
+        priv_t * p = (priv_t * ) ft->priv;
 
         size_t i, len;
         char svxbuf[512];
@@ -363,13 +360,12 @@
 {
   static char const * const names[] = {"8svx", NULL};
   static unsigned const write_encodings[] = {SOX_ENCODING_SIGN2, 8, 0, 0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
     "Amiga audio format (a subformat of the Interchange File Format)",
     names, SOX_FILE_BIG_END|SOX_FILE_MONO|SOX_FILE_STEREO|SOX_FILE_QUAD,
     startread, read_samples, stopread,
     startwrite, write_samples, stopwrite,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/FFT.c
+++ b/src/FFT.c
@@ -1,7 +1,20 @@
-/*
+/* libSoX FFT funtions    copyright Ian Turner and others.
  *
- * FFT.c
+ * 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
+ *
+ *
  * Based on FFT.cpp from Audacity, with the following permission from
  * its author, Dominic Mazzoni (in particular, relicensing the code
  * for use in SoX):
@@ -27,22 +40,6 @@
  *
  * The basic algorithm for his code was based on Numerical Recipes
  * in Fortran.
- *
- * This file is now part of SoX, and is copyright Ian Turner and others.
- * 
- * 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
  */
 
 #include "sox_i.h"
@@ -49,7 +46,6 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <math.h>
 #include <assert.h>
 
 #include "FFT.h"
@@ -96,9 +92,9 @@
 static void InitFFT(void)
 {
    unsigned len, b;
-   
+
    gFFTBitTable = lsx_calloc(MaxFastBits, sizeof(*gFFTBitTable));
-   
+
    for (b = 1, len = 2; b <= MaxFastBits; b++) {
       unsigned i;
 
@@ -250,22 +246,22 @@
 
    for (i = 1; i < Half / 2; i++) {
      i3 = Half - i;
-       
+
      h1r = 0.5 * (RealOut[i] + RealOut[i3]);
      h1i = 0.5 * (ImagOut[i] - ImagOut[i3]);
      h2r = 0.5 * (ImagOut[i] + ImagOut[i3]);
      h2i = -0.5 * (RealOut[i] - RealOut[i3]);
-       
+
      RealOut[i] = h1r + wr * h2r - wi * h2i;
      ImagOut[i] = h1i + wr * h2i + wi * h2r;
      RealOut[i3] = h1r - wr * h2r + wi * h2i;
      ImagOut[i3] = -h1i + wr * h2i + wi * h2r;
-       
+
      wtemp = wr;
      wr = wr * wpr - wi * wpi + wr;
      wi = wi * wpr + wtemp * wpi + wi;
    }
-     
+
    h1r = RealOut[0];
    RealOut[0] += ImagOut[0];
    ImagOut[0] = h1r - ImagOut[0];
@@ -310,7 +306,7 @@
   }
 
   FFT(Half, 0, tmpReal, tmpImag, RealOut, ImagOut);
-  
+
   wtemp = (float) sin(0.5 * theta);
 
   wpr = -2.0 * wtemp * wtemp;
@@ -317,16 +313,16 @@
   wpi = (float) sin(theta);
   wr = 1.0 + wpr;
   wi = wpi;
-    
+
   for (i = 1; i < Half / 2; i++) {
-      
+
     i3 = Half - i;
-    
+
     h1r = 0.5 * (RealOut[i] + RealOut[i3]);
     h1i = 0.5 * (ImagOut[i] - ImagOut[i3]);
     h2r = 0.5 * (ImagOut[i] + ImagOut[i3]);
     h2i = -0.5 * (RealOut[i] - RealOut[i3]);
-    
+
     rt = h1r + wr * h2r - wi * h2i;
     it = h1i + wr * h2i + wi * h2r;
 
@@ -334,9 +330,9 @@
 
     rt = h1r - wr * h2r + wi * h2i;
     it = -h1i + wr * h2i + wi * h2r;
-    
+
     Out[i3] = rt * rt + it * it;
-    
+
     wr = (wtemp = wr) * wpr - wi * wpi + wr;
     wi = wi * wpr + wtemp * wpi + wi;
   }
@@ -344,11 +340,11 @@
   rt = (h1r = RealOut[0]) + ImagOut[0];
   it = h1r - ImagOut[0];
   Out[0] = rt * rt + it * it;
-  
+
   rt = RealOut[Half / 2];
   it = ImagOut[Half / 2];
   Out[Half / 2] = rt * rt + it * it;
-  
+
   free(tmpReal);
 }
 
@@ -359,7 +355,7 @@
 void WindowFunc(windowfunc_t whichFunction, int NumSamples, float *in)
 {
     int i;
-    
+
     switch (whichFunction) {
     case BARTLETT:
         for (i = 0; i < NumSamples / 2; i++) {
@@ -368,12 +364,12 @@
                 (1.0 - (i / (float) (NumSamples / 2)));
         }
         break;
-        
+
     case HAMMING:
         for (i = 0; i < NumSamples; i++)
             in[i] *= 0.54 - 0.46 * cos(2 * M_PI * i / (NumSamples - 1));
         break;
-        
+
     case HANNING:
         for (i = 0; i < NumSamples; i++)
             in[i] *= 0.50 - 0.50 * cos(2 * M_PI * i / (NumSamples - 1));
--- a/src/FFT.h
+++ b/src/FFT.h
@@ -1,14 +1,20 @@
-/* aliases */
-#define gFFTBitTable lsx_gFFTBitTable
-#define MaxFastBits lsx_MaxFastBits
-#define FFT lsx_FFT
-#define RealFFT lsx_RealFFT
-#define PowerSpectrum lsx_PowerSpectrum
-#define WindowFunc lsx_WindowFunc
-
-/*
- * FFT.h
+/* libSoX FFT funtions    copyright Ian Turner and others.
  *
+ * 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
+ *
+ *
  * Based on FFT.h from Audacity, with the following permission from
  * its author, Dominic Mazzoni (in particular, relicensing the code
  * for use in SoX):
@@ -34,23 +40,15 @@
  *
  * The basic algorithm for his code was based on Numerical Recipes
  * in Fortran.
- *
- * This file is now part of SoX, and is copyright Ian Turner and others.
- * 
- * 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
  */
+
+/* aliases */
+#define gFFTBitTable lsx_gFFTBitTable
+#define MaxFastBits lsx_MaxFastBits
+#define FFT lsx_FFT
+#define RealFFT lsx_RealFFT
+#define PowerSpectrum lsx_PowerSpectrum
+#define WindowFunc lsx_WindowFunc
 
 /*
  * This is the function you will use the most often.
--- a/src/adpcm.c
+++ b/src/adpcm.c
@@ -1,5 +1,4 @@
-/*
- * adpcm.c  codex functions for MS_ADPCM data
+/* adpcm.c  codex functions for MS_ADPCM data
  *          (hopefully) provides interoperability with
  *          Microsoft's ADPCM format, but, as usual,
  *          see LACK-OF-WARRANTY information below.
@@ -36,10 +35,9 @@
 #include "adpcm.h"
 
 #include <sys/types.h>
-#include <math.h>
 #include <stdio.h>
 
-typedef struct MsState {
+typedef struct {
         sox_sample_t  step;      /* step size */
         short lsx_ms_adpcm_i_coef[2];
 } MsState_t;
--- a/src/adpcm.h
+++ b/src/adpcm.h
@@ -1,5 +1,4 @@
-/*
- * adpcm.h  codex functions for MS_ADPCM data
+/* adpcm.h  codex functions for MS_ADPCM data
  *          (hopefully) provides interoperability with
  *          Microsoft's ADPCM format, but, as usual,
  *          see LACK-OF-WARRANTY information below.
--- a/src/adpcms.c
+++ b/src/adpcms.c
@@ -1,4 +1,5 @@
-/*
+/* libSoX ADPCM codecs: IMA, OKI, CL.   (c) 2007-8 robs@users.sourceforge.net
+ *
  * 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
@@ -14,8 +15,6 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-/* ADPCM CODECs: IMA, OKI, CL.   (c) 2007-8 robs@users.sourceforge.net */
-
 #include "sox_i.h"
 #include "adpcms.h"
 
@@ -75,7 +74,7 @@
   if (s < min_sample || s > max_sample) {
     int grace = (p->setup.steps[p->step_index] >> (p->setup.shift + 1)) & p->setup.mask;
     if (s < min_sample - grace || s > max_sample + grace) {
-      sox_debug_most("code=%i step=%i grace=%i s=%i", 
+      sox_debug_most("code=%i step=%i grace=%i s=%i",
           code & (2 * p->setup.sign - 1), p->setup.steps[p->step_index], grace, s);
       p->errors++;
     }
@@ -120,7 +119,7 @@
  *                 the decoder between frames.
  ******************************************************************************/
 
-void sox_adpcm_reset(adpcm_io_t state, sox_encoding_t type)
+void sox_adpcm_reset(adpcm_io_t * state, sox_encoding_t type)
 {
   state->file.count = 0;
   state->file.pos = 0;
@@ -141,13 +140,13 @@
  * Exceptions :
  * Notes      : 1. This function can be used as a startread or
  *                 startwrite method.
- *              2. VOX file format is 4-bit OKI ADPCM that decodes to 
+ *              2. VOX file format is 4-bit OKI ADPCM that decodes to
  *                 to 12 bit signed linear PCM.
  *              3. Dialogic only supports 6kHz, 8kHz and 11 kHz sampling
  *                 rates but the codecs allows any user specified rate.
  ******************************************************************************/
 
-static int adpcm_start(sox_format_t * ft, adpcm_io_t state, sox_encoding_t type)
+static int adpcm_start(sox_format_t * ft, adpcm_io_t * state, sox_encoding_t type)
 {
   /* setup file info */
   state->file.buf = (char *) lsx_malloc(sox_globals.bufsiz);
@@ -155,22 +154,22 @@
   ft->signal.channels = 1;
 
   sox_adpcm_reset(state, type);
-  
+
   return lsx_rawstart(ft, sox_true, sox_false, sox_true, type, 4);
 }
 
-int sox_adpcm_oki_start(sox_format_t * ft, adpcm_io_t state)
+int sox_adpcm_oki_start(sox_format_t * ft, adpcm_io_t * state)
 {
   return adpcm_start(ft, state, SOX_ENCODING_OKI_ADPCM);
 }
 
-int sox_adpcm_ima_start(sox_format_t * ft, adpcm_io_t state)
+int sox_adpcm_ima_start(sox_format_t * ft, adpcm_io_t * state)
 {
   return adpcm_start(ft, state, SOX_ENCODING_IMA_ADPCM);
 }
 
 /******************************************************************************
- * Function   : sox_adpcm_read 
+ * Function   : sox_adpcm_read
  * Description: Converts the OKI ADPCM 4-bit samples to 16-bit signed PCM and
  *              then scales the samples to full sox_sample_t range.
  * Parameters : ft     - file info structure
@@ -179,10 +178,10 @@
  *              len    - size of output buffer
  * Returns    :        - number of samples returned in buffer
  * Exceptions :
- * Notes      : 
+ * Notes      :
  ******************************************************************************/
 
-sox_size_t sox_adpcm_read(sox_format_t * ft, adpcm_io_t state, sox_sample_t * buffer, sox_size_t len)
+sox_size_t sox_adpcm_read(sox_format_t * ft, adpcm_io_t * state, sox_sample_t * buffer, sox_size_t len)
 {
   sox_size_t n = 0;
   uint8_t byte;
@@ -211,16 +210,16 @@
 }
 
 /******************************************************************************
- * Function   : stopread 
+ * Function   : stopread
  * Description: Frees the internal buffer allocated in voxstart/imastart.
  * Parameters : ft   - file info structure
  *              state  - ADPCM state structure
  * Returns    : int  - SOX_SUCCESS
  * Exceptions :
- * Notes      : 
+ * Notes      :
  ******************************************************************************/
 
-int sox_adpcm_stopread(sox_format_t * ft UNUSED, adpcm_io_t state)
+int sox_adpcm_stopread(sox_format_t * ft UNUSED, adpcm_io_t * state)
 {
   if (state->encoder.errors)
     sox_warn("%s: ADPCM state errors: %u", ft->filename, state->encoder.errors);
@@ -241,10 +240,10 @@
  * Returns    : int    - SOX_SUCCESS
  *                       SOX_EOF
  * Exceptions :
- * Notes      : 
+ * Notes      :
  ******************************************************************************/
 
-sox_size_t sox_adpcm_write(sox_format_t * ft, adpcm_io_t state, const sox_sample_t * buffer, sox_size_t length)
+sox_size_t sox_adpcm_write(sox_format_t * ft, adpcm_io_t * state, const sox_sample_t * buffer, sox_size_t length)
 {
   sox_size_t count = 0;
   uint8_t byte = state->store.byte;
@@ -288,7 +287,7 @@
  * Notes      : 1. Called directly for writing framed formats
  ******************************************************************************/
 
-void sox_adpcm_flush(sox_format_t * ft, adpcm_io_t state)
+void sox_adpcm_flush(sox_format_t * ft, adpcm_io_t * state)
 {
   uint8_t byte = state->store.byte;
   uint8_t flag = state->store.flag;
@@ -305,16 +304,16 @@
 
 /******************************************************************************
  * Function   : sox_adpcm_stopwrite
- * Description: Flushes any leftover samples and frees the internal buffer 
+ * Description: Flushes any leftover samples and frees the internal buffer
  *              allocated in voxstart/imastart.
  * Parameters : ft   - file info structure
  *              state  - ADPCM state structure
  * Returns    : int  - SOX_SUCCESS
  * Exceptions :
- * Notes      : 
+ * Notes      :
  ******************************************************************************/
 
-int sox_adpcm_stopwrite(sox_format_t * ft, adpcm_io_t state)
+int sox_adpcm_stopwrite(sox_format_t * ft, adpcm_io_t * state)
 {
   sox_adpcm_flush(ft, state);
   free(state->file.buf);
--- a/src/adpcms.h
+++ b/src/adpcms.h
@@ -1,4 +1,5 @@
-/*
+/* libSoX ADPCM codecs: IMA, OKI, CL.   (c) 2007-8 robs@users.sourceforge.net
+ *
  * 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
@@ -14,8 +15,6 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-/* ADPCM CODECs: IMA, OKI.   (c) 2007 robs@users.sourceforge.net */
-
 typedef struct {
   int max_step_index;
   int sign;
@@ -36,7 +35,7 @@
 int lsx_adpcm_decode(int code, adpcm_t * p);
 int lsx_adpcm_encode(int sample, adpcm_t * p);
 
-typedef struct adpcm_io {
+typedef struct {
   adpcm_t encoder;
   struct {
     uint8_t byte;               /* write store */
@@ -43,14 +42,14 @@
     uint8_t flag;
   } store;
   sox_fileinfo_t file;
-} *adpcm_io_t;
+} adpcm_io_t;
 
 /* Format methods */
-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);
-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);
-void sox_adpcm_flush(sox_format_t * ft, adpcm_io_t state);
-int sox_adpcm_stopwrite(sox_format_t * ft, adpcm_io_t state);
+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);
+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);
+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/aifc-fmt.c
+++ b/src/aifc-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File format: AIFF-C (see aiff.c)           (c) 2007-8 SoX contributors
+/* File format: AIFF-C (see aiff.c)           (c) 2007-8 SoX contributors
  *
  * 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
@@ -24,13 +23,12 @@
   static char const * const names[] = {"aifc", "aiffc", NULL};
   static unsigned const write_encodings[] = {
     SOX_ENCODING_SIGN2, 32, 24, 16, 8, 0, 0};
-  static sox_format_handler_t const sox_aifc_format = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t const sox_aifc_format = {SOX_LIB_VERSION_CODE,
     "AIFF-C (not compressed, linear), defined in DAVIC 1.4 Part 9 Annex B",
     names, SOX_FILE_BIG_END,
     sox_aiffstartread, sox_aiffread, sox_aiffstopread,
     sox_aifcstartwrite, sox_aiffwrite, sox_aifcstopwrite,
-    sox_aiffseek, write_encodings, NULL
+    sox_aiffseek, write_encodings, NULL, sizeof(aiff_priv_t)
   };
   return &sox_aifc_format;
 }
--- a/src/aiff-fmt.c
+++ b/src/aiff-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File format: AIFF (see aiff.c)           (c) 2007-8 SoX contributors
+/* File format: AIFF (see aiff.c)           (c) 2007-8 SoX contributors
  *
  * 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
@@ -24,13 +23,11 @@
   static char const * const names[] = {"aiff", "aif", NULL};
   static unsigned const write_encodings[] = {
     SOX_ENCODING_SIGN2, 32, 24, 16, 8, 0, 0};
-  static sox_format_handler_t const sox_aiff_format = {
-    SOX_LIB_VERSION_CODE,
-    "AIFF files used on Apple IIc/IIgs and SGI",
-    names, SOX_FILE_BIG_END,
+  static sox_format_handler_t const sox_aiff_format = {SOX_LIB_VERSION_CODE,
+    "AIFF files used on Apple IIc/IIgs and SGI", names, SOX_FILE_BIG_END,
     sox_aiffstartread, sox_aiffread, sox_aiffstopread,
     sox_aiffstartwrite, sox_aiffwrite, sox_aiffstopwrite,
-    sox_aiffseek, write_encodings, NULL
+    sox_aiffseek, write_encodings, NULL, sizeof(aiff_priv_t)
   };
   return &sox_aiff_format;
 }
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -1,5 +1,11 @@
-/*
- * libSoX SGI/Amiga AIFF format.
+/* libSoX SGI/Amiga AIFF format.
+ * Copyright 1991-2007 Guido van Rossum And Sundry Contributors
+ *
+ * This source code is freely redistributable and may be used for
+ * any purpose.  This copyright notice must be maintained.
+ * Guido van Rossum And Sundry Contributors are not responsible for
+ * the consequences of using this software.
+ *
  * Used by SGI on 4D/35 and Indigo.
  * This is a subformat of the EA-IFF-85 format.
  * This is related to the IFF format used by the Amiga.
@@ -6,19 +12,11 @@
  * But, apparently, not the same.
  * Also AIFF-C format output that is defined in DAVIC 1.4 Part 9 Annex B
  * (usable for japanese-data-broadcasting, specified by ARIB STD-B24.)
- *
- * Copyright 1991-2007 Guido van Rossum And Sundry Contributors
- * 
- * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Guido van Rossum And Sundry Contributors are not responsible for 
- * the consequences of using this software.
  */
 
 #include "sox_i.h"
 #include "aiff.h"
 
-#include <math.h>
 #include <time.h>      /* for time stamping comments */
 #include <stdlib.h>
 #include <string.h>
@@ -41,15 +39,11 @@
 static void reportInstrument(sox_format_t * ft);
 
 /* Private data used by writer */
-typedef struct aiffpriv {
-    sox_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 */
-} *aiff_t;
+typedef aiff_priv_t priv_t;
 
-int sox_aiffseek(sox_format_t * ft, sox_size_t offset) 
+int sox_aiffseek(sox_format_t * ft, sox_size_t offset)
 {
-    aiff_t aiff = (aiff_t ) ft->priv;
+    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;
 
@@ -68,14 +62,14 @@
     ft->sox_errno = lsx_seeki(ft, (sox_ssize_t)new_offset, SEEK_SET);
 
     if (ft->sox_errno == SOX_SUCCESS)
-        aiff->nsamples = ft->length - (new_offset / size);
+        aiff->nsamples = ft->signal.length - (new_offset / size);
 
     return(ft->sox_errno);
 }
 
-int sox_aiffstartread(sox_format_t * ft) 
+int sox_aiffstartread(sox_format_t * ft)
 {
-        aiff_t aiff = (aiff_t ) ft->priv;
+        priv_t * aiff = (priv_t *) ft->priv;
         char buf[5];
         uint32_t totalsize;
         uint32_t chunksize;
@@ -89,7 +83,7 @@
         struct mark {
                 unsigned short id;
                 uint32_t position;
-                char name[40]; 
+                char name[40];
         } marks[32];
         unsigned short looptype;
         int i, j;
@@ -117,7 +111,7 @@
                 return(SOX_EOF);
         }
         lsx_readdw(ft, &totalsize);
-        if (lsx_reads(ft, buf, 4) == SOX_EOF || (strncmp(buf, "AIFF", 4) != 0 && 
+        if (lsx_reads(ft, buf, 4) == SOX_EOF || (strncmp(buf, "AIFF", 4) != 0 &&
             strncmp(buf, "AIFC", 4) != 0))
         {
                 lsx_fail_errno(ft,SOX_EHDR,"AIFF 'FORM' chunk does not specify 'AIFF' or 'AIFC' as type");
@@ -124,7 +118,7 @@
                 return(SOX_EOF);
         }
 
-        
+
         /* Skip everything but the COMM chunk and the SSND chunk */
         /* The SSND chunk must be the last in the file */
         while (1) {
@@ -185,7 +179,7 @@
                                 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, (sox_ssize_t)chunksize, SEEK_CUR);
                 }
                 else if (strncmp(buf, "MARK", 4) == 0) {
                         /* MARK chunk */
@@ -229,7 +223,7 @@
                                 read_len = len;
                                 if (read_len > 39)
                                     read_len = 39;
-                                for(j = 0; j < len && chunksize; j++) 
+                                for(j = 0; j < len && chunksize; j++)
                                 {
                                     lsx_readb(ft, &tmp_c);
                                     if (j < read_len)
@@ -251,10 +245,10 @@
                 else if (strncmp(buf, "INST", 4) == 0) {
                         /* INST chunk */
                         lsx_readdw(ft, &chunksize);
-                        lsx_readb(ft, (unsigned char *)&(ft->instr.MIDInote));
+                        lsx_readb(ft, (unsigned char *)&(ft->oob.instr.MIDInote));
                         lsx_readb(ft, (unsigned char *)&trash8);
-                        lsx_readb(ft, (unsigned char *)&(ft->instr.MIDIlow));
-                        lsx_readb(ft, (unsigned char *)&(ft->instr.MIDIhi));
+                        lsx_readb(ft, (unsigned char *)&(ft->oob.instr.MIDIlow));
+                        lsx_readb(ft, (unsigned char *)&(ft->oob.instr.MIDIhi));
                         /* Low  velocity */
                         lsx_readb(ft, (unsigned char *)&trash8);
                         /* Hi  velocity */
@@ -261,11 +255,11 @@
                         lsx_readb(ft, (unsigned char *)&trash8);
                         lsx_readw(ft, (unsigned short *)&trash16);/* gain */
                         lsx_readw(ft, &looptype); /* sustain loop */
-                        ft->loops[0].type = looptype;
+                        ft->oob.loops[0].type = looptype;
                         lsx_readw(ft, &sustainLoopBegin); /* begin marker */
                         lsx_readw(ft, &sustainLoopEnd);    /* end marker */
                         lsx_readw(ft, &looptype); /* release loop */
-                        ft->loops[1].type = looptype;
+                        ft->oob.loops[1].type = looptype;
                         lsx_readw(ft, &releaseLoopBegin);  /* begin marker */
                         lsx_readw(ft, &releaseLoopEnd);    /* end marker */
 
@@ -296,7 +290,7 @@
                     return(SOX_EOF);
                   }
                   if (annotation)
-                    sox_append_comments(&ft->comments, annotation);
+                    sox_append_comments(&ft->oob.comments, annotation);
                   free(annotation);
                 }
                 else if (strncmp(buf, "COMT", 4) == 0) {
@@ -306,7 +300,7 @@
                     return(SOX_EOF);
                   }
                   if (comment)
-                    sox_append_comments(&ft->comments, comment);
+                    sox_append_comments(&ft->oob.comments, comment);
                   free(comment);
                 }
                 else if (strncmp(buf, "AUTH", 4) == 0) {
@@ -358,9 +352,9 @@
                         break;
         }
 
-        /* 
-         * if a pipe, we lose all chunks after sound.  
-         * Like, say, instrument loops. 
+        /*
+         * if a pipe, we lose all chunks after sound.
+         * Like, say, instrument loops.
          */
         if (ft->seekable)
         {
@@ -424,7 +418,7 @@
                 aiff->nsamples -= 4;
                 ft->encoding.reverse_bytes = !ft->encoding.reverse_bytes;
         }
-        
+
         if (foundmark && !foundinstr)
         {
             sox_debug("Ignoring MARK chunk since no INSTR found.");
@@ -441,7 +435,7 @@
                 int rlbIndex = 0, rleIndex = 0;
 
                 /* find our loop markers and save their marker indexes */
-                for(i = 0; i < nmarks; i++) { 
+                for(i = 0; i < nmarks; i++) {
                   if(marks[i].id == sustainLoopBegin)
                     slbIndex = i;
                   if(marks[i].id == sustainLoopEnd)
@@ -452,25 +446,25 @@
                     rleIndex = i;
                 }
 
-                ft->instr.nloops = 0;
-                if (ft->loops[0].type != 0) {
-                        ft->loops[0].start = marks[slbIndex].position;
-                        ft->loops[0].length = 
+                ft->oob.instr.nloops = 0;
+                if (ft->oob.loops[0].type != 0) {
+                        ft->oob.loops[0].start = marks[slbIndex].position;
+                        ft->oob.loops[0].length =
                             marks[sleIndex].position - marks[slbIndex].position;
                         /* really the loop count should be infinite */
-                        ft->loops[0].count = 1; 
-                        ft->instr.loopmode = SOX_LOOP_SUSTAIN_DECAY | ft->loops[0].type;
-                        ft->instr.nloops++;
+                        ft->oob.loops[0].count = 1;
+                        ft->oob.instr.loopmode = SOX_LOOP_SUSTAIN_DECAY | ft->oob.loops[0].type;
+                        ft->oob.instr.nloops++;
                 }
-                if (ft->loops[1].type != 0) {
-                        ft->loops[1].start = marks[rlbIndex].position;
-                        ft->loops[1].length = 
+                if (ft->oob.loops[1].type != 0) {
+                        ft->oob.loops[1].start = marks[rlbIndex].position;
+                        ft->oob.loops[1].length =
                             marks[rleIndex].position - marks[rlbIndex].position;
                         /* really the loop count should be infinite */
-                        ft->loops[1].count = 1;
-                        ft->instr.loopmode = SOX_LOOP_SUSTAIN_DECAY | ft->loops[1].type;
-                        ft->instr.nloops++;
-                } 
+                        ft->oob.loops[1].count = 1;
+                        ft->oob.instr.loopmode = SOX_LOOP_SUSTAIN_DECAY | ft->oob.loops[1].type;
+                        ft->oob.instr.nloops++;
+                }
         }
         reportInstrument(ft);
 
@@ -479,7 +473,7 @@
         if (rc)
             return rc;
 
-        ft->length = aiff->nsamples;    /* for seeking */
+        ft->signal.length = aiff->nsamples;    /* for seeking */
         aiff->dataStart = lsx_tell(ft);
 
         return(SOX_SUCCESS);
@@ -490,16 +484,16 @@
 {
   unsigned loopNum;
 
-  if(ft->instr.nloops > 0)
+  if(ft->oob.instr.nloops > 0)
     sox_report("AIFF Loop markers:");
-  for(loopNum  = 0; loopNum < ft->instr.nloops; loopNum++) {
-    if (ft->loops[loopNum].count) {
-      sox_report("Loop %d: start: %6d", loopNum, ft->loops[loopNum].start);
-      sox_report(" end:   %6d", 
-              ft->loops[loopNum].start + ft->loops[loopNum].length);
-      sox_report(" count: %6d", ft->loops[loopNum].count);
+  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(" count: %6d", ft->oob.loops[loopNum].count);
       sox_report(" type:  ");
-      switch(ft->loops[loopNum].type & ~SOX_LOOP_SUSTAIN_DECAY) {
+      switch(ft->oob.loops[loopNum].type & ~SOX_LOOP_SUSTAIN_DECAY) {
       case 0: sox_report("off"); break;
       case 1: sox_report("forward"); break;
       case 2: sox_report("forward/backward"); break;
@@ -506,13 +500,13 @@
       }
     }
   }
-  sox_report("Unity MIDI Note: %d", ft->instr.MIDInote);
-  sox_report("Low   MIDI Note: %d", ft->instr.MIDIlow);
-  sox_report("High  MIDI Note: %d", ft->instr.MIDIhi);
+  sox_report("Unity MIDI Note: %d", ft->oob.instr.MIDInote);
+  sox_report("Low   MIDI Note: %d", ft->oob.instr.MIDIlow);
+  sox_report("High  MIDI Note: %d", ft->oob.instr.MIDIhi);
 }
 
 /* Process a text chunk, allocate memory, display it if verbose and return */
-static int textChunk(char **text, char *chunkDescription, sox_format_t * ft) 
+static int textChunk(char **text, char *chunkDescription, sox_format_t * ft)
 {
   uint32_t chunksize;
   lsx_readdw(ft, &chunksize);
@@ -601,7 +595,7 @@
 
 sox_size_t sox_aiffread(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-        aiff_t aiff = (aiff_t ) ft->priv;
+        priv_t * aiff = (priv_t *) ft->priv;
         sox_ssize_t done;
 
         if ((sox_size_t)len > aiff->nsamples)
@@ -613,7 +607,7 @@
         return done;
 }
 
-int sox_aiffstopread(sox_format_t * ft) 
+int sox_aiffstopread(sox_format_t * ft)
 {
         char buf[5];
         uint32_t chunksize;
@@ -621,7 +615,7 @@
 
         if (!ft->seekable)
         {
-            while (! lsx_eof(ft)) 
+            while (! lsx_eof(ft))
             {
                 if (lsx_readbuf(ft, buf, 4) != 4)
                         break;
@@ -630,11 +624,11 @@
                 if (lsx_eof(ft))
                         break;
                 buf[4] = '\0';
-                sox_warn("Ignoring AIFF tail chunk: '%s', %d bytes long", 
+                sox_warn("Ignoring AIFF tail chunk: '%s', %d bytes long",
                         buf, chunksize);
                 if (! strcmp(buf, "MARK") || ! strcmp(buf, "INST"))
                         sox_warn("       You're stripping MIDI/loop info!");
-                while (chunksize-- > 0) 
+                while (chunksize-- > 0)
                 {
                         if (lsx_readb(ft, (unsigned char *)&trash) == SOX_EOF)
                                 break;
@@ -656,7 +650,7 @@
 
 int sox_aiffstartwrite(sox_format_t * ft)
 {
-        aiff_t aiff = (aiff_t ) ft->priv;
+        priv_t * aiff = (priv_t *) ft->priv;
         int rc;
 
         /* Needed because lsx_rawwrite() */
@@ -677,7 +671,7 @@
 
 sox_size_t sox_aiffwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-        aiff_t aiff = (aiff_t ) ft->priv;
+        priv_t * aiff = (priv_t *) ft->priv;
         aiff->nsamples += len;
         lsx_rawwrite(ft, buf, len);
         return(len);
@@ -685,7 +679,7 @@
 
 int sox_aiffstopwrite(sox_format_t * ft)
 {
-        aiff_t aiff = (aiff_t ) ft->priv;
+        priv_t * aiff = (priv_t *) ft->priv;
 
         /* If we've written an odd number of bytes, write a padding
            NUL */
@@ -717,24 +711,24 @@
         unsigned i;
         sox_size_t padded_comment_size = 0, comment_size = 0;
         sox_size_t comment_chunk_size = 0;
-        char * comment = sox_cat_comments(ft->comments);
+        char * comment = sox_cat_comments(ft->oob.comments);
 
         /* MARK and INST chunks */
-        if (ft->instr.nloops) {
-          hsize += 8 /* MARK hdr */ + 2 + 16*ft->instr.nloops;
+        if (ft->oob.instr.nloops) {
+          hsize += 8 /* MARK hdr */ + 2 + 16*ft->oob.instr.nloops;
           hsize += 8 /* INST hdr */ + 20; /* INST chunk */
         }
 
-        if (ft->encoding.encoding == SOX_ENCODING_SIGN2 && 
+        if (ft->encoding.encoding == SOX_ENCODING_SIGN2 &&
             ft->encoding.bits_per_sample == 8)
                 bits = 8;
-        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 && 
+        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 &&
                  ft->encoding.bits_per_sample == 16)
                 bits = 16;
-        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 && 
+        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 &&
                  ft->encoding.bits_per_sample == 24)
                 bits = 24;
-        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 && 
+        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 &&
                  ft->encoding.bits_per_sample == 32)
                 bits = 32;
         else
@@ -745,7 +739,7 @@
 
         /* COMT comment chunk -- holds comments text with a timestamp and marker id */
         /* We calculate the comment_chunk_size if we will be writing a comment */
-        if (ft->comments)
+        if (ft->oob.comments)
         {
           comment_size = strlen(comment);
           /* Must put an even number of characters out.
@@ -755,16 +749,16 @@
                                 comment_size : comment_size + 1;
           /* one comment, timestamp, marker ID and text count */
           comment_chunk_size = (2 + 4 + 2 + 2 + padded_comment_size);
-          hsize += 8 /* COMT hdr */ + comment_chunk_size; 
+          hsize += 8 /* COMT hdr */ + comment_chunk_size;
         }
 
         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, 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 */
-        if (ft->comments)
+        if (ft->oob.comments)
         {
           lsx_writes(ft, "COMT");
           lsx_writedw(ft, comment_chunk_size);
@@ -797,20 +791,20 @@
         write_ieee_extended(ft, (double)ft->signal.rate);
 
         /* MARK chunk -- set markers */
-        if (ft->instr.nloops) {
+        if (ft->oob.instr.nloops) {
                 lsx_writes(ft, "MARK");
-                if (ft->instr.nloops > 2)
-                        ft->instr.nloops = 2;
-                lsx_writedw(ft, 2 + 16u*ft->instr.nloops);
-                lsx_writew(ft, ft->instr.nloops);
+                if (ft->oob.instr.nloops > 2)
+                        ft->oob.instr.nloops = 2;
+                lsx_writedw(ft, 2 + 16u*ft->oob.instr.nloops);
+                lsx_writew(ft, ft->oob.instr.nloops);
 
-                for(i = 0; i < ft->instr.nloops; i++) {
+                for(i = 0; i < ft->oob.instr.nloops; i++) {
                         lsx_writew(ft, i + 1);
-                        lsx_writedw(ft, ft->loops[i].start);
+                        lsx_writedw(ft, ft->oob.loops[i].start);
                         lsx_writeb(ft, 0);
                         lsx_writeb(ft, 0);
                         lsx_writew(ft, i*2 + 1);
-                        lsx_writedw(ft, ft->loops[i].start + ft->loops[i].length);
+                        lsx_writedw(ft, ft->oob.loops[i].start + ft->oob.loops[i].length);
                         lsx_writeb(ft, 0);
                         lsx_writeb(ft, 0);
                 }
@@ -818,21 +812,21 @@
                 lsx_writes(ft, "INST");
                 lsx_writedw(ft, 20);
                 /* random MIDI shit that we default on */
-                lsx_writeb(ft, (uint8_t)ft->instr.MIDInote);
+                lsx_writeb(ft, (uint8_t)ft->oob.instr.MIDInote);
                 lsx_writeb(ft, 0);                       /* detune */
-                lsx_writeb(ft, (uint8_t)ft->instr.MIDIlow);
-                lsx_writeb(ft, (uint8_t)ft->instr.MIDIhi);
+                lsx_writeb(ft, (uint8_t)ft->oob.instr.MIDIlow);
+                lsx_writeb(ft, (uint8_t)ft->oob.instr.MIDIhi);
                 lsx_writeb(ft, 1);                       /* low velocity */
                 lsx_writeb(ft, 127);                     /* hi  velocity */
                 lsx_writew(ft, 0);                               /* gain */
 
                 /* sustain loop */
-                lsx_writew(ft, ft->loops[0].type);
+                lsx_writew(ft, ft->oob.loops[0].type);
                 lsx_writew(ft, 1);                               /* marker 1 */
                 lsx_writew(ft, 3);                               /* marker 3 */
                 /* release loop, if there */
-                if (ft->instr.nloops == 2) {
-                        lsx_writew(ft, ft->loops[1].type);
+                if (ft->oob.instr.nloops == 2) {
+                        lsx_writew(ft, ft->oob.loops[1].type);
                         lsx_writew(ft, 2);                       /* marker 2 */
                         lsx_writew(ft, 4);                       /* marker 4 */
                 } else {
@@ -845,7 +839,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, 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);
@@ -853,7 +847,7 @@
 
 int sox_aifcstartwrite(sox_format_t * ft)
 {
-        aiff_t aiff = (aiff_t ) ft->priv;
+        priv_t * aiff = (priv_t *) ft->priv;
         int rc;
 
         /* Needed because lsx_rawwrite() */
@@ -874,7 +868,7 @@
 
 int sox_aifcstopwrite(sox_format_t * ft)
 {
-        aiff_t aiff = (aiff_t ) ft->priv;
+        priv_t * aiff = (priv_t *) ft->priv;
 
         /* If we've written an odd number of bytes, write a padding
            NUL */
@@ -904,16 +898,16 @@
                 8 /*SSND hdr*/ + 12 /*SSND chunk*/;
         unsigned bits = 0;
 
-        if (ft->encoding.encoding == SOX_ENCODING_SIGN2 && 
+        if (ft->encoding.encoding == SOX_ENCODING_SIGN2 &&
             ft->encoding.bits_per_sample == 8)
                 bits = 8;
-        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 && 
+        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 &&
                  ft->encoding.bits_per_sample == 16)
                 bits = 16;
-        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 && 
+        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 &&
                  ft->encoding.bits_per_sample == 24)
                 bits = 24;
-        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 && 
+        else if (ft->encoding.encoding == SOX_ENCODING_SIGN2 &&
                  ft->encoding.bits_per_sample == 32)
                 bits = 32;
         else
@@ -924,7 +918,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, hsize + nframes * (ft->encoding.bits_per_sample >> 3) * ft->signal.channels);
         lsx_writes(ft, "AIFC"); /* File type */
 
         /* FVER chunk */
@@ -948,7 +942,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, 8 + nframes * ft->signal.channels * (ft->encoding.bits_per_sample >> 3));
         lsx_writedw(ft, 0); /* offset */
         lsx_writedw(ft, 0); /* block size */
 
@@ -1045,15 +1039,15 @@
                 expon = 0;
             }
             expon |= sign;
-            fMant = ldexp(fMant, 32);          
-            fsMant = floor(fMant); 
+            fMant = ldexp(fMant, 32);
+            fsMant = floor(fMant);
             hiMant = FloatToUnsigned(fsMant);
-            fMant = ldexp(fMant - fsMant, 32); 
-            fsMant = floor(fMant); 
+            fMant = ldexp(fMant - fsMant, 32);
+            fsMant = floor(fMant);
             loMant = FloatToUnsigned(fsMant);
         }
     }
-    
+
     bytes[0] = expon >> 8;
     bytes[1] = expon;
     bytes[2] = hiMant >> 24;
@@ -1068,10 +1062,10 @@
 
 
 /*
- * C O N V E R T   F R O M   I E E E   E X T E N D E D  
+ * C O N V E R T   F R O M   I E E E   E X T E N D E D
  */
 
-/* 
+/*
  * Copyright (C) 1988-1991 Apple Computer, Inc.
  * All rights reserved.
  *
@@ -1114,7 +1108,7 @@
     double    f;
     int    expon;
     uint32_t hiMant, loMant;
-    
+
     expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
     hiMant    =    ((uint32_t)(bytes[2] & 0xFF) << 24)
             |    ((uint32_t)(bytes[3] & 0xFF) << 16)
--- a/src/aiff.h
+++ b/src/aiff.h
@@ -1,5 +1,11 @@
-/*
- * libSoX SGI/Amiga AIFF format.
+/* libSoX SGI/Amiga AIFF format.
+ * Copyright 1991-2007 Guido van Rossum And Sundry Contributors
+ *
+ * This source code is freely redistributable and may be used for
+ * any purpose.  This copyright notice must be maintained.
+ * Guido van Rossum And Sundry Contributors are not responsible for
+ * the consequences of using this software.
+ *
  * Used by SGI on 4D/35 and Indigo.
  * This is a subformat of the EA-IFF-85 format.
  * This is related to the IFF format used by the Amiga.
@@ -6,14 +12,13 @@
  * But, apparently, not the same.
  * Also AIFF-C format output that is defined in DAVIC 1.4 Part 9 Annex B
  * (usable for japanese-data-broadcasting, specified by ARIB STD-B24.)
- *
- * Copyright 1991-2007 Guido van Rossum And Sundry Contributors
- * 
- * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Guido van Rossum And Sundry Contributors are not responsible for 
- * the consequences of using this software.
  */
+
+typedef struct {
+    sox_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 */
+} aiff_priv_t;
 
 int sox_aiffseek(sox_format_t * ft, sox_size_t offset);
 int sox_aiffstartread(sox_format_t * ft);
--- a/src/al-fmt.c
+++ b/src/al-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* File format: raw A-law         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/alsa.c
+++ b/src/alsa.c
@@ -11,14 +11,13 @@
 
 #include <alsa/asoundlib.h>
 
-typedef struct alsa_priv
-{
-    snd_pcm_t *pcm_handle;
-    char *buf;
-    sox_size_t buf_size;
-    snd_pcm_uframes_t period_size;
-    snd_pcm_uframes_t frames_this_period;
-} *alsa_priv_t;
+typedef struct {
+  snd_pcm_t *pcm_handle;
+  char *buf;
+  sox_size_t buf_size;
+  snd_pcm_uframes_t period_size;
+  snd_pcm_uframes_t frames_this_period;
+} priv_t;
 
 static int get_format(sox_format_t * ft, snd_pcm_format_mask_t *fmask, int *fmt)
 {
@@ -48,7 +47,7 @@
     /* Some hardware only wants to work with 8-bit or 16-bit data */
     if (ft->encoding.bits_per_sample == 8)
     {
-        if (!(snd_pcm_format_mask_test(fmask, SND_PCM_FORMAT_U8)) && 
+        if (!(snd_pcm_format_mask_test(fmask, SND_PCM_FORMAT_U8)) &&
             !(snd_pcm_format_mask_test(fmask, SND_PCM_FORMAT_S8)))
         {
             sox_report("driver doesn't supported byte samples.  Changing to words.");
@@ -57,7 +56,7 @@
     }
     else if (ft->encoding.bits_per_sample == 16)
     {
-        if (!(snd_pcm_format_mask_test(fmask, SND_PCM_FORMAT_U16)) && 
+        if (!(snd_pcm_format_mask_test(fmask, SND_PCM_FORMAT_U16)) &&
             !(snd_pcm_format_mask_test(fmask, SND_PCM_FORMAT_S16)))
         {
             sox_report("driver doesn't supported word samples.  Changing to bytes.");
@@ -175,7 +174,7 @@
 {
     int fmt = SND_PCM_FORMAT_S16;
     int err;
-    alsa_priv_t alsa = (alsa_priv_t)ft->priv;
+    priv_t * alsa = (priv_t *)ft->priv;
     snd_pcm_hw_params_t *hw_params = NULL;
     unsigned int min_rate, max_rate;
     unsigned int min_chan, max_chan;
@@ -188,21 +187,21 @@
 
     lsx_set_signal_defaults(&ft->signal);
 
-    if ((err = snd_pcm_open(&(alsa->pcm_handle), ft->filename, 
-                            mode, 0)) < 0) 
+    if ((err = snd_pcm_open(&(alsa->pcm_handle), ft->filename,
+                            mode, 0)) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM, "cannot open audio device");
         goto open_error;
     }
 
-    if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) 
+    if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0)
     {
-        lsx_fail_errno(ft, SOX_ENOMEM, 
+        lsx_fail_errno(ft, SOX_ENOMEM,
                       "cannot allocate hardware parameter structure");
         goto open_error;
     }
 
-    if ((err = snd_pcm_hw_params_any(alsa->pcm_handle, hw_params)) < 0) 
+    if ((err = snd_pcm_hw_params_any(alsa->pcm_handle, hw_params)) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM,
                       "cannot initialize hardware parameter structure");
@@ -218,7 +217,7 @@
     }
 #endif
 
-    if ((err = snd_pcm_hw_params_set_access(alsa->pcm_handle, hw_params, 
+    if ((err = snd_pcm_hw_params_set_access(alsa->pcm_handle, hw_params,
                                             SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM,
@@ -228,12 +227,12 @@
 
     snd_pcm_hw_params_get_channels_min(hw_params, &min_chan);
     snd_pcm_hw_params_get_channels_max(hw_params, &max_chan);
-    if (ft->signal.channels == 0) 
+    if (ft->signal.channels == 0)
         ft->signal.channels = min_chan;
-    else 
-        if (ft->signal.channels > max_chan) 
+    else
+        if (ft->signal.channels > max_chan)
             ft->signal.channels = max_chan;
-        else if (ft->signal.channels < min_chan) 
+        else if (ft->signal.channels < min_chan)
             ft->signal.channels = min_chan;
 
     if (snd_pcm_format_mask_malloc(&fmask) < 0)
@@ -246,8 +245,8 @@
     snd_pcm_format_mask_free(fmask);
     fmask = NULL;
 
-    if ((err = snd_pcm_hw_params_set_format(alsa->pcm_handle, 
-                                            hw_params, fmt)) < 0) 
+    if ((err = snd_pcm_hw_params_set_format(alsa->pcm_handle,
+                                            hw_params, fmt)) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM, "cannot set sample format");
         goto open_error;
@@ -264,18 +263,18 @@
         ft->signal.rate = rate;
     }
     dir = 0;
-    if ((err = snd_pcm_hw_params_set_rate_near(alsa->pcm_handle, 
-                                               hw_params, 
+    if ((err = snd_pcm_hw_params_set_rate_near(alsa->pcm_handle,
+                                               hw_params,
                                                &rate,
-                                               &dir)) < 0) 
+                                               &dir)) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM, "cannot set sample rate");
         goto open_error;
     }
-    snd_pcm_hw_params_get_rate(hw_params, 
+    snd_pcm_hw_params_get_rate(hw_params,
                                &rate,
                                &dir);
- 
+
     if (rate != ft->signal.rate)
     {
         sox_report("Could not set exact rate of %g.  Approximating with %i",
@@ -285,8 +284,8 @@
     snd_pcm_hw_params_get_rate(hw_params, &rate, &dir);
 
     if ((err = snd_pcm_hw_params_set_channels(alsa->pcm_handle,
-                                              hw_params, 
-                                              ft->signal.channels)) < 0) 
+                                              hw_params,
+                                              ft->signal.channels)) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM, "cannot set channel count");
         goto open_error;
@@ -308,7 +307,7 @@
     }
 
     dir = 0;
-    if (snd_pcm_hw_params_get_period_size_min(hw_params, 
+    if (snd_pcm_hw_params_get_period_size_min(hw_params,
                                               &period_size_min, &dir) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM, "Error getting min period size.");
@@ -316,7 +315,7 @@
     }
 
     dir = 0;
-    if (snd_pcm_hw_params_get_period_size_max(hw_params, 
+    if (snd_pcm_hw_params_get_period_size_max(hw_params,
                                               &period_size_max, &dir) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM, "Error getting max buffer size.");
@@ -332,8 +331,8 @@
     buffer_size = period_size * 8;
 
     dir = 0;
-    if (snd_pcm_hw_params_set_period_size_near(alsa->pcm_handle, hw_params, 
-                                               &period_size, &dir) < 0) 
+    if (snd_pcm_hw_params_set_period_size_near(alsa->pcm_handle, hw_params,
+                                               &period_size, &dir) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM, "Error setting periods.");
         goto open_error;
@@ -341,7 +340,7 @@
     snd_pcm_hw_params_get_period_size(hw_params, &period_size, &dir);
 
     dir = 0;
-    if (snd_pcm_hw_params_set_buffer_size_near(alsa->pcm_handle, hw_params, 
+    if (snd_pcm_hw_params_set_buffer_size_near(alsa->pcm_handle, hw_params,
                                                &buffer_size) < 0) {
         lsx_fail_errno(ft, SOX_EPERM, "Error setting buffer size.");
         goto open_error;
@@ -354,7 +353,7 @@
         goto open_error;
     }
 
-    if ((err = snd_pcm_hw_params(alsa->pcm_handle, hw_params)) < 0) 
+    if ((err = snd_pcm_hw_params(alsa->pcm_handle, hw_params)) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM, "cannot set parameters");
         goto open_error;
@@ -363,7 +362,7 @@
     snd_pcm_hw_params_free(hw_params);
     hw_params = NULL;
 
-    if ((err = snd_pcm_prepare(alsa->pcm_handle)) < 0) 
+    if ((err = snd_pcm_prepare(alsa->pcm_handle)) < 0)
     {
         lsx_fail_errno(ft, SOX_EPERM, "cannot prepare audio interface for use");
         goto open_error;
@@ -391,21 +390,21 @@
  */
 static int xrun_recovery(snd_pcm_t *handle, int err)
 {
-    if (err == -EPIPE) 
+    if (err == -EPIPE)
     {   /* over/under-run */
         err = snd_pcm_prepare(handle);
         if (err < 0)
             sox_warn("Can't recover from over/underrun, prepare failed: %s", snd_strerror(err));
         return 0;
-    } 
-    else 
+    }
+    else
     {
-        if (err == -ESTRPIPE) 
+        if (err == -ESTRPIPE)
         {
             /* wait until the suspend flag is released */
             while ((err = snd_pcm_resume(handle)) == -EAGAIN)
-                sleep(1);                       
-            if (err < 0) 
+                sleep(1);
+            if (err < 0)
             {
                 err = snd_pcm_prepare(handle);
                 if (err < 0)
@@ -469,7 +468,7 @@
 
 static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t nsamp)
 {
-    alsa_priv_t alsa = (alsa_priv_t)ft->priv;
+    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;
 
@@ -503,7 +502,7 @@
 
     len = 0;
     while (len < nsamp) {
-      sox_size_t n = snd_pcm_readi(alsa->pcm_handle, alsa->buf, 
+      sox_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) {
@@ -521,7 +520,7 @@
 
 static int stopread(sox_format_t * ft)
 {
-    alsa_priv_t alsa = (alsa_priv_t)ft->priv;
+    priv_t * alsa = (priv_t *)ft->priv;
 
     snd_pcm_close(alsa->pcm_handle);
 
@@ -574,7 +573,7 @@
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp)
 {
     sox_size_t osamp, done;
-    alsa_priv_t alsa = (alsa_priv_t)ft->priv;
+    priv_t * alsa = (priv_t *)ft->priv;
     void (*write_buf)(char *, const sox_sample_t *, sox_size_t, sox_bool, sox_size_t *) = 0;
 
     switch(ft->encoding.bits_per_sample) {
@@ -614,14 +613,14 @@
     for (done = 0; done < nsamp; done += osamp) {
       int err;
       sox_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);
       buf += osamp;
 
       for (len = 0; len < osamp;) {
-        err = snd_pcm_writei(alsa->pcm_handle, 
-                             alsa->buf + (len * (ft->encoding.bits_per_sample >> 3)), 
+        err = snd_pcm_writei(alsa->pcm_handle,
+                             alsa->buf + (len * (ft->encoding.bits_per_sample >> 3)),
                              (osamp - len) / ft->signal.channels);
         if (errno == EAGAIN) /* Happens naturally; don't report it */
           errno = 0;
@@ -644,7 +643,7 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-  alsa_priv_t alsa = (alsa_priv_t)ft->priv;
+  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;
@@ -665,13 +664,12 @@
     SOX_ENCODING_SIGN2, 16, 8, 0,
     SOX_ENCODING_UNSIGNED, 16, 8, 0,
     0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
     "Advanced Linux Sound Architecture device driver",
     names, SOX_FILE_DEVICE | SOX_FILE_NOSTDIO,
     startread, read_samples, stopread,
     startwrite, write_samples, stopwrite,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/amr-nb.c
+++ b/src/amr-nb.c
@@ -1,5 +1,4 @@
-/*
- * File format: AMR-NB   (c) 2007 robs@users.sourceforge.net
+/* File format: AMR-NB   (c) 2007 robs@users.sourceforge.net
  *
  * 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
--- a/src/amr-wb.c
+++ b/src/amr-wb.c
@@ -1,6 +1,5 @@
-/*
- * File format: AMR-WB   (c) 2007 robs@users.sourceforge.net
- * 
+/* File format: AMR-WB   (c) 2007 robs@users.sourceforge.net
+ *
  * 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
--- a/src/amr.h
+++ b/src/amr.h
@@ -1,5 +1,4 @@
-/*
- * File format: AMR   (c) 2007 robs@users.sourceforge.net
+/* File format: AMR   (c) 2007 robs@users.sourceforge.net
  *
  * 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
@@ -19,19 +18,16 @@
 #include <string.h>
 #include <math.h>
 
-typedef struct amr
-{
+typedef struct {
   void * state;
   unsigned mode;
   short pcm[AMR_FRAME];
   sox_size_t pcm_index;
-} * amr_t;
+} priv_t;
+#define p (*(priv_t *)ft->priv)
 
-assert_static(sizeof(struct amr) <= SOX_MAX_FILE_PRIVSIZE, AMR_PRIV_TOO_BIG);
-
 static sox_size_t decode_1_frame(sox_format_t * ft)
 {
-  amr_t amr = (amr_t) ft->priv;
   size_t n_1;
   UWord8 coded[AMR_CODED_MAX];
 
@@ -40,13 +36,12 @@
   n_1 = block_size[(coded[0] >> 3) & 0x0F] - 1;
   if (lsx_readbuf(ft, &coded[1], n_1) != n_1)
     return AMR_FRAME;
-  D_IF_decode(amr->state, coded, amr->pcm, 0);
+  D_IF_decode(p.state, coded, p.pcm, 0);
   return 0;
 }
 
 static sox_bool encode_1_frame(sox_format_t * ft)
 {
-  amr_t amr = (amr_t) ft->priv;
   UWord8 coded[AMR_CODED_MAX];
 #include "amr1.h"
   sox_bool result = lsx_writebuf(ft, coded, (unsigned)n) == (unsigned)n;
@@ -57,11 +52,10 @@
 
 static int startread(sox_format_t * ft)
 {
-  amr_t amr = (amr_t) ft->priv;
   char buffer[sizeof(magic) - 1];
 
-  amr->pcm_index = AMR_FRAME;
-  amr->state = D_IF_init();
+  p.pcm_index = AMR_FRAME;
+  p.state = D_IF_init();
 
   if (lsx_readchars(ft, buffer, sizeof(buffer)))
     return SOX_EOF;
@@ -77,15 +71,14 @@
 
 static sox_size_t read(sox_format_t * ft, sox_sample_t * buf, sox_size_t len)
 {
-  amr_t amr = (amr_t) ft->priv;
   sox_size_t done;
 
   for (done = 0; done < len; done++) {
-    if (amr->pcm_index >= AMR_FRAME)
-      amr->pcm_index = decode_1_frame(ft);
-    if (amr->pcm_index >= AMR_FRAME)
+    if (p.pcm_index >= AMR_FRAME)
+      p.pcm_index = decode_1_frame(ft);
+    if (p.pcm_index >= AMR_FRAME)
       break;
-    *buf++ = SOX_SIGNED_16BIT_TO_SAMPLE(amr->pcm[amr->pcm_index++], ft->clips);
+    *buf++ = SOX_SIGNED_16BIT_TO_SAMPLE(p.pcm[p.pcm_index++], ft->clips);
   }
   return done;
 }
@@ -92,39 +85,35 @@
 
 static int stopread(sox_format_t * ft)
 {
-  amr_t amr = (amr_t) ft->priv;
-  D_IF_exit(amr->state);
+  D_IF_exit(p.state);
   return SOX_SUCCESS;
 }
 
 static int startwrite(sox_format_t * ft)
 {
-  amr_t amr = (amr_t) ft->priv;
-
   if (ft->encoding.compression != HUGE_VAL) {
-    amr->mode = ft->encoding.compression;
-    if (amr->mode != ft->encoding.compression || amr->mode > AMR_MODE_MAX) {
+    p.mode = ft->encoding.compression;
+    if (p.mode != ft->encoding.compression || p.mode > AMR_MODE_MAX) {
       lsx_fail_errno(ft, SOX_EINVAL, "compression level must be a whole number from 0 to %i", AMR_MODE_MAX);
       return SOX_EOF;
     }
   }
-  else amr->mode = 0;
+  else p.mode = 0;
 
 #include "amr2.h"
   lsx_writes(ft, magic);
-  amr->pcm_index = 0;
+  p.pcm_index = 0;
   return SOX_SUCCESS;
 }
 
 static sox_size_t write(sox_format_t * ft, const sox_sample_t * buf, sox_size_t len)
 {
-  amr_t amr = (amr_t) ft->priv;
   sox_size_t done;
 
   for (done = 0; done < len; ++done) {
-    amr->pcm[amr->pcm_index++] = SOX_SAMPLE_TO_SIGNED_16BIT(*buf++, ft->clips);
-    if (amr->pcm_index == AMR_FRAME) {
-      amr->pcm_index = 0;
+    p.pcm[p.pcm_index++] = SOX_SAMPLE_TO_SIGNED_16BIT(*buf++, ft->clips);
+    if (p.pcm_index == AMR_FRAME) {
+      p.pcm_index = 0;
       if (!encode_1_frame(ft))
         return 0;
     }
@@ -134,17 +123,16 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-  amr_t amr = (amr_t) ft->priv;
   int result = SOX_SUCCESS;
 
-  if (amr->pcm_index) {
+  if (p.pcm_index) {
     do {
-      amr->pcm[amr->pcm_index++] = 0;
-    } while (amr->pcm_index < AMR_FRAME);
+      p.pcm[p.pcm_index++] = 0;
+    } while (p.pcm_index < AMR_FRAME);
     if (!encode_1_frame(ft))
       result = SOX_EOF;
   }
-  E_IF_exit(amr->state);
+  E_IF_exit(p.state);
   return result;
 }
 
@@ -160,7 +148,7 @@
     names, SOX_FILE_MONO,
     startread, read, stopread,
     startwrite, write, stopwrite,
-    NULL, write_encodings, write_rates
+    NULL, write_encodings, write_rates, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/amr1.h
+++ b/src/amr1.h
@@ -1,5 +1,4 @@
-/*
- * This library is free software; you can redistribute it and/or modify it
+/* 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.
@@ -14,18 +13,18 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#if defined __GNUC__ 
-  #pragma GCC system_header 
-#elif defined __SUNPRO_CC 
-  #pragma disable_warn 
-#elif defined _MSC_VER 
-  #pragma warning(push, 1) 
-#endif 
+#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);
+  int n = E_IF_encode(p.state, p.mode, p.pcm, coded, 1);
 
-#if defined __SUNPRO_CC 
-  #pragma enable_warn 
-#elif defined _MSC_VER 
-  #pragma warning(pop) 
-#endif 
+#if defined __SUNPRO_CC
+  #pragma enable_warn
+#elif defined _MSC_VER
+  #pragma warning(pop)
+#endif
--- a/src/amr2.h
+++ b/src/amr2.h
@@ -1,5 +1,4 @@
-/*
- * This library is free software; you can redistribute it and/or modify it
+/* 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.
@@ -14,18 +13,18 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#if defined __GNUC__ 
-  #pragma GCC system_header 
-#elif defined __SUNPRO_CC 
-  #pragma disable_warn 
-#elif defined _MSC_VER 
-  #pragma warning(push, 1) 
-#endif 
+#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();
+  p.state = E_IF_init();
 
-#if defined __SUNPRO_CC 
-  #pragma enable_warn 
-#elif defined _MSC_VER 
-  #pragma warning(pop) 
-#endif 
+#if defined __SUNPRO_CC
+  #pragma enable_warn
+#elif defined _MSC_VER
+  #pragma warning(pop)
+#endif
--- a/src/ao.c
+++ b/src/ao.c
@@ -1,5 +1,4 @@
-/*
- * libao player support for sox
+/* libao player support for sox
  * (c) Reuben Thomas <rrt@sc3d.org> 2007
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -24,18 +23,17 @@
 #include <string.h>
 #include <ao/ao.h>
 
-typedef struct ao_priv
-{
+typedef struct {
   int driver_id;
   ao_device *device;
   ao_sample_format format;
   char *buf;
   sox_size_t buf_size;
-} *ao_priv_t;
+} priv_t;
 
 static int startwrite(sox_format_t * ft)
 {
-  ao_priv_t ao = (ao_priv_t)ft->priv;
+  priv_t * ao = (priv_t *)ft->priv;
 
   lsx_set_signal_defaults(&ft->signal);
   ao->buf_size = sox_globals.bufsiz - (sox_globals.bufsiz % (ft->encoding.bits_per_sample >> 3));
@@ -91,7 +89,7 @@
 
 static sox_size_t write_samples(sox_format_t *ft, const sox_sample_t *buf, sox_size_t len)
 {
-  ao_priv_t ao = (ao_priv_t)ft->priv;
+  priv_t * ao = (priv_t *)ft->priv;
   sox_size_t aobuf_size;
 
   if (len > ao->buf_size / (ft->encoding.bits_per_sample >> 3))
@@ -109,7 +107,7 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-  ao_priv_t ao = (ao_priv_t)ft->priv;
+  priv_t * ao = (priv_t *)ft->priv;
 
   free(ao->buf);
 
@@ -126,13 +124,11 @@
 {
   static char const * const names[] = {"ao", NULL};
   static unsigned const encodings[] = {SOX_ENCODING_SIGN2, 16, 0, 0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
-    "Xiph's libao device driver",
-    names, SOX_FILE_DEVICE | SOX_FILE_NOSTDIO,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
+    "Xiph's libao device driver", names, SOX_FILE_DEVICE | SOX_FILE_NOSTDIO,
     NULL, NULL, NULL,
     startwrite, write_samples, stopwrite,
-    NULL, encodings, NULL
+    NULL, encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/au.c
+++ b/src/au.c
@@ -1,5 +1,6 @@
-/*
+/* libSoX Sun format with header (SunOS 4.1; see /usr/demo/SOUND).
  * Copyright 1991, 1992, 1993 Guido van Rossum And Sundry Contributors.
+ *
  * This source code is freely redistributable and may be used for
  * any purpose.  This copyright notice must be maintained.
  * Guido van Rossum And Sundry Contributors are not responsible for
@@ -8,7 +9,6 @@
  * October 7, 1998 - cbagwell@sprynet.com
  *   G.723 was using incorrect # of bits.  Corrected to 3 and 5 bits.
  *
- * libSoX Sun format with header (SunOS 4.1; see /usr/demo/SOUND).
  * NeXT uses this format also, but has more format codes defined.
  * DEC uses a slight variation and swaps bytes.
  * We support only the common formats, plus
@@ -93,7 +93,7 @@
  */
 static int unpack_input(sox_format_t * ft, unsigned char *code)
 {
-  priv_t * p = (priv_t * ) ft->priv;
+  priv_t * p = (priv_t *) ft->priv;
   unsigned char           in_byte;
 
   if (p->in_bits < (int)ft->encoding.bits_per_sample) {
@@ -124,7 +124,7 @@
 
 static int startread(sox_format_t * ft)
 {
-  priv_t * p = (priv_t * ) ft->priv;
+  priv_t * p = (priv_t *) ft->priv;
   char     magic[4];     /* These 6 variables represent a Sun sound */
   uint32_t hdr_size;     /* header on disk.  The uint32_t are written as */
   uint32_t data_size;    /* big-endians.  At least extra bytes (totalling */
@@ -136,7 +136,7 @@
 
   if (lsx_readchars(ft, magic, sizeof(magic)))
     return SOX_EOF;
- 
+
   for (i = 0; id[i].desc && memcmp(magic, id[i].str, sizeof(magic)); ++i);
   if (!id[i].desc) {
     lsx_fail_errno(ft, SOX_EHDR, "au: can't find Sun/NeXT/DEC identifier");
@@ -183,7 +183,7 @@
       free(buf);
       return SOX_EOF;
     }
-    sox_append_comments(&ft->comments, buf);
+    sox_append_comments(&ft->oob.comments, buf);
     free(buf);
   }
   if (data_size == SUN_UNSPEC)
@@ -194,10 +194,10 @@
 
 static int write_header(sox_format_t * ft)
 {
-  char * comment  = sox_cat_comments(ft->comments);
+  char * comment  = sox_cat_comments(ft->oob.comments);
   size_t len      = strlen(comment) + 1;     /* Write out null-terminated */
   size_t info_len = max(4, (len + 3) & ~3u); /* Minimum & multiple of 4 bytes */
-  size_t size     = ft->olength? ft->olength : ft->length;
+  size_t size     = ft->olength? ft->olength : ft->signal.length;
   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))
@@ -226,7 +226,7 @@
     names, SOX_FILE_BIG_END | SOX_FILE_REWIND,
     startread, lsx_rawread, NULL,
     write_header, lsx_rawwrite, NULL,
-    lsx_rawseek, write_encodings, NULL
+    lsx_rawseek, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/avr.c
+++ b/src/avr.c
@@ -1,8 +1,6 @@
-/*
-
-    AVR file format handler for SoX
-    Copyright (C) 1999 Jan Paul Schmidt <jps@fundament.org>
-
+/* AVR file format handler for SoX
+ * Copyright (C) 1999 Jan Paul Schmidt <jps@fundament.org>
+ *
  * 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
@@ -16,7 +14,6 @@
  * 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
-
  */
 
 #include "sox_i.h"
@@ -28,7 +25,7 @@
 
 /* Taken from the Audio File Formats FAQ */
 
-typedef struct avrstuff {
+typedef struct {
   char magic [5];      /* 2BIT */
   char name [8];       /* null-padded sample name */
   unsigned short mono; /* 0 = mono, 0xffff = stereo */
@@ -50,22 +47,22 @@
   char ext[20];        /* Additional filename space, used
                           if (name[7] != 0) */
   char user[64];       /* User defined. Typically ASCII message. */
-} *avr_t;
+} priv_t;
 
 
 
 /*
  * Do anything required before you start reading samples.
- * Read file header. 
- *      Find out sampling rate, 
- *      size and encoding of samples, 
+ * Read file header.
+ *      Find out sampling rate,
+ *      size and encoding of samples,
  *      mono/stereo/quad.
  */
 
 
-static int startread(sox_format_t * ft) 
+static int startread(sox_format_t * ft)
 {
-  avr_t avr = (avr_t)ft->priv;
+  priv_t * avr = (priv_t *)ft->priv;
   int rc;
 
   lsx_reads(ft, avr->magic, 4);
@@ -141,9 +138,9 @@
   return(SOX_SUCCESS);
 }
 
-static int startwrite(sox_format_t * ft) 
+static int startwrite(sox_format_t * ft)
 {
-  avr_t avr = (avr_t)ft->priv;
+  priv_t * avr = (priv_t *)ft->priv;
   int rc;
 
   if (!ft->seekable) {
@@ -237,7 +234,7 @@
   lsx_writebuf(ft, (void *)"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(avr->ext));
 
   /* user */
-  lsx_writebuf(ft, 
+  lsx_writebuf(ft,
            (void *)"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
            "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
            "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
@@ -246,9 +243,9 @@
   return(SOX_SUCCESS);
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp) 
+static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp)
 {
-  avr_t avr = (avr_t)ft->priv;
+  priv_t * avr = (priv_t *)ft->priv;
 
   avr->size += nsamp;
 
@@ -255,9 +252,9 @@
   return (lsx_rawwrite (ft, buf, nsamp));
 }
 
-static int stopwrite(sox_format_t * ft) 
+static int stopwrite(sox_format_t * ft)
 {
-  avr_t avr = (avr_t)ft->priv;
+  priv_t * avr = (priv_t *)ft->priv;
 
   unsigned size = avr->size / ft->signal.channels;
 
@@ -279,14 +276,12 @@
     SOX_ENCODING_SIGN2, 16, 8, 0,
     SOX_ENCODING_UNSIGNED, 16, 8, 0,
     0};
-  static sox_format_handler_t handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
     "Audio Visual Research format; used on the Mac",
-    names,
-    SOX_FILE_BIG_END|SOX_FILE_MONO|SOX_FILE_STEREO,
+    names, SOX_FILE_BIG_END | SOX_FILE_MONO | SOX_FILE_STEREO,
     startread, lsx_rawread, NULL,
     startwrite, write_samples, stopwrite,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/band.h
+++ b/src/band.h
@@ -1,34 +1,30 @@
-/*
- * July 5, 1991
+/* libSoX Bandpass effect file.     July 5, 1991
  * Copyright 1991 Lance Norskog And Sundry Contributors
+ *
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Lance Norskog And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Lance Norskog And Sundry Contributors are not responsible for
  * the consequences of using this software.
- */
-
-/*
- * libSoX Bandpass effect file.
  *
  * Algorithm:  2nd order recursive filter.
  * Formula stolen from MUSIC56K, a toolkit of 56000 assembler stuff.
  * Quote:
- *   This is a 2nd order recursive band pass filter of the form.                
- *   y(n)= a * x(n) - b * y(n-1) - c * y(n-2)   
- *   where :    
- *        x(n) = "IN"           
- *        "OUT" = y(n)          
- *        c = EXP(-2*pi*cBW/S_RATE)             
- *        b = -4*c/(1+c)*COS(2*pi*cCF/S_RATE)   
- *   if cSCL=2 (i.e. noise input)               
- *        a = SQT(((1+c)*(1+c)-b*b)*(1-c)/(1+c))                
- *   else       
- *        a = SQT(1-b*b/(4*c))*(1-c)            
- *   endif      
- *   note :     cCF is the center frequency in Hertz            
- *        cBW is the band width in Hertz        
- *        cSCL is a scale factor, use 1 for pitched sounds      
- *   use 2 for noise.           
+ *   This is a 2nd order recursive band pass filter of the form.
+ *   y(n)= a * x(n) - b * y(n-1) - c * y(n-2)
+ *   where :
+ *        x(n) = "IN"
+ *        "OUT" = y(n)
+ *        c = EXP(-2*pi*cBW/S_RATE)
+ *        b = -4*c/(1+c)*COS(2*pi*cCF/S_RATE)
+ *   if cSCL=2 (i.e. noise input)
+ *        a = SQT(((1+c)*(1+c)-b*b)*(1-c)/(1+c))
+ *   else
+ *        a = SQT(1-b*b/(4*c))*(1-c)
+ *   endif
+ *   note :     cCF is the center frequency in Hertz
+ *        cBW is the band width in Hertz
+ *        cSCL is a scale factor, use 1 for pitched sounds
+ *   use 2 for noise.
  *
  *
  * July 1, 1999 - Jan Paul Schmidt <jps@fundament.org>
@@ -36,15 +32,15 @@
  *   This looks like the resonator band pass in SPKit. It's a
  *   second order all-pole (IIR) band-pass filter described
  *   at the pages 186 - 189 in
- *     Dodge, Charles & Jerse, Thomas A. 1985: 
+ *     Dodge, Charles & Jerse, Thomas A. 1985:
  *       Computer Music -- Synthesis, Composition and Performance.
- *       New York: Schirmer Books.  
+ *       New York: Schirmer Books.
  *   Reference from the SPKit manual.
  */
 
-  p->a2 = exp(-2 * M_PI * bw_Hz / effp->in_signal.rate);
-  p->a1 = -4 * p->a2 / (1 + p->a2) * cos(2 * M_PI * p->fc / effp->in_signal.rate);
-  if (p->filter_type == filter_BPF_SPK_N)
-    p->b0 = sqrt(((1+p->a2) * (1+p->a2) - p->a1*p->a1) * (1-p->a2) / (1+p->a2));
+  p.a2 = exp(-2 * M_PI * bw_Hz / effp->in_signal.rate);
+  p.a1 = -4 * p.a2 / (1 + p.a2) * cos(2 * M_PI * p.fc / effp->in_signal.rate);
+  if (p.filter_type == filter_BPF_SPK_N)
+    p.b0 = sqrt(((1+p.a2) * (1+p.a2) - p.a1*p.a1) * (1-p.a2) / (1+p.a2));
   else
-    p->b0 = sqrt(1 - p->a1 * p->a1 / (4 * p->a2)) * (1 - p->a2);
+    p.b0 = sqrt(1 - p.a1 * p.a1 / (4 * p.a2)) * (1 - p.a2);
--- a/src/biquad.c
+++ b/src/biquad.c
@@ -1,4 +1,5 @@
-/*
+/* libSoX Biquad filter common functions   (c) 2006-7 robs@users.sourceforge.net
+ *
  * 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
@@ -14,13 +15,13 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-/* Biquad filter common functions   (c) 2006-7 robs@users.sourceforge.net */
-
-
 #include "biquad.h"
 #include <string.h>
 
+typedef biquad_t priv_t;
+#define p (*(priv_t *)effp->priv)
 
+
 static char const * const width_str[] = {
   "band-width(Hz)",
   "band-width(Hz, no warp)", /* deprecated */
@@ -35,20 +36,19 @@
     int min_args, int max_args, int fc_pos, int width_pos, int gain_pos,
     char const * allowed_width_types, filter_t filter_type)
 {
-  biquad_t p = (biquad_t) effp->priv;
   char width_type = *allowed_width_types;
   char dummy;     /* To check for extraneous chars. */
 
-  p->filter_type = filter_type;
+  p.filter_type = filter_type;
   if (n < min_args || n > max_args ||
-      (n > fc_pos    && (sscanf(argv[fc_pos], "%lf %c", &p->fc, &dummy) != 1 || p->fc <= 0)) ||
-      (n > width_pos && ((unsigned)(sscanf(argv[width_pos], "%lf%c %c", &p->width, &width_type, &dummy)-1) > 1 || p->width <= 0)) ||
-      (n > gain_pos  && sscanf(argv[gain_pos], "%lf %c", &p->gain, &dummy) != 1) ||
-      !strchr(allowed_width_types, width_type) || (width_type == 's' && p->width > 1))
+      (n > fc_pos    && (sscanf(argv[fc_pos], "%lf %c", &p.fc, &dummy) != 1 || p.fc <= 0)) ||
+      (n > width_pos && ((unsigned)(sscanf(argv[width_pos], "%lf%c %c", &p.width, &width_type, &dummy)-1) > 1 || p.width <= 0)) ||
+      (n > gain_pos  && sscanf(argv[gain_pos], "%lf %c", &p.gain, &dummy) != 1) ||
+      !strchr(allowed_width_types, width_type) || (width_type == 's' && p.width > 1))
     return lsx_usage(effp);
-  p->width_type = strchr(all_width_types, width_type) - all_width_types;
-  if (p->width_type >= strlen(all_width_types))
-    p->width_type = 0;
+  p.width_type = strchr(all_width_types, width_type) - all_width_types;
+  if (p.width_type >= strlen(all_width_types))
+    p.width_type = 0;
   return SOX_SUCCESS;
 }
 
@@ -55,14 +55,12 @@
 
 int sox_biquad_start(sox_effect_t * effp)
 {
-  biquad_t p = (biquad_t) effp->priv;
-
   /* Simplify: */
-  p->b2 /= p->a0;
-  p->b1 /= p->a0;
-  p->b0 /= p->a0;
-  p->a2 /= p->a0;
-  p->a1 /= p->a0;
+  p.b2 /= p.a0;
+  p.b1 /= p.a0;
+  p.b0 /= p.a0;
+  p.a2 /= p.a0;
+  p.a1 /= p.a0;
 
   if (effp->global_info->plot == sox_plot_octave) {
     printf(
@@ -78,10 +76,9 @@
       "semilogx(w,20*log10(h))\n"
       "disp('Hit return to continue')\n"
       "pause\n"
-      , effp->handler.name, p->gain, p->fc, width_str[p->width_type], p->width
+      , effp->handler.name, p.gain, p.fc, width_str[p.width_type], p.width
       , effp->in_signal.rate, effp->in_signal.rate
-      , p->b0, p->b1, p->b2, p->a1, p->a2
-      );
+      , p.b0, p.b1, p.b2, p.a1, p.a2);
     return SOX_EOF;
   }
   if (effp->global_info->plot == sox_plot_gnuplot) {
@@ -99,14 +96,12 @@
       "set key off\n"
       "plot [f=10:Fs/2] [-35:25] 20*log10(H(f))\n"
       "pause -1 'Hit return to continue'\n"
-      , effp->handler.name, p->gain, p->fc, width_str[p->width_type], p->width
+      , effp->handler.name, p.gain, p.fc, width_str[p.width_type], p.width
       , effp->in_signal.rate, effp->in_signal.rate
-      , p->b0, p->b1, p->b2, p->a1, p->a2
-      );
+      , p.b0, p.b1, p.b2, p.a1, p.a2);
     return SOX_EOF;
   }
-
-  p->o2 = p->o1 = p->i2 = p-> i1 = 0;
+  p.o2 = p.o1 = p.i2 = p. i1 = 0;
   return SOX_SUCCESS;
 }
 
@@ -114,15 +109,11 @@
 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)
 {
-  biquad_t p = (biquad_t) effp->priv;
-  sox_size_t len = min(*isamp, *osamp);
-  *isamp = *osamp = len;
-
-  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++;
-    p->o2 = p->o1, p->o1 = o0;
+  sox_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++;
+    p.o2 = p.o1, p.o1 = o0;
     *obuf++ = SOX_ROUND_CLIP_COUNT(o0, effp->clips);
   }
   return SOX_SUCCESS;
--- a/src/biquad.h
+++ b/src/biquad.h
@@ -1,4 +1,5 @@
-/*
+/* libSoX Biquad filter common definitions (c) 2006-7 robs@users.sourceforge.net
+ *
  * 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
@@ -14,27 +15,24 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-/* Biquad filter common definitions   (c) 2006-7 robs@users.sourceforge.net */
-
 #ifndef biquad_included
 #define biquad_included
 
 #include "sox_i.h"
 
-
 typedef enum {
-  filter_LPF, 
-  filter_HPF, 
-  filter_BPF_CSG, 
-  filter_BPF, 
-  filter_notch, 
-  filter_APF, 
-  filter_peakingEQ, 
-  filter_lowShelf, 
+  filter_LPF,
+  filter_HPF,
+  filter_BPF_CSG,
+  filter_BPF,
+  filter_notch,
+  filter_APF,
+  filter_peakingEQ,
+  filter_lowShelf,
   filter_highShelf,
-  filter_LPF_1, 
-  filter_HPF_1, 
-  filter_BPF_SPK, 
+  filter_LPF_1,
+  filter_HPF_1,
+  filter_BPF_SPK,
   filter_BPF_SPK_N,
   filter_AP1,
   filter_AP2,
@@ -41,7 +39,6 @@
   filter_deemph
 } filter_t;
 
-
 typedef enum {
   width_bw_Hz,
   /* The old, non-RBJ, non-freq-warped band-pass/reject response;
@@ -52,14 +49,12 @@
   width_slope
 } width_t;
 
-
 /* Private data for the biquad filter effects */
-typedef struct biquad
-{
+typedef struct {
   double gain;             /* For EQ filters */
   double fc;               /* Centre/corner/cutoff frequency */
   double width;            /* Filter width; interpreted as per width_type */
-  width_t width_type;      
+  width_t width_type;
 
   filter_t filter_type;
 
@@ -66,19 +61,15 @@
   double b2, b1, b0;       /* Filter coefficients */
   double a2, a1, a0;       /* Filter coefficients */
 
-  sox_sample_t i1, i2;      /* Filter memory */
+  sox_sample_t i1, i2;     /* Filter memory */
   double      o1, o2;      /* Filter memory */
-} * biquad_t;
+} biquad_t;
 
-
-assert_static(sizeof(struct biquad) <= SOX_MAX_EFFECT_PRIVSIZE, 
-    /* else */ biquad_PRIVSIZE_too_big);
-
 int sox_biquad_getopts(sox_effect_t * effp, int n, char **argv,
     int min_args, int max_args, int fc_pos, int width_pos, int gain_pos,
     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, 
+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);
 
 #undef sox_fail
--- a/src/biquads.c
+++ b/src/biquads.c
@@ -1,4 +1,5 @@
-/*
+/* libSoX Biquad filter effects   (c) 2006-7 robs@users.sourceforge.net
+ *
  * 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
@@ -12,10 +13,8 @@
  * 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
- */
-
-/* Biquad filter effects   (c) 2006-7 robs@users.sourceforge.net
  *
+ *
  * 2-pole filters designed by Robert Bristow-Johnson <rbj@audioimagination.com>
  *   see http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
  *
@@ -28,9 +27,9 @@
  *     A = 1 - X
  *     B = X
  *     Fc = cutoff freq / sample rate
- *   
- *     Mimics an RC low-pass filter:   
- *   
+ *
+ *     Mimics an RC low-pass filter:
+ *
  *     ---/\/\/\/\----------->
  *                   |
  *                  --- C
@@ -38,7 +37,7 @@
  *                   |
  *                   |
  *                   V
- *   
+ *
  *   high-pass: output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1]
  *     X  = exp(-2.0 * pi * Fc)
  *     A0 = (1 + X) / 2
@@ -45,9 +44,9 @@
  *     A1 = -(1 + X) / 2
  *     B1 = X
  *     Fc = cutoff freq / sample rate
- *   
+ *
  *     Mimics an RC high-pass filter:
- *   
+ *
  *         || C
  *     ----||--------->
  *         ||    |
@@ -61,9 +60,11 @@
 
 #include "biquad.h"
 #include <string.h>
-#include <math.h>
 
+typedef biquad_t priv_t;
+#define p (*(priv_t *)effp->priv)
 
+
 static int hilo1_getopts(sox_effect_t * effp, int n, char **argv) {
   return sox_biquad_getopts(effp, n, argv, 1, 1, 0, 1, 2, "",
       *effp->handler.name == 'l'? filter_LPF_1 : filter_HPF_1);
@@ -71,12 +72,11 @@
 
 
 static int hilo2_getopts(sox_effect_t * effp, int n, char **argv) {
-  biquad_t p = (biquad_t) effp->priv;
   if (n != 0 && strcmp(argv[0], "-1") == 0)
     return hilo1_getopts(effp, n - 1, argv + 1);
   if (n != 0 && strcmp(argv[0], "-2") == 0)
     ++argv, --n;
-  p->width = sqrt(0.5); /* Default to Butterworth */
+  p.width = sqrt(0.5); /* Default to Butterworth */
   return sox_biquad_getopts(effp, n, argv, 1, 2, 0, 1, 2, "qoh",
       *effp->handler.name == 'l'? filter_LPF : filter_HPF);
 }
@@ -108,9 +108,8 @@
 
 
 static int tone_getopts(sox_effect_t * effp, int n, char **argv) {
-  biquad_t p = (biquad_t) effp->priv;
-  p->width = 0.5;
-  p->fc = *effp->handler.name == 'b'? 100 : 3000;
+  p.width = 0.5;
+  p.fc = *effp->handler.name == 'b'? 100 : 3000;
   return sox_biquad_getopts(effp, n, argv, 1, 3, 1, 2, 0, "shqo",
       *effp->handler.name == 'b'?  filter_lowShelf: filter_highShelf);
 }
@@ -130,10 +129,9 @@
 
 
 static int deemph_getopts(sox_effect_t * effp, int n, char **argv) {
-  biquad_t p = (biquad_t) effp->priv;
-  p->fc    = 5283;
-  p->width = 0.4845;
-  p->gain  = -9.477;
+  p.fc    = 5283;
+  p.width = 0.4845;
+  p.gain  = -9.477;
   return sox_biquad_getopts(effp, n, argv, 0, 0, 0, 1, 2, "s", filter_deemph);
 }
 
@@ -140,9 +138,8 @@
 
 static int start(sox_effect_t * effp)
 {
-  biquad_t p = (biquad_t) effp->priv;
-  double w0 = 2 * M_PI * p->fc / effp->in_signal.rate;
-  double A  = exp(p->gain / 40 * log(10.));
+  double w0 = 2 * M_PI * p.fc / effp->in_signal.rate;
+  double A  = exp(p.gain / 40 * log(10.));
   double alpha = 0;
 
   if (w0 > M_PI) {
@@ -149,107 +146,107 @@
     sox_fail("frequency must be less than half the sample-rate (Nyquist rate)");
     return SOX_EOF;
   }
-  
+
   /* Set defaults: */
-  p->b0 = p->b1 = p->b2 = p->a1 = p->a2 = 0;
-  p->a0 = 1;
+  p.b0 = p.b1 = p.b2 = p.a1 = p.a2 = 0;
+  p.a0 = 1;
 
-  if (p->width) switch (p->width_type) {
+  if (p.width) switch (p.width_type) {
     case width_slope:
-      alpha = sin(w0)/2 * sqrt((A + 1/A)*(1/p->width - 1) + 2);
+      alpha = sin(w0)/2 * sqrt((A + 1/A)*(1/p.width - 1) + 2);
       break;
 
     case width_Q:
-      alpha = sin(w0)/(2*p->width);
+      alpha = sin(w0)/(2*p.width);
       break;
 
     case width_bw_oct:
-      alpha = sin(w0)*sinh(log(2.)/2 * p->width * w0/sin(w0));
+      alpha = sin(w0)*sinh(log(2.)/2 * p.width * w0/sin(w0));
       break;
 
     case width_bw_Hz:
-      alpha = sin(w0)/(2*p->fc/p->width);
+      alpha = sin(w0)/(2*p.fc/p.width);
       break;
 
     case width_bw_old:
-      alpha = tan(M_PI * p->width / effp->in_signal.rate);
+      alpha = tan(M_PI * p.width / effp->in_signal.rate);
       break;
   }
-  switch (p->filter_type) {
+  switch (p.filter_type) {
     case filter_LPF: /* H(s) = 1 / (s^2 + s/Q + 1) */
-      p->b0 =  (1 - cos(w0))/2;
-      p->b1 =   1 - cos(w0);
-      p->b2 =  (1 - cos(w0))/2;
-      p->a0 =   1 + alpha;
-      p->a1 =  -2*cos(w0);
-      p->a2 =   1 - alpha;
+      p.b0 =  (1 - cos(w0))/2;
+      p.b1 =   1 - cos(w0);
+      p.b2 =  (1 - cos(w0))/2;
+      p.a0 =   1 + alpha;
+      p.a1 =  -2*cos(w0);
+      p.a2 =   1 - alpha;
       break;
 
     case filter_HPF: /* H(s) = s^2 / (s^2 + s/Q + 1) */
-      p->b0 =  (1 + cos(w0))/2;
-      p->b1 = -(1 + cos(w0));
-      p->b2 =  (1 + cos(w0))/2;
-      p->a0 =   1 + alpha;
-      p->a1 =  -2*cos(w0);
-      p->a2 =   1 - alpha;
+      p.b0 =  (1 + cos(w0))/2;
+      p.b1 = -(1 + cos(w0));
+      p.b2 =  (1 + cos(w0))/2;
+      p.a0 =   1 + alpha;
+      p.a1 =  -2*cos(w0);
+      p.a2 =   1 - alpha;
       break;
 
     case filter_BPF_CSG: /* H(s) = s / (s^2 + s/Q + 1)  (constant skirt gain, peak gain = Q) */
-      p->b0 =   sin(w0)/2;
-      p->b1 =   0;
-      p->b2 =  -sin(w0)/2;
-      p->a0 =   1 + alpha;
-      p->a1 =  -2*cos(w0);
-      p->a2 =   1 - alpha;
+      p.b0 =   sin(w0)/2;
+      p.b1 =   0;
+      p.b2 =  -sin(w0)/2;
+      p.a0 =   1 + alpha;
+      p.a1 =  -2*cos(w0);
+      p.a2 =   1 - alpha;
       break;
 
     case filter_BPF: /* H(s) = (s/Q) / (s^2 + s/Q + 1)      (constant 0 dB peak gain) */
-      p->b0 =   alpha;
-      p->b1 =   0;
-      p->b2 =  -alpha;
-      p->a0 =   1 + alpha;
-      p->a1 =  -2*cos(w0);
-      p->a2 =   1 - alpha;
+      p.b0 =   alpha;
+      p.b1 =   0;
+      p.b2 =  -alpha;
+      p.a0 =   1 + alpha;
+      p.a1 =  -2*cos(w0);
+      p.a2 =   1 - alpha;
       break;
 
     case filter_notch: /* H(s) = (s^2 + 1) / (s^2 + s/Q + 1) */
-      p->b0 =   1;
-      p->b1 =  -2*cos(w0);
-      p->b2 =   1;
-      p->a0 =   1 + alpha;
-      p->a1 =  -2*cos(w0);
-      p->a2 =   1 - alpha;
+      p.b0 =   1;
+      p.b1 =  -2*cos(w0);
+      p.b2 =   1;
+      p.a0 =   1 + alpha;
+      p.a1 =  -2*cos(w0);
+      p.a2 =   1 - alpha;
       break;
 
     case filter_APF: /* H(s) = (s^2 - s/Q + 1) / (s^2 + s/Q + 1) */
-      p->b0 =   1 - alpha;
-      p->b1 =  -2*cos(w0);
-      p->b2 =   1 + alpha;
-      p->a0 =   1 + alpha;
-      p->a1 =  -2*cos(w0);
-      p->a2 =   1 - alpha;
+      p.b0 =   1 - alpha;
+      p.b1 =  -2*cos(w0);
+      p.b2 =   1 + alpha;
+      p.a0 =   1 + alpha;
+      p.a1 =  -2*cos(w0);
+      p.a2 =   1 - alpha;
       break;
 
     case filter_peakingEQ: /* H(s) = (s^2 + s*(A/Q) + 1) / (s^2 + s/(A*Q) + 1) */
       if (A == 1)
         return SOX_EFF_NULL;
-      p->b0 =   1 + alpha*A;
-      p->b1 =  -2*cos(w0);
-      p->b2 =   1 - alpha*A;
-      p->a0 =   1 + alpha/A;
-      p->a1 =  -2*cos(w0);
-      p->a2 =   1 - alpha/A;
+      p.b0 =   1 + alpha*A;
+      p.b1 =  -2*cos(w0);
+      p.b2 =   1 - alpha*A;
+      p.a0 =   1 + alpha/A;
+      p.a1 =  -2*cos(w0);
+      p.a2 =   1 - alpha/A;
       break;
 
     case filter_lowShelf: /* H(s) = A * (s^2 + (sqrt(A)/Q)*s + A)/(A*s^2 + (sqrt(A)/Q)*s + 1) */
       if (A == 1)
         return SOX_EFF_NULL;
-      p->b0 =    A*( (A+1) - (A-1)*cos(w0) + 2*sqrt(A)*alpha );
-      p->b1 =  2*A*( (A-1) - (A+1)*cos(w0)                   );
-      p->b2 =    A*( (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha );
-      p->a0 =        (A+1) + (A-1)*cos(w0) + 2*sqrt(A)*alpha;
-      p->a1 =   -2*( (A-1) + (A+1)*cos(w0)                   );
-      p->a2 =        (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha;
+      p.b0 =    A*( (A+1) - (A-1)*cos(w0) + 2*sqrt(A)*alpha );
+      p.b1 =  2*A*( (A-1) - (A+1)*cos(w0)                   );
+      p.b2 =    A*( (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha );
+      p.a0 =        (A+1) + (A-1)*cos(w0) + 2*sqrt(A)*alpha;
+      p.a1 =   -2*( (A-1) + (A+1)*cos(w0)                   );
+      p.a2 =        (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha;
       break;
 
     case filter_deemph:  /* See deemph.plt for documentation */
@@ -262,49 +259,49 @@
     case filter_highShelf: /* H(s) = A * (A*s^2 + (sqrt(A)/Q)*s + 1)/(s^2 + (sqrt(A)/Q)*s + A) */
       if (!A)
         return SOX_EFF_NULL;
-      p->b0 =    A*( (A+1) + (A-1)*cos(w0) + 2*sqrt(A)*alpha );
-      p->b1 = -2*A*( (A-1) + (A+1)*cos(w0)                   );
-      p->b2 =    A*( (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha );
-      p->a0 =        (A+1) - (A-1)*cos(w0) + 2*sqrt(A)*alpha;
-      p->a1 =    2*( (A-1) - (A+1)*cos(w0)                   );
-      p->a2 =        (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha;
+      p.b0 =    A*( (A+1) + (A-1)*cos(w0) + 2*sqrt(A)*alpha );
+      p.b1 = -2*A*( (A-1) + (A+1)*cos(w0)                   );
+      p.b2 =    A*( (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha );
+      p.a0 =        (A+1) - (A-1)*cos(w0) + 2*sqrt(A)*alpha;
+      p.a1 =    2*( (A-1) - (A+1)*cos(w0)                   );
+      p.a2 =        (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha;
       break;
 
     case filter_LPF_1: /* single-pole */
-      p->a1 = -exp(-w0);
-      p->b0 = 1 + p->a1;
+      p.a1 = -exp(-w0);
+      p.b0 = 1 + p.a1;
       break;
 
     case filter_HPF_1: /* single-pole */
-      p->a1 = -exp(-w0);
-      p->b0 = (1 - p->a1)/2;
-      p->b1 = -p->b0;
+      p.a1 = -exp(-w0);
+      p.b0 = (1 - p.a1)/2;
+      p.b1 = -p.b0;
       break;
 
     case filter_BPF_SPK: case filter_BPF_SPK_N: {
       double bw_Hz;
-      if (!p->width)
-        p->width = p->fc / 2;
-      bw_Hz = p->width_type == width_Q?  p->fc / p->width :
-        p->width_type == width_bw_Hz? p->width :
-        p->fc * (pow(2., p->width) - 1) * pow(2., -0.5 * p->width); /* bw_oct */
+      if (!p.width)
+        p.width = p.fc / 2;
+      bw_Hz = p.width_type == width_Q?  p.fc / p.width :
+        p.width_type == width_bw_Hz? p.width :
+        p.fc * (pow(2., p.width) - 1) * pow(2., -0.5 * p.width); /* bw_oct */
       #include "band.h" /* Has different licence */
       break;
     }
 
     case filter_AP1:     /* Experimental 1-pole all-pass from Tom Erbe @ UCSD */
-      p->b0 = exp(-w0);
-      p->b1 = -1;
-      p->a1 = -exp(-w0);
+      p.b0 = exp(-w0);
+      p.b1 = -1;
+      p.a1 = -exp(-w0);
       break;
 
     case filter_AP2:     /* Experimental 2-pole all-pass from Tom Erbe @ UCSD */
-      p->b0 = 1 - sin(w0);
-      p->b1 = -2 * cos(w0);
-      p->b2 = 1 + sin(w0);
-      p->a0 = 1 + sin(w0);
-      p->a1 = -2 * cos(w0);
-      p->a2 = 1 - sin(w0);
+      p.b0 = 1 - sin(w0);
+      p.b1 = -2 * cos(w0);
+      p.b2 = 1 + sin(w0);
+      p.a0 = 1 + sin(w0);
+      p.a1 = -2 * cos(w0);
+      p.a2 = 1 - sin(w0);
       break;
   }
   return sox_biquad_start(effp);
@@ -315,7 +312,7 @@
 sox_effect_handler_t const * sox_##name##_effect_fn(void) { \
   static sox_effect_handler_t handler = { \
     #name, usage, flags, \
-    group##_getopts, start, sox_biquad_flow, 0, 0, 0, \
+    group##_getopts, start, sox_biquad_flow, 0, 0, 0, sizeof(biquad_t)\
   }; \
   return &handler; \
 }
--- a/src/cdr.c
+++ b/src/cdr.c
@@ -1,5 +1,4 @@
-/*
- * File format: cdda   (c) 2006-8 SoX contributors
+/* libSoX file format: cdda   (c) 2006-8 SoX contributors
  * Based on an original idea by David Elliott
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -19,12 +18,12 @@
 
 #include "sox_i.h"
 
-static int start(sox_format_t * ft) 
+static int start(sox_format_t * ft)
 {
   return lsx_check_read_params(ft, 2, 44100., SOX_ENCODING_SIGN2, 16, (off_t)0);
 }
 
-static int stopwrite(sox_format_t * ft) 
+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;
@@ -39,13 +38,12 @@
   static char const * const names[] = {"cdda", "cdr", NULL};
   static unsigned const write_encodings[] = {SOX_ENCODING_SIGN2, 16, 0, 0};
   static sox_rate_t const write_rates[] = {44100, 0};
-  static sox_format_handler_t handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
     "Red Book Compact Disc Digital Audio",
     names, SOX_FILE_BIG_END|SOX_FILE_STEREO,
     start, lsx_rawread, NULL,
     NULL, lsx_rawwrite, stopwrite,
-    lsx_rawseek, write_encodings, write_rates
+    lsx_rawseek, write_encodings, write_rates, 0
   };
   return &handler;
 }
--- a/src/chorus.c
+++ b/src/chorus.c
@@ -1,15 +1,14 @@
-/*
- * August 24, 1998
+/* August 24, 1998
  * Copyright (C) 1998 Juergen Mueller And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Juergen Mueller And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Juergen Mueller And Sundry Contributors are not responsible for
  * the consequences of using this software.
  */
 
 /*
  *      Chorus effect.
- * 
+ *
  * Flow diagram scheme for n delays ( 1 <= n <= MAX_CHORUS ):
  *
  *        * gain-in                                           ___
@@ -28,7 +27,7 @@
  *            +---->| delay n |----------------------------->|   |
  *                  |_________|                              |   |
  *                     /|\                                   |___|
- *                      |                                      |  
+ *                      |                                      |
  *              +-----------------+   +--------------+         | * gain-out
  *              | Delay control n |<--| mod. speed n |         |
  *              +-----------------+   +--------------+         +----->obuff
@@ -36,7 +35,7 @@
  *
  * The delay i is controled by a sine or triangle modulation i ( 1 <= i <= n).
  *
- * Usage: 
+ * Usage:
  *   chorus gain-in gain-out delay-1 decay-1 speed-1 depth-1 -s1|t1 [
  *       delay-2 decay-2 speed-2 depth-2 -s2|-t2 ... ]
  *
@@ -51,7 +50,7 @@
  *
  * Note:
  *   when decay is close to 1.0, the samples can begin clipping and the output
- *   can saturate! 
+ *   can saturate!
  *
  * Hint:
  *   1 / out-gain < gain-in ( 1 + decay-1 + ... + decay-n )
@@ -65,7 +64,6 @@
 #include "sox_i.h"
 
 #include <stdlib.h> /* Harmless, and prototypes atof() etc. --dgc */
-#include <math.h>
 #include <string.h>
 
 #define MOD_SINE        0
@@ -72,10 +70,10 @@
 #define MOD_TRIANGLE    1
 #define MAX_CHORUS      7
 
-typedef struct chorusstuff {
+typedef struct {
         int     num_chorus;
         int     modulation[MAX_CHORUS];
-        int     counter;                        
+        int     counter;
         long    phase[MAX_CHORUS];
         float   *chorusbuf;
         float   in_gain, out_gain;
@@ -86,14 +84,14 @@
         int     depth_samples[MAX_CHORUS], samples[MAX_CHORUS];
         int maxsamples;
         unsigned int fade_out;
-} *chorus_t;
+} priv_t;
 
 /*
  * Process options
  */
-static int sox_chorus_getopts(sox_effect_t * effp, int n, char **argv) 
+static int sox_chorus_getopts(sox_effect_t * effp, int n, char **argv)
 {
-        chorus_t chorus = (chorus_t) effp->priv;
+        priv_t * chorus = (priv_t *) effp->priv;
         int i;
 
         chorus->num_chorus = 0;
@@ -131,7 +129,7 @@
  */
 static int sox_chorus_start(sox_effect_t * effp)
 {
-        chorus_t chorus = (chorus_t) effp->priv;
+        priv_t * chorus = (priv_t *) effp->priv;
         int i;
         float sum_in_volume;
 
@@ -153,9 +151,9 @@
                 return (SOX_EOF);
         }
         for ( i = 0; i < chorus->num_chorus; i++ ) {
-                chorus->samples[i] = (int) ( ( chorus->delay[i] + 
+                chorus->samples[i] = (int) ( ( chorus->delay[i] +
                         chorus->depth[i] ) * effp->in_signal.rate / 1000.0);
-                chorus->depth_samples[i] = (int) (chorus->depth[i] * 
+                chorus->depth_samples[i] = (int) (chorus->depth[i] *
                         effp->in_signal.rate / 1000.0);
 
                 if ( chorus->delay[i] < 20.0 )
@@ -205,12 +203,12 @@
                   lsx_generate_wave_table(SOX_WAVE_SINE, SOX_INT, chorus->lookup_tab[i],
                                          (unsigned)chorus->length[i], 0., (double)chorus->depth_samples[i], 0.);
                 else
-                  lsx_generate_wave_table(SOX_WAVE_TRIANGLE, SOX_INT, chorus->lookup_tab[i], 
+                  lsx_generate_wave_table(SOX_WAVE_TRIANGLE, SOX_INT, chorus->lookup_tab[i],
                                          (unsigned)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;
-                
+
                 if ( chorus->samples[i] > chorus->maxsamples )
                   chorus->maxsamples = chorus->samples[i];
         }
@@ -236,10 +234,10 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int sox_chorus_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
-        chorus_t chorus = (chorus_t) effp->priv;
+        priv_t * chorus = (priv_t *) effp->priv;
         int i;
         float d_in, d_out;
         sox_sample_t out;
@@ -252,8 +250,8 @@
                 /* Compute output first */
                 d_out = d_in * chorus->in_gain;
                 for ( i = 0; i < chorus->num_chorus; i++ )
-                        d_out += chorus->chorusbuf[(chorus->maxsamples + 
-                        chorus->counter - chorus->lookup_tab[i][chorus->phase[i]]) % 
+                        d_out += chorus->chorusbuf[(chorus->maxsamples +
+                        chorus->counter - chorus->lookup_tab[i][chorus->phase[i]]) %
                         chorus->maxsamples] * chorus->decay[i];
                 /* Adjust the output volume and size to 24 bit */
                 d_out = d_out * chorus->out_gain;
@@ -261,10 +259,10 @@
                 *obuf++ = out * 256;
                 /* Mix decay of delay and input */
                 chorus->chorusbuf[chorus->counter] = d_in;
-                chorus->counter = 
+                chorus->counter =
                         ( chorus->counter + 1 ) % chorus->maxsamples;
                 for ( i = 0; i < chorus->num_chorus; i++ )
-                        chorus->phase[i]  = 
+                        chorus->phase[i]  =
                                 ( chorus->phase[i] + 1 ) % chorus->length[i];
         }
         /* processed all samples */
@@ -272,14 +270,14 @@
 }
 
 /*
- * Drain out reverb lines. 
+ * Drain out reverb lines.
  */
 static int sox_chorus_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-        chorus_t chorus = (chorus_t) effp->priv;
+        priv_t * chorus = (priv_t *) effp->priv;
         sox_size_t done;
         int i;
-        
+
         float d_in, d_out;
         sox_sample_t out;
 
@@ -289,8 +287,8 @@
                 d_out = 0;
                 /* Compute output first */
                 for ( i = 0; i < chorus->num_chorus; i++ )
-                        d_out += chorus->chorusbuf[(chorus->maxsamples + 
-                chorus->counter - chorus->lookup_tab[i][chorus->phase[i]]) % 
+                        d_out += chorus->chorusbuf[(chorus->maxsamples +
+                chorus->counter - chorus->lookup_tab[i][chorus->phase[i]]) %
                 chorus->maxsamples] * chorus->decay[i];
                 /* Adjust the output volume and size to 24 bit */
                 d_out = d_out * chorus->out_gain;
@@ -298,10 +296,10 @@
                 *obuf++ = out * 256;
                 /* Mix decay of delay and input */
                 chorus->chorusbuf[chorus->counter] = d_in;
-                chorus->counter = 
+                chorus->counter =
                         ( chorus->counter + 1 ) % chorus->maxsamples;
                 for ( i = 0; i < chorus->num_chorus; i++ )
-                        chorus->phase[i]  = 
+                        chorus->phase[i]  =
                                 ( chorus->phase[i] + 1 ) % chorus->length[i];
                 done++;
                 chorus->fade_out--;
@@ -319,7 +317,7 @@
  */
 static int sox_chorus_stop(sox_effect_t * effp)
 {
-        chorus_t chorus = (chorus_t) effp->priv;
+        priv_t * chorus = (priv_t *) effp->priv;
         int i;
 
         free((char *) chorus->chorusbuf);
@@ -340,7 +338,7 @@
   sox_chorus_flow,
   sox_chorus_drain,
   sox_chorus_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_chorus_effect_fn(void)
--- a/src/compand.c
+++ b/src/compand.c
@@ -1,5 +1,4 @@
-/*
- * Compander effect
+/* libSoX compander effect
  *
  * Written by Nick Bailey (nick@bailey-family.org.uk or
  *                         n.bailey@elec.gla.ac.uk)
@@ -59,11 +58,11 @@
   sox_ssize_t delay_buf_index; /* Index into delay_buf */
   sox_ssize_t delay_buf_cnt; /* No. of active entries in delay_buf */
   int delay_buf_full;       /* Shows buffer situation (important for drain) */
-} * compand_t;
+} priv_t;
 
 static int getopts(sox_effect_t * effp, int n, char * * argv)
 {
-  compand_t l = (compand_t) effp->priv;
+  priv_t * l = (priv_t *) effp->priv;
   char * s;
   char dummy;     /* To check for extraneous chars. */
   unsigned pairs, i, j, commas;
@@ -128,7 +127,7 @@
 
 static int start(sox_effect_t * effp)
 {
-  compand_t l = (compand_t) effp->priv;
+  priv_t * l = (priv_t *) effp->priv;
   unsigned i, j;
 
   sox_debug("%i input channel(s) expected: actually %i",
@@ -163,7 +162,7 @@
  * Update a volume value using the given sample
  * value, the attack rate and decay rate
  */
-static void doVolume(double *v, double samp, compand_t l, int chan)
+static void doVolume(double *v, double samp, priv_t * l, int chan)
 {
   double s = -samp / SOX_SAMPLE_MIN;
   double delta = s - *v;
@@ -177,7 +176,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)
 {
-  compand_t l = (compand_t) effp->priv;
+  priv_t * l = (priv_t *) effp->priv;
   int len =  (*isamp > *osamp) ? *osamp : *isamp;
   int filechans = effp->out_signal.channels;
   int idone,odone;
@@ -237,7 +236,7 @@
 
 static int drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-  compand_t l = (compand_t) effp->priv;
+  priv_t * l = (priv_t *) effp->priv;
   sox_size_t chan, done = 0;
 
   if (l->delay_buf_full == 0)
@@ -257,7 +256,7 @@
 
 static int stop(sox_effect_t * effp)
 {
-  compand_t l = (compand_t) effp->priv;
+  priv_t * l = (priv_t *) effp->priv;
 
   free(l->delay_buf);
   return SOX_SUCCESS;
@@ -265,7 +264,7 @@
 
 static int kill(sox_effect_t * effp)
 {
-  compand_t l = (compand_t) effp->priv;
+  priv_t * l = (priv_t *) effp->priv;
 
   sox_compandt_kill(&l->transfer_fn);
   free(l->channels);
@@ -276,7 +275,7 @@
 {
   static sox_effect_handler_t handler = {
     "compand", compand_usage, SOX_EFF_MCHAN,
-    getopts, start, flow, drain, stop, kill
+    getopts, start, flow, drain, stop, kill, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/compandt.c
+++ b/src/compandt.c
@@ -1,4 +1,5 @@
-/*
+/* libSoX Compander Transfer Function: (c) 2007 robs@users.sourceforge.net
+ *
  * 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
@@ -12,8 +13,6 @@
  * 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
- *
- * Compander Transfer Function: (c) 2007 robs@users.sourceforge.net
  */
 
 #include "sox_i.h"
--- a/src/compandt.h
+++ b/src/compandt.h
@@ -1,4 +1,5 @@
-/*
+/* libSoX Compander Transfer Function  (c) 2007 robs@users.sourceforge.net
+ *
  * 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
@@ -12,8 +13,6 @@
  * 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
- *
- * Compander Transfer Function: (c) 2007 robs@users.sourceforge.net
  */
 
 #include <math.h>
--- a/src/contrast.c
+++ b/src/contrast.c
@@ -1,5 +1,4 @@
-/*
- * Effect: Contrast Enhancement        (c) 2008 robs@users.sourceforge.net
+/* libSoX effect: Contrast Enhancement    (c) 2008 robs@users.sourceforge.net
  *
  * 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
@@ -17,27 +16,22 @@
  */
 
 #include "sox_i.h"
-#include <math.h>
 
 typedef struct {double contrast;} priv_t;
-assert_static(sizeof(priv_t) <= SOX_MAX_EFFECT_PRIVSIZE, PRIVSIZE_too_big);
+#define p ((priv_t *)effp->priv)
 
 static int create(sox_effect_t * effp, int argc, char * * argv)
 {
-  priv_t * p = (priv_t *)effp->priv;
-
   p->contrast = 75;
   do {NUMERIC_PARAMETER(contrast, 0, 100)} while (0);
-  p->contrast /= 750;
-  return argc?  lsx_usage(effp) : SOX_SUCCESS;
+  p->contrast /= 750; /* shift range to 0 to 0.1333, default 0.1 */
+  return argc? lsx_usage(effp) : SOX_SUCCESS;
 }
 
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
     sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
 {
-  priv_t * p = (priv_t *)effp->priv;
   sox_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;
@@ -47,8 +41,7 @@
 
 sox_effect_handler_t const * sox_contrast_effect_fn(void)
 {
-  static sox_effect_handler_t handler = {
-    "contrast", "[enhancement]", SOX_EFF_MCHAN, create, 0, flow, 0, 0, 0
-  };
+  static sox_effect_handler_t handler = {"contrast", "[enhancement (75)]",
+    SOX_EFF_MCHAN, create, NULL, flow, NULL, NULL, NULL, sizeof(priv_t)};
   return &handler;
 }
--- a/src/cvsd-fmt.c
+++ b/src/cvsd-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File format: CVSD (see cvsd.c)        (c) 2007-8 SoX contributors
+/* libSoX file format: CVSD (see cvsd.c)        (c) 2007-8 SoX contributors
  *
  * 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
@@ -22,13 +21,12 @@
 {
   static char const * const names[] = {"cvsd", "cvs", NULL};
   static unsigned const write_encodings[] = {SOX_ENCODING_CVSD, 1, 0, 0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
     "Headerless Continuously Variable Slope Delta modulation",
     names, SOX_FILE_MONO,
     sox_cvsdstartread, sox_cvsdread, sox_cvsdstopread,
     sox_cvsdstartwrite, sox_cvsdwrite, sox_cvsdstopwrite,
-    lsx_rawseek, write_encodings, NULL
+    lsx_rawseek, write_encodings, NULL, sizeof(cvsd_priv_t)
   };
   return &handler;
 }
--- a/src/cvsd.c
+++ b/src/cvsd.c
@@ -1,11 +1,10 @@
-/*
- *      CVSD (Continuously Variable Slope Delta modulation)
+/*      libSoX CVSD (Continuously Variable Slope Delta modulation)
  *      conversion routines
  *
  *      The CVSD format is described in the MIL Std 188 113, which is
  *      available from http://bbs.itsi.disa.mil:5580/T3564
  *
- *      Copyright (C) 1996  
+ *      Copyright (C) 1996
  *      Thomas Sailer (sailer@ife.ee.ethz.ch) (HB9JNX/AE4WA)
  *      Swiss Federal Institute of Technology, Electronics Lab
  *
@@ -28,65 +27,22 @@
  * June 1, 1998 - Chris Bagwell (cbagwell@sprynet.com)
  *   Fixed compile warnings reported by Kjetil Torgrim Homme
  *   <kjetilho@ifi.uio.no>
- *
- *
  */
 
-/* ---------------------------------------------------------------------- */
-
 #include "sox_i.h"
 #include "cvsd.h"
+#include "cvsdfilt.h"
 
-#include <math.h>
 #include <string.h>
 #include <time.h>
-#include <stdio.h>
-#include <errno.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>     /* For SEEK_* defines if not found in stdio */
-#endif
 
-#include "cvsdfilt.h"
-
 /* ---------------------------------------------------------------------- */
 /*
  * private data structures
  */
 
-struct cvsd_common_state {
-        unsigned overload;
-        float mla_int;
-        float mla_tc0;
-        float mla_tc1;
-        unsigned phase;
-        unsigned phase_inc;
-        float v_min, v_max;
-};
+typedef cvsd_priv_t priv_t;
 
-struct cvsd_decode_state {
-        float output_filter[DEC_FILTERLEN];
-};
-
-struct cvsd_encode_state {
-        float recon_int;
-        float input_filter[ENC_FILTERLEN];
-};
-
-struct cvsdpriv {
-        struct cvsd_common_state com;
-        union {
-                struct cvsd_decode_state dec;
-                struct cvsd_encode_state enc;
-        } c;
-        struct {
-                unsigned char shreg;
-                unsigned mask;
-                unsigned cnt;
-        } bit;
-        unsigned bytes_written;
-        unsigned cvsd_rate;
-};
-
 static int debug_count = 0;
 
 /* ---------------------------------------------------------------------- */
@@ -113,8 +69,8 @@
 
 static void cvsdstartcommon(sox_format_t * ft)
 {
-        struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
-        
+        priv_t *p = (priv_t *) ft->priv;
+
         p->cvsd_rate = (ft->signal.rate <= 24000) ? 16000 : 32000;
         ft->signal.rate = 8000;
         ft->signal.channels = 1;
@@ -150,9 +106,9 @@
 
 /* ---------------------------------------------------------------------- */
 
-int sox_cvsdstartread(sox_format_t * ft) 
+int sox_cvsdstartread(sox_format_t * ft)
 {
-        struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
         float *fp1;
         int i;
 
@@ -166,9 +122,9 @@
          * this is now done in the filter parameter generation utility
          */
         /*
-         * zero the filter 
+         * zero the filter
          */
-        for(fp1 = p->c.dec.output_filter, i = DEC_FILTERLEN; i > 0; i--)
+        for(fp1 = p->c.dec.output_filter, i = CVSD_DEC_FILTERLEN; i > 0; i--)
                 *fp1++ = 0;
 
         return (SOX_SUCCESS);
@@ -176,9 +132,9 @@
 
 /* ---------------------------------------------------------------------- */
 
-int sox_cvsdstartwrite(sox_format_t * ft) 
+int sox_cvsdstartwrite(sox_format_t * ft)
 {
-        struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
         float *fp1;
         int i;
 
@@ -187,9 +143,9 @@
         p->com.mla_tc1 = 0.1 * (1 - p->com.mla_tc0);
         p->com.phase = 4;
         /*
-         * zero the filter 
+         * zero the filter
          */
-        for(fp1 = p->c.enc.input_filter, i = ENC_FILTERLEN; i > 0; i--)
+        for(fp1 = p->c.enc.input_filter, i = CVSD_ENC_FILTERLEN; i > 0; i--)
                 *fp1++ = 0;
         p->c.enc.recon_int = 0;
 
@@ -200,14 +156,14 @@
 
 int sox_cvsdstopwrite(sox_format_t * ft)
 {
-        struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
 
         if (p->bit.cnt) {
                 lsx_writeb(ft, p->bit.shreg);
                 p->bytes_written++;
         }
-        sox_debug("cvsd: min slope %f, max slope %f", 
-               p->com.v_min, p->com.v_max);     
+        sox_debug("cvsd: min slope %f, max slope %f",
+               p->com.v_min, p->com.v_max);
 
         return (SOX_SUCCESS);
 }
@@ -216,9 +172,9 @@
 
 int sox_cvsdstopread(sox_format_t * ft)
 {
-        struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
 
-        sox_debug("cvsd: min value %f, max value %f", 
+        sox_debug("cvsd: min value %f, max value %f",
                p->com.v_min, p->com.v_max);
 
         return(SOX_SUCCESS);
@@ -226,12 +182,12 @@
 
 /* ---------------------------------------------------------------------- */
 
-sox_size_t sox_cvsdread(sox_format_t * ft, sox_sample_t *buf, sox_size_t nsamp) 
+sox_size_t sox_cvsdread(sox_format_t * ft, sox_sample_t *buf, sox_size_t nsamp)
 {
-        struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
         sox_size_t done = 0;
         float oval;
-        
+
         while (done < nsamp) {
                 if (!p->bit.cnt) {
                         if (lsx_read_b_buf(ft, &(p->bit.shreg), 1) != 1)
@@ -243,7 +199,7 @@
                  * handle one bit
                  */
                 p->bit.cnt--;
-                p->com.overload = ((p->com.overload << 1) | 
+                p->com.overload = ((p->com.overload << 1) |
                                    (!!(p->bit.shreg & p->bit.mask))) & 7;
                 p->bit.mask <<= 1;
                 p->com.mla_int *= p->com.mla_tc0;
@@ -260,10 +216,10 @@
                  */
                 p->com.phase += p->com.phase_inc;
                 if (p->com.phase >= 4) {
-                        oval = float_conv(p->c.dec.output_filter, 
-                                          (p->cvsd_rate < 24000) ? 
-                                          dec_filter_16 : dec_filter_32, 
-                                          DEC_FILTERLEN);
+                        oval = float_conv(p->c.dec.output_filter,
+                                          (p->cvsd_rate < 24000) ?
+                                          dec_filter_16 : dec_filter_32,
+                                          CVSD_DEC_FILTERLEN);
                         sox_debug_more("input %d %f\n", debug_count, p->com.mla_int);
                         sox_debug_more("recon %d %f\n", debug_count, oval);
                         debug_count++;
@@ -282,9 +238,9 @@
 
 /* ---------------------------------------------------------------------- */
 
-sox_size_t sox_cvsdwrite(sox_format_t * ft, const 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)
 {
-        struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
         sox_size_t done = 0;
         float inval;
 
@@ -297,17 +253,17 @@
                                 return done;
                         memmove(p->c.enc.input_filter+1, p->c.enc.input_filter,
                                 sizeof(p->c.enc.input_filter)-sizeof(float));
-                        p->c.enc.input_filter[0] = (*buf++) / 
+                        p->c.enc.input_filter[0] = (*buf++) /
                                 ((float)SOX_SAMPLE_MAX);
                         done++;
                 }
                 p->com.phase &= 3;
                 /* insert input filter here! */
-                inval = float_conv(p->c.enc.input_filter, 
-                                   (p->cvsd_rate < 24000) ? 
-                                   (enc_filter_16[(p->com.phase >= 2)]) : 
-                                   (enc_filter_32[p->com.phase]), 
-                                   ENC_FILTERLEN);
+                inval = float_conv(p->c.enc.input_filter,
+                                   (p->cvsd_rate < 24000) ?
+                                   (enc_filter_16[(p->com.phase >= 2)]) :
+                                   (enc_filter_32[p->com.phase]),
+                                   CVSD_ENC_FILTERLEN);
                 /*
                  * encode one bit
                  */
@@ -348,7 +304,7 @@
 
 static uint32_t get32_le(unsigned char **p)
 {
-  uint32_t val = (((*p)[3]) << 24) | (((*p)[2]) << 16) | 
+  uint32_t val = (((*p)[3]) << 24) | (((*p)[2]) << 16) |
           (((*p)[1]) << 8) | (**p);
   (*p) += 4;
   return val;
@@ -427,7 +383,7 @@
         memcpy(hdr->extend, pch, sizeof(hdr->extend));
         pch += sizeof(hdr->extend);
         hdr->Crc = get16_le(&pch);
-        if (sum != hdr->Crc) 
+        if (sum != hdr->Crc)
         {
                 sox_report("DVMS header checksum error, read %u, calculated %u",
                      hdr->Crc, sum);
@@ -486,9 +442,9 @@
 
 static void make_dvms_hdr(sox_format_t * ft, struct dvms_header *hdr)
 {
-        struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
         size_t len;
-        char * comment = sox_cat_comments(ft->comments);
+        char * comment = sox_cat_comments(ft->oob.comments);
 
         memset(hdr->Filename, 0, sizeof(hdr->Filename));
         len = strlen(ft->filename);
@@ -512,7 +468,7 @@
 
 /* ---------------------------------------------------------------------- */
 
-int sox_dvmsstartread(sox_format_t * ft) 
+int sox_dvmsstartread(sox_format_t * ft)
 {
         struct dvms_header hdr;
         int rc;
@@ -537,8 +493,8 @@
         sox_debug("  custom2   %u", hdr.Custom2);
         sox_debug("  info      \"%.16s\"", hdr.Info);
         ft->signal.rate = (hdr.Srate < 240) ? 16000 : 32000;
-        sox_debug("DVMS rate %dbit/s using %gbit/s deviation %g%%", 
-               hdr.Srate*100, ft->signal.rate, 
+        sox_debug("DVMS rate %dbit/s using %gbit/s deviation %g%%",
+               hdr.Srate*100, ft->signal.rate,
                ((ft->signal.rate - hdr.Srate*100) * 100) / ft->signal.rate);
         rc = sox_cvsdstartread(ft);
         if (rc)
@@ -549,11 +505,11 @@
 
 /* ---------------------------------------------------------------------- */
 
-int sox_dvmsstartwrite(sox_format_t * ft) 
+int sox_dvmsstartwrite(sox_format_t * ft)
 {
         struct dvms_header hdr;
         int rc;
-        
+
         rc = sox_cvsdstartwrite(ft);
         if (rc)
             return rc;
@@ -577,7 +533,7 @@
 {
         struct dvms_header hdr;
         int rc;
-        
+
         sox_cvsdstopwrite(ft);
         if (!ft->seekable)
         {
@@ -594,6 +550,6 @@
         if(rc){
             lsx_fail_errno(ft,rc,"cannot write DVMS header");
             return rc;
-        }       
+        }
         return rc;
 }
--- a/src/cvsd.h
+++ b/src/cvsd.h
@@ -1,5 +1,4 @@
-/*
- *      DVMS format module (implementation in cvsd.c)
+/*      libSoX DVMS format module (implementation in cvsd.c)
  *
  *      Copyright (C) 1996-2007 Thomas Sailer and SoX Contributors
  *      Thomas Sailer (sailer@ife.ee.ethz.ch) (HB9JNX/AE4WA)
@@ -21,6 +20,37 @@
  *
  */
 #include "sox_i.h"
+
+#define CVSD_ENC_FILTERLEN 16  /* PCM sampling rate */
+#define CVSD_DEC_FILTERLEN 48  /* CVSD sampling rate */
+
+typedef struct {
+  struct {
+    unsigned overload;
+    float mla_int;
+    float mla_tc0;
+    float mla_tc1;
+    unsigned phase;
+    unsigned phase_inc;
+    float v_min, v_max;
+  } com;
+  union {
+    struct {
+      float output_filter[CVSD_DEC_FILTERLEN];
+    } dec;
+    struct {
+      float recon_int;
+      float input_filter[CVSD_ENC_FILTERLEN];
+    } enc;
+  } c;
+  struct {
+    unsigned char shreg;
+    unsigned mask;
+    unsigned cnt;
+  } bit;
+  unsigned bytes_written;
+  unsigned cvsd_rate;
+} cvsd_priv_t;
 
 int sox_cvsdstartread(sox_format_t * ft);
 int sox_cvsdstartwrite(sox_format_t * ft);
--- a/src/cvsdfilt.h
+++ b/src/cvsdfilt.h
@@ -1,11 +1,10 @@
-/*
- *      CVSD (Continuously Variable Slope Delta modulation)
+/*      libSoX CVSD (Continuously Variable Slope Delta modulation)
  *      conversion routines
  *
  *      The CVSD format is described in the MIL Std 188 113, which is
  *      available from http://bbs.itsi.disa.mil:5580/T3564
  *
- *	Copyright (C) 1996  
+ *	Copyright (C) 1996
  *      Thomas Sailer (sailer@ife.ee.ethz.ch) (HB9JNX/AE4WA)
  *      Swiss Federal Institute of Technology, Electronics Lab
  *
@@ -22,15 +21,7 @@
  * 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
- *
  */
-
-/* ---------------------------------------------------------------------- */
-
-#define ENC_FILTERLEN 16  /* PCM sampling rate */
-#define DEC_FILTERLEN 48  /* CVSD sampling rate */
-
-/* ---------------------------------------------------------------------- */
 
 static float dec_filter_16[48] = {
 	       0.001102,       0.001159,       0.000187,      -0.000175,
--- a/src/dat.c
+++ b/src/dat.c
@@ -1,12 +1,11 @@
-/*
- * libSoX text format file.  Tom Littlejohn, March 93.
+/* libSoX text format file.  Tom Littlejohn, March 93.
  *
  * Reads/writes sound files as text.
  *
  * Copyright 1998-2006 Chris Bagwell and SoX Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Lance Norskog And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Lance Norskog And Sundry Contributors are not responsible for
  * the consequences of using this software.
  */
 
@@ -16,11 +15,11 @@
 #define LINEWIDTH 256
 
 /* Private data for dat file */
-typedef struct dat {
+typedef struct {
     double timevalue, deltat;
     int buffered;
-    char prevline[LINEWIDTH]; 
-} *dat_t;
+    char prevline[LINEWIDTH];
+} priv_t;
 
 static int sox_datstartread(sox_format_t * ft)
 {
@@ -42,10 +41,10 @@
     }
     /* Hold a copy of the last line we read (first non-comment) */
     if (status != SOX_EOF) {
-      strncpy(((dat_t)ft->priv)->prevline, inpstr, LINEWIDTH);
-      ((dat_t)ft->priv)->buffered = 1;
+      strncpy(((priv_t *)ft->priv)->prevline, inpstr, LINEWIDTH);
+      ((priv_t *)ft->priv)->buffered = 1;
     } else {
-      ((dat_t)ft->priv)->buffered = 0;
+      ((priv_t *)ft->priv)->buffered = 0;
     }
 
     /* Default channels to 1 if not found */
@@ -59,7 +58,7 @@
 
 static int sox_datstartwrite(sox_format_t * ft)
 {
-    dat_t dat = (dat_t) ft->priv;
+    priv_t * dat = (priv_t *) ft->priv;
     char s[LINEWIDTH];
 
     dat->timevalue = 0.0;
@@ -90,9 +89,9 @@
     while (done < nsamp) {
 
       /* Read a line or grab the buffered first line */
-      if (((dat_t)ft->priv)->buffered) {
-        strncpy(inpstr, ((dat_t)ft->priv)->prevline, LINEWIDTH);
-        ((dat_t)ft->priv)->buffered=0;
+      if (((priv_t *)ft->priv)->buffered) {
+        strncpy(inpstr, ((priv_t *)ft->priv)->prevline, LINEWIDTH);
+        ((priv_t *)ft->priv)->buffered=0;
       } else {
         lsx_reads(ft, inpstr, LINEWIDTH-1);
         inpstr[LINEWIDTH-1] = 0;
@@ -122,7 +121,7 @@
 
 static sox_size_t sox_datwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp)
 {
-    dat_t dat = (dat_t) ft->priv;
+    priv_t * dat = (priv_t *) ft->priv;
     sox_size_t done = 0;
     double sampval=0.0;
     char s[LINEWIDTH];
@@ -152,13 +151,11 @@
 {
   static char const * const names[] = {"dat", NULL};
   static unsigned const write_encodings[] = {SOX_ENCODING_FLOAT_TEXT, 0, 0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
-    "Textual representation of the sampled audio",
-    names, 0,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
+    "Textual representation of the sampled audio", names, 0,
     sox_datstartread, sox_datread, NULL,
     sox_datstartwrite, sox_datwrite, NULL,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/dcshift.c
+++ b/src/dcshift.c
@@ -1,5 +1,4 @@
-/*
- * dcshift.c
+/* libSoX dcshift.c
  * (c) 2000.04.15 Chris Ausbrooks <weed@bucket.pp.ualr.edu>
  *
  * based on vol.c which is
@@ -13,8 +12,6 @@
 
 #include "sox_i.h"
 
-#include <math.h>   /* exp(), sqrt() */
-
 typedef struct {
     double dcshift; /* DC shift. */
     int uselimiter; /* boolean: are we using the limiter? */
@@ -23,7 +20,7 @@
     int limited; /* number of limited values to report. */
     int totalprocessed;
     int clipped;    /* number of clipped values to report. */
-} * dcs_t;
+} priv_t;
 
 /*
  * Process options: dcshift (double) type (amplitude, power, dB)
@@ -30,7 +27,7 @@
  */
 static int sox_dcshift_getopts(sox_effect_t * effp, int n, char **argv)
 {
-    dcs_t dcs = (dcs_t) effp->priv;
+    priv_t * dcs = (priv_t *) effp->priv;
     dcs->dcshift = 1.0; /* default is no change */
     dcs->uselimiter = 0; /* default is no limiter */
 
@@ -46,11 +43,11 @@
           return lsx_usage(effp);
 
         dcs->uselimiter = 1; /* ok, we'll use it */
-        /* The following equation is derived so that there is no 
+        /* The following equation is derived so that there is no
          * discontinuity in output amplitudes */
-        /* and a SOX_SAMPLE_MAX input always maps to a SOX_SAMPLE_MAX output 
+        /* and a SOX_SAMPLE_MAX input always maps to a SOX_SAMPLE_MAX output
          * when the limiter is activated. */
-        /* (NOTE: There **WILL** be a discontinuity in the slope of the 
+        /* (NOTE: There **WILL** be a discontinuity in the slope of the
          * output amplitudes when using the limiter.) */
         dcs->limiterthreshhold = SOX_SAMPLE_MAX * (1.0 - (fabs(dcs->dcshift) - dcs->limitergain));
     }
@@ -63,7 +60,7 @@
  */
 static int sox_dcshift_start(sox_effect_t * effp)
 {
-    dcs_t dcs = (dcs_t) effp->priv;
+    priv_t * dcs = (priv_t *) effp->priv;
 
     if (dcs->dcshift == 0)
       return SOX_EFF_NULL;
@@ -78,10 +75,10 @@
 /*
  * Process data.
  */
-static int sox_dcshift_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
-    dcs_t dcs = (dcs_t) effp->priv;
+    priv_t * dcs = (priv_t *) effp->priv;
     double dcshift = dcs->dcshift;
     double limitergain = dcs->limitergain;
     double limiterthreshhold = dcs->limiterthreshhold;
@@ -147,7 +144,7 @@
  */
 static int sox_dcshift_stop(sox_effect_t * effp)
 {
-    dcs_t dcs = (dcs_t) effp->priv;
+    priv_t * dcs = (priv_t *) effp->priv;
 
     if (dcs->limited)
     {
@@ -181,7 +178,7 @@
    sox_dcshift_flow,
    NULL,
    sox_dcshift_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_dcshift_effect_fn(void)
--- a/src/delay.c
+++ b/src/delay.c
@@ -1,5 +1,4 @@
-/*
- * Effect: Delay one or more channels.   (c) 2008 robs@users.sourceforge.net
+/* libSoX effect: Delay one or more channels (c) 2008 robs@users.sourceforge.net
  *
  * 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
@@ -19,19 +18,16 @@
 #include "sox_i.h"
 #include <string.h>
 
-typedef struct delay {
+typedef struct {
   size_t argc;
   char * * argv, * max_arg;
   sox_size_t delay, pad, buffer_size, buffer_index;
   sox_sample_t * buffer;
-} * priv_t;
+} priv_t;
+#define p ((priv_t *)effp->priv)
 
-assert_static(sizeof(struct delay) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ delay_PRIVSIZE_too_big);
-
 static int kill(sox_effect_t * effp)
 {
-  priv_t p = (priv_t) effp->priv;
   unsigned i;
 
   for (i = 0; i < p->argc; ++i)
@@ -42,7 +38,6 @@
 
 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;
   unsigned i;
 
@@ -63,7 +58,6 @@
 
 static int stop(sox_effect_t * effp)
 {
-  priv_t p = (priv_t) effp->priv;
   free(p->buffer);
   return SOX_SUCCESS;
 }
@@ -70,7 +64,6 @@
 
 static int start(sox_effect_t * effp)
 {
-  priv_t p = (priv_t) effp->priv;
   sox_size_t max_delay;
 
   if (!p->max_arg)
@@ -87,7 +80,6 @@
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
     sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
 {
-  priv_t p = (priv_t) effp->priv;
   sox_size_t len = *isamp = *osamp = min(*isamp, *osamp);
 
   if (!p->buffer_size)
@@ -107,7 +99,6 @@
 
 static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
 {
-  priv_t p = (priv_t) effp->priv;
   sox_size_t len = *osamp = min(p->delay + p->pad, *osamp);
 
   for (; p->delay && len; --p->delay, --len) {
@@ -123,7 +114,7 @@
 {
   static sox_effect_handler_t handler = {
     "delay", "{length}", SOX_EFF_LENGTH,
-    create, start, flow, drain, stop, kill
+    create, start, flow, drain, stop, kill, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/dither.c
+++ b/src/dither.c
@@ -1,57 +1,33 @@
-/*
- * libSoX dithering noise effect file.
+/* libSoX dithering noise effect file.      July 5, 1991
  *
- * July 5, 1991
+ * Copyright (c) 1999-8 Chris Bagwell & SoX contributors
  * Copyright 1991 Lance Norskog And Sundry Contributors
+ *
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Lance Norskog And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Lance Norskog And Sundry Contributors are not responsible for
  * the consequences of using this software.
  *
- * TODO: does triangular noise, could do local shaping
- *
+ * TODO: does triangular noise, could do local shaping.
  */
 
 #include "sox_i.h"
 
-#include <stdlib.h>
-#include <math.h>
+typedef struct {double amount;} priv_t;
+#define p ((priv_t *)effp->priv)
 
-typedef struct dither {
-  double amount;
-} * dither_t;
-
-assert_static(sizeof(struct dither) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ dither_PRIVSIZE_too_big);
-
-static int getopts(sox_effect_t * effp, int n, char * * argv)
+static int getopts(sox_effect_t * effp, int argc, char * * argv)
 {
-  dither_t dither = (dither_t) effp->priv;
-
-  if (n > 1)
-    return lsx_usage(effp);
-  
-  dither->amount = sqrt(2.); /* M_SQRT2 missing in some places */   /* Default to half a bit. */
-  if (n == 1) {
-    double amount;
-    char dummy;
-    int scanned = sscanf(*argv, "%lf %c", &amount, &dummy);
-    if (scanned == 1 && amount > 0)
-      dither->amount *= amount;
-    else
-      return lsx_usage(effp);
-  }
-
-  return SOX_SUCCESS;
+  p->amount = M_SQRT2;   /* Default to half a bit. */
+  do {NUMERIC_PARAMETER(amount, 1, 10)} while (0);
+  return argc?  lsx_usage(effp) : SOX_SUCCESS;
 }
 
 static int start(sox_effect_t * effp)
 {
-  dither_t dither = (dither_t) effp->priv;
-
   if (effp->out_signal.precision > 16)
     return SOX_EFF_NULL;   /* Dithering not needed at >= 24 bits */
-  dither->amount *= 1 << (16 - effp->out_signal.precision);
+  p->amount *= 1 << (16 - effp->out_signal.precision);
   return SOX_SUCCESS;
 }
 
@@ -58,13 +34,11 @@
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
     sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
 {
-  dither_t dither = (dither_t)effp->priv;
-  sox_size_t len = min(*isamp, *osamp);
+  sox_size_t len = *isamp = *osamp = min(*isamp, *osamp);
 
-  *isamp = *osamp = len;
-  while (len--) {             /* 16 signed bits of triangular noise */
+  while (len--) {   /* 16 signed bits of triangular noise: */
     int tri16 = ((rand() % 32768) + (rand() % 32768)) - 32767;
-    double l = *ibuf++ + tri16 * dither->amount;
+    double l = *ibuf++ + tri16 * p->amount;
     *obuf++ = SOX_ROUND_CLIP_COUNT(l, effp->clips);
   }
   return SOX_SUCCESS;
@@ -74,7 +48,7 @@
 {
   static sox_effect_handler_t handler = {
     "dither", "[amount]", SOX_EFF_MCHAN | SOX_EFF_PREC,
-    getopts, start, flow, 0, 0, 0
+    getopts, start, flow, 0, 0, 0, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/dvms-fmt.c
+++ b/src/dvms-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File format: DVMS (see cvsd.c)        (c) 2007-8 SoX contributors
+/* libSoX file format: DVMS (see cvsd.c)        (c) 2007-8 SoX contributors
  *
  * 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
@@ -22,13 +21,12 @@
 {
   static char const * const names[] = {"dvms", "vms", NULL};
   static unsigned const write_encodings[] = {SOX_ENCODING_CVSD, 1, 0, 0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
     "Continuously Variable Slope Delta modulation with header",
     names, SOX_FILE_MONO,
     sox_dvmsstartread, sox_cvsdread, sox_cvsdstopread,
     sox_dvmsstartwrite, sox_cvsdwrite, sox_dvmsstopwrite,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(cvsd_priv_t)
   };
   return &handler;
 }
--- a/src/earwax.c
+++ b/src/earwax.c
@@ -1,25 +1,16 @@
-/*
- * earwax - makes listening to headphones easier
+/* libSoX earwax - makes listening to headphones easier     November 9, 2000
  *
- * This effect takes a stereo sound that is meant to be listened to
- * on headphones, and adds audio cues to move the soundstage from inside
- * your head (standard for headphones) to outside and in front of the
- * listener (standard for speakers). This makes the sound much easier to
- * listen to on headphones. See www.geocities.com/beinges for a full
- * explanation.
+ * Copyright (c) 2000 Edward Beingessner And Sundry Contributors.
+ * This source code is freely redistributable and may be used for any purpose.
+ * This copyright notice must be maintained.  Edward Beingessner And Sundry
+ * Contributors are not responsible for the consequences of using this
+ * software.
  *
- * Usage:
- *   earwax
- *
- * Note:
- *   This filter only works for 44.1 kHz stereo signals (CD format)
- *
- * November 9, 2000
- * Copyright (c) 2000 Edward Beingessner And Sundry Contributors
- * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained.
- * Edward Beingessner And Sundry Contributors are not responsible for
- * the consequences of using this software.
+ * This effect takes a 44.1kHz stereo (CD format) signal that is meant to be
+ * listened to on headphones, and adds audio cues to move the soundstage from
+ * inside your head (standard for headphones) to outside and in front of the
+ * listener (standard for speakers). This makes the sound much easier to listen
+ * to on headphones. See www.geocities.com/beinges for a full explanation.
  */
 
 #include "sox_i.h"
@@ -60,18 +51,17 @@
     0,   -5,
     4,    0};
 
-#define EARWAX_NUMTAPS array_length(filt)
-#define taps ((sox_sample_t *)&(effp->priv)) /* FIR filter z^-1 delays */
+#define NUMTAPS array_length(filt)
+typedef struct {sox_sample_t tap[NUMTAPS];} priv_t; /* FIR filter z^-1 delays */
+#define p (*(priv_t *)effp->priv)
 
 static int start(sox_effect_t * effp)
 {
-  assert_static(EARWAX_NUMTAPS * sizeof(*taps) <= SOX_MAX_EFFECT_PRIVSIZE,
-                /* else */ earwax_PRIVSIZE_too_big);
   if (effp->in_signal.rate != 44100 || effp->in_signal.channels != 2) {
     sox_fail("works only with stereo audio sampled at 44100Hz (i.e. CDDA)");
     return SOX_EOF;
   }
-  memset(taps, 0, EARWAX_NUMTAPS * sizeof(*taps)); /* zero tap memory */
+  memset(p.tap, 0, NUMTAPS * sizeof(*p.tap)); /* zero tap memory */
   return SOX_SUCCESS;
 }
 
@@ -83,12 +73,12 @@
   while (len--) {       /* update taps and calculate output */
     sox_sample_t output = 0;
 
-    for (i = EARWAX_NUMTAPS - 1; i; --i) {
-      taps[i] = taps[i - 1];
-      output += taps[i] * filt[i];
+    for (i = NUMTAPS - 1; i; --i) {
+      p.tap[i] = p.tap[i - 1];
+      output += p.tap[i] * filt[i];
     }
-    taps[0] = *ibuf++ / 64;
-    *obuf++ = output + taps[0] * filt[0];   /* store scaled output */
+    p.tap[0] = *ibuf++ / 64;
+    *obuf++ = output + p.tap[0] * filt[0];   /* store scaled output */
   }
   return SOX_SUCCESS;
 }
@@ -97,7 +87,7 @@
 
 sox_effect_handler_t const *sox_earwax_effect_fn(void)
 {
-  static sox_effect_handler_t handler = {
-    "earwax", NULL, SOX_EFF_MCHAN, NULL, start, flow, NULL, NULL, NULL};
+  static sox_effect_handler_t handler = {"earwax", NULL, SOX_EFF_MCHAN,
+    NULL, start, flow, NULL, NULL, NULL, sizeof(priv_t)};
   return &handler;
 }
--- a/src/echo.c
+++ b/src/echo.c
@@ -1,19 +1,12 @@
-/*
- * August 24, 1998
+/* libSoX Echo effect             August 24, 1998
+ *
  * Copyright (C) 1998 Juergen Mueller And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Juergen Mueller And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Juergen Mueller And Sundry Contributors are not responsible for
  * the consequences of using this software.
- */
-
-/*
- * This is the "echo.c" while the old "echo.c" from version 12 moves to
- * "reverb.c" satisfying the definitions made in the Guitar FX FAQ.
  *
  *
- * Echo effect for dsp.
- * 
  * Flow diagram scheme for n delays ( 1 <= n <= MAX_ECHOS ):
  *
  *        * gain-in                                              ___
@@ -29,12 +22,11 @@
  *                  :                 _________                 |   |
  *                  |                |         |      * decay n |   |
  *                  +--------------->| delay n |--------------->|___|
- *                                   |_________|                  | 
+ *                                   |_________|                  |
  *                                                                | * gain-out
  *                                                                |
  *                                                                +----->obuff
- *
- * Usage: 
+ * Usage:
  *   echo gain-in gain-out delay-1 decay-1 [delay-2 decay-2 ... delay-n decay-n]
  *
  * Where:
@@ -44,21 +36,15 @@
  *
  * Note:
  *   when decay is close to 1.0, the samples can begin clipping and the output
- *   can saturate! 
+ *   can saturate!
  *
  * Hint:
  *   1 / out-gain > gain-in ( 1 + decay-1 + ... + decay-n )
- *
-*/
-
-/*
- * libSoX reverb effect file.
  */
 
 #include "sox_i.h"
 
 #include <stdlib.h> /* Harmless, and prototypes atof() etc. --dgc */
-#include <math.h>
 
 #define DELAY_BUFSIZ ( 50 * 50U * 1024 )
 #define MAX_ECHOS 7     /* 24 bit x ( 1 + MAX_ECHOS ) = */
@@ -65,8 +51,8 @@
                         /* 24 bit x 8 = 32 bit !!!      */
 
 /* Private data for SKEL file */
-typedef struct echostuff {
-        int     counter;                        
+typedef struct {
+        int     counter;
         int     num_delays;
         double  *delay_buf;
         float   in_gain, out_gain;
@@ -73,7 +59,7 @@
         float   delay[MAX_ECHOS], decay[MAX_ECHOS];
         sox_ssize_t samples[MAX_ECHOS], maxsamples;
         sox_size_t fade_out;
-} *echo_t;
+} priv_t;
 
 /* Private data for SKEL file */
 
@@ -81,9 +67,9 @@
 /*
  * Process options
  */
-static int sox_echo_getopts(sox_effect_t * effp, int n, char **argv) 
+static int sox_echo_getopts(sox_effect_t * effp, int n, char **argv)
 {
-        echo_t echo = (echo_t) effp->priv;
+        priv_t * echo = (priv_t *) effp->priv;
         int i;
 
         echo->num_delays = 0;
@@ -111,7 +97,7 @@
  */
 static int sox_echo_start(sox_effect_t * effp)
 {
-        echo_t echo = (echo_t) effp->priv;
+        priv_t * echo = (priv_t *) effp->priv;
         int i;
         float sum_in_volume;
         long j;
@@ -163,7 +149,7 @@
                 echo->delay_buf[j] = 0.0;
         /* Be nice and check the hint with warning, if... */
         sum_in_volume = 1.0;
-        for ( i = 0; i < echo->num_delays; i++ ) 
+        for ( i = 0; i < echo->num_delays; i++ )
                 sum_in_volume += echo->decay[i];
         if ( sum_in_volume * echo->in_gain > 1.0 / echo->out_gain )
                 sox_warn("echo: warning >>> gain-out can cause saturation of output <<<");
@@ -176,10 +162,10 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int sox_echo_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
-        echo_t echo = (echo_t) effp->priv;
+        priv_t * echo = (priv_t *) effp->priv;
         int j;
         double d_in, d_out;
         sox_sample_t out;
@@ -192,8 +178,8 @@
                 /* Compute output first */
                 d_out = d_in * echo->in_gain;
                 for ( j = 0; j < echo->num_delays; j++ ) {
-                        d_out += echo->delay_buf[ 
-(echo->counter + echo->maxsamples - echo->samples[j]) % echo->maxsamples] 
+                        d_out += echo->delay_buf[
+(echo->counter + echo->maxsamples - echo->samples[j]) % echo->maxsamples]
                         * echo->decay[j];
                 }
                 /* Adjust the output volume and size to 24 bit */
@@ -210,11 +196,11 @@
 }
 
 /*
- * Drain out reverb lines. 
+ * Drain out reverb lines.
  */
 static int sox_echo_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-        echo_t echo = (echo_t) effp->priv;
+        priv_t * echo = (priv_t *) effp->priv;
         double d_in, d_out;
         sox_sample_t out;
         int j;
@@ -226,8 +212,8 @@
                 d_in = 0;
                 d_out = 0;
                 for ( j = 0; j < echo->num_delays; j++ ) {
-                        d_out += echo->delay_buf[ 
-(echo->counter + echo->maxsamples - echo->samples[j]) % echo->maxsamples] 
+                        d_out += echo->delay_buf[
+(echo->counter + echo->maxsamples - echo->samples[j]) % echo->maxsamples]
                         * echo->decay[j];
                 }
                 /* Adjust the output volume and size to 24 bit */
@@ -254,7 +240,7 @@
  */
 static int sox_echo_stop(sox_effect_t * effp)
 {
-        echo_t echo = (echo_t) effp->priv;
+        priv_t * echo = (priv_t *) effp->priv;
 
         free((char *) echo->delay_buf);
         echo->delay_buf = (double *) -1;   /* guaranteed core dump */
@@ -270,7 +256,7 @@
   sox_echo_flow,
   sox_echo_drain,
   sox_echo_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_echo_effect_fn(void)
--- a/src/echos.c
+++ b/src/echos.c
@@ -1,15 +1,12 @@
-/*
- * August 24, 1998
+/* libSoX Echo effect             August 24, 1998
+ *
  * Copyright (C) 1998 Juergen Mueller And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Juergen Mueller And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Juergen Mueller And Sundry Contributors are not responsible for
  * the consequences of using this software.
- */
-
-/*
- * Echos effect for dsp.
- * 
+ *
+ *
  * Flow diagram scheme for n delays ( 1 <= n <= MAX_ECHOS ):
  *
  *                                                    * gain-in  ___
@@ -20,12 +17,11 @@
  *         |               |             +--------------------->|   |
  *         |               |             |            * decay n |   |
  *         |    _________  |  _________  |     _________   +--->|___|
- *         |   |         | | |         | |    |         |  |      | 
+ *         |   |         | | |         | |    |         |  |      |
  *         +-->| delay 1 |-+-| delay 2 |-+...-| delay n |--+      | * gain-out
  *             |_________|   |_________|      |_________|         |
  *                                                                +----->obuff
- *
- * Usage: 
+ * Usage:
  *   echos gain-in gain-out delay-1 decay-1 [delay-2 decay-2 ... delay-n decay-n]
  *
  * Where:
@@ -35,21 +31,16 @@
  *
  * Note:
  *   when decay is close to 1.0, the samples can begin clipping and the output
- *   can saturate! 
+ *   can saturate!
  *
  * Hint:
  *   1 / out-gain > gain-in ( 1 + decay-1 + ... + decay-n )
  *
-*/
-
-/*
- * libSoX reverb effect file.
  */
 
 #include "sox_i.h"
 
 #include <stdlib.h> /* Harmless, and prototypes atof() etc. --dgc */
-#include <math.h>
 
 #define DELAY_BUFSIZ ( 50 * 50U * 1024 )
 #define MAX_ECHOS 7     /* 24 bit x ( 1 + MAX_ECHOS ) = */
@@ -56,8 +47,8 @@
                         /* 24 bit x 8 = 32 bit !!!      */
 
 /* Private data for SKEL file */
-typedef struct echosstuff {
-        int     counter[MAX_ECHOS];                     
+typedef struct {
+        int     counter[MAX_ECHOS];
         int     num_delays;
         double  *delay_buf;
         float   in_gain, out_gain;
@@ -64,7 +55,7 @@
         float   delay[MAX_ECHOS], decay[MAX_ECHOS];
         sox_ssize_t samples[MAX_ECHOS], pointer[MAX_ECHOS];
         sox_size_t sumsamples;
-} *echos_t;
+} priv_t;
 
 /* Private data for SKEL file */
 
@@ -71,9 +62,9 @@
 /*
  * Process options
  */
-static int sox_echos_getopts(sox_effect_t * effp, int n, char **argv) 
+static int sox_echos_getopts(sox_effect_t * effp, int n, char **argv)
 {
-        echos_t echos = (echos_t) effp->priv;
+        priv_t * echos = (priv_t *) effp->priv;
         int i;
 
         echos->num_delays = 0;
@@ -105,7 +96,7 @@
  */
 static int sox_echos_start(sox_effect_t * effp)
 {
-        echos_t echos = (echos_t) effp->priv;
+        priv_t * echos = (priv_t *) effp->priv;
         int i;
         float sum_in_volume;
         unsigned long j;
@@ -157,7 +148,7 @@
                 echos->delay_buf[j] = 0.0;
         /* Be nice and check the hint with warning, if... */
         sum_in_volume = 1.0;
-        for ( i = 0; i < echos->num_delays; i++ ) 
+        for ( i = 0; i < echos->num_delays; i++ )
                 sum_in_volume += echos->decay[i];
         if ( sum_in_volume * echos->in_gain > 1.0 / echos->out_gain )
                 sox_warn("echos: warning >>> gain-out can cause saturation of output <<<");
@@ -168,10 +159,10 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int sox_echos_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
-        echos_t echos = (echos_t) effp->priv;
+        priv_t * echos = (priv_t *) effp->priv;
         int j;
         double d_in, d_out;
         sox_sample_t out;
@@ -195,12 +186,12 @@
                         if ( j == 0 )
                                 echos->delay_buf[echos->counter[j] + echos->pointer[j]] = d_in;
                         else
-                                echos->delay_buf[echos->counter[j] + echos->pointer[j]] = 
+                                echos->delay_buf[echos->counter[j] + echos->pointer[j]] =
                                    echos->delay_buf[echos->counter[j-1] + echos->pointer[j-1]] + d_in;
                 }
                 /* Adjust the counters */
                 for ( j = 0; j < echos->num_delays; j++ )
-                        echos->counter[j] = 
+                        echos->counter[j] =
                            ( echos->counter[j] + 1 ) % echos->samples[j];
         }
         /* processed all samples */
@@ -208,11 +199,11 @@
 }
 
 /*
- * Drain out reverb lines. 
+ * Drain out reverb lines.
  */
 static int sox_echos_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-        echos_t echos = (echos_t) effp->priv;
+        priv_t * echos = (priv_t *) effp->priv;
         double d_in, d_out;
         sox_sample_t out;
         int j;
@@ -235,12 +226,12 @@
                         if ( j == 0 )
                                 echos->delay_buf[echos->counter[j] + echos->pointer[j]] = d_in;
                         else
-                                echos->delay_buf[echos->counter[j] + echos->pointer[j]] = 
+                                echos->delay_buf[echos->counter[j] + echos->pointer[j]] =
                                    echos->delay_buf[echos->counter[j-1] + echos->pointer[j-1]];
                 }
                 /* Adjust the counters */
                 for ( j = 0; j < echos->num_delays; j++ )
-                        echos->counter[j] = 
+                        echos->counter[j] =
                            ( echos->counter[j] + 1 ) % echos->samples[j];
                 done++;
                 echos->sumsamples--;
@@ -258,7 +249,7 @@
  */
 static int sox_echos_stop(sox_effect_t * effp)
 {
-        echos_t echos = (echos_t) effp->priv;
+        priv_t * echos = (priv_t *) effp->priv;
 
         free((char *) echos->delay_buf);
         echos->delay_buf = (double *) -1;   /* guaranteed core dump */
@@ -274,7 +265,7 @@
   sox_echos_flow,
   sox_echos_drain,
   sox_echos_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_echos_effect_fn(void)
--- a/src/effects.c
+++ b/src/effects.c
@@ -1,6 +1,4 @@
-/*
- * SoX Effects chain
- * (c) 2007 robs@users.sourceforge.net
+/* SoX Effects chain     (c) 2007 robs@users.sourceforge.net
  *
  * 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
@@ -65,10 +63,10 @@
 }
 
 /* Partially initialise the effect structure; signal info will come later */
-void sox_create_effect(sox_effect_t * effp, sox_effect_handler_t const * eh)
+sox_effect_t * sox_create_effect(sox_effect_handler_t const * eh)
 {
+  sox_effect_t * effp = lsx_calloc(1, sizeof(*effp));
   assert(eh);
-  memset(effp, 0, sizeof(*effp));
   effp->global_info = &sox_effects_globals;
   effp->handler = *eh;
   if (!effp->handler.getopts) effp->handler.getopts = default_getopts;
@@ -77,6 +75,8 @@
   if (!effp->handler.drain  ) effp->handler.drain   = default_drain;
   if (!effp->handler.stop   ) effp->handler.stop    = default_function;
   if (!effp->handler.kill   ) effp->handler.kill    = default_function;
+  effp->priv = lsx_calloc(1, effp->handler.priv_size);
+  return effp;
 }
 
 
@@ -139,18 +139,23 @@
   effp->clips = 0;
   effp->imin = 0;
   eff0 = *effp;
+  eff0.priv = lsx_memdup(eff0.priv, eff0.handler.priv_size);
   ret = start(effp);
   if (ret == SOX_EFF_NULL) {
     sox_report("has no effect in this configuration");
+    free(eff0.priv);
     return SOX_SUCCESS;
   }
-  if (ret != SOX_SUCCESS)
+  if (ret != SOX_SUCCESS) {
+    free(eff0.priv);
     return SOX_EOF;
+  }
 
   *in = effp->out_signal;
 
   if (chain->length == SOX_MAX_EFFECTS) {
     sox_fail("Too many effects!");
+    free(eff0.priv);
     return SOX_EOF;
   }
   chain->effects[chain->length] =
@@ -160,11 +165,15 @@
   for (f = 1; f < effp->flows; ++f) {
     chain->effects[chain->length][f] = eff0;
     chain->effects[chain->length][f].flow = f;
-    if (start(&chain->effects[chain->length][f]) != SOX_SUCCESS)
+    chain->effects[chain->length][f].priv = lsx_memdup(eff0.priv, eff0.handler.priv_size);
+    if (start(&chain->effects[chain->length][f]) != SOX_SUCCESS) {
+      free(eff0.priv);
       return SOX_EOF;
+    }
   }
 
   ++chain->length;
+  free(eff0.priv);
   return SOX_SUCCESS;
 }
 
@@ -370,6 +379,7 @@
 void sox_delete_effects(sox_effects_chain_t * chain)
 {
   sox_size_t e, clips;
+  unsigned f;
 
   for (e = 0; e < chain->length; ++e) {
     sox_effect_t * effp = chain->effects[e];
@@ -377,7 +387,9 @@
       sox_warn("%s clipped %u samples; decrease volume?",
           chain->effects[e][0].handler.name, clips);
     effp->handler.kill(effp);
-    free(chain->effects[e]);
+    for (f = 0; f < effp->flows; ++f)
+      free(chain->effects[e][f].priv);
+    free(effp);
   }
   chain->length = 0;
 }
--- a/src/effects.h
+++ b/src/effects.h
@@ -1,5 +1,4 @@
-/*
- * This library is free software; you can redistribute it and/or modify it
+/* 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.
--- a/src/effects_i.c
+++ b/src/effects_i.c
@@ -1,5 +1,4 @@
-/*
- * Implements a libSoX internal interface for implementing effects.
+/* Implements a libSoX internal interface for implementing effects.
  * All public functions & data are prefixed with lsx_ .
  *
  * (c) 2005-8 Chris Bagwell and SoX contributors
@@ -20,7 +19,6 @@
  */
 
 #include "sox_i.h"
-#include <math.h>
 #include <string.h>
 
 #undef sox_fail
@@ -159,7 +157,7 @@
 
     pos = strchr(str, ':');
     found_colon = pos && pos < end;
-    
+
     pos = strchr(str, '.');
     found_dot = pos && pos < end;
 
--- a/src/example1.c
+++ b/src/example1.c
@@ -1,5 +1,4 @@
-/*
- * Simple example of using SoX libraries
+/* Simple example of using SoX libraries
  *
  * Copyright (c) 2007-8 robs@users.sourceforge.net
  *
@@ -25,7 +24,7 @@
 #endif
 #include <assert.h>
 
-static sox_format_t * in, * out; /* input and output files */ 
+static sox_format_t * in, * out; /* input and output files */
 
 /* The function that will be called to input samples into the effects chain.
  * In this example, we get samples to process from a SoX-openned audio file.
@@ -43,7 +42,7 @@
    * back to *osamp */
   *osamp = sox_read(in, obuf, *osamp);
 
-  /* sox_read may return a number that is less than was requested; only if 
+  /* sox_read may return a number that is less than was requested; only if
    * 0 samples is returned does it indicate that end-of-file has been reached
    * or an error has occurred */
   if (!*osamp && in->sox_errno)
@@ -53,7 +52,7 @@
 
 /* The function that will be called to output samples from the effects chain.
  * In this example, we store the samples in a SoX-openned audio file.
- * In a different application, they might perhaps be analysed in some way, 
+ * 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)
@@ -83,7 +82,7 @@
 static sox_effect_handler_t const * input_handler(void)
 {
   static sox_effect_handler_t handler = {
-    "input", NULL, SOX_EFF_MCHAN, NULL, NULL, NULL, input_drain, NULL, NULL
+    "input", NULL, SOX_EFF_MCHAN, NULL, NULL, NULL, input_drain, NULL, NULL, 0
   };
   return &handler;
 }
@@ -93,12 +92,12 @@
 static sox_effect_handler_t const * output_handler(void)
 {
   static sox_effect_handler_t handler = {
-    "output", NULL, SOX_EFF_MCHAN, NULL, NULL, output_flow, NULL, NULL, NULL
+    "output", NULL, SOX_EFF_MCHAN, NULL, NULL, output_flow, NULL, NULL, NULL, 0
   };
   return &handler;
 }
 
-/* 
+/*
  * Reads input file, applies vol & flanger effects, stores in output file.
  * E.g. example1 monkey.au monkey.aiff
  */
@@ -105,7 +104,7 @@
 int main(int argc, char * argv[])
 {
   sox_effects_chain_t * chain;
-  sox_effect_t e;
+  sox_effect_t * e;
   char * vol[] = {"3dB"};
 
   assert(argc == 3);
@@ -119,7 +118,7 @@
   /* Open the output file; we must specify the output signal characteristics.
    * Since we are using only simple effects, they are the same as the input
    * file characteristics */
-  assert(out = sox_open_write(NULL, argv[2], &in->signal, NULL, NULL, NULL, 0, NULL, 0));
+  assert(out = sox_open_write(argv[2], &in->signal, NULL, NULL, NULL, NULL));
 
   /* Create an effects chain; some effects need to know about the input
    * or output file encoding so we provide that information here */
@@ -128,27 +127,27 @@
   /* The first effect in the effect chain must be something that can source
    * samples; in this case, we have defined an input handler that inputs
    * data from an audio file */
-  sox_create_effect(&e, input_handler());
+  e = sox_create_effect(input_handler());
   /* This becomes the first `effect' in the chain */
-  assert(sox_add_effect(chain, &e, &in->signal, &in->signal) == SOX_SUCCESS);
+  assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
 
   /* Create the `vol' effect, and initialise it with the desired parameters: */
-  sox_create_effect(&e, sox_find_effect("vol"));
-  assert(e.handler.getopts(&e, 1, vol) == SOX_SUCCESS);
+  e = sox_create_effect(sox_find_effect("vol"));
+  assert(e->handler.getopts(e, 1, vol) == SOX_SUCCESS);
   /* Add the effect to the end of the effects processing chain: */
-  assert(sox_add_effect(chain, &e, &in->signal, &in->signal) == SOX_SUCCESS);
+  assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
 
   /* Create the `flanger' effect, and initialise it with default parameters: */
-  sox_create_effect(&e, sox_find_effect("flanger"));
-  assert(e.handler.getopts(&e, 0, NULL) == SOX_SUCCESS);
+  e = sox_create_effect(sox_find_effect("flanger"));
+  assert(e->handler.getopts(e, 0, NULL) == SOX_SUCCESS);
   /* Add the effect to the end of the effects processing chain: */
-  assert(sox_add_effect(chain, &e, &in->signal, &in->signal) == SOX_SUCCESS);
+  assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
 
   /* The last effect in the effect chain must be something that only consumes
    * samples; in this case, we have defined an output handler that outputs
    * data to an audio file */
-  sox_create_effect(&e, output_handler());
-  assert(sox_add_effect(chain, &e, &in->signal, &in->signal) == SOX_SUCCESS);
+  e = sox_create_effect(output_handler());
+  assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
 
   /* Flow samples through the effects processing chain until EOF is reached */
   sox_flow_effects(chain, NULL);
--- a/src/example2.c
+++ b/src/example2.c
@@ -1,5 +1,4 @@
-/*
- * Simple example of using SoX libraries
+/* Simple example of using SoX libraries
  *
  * Copyright (c) 2008 robs@users.sourceforge.net
  *
@@ -27,7 +26,7 @@
 #endif
 #include <assert.h>
 
-/* 
+/*
  * Reads input file and displays a few seconds of wave-form, starting from
  * a given time through the audio.   E.g. example2 song2.au 30.75 1
  */
--- a/src/fade.c
+++ b/src/fade.c
@@ -1,5 +1,4 @@
-/*
- * Ari Moisio <armoi@sci.fi> Aug 29 2000, based on skeleton effect
+/* Ari Moisio <armoi@sci.fi> Aug 29 2000, based on skeleton effect
  * Written by Chris Bagwell (cbagwell@sprynet.com) - March 16, 1999
  *
  * Copyright 1999 Chris Bagwell And Sundry Contributors
@@ -21,18 +20,16 @@
 #define FADE_TRI        't'     /* Linear slope. */
 #define FADE_PAR        'p'     /* Inverted parabola. */
 
-#include <math.h>
 #include <string.h>
 
 /* Private data for fade file */
-typedef struct fadestuff
-{ /* These are measured as samples */
+typedef struct { /* These are measured as samples */
     sox_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;
     int endpadwarned;
-} *fade_t;
+} priv_t;
 
 /* prototypes */
 static double fade_gain(sox_size_t index, sox_size_t range, int fadetype);
@@ -47,7 +44,7 @@
 static int sox_fade_getopts(sox_effect_t * effp, int n, char **argv)
 {
 
-    fade_t fade = (fade_t) effp->priv;
+    priv_t * fade = (priv_t *) effp->priv;
     char t_char[2];
     int t_argno;
 
@@ -90,7 +87,7 @@
             strcpy(fade->out_stop_str,argv[t_argno]);
 
             /* Do a dummy parse to see if it will fail */
-            if (lsx_parsesamples(0., fade->out_stop_str, 
+            if (lsx_parsesamples(0., fade->out_stop_str,
                                 &fade->out_stop, 't') == NULL)
               return lsx_usage(effp);
         }
@@ -100,7 +97,7 @@
             strcpy(fade->out_start_str,argv[t_argno]);
 
             /* Do a dummy parse to see if it will fail */
-            if (lsx_parsesamples(0., fade->out_start_str, 
+            if (lsx_parsesamples(0., fade->out_start_str,
                                 &fade->out_start, 't') == NULL)
               return lsx_usage(effp);
         }
@@ -115,7 +112,7 @@
  */
 static int sox_fade_start(sox_effect_t * effp)
 {
-    fade_t fade = (fade_t) effp->priv;
+    priv_t * fade = (priv_t *) effp->priv;
 
     /* converting time values to samples */
     fade->in_start = 0;
@@ -150,7 +147,7 @@
             fade->out_start = fade->out_stop - fade->in_stop;
     }
     else
-        /* If not specified then user wants to process all 
+        /* If not specified then user wants to process all
          * of file.  Use a value of zero to indicate this.
          */
         fade->out_stop = 0;
@@ -177,10 +174,10 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int sox_fade_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
-    fade_t fade = (fade_t) effp->priv;
+    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;
@@ -260,7 +257,7 @@
  */
 static int sox_fade_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-    fade_t fade = (fade_t) effp->priv;
+    priv_t * fade = (priv_t *) effp->priv;
     int len;
     sox_size_t t_chan = 0;
 
@@ -301,7 +298,7 @@
  */
 static int kill(sox_effect_t * effp)
 {
-    fade_t fade = (fade_t) effp->priv;
+    priv_t * fade = (priv_t *) effp->priv;
 
     free(fade->in_stop_str);
     free(fade->out_start_str);
@@ -362,7 +359,7 @@
   sox_fade_flow,
   sox_fade_drain,
   NULL,
-  kill
+  kill, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_fade_effect_fn(void)
--- a/src/ffmpeg.c
+++ b/src/ffmpeg.c
@@ -1,5 +1,4 @@
-/*
- * libSoX ffmpeg formats.
+/* libSoX ffmpeg formats.
  *
  * Copyright 2007 Reuben Thomas <rrt@sc3d.org>
  *
@@ -50,8 +49,7 @@
 #include <ffmpeg/avformat.h>
 
 /* Private data for ffmpeg files */
-typedef struct ffmpeg
-{
+typedef struct {
   int audio_index;
   int audio_stream;
   AVStream *audio_st;
@@ -65,13 +63,10 @@
   AVPacket audio_pkt;
   uint8_t *audio_pkt_data;
   int audio_pkt_size;
-} *ffmpeg_t;
+} priv_t;
 
-assert_static(sizeof(struct ffmpeg) <= SOX_MAX_FILE_PRIVSIZE, 
-              /* else */ ffmpeg_PRIVSIZE_too_big);
-
 /* open a given stream. Return 0 if OK */
-static int stream_component_open(ffmpeg_t ffmpeg, int stream_index)
+static int stream_component_open(priv_t * ffmpeg, int stream_index)
 {
   AVFormatContext *ic = ffmpeg->ctxt;
   AVCodecContext *enc;
@@ -105,7 +100,7 @@
   return 0;
 }
 
-static void stream_component_close(ffmpeg_t ffmpeg, int stream_index)
+static void stream_component_close(priv_t * ffmpeg, int stream_index)
 {
   AVFormatContext *ic = ffmpeg->ctxt;
   AVCodecContext *enc;
@@ -118,7 +113,7 @@
 }
 
 /* Decode one audio frame and returns its uncompressed size */
-static int audio_decode_frame(ffmpeg_t ffmpeg, uint8_t *audio_buf, int buf_size)
+static int audio_decode_frame(priv_t * ffmpeg, uint8_t *audio_buf, int buf_size)
 {
   AVPacket *pkt = &ffmpeg->audio_pkt;
   int len1, data_size;
@@ -150,7 +145,7 @@
 
 static int startread(sox_format_t * ft)
 {
-  ffmpeg_t ffmpeg = (ffmpeg_t)ft->priv;
+  priv_t * ffmpeg = (priv_t *)ft->priv;
   AVFormatParameters params;
   int ret;
   int i;
@@ -159,7 +154,7 @@
 
   /* Signal audio stream not found */
   ffmpeg->audio_index = -1;
-  
+
   /* register all CODECs, demux and protocols */
   av_register_all();
 
@@ -201,7 +196,7 @@
   ft->encoding.bits_per_sample = 16;
   ft->encoding.encoding = SOX_ENCODING_SIGN2;
   ft->signal.channels = ffmpeg->audio_st->codec->channels;
-  ft->length = 0; /* Currently we can't seek; no idea how to get this
+  ft->signal.length = 0; /* Currently we can't seek; no idea how to get this
                      info from ffmpeg anyway (in time, yes, but not in
                      samples); but ffmpeg *can* seek */
 
@@ -214,7 +209,7 @@
  */
 static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-  ffmpeg_t ffmpeg = (ffmpeg_t)ft->priv;
+  priv_t * ffmpeg = (priv_t *)ft->priv;
   AVPacket *pkt = &ffmpeg->audio_pkt;
   int ret;
   sox_size_t nsamp = 0, nextra;
@@ -243,7 +238,7 @@
  */
 static int stopread(sox_format_t * ft)
 {
-  ffmpeg_t ffmpeg = (ffmpeg_t)ft->priv;
+  priv_t * ffmpeg = (priv_t *)ft->priv;
 
   if (ffmpeg->audio_stream >= 0)
     stream_component_close(ffmpeg, ffmpeg->audio_stream);
@@ -251,7 +246,7 @@
     av_close_input_file(ffmpeg->ctxt);
     ffmpeg->ctxt = NULL; /* safety */
   }
-  
+
   return SOX_SUCCESS;
 }
 
@@ -282,7 +277,7 @@
   return st;
 }
 
-static int open_audio(ffmpeg_t ffmpeg, AVStream *st)
+static int open_audio(priv_t * ffmpeg, AVStream *st)
 {
   AVCodecContext *c;
   AVCodec *codec;
@@ -328,7 +323,7 @@
 
 static int startwrite(sox_format_t * ft)
 {
-  ffmpeg_t ffmpeg = (ffmpeg_t)ft->priv;
+  priv_t * ffmpeg = (priv_t *)ft->priv;
 
   /* initialize libavcodec, and register all codecs and formats */
   av_register_all();
@@ -353,7 +348,7 @@
   }
   ffmpeg->ctxt->oformat = ffmpeg->fmt;
   snprintf(ffmpeg->ctxt->filename, sizeof(ffmpeg->ctxt->filename), "%s", ft->filename);
-  
+
   /* add the audio stream using the default format codecs
      and initialize the codecs */
   ffmpeg->audio_st = NULL;
@@ -362,7 +357,7 @@
     if (ffmpeg->audio_st == NULL)
       return SOX_EOF;
   }
-  
+
   /* set the output parameters (must be done even if no
      parameters). */
   if (av_set_parameters(ffmpeg->ctxt, NULL) < 0) {
@@ -372,13 +367,13 @@
 
   /* Next line for debugging */
   /* dump_format(ffmpeg->ctxt, 0, ft->filename, 1); */
-  
+
   /* now that all the parameters are set, we can open the audio and
      codec and allocate the necessary encode buffers */
   if (ffmpeg->audio_st)
     if (open_audio(ffmpeg, ffmpeg->audio_st) == SOX_EOF)
       return SOX_EOF;
-  
+
   /* open the output file, if needed */
   if (!(ffmpeg->fmt->flags & AVFMT_NOFILE)) {
     if (url_fopen(&ffmpeg->ctxt->pb, ft->filename, URL_WRONLY) < 0) {
@@ -386,10 +381,10 @@
       return SOX_EOF;
     }
   }
-  
+
   /* write the stream header, if any */
   av_write_header(ffmpeg->ctxt);
-  
+
   return SOX_SUCCESS;
 }
 
@@ -399,7 +394,7 @@
  */
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-  ffmpeg_t ffmpeg = (ffmpeg_t)ft->priv;
+  priv_t * ffmpeg = (priv_t *)ft->priv;
   sox_size_t nread = 0, nwritten = 0;
 
   /* Write data repeatedly until buf is empty */
@@ -422,7 +417,7 @@
       pkt.flags |= PKT_FLAG_KEY;
       pkt.stream_index = ffmpeg->audio_st->index;
       pkt.data = ffmpeg->audio_buf;
-      
+
       /* write the compressed frame to the media file */
       if (av_write_frame(ffmpeg->ctxt, &pkt) != 0)
         sox_fail("ffmpeg had error while writing audio frame");
@@ -442,7 +437,7 @@
  */
 static int stopwrite(sox_format_t * ft)
 {
-  ffmpeg_t ffmpeg = (ffmpeg_t)ft->priv;
+  priv_t * ffmpeg = (priv_t *)ft->priv;
   int i;
 
   /* Close CODEC */
@@ -451,16 +446,16 @@
     free(ffmpeg->samples);
     free(ffmpeg->audio_buf);
   }
-  
+
   /* Write the trailer, if any */
   av_write_trailer(ffmpeg->ctxt);
-  
+
   /* Free the streams */
   for (i = 0; i < ffmpeg->ctxt->nb_streams; i++) {
     av_freep(&ffmpeg->ctxt->streams[i]->codec);
     av_freep(&ffmpeg->ctxt->streams[i]);
   }
-  
+
   if (!(ffmpeg->fmt->flags & AVFMT_NOFILE)) {
     /* close the output file */
     url_fclose(&ffmpeg->ctxt->pb);
@@ -488,14 +483,11 @@
 
   static unsigned const write_encodings[] = {SOX_ENCODING_SIGN2, 16, 0, 0};
 
-  static sox_format_handler_t handler = {
-    SOX_LIB_VERSION_CODE,
-    "Pseudo format to use libffmpeg",
-    names,
-    SOX_FILE_NOSTDIO,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
+    "Pseudo format to use libffmpeg", names, SOX_FILE_NOSTDIO,
     startread, read_samples, stopread,
     startwrite, write_samples, stopwrite,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(priv_t)
   };
 
   return &handler;
--- a/src/fifo.h
+++ b/src/fifo.h
@@ -1,7 +1,4 @@
-#ifndef fifo_included
-#define fifo_included
-/*
- * Addressible FIFO buffer    Copyright (c) 2007 robs@users.sourceforge.net
+/* Addressable FIFO buffer    Copyright (c) 2007 robs@users.sourceforge.net
  *
  * 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
@@ -17,6 +14,9 @@
  * along with this library; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
+
+#ifndef fifo_included
+#define fifo_included
 
 #include <string.h>
 
--- a/src/filter.c
+++ b/src/filter.c
@@ -1,29 +1,31 @@
-/*
- * Windowed sinc lowpass/bandpass/highpass filter.
- */
-
-/*
- * November 18, 1999
+/* libSoX Windowed sinc lowpass/bandpass/highpass filter     November 18, 1999
+ * Copyright 1999 Stan Brooks <stabro@megsinet.net>
  * Copyright 1994 Julius O. Smith
  * Copyright 1991 (?) Lance Norskog (?)
- * Copyright 1999 Stan Brooks <stabro@megsinet.net>
  *
- * -------------------------------------------------------------------
- * This source code 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.
- * -------------------------------------------------------------------
+ * 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
+ *
+ *
  * REMARKS: (Stan Brooks speaking)
  * This code is heavily based on the resample.c code which was
  * apparently itself a rewrite (by Lance Norskog?) of code originally
- * by Julius O. Smith, and distributed under the GPL license...
- *
+ * by Julius O. Smith, and distributed under the LGPL.
  */
 
 #include "sox_i.h"
 
-#include <math.h>
 #include <string.h>
 #include <stdlib.h>
 
@@ -31,7 +33,7 @@
 #define BUFFSIZE 8192
 
 /* Private data for Lerp via LCM file */
-typedef struct filterstuff {
+typedef struct {
         sox_rate_t rate;
         sox_sample_t freq0;/* low  corner freq */
         sox_sample_t freq1;/* high corner freq */
@@ -41,13 +43,13 @@
         long Xh;/* number of past/future samples needed by filter  */
         long Xt;/* target to enter new data into X */
         double *X, *Y;/* I/O buffers */
-} *filter_t;
+} priv_t;
 
 /* lsx_makeFilter() declared in resample.c */
-extern int 
+extern int
 lsx_makeFilter(double Fp[], long Nwing, double Froll, double Beta, long Num, int Normalize);
 
-static void FiltWin(filter_t f, long Nx);
+static void FiltWin(priv_t * f, long Nx);
 
 /*
  * Process options
@@ -54,11 +56,11 @@
  */
 static int sox_filter_getopts(sox_effect_t * effp, int n, char **argv)
 {
-        filter_t f = (filter_t) effp->priv;
+        priv_t * f = (priv_t *) effp->priv;
 
         f->beta = 16;  /* Kaiser window, beta 16 */
         f->Nwin = 128;
-        
+
         f->freq0 = f->freq1 = 0;
         if (n >= 1) {
                 char *p;
@@ -95,7 +97,7 @@
  */
 static int sox_filter_start(sox_effect_t * effp)
 {
-        filter_t f = (filter_t) effp->priv;
+        priv_t * f = (priv_t *) effp->priv;
         double *Fp0, *Fp1;
         long Xh0, Xh1, Xh;
         int i;
@@ -112,7 +114,7 @@
                                         f->freq0, f->freq1, f->rate/2);
                 return (SOX_EOF);
         }
-        
+
         Xh = f->Nwin/2;
         Fp0 = (double *) lsx_malloc(sizeof(double) * (Xh + 2)) + 1;
         if (f->freq0 > (sox_sample_t)f->rate/200) {
@@ -171,10 +173,10 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int sox_filter_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
-        filter_t f = (filter_t) effp->priv;
+        priv_t * f = (priv_t *) effp->priv;
         sox_size_t Nx;
         long i, Nproc;
 
@@ -211,7 +213,7 @@
         /* Copy back portion of input signal that must be re-used */
         Nx += f->Xt;
         if (f->Xh)
-                memmove(f->X, f->X + Nx - 2*f->Xh, sizeof(double)*2*f->Xh); 
+                memmove(f->X, f->X + Nx - 2*f->Xh, sizeof(double)*2*f->Xh);
         f->Xt = 2*f->Xh;
 
         for (i = 0; i < Nproc; i++)
@@ -226,7 +228,7 @@
  */
 static int sox_filter_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-        filter_t f = (filter_t) effp->priv;
+        priv_t * f = (priv_t *) effp->priv;
         long isamp_res, osamp_res;
         sox_sample_t *Obuf;
 
@@ -258,12 +260,12 @@
 }
 
 /*
- * Do anything required when you stop reading samples.  
- * Don't close input file! 
+ * Do anything required when you stop reading samples.
+ * Don't close input file!
  */
 static int sox_filter_stop(sox_effect_t * effp)
 {
-        filter_t f = (filter_t) effp->priv;
+        priv_t * f = (priv_t *) effp->priv;
 
         free(f->Fp - 1);
         free(f->X);
@@ -274,7 +276,7 @@
 {
         const double *fp, *xp, *xq;
         double v = 0;
-        
+
         fp = Fp + ct;   /* so sum starts with smaller coef's */
         xp = Xp - ct;
         xq = Xp + ct;
@@ -286,7 +288,7 @@
         return v;
 }
 
-static void FiltWin(filter_t f, long Nx)
+static void FiltWin(priv_t * f, long Nx)
 {
         double *Y;
         double *X, *Xend;
@@ -309,7 +311,7 @@
   sox_filter_flow,
   sox_filter_drain,
   sox_filter_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_filter_effect_fn(void)
--- a/src/flac.c
+++ b/src/flac.c
@@ -1,5 +1,4 @@
-/*
- * File format: FLAC   (c) 2006-7 robs@users.sourceforge.net
+/* libSoX file format: FLAC   (c) 2006-7 robs@users.sourceforge.net
  *
  * 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
@@ -16,10 +15,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-
 #include "sox_i.h"
 
-#include <math.h>
 #include <string.h>
 /* Next line for systems that don't define off_t when you #include
    stdio.h; apparently OS/2 has this bug */
@@ -59,28 +56,32 @@
   unsigned number_of_wide_samples;
   unsigned wide_sample_number;
 
-  FLAC__StreamDecoder * flac;
+  FLAC__StreamDecoder * decoder;
   FLAC__bool eof;
-} Decoder;
 
+  /* Encode buffer: */
+  FLAC__int32 * decoded_samples;
+  unsigned number_of_samples;
 
+  FLAC__StreamEncoder * encoder;
+  FLAC__StreamMetadata * metadata[2];
+  unsigned num_metadata;
+} priv_t;
+#define p ((priv_t *)ft->priv)
 
-assert_static(sizeof(Decoder) <= SOX_MAX_FILE_PRIVSIZE, /* else */ Decoder__PRIVSIZE_too_big);
 
 
-
 static void FLAC__decoder_metadata_callback(FLAC__StreamDecoder const * const flac, FLAC__StreamMetadata const * const metadata, void * const client_data)
 {
   sox_format_t * ft = (sox_format_t *) client_data;
-  Decoder * decoder = (Decoder *) ft->priv;
 
   (void) flac;
 
   if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
-    decoder->bits_per_sample = metadata->data.stream_info.bits_per_sample;
-    decoder->channels = metadata->data.stream_info.channels;
-    decoder->sample_rate = metadata->data.stream_info.sample_rate;
-    decoder->total_samples = metadata->data.stream_info.total_samples;
+    p->bits_per_sample = metadata->data.stream_info.bits_per_sample;
+    p->channels = metadata->data.stream_info.channels;
+    p->sample_rate = metadata->data.stream_info.sample_rate;
+    p->total_samples = metadata->data.stream_info.total_samples;
   }
   else if (metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
     size_t i;
@@ -88,13 +89,13 @@
     if (metadata->data.vorbis_comment.num_comments == 0)
       return;
 
-    if (ft->comments != NULL) {
+    if (ft->oob.comments != NULL) {
       sox_warn("multiple Vorbis comment block ignored");
       return;
     }
 
     for (i = 0; i < metadata->data.vorbis_comment.num_comments; ++i)
-      sox_append_comment(&ft->comments, (char const *) metadata->data.vorbis_comment.comments[i].entry);
+      sox_append_comment(&ft->oob.comments, (char const *) metadata->data.vorbis_comment.comments[i].entry);
   }
 }
 
@@ -114,18 +115,17 @@
 static FLAC__StreamDecoderWriteStatus FLAC__frame_decode_callback(FLAC__StreamDecoder const * const flac, FLAC__Frame const * const frame, FLAC__int32 const * const buffer[], void * const client_data)
 {
   sox_format_t * ft = (sox_format_t *) client_data;
-  Decoder * decoder = (Decoder *) ft->priv;
 
   (void) flac;
 
-  if (frame->header.bits_per_sample != decoder->bits_per_sample || frame->header.channels != decoder->channels || frame->header.sample_rate != decoder->sample_rate) {
+  if (frame->header.bits_per_sample != p->bits_per_sample || frame->header.channels != p->channels || frame->header.sample_rate != p->sample_rate) {
     lsx_fail_errno(ft, SOX_EINVAL, "FLAC ERROR: parameters differ between frame and header");
     return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
   }
 
-  decoder->decoded_wide_samples = buffer;
-  decoder->number_of_wide_samples = frame->header.blocksize;
-  decoder->wide_sample_number = 0;
+  p->decoded_wide_samples = buffer;
+  p->number_of_wide_samples = frame->header.blocksize;
+  p->wide_sample_number = 0;
   return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
 }
 
@@ -133,27 +133,24 @@
 
 static int start_read(sox_format_t * const ft)
 {
-  Decoder * decoder = (Decoder *) ft->priv;
-
-  memset(decoder, 0, sizeof(*decoder));
-  decoder->flac = FLAC__stream_decoder_new();
-  if (decoder->flac == NULL) {
+  p->decoder = FLAC__stream_decoder_new();
+  if (p->decoder == NULL) {
     lsx_fail_errno(ft, SOX_ENOMEM, "FLAC ERROR creating the decoder instance");
     return SOX_EOF;
   }
 
-  FLAC__stream_decoder_set_md5_checking(decoder->flac, sox_true);
-  FLAC__stream_decoder_set_metadata_respond_all(decoder->flac);
+  FLAC__stream_decoder_set_md5_checking(p->decoder, sox_true);
+  FLAC__stream_decoder_set_metadata_respond_all(p->decoder);
 #if FLAC_API_VERSION_CURRENT <= 7
-  FLAC__file_decoder_set_filename(decoder->flac, ft->filename);
-  FLAC__file_decoder_set_write_callback(decoder->flac, FLAC__frame_decode_callback);
-  FLAC__file_decoder_set_metadata_callback(decoder->flac, FLAC__decoder_metadata_callback);
-  FLAC__file_decoder_set_error_callback(decoder->flac, FLAC__decoder_error_callback);
-  FLAC__file_decoder_set_client_data(decoder->flac, ft);
-  if (FLAC__file_decoder_init(decoder->flac) != FLAC__FILE_DECODER_OK) {
+  FLAC__file_decoder_set_filename(p->decoder, ft->filename);
+  FLAC__file_decoder_set_write_callback(p->decoder, FLAC__frame_decode_callback);
+  FLAC__file_decoder_set_metadata_callback(p->decoder, FLAC__decoder_metadata_callback);
+  FLAC__file_decoder_set_error_callback(p->decoder, FLAC__decoder_error_callback);
+  FLAC__file_decoder_set_client_data(p->decoder, ft);
+  if (FLAC__file_decoder_init(p->decoder) != FLAC__FILE_DECODER_OK) {
 #else
   if (FLAC__stream_decoder_init_file(
-    decoder->flac,
+    p->decoder,
     ft->filename,
     FLAC__frame_decode_callback,
     FLAC__decoder_metadata_callback,
@@ -165,15 +162,15 @@
   }
 
 
-  if (!FLAC__stream_decoder_process_until_end_of_metadata(decoder->flac)) {
+  if (!FLAC__stream_decoder_process_until_end_of_metadata(p->decoder)) {
     lsx_fail_errno(ft, SOX_EHDR, "FLAC ERROR whilst decoding metadata");
     return SOX_EOF;
   }
 
 #if FLAC_API_VERSION_CURRENT <= 7
-  if (FLAC__file_decoder_get_state(decoder->flac) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(decoder->flac) != FLAC__FILE_DECODER_END_OF_FILE) {
+  if (FLAC__file_decoder_get_state(p->decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(p->decoder) != FLAC__FILE_DECODER_END_OF_FILE) {
 #else
-  if (FLAC__stream_decoder_get_state(decoder->flac) > FLAC__STREAM_DECODER_END_OF_STREAM) {
+  if (FLAC__stream_decoder_get_state(p->decoder) > FLAC__STREAM_DECODER_END_OF_STREAM) {
 #endif
     lsx_fail_errno(ft, SOX_EHDR, "FLAC ERROR during metadata decoding");
     return SOX_EOF;
@@ -180,10 +177,10 @@
   }
 
   ft->encoding.encoding = SOX_ENCODING_FLAC;
-  ft->signal.rate = decoder->sample_rate;
-  ft->encoding.bits_per_sample = decoder->bits_per_sample;
-  ft->signal.channels = decoder->channels;
-  ft->length = decoder->total_samples * decoder->channels;
+  ft->signal.rate = p->sample_rate;
+  ft->encoding.bits_per_sample = p->bits_per_sample;
+  ft->signal.channels = p->channels;
+  ft->signal.length = p->total_samples * p->channels;
   return SOX_SUCCESS;
 }
 
@@ -190,20 +187,19 @@
 
 static sox_size_t read_samples(sox_format_t * const ft, sox_sample_t * sampleBuffer, sox_size_t const requested)
 {
-  Decoder * decoder = (Decoder *) ft->priv;
   size_t actual = 0;
 
-  while (!decoder->eof && actual < requested) {
-    if (decoder->wide_sample_number >= decoder->number_of_wide_samples)
-      FLAC__stream_decoder_process_single(decoder->flac);
-    if (decoder->wide_sample_number >= decoder->number_of_wide_samples)
-      decoder->eof = sox_true;
+  while (!p->eof && actual < requested) {
+    if (p->wide_sample_number >= p->number_of_wide_samples)
+      FLAC__stream_decoder_process_single(p->decoder);
+    if (p->wide_sample_number >= p->number_of_wide_samples)
+      p->eof = sox_true;
     else {
       unsigned channel;
 
-      for (channel = 0; channel < decoder->channels; channel++, actual++) {
-        FLAC__int32 d = decoder->decoded_wide_samples[channel][decoder->wide_sample_number];
-        switch (decoder->bits_per_sample) {
+      for (channel = 0; channel < p->channels; channel++, actual++) {
+        FLAC__int32 d = p->decoded_wide_samples[channel][p->wide_sample_number];
+        switch (p->bits_per_sample) {
         case  8: *sampleBuffer++ = SOX_SIGNED_8BIT_TO_SAMPLE(d,); break;
         case 16: *sampleBuffer++ = SOX_SIGNED_16BIT_TO_SAMPLE(d,); break;
         case 24: *sampleBuffer++ = SOX_SIGNED_24BIT_TO_SAMPLE(d,); break;
@@ -210,7 +206,7 @@
         case 32: *sampleBuffer++ = SOX_SIGNED_32BIT_TO_SAMPLE(d,); break;
         }
       }
-      ++decoder->wide_sample_number;
+      ++p->wide_sample_number;
     }
   }
   return actual;
@@ -220,35 +216,14 @@
 
 static int stop_read(sox_format_t * const ft)
 {
-  Decoder * decoder = (Decoder *) ft->priv;
-
-  if (!FLAC__stream_decoder_finish(decoder->flac) && decoder->eof)
+  if (!FLAC__stream_decoder_finish(p->decoder) && p->eof)
     sox_warn("decoder MD5 checksum mismatch.");
-  FLAC__stream_decoder_delete(decoder->flac);
+  FLAC__stream_decoder_delete(p->decoder);
   return SOX_SUCCESS;
 }
 
 
 
-typedef struct {
-  /* Info: */
-  unsigned bits_per_sample;
-
-  /* Encode buffer: */
-  FLAC__int32 * decoded_samples;
-  unsigned number_of_samples;
-
-  FLAC__StreamEncoder * flac;
-  FLAC__StreamMetadata * metadata[2];
-  unsigned num_metadata;
-} Encoder;
-
-
-
-assert_static(sizeof(Encoder) <= SOX_MAX_FILE_PRIVSIZE, /* else */ Encoder__PRIVSIZE_too_big);
-
-
-
 static FLAC__StreamEncoderWriteStatus flac_stream_encoder_write_callback(FLAC__StreamEncoder const * const flac, const FLAC__byte buffer[], size_t const bytes, unsigned const samples, unsigned const current_frame, void * const client_data)
 {
   sox_format_t * const ft = (sox_format_t *) client_data;
@@ -301,13 +276,12 @@
 
 static int start_write(sox_format_t * const ft)
 {
-  Encoder * encoder = (Encoder *) ft->priv;
   FLAC__StreamEncoderState status;
   unsigned compression_level = MAX_COMPRESSION; /* Default to "best" */
 
   if (ft->encoding.compression != HUGE_VAL) {
     compression_level = ft->encoding.compression;
-    if (compression_level != ft->encoding.compression || 
+    if (compression_level != ft->encoding.compression ||
         compression_level > MAX_COMPRESSION) {
       lsx_fail_errno(ft, SOX_EINVAL,
                  "FLAC compression level must be a whole number from 0 to %i",
@@ -316,21 +290,20 @@
     }
   }
 
-  memset(encoder, 0, sizeof(*encoder));
-  encoder->flac = FLAC__stream_encoder_new();
-  if (encoder->flac == NULL) {
+  p->encoder = FLAC__stream_encoder_new();
+  if (p->encoder == NULL) {
     lsx_fail_errno(ft, SOX_ENOMEM, "FLAC ERROR creating the encoder instance");
     return SOX_EOF;
   }
-  encoder->decoded_samples = lsx_malloc(sox_globals.bufsiz * sizeof(FLAC__int32));
+  p->decoded_samples = lsx_malloc(sox_globals.bufsiz * sizeof(FLAC__int32));
 
-  encoder->bits_per_sample = ft->encoding.bits_per_sample;
+  p->bits_per_sample = ft->encoding.bits_per_sample;
 
-  sox_report("encoding at %i bits per sample", encoder->bits_per_sample);
+  sox_report("encoding at %i bits per sample", p->bits_per_sample);
 
-  FLAC__stream_encoder_set_channels(encoder->flac, ft->signal.channels);
-  FLAC__stream_encoder_set_bits_per_sample(encoder->flac, encoder->bits_per_sample);
-  FLAC__stream_encoder_set_sample_rate(encoder->flac, (unsigned)(ft->signal.rate + .5));
+  FLAC__stream_encoder_set_channels(p->encoder, ft->signal.channels);
+  FLAC__stream_encoder_set_bits_per_sample(p->encoder, p->bits_per_sample);
+  FLAC__stream_encoder_set_sample_rate(p->encoder, (unsigned)(ft->signal.rate + .5));
 
   { /* Check if rate is streamable: */
     static const unsigned streamable_rates[] =
@@ -341,12 +314,12 @@
        streamable = (streamable_rates[i] == ft->signal.rate);
     if (!streamable) {
       sox_report("non-standard rate; output may not be streamable");
-      FLAC__stream_encoder_set_streamable_subset(encoder->flac, sox_false);
+      FLAC__stream_encoder_set_streamable_subset(p->encoder, sox_false);
     }
   }
 
 #if FLAC_API_VERSION_CURRENT >= 10
-  FLAC__stream_encoder_set_compression_level(encoder->flac, compression_level);
+  FLAC__stream_encoder_set_compression_level(p->encoder, compression_level);
 #else
   {
     static struct {
@@ -370,7 +343,7 @@
     };
 #define SET_OPTION(x) do {\
   sox_report(#x" = %i", options[compression_level].x); \
-  FLAC__stream_encoder_set_##x(encoder->flac, options[compression_level].x);\
+  FLAC__stream_encoder_set_##x(p->encoder, options[compression_level].x);\
 } while (0)
     SET_OPTION(blocksize);
     SET_OPTION(do_exhaustive_model_search);
@@ -385,59 +358,59 @@
   }
 #endif
 
-  if (ft->length != 0) {
-    FLAC__stream_encoder_set_total_samples_estimate(encoder->flac, (FLAC__uint64)(ft->length / ft->signal.channels));
+  if (ft->signal.length != 0) {
+    FLAC__stream_encoder_set_total_samples_estimate(p->encoder, (FLAC__uint64)(ft->signal.length / ft->signal.channels));
 
-    encoder->metadata[encoder->num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
-    if (encoder->metadata[encoder->num_metadata] == NULL) {
+    p->metadata[p->num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
+    if (p->metadata[p->num_metadata] == NULL) {
       lsx_fail_errno(ft, SOX_ENOMEM, "FLAC ERROR creating the encoder seek table template");
       return SOX_EOF;
     }
     {
 #if FLAC_API_VERSION_CURRENT >= 8
-      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))) {
+      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->length/ft->signal.channels;
-      if (!FLAC__metadata_object_seektable_template_append_spaced_points(encoder->metadata[encoder->num_metadata], total_samples / samples + (total_samples % samples != 0), (FLAC__uint64)total_samples)) {
+      sox_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");
         return SOX_EOF;
       }
     }
-    encoder->metadata[encoder->num_metadata]->is_last = sox_false; /* the encoder will set this for us */
-    ++encoder->num_metadata;
+    p->metadata[p->num_metadata]->is_last = sox_false; /* the encoder will set this for us */
+    ++p->num_metadata;
   }
 
-  if (ft->comments) {     /* Make the comment structure */
+  if (ft->oob.comments) {     /* Make the comment structure */
     FLAC__StreamMetadata_VorbisComment_Entry entry;
     int i;
 
-    encoder->metadata[encoder->num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
-    for (i = 0; ft->comments[i]; ++i) {
+    p->metadata[p->num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
+    for (i = 0; ft->oob.comments[i]; ++i) {
       static const char prepend[] = "Comment=";
-      char * text = lsx_calloc(strlen(prepend) + strlen(ft->comments[i]) + 1, sizeof(*text));
+      char * text = lsx_calloc(strlen(prepend) + strlen(ft->oob.comments[i]) + 1, sizeof(*text));
       /* Prepend `Comment=' if no field-name already in the comment */
-      if (!strchr(ft->comments[i], '='))
+      if (!strchr(ft->oob.comments[i], '='))
         strcpy(text, prepend);
-      entry.entry = (FLAC__byte *) strcat(text, ft->comments[i]);
+      entry.entry = (FLAC__byte *) strcat(text, ft->oob.comments[i]);
       entry.length = strlen(text);
-      FLAC__metadata_object_vorbiscomment_append_comment(encoder->metadata[encoder->num_metadata], entry, /*copy= */ sox_true);
+      FLAC__metadata_object_vorbiscomment_append_comment(p->metadata[p->num_metadata], entry, /*copy= */ sox_true);
       free(text);
     }
-    ++encoder->num_metadata;
+    ++p->num_metadata;
   }
 
-  if (encoder->num_metadata)
-    FLAC__stream_encoder_set_metadata(encoder->flac, encoder->metadata, encoder->num_metadata);
+  if (p->num_metadata)
+    FLAC__stream_encoder_set_metadata(p->encoder, p->metadata, p->num_metadata);
 
 #if FLAC_API_VERSION_CURRENT <= 7
-  FLAC__stream_encoder_set_write_callback(encoder->flac, flac_stream_encoder_write_callback);
-  FLAC__stream_encoder_set_metadata_callback(encoder->flac, flac_stream_encoder_metadata_callback);
-  FLAC__stream_encoder_set_client_data(encoder->flac, ft);
-  status = FLAC__stream_encoder_init(encoder->flac);
+  FLAC__stream_encoder_set_write_callback(p->encoder, flac_stream_encoder_write_callback);
+  FLAC__stream_encoder_set_metadata_callback(p->encoder, flac_stream_encoder_metadata_callback);
+  FLAC__stream_encoder_set_client_data(p->encoder, ft);
+  status = FLAC__stream_encoder_init(p->encoder);
 #else
-  status = FLAC__stream_encoder_init_stream(encoder->flac, flac_stream_encoder_write_callback,
+  status = FLAC__stream_encoder_init_stream(p->encoder, flac_stream_encoder_write_callback,
       flac_stream_encoder_seek_callback, flac_stream_encoder_tell_callback, flac_stream_encoder_metadata_callback, ft);
 #endif
 
@@ -452,30 +425,29 @@
 
 static sox_size_t write_samples(sox_format_t * const ft, sox_sample_t const * const sampleBuffer, sox_size_t const len)
 {
-  Encoder * encoder = (Encoder *) ft->priv;
   unsigned i;
 
   for (i = 0; i < len; ++i) {
     long pcm = SOX_SAMPLE_TO_SIGNED_32BIT(sampleBuffer[i], ft->clips);
-    encoder->decoded_samples[i] = pcm >> (32 - encoder->bits_per_sample);
-    switch (encoder->bits_per_sample) {
-      case  8: encoder->decoded_samples[i] =
+    p->decoded_samples[i] = pcm >> (32 - p->bits_per_sample);
+    switch (p->bits_per_sample) {
+      case  8: p->decoded_samples[i] =
           SOX_SAMPLE_TO_SIGNED_8BIT(sampleBuffer[i], ft->clips);
         break;
-      case 16: encoder->decoded_samples[i] =
+      case 16: p->decoded_samples[i] =
           SOX_SAMPLE_TO_SIGNED_16BIT(sampleBuffer[i], ft->clips);
         break;
-      case 24: encoder->decoded_samples[i] = /* sign extension: */
+      case 24: p->decoded_samples[i] = /* sign extension: */
           SOX_SAMPLE_TO_SIGNED_24BIT(sampleBuffer[i],ft->clips) << 8;
-        encoder->decoded_samples[i] >>= 8;
+        p->decoded_samples[i] >>= 8;
         break;
-      case 32: encoder->decoded_samples[i] =
+      case 32: p->decoded_samples[i] =
           SOX_SAMPLE_TO_SIGNED_32BIT(sampleBuffer[i],ft->clips);
         break;
     }
   }
-  FLAC__stream_encoder_process_interleaved(encoder->flac, encoder->decoded_samples, len / ft->signal.channels);
-  return FLAC__stream_encoder_get_state(encoder->flac) == FLAC__STREAM_ENCODER_OK ? len : 0;
+  FLAC__stream_encoder_process_interleaved(p->encoder, p->decoded_samples, len / ft->signal.channels);
+  return FLAC__stream_encoder_get_state(p->encoder) == FLAC__STREAM_ENCODER_OK ? len : 0;
 }
 
 
@@ -482,15 +454,14 @@
 
 static int stop_write(sox_format_t * const ft)
 {
-  Encoder * encoder = (Encoder *) ft->priv;
-  FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder->flac);
+  FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(p->encoder);
   unsigned i;
 
-  FLAC__stream_encoder_finish(encoder->flac);
-  FLAC__stream_encoder_delete(encoder->flac);
-  for (i = 0; i < encoder->num_metadata; ++i)
-    FLAC__metadata_object_delete(encoder->metadata[i]);
-  free(encoder->decoded_samples);
+  FLAC__stream_encoder_finish(p->encoder);
+  FLAC__stream_encoder_delete(p->encoder);
+  for (i = 0; i < p->num_metadata; ++i)
+    FLAC__metadata_object_delete(p->metadata[i]);
+  free(p->decoded_samples);
   if (state != FLAC__STREAM_ENCODER_OK) {
     lsx_fail_errno(ft, SOX_EINVAL, "FLAC ERROR: failed to encode to end of stream");
     return SOX_EOF;
@@ -506,10 +477,8 @@
  */
 static int seek(sox_format_t * ft, sox_size_t offset)
 {
-  Decoder * decoder = (Decoder *) ft->priv;
-
-  int result = ft->mode == 'r' && FLAC__stream_decoder_seek_absolute(decoder->flac, (FLAC__uint64)(offset / ft->signal.channels)) ?  SOX_SUCCESS : SOX_EOF;
-  decoder->wide_sample_number = decoder->number_of_wide_samples = 0;
+  int result = ft->mode == 'r' && FLAC__stream_decoder_seek_absolute(p->decoder, (FLAC__uint64)(offset / ft->signal.channels)) ?  SOX_SUCCESS : SOX_EOF;
+  p->wide_sample_number = p->number_of_wide_samples = 0;
   return result;
 }
 
@@ -518,13 +487,11 @@
 {
   static char const * const names[] = {"flac", NULL};
   static unsigned const encodings[] = {SOX_ENCODING_FLAC, 8, 16, 24, 0, 0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
-    "Free Lossless Audio CODEC compressed audio",
-    names, 0,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
+    "Free Lossless Audio CODEC compressed audio", names, 0,
     start_read, read_samples, stop_read,
     start_write, write_samples, stop_write,
-    seek, encodings, NULL
+    seek, encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/flanger.c
+++ b/src/flanger.c
@@ -1,4 +1,5 @@
-/*
+/* libSoX effect: Stereo Flanger   (c) 2006 robs@users.sourceforge.net
+ *
  * 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
@@ -14,8 +15,6 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-/* Effect: Stereo Flanger   (c) 2006 robs@users.sourceforge.net */
-
 #define sox_flanger_usage \
   "[delay depth regen width speed shape phase interp]\n"
 /*
@@ -54,7 +53,6 @@
 
 
 #include "sox_i.h"
-#include <math.h>
 #include <string.h>
 
 
@@ -65,7 +63,7 @@
 
 
 
-typedef struct flanger {
+typedef struct {
   /* Parameters */
   double     delay_min;
   double     delay_depth;
@@ -75,27 +73,24 @@
   lsx_wave_t  wave_shape;
   double     channel_phase;
   interp_t   interpolation;
-            
+
   /* Delay buffers */
   double *   delay_bufs[MAX_CHANNELS];
   sox_size_t  delay_buf_length;
   sox_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;
-            
+
   /* Balancing */
   double     in_gain;
-} * flanger_t;
+} priv_t;
 
-assert_static(sizeof(struct flanger) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ flanger_PRIVSIZE_too_big);
 
 
-
 static enum_item const interp_enum[] = {
   ENUM_ITEM(INTERP_,LINEAR)
   ENUM_ITEM(INTERP_,QUADRATIC)
@@ -105,7 +100,7 @@
 
 static int sox_flanger_getopts(sox_effect_t * effp, int argc, char *argv[])
 {
-  flanger_t p = (flanger_t) effp->priv;
+  priv_t * p = (priv_t *) effp->priv;
 
   /* Set non-zero defaults: */
   p->delay_depth  = 2;
@@ -152,7 +147,7 @@
 
 static int sox_flanger_start(sox_effect_t * effp)
 {
-  flanger_t f = (flanger_t) effp->priv;
+  priv_t * f = (priv_t *) effp->priv;
   int c, channels = effp->in_signal.channels;
 
   if (channels > MAX_CHANNELS) {
@@ -206,7 +201,7 @@
 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)
 {
-  flanger_t f = (flanger_t) effp->priv;
+  priv_t * f = (priv_t *) effp->priv;
   int c, channels = effp->in_signal.channels;
   sox_size_t len = (*isamp > *osamp ? *osamp : *isamp) / channels;
 
@@ -260,7 +255,7 @@
 
 static int sox_flanger_stop(sox_effect_t * effp)
 {
-  flanger_t f = (flanger_t) effp->priv;
+  priv_t * f = (priv_t *) effp->priv;
   int c, channels = effp->in_signal.channels;
 
   for (c = 0; c < channels; ++c)
@@ -284,7 +279,7 @@
   sox_flanger_flow,
   NULL,
   sox_flanger_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 
--- a/src/formats.c
+++ b/src/formats.c
@@ -1,5 +1,4 @@
-/*
- * Implements the public API for using libSoX file formats.
+/* Implements the public API for using libSoX file formats.
  * All public functions & data are prefixed with sox_ .
  *
  * (c) 2005-8 Chris Bagwell and SoX contributors
@@ -25,7 +24,6 @@
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
@@ -367,23 +365,23 @@
   return *text == ':';
 }
 
-static FILE * xfopen(char const * identifier, char const * mode) 
-{ 
+static FILE * xfopen(char const * identifier, char const * mode)
+{
   if (is_uri(identifier)) {
     FILE * f = NULL;
 #ifdef HAVE_POPEN
     char const * const command_format = "wget --no-check-certificate -q -O- \"%s\"";
-    char * command = lsx_malloc(strlen(command_format) + strlen(identifier)); 
-    sprintf(command, command_format, identifier); 
-    f = popen(command, "r"); 
+    char * command = lsx_malloc(strlen(command_format) + strlen(identifier));
+    sprintf(command, command_format, identifier);
+    f = popen(command, "r");
     free(command);
 #else
     sox_fail("open URL support has not been built into SoX");
-#endif 
+#endif
     return f;
   }
   return fopen(identifier, mode);
-} 
+}
 
 sox_format_t * sox_open_read(
     char               const * path,
@@ -451,20 +449,19 @@
     sox_fail("file type `%s' isn't readable", filetype);
     goto error;
   }
-  
+
   ft->mode = 'r';
-  
+  ft->filetype = lsx_strdup(filetype);
+  ft->filename = lsx_strdup(path);
   if (signal)
     ft->signal = *signal;
-  
+
   if (encoding)
     ft->encoding = *encoding;
   else sox_init_encodinginfo(&ft->encoding);
   set_endiannesses(ft);
 
-  ft->filetype = lsx_strdup(filetype);
-  ft->filename = lsx_strdup(path);
-
+  ft->priv = lsx_calloc(1, ft->handler.priv_size);
   /* Read and write starters can change their formats. */
   if (ft->handler.startread && (*ft->handler.startread)(ft) != SOX_SUCCESS) {
     sox_fail("can't open input file `%s': %s", ft->filename, ft->sox_errstr);
@@ -484,6 +481,7 @@
 error:
   if (ft->fp && ft->fp != stdin)
     fclose(ft->fp);
+  free(ft->priv);
   free(ft->filename);
   free(ft->filetype);
   free(ft);
@@ -674,19 +672,15 @@
 }
 
 sox_format_t * sox_open_write(
-    sox_bool (*overwrite_permitted)(const char *filename),
     char               const * path,
     sox_signalinfo_t   const * signal,
     sox_encodinginfo_t const * encoding,
     char               const * filetype,
-    sox_comments_t                 comments,
-    sox_size_t                 length,
-    sox_instrinfo_t    const * instr,
-    sox_loopinfo_t     const * loops)
+    sox_oob_t    const * oob,
+    sox_bool           (*overwrite_permitted)(const char *filename))
 {
   sox_format_t * ft = lsx_calloc(sizeof(*ft), 1);
   sox_format_handler_t const * handler;
-  int i;
 
   if (!path || !signal) {
     sox_fail("must specify file name and signal parameters to write file");
@@ -748,39 +742,34 @@
     ft->seekable = is_seekable(ft);
   }
 
+  ft->filetype = lsx_strdup(filetype);
+  ft->filename = lsx_strdup(path);
   ft->mode = 'w';
-
   ft->signal = *signal;
-  
+
   if (encoding)
     ft->encoding = *encoding;
   else sox_init_encodinginfo(&ft->encoding);
   set_endiannesses(ft);
 
-  ft->filetype = lsx_strdup(filetype);
-  ft->filename = lsx_strdup(path);
+  if (oob) {
+    ft->oob = *oob;
+    /* deep copy: */
+    ft->oob.comments = sox_copy_comments(oob->comments);
+  }
 
-  ft->comments = sox_copy_comments(comments);
-
-  if (loops) for (i = 0; i < SOX_MAX_NLOOPS; i++)
-    ft->loops[i] = loops[i];
-
-  /* leave SMPTE # alone since it's absolute */
-  if (instr)
-    ft->instr = *instr;
-
-  ft->length = length;
   set_output_format(ft);
 
   /* FIXME: doesn't cover the situation where
    * codec changes audio length due to block alignment (e.g. 8svx, gsm): */
   if (signal->rate && signal->channels)
-    ft->length = ft->length * ft->signal.rate / signal->rate *
+    ft->signal.length = ft->signal.length * ft->signal.rate / signal->rate *
       ft->signal.channels / signal->channels + .5;
 
-  if ((ft->handler.flags & SOX_FILE_REWIND) && !ft->length && !ft->seekable)
+  if ((ft->handler.flags & SOX_FILE_REWIND) && !ft->signal.length && !ft->seekable)
     sox_warn("can't seek in output file `%s'; length in file header will be unspecified", ft->filename);
 
+  ft->priv = lsx_calloc(1, ft->handler.priv_size);
   /* Read and write starters can change their formats. */
   if (ft->handler.startwrite && (ft->handler.startwrite)(ft) != SOX_SUCCESS){
     sox_fail("can't open output file `%s': %s", ft->filename, ft->sox_errstr);
@@ -794,6 +783,7 @@
 error:
   if (ft->fp && ft->fp != stdout)
     fclose(ft->fp);
+  free(ft->priv);
   free(ft->filename);
   free(ft->filetype);
   free(ft);
@@ -822,7 +812,7 @@
     rc = ft->handler.stopread? (*ft->handler.stopread)(ft) : SOX_SUCCESS;
   else {
     if (ft->handler.flags & SOX_FILE_REWIND) {
-      if (ft->olength != ft->length && ft->seekable) {
+      if (ft->olength != ft->signal.length && ft->seekable) {
         rc = lsx_seeki(ft, 0, 0);
         if (rc == SOX_SUCCESS)
           rc = ft->handler.stopwrite? (*ft->handler.stopwrite)(ft)
@@ -836,7 +826,7 @@
     fclose(ft->fp);
   free(ft->filename);
   free(ft->filetype);
-  sox_delete_comments(&ft->comments);
+  sox_delete_comments(&ft->oob.comments);
 
   free(ft);
   return rc;
@@ -924,8 +914,8 @@
       if (!dirname[0] || is_uri(id) || IS_ABSOLUTE(id))
         filename = lsx_strdup(id);
       else {
-        filename = lsx_malloc(strlen(dirname) + strlen(id) + 2); 
-        sprintf(filename, "%s/%s", dirname, id); 
+        filename = lsx_malloc(strlen(dirname) + strlen(id) + 2);
+        sprintf(filename, "%s/%s", dirname, id);
       }
       if (sox_is_playlist(filename))
         sox_parse_playlist(callback, p, filename);
@@ -1016,7 +1006,7 @@
 int sox_format_init(void) {return SOX_SUCCESS;}
 void sox_format_quit(void) {}
 
-#endif 
+#endif
 
 /* Find a named format in the formats library.
  *
--- a/src/formats.h
+++ b/src/formats.h
@@ -1,5 +1,4 @@
-/*
- * This library is free software; you can redistribute it and/or modify it
+/* 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.
--- a/src/formats_i.c
+++ b/src/formats_i.c
@@ -1,5 +1,4 @@
-/*
- * Implements a libSoX internal interface for use in implementing file formats.
+/* Implements a libSoX internal interface for use in implementing file formats.
  * All public functions & data are prefixed with lsx_ .
  *
  * (c) 2005-8 Chris Bagwell and SoX contributors
@@ -50,7 +49,7 @@
 int lsx_check_read_params(sox_format_t * ft, unsigned channels,
     sox_rate_t rate, sox_encoding_t encoding, unsigned bits_per_sample, off_t length)
 {
-  ft->length = length;
+  ft->signal.length = length;
 
   if (ft->seekable)
     ft->data_start = lsx_tell(ft);
@@ -73,8 +72,8 @@
 
   if (ft->encoding.bits_per_sample && lsx_filelength(ft)) {
     off_t calculated_length = div_bits(lsx_filelength(ft) - ft->data_start, ft->encoding.bits_per_sample);
-    if (!ft->length)
-      ft->length = calculated_length;
+    if (!ft->signal.length)
+      ft->signal.length = calculated_length;
     else if (length != calculated_length)
       sox_warn("`%s': file header gives the total number of samples as %u but file length indicates the number is in fact %u", ft->filename, (unsigned)length, (unsigned)calculated_length); /* FIXME: casts */
   }
@@ -113,7 +112,7 @@
   while (n--)
     if (lsx_readb(ft, &trash) == SOX_EOF)
       return (SOX_EOF);
-  
+
   return (SOX_SUCCESS);
 }
 
@@ -292,24 +291,24 @@
 /* Lookup table to reverse the bit order of a byte. ie MSB become LSB */
 static uint8_t const cswap[256] = {
   0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0,
-  0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 
-  0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4, 
+  0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
+  0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4,
   0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
   0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC,
-  0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 
-  0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA, 
-  0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
+  0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
+  0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA,
+  0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
   0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6,
-  0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 
-  0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1, 
+  0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
+  0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1,
   0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
   0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9,
-  0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 
-  0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD, 
+  0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
+  0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD,
   0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
   0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3,
-  0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 
-  0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7, 
+  0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
+  0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7,
   0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
   0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF,
   0x3F, 0xBF, 0x7F, 0xFF
--- a/src/g711.c
+++ b/src/g711.c
@@ -1,4 +1,4 @@
-/* g711.c - G711 u-law, A-law and linear PCM conversions.
+/* libSoX G711.c - G711 u-law, A-law and linear PCM conversions.
  *
  * Copyright (C) 2001 Chris Bagwell
  *
--- a/src/g711.h
+++ b/src/g711.h
@@ -1,4 +1,4 @@
-/* g711.h - include for G711 u-law and a-law conversion routines
+/* libSoX G711.h - include for G711 u-law and a-law conversion routines
  *
  * Copyright (C) 2001 Chris Bagwell
  *
--- a/src/g721.c
+++ b/src/g721.c
@@ -1,5 +1,4 @@
-/*
- * This source code is a product of Sun Microsystems, Inc. and is provided
+/* This source code is a product of Sun Microsystems, Inc. and is provided
  * for unrestricted use.  Users may copy or modify this source code without
  * charge.
  *
--- a/src/g723_24.c
+++ b/src/g723_24.c
@@ -1,5 +1,4 @@
-/*
- * This source code is a product of Sun Microsystems, Inc. and is provided
+/* This source code is a product of Sun Microsystems, Inc. and is provided
  * for unrestricted use.  Users may copy or modify this source code without
  * charge.
  *
--- a/src/g723_40.c
+++ b/src/g723_40.c
@@ -1,5 +1,4 @@
-/*
- * This source code is a product of Sun Microsystems, Inc. and is provided
+/* This source code is a product of Sun Microsystems, Inc. and is provided
  * for unrestricted use.  Users may copy or modify this source code without
  * charge.
  *
--- a/src/g72x.c
+++ b/src/g72x.c
@@ -1,5 +1,4 @@
-/*
- * Common routines for G.721 and G.723 conversions.
+/* Common routines for G.721 and G.723 conversions.
  *
  * (c) SoX Contributors
  *
@@ -17,7 +16,7 @@
  * along with this library; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * 
+ *
  * This code is based on code from Sun, which came with the following
  * copyright notice:
  * -----------------------------------------------------------------------
@@ -89,7 +88,7 @@
 
         return r + 1;
 }
-  
+
 /*
  * quan()
  *
@@ -294,7 +293,7 @@
  *
  * updates the state variables for each output code
  */
-void update(int code_size, int y, int wi, int fi, int dq, int sr, 
+void update(int code_size, int y, int wi, int fi, int dq, int sr,
             int dqsez, struct g72x_state *state_ptr)
 {
         int             cnt;
--- a/src/g72x.h
+++ b/src/g72x.h
@@ -1,5 +1,4 @@
-/*
- * This source code is a product of Sun Microsystems, Inc. and is provided
+/* This source code is a product of Sun Microsystems, Inc. and is provided
  * for unrestricted use.  Users may copy or modify this source code without
  * charge.
  *
--- a/src/getopt.h
+++ b/src/getopt.h
@@ -1,10 +1,10 @@
-#if defined __GNUC__ 
-  #pragma GCC system_header 
-#elif defined __SUNPRO_CC 
-  #pragma disable_warn 
-#elif defined _MSC_VER 
-  #pragma warning(push, 1) 
-#endif 
+#if defined __GNUC__
+  #pragma GCC system_header
+#elif defined __SUNPRO_CC
+  #pragma disable_warn
+#elif defined _MSC_VER
+  #pragma warning(push, 1)
+#endif
 
 /* Declarations for getopt.
    Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc.
@@ -188,8 +188,8 @@
 
 #endif /* getopt.h */
 
-#if defined __SUNPRO_CC 
-  #pragma enable_warn 
-#elif defined _MSC_VER 
-  #pragma warning(pop) 
-#endif 
+#if defined __SUNPRO_CC
+  #pragma enable_warn
+#elif defined _MSC_VER
+  #pragma warning(pop)
+#endif
--- a/src/gsm.c
+++ b/src/gsm.c
@@ -1,8 +1,7 @@
-/*
- * Copyright 1991, 1992, 1993 Guido van Rossum And Sundry Contributors.
+/* Copyright 1991, 1992, 1993 Guido van Rossum And Sundry Contributors.
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Guido van Rossum And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Guido van Rossum And Sundry Contributors are not responsible for
  * the consequences of using this software.
  */
 
@@ -44,7 +43,7 @@
 #define BLOCKSIZE 160
 
 /* Private data */
-struct gsmpriv {
+typedef struct {
         unsigned        channels;
         gsm_signal      *samples;
         gsm_signal      *samplePtr;
@@ -51,13 +50,13 @@
         gsm_signal      *sampleTop;
         gsm_byte *frames;
         gsm             handle[MAXCHANS];
-};
+} priv_t;
 
-static int gsmstart_rw(sox_format_t * ft, int w) 
+static int gsmstart_rw(sox_format_t * ft, int w)
 {
-        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
         unsigned ch;
-        
+
         ft->encoding.encoding = SOX_ENCODING_GSM;
         if (!ft->signal.rate)
                 ft->signal.rate = 8000;
@@ -87,7 +86,7 @@
         return (SOX_SUCCESS);
 }
 
-static int sox_gsmstartread(sox_format_t * ft) 
+static int sox_gsmstartread(sox_format_t * ft)
 {
         return gsmstart_rw(ft,0);
 }
@@ -109,7 +108,7 @@
         size_t done = 0, r;
         int ch, chans;
         gsm_signal *gbuff;
-        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
 
         chans = p->channels;
 
@@ -116,7 +115,7 @@
         while (done < samp)
         {
                 while (p->samplePtr < p->sampleTop && done < samp)
-                        buf[done++] = 
+                        buf[done++] =
                             SOX_SIGNED_16BIT_TO_SAMPLE(*(p->samplePtr)++,);
 
                 if (done>=samp) break;
@@ -136,7 +135,7 @@
                                 lsx_fail_errno(ft,errno,"error during GSM decode");
                                 return (0);
                         }
-                        
+
                         gsp = p->samples + ch;
                         for (i=0; i<BLOCKSIZE; i++) {
                                 *gsp = *gbuff++;
@@ -152,7 +151,7 @@
 {
         int r, ch, chans;
         gsm_signal *gbuff;
-        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
 
         chans = p->channels;
 
@@ -159,7 +158,7 @@
         /* zero-fill samples as needed */
         while (p->samplePtr < p->sampleTop)
                 *(p->samplePtr)++ = 0;
-        
+
         gbuff = p->sampleTop;
         for (ch=0; ch<chans; ch++) {
                 int i;
@@ -186,12 +185,12 @@
 static sox_size_t sox_gsmwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t samp)
 {
         size_t done = 0;
-        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
 
         while (done < samp)
         {
                 while ((p->samplePtr < p->sampleTop) && (done < samp))
-                        *(p->samplePtr)++ = 
+                        *(p->samplePtr)++ =
                             SOX_SAMPLE_TO_SIGNED_16BIT(buf[done++], ft->clips);
 
                 if (p->samplePtr == p->sampleTop)
@@ -208,7 +207,7 @@
 
 static int sox_gsmstopread(sox_format_t * ft)
 {
-        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
         unsigned ch;
 
         for (ch=0; ch<p->channels; ch++)
@@ -222,7 +221,7 @@
 static int sox_gsmstopwrite(sox_format_t * ft)
 {
         int rc;
-        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
 
         if (p->samplePtr > p->samples)
         {
@@ -239,13 +238,11 @@
   static char const * const names[] = {"gsm", NULL};
   static sox_rate_t   const write_rates[] = {8000, 0};
   static unsigned const write_encodings[] = {SOX_ENCODING_GSM, 0, 0};
-  static sox_format_handler_t handler = {
-    SOX_LIB_VERSION_CODE,
-    "GSM 06.10 (full-rate) lossy speech compression",
-    names, 0,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
+    "GSM 06.10 (full-rate) lossy speech compression", names, 0,
     sox_gsmstartread, sox_gsmread, sox_gsmstopread,
     sox_gsmstartwrite, sox_gsmwrite, sox_gsmstopwrite,
-    NULL, write_encodings, write_rates
+    NULL, write_encodings, write_rates, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -1,5 +1,4 @@
-/*
- * libSoX Macintosh HCOM format.
+/* libSoX Macintosh HCOM format.
  * These are really FSSD type files with Huffman compression,
  * in MacBinary format.
  * TODO: make the MacBinary format optional (so that .data files
@@ -50,29 +49,33 @@
         short dict_rightson;
 } dictent;
 
-/* Private data used by reader */
-struct readpriv {
-        /* Static data from the header */
-        dictent *dictionary;
-        int32_t checksum;
-        int deltacompression;
-        /* Engine state */
-        long huffcount;
-        long cksum;
-        int dictentry;
-        int nrbits;
-        uint32_t current;
-        short sample;
-        /* Dictionary */
-        dictent *de;
-        int32_t new_checksum;
-        int nbits;
-        int32_t curword;
-};
+typedef struct {
+  /* Static data from the header */
+  dictent *dictionary;
+  int32_t checksum;
+  int deltacompression;
+  /* Engine state */
+  long huffcount;
+  long cksum;
+  int dictentry;
+  int nrbits;
+  uint32_t current;
+  short sample;
+  /* Dictionary */
+  dictent *de;
+  int32_t new_checksum;
+  int nbits;
+  int32_t curword;
 
+  /* 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 */
+} priv_t;
+
 static int startread(sox_format_t * ft)
 {
-        struct readpriv *p = (struct readpriv *) ft->priv;
+        priv_t *p = (priv_t *) ft->priv;
         int i;
         char buf[5];
         uint32_t datasize, rsrcsize;
@@ -167,7 +170,7 @@
 
 static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-        register struct readpriv *p = (struct readpriv *) ft->priv;
+        register priv_t *p = (priv_t *) ft->priv;
         int done = 0;
         unsigned char sample_rate;
 
@@ -230,7 +233,7 @@
 
 static int stopread(sox_format_t * ft)
 {
-        register struct readpriv *p = (struct readpriv *) ft->priv;
+        register priv_t *p = (priv_t *) ft->priv;
 
         if (p->huffcount != 0)
         {
@@ -247,17 +250,11 @@
         return (SOX_SUCCESS);
 }
 
-struct writepriv {
-  unsigned char *data;          /* Buffer allocated with lsx_malloc */
-  sox_size_t size;               /* Size of allocated buffer */
-  sox_size_t pos;                /* Where next byte goes */
-};
-
 #define BUFINCR (10*BUFSIZ)
 
 static int startwrite(sox_format_t * ft)
 {
-  struct writepriv * p = (struct writepriv *) ft->priv;
+  priv_t * p = (priv_t *) ft->priv;
 
   p->size = BUFINCR;
   p->pos = 0;
@@ -267,7 +264,7 @@
 
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-  struct writepriv *p = (struct writepriv *) ft->priv;
+  priv_t *p = (priv_t *) ft->priv;
   sox_sample_t datum;
   sox_size_t i;
 
@@ -301,7 +298,7 @@
 
 static void putcode(sox_format_t * ft, long codes[256], long codesize[256], unsigned c, unsigned char **df)
 {
-  struct readpriv *p = (struct readpriv *) ft->priv;
+  priv_t *p = (priv_t *) ft->priv;
   long code, size;
   int i;
 
@@ -324,7 +321,7 @@
 
 static void compress(sox_format_t * ft, unsigned char **df, int32_t *dl)
 {
-  struct readpriv *p = (struct readpriv *) ft->priv;
+  priv_t *p = (priv_t *) ft->priv;
   int samplerate;
   unsigned char *datafork = *df;
   unsigned char *ddf, *dfp;
@@ -339,7 +336,7 @@
   memset(codes, 0, sizeof(codes));
   memset(codesize, 0, sizeof(codesize));
   memset(newdict, 0, sizeof(newdict));
-  
+
   for (i = 1; i < *dl; i++) {
     d = (datafork[i] - (sample & 0xff)) & 0xff; /* creates absolute entries LMS */
     sample = datafork[i];
@@ -428,7 +425,7 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-  struct writepriv *p = (struct writepriv *) ft->priv;
+  priv_t *p = (priv_t *) ft->priv;
   unsigned char *compressed_data = p->data;
   sox_size_t compressed_len = p->pos;
   int rc = SOX_SUCCESS;
@@ -469,13 +466,12 @@
   static sox_rate_t   const write_rates[] = {22050,22050/2,22050/3,22050/4.,0};
   static unsigned     const write_encodings[] = {
     SOX_ENCODING_HCOM, 8, 0, 0};
-  static sox_format_handler_t handler   = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
     "Mac FSSD files with Huffman compression",
     names, SOX_FILE_BIG_END|SOX_FILE_MONO,
     startread, read_samples, stopread,
     startwrite, write_samples, stopwrite,
-    NULL, write_encodings, write_rates
+    NULL, write_encodings, write_rates, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/htk.c
+++ b/src/htk.c
@@ -1,5 +1,4 @@
-/*
- * File format: HTK   (c) 2008 robs@users.sourceforge.net
+/* libSoX file format: HTK   (c) 2008 robs@users.sourceforge.net
  *
  * See http://labrosa.ee.columbia.edu/doc/HTKBook21/HTKBook.html
  *
@@ -19,7 +18,6 @@
  */
 
 #include "sox_i.h"
-#include <math.h>
 
 typedef enum {
   Waveform, Lpc, Lprefc, Lpcepstra, Lpdelcep, Irefc,
@@ -54,7 +52,7 @@
 
   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->length)
+  return lsx_writedw(ft, ft->olength? ft->olength:ft->signal.length)
       || lsx_writedw(ft, (uint32_t)(period_100ns + .5))
       || lsx_writew(ft, ft->encoding.bits_per_sample >> 3)
       || lsx_writew(ft, Waveform) ? SOX_EOF : SOX_SUCCESS;
@@ -70,7 +68,7 @@
     names, SOX_FILE_BIG_END | SOX_FILE_MONO | SOX_FILE_REWIND,
     start_read, lsx_rawread, NULL,
     write_header, lsx_rawwrite, NULL,
-    lsx_rawseek, write_encodings, NULL
+    lsx_rawseek, write_encodings, NULL, 0
   };
   return &handler;
 }
--- a/src/ima-fmt.c
+++ b/src/ima-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File format: raw IMA ADPCM           (c) 2007-8 SoX contributors
+/* libSoX format: raw IMA ADPCM           (c) 2007-8 SoX contributors
  *
  * 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
@@ -17,6 +16,7 @@
  */
 
 #include "sox_i.h"
+#include "adpcms.h"
 #include "vox.h"
 
 SOX_FORMAT_HANDLER(ima)
@@ -23,13 +23,11 @@
 {
   static char const * const names[] = {"ima", NULL};
   static unsigned const write_encodings[] = {SOX_ENCODING_IMA_ADPCM, 4, 0, 0};
-  static sox_format_handler_t handler = {
-    SOX_LIB_VERSION_CODE,
-    "Raw IMA ADPCM",
-    names, SOX_FILE_MONO,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
+    "Raw IMA ADPCM", names, SOX_FILE_MONO,
     sox_ima_start, sox_vox_read, sox_vox_stopread,
     sox_ima_start, sox_vox_write, sox_vox_stopwrite,
-    lsx_rawseek, write_encodings, NULL
+    lsx_rawseek, write_encodings, NULL, sizeof(adpcm_io_t)
   };
   return &handler;
 }
--- a/src/ima_rw.c
+++ b/src/ima_rw.c
@@ -1,8 +1,6 @@
-/*
-        ima_rw.c -- codex utilities for WAV_FORMAT_IMA_ADPCM
-         
-        Copyright (C) 1999 Stanley J. Brooks <stabro@megsinet.net> 
-
+/* libSoX ima_rw.c -- codex utilities for WAV_FORMAT_IMA_ADPCM
+ * Copyright (C) 1999 Stanley J. Brooks <stabro@megsinet.net>
+ *
  * 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
@@ -23,7 +21,6 @@
 #include "ima_rw.h"
 
 #include <sys/types.h>
-#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 /*
@@ -102,7 +99,7 @@
                 } else {
                         cm = (*ip++)>>4;
                         if ((i&7) == 0)  /* ends the 8-sample input block for this channel */
-                                ip += i_inc;   /* skip ip for next group */ 
+                                ip += i_inc;   /* skip ip for next group */
                 }
 
                 step = imaStepSizeTable[state];
@@ -179,7 +176,7 @@
         itop = ibuff + n*chans;
         val = *ip - v0; ip += chans;/* 1st input sample for this channel */
         d2 = val*val;/* d2 will be sum of squares of errors, given input v0 and *st */
-        val = v0;       
+        val = v0;
 
         op = obuff;            /* output pointer (or NULL) */
         if (op) {              /* NULL means don't output, just compute the rms error */
@@ -209,7 +206,7 @@
                         if (i&1) {       /* odd numbered output */
                                 *op++ |= (cm<<4);
                                 if (i == 7)    /* ends the 8-sample output block for this channel */
-                                        op += o_inc; /* skip op for next group */ 
+                                        op += o_inc; /* skip op for next group */
                         } else {
                                 *op = cm;
                         }
--- a/src/ima_rw.h
+++ b/src/ima_rw.h
@@ -1,8 +1,6 @@
-/*
-	ima_rw.h -- codex utilities for WAV_FORMAT_IMA_ADPCM
-	 
-	Copyright (C) 1999 Stanley J. Brooks <stabro@megsinet.net> 
-
+/* libSoX ima_rw.h -- codex utilities for WAV_FORMAT_IMA_ADPCM
+ * Copyright (C) 1999 Stanley J. Brooks <stabro@megsinet.net>
+ *
  * 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
@@ -16,7 +14,7 @@
  * 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
- 
+
 */
 
 #include "sox.h"
--- a/src/key.c
+++ b/src/key.c
@@ -1,6 +1,4 @@
-/*
- * Effect: change the audio key (i.e. change pitch but not tempo)
- *
+/* libSoX effect: change the audio key (i.e. change pitch but not tempo)
  * Copyright (c) 2007 robs@users.sourceforge.net
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -24,7 +22,6 @@
  */
 
 #include "sox_i.h"
-#include <math.h>
 #include <string.h>
 
 static int getopts(sox_effect_t * effp, int argc, char **argv)
--- a/src/la-fmt.c
+++ b/src/la-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/ladspa.c
+++ b/src/ladspa.c
@@ -1,5 +1,4 @@
-/*
- * LADSPA effect support for sox
+/* LADSPA effect support for sox
  * (c) Reuben Thomas <rrt@sc3d.org> 2007
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -24,7 +23,6 @@
 #include <assert.h>
 #include <limits.h>
 #include <string.h>
-#include <math.h>
 #include <ltdl.h>
 #include <ladspa.h>
 
@@ -38,12 +36,12 @@
   LADSPA_Handle handle;         /* instantiated plugin handle */
   LADSPA_Data *control;         /* control ports */
   unsigned long input_port, output_port;
-} *ladspa_t;
+} priv_t;
 
 static LADSPA_Data ladspa_default(const LADSPA_PortRangeHint *p)
 {
   LADSPA_Data d;
-  
+
   if (LADSPA_IS_HINT_DEFAULT_0(p->HintDescriptor))
     d = 0.0;
   else if (LADSPA_IS_HINT_DEFAULT_1(p->HintDescriptor))
@@ -85,7 +83,7 @@
  */
 static int sox_ladspa_getopts(sox_effect_t *effp, int n, char **argv)
 {
-  ladspa_t l_st = (ladspa_t)effp->priv;
+  priv_t * l_st = (priv_t *)effp->priv;
   char *path;
   union {LADSPA_Descriptor_Function fn; lt_ptr ptr;} ltptr;
   unsigned long index = 0, i;
@@ -152,7 +150,7 @@
       sox_fail("port %lu is both audio and control", i);
       return SOX_EOF;
     }
-               
+
     if (LADSPA_IS_PORT_AUDIO(port)) {
       if (LADSPA_IS_PORT_INPUT(port)) {
         if (l_st->input_port != ULONG_MAX) {
@@ -194,7 +192,7 @@
  */
 static int sox_ladspa_start(sox_effect_t * effp)
 {
-  ladspa_t l_st = (ladspa_t)effp->priv;
+  priv_t * l_st = (priv_t *)effp->priv;
   unsigned long i;
 
   /* Instantiate the plugin */
@@ -225,7 +223,7 @@
 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)
 {
-  ladspa_t l_st = (ladspa_t)effp->priv;
+  priv_t * l_st = (priv_t *)effp->priv;
   sox_size_t i, len = min(*isamp, *osamp);
 
   *osamp = *isamp = len;
@@ -232,24 +230,24 @@
 
   if (len) {
     LADSPA_Data *buf = lsx_malloc(sizeof(LADSPA_Data) * len);
-    
+
     /* Insert input if effect takes it */
     if (l_st->input_port != ULONG_MAX) {
       /* Copy the input; FIXME: Assume LADSPA_Data == float! */
       for (i = 0; i < len; i++)
         buf[i] = SOX_SAMPLE_TO_FLOAT_32BIT(ibuf[i], effp->clips);
-      
+
       /* Connect the input port */
       l_st->desc->connect_port(l_st->handle, l_st->input_port, buf);
     }
-    
+
     /* Connect the output port if used */
     if (l_st->output_port != ULONG_MAX)
       l_st->desc->connect_port(l_st->handle, l_st->output_port, buf);
-    
+
     /* Run the plugin */
     l_st->desc->run(l_st->handle, len);
-    
+
     /* Grab output if effect produces it */
     if (l_st->output_port != ULONG_MAX)
       /* FIXME: Assume LADSPA_Data == float! */
@@ -256,7 +254,7 @@
       for (i = 0; i < len; i++) {
         obuf[i] = SOX_FLOAT_32BIT_TO_SAMPLE(buf[i], effp->clips);
       }
-    
+
     free(buf);
   }
 
@@ -279,7 +277,7 @@
  */
 static int sox_ladspa_stop(sox_effect_t * effp)
 {
-  ladspa_t l_st = (ladspa_t)effp->priv;
+  priv_t * l_st = (priv_t *)effp->priv;
 
   /* If needed, deactivate the plugin */
   if (l_st->desc->deactivate)
@@ -297,7 +295,7 @@
   sox_ladspa_flow,
   sox_ladspa_drain,
   sox_ladspa_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_ladspa_effect_fn(void)
--- a/src/libsox.c
+++ b/src/libsox.c
@@ -1,5 +1,4 @@
-/*
- * Implements the public API for libSoX general functions
+/* Implements the public API for libSoX general functions
  * All public functions & data are prefixed with sox_ .
  *
  * (c) 2006-8 Chris Bagwell and SoX contributors
--- a/src/libsox_i.c
+++ b/src/libsox_i.c
@@ -1,5 +1,4 @@
-/*
- * libSoX internal functions that apply to both formats and effects
+/* libSoX internal functions that apply to both formats and effects
  * All public functions & data are prefixed with lsx_ .
  *
  * Copyright 1998-2008 Chris Bagwell and SoX Contributors
--- a/src/lpc10.c
+++ b/src/lpc10.c
@@ -1,5 +1,4 @@
-/*
- * libSoX lpc-10 format.
+/* libSoX lpc-10 format.
  *
  * Copyright 2007 Reuben Thomas <rrt@sc3d.org>
  *
@@ -22,12 +21,12 @@
 #include "../lpc10/lpc10.h"
 
 /* Private data */
-typedef struct lpcpriv {
+typedef struct {
   struct lpc10_encoder_state *encst;
   float speech[LPC10_SAMPLES_PER_FRAME];
   unsigned samples;
   struct lpc10_decoder_state *decst;
-} *lpcpriv_t;
+} priv_t;
 
 /*
   Write the bits in bits[0] through bits[len-1] to file f, in "packed"
@@ -120,7 +119,7 @@
 
 static int startread(sox_format_t * ft)
 {
-  lpcpriv_t lpc = (lpcpriv_t)ft->priv;
+  priv_t * lpc = (priv_t *)ft->priv;
 
   if ((lpc->decst = create_lpc10_decoder_state()) == NULL) {
     fprintf(stderr, "lpc10 could not allocate decoder state");
@@ -130,9 +129,9 @@
   return lsx_check_read_params(ft, 1, 8000., SOX_ENCODING_LPC10, 0, (off_t)0);
 }
 
-static int startwrite(sox_format_t * ft) 
+static int startwrite(sox_format_t * ft)
 {
-  lpcpriv_t lpc = (lpcpriv_t)ft->priv;
+  priv_t * lpc = (priv_t *)ft->priv;
 
   if ((lpc->encst = create_lpc10_encoder_state()) == NULL) {
     fprintf(stderr, "lpc10 could not allocate encoder state");
@@ -145,7 +144,7 @@
 
 static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-  lpcpriv_t lpc = (lpcpriv_t)ft->priv;
+  priv_t * lpc = (priv_t *)ft->priv;
   sox_size_t nread = 0;
 
   while (nread < len) {
@@ -169,7 +168,7 @@
 
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-  lpcpriv_t lpc = (lpcpriv_t)ft->priv;
+  priv_t * lpc = (priv_t *)ft->priv;
   sox_size_t nwritten = 0;
 
   while (len > 0) {
@@ -192,7 +191,7 @@
 
 static int stopread(sox_format_t * ft)
 {
-  lpcpriv_t lpc = (lpcpriv_t)ft->priv;
+  priv_t * lpc = (priv_t *)ft->priv;
 
   free(lpc->decst);
 
@@ -201,7 +200,7 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-  lpcpriv_t lpc = (lpcpriv_t)ft->priv;
+  priv_t * lpc = (priv_t *)ft->priv;
 
   free(lpc->encst);
 
@@ -213,13 +212,11 @@
   static char const * const names[] = {"lpc10", "lpc", NULL};
   static sox_rate_t   const write_rates[] = {8000, 0};
   static unsigned     const write_encodings[] = {SOX_ENCODING_LPC10, 0, 0};
-  static sox_format_handler_t handler = {
-    SOX_LIB_VERSION_CODE,
-    "Low bandwidth, robotic sounding speech compression",
-    names, SOX_FILE_MONO,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
+    "Low bandwidth, robotic sounding speech compression", names, SOX_FILE_MONO,
     startread, read_samples, stopread,
     startwrite, write_samples, stopwrite,
-    NULL, write_encodings, write_rates
+    NULL, write_encodings, write_rates, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/lu-fmt.c
+++ b/src/lu-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/maud.c
+++ b/src/maud.c
@@ -1,12 +1,11 @@
-/*
- * libSoX MAUD file format handler, by Lutz Vieweg 1993
+/* libSoX MAUD file format handler, by Lutz Vieweg 1993
  *
  * supports: mono and stereo, linear, a-law and u-law reading and writing
  *
  * Copyright 1998-2006 Chris Bagwell and SoX Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Lance Norskog And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Lance Norskog And Sundry Contributors are not responsible for
  * the consequences of using this software.
  */
 
@@ -17,31 +16,31 @@
 #include <errno.h>
 
 /* Private data for MAUD file */
-struct maudstuff { /* max. 100 bytes!!!! */
+typedef struct {
         uint32_t nsamples;
-};
+} priv_t;
 
 static void maudwriteheader(sox_format_t *);
 
 /*
  * Do anything required before you start reading samples.
- * Read file header. 
- *      Find out sampling rate, 
- *      size and encoding of samples, 
+ * Read file header.
+ *      Find out sampling rate,
+ *      size and encoding of samples,
  *      mono/stereo/quad.
  */
-static int startread(sox_format_t * ft) 
+static int startread(sox_format_t * ft)
 {
-        struct maudstuff * p = (struct maudstuff *) ft->priv;
-        
+        priv_t * p = (priv_t *) ft->priv;
+
         char buf[12];
         char *chunk_buf;
-        
+
         unsigned short bitpersam;
         uint32_t nom;
         unsigned short denom;
         unsigned short chaninf;
-        
+
         uint32_t chunksize;
         uint32_t trash32;
         uint16_t trash16;
@@ -58,33 +57,33 @@
                 lsx_fail_errno(ft,SOX_EHDR,"MAUD: header does not begin with magic word 'FORM'");
                 return (SOX_EOF);
         }
-        
+
         lsx_readdw(ft, &trash32); /* totalsize */
-        
+
         if (lsx_reads(ft, buf, 4) == SOX_EOF || strncmp(buf, "MAUD", 4) != 0)
         {
                 lsx_fail_errno(ft,SOX_EHDR,"MAUD: 'FORM' chunk does not specify 'MAUD' as type");
                 return(SOX_EOF);
         }
-        
+
         /* read chunks until 'BODY' (or end) */
-        
+
         while (lsx_reads(ft, buf, 4) == SOX_SUCCESS && strncmp(buf,"MDAT",4) != 0) {
-                
+
                 /*
                 buf[4] = 0;
                 sox_debug("chunk %s",buf);
                 */
-                
+
                 if (strncmp(buf,"MHDR",4) == 0) {
-                        
+
                         lsx_readdw(ft, &chunksize);
-                        if (chunksize != 8*4) 
+                        if (chunksize != 8*4)
                         {
                             lsx_fail_errno(ft,SOX_EHDR,"MAUD: MHDR chunk has bad size");
                             return(SOX_EOF);
                         }
-                        
+
                         /* fseeko(ft->fp,12,SEEK_CUR); */
 
                         /* number of samples stored in MDAT */
@@ -98,14 +97,14 @@
 
                         lsx_readdw(ft, &nom);         /* clock source frequency */
                         lsx_readw(ft, &denom);       /* clock devide           */
-                        if (denom == 0) 
+                        if (denom == 0)
                         {
                             lsx_fail_errno(ft,SOX_EHDR,"MAUD: frequency denominator == 0, failed");
                             return (SOX_EOF);
                         }
-                        
+
                         ft->signal.rate = nom / denom;
-                        
+
                         lsx_readw(ft, &chaninf); /* channel information */
                         switch (chaninf) {
                         case 0:
@@ -118,20 +117,20 @@
                                 lsx_fail_errno(ft,SOX_EFMT,"MAUD: unsupported number of channels in file");
                                 return (SOX_EOF);
                         }
-                        
+
                         lsx_readw(ft, &chaninf); /* number of channels (mono: 1, stereo: 2, ...) */
-                        if (chaninf != ft->signal.channels) 
+                        if (chaninf != ft->signal.channels)
                         {
                                 lsx_fail_errno(ft,SOX_EFMT,"MAUD: unsupported number of channels in file");
                             return(SOX_EOF);
                         }
-                        
+
                         lsx_readw(ft, &chaninf); /* compression type */
-                        
+
                         lsx_readdw(ft, &trash32); /* rest of chunk, unused yet */
                         lsx_readdw(ft, &trash32);
                         lsx_readdw(ft, &trash32);
-                        
+
                         if (bitpersam == 8 && chaninf == 0) {
                                 ft->encoding.bits_per_sample = 8;
                                 ft->encoding.encoding = SOX_ENCODING_UNSIGNED;
@@ -148,21 +147,21 @@
                                 ft->encoding.bits_per_sample = 16;
                                 ft->encoding.encoding = SOX_ENCODING_SIGN2;
                         }
-                        else 
+                        else
                         {
                                 lsx_fail_errno(ft,SOX_EFMT,"MAUD: unsupported compression type detected");
                                 return(SOX_EOF);
                         }
-                        
+
                         continue;
                 }
-                
+
                 if (strncmp(buf,"ANNO",4) == 0) {
                         lsx_readdw(ft, &chunksize);
                         if (chunksize & 1)
                                 chunksize++;
                         chunk_buf = (char *) lsx_malloc(chunksize + 1);
-                        if (lsx_readbuf(ft, chunk_buf, chunksize) 
+                        if (lsx_readbuf(ft, chunk_buf, chunksize)
                             != chunksize)
                         {
                                 lsx_fail_errno(ft,SOX_EOF,"MAUD: Unexpected EOF in ANNO header");
@@ -171,10 +170,10 @@
                         chunk_buf[chunksize] = '\0';
                         sox_debug("%s",chunk_buf);
                         free(chunk_buf);
-                        
+
                         continue;
                 }
-                
+
                 /* some other kind of chunk */
                 lsx_readdw(ft, &chunksize);
                 if (chunksize & 1)
@@ -181,10 +180,10 @@
                         chunksize++;
                 lsx_seeki(ft, (sox_ssize_t)chunksize, SEEK_CUR);
                 continue;
-                
+
         }
-        
-        if (strncmp(buf,"MDAT",4) != 0) 
+
+        if (strncmp(buf,"MDAT",4) != 0)
         {
             lsx_fail_errno(ft,SOX_EFMT,"MAUD: MDAT chunk not found");
             return(SOX_EOF);
@@ -193,9 +192,9 @@
         return(SOX_SUCCESS);
 }
 
-static int startwrite(sox_format_t * ft) 
+static int startwrite(sox_format_t * ft)
 {
-        struct maudstuff * p = (struct maudstuff *) ft->priv;
+        priv_t * p = (priv_t *) ft->priv;
         int rc;
 
         /* Needed for rawwrite() */
@@ -204,7 +203,7 @@
             return rc;
 
         /* If you have to seek around the output file */
-        if (! ft->seekable) 
+        if (! ft->seekable)
         {
             lsx_fail_errno(ft,SOX_EOF,"Output .maud file must be a file, not a pipe");
             return (SOX_EOF);
@@ -215,25 +214,25 @@
         return (SOX_SUCCESS);
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len) 
+static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-        struct maudstuff * p = (struct maudstuff *) ft->priv;
-        
+        priv_t * p = (priv_t *) ft->priv;
+
         p->nsamples += len;
-        
+
         return lsx_rawwrite(ft, buf, len);
 }
 
-static int stopwrite(sox_format_t * ft) 
+static int stopwrite(sox_format_t * ft)
 {
         /* All samples are already written out. */
-        
-        if (lsx_seeki(ft, 0, 0) != 0) 
+
+        if (lsx_seeki(ft, 0, 0) != 0)
         {
             lsx_fail_errno(ft,errno,"can't rewind output file to rewrite MAUD header");
             return(SOX_EOF);
         }
-        
+
         maudwriteheader(ft);
         return(SOX_SUCCESS);
 }
@@ -241,28 +240,28 @@
 #define MAUDHEADERSIZE (4+(4+4+32)+(4+4+32)+(4+4))
 static void maudwriteheader(sox_format_t * ft)
 {
-        struct maudstuff * p = (struct maudstuff *) ft->priv;
-        
+        priv_t * p = (priv_t *) ft->priv;
+
         lsx_writes(ft, "FORM");
         lsx_writedw(ft, (p->nsamples* (ft->encoding.bits_per_sample >> 3)) + MAUDHEADERSIZE);  /* size of file */
         lsx_writes(ft, "MAUD"); /* File type */
-        
+
         lsx_writes(ft, "MHDR");
         lsx_writedw(ft,  8*4); /* number of bytes to follow */
         lsx_writedw(ft, p->nsamples);  /* number of samples stored in MDAT */
-        
+
         switch (ft->encoding.encoding) {
-                
+
         case SOX_ENCODING_UNSIGNED:
           lsx_writew(ft, 8); /* number of bits per sample as stored in MDAT */
           lsx_writew(ft, 8); /* number of bits per sample after decompression */
           break;
-                
+
         case SOX_ENCODING_SIGN2:
           lsx_writew(ft, 16); /* number of bits per sample as stored in MDAT */
           lsx_writew(ft, 16); /* number of bits per sample after decompression */
           break;
-                
+
         case SOX_ENCODING_ALAW:
         case SOX_ENCODING_ULAW:
           lsx_writew(ft, 8); /* number of bits per sample as stored in MDAT */
@@ -272,10 +271,10 @@
         default:
           break;
         }
-        
+
         lsx_writedw(ft, (unsigned)(ft->signal.rate + .5)); /* sample rate, Hz */
         lsx_writew(ft, (int) 1); /* clock devide */
-        
+
         if (ft->signal.channels == 1) {
           lsx_writew(ft, 0); /* channel information */
           lsx_writew(ft, 1); /* number of channels (mono: 1, stereo: 2, ...) */
@@ -284,18 +283,18 @@
           lsx_writew(ft, 1);
           lsx_writew(ft, 2);
         }
-        
+
         switch (ft->encoding.encoding) {
-                
+
         case SOX_ENCODING_UNSIGNED:
         case SOX_ENCODING_SIGN2:
           lsx_writew(ft, 0); /* no compression */
           break;
-                
+
         case SOX_ENCODING_ULAW:
           lsx_writew(ft, 3);
           break;
-                
+
         case SOX_ENCODING_ALAW:
           lsx_writew(ft, 2);
           break;
@@ -303,15 +302,15 @@
         default:
           break;
         }
-        
+
         lsx_writedw(ft, 0); /* reserved */
         lsx_writedw(ft, 0); /* reserved */
         lsx_writedw(ft, 0); /* reserved */
-        
+
         lsx_writes(ft, "ANNO");
         lsx_writedw(ft, 30); /* length of block */
         lsx_writes(ft, "file create by Sound eXchange ");
-        
+
         lsx_writes(ft, "MDAT");
         lsx_writedw(ft, p->nsamples * (ft->encoding.bits_per_sample >> 3)); /* samples in file */
 }
@@ -325,13 +324,12 @@
     SOX_ENCODING_ULAW, 8, 0,
     SOX_ENCODING_ALAW, 8, 0,
     0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
     "Used with the ‘Toccata’ sound-card on the Amiga",
     names, SOX_FILE_BIG_END | SOX_FILE_MONO | SOX_FILE_STEREO,
     startread, lsx_rawread, lsx_rawstopread,
     startwrite, write_samples, stopwrite,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/mcompand.c
+++ b/src/mcompand.c
@@ -1,5 +1,4 @@
-/*
- * multiband compander effect for SoX
+/* multiband compander effect for SoX
  * by Daniel Pouzzner <douzzer@mega.nu> 2002-Oct-8
  *
  * Compander code adapted from the SoX compand effect, by Nick Bailey
@@ -9,8 +8,8 @@
  *
  * SoX is Copyright 1999 Chris Bagwell And Nick Bailey
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Chris Bagwell And Nick Bailey are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Chris Bagwell And Nick Bailey are not responsible for
  * the consequences of using this software.
  */
 
@@ -29,7 +28,7 @@
  *
  *   attack1,decay1[,attack2,decay2...]
  *                  in-dB1,out-dB1[,in-dB2,out-dB2...]
- *                 [ gain [ initial-volume [ delay ] ] ] 
+ *                 [ gain [ initial-volume [ delay ] ] ]
  *
  *   Beware a variety of headroom (clipping) bugaboos.
  *
@@ -78,7 +77,7 @@
     double y [2];
 } ;
 
-typedef struct butterworth_crossover {
+typedef struct {
   struct xy *xy_low, *xy_high;
 
   double a_low[3], a_high[3];
@@ -90,9 +89,9 @@
   double frequency_low, frequency_high;
 
   double bandwidth;
-} *butterworth_crossover_t;
+} 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, sox_size_t nchan) {
   double c;
 
   butterworth->xy_low = (struct xy *)lsx_calloc(nchan, sizeof(struct xy));
@@ -125,7 +124,7 @@
   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,
+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;
   double in, out;
@@ -191,7 +190,7 @@
   return (SOX_SUCCESS);
 }
 
-typedef struct comp_band {
+typedef struct {
   sox_compandt_t transfer_fn;
 
   sox_size_t expectedChannels; /* Also flags that channels aren't to be treated
@@ -201,12 +200,12 @@
   double *volume;       /* Current "volume" of each channel */
   double delay;         /* Delay to apply before companding */
   double topfreq;       /* upper bound crossover frequency */
-  struct butterworth_crossover filter;
+  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 */
-} *comp_band_t;
+} comp_band_t;
 
 typedef struct {
   sox_size_t nBands;
@@ -213,8 +212,8 @@
   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 */
-  struct comp_band *bands;
-} *compand_t;
+  comp_band_t *bands;
+} priv_t;
 
 /*
  * Process options
@@ -222,7 +221,7 @@
  * 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, sox_size_t n, char **argv)
 {
       char *s;
       sox_size_t rates, i, commas;
@@ -302,12 +301,12 @@
       return SOX_SUCCESS;
 }
 
-static int getopts(sox_effect_t * effp, int n, char **argv) 
+static int getopts(sox_effect_t * effp, int n, char **argv)
 {
   char *subargv[6], *cp;
   sox_size_t subargc, i, len;
 
-  compand_t c = (compand_t) effp->priv;
+  priv_t * c = (priv_t *) effp->priv;
 
   c->band_buf1 = c->band_buf2 = c->band_buf3 = 0;
   c->band_buf_len = 0;
@@ -320,7 +319,7 @@
   }
   c->nBands = (n+1)>>1;
 
-  c->bands = (struct comp_band *)lsx_calloc(c->nBands, sizeof(struct comp_band));
+  c->bands = (comp_band_t *)lsx_calloc(c->nBands, sizeof(comp_band_t));
 
   for (i=0;i<c->nBands;++i) {
     len = strlen(argv[i<<1]);
@@ -352,11 +351,11 @@
  */
 static int start(sox_effect_t * effp)
 {
-  compand_t c = (compand_t) effp->priv;
-  comp_band_t l;
+  priv_t * c = (priv_t *) effp->priv;
+  comp_band_t * l;
   sox_size_t i;
   sox_size_t band;
-  
+
   for (band=0;band<c->nBands;++band) {
     l = &c->bands[band];
     l->delay_size = c->bands[band].delay * effp->out_signal.rate * effp->out_signal.channels;
@@ -398,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, sox_size_t chan)
 {
   double s = samp/(~((sox_sample_t)1<<31));
   double delta = s - *v;
@@ -409,7 +408,7 @@
     *v += delta * l->decayRate[chan];
 }
 
-static int sox_mcompand_flow_1(sox_effect_t * effp, compand_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, sox_size_t len, sox_size_t filechans)
 {
   sox_size_t done, chan;
 
@@ -479,10 +478,10 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
                      sox_size_t *isamp, sox_size_t *osamp) {
-  compand_t c = (compand_t) effp->priv;
-  comp_band_t l;
+  priv_t * c = (priv_t *) effp->priv;
+  comp_band_t * l;
   sox_size_t len = min(*isamp, *osamp);
   sox_size_t band, i;
   sox_sample_t *abuf, *bbuf, *cbuf, *oldabuf, *ibuf_copy;
@@ -531,7 +530,7 @@
   return SOX_SUCCESS;
 }
 
-static int sox_mcompand_drain_1(sox_effect_t * effp, compand_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, sox_size_t maxdrain)
 {
   sox_size_t done;
   double out;
@@ -553,13 +552,13 @@
 }
 
 /*
- * Drain out compander delay lines. 
+ * Drain out compander delay lines.
  */
 static int drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
   sox_size_t band, drained, mostdrained = 0;
-  compand_t c = (compand_t)effp->priv;
-  comp_band_t l;
+  priv_t * c = (priv_t *)effp->priv;
+  comp_band_t * l;
 
   memset(obuf,0,*osamp * sizeof *obuf);
   for (band=0;band<c->nBands;++band) {
@@ -582,8 +581,8 @@
  */
 static int stop(sox_effect_t * effp)
 {
-  compand_t c = (compand_t) effp->priv;
-  comp_band_t l;
+  priv_t * c = (priv_t *) effp->priv;
+  comp_band_t * l;
   sox_size_t band;
 
   free(c->band_buf1);
@@ -607,8 +606,8 @@
 
 static int kill(sox_effect_t * effp)
 {
-  compand_t c = (compand_t) effp->priv;
-  comp_band_t l;
+  priv_t * c = (priv_t *) effp->priv;
+  comp_band_t * l;
   sox_size_t band;
 
   for (band = 0; band < c->nBands; band++) {
@@ -636,7 +635,7 @@
     "                 in-dB1,out-dB1[,in-dB2,out-dB2...]\n"
     "                [ gain [ initial-volume [ delay ] ] ]\n",
     SOX_EFF_MCHAN,
-    getopts, start, flow, drain, stop, kill
+    getopts, start, flow, drain, stop, kill, sizeof(priv_t)
   };
 
   return &handler;
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -1,9 +1,8 @@
-/*
- * July 5, 1991
+/* July 5, 1991
  * Copyright 1991 Lance Norskog And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Lance Norskog And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Lance Norskog And Sundry Contributors are not responsible for
  * the consequences of using this software.
  *
  * Channel duplication code by Graeme W. Gill - 93/5/18
@@ -20,7 +19,7 @@
 #include <string.h>
 #include <stdlib.h>
 
-typedef struct mixerstuff {
+typedef struct {
         /* How to generate each output channel.  sources[i][j] */
         /* represents the fraction of channel i that should be passed */
         /* through to channel j on output, and so forth.  Channel 0 is */
@@ -29,7 +28,7 @@
         double  sources[4][4];
         int     num_pans;
         int     mix;                    /* How are we mixing it? */
-} *mixer_t;
+} priv_t;
 
 /* MIX_CENTER is shorthand to mix channels together at 50% each */
 #define MIX_CENTER      0
@@ -39,9 +38,9 @@
 /*
  * Process options
  */
-static int getopts(sox_effect_t * effp, int n, char **argv) 
+static int getopts(sox_effect_t * effp, int n, char **argv)
 {
-    mixer_t mixer = (mixer_t) effp->priv;
+    priv_t * mixer = (priv_t *) effp->priv;
     double* pans = &mixer->sources[0][0];
     int i;
 
@@ -159,7 +158,7 @@
 
        GHK 2000/11/28
      */
-     mixer_t mixer = (mixer_t) effp->priv;
+     priv_t * mixer = (priv_t *) effp->priv;
      double pans[16];
      int i, j;
      int ichan, ochan;
@@ -362,7 +361,7 @@
      {
          for (i = 0; i < ichan; i++)
          {
-             for (j = 0; j < ochan; j++) 
+             for (j = 0; j < ochan; j++)
              {
                  mixer->sources[i][j] = 0;
              }
@@ -500,10 +499,10 @@
  * Process either isamp or osamp samples, whichever is smaller.
  */
 
-static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
                 sox_size_t *isamp, sox_size_t *osamp)
 {
-    mixer_t mixer = (mixer_t) effp->priv;
+    priv_t * mixer = (priv_t *) effp->priv;
     sox_size_t len, done;
     int ichan, ochan;
     int i, j;
@@ -534,12 +533,12 @@
     "mixer",
     "[ -l | -r | -f | -b | -1 | -2 | -3 | -4 | n,n,n...,n ]",
     SOX_EFF_MCHAN | SOX_EFF_CHAN,
-    getopts, start, flow, 0, 0, 0
+    getopts, start, flow, 0, 0, 0, sizeof(priv_t)
   };
   return &handler;
 }
 
-static int oops_getopts(sox_effect_t * effp, int argc, char * * argv UNUSED) 
+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);
--- a/src/mp3-duration.h
+++ b/src/mp3-duration.h
@@ -1,5 +1,4 @@
-/*
- * Determine MP3 duration
+/* libSoX determine MP3 duration
  * Copyright (c) 2007 robs@users.sourceforge.net
  * Based on original ideas by Regis Boudin, Thibaut Varene & Pascal Giard
  *
@@ -58,17 +57,17 @@
 
   if ((id3struct = id3_file_fdopen(fd, ID3_FILE_MODE_READONLY))) {
     if ((tag = id3_file_tag(id3struct)) && tag->frames)
-      for (i = 0; list[i][0]; ++i) 
+      for (i = 0; list[i][0]; ++i)
         if ((utf8 = utf8_id3tag_findframe(tag, list[i][0], 0))) {
           char * comment = lsx_malloc(strlen(list[i][1]) + 1 + strlen((char *)utf8) + 1);
           sprintf(comment, "%s=%s", list[i][1], utf8);
-          sox_append_comment(&ft->comments, comment);
+          sox_append_comment(&ft->oob.comments, comment);
           free(comment);
           free(utf8);
         }
       if ((utf8 = utf8_id3tag_findframe(tag, "TLEN", 0))) {
         if (atoi((char *)utf8) > 0) {
-          ft->length = atoi((char *)utf8); /* In ms; convert to samples later */
+          ft->signal.length = atoi((char *)utf8); /* In ms; convert to samples later */
           sox_debug("got exact duration from ID3 TLEN");
         }
         free(utf8);
--- a/src/mp3.c
+++ b/src/mp3.c
@@ -1,5 +1,4 @@
-/*
- * MP3 support for SoX
+/* MP3 support for SoX
  *
  * Uses libmad for MP3 decoding
  * and libmp3lame for MP3 encoding
@@ -20,7 +19,6 @@
 
 #ifdef HAVE_LAME_LAME_H
 #include <lame/lame.h>
-#include <math.h>
 #endif
 
 #if HAVE_ID3TAG && HAVE_UNISTD_H
@@ -33,7 +31,7 @@
 #define INPUT_BUFFER_SIZE       (sox_globals.bufsiz)
 
 /* Private data */
-struct mp3priv {
+typedef struct {
 #ifdef HAVE_MAD_H
         struct mad_stream       *Stream;
         struct mad_frame        *Frame;
@@ -46,7 +44,7 @@
 #ifdef HAVE_LAME_LAME_H
         lame_global_flags       *gfp;
 #endif /*HAVE_LAME_LAME_H*/
-};
+} priv_t;
 
 #ifdef HAVE_MAD_H
 
@@ -88,7 +86,7 @@
  */
 static int sox_mp3_input(sox_format_t * ft)
 {
-    struct mp3priv *p = (struct mp3priv *) ft->priv;
+    priv_t *p = (priv_t *) ft->priv;
     size_t bytes_read;
     size_t remaining;
 
@@ -125,7 +123,7 @@
  * */
 static int sox_mp3_inputtag(sox_format_t * ft)
 {
-    struct mp3priv *p = (struct mp3priv *) ft->priv;
+    priv_t *p = (priv_t *) ft->priv;
     int rc = SOX_EOF;
     size_t remaining;
     size_t tagsize;
@@ -158,9 +156,9 @@
     return rc;
 }
 
-static int startread(sox_format_t * ft) 
+static int startread(sox_format_t * ft)
 {
-    struct mp3priv *p = (struct mp3priv *) ft->priv;
+    priv_t *p = (priv_t *) ft->priv;
     size_t ReadSize;
 
     p->Stream = NULL;
@@ -178,9 +176,9 @@
     if (ft->seekable) {
 #if HAVE_ID3TAG && HAVE_UNISTD_H
       read_comments(ft);
-      if (!ft->length)
-#endif 
-        ft->length = mp3_duration_ms(ft->fp, p->InputBuffer);
+      if (!ft->signal.length)
+#endif
+        ft->signal.length = mp3_duration_ms(ft->fp, p->InputBuffer);
     }
 
     mad_stream_init(p->Stream);
@@ -208,7 +206,7 @@
      * at the beginning of the audio file.
      */
     p->Stream->error = 0;
-    while (mad_frame_decode(p->Frame,p->Stream)) 
+    while (mad_frame_decode(p->Frame,p->Stream))
     {
         /* check whether input buffer needs a refill */
         if (p->Stream->error == MAD_ERROR_BUFLEN)
@@ -254,8 +252,8 @@
     mad_timer_add(p->Timer,p->Frame->header.duration);
     mad_synth_frame(p->Synth,p->Frame);
     ft->signal.rate=p->Synth->pcm.samplerate;
-    ft->length = ft->length * .001 * ft->signal.rate + .5;
-    ft->length *= ft->signal.channels;  /* Keep separate from line above! */
+    ft->signal.length = ft->signal.length * .001 * ft->signal.rate + .5;
+    ft->signal.length *= ft->signal.channels;  /* Keep separate from line above! */
 
     p->cursamp = 0;
 
@@ -270,7 +268,7 @@
  */
 static sox_size_t sox_mp3read(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-    struct mp3priv *p = (struct mp3priv *) ft->priv;
+    priv_t *p = (priv_t *) ft->priv;
     sox_size_t donow,i,done=0;
     mad_fixed_t sample;
     size_t chan;
@@ -333,7 +331,7 @@
 
 static int stopread(sox_format_t * ft)
 {
-  struct mp3priv *p=(struct mp3priv*) ft->priv;
+  priv_t *p=(priv_t*) ft->priv;
 
   mad_synth_finish(p->Synth);
   mad_frame_finish(p->Frame);
@@ -365,8 +363,8 @@
 
 static int startwrite(sox_format_t * ft)
 {
-  struct mp3priv *p = (struct mp3priv *) ft->priv;
-  
+  priv_t *p = (priv_t *) ft->priv;
+
   if (ft->encoding.encoding != SOX_ENCODING_MP3) {
     if(ft->encoding.encoding != SOX_ENCODING_UNKNOWN)
       sox_report("Encoding forced to MP3");
@@ -413,7 +411,7 @@
 
 static sox_size_t sox_mp3write(sox_format_t * ft, const sox_sample_t *buf, sox_size_t samp)
 {
-    struct mp3priv *p = (struct mp3priv *)ft->priv;
+    priv_t *p = (priv_t *)ft->priv;
     char *mp3buffer;
     sox_size_t mp3buffer_size;
     short signed int *buffer_l, *buffer_r = NULL;
@@ -430,7 +428,7 @@
      * and assumes for the majority of cases that your passing
      * in something scaled based on passed in datatype
      * (16, 32, 64, and float).
-     * 
+     *
      * If we used long buffers then this means it expects
      * different scalling between 32-bit and 64-bit CPU's.
      *
@@ -445,7 +443,7 @@
         /* lame doesn't support iterleaved samples so we must break
          * them out into seperate buffers.
          */
-        if ((buffer_r = 
+        if ((buffer_r =
              (short signed int *)lsx_malloc(nsamples*
                                           sizeof(short signed int))) == NULL)
         {
@@ -465,7 +463,7 @@
         j=0;
         for (i=0; i<nsamples; i++)
         {
-            buffer_l[i]=SOX_SAMPLE_TO_SIGNED_16BIT(buf[j++], ft->clips); 
+            buffer_l[i]=SOX_SAMPLE_TO_SIGNED_16BIT(buf[j++], ft->clips);
         }
     }
 
@@ -504,11 +502,11 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-  struct mp3priv *p = (struct mp3priv *) ft->priv;
+  priv_t *p = (priv_t *) ft->priv;
   char mp3buffer[7200];
   int written;
   size_t written2;
-  
+
   if ((written=lame_encode_flush(p->gfp, (unsigned char *)mp3buffer, 7200)) <0){
     lsx_fail_errno(ft,SOX_EOF,"Encoding failed");
   }
@@ -535,13 +533,11 @@
   static char const * const names[] = {"mp3", "mp2", NULL};
   static unsigned const write_encodings[] = {
     SOX_ENCODING_GSM, 0, 0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
-    "MPEG Layer 3 lossy audio compression",
-    names, 0,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
+    "MPEG Layer 3 lossy audio compression", names, 0,
     startread, sox_mp3read, stopread,
     startwrite, sox_mp3write, stopwrite,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/noiseprof.c
+++ b/src/noiseprof.c
@@ -1,5 +1,4 @@
-/*
- * noiseprof - SoX Noise Profiling Effect. 
+/* noiseprof - SoX Noise Profiling Effect.
  *
  * Written by Ian Turner (vectro@vectro.org)
  * Copyright 1999 Ian Turner and others
@@ -25,7 +24,7 @@
 #include <string.h>
 #include <errno.h>
 
-typedef struct chandata {
+typedef struct {
     float *sum;
     int   *profilecount;
 
@@ -32,20 +31,20 @@
     float *window;
 } chandata_t;
 
-typedef struct profdata {
+typedef struct {
     char* output_filename;
     FILE* output_file;
 
     chandata_t *chandata;
     sox_size_t bufdata;
-} * profdata_t;
+} priv_t;
 
 /*
  * Get the filename, if any. We don't open it until sox_noiseprof_start.
  */
-static int sox_noiseprof_getopts(sox_effect_t * effp, int n, char **argv) 
+static int sox_noiseprof_getopts(sox_effect_t * effp, int n, char **argv)
 {
-    profdata_t data = (profdata_t) effp->priv;
+    priv_t * data = (priv_t *) effp->priv;
 
     if (n == 1) {
         data->output_filename = argv[0];
@@ -61,10 +60,10 @@
  */
 static int sox_noiseprof_start(sox_effect_t * effp)
 {
-  profdata_t data = (profdata_t) effp->priv;
+  priv_t * data = (priv_t *) effp->priv;
   unsigned channels = effp->in_signal.channels;
   unsigned i;
-   
+
   /* Note: don't fall back to stderr if stdout is unavailable
    * since we already use stderr for diagnostics. */
   if (!data->output_filename || !strcmp(data->output_filename, "-")) {
@@ -112,10 +111,10 @@
 /*
  * 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, 
+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)
 {
-    profdata_t data = (profdata_t) effp->priv;
+    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;
@@ -144,7 +143,7 @@
     assert(data->bufdata <= WINDOWSIZE);
     if (data->bufdata == WINDOWSIZE)
         data->bufdata = 0;
-        
+
     memcpy(obuf, ibuf, ncopy*tracks);
     *isamp = *osamp = ncopy*tracks;
 
@@ -157,7 +156,7 @@
 
 static int sox_noiseprof_drain(sox_effect_t * effp, sox_sample_t *obuf UNUSED, sox_size_t *osamp)
 {
-    profdata_t data = (profdata_t) effp->priv;
+    priv_t * data = (priv_t *) effp->priv;
     int tracks = effp->in_signal.channels;
     int i;
 
@@ -186,7 +185,7 @@
  */
 static int sox_noiseprof_stop(sox_effect_t * effp)
 {
-    profdata_t data = (profdata_t) effp->priv;
+    priv_t * data = (priv_t *) effp->priv;
     sox_size_t i;
 
     for (i = 0; i < effp->in_signal.channels; i ++) {
@@ -196,7 +195,7 @@
         fprintf(data->output_file, "Channel %d: ", i);
 
         for (j = 0; j < FREQCOUNT; j ++) {
-            double r = chan->profilecount[j] != 0 ? 
+            double r = chan->profilecount[j] != 0 ?
                     chan->sum[j] / chan->profilecount[j] : 0;
             fprintf(data->output_file, "%s%f", j == 0 ? "" : ", ", r);
         }
@@ -210,7 +209,7 @@
 
     if (data->output_file != stdout)
         fclose(data->output_file);
-    
+
     return (SOX_SUCCESS);
 }
 
@@ -223,7 +222,7 @@
   sox_noiseprof_flow,
   sox_noiseprof_drain,
   sox_noiseprof_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_noiseprof_effect_fn(void)
--- a/src/noisered.c
+++ b/src/noisered.c
@@ -1,11 +1,10 @@
-/*
- * noiseprof - Noise Profiling Effect. 
+/* noiseprof - Noise Profiling Effect.
  *
  * Written by Ian Turner (vectro@vectro.org)
  *
  * Copyright 1999 Ian Turner
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
+ * any purpose.  This copyright notice must be maintained.
  * Authors are not responsible for the consequences of using this software.
  */
 
@@ -16,7 +15,7 @@
 #include <string.h>
 #include <assert.h>
 
-typedef struct chandata {
+typedef struct {
     float *window;
     float *lastwindow;
     float *noisegate;
@@ -24,13 +23,13 @@
 } chandata_t;
 
 /* Holds profile information */
-typedef struct reddata {
+typedef struct {
     char* profile_filename;
     float threshold;
 
     chandata_t *chandata;
     sox_size_t bufdata;
-} * reddata_t;
+} priv_t;
 
 /*
  * Get the options. Default file is stdin (if the audio
@@ -38,7 +37,7 @@
  */
 static int sox_noisered_getopts(sox_effect_t * effp, int argc, char **argv)
 {
-  reddata_t p = (reddata_t) effp->priv;
+  priv_t * p = (priv_t *) effp->priv;
 
   if (argc > 0) {
     p->profile_filename = argv[0];
@@ -60,7 +59,7 @@
  */
 static int sox_noisered_start(sox_effect_t * effp)
 {
-    reddata_t data = (reddata_t) effp->priv;
+    priv_t * data = (priv_t *) effp->priv;
     sox_size_t fchannels = 0;
     sox_size_t channels = effp->in_signal.channels;
     sox_size_t i;
@@ -123,7 +122,7 @@
 }
 
 /* Mangle a single window. Each output sample (except the first and last
- * half-window) is the result of two distinct calls to this function, 
+ * half-window) is the result of two distinct calls to this function,
  * due to overlapping windows. */
 static void reduce_noise(chandata_t* chan, float* window, double level)
 {
@@ -136,7 +135,7 @@
     outr = ini + WINDOWSIZE;
     outi = outr + WINDOWSIZE;
     power = outi + WINDOWSIZE;
-    
+
     for (i = 0; i < FREQCOUNT; i ++)
         assert(smoothing[i] >= 0 && smoothing[i] <= 1);
 
@@ -156,10 +155,10 @@
             smooth = 0.0;
         else
             smooth = 1.0;
-        
+
         smoothing[i] = smooth * 0.5 + smoothing[i] * 0.5;
     }
-    
+
     /* Audacity says this code will eliminate tinkle bells.
      * I have no idea what that means. */
     for (i = 2; i < FREQCOUNT - 2; i ++) {
@@ -171,25 +170,25 @@
             smoothing[i+2]<0.1)
             smoothing[i] = 0.0;
     }
-    
+
     outr[0] *= smoothing[0];
     outi[0] *= smoothing[0];
     outr[FREQCOUNT-1] *= smoothing[FREQCOUNT-1];
     outi[FREQCOUNT-1] *= smoothing[FREQCOUNT-1];
-    
+
     for (i = 1; i < FREQCOUNT-1; i ++) {
         int j = WINDOWSIZE - i;
         float smooth = smoothing[i];
-        
+
         outr[i] *= smooth;
         outi[i] *= smooth;
         outr[j] *= smooth;
         outi[j] *= smooth;
     }
-    
+
     FFT(WINDOWSIZE, 1, outr, outi, inr, ini);
     WindowFunc(HANNING, WINDOWSIZE, inr);
-    
+
     memcpy(window, inr, WINDOWSIZE*sizeof(float));
 
     for (i = 0; i < FREQCOUNT; i ++)
@@ -200,7 +199,7 @@
 
 /* Do window management once we have a complete window, including mangling
  * the current window. */
-static int process_window(sox_effect_t * effp, reddata_t data, unsigned chan_num, unsigned num_chans,
+static int process_window(sox_effect_t * effp, priv_t * data, unsigned chan_num, unsigned num_chans,
                           sox_sample_t *obuf, unsigned len) {
     int j;
     float* nextwindow;
@@ -210,7 +209,7 @@
 
     if ((nextwindow = (float*)lsx_calloc(WINDOWSIZE, sizeof(float))) == NULL)
         return SOX_EOF;
-    
+
     memcpy(nextwindow, chan->window+WINDOWSIZE/2,
            sizeof(float)*(WINDOWSIZE/2));
 
@@ -231,7 +230,7 @@
     }
     chan->lastwindow = chan->window;
     chan->window = nextwindow;
-    
+
     return use;
 }
 
@@ -238,10 +237,10 @@
 /*
  * 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, 
+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)
 {
-    reddata_t data = (reddata_t) effp->priv;
+    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;
@@ -265,7 +264,7 @@
 
         if (chan->window == NULL)
             chan->window = (float*)lsx_calloc(WINDOWSIZE, sizeof(float));
-        
+
         for (j = 0; j < ncopy; j ++)
             chan->window[oldbuf + j] =
                 SOX_SAMPLE_TO_FLOAT_32BIT(ibuf[i + tracks * j], effp->clips);
@@ -275,7 +274,7 @@
         else
             process_window(effp, data, i, tracks, obuf, oldbuf + ncopy);
     }
-    
+
     *isamp = tracks*ncopy;
     if (whole_window)
         *osamp = tracks*(WINDOWSIZE/2);
@@ -291,7 +290,7 @@
 
 static int sox_noisered_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-    reddata_t data = (reddata_t)effp->priv;
+    priv_t * data = (priv_t *)effp->priv;
     unsigned i;
     unsigned tracks = effp->in_signal.channels;
     for (i = 0; i < tracks; i ++)
@@ -308,7 +307,7 @@
  */
 static int sox_noisered_stop(sox_effect_t * effp)
 {
-    reddata_t data = (reddata_t) effp->priv;
+    priv_t * data = (priv_t *) effp->priv;
     sox_size_t i;
 
     for (i = 0; i < effp->in_signal.channels; i ++) {
@@ -318,7 +317,7 @@
         free(chan->smoothing);
         free(chan->noisegate);
     }
-    
+
     free(data->chandata);
 
     return (SOX_SUCCESS);
@@ -333,7 +332,7 @@
   sox_noisered_flow,
   sox_noisered_drain,
   sox_noisered_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_noisered_effect_fn(void)
--- a/src/noisered.h
+++ b/src/noisered.h
@@ -1,5 +1,4 @@
-/*
- * noiseprof.h - Headers for SoX Noise Profiling Effect. 
+/* noiseprof.h - Headers for SoX Noise Profiling Effect.
  *
  * Written by Ian Turner (vectro@vectro.org)
  * Copyright 1999 Ian Turner and others
--- a/src/normalise.c
+++ b/src/normalise.c
@@ -1,4 +1,5 @@
-/*
+/* libSoX effect: Normalise   (c) 2008 robs@users.sourceforge.net
+ *
  * 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
@@ -14,40 +15,28 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-/* Effect: Normalise   (c) 2008 robs@users.sourceforge.net */
-
 #include "sox_i.h"
-#include <math.h>
 #include <string.h>
 
-typedef struct norm {
+typedef struct {
   sox_bool      individual;
   double        norm0;    /* Multiplier to take to 0dB FSD */
   double        level;    /* Multiplier to take to 'level' */
   sox_sample_t  min, max;
   FILE          * tmp_file;
-} * priv_t;
+} priv_t;
+#define p ((priv_t *)effp->priv)
 
-assert_static(sizeof(struct norm) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ norm_PRIVSIZE_too_big);
-
 static int create(sox_effect_t * effp, int argc, char * * argv)
 {
-  priv_t p = (priv_t)effp->priv;
-  char dummy;
-
   if (argc && !strcmp(*argv, "-i")) p->individual = sox_true, ++argv, --argc;
-  if (argc > 1 || (argc == 1 &&
-        (sscanf(*argv, "%lf%c", &p->level, &dummy) != 1 || p->level > 0)))
-    return lsx_usage(effp);
+  do {NUMERIC_PARAMETER(level, -100, 0)} while (0);
   p->level = dB_to_linear(p->level);
-  return SOX_SUCCESS;
+  return argc?  lsx_usage(effp) : SOX_SUCCESS;
 }
 
 static int start(sox_effect_t * effp)
 {
-  priv_t p = (priv_t)effp->priv;
-
   if (!p->individual)
     effp->flows = 1;
   p->norm0 = p->max = p->min = 0;
@@ -62,7 +51,6 @@
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
     sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
 {
-  priv_t p = (priv_t)effp->priv;
   sox_size_t len;
 
   if (fwrite(ibuf, sizeof(*ibuf), *isamp, p->tmp_file) != *isamp) {
@@ -79,7 +67,6 @@
 
 static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
 {
-  priv_t p = (priv_t)effp->priv;
   sox_size_t len;
   int result = SOX_SUCCESS;
 
@@ -100,8 +87,6 @@
 
 static int stop(sox_effect_t * effp)
 {
-  priv_t p = (priv_t)effp->priv;
-
   fclose(p->tmp_file); /* auto-deleted by tmpfile */
   return SOX_SUCCESS;
 }
@@ -108,8 +93,7 @@
 
 sox_effect_handler_t const * sox_norm_effect_fn(void)
 {
-  static sox_effect_handler_t handler = {
-    "norm", "[-i] [level]", 0, create, start, flow, drain, stop, NULL
-  };
+  static sox_effect_handler_t handler = {"norm", "[-i] [level]", 0,
+    create, start, flow, drain, stop, NULL, sizeof(priv_t)};
   return &handler;
 }
--- a/src/nulfile.c
+++ b/src/nulfile.c
@@ -1,5 +1,4 @@
-/*
- * File format: null   (c) 2006-8 SoX contributors
+/* libSoX file format: null   (c) 2006-8 SoX contributors
  * Based on an original idea by Carsten Borchardt
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -26,8 +25,8 @@
     ft->signal.rate = SOX_DEFAULT_RATE;
     sox_report("sample rate not specified; using %g", ft->signal.rate);
   }
-  ft->signal.precision =
-      ft->encoding.bits_per_sample? ft->encoding.bits_per_sample: SOX_SAMPLE_PRECISION;
+  ft->signal.precision = ft->encoding.bits_per_sample?
+      ft->encoding.bits_per_sample: SOX_SAMPLE_PRECISION;
   /* Default number of channels is application-dependent */
   return SOX_SUCCESS;
 }
@@ -51,11 +50,9 @@
 SOX_FORMAT_HANDLER(nul)
 {
   static const char * const names[] = {"null", NULL};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
-    NULL,
-    names, SOX_FILE_DEVICE | SOX_FILE_PHONY | SOX_FILE_NOSTDIO,
-    startread, read_samples, NULL, NULL, write_samples, NULL, NULL, NULL, NULL
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
+    NULL, names, SOX_FILE_DEVICE | SOX_FILE_PHONY | SOX_FILE_NOSTDIO,
+    startread, read_samples,NULL,NULL, write_samples,NULL,NULL, NULL, NULL, 0
   };
   return &handler;
 }
--- a/src/oss.c
+++ b/src/oss.c
@@ -1,5 +1,4 @@
-/*
- * Copyright 1997 Chris Bagwell And Sundry Contributors
+/* Copyright 1997 Chris Bagwell And Sundry Contributors
  * This source code is freely redistributable and may be used for
  * any purpose.  This copyright notice must be maintained.
  * Chris Bagwell And Sundry Contributors are not
@@ -40,12 +39,13 @@
 
 #include <sys/ioctl.h>
 
+typedef sox_fileinfo_t priv_t;
 /* common r/w initialization code */
 static int ossinit(sox_format_t * ft)
 {
     int sampletype, samplesize, dsp_stereo;
     int tmp, rc;
-    sox_fileinfo_t *file = (sox_fileinfo_t *)ft->priv;
+    priv_t *file = (priv_t *)ft->priv;
     sox_signalinfo_t client_signal = ft->signal;
 
     lsx_set_signal_defaults(&ft->signal);
@@ -164,7 +164,7 @@
     }
 
     tmp = ft->signal.rate;
-    if (ioctl (fileno(ft->fp), SNDCTL_DSP_SPEED, &tmp) < 0 || 
+    if (ioctl (fileno(ft->fp), SNDCTL_DSP_SPEED, &tmp) < 0 ||
         (int)ft->signal.rate != tmp) {
         /* If the rate the sound card is using is not within 1% of what
          * the user specified then override the user setting.
@@ -174,7 +174,7 @@
          * this and having strange output file rates for something that
          * we can't hear anyways.
          */
-        if ((int)ft->signal.rate - tmp > (tmp * .01) || 
+        if ((int)ft->signal.rate - tmp > (tmp * .01) ||
             tmp - (int)ft->signal.rate > (tmp * .01)) {
           if (client_signal.rate != 0)
             sox_warn("Unable to set audio speed to %g (set to %d)",
@@ -213,13 +213,12 @@
     SOX_ENCODING_SIGN2, 16, 0,
     SOX_ENCODING_UNSIGNED, 8, 0,
     0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
     "Open Sound Sytem device driver for unix-like systems",
     names, SOX_FILE_DEVICE,
     ossinit, lsx_rawread, lsx_rawstopread,
     ossinit, lsx_rawwrite, lsx_rawstopwrite,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/pad.c
+++ b/src/pad.c
@@ -1,4 +1,5 @@
-/*
+/* libSoX effect: Pad With Silence   (c) 2006 robs@users.sourceforge.net
+ *
  * 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
@@ -14,12 +15,9 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-/* Effect: Pad With Silence   (c) 2006 robs@users.sourceforge.net */
-
 #include "sox_i.h"
 
-typedef struct pad
-{
+typedef struct {
   unsigned npads;     /* Number of pads requested */
   struct {
     char * str;       /* Command-line argument to parse for this pad */
@@ -30,32 +28,29 @@
   sox_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 */
-} * pad_t;
+} priv_t;
+#define p (*(priv_t *)effp->priv)
 
-assert_static(sizeof(struct pad) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ pad_PRIVSIZE_too_big);
-
 static int parse(sox_effect_t * effp, char * * argv, sox_rate_t rate)
 {
-  pad_t p = (pad_t) effp->priv;
   char const * next;
   unsigned i;
 
-  for (i = 0; i < p->npads; ++i) {
+  for (i = 0; i < p.npads; ++i) {
     if (argv) /* 1st parse only */
-      p->pads[i].str = lsx_strdup(argv[i]);
-    next = lsx_parsesamples(rate, p->pads[i].str, &p->pads[i].pad, 't');
+      p.pads[i].str = lsx_strdup(argv[i]);
+    next = lsx_parsesamples(rate, p.pads[i].str, &p.pads[i].pad, 't');
     if (next == NULL) break;
     if (*next == '\0')
-      p->pads[i].start = i? SOX_SIZE_MAX : 0;
+      p.pads[i].start = i? SOX_SIZE_MAX : 0;
     else {
       if (*next != '@') break;
-      next = lsx_parsesamples(rate, next+1, &p->pads[i].start, 't');
+      next = lsx_parsesamples(rate, next+1, &p.pads[i].start, 't');
       if (next == NULL || *next != '\0') break;
     }
-    if (i > 0 && p->pads[i].start <= p->pads[i-1].start) break;
+    if (i > 0 && p.pads[i].start <= p.pads[i-1].start) break;
   }
-  if (i < p->npads)
+  if (i < p.npads)
     return lsx_usage(effp);
   return SOX_SUCCESS;
 }
@@ -62,20 +57,18 @@
 
 static int create(sox_effect_t * effp, int n, char * * argv)
 {
-  pad_t p = (pad_t) effp->priv;
-  p->pads = lsx_calloc(p->npads = n, sizeof(*p->pads));
+  p.pads = lsx_calloc(p.npads = n, sizeof(*p.pads));
   return parse(effp, argv, 96000.); /* No rate yet; parse with dummy */
 }
 
 static int start(sox_effect_t * effp)
 {
-  pad_t p = (pad_t) effp->priv;
   unsigned i;
 
   parse(effp, 0, effp->in_signal.rate); /* Re-parse now rate is known */
-  p->in_pos = p->pad_pos = p->pads_pos = 0;
-  for (i = 0; i < p->npads; ++i)
-    if (p->pads[i].pad)
+  p.in_pos = p.pad_pos = p.pads_pos = 0;
+  for (i = 0; i < p.npads; ++i)
+    if (p.pads[i].pad)
       return SOX_SUCCESS;
   return SOX_EFF_NULL;
 }
@@ -83,7 +76,6 @@
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, sox_sample_t * obuf,
                 sox_size_t * isamp, sox_size_t * osamp)
 {
-  pad_t p = (pad_t) effp->priv;
   sox_size_t c, idone = 0, odone = 0;
   *isamp /= effp->in_signal.channels;
   *osamp /= effp->in_signal.channels;
@@ -90,16 +82,16 @@
 
   do {
     /* Copying: */
-    for (; idone < *isamp && odone < *osamp && !(p->pads_pos != p->npads && p->in_pos == p->pads[p->pads_pos].start); ++idone, ++odone, ++p->in_pos)
+    for (; idone < *isamp && odone < *osamp && !(p.pads_pos != p.npads && p.in_pos == p.pads[p.pads_pos].start); ++idone, ++odone, ++p.in_pos)
       for (c = 0; c < effp->in_signal.channels; ++c) *obuf++ = *ibuf++;
 
     /* Padding: */
-    if (p->pads_pos != p->npads && p->in_pos == p->pads[p->pads_pos].start) {
-      for (; odone < *osamp && p->pad_pos < p->pads[p->pads_pos].pad; ++odone, ++p->pad_pos)
+    if (p.pads_pos != p.npads && p.in_pos == p.pads[p.pads_pos].start) {
+      for (; odone < *osamp && p.pad_pos < p.pads[p.pads_pos].pad; ++odone, ++p.pad_pos)
         for (c = 0; c < effp->in_signal.channels; ++c) *obuf++ = 0;
-      if (p->pad_pos == p->pads[p->pads_pos].pad) { /* Move to next pad? */
-        ++p->pads_pos;
-        p->pad_pos = 0;
+      if (p.pad_pos == p.pads[p.pads_pos].pad) { /* Move to next pad? */
+        ++p.pads_pos;
+        p.pad_pos = 0;
       }
     }
   } while (idone < *isamp && odone < *osamp);
@@ -112,27 +104,24 @@
 static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
 {
   static sox_size_t isamp = 0;
-  pad_t p = (pad_t) effp->priv;
-  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) */
+  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);
 }
 
 static int stop(sox_effect_t * effp)
 {
-  pad_t p = (pad_t) effp->priv;
-  if (p->pads_pos != p->npads)
-    sox_warn("Input audio too short; pads not applied: %u",p->npads-p->pads_pos);
+  if (p.pads_pos != p.npads)
+    sox_warn("Input audio too short; pads not applied: %u", p.npads-p.pads_pos);
   return SOX_SUCCESS;
 }
 
 static int kill(sox_effect_t * effp)
 {
-  pad_t p = (pad_t) effp->priv;
   unsigned i;
-  for (i = 0; i < p->npads; ++i)
-    free(p->pads[i].str);
-  free(p->pads);
+  for (i = 0; i < p.npads; ++i)
+    free(p.pads[i].str);
+  free(p.pads);
   return SOX_SUCCESS;
 }
 
@@ -140,7 +129,7 @@
 {
   static sox_effect_handler_t handler = {
     "pad", "{length[@position]}", SOX_EFF_MCHAN|SOX_EFF_LENGTH,
-    create, start, flow, drain, stop, kill
+    create, start, flow, drain, stop, kill, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/pan.c
+++ b/src/pan.c
@@ -1,5 +1,4 @@
-/*
- * (c) 20/03/2000 Fabien COELHO <fabien@coelho.net> for sox.
+/* (c) 20/03/2000 Fabien COELHO <fabien@coelho.net> for sox.
  *
  * 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
@@ -17,14 +16,14 @@
  *
  * Change panorama of sound file with basic linear volume interpolation.
  * The human ear is not sensible to phases? What about delay? too short?
- * 
- * Volume is kept constant (?). 
+ *
+ * Volume is kept constant (?).
  * Beware of saturations!
  * Operations are carried out on doubles.
  * Can handle different number of channels.
  * Cannot handle rate change.
  *
- * Initially based on avg effect. 
+ * Initially based on avg effect.
  * pan 0.0 basically behaves as avg.
  */
 
@@ -33,21 +32,19 @@
 
 /* structure to hold pan parameter */
 
-typedef struct {
-    double dir; /* direction, from left (-1.0) to right (1.0) */
-} * pan_t;
+typedef struct {double direction;} priv_t; /* from left (-1.0) to right (1.0) */
 
 /*
  * Process options
  */
-static int sox_pan_getopts(sox_effect_t * effp, int n, char **argv) 
+static int sox_pan_getopts(sox_effect_t * effp, int n, char **argv)
 {
-    pan_t pan = (pan_t) effp->priv; 
-    
-    pan->dir = 0.0; /* default is no change */
-    
-    if (n && (!sscanf(argv[0], "%lf", &pan->dir) || 
-              pan->dir < -1.0 || pan->dir > 1.0))
+    priv_t * pan = (priv_t *) effp->priv;
+
+    pan->direction = 0.0; /* default is no change */
+
+    if (n && (!sscanf(argv[0], "%lf", &pan->direction) ||
+              pan->direction < -1.0 || pan->direction > 1.0))
       return lsx_usage(effp);
 
     return SOX_SUCCESS;
@@ -72,20 +69,20 @@
 /*
  * 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, 
+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)
 {
-    pan_t pan = (pan_t) effp->priv;
+    priv_t * pan = (priv_t *) effp->priv;
     sox_size_t len, done;
     sox_sample_t *ibuf_copy;
     char ich, och;
-    double left, right, dir, hdir;
-    
+    double left, right, direction, hdir;
+
     ibuf_copy = (sox_sample_t *)lsx_malloc(*isamp * sizeof(sox_sample_t));
     memcpy(ibuf_copy, ibuf, *isamp * sizeof(sox_sample_t));
 
-    dir   = pan->dir;    /* -1   <=  dir  <= 1   */
-    hdir  = 0.5 * dir;  /* -0.5 <=  hdir <= 0.5 */
+    direction   = pan->direction;    /* -1   <=  direction  <= 1   */
+    hdir  = 0.5 * direction;  /* -0.5 <=  hdir <= 0.5 */
     left  = 0.5 - hdir; /*  0   <=  left <= 1   */
     right = 0.5 + hdir; /*  0   <= right <= 1   */
 
@@ -97,7 +94,7 @@
     /* report back how much is processed. */
     *isamp = len*ich;
     *osamp = len*och;
-    
+
     /* 9 different cases to handle: (1,2,4) X (1,2,4) */
     switch (och) {
     case 1: /* pan on mono channel... not much sense. just avg. */
@@ -120,7 +117,7 @@
             for (done=0; done<len; done++)
             {
                 double f;
-                f = 0.25*ibuf_copy[0] + 0.25*ibuf_copy[1] + 
+                f = 0.25*ibuf_copy[0] + 0.25*ibuf_copy[1] +
                         0.25*ibuf_copy[2] + 0.25*ibuf_copy[3];
                 SOX_SAMPLE_CLIP_COUNT(f, effp->clips);
                 *obuf++ = f;
@@ -149,17 +146,17 @@
                 ibuf_copy++;
             }
             break;
-        case 2: /* linear panorama. 
+        case 2: /* linear panorama.
                  * I'm not sure this is the right way to do it.
                  */
-            if (dir <= 0.0) /* to the left */
+            if (direction <= 0.0) /* to the left */
             {
                 register double volume, cll, clr, cr;
 
-                volume = 1.0 - 0.5*dir;
+                volume = 1.0 - 0.5*direction;
                 cll = volume*(1.5-left);
                 clr = volume*(left-0.5);
-                cr  = volume*(1.0+dir);
+                cr  = volume*(1.0+direction);
 
                 for (done=0; done<len; done++)
                 {
@@ -179,8 +176,8 @@
             {
                 register double volume, cl, crl, crr;
 
-                volume = 1.0 + 0.5*dir;
-                cl  = volume*(1.0-dir);
+                volume = 1.0 + 0.5*direction;
+                cl  = volume*(1.0-direction);
                 crl = volume*(right-0.5);
                 crr = volume*(1.5-right);
 
@@ -200,14 +197,14 @@
             }
             break;
         case 4:
-            if (dir <= 0.0) /* to the left */
+            if (direction <= 0.0) /* to the left */
             {
                 register double volume, cll, clr, cr;
 
-                volume = 1.0 - 0.5*dir;
+                volume = 1.0 - 0.5*direction;
                 cll = volume*(1.5-left);
                 clr = volume*(left-0.5);
-                cr  = volume*(1.0+dir);
+                cr  = volume*(1.0+direction);
 
                 for (done=0; done<len; done++)
                 {
@@ -232,8 +229,8 @@
             {
                 register double volume, cl, crl, crr;
 
-                volume = 1.0 + 0.5*dir;
-                cl  = volume*(1.0-dir);
+                volume = 1.0 + 0.5*direction;
+                cl  = volume*(1.0-direction);
                 crl = volume*(right-0.5);
                 crr = volume*(1.5-right);
 
@@ -285,14 +282,14 @@
             }
             break;
         case 2: /* simple linear panorama */
-            if (dir <= 0.0) /* to the left */
+            if (direction <= 0.0) /* to the left */
             {
                 register double volume, cll, clr, cr;
 
-                volume = 0.5 - 0.25*dir;
+                volume = 0.5 - 0.25*direction;
                 cll = volume * (1.5-left);
                 clr = volume * (left-0.5);
-                cr  = volume * (1.0+dir);
+                cr  = volume * (1.0+direction);
 
                 for (done=0; done<len; done++)
                 {
@@ -312,8 +309,8 @@
             {
                 register double volume, cl, crl, crr;
 
-                volume = 0.5 + 0.25*dir;
-                cl  = volume * (1.0-dir);
+                volume = 0.5 + 0.25*direction;
+                cl  = volume * (1.0-direction);
                 crl = volume * (right-0.5);
                 crr = volume * (1.5-right);
 
@@ -336,12 +333,12 @@
             /* maybe I could improve the formula to reverse...
                also, turn only by quarters.
              */
-            if (dir <= 0.0) /* to the left */
+            if (direction <= 0.0) /* to the left */
             {
                 register double cown, cright;
 
-                cright = -dir;
-                cown = 1.0 + dir;
+                cright = -direction;
+                cown = 1.0 + direction;
 
                 for (done=0; done<len; done++)
                 {
@@ -360,7 +357,7 @@
                     SOX_SAMPLE_CLIP_COUNT(f, effp->clips);
                     obuf[3] = f;
                     obuf += 4;
-                    ibuf_copy += 4;              
+                    ibuf_copy += 4;
                 }
             }
             else /* to the right */
@@ -367,8 +364,8 @@
             {
                 register double cleft, cown;
 
-                cleft = dir;
-                cown = 1.0 - dir;
+                cleft = direction;
+                cown = 1.0 - direction;
 
                 for (done=0; done<len; done++)
                 {
@@ -402,7 +399,7 @@
     } /* end switch out channel */
 
     free(ibuf_copy - len * ich);
-    
+
     return SOX_SUCCESS;
 }
 
@@ -419,7 +416,7 @@
   sox_pan_flow,
   NULL,
   NULL,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_pan_effect_fn(void)
--- a/src/phaser.c
+++ b/src/phaser.c
@@ -1,15 +1,14 @@
-/*
- * August 24, 1998
+/* August 24, 1998
  * Copyright (C) 1998 Juergen Mueller And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Juergen Mueller And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Juergen Mueller And Sundry Contributors are not responsible for
  * the consequences of using this software.
  */
 
 /*
  *      Phaser effect.
- * 
+ *
  * Flow diagram scheme:
  *
  *        * gain-in  +---+                     * gain-out
@@ -29,7 +28,7 @@
  *
  * The delay is controled by a sine or triangle modulation.
  *
- * Usage: 
+ * Usage:
  *   phaser gain-in gain-out delay decay speed [ -s | -t ]
  *
  * Where:
@@ -42,7 +41,7 @@
  *
  * Note:
  *   when decay is close to 1.0, the samples may begin clipping or the output
- *   can saturate! 
+ *   can saturate!
  *
  * Hint:
  *   in-gain < ( 1 - decay * decay )
@@ -57,7 +56,6 @@
 #include "sox_i.h"
 
 #include <stdlib.h> /* Harmless, and prototypes atof() etc. --dgc */
-#include <math.h>
 #include <string.h>
 
 #define MOD_SINE        0
@@ -64,9 +62,9 @@
 #define MOD_TRIANGLE    1
 
 /* Private data for SKEL file */
-typedef struct phaserstuff {
+typedef struct {
         int     modulation;
-        int     counter;                        
+        int     counter;
         int     phase;
         double  *phaserbuf;
         float   in_gain, out_gain;
@@ -75,14 +73,14 @@
         sox_size_t length;
         int     *lookup_tab;
         sox_size_t maxsamples, fade_out;
-} *phaser_t;
+} priv_t;
 
 /*
  * Process options
  */
-static int sox_phaser_getopts(sox_effect_t * effp, int n, char **argv) 
+static int sox_phaser_getopts(sox_effect_t * effp, int n, char **argv)
 {
-        phaser_t phaser = (phaser_t) effp->priv;
+        priv_t * phaser = (priv_t *) effp->priv;
 
         if (!((n == 5) || (n == 6)))
           return lsx_usage(effp);
@@ -109,7 +107,7 @@
  */
 static int sox_phaser_start(sox_effect_t * effp)
 {
-        phaser_t phaser = (phaser_t) effp->priv;
+        priv_t * phaser = (priv_t *) effp->priv;
         unsigned int i;
 
         phaser->maxsamples = phaser->delay * effp->in_signal.rate / 1000.0;
@@ -172,10 +170,10 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int sox_phaser_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
-        phaser_t phaser = (phaser_t) effp->priv;
+        priv_t * phaser = (priv_t *) effp->priv;
         double d_in, d_out;
         sox_sample_t out;
         sox_size_t len = min(*isamp, *osamp);
@@ -186,8 +184,8 @@
                 d_in = (double) *ibuf++ / 256;
                 /* Compute output first */
                 d_in = d_in * phaser->in_gain;
-                d_in += phaser->phaserbuf[(phaser->maxsamples + 
-        phaser->counter - phaser->lookup_tab[phaser->phase]) % 
+                d_in += phaser->phaserbuf[(phaser->maxsamples +
+        phaser->counter - phaser->lookup_tab[phaser->phase]) %
         phaser->maxsamples] * phaser->decay * -1.0;
                 /* Adjust the output volume and size to 24 bit */
                 d_out = d_in * phaser->out_gain;
@@ -195,7 +193,7 @@
                 *obuf++ = out * 256;
                 /* Mix decay of delay and input */
                 phaser->phaserbuf[phaser->counter] = d_in;
-                phaser->counter = 
+                phaser->counter =
                         ( phaser->counter + 1 ) % phaser->maxsamples;
                 phaser->phase  = ( phaser->phase + 1 ) % phaser->length;
         }
@@ -204,13 +202,13 @@
 }
 
 /*
- * Drain out reverb lines. 
+ * Drain out reverb lines.
  */
 static int sox_phaser_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-        phaser_t phaser = (phaser_t) effp->priv;
+        priv_t * phaser = (priv_t *) effp->priv;
         sox_size_t done;
-        
+
         double d_in, d_out;
         sox_sample_t out;
 
@@ -219,8 +217,8 @@
                 d_in = 0;
                 d_out = 0;
                 /* Compute output first */
-                d_in += phaser->phaserbuf[(phaser->maxsamples + 
-        phaser->counter - phaser->lookup_tab[phaser->phase]) % 
+                d_in += phaser->phaserbuf[(phaser->maxsamples +
+        phaser->counter - phaser->lookup_tab[phaser->phase]) %
         phaser->maxsamples] * phaser->decay * -1.0;
                 /* Adjust the output volume and size to 24 bit */
                 d_out = d_in * phaser->out_gain;
@@ -228,7 +226,7 @@
                 *obuf++ = out * 256;
                 /* Mix decay of delay and input */
                 phaser->phaserbuf[phaser->counter] = d_in;
-                phaser->counter = 
+                phaser->counter =
                         ( phaser->counter + 1 ) % phaser->maxsamples;
                 phaser->phase  = ( phaser->phase + 1 ) % phaser->length;
                 done++;
@@ -247,7 +245,7 @@
  */
 static int sox_phaser_stop(sox_effect_t * effp)
 {
-        phaser_t phaser = (phaser_t) effp->priv;
+        priv_t * phaser = (priv_t *) effp->priv;
 
         free(phaser->phaserbuf);
         free(phaser->lookup_tab);
@@ -263,7 +261,7 @@
   sox_phaser_flow,
   sox_phaser_drain,
   sox_phaser_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_phaser_effect_fn(void)
--- a/src/pitch.c
+++ b/src/pitch.c
@@ -1,5 +1,4 @@
-/*
- * (c) Fabien Coelho <fabien@coelho.net> 03/2000 for sox.
+/* (c) Fabien Coelho <fabien@coelho.net> 03/2000 for sox.
  *
  * pitch shifting.
  *
@@ -20,12 +19,12 @@
  * I found a code on the Computer Music Journal web site
  * <http://mitpress.mit.edu/e-journals/Computer_Music_Journal/>
  * for pitch shifting the AD 1848 PC soundcards, with
- * a lot of (unclear) pointer and integer arithmetics, and 
+ * a lot of (unclear) pointer and integer arithmetics, and
  * combine effects (feedback, delay, mixing).
  *
  * I tried to understand the code, dropped the other effects,
- * translated the stuff in float so it's easier to understand, 
- * drop one of the lookup tables (I know that sin(pi/2-x) = cos(x)), 
+ * translated the stuff in float so it's easier to understand,
+ * drop one of the lookup tables (I know that sin(pi/2-x) = cos(x)),
  * and added interpolation and fade options of my own.
  * cross fading is always symetric.
  *
@@ -39,7 +38,7 @@
  * frequencies, and come back to time", but it does not seem to work
  * that way... at least not so easily. Or maybe my attempt was buggy.
  *
- * Here is the result. It can certainly be improved. 
+ * Here is the result. It can certainly be improved.
  * The result buzzes some time.
  * Lot of options available so than one can adjust the result.
  *
@@ -54,8 +53,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <math.h>   /* cos(), pow() */
-
 /* cross fading options for transitions
  */
 #define PITCH_FADE_COS 0 /* cosine */
@@ -86,8 +83,7 @@
 typedef enum { pi_input, pi_compute, pi_output } pitch_state_t;
 
 /* structure hold by the effect descriptor. */
-typedef struct 
-{
+typedef struct {
     /* OPTIONS
      */
     double shift;   /* shift in cents, >0 to treble, <0 to bass */
@@ -120,7 +116,7 @@
 
     pitch_state_t state; /* buffer management status. */
 
-} * pitch_t;
+} priv_t;
 
 /* // debug functions
 
@@ -136,10 +132,10 @@
     }
 }
 
-static void debug(pitch_t pitch, char * where)
+static void debug(priv_t * pitch, char * where)
 {
-  sox_debug("%s: ind=%d sz=%ld step=%d o=%d rate=%f ia=%d st=%d fo=%s", 
-  where, pitch->index, pitch->size, pitch->step, pitch->overlap, 
+  sox_debug("%s: ind=%d sz=%ld step=%d o=%d rate=%f ia=%d st=%d fo=%s",
+  where, pitch->index, pitch->size, pitch->step, pitch->overlap,
   pitch->rate, pitch->iacc, pitch->state, fadeoptname(pitch->fadeopt));
 }
 */
@@ -170,7 +166,7 @@
     b = 0.5 * (f1+fm1) - f0;
     a = (1.0/6.0) * (f2-f1+fm1-f0-4.0*b);
     c = f1 - a - b - d;
-    
+
     return ((a * x + b) * x + c) * x + d;
 }
 
@@ -180,8 +176,8 @@
  * result put in output buffer obuf of size olen.
  */
 static void interpolation(
-  pitch_t pitch,
-  const sox_sample_t *ibuf, sox_size_t ilen, 
+  priv_t * pitch,
+  const sox_sample_t *ibuf, sox_size_t ilen,
   double * out, sox_size_t olen,
   double rate) /* signed */
 {
@@ -198,13 +194,13 @@
             register double frac = index - ifl;
 
             if (pitch->interopt==PITCH_INTERPOLE_LIN)
-                out[i] = lin((double) ibuf[ifl], 
+                out[i] = lin((double) ibuf[ifl],
                              (double) ibuf[ifl+1],
                              frac);
             else
-                out[i] = cub((double) ibuf[ifl-1], 
-                             (double) ibuf[ifl], 
-                             (double) ibuf[ifl+1], 
+                out[i] = cub((double) ibuf[ifl-1],
+                             (double) ibuf[ifl],
+                             (double) ibuf[ifl+1],
                              (double) ibuf[ifl+2],
                              frac);
         }
@@ -217,13 +213,13 @@
             register double frac = index - ifl;
 
             if (pitch->interopt==PITCH_INTERPOLE_LIN)
-                out[i] = lin((double) ibuf[ifl], 
+                out[i] = lin((double) ibuf[ifl],
                              (double) ibuf[ifl+1],
                              frac);
             else
-                out[i] = cub((double) ibuf[ifl-1], 
-                             (double) ibuf[ifl], 
-                             (double) ibuf[ifl+1], 
+                out[i] = cub((double) ibuf[ifl-1],
+                             (double) ibuf[ifl],
+                             (double) ibuf[ifl+1],
                              (double) ibuf[ifl+2],
                              frac);
         }
@@ -232,16 +228,16 @@
 
 /* from input buffer to acc
  */
-static void process_intput_buffer(pitch_t pitch)
+static void process_intput_buffer(priv_t * pitch)
 {
     register int i, len = pitch->step;
 
     /* forwards sweep */
-    interpolation(pitch, 
-                  pitch->buf+pitch->overlap, pitch->step+pitch->overlap, 
+    interpolation(pitch,
+                  pitch->buf+pitch->overlap, pitch->step+pitch->overlap,
                   pitch->tmp, pitch->step,
                   pitch->rate);
-    
+
     for (i=0; i<len; i++)
         pitch->acc[i] = pitch->fade[i]*pitch->tmp[i];
 
@@ -250,7 +246,7 @@
                   pitch->buf, pitch->step+pitch->overlap,
                   pitch->tmp, pitch->step,
                   -pitch->rate);
-    
+
     for (i=0; i<len; i++)
         pitch->acc[i] += pitch->fade[pitch->step-i-1]*pitch->tmp[i];
 }
@@ -258,10 +254,10 @@
 /*
  * Process options
  */
-static int sox_pitch_getopts(sox_effect_t * effp, int n, char **argv) 
+static int sox_pitch_getopts(sox_effect_t * effp, int n, char **argv)
 {
-    pitch_t pitch = (pitch_t) effp->priv; 
-    
+    priv_t * pitch = (priv_t *) effp->priv;
+
     /* get pitch shift */
     pitch->shift = 0.0; /* default is no change */
 
@@ -294,7 +290,7 @@
 
     /* fade option */
     pitch->fadeopt = PITCH_FADE_DEFAULT; /* default */
-    if (n>3) 
+    if (n>3)
     {
         switch (argv[3][0]) /* what a parser;-) */
         {
@@ -318,7 +314,7 @@
             return lsx_usage(effp);
         }
     }
-    
+
     pitch->coef = 0.25;
     if (n>4 && (!sscanf(argv[4], "%lf", &pitch->coef) ||
                 pitch->coef<0.0 || pitch->coef>0.5))
@@ -332,7 +328,7 @@
  */
 static int sox_pitch_start(sox_effect_t * effp)
 {
-    pitch_t pitch = (pitch_t) effp->priv;
+    priv_t * pitch = (priv_t *) effp->priv;
     register int sample_rate = effp->out_signal.rate;
     unsigned int i;
 
@@ -357,7 +353,7 @@
     if (pitch->rate > 1.0)
         pitch->overlap = (int) ((pitch->rate-1.0)*pitch->step) + 2;
     else
-        pitch->overlap = 2; 
+        pitch->overlap = 2;
 
     pitch->size = pitch->step + 2*pitch->overlap;
 
@@ -375,7 +371,7 @@
     {
         /* does it make sense to have such an option? */
         register double pi_step = M_PI / (pitch->step-1);
-        
+
         for (i=0; i<pitch->step; i++)
             pitch->fade[i] = (double) (HAM0 + HAM1*cos(pi_step*i));
     }
@@ -426,10 +422,10 @@
 
 /* Processes input.
  */
-static int sox_pitch_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
-    pitch_t pitch = (pitch_t) effp->priv;
+    priv_t * pitch = (priv_t *) effp->priv;
     int i, size;
     sox_size_t len, iindex, oindex;
 
@@ -442,7 +438,7 @@
     /* warning:
        because of the asynchronous nature of buffering,
        the output index can reach the buffer limits before full consumption.
-       I put the input index just in case. 
+       I put the input index just in case.
        If the code is correct, eithier len or iindex is redundant.
     */
     while (len>0 && iindex<*isamp && oindex<*osamp)
@@ -488,7 +484,7 @@
                 /* shift input buffer. memmove? */
                 for (i=0; i<2*pitch->overlap; i++)
                     pitch->buf[i] = pitch->buf[i+pitch->step];
-                
+
                 pitch->index = 2*pitch->overlap;
             }
         }
@@ -505,7 +501,7 @@
  */
 static int sox_pitch_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-    pitch_t pitch = (pitch_t) effp->priv;
+    priv_t * pitch = (priv_t *) effp->priv;
     sox_size_t i;
 
     if (pitch->state == pi_input)
@@ -542,14 +538,14 @@
     else
         return SOX_SUCCESS;
 }
-    
+
 /*
- * Do anything required when you stop reading samples.  
- * Don't close input file! 
+ * Do anything required when you stop reading samples.
+ * Don't close input file!
  */
 static int sox_pitch_stop(sox_effect_t * effp)
 {
-    pitch_t pitch = (pitch_t) effp->priv;
+    priv_t * pitch = (priv_t *) effp->priv;
 
     free(pitch->fade);
     free(pitch->tmp);
@@ -570,7 +566,7 @@
   sox_pitch_flow,
   sox_pitch_drain,
   sox_pitch_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_pitch_effect_fn(void)
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -1,5 +1,4 @@
-/*
- * libSoX rate change effect file.
+/* libSoX rate change effect file.
  *
  * July 14, 1998
  * Copyright 1998  K. Bradley, Carnegie Mellon University
@@ -25,7 +24,6 @@
 
 #include "sox_i.h"
 
-#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -44,7 +42,7 @@
   Float *window;  /* this is past_hist[hsize], then input[size]     */
 } polystage;
 
-typedef struct polyphase {
+typedef struct {
   unsigned lcmrate;             /* least common multiple of rates */
   unsigned inskip, outskip;     /* LCM increments for I & O rates */
   double Factor;                 /* out_rate/in_rate               */
@@ -56,17 +54,14 @@
   int win_width;
   Float cutoff;
   int m1[MF], m2[MF], b1[MF], b2[MF]; /* arrays used in optimize_factors */
-} *poly_t;
+} priv_t;
 
-assert_static(sizeof(struct polyphase) <= SOX_MAX_EFFECT_PRIVSIZE, 
-              /* else */ skeleff_PRIVSIZE_too_big);
-
 /*
  * Process options
  */
 static int sox_poly_getopts(sox_effect_t * effp, int n, char **argv)
 {
-  poly_t rate = (poly_t) effp->priv;
+  priv_t * rate = (priv_t *) effp->priv;
 
   rate->win_type = 0;           /* 0: nuttall, 1: hamming */
   rate->win_width = 1024;
@@ -103,7 +98,7 @@
     sox_fail("Polyphase: unknown argument (%s %s)!", argv[0], argv[1]);
     return SOX_EOF;
   }
-  
+
   return SOX_SUCCESS;
 }
 
@@ -190,7 +185,7 @@
   return (p-m);
 }
 
-static int optimize_factors(poly_t rate, unsigned numer, unsigned denom, int *l1, int *l2)
+static int optimize_factors(priv_t * rate, unsigned numer, unsigned denom, int *l1, int *l2)
 {
   unsigned f_min;
   int c_min,u_min,ct1,ct2;
@@ -309,7 +304,7 @@
 
    buffer must already be allocated.
 */
-static void fir_design(poly_t rate, Float *buffer, int length, double cutoff)
+static void fir_design(priv_t * rate, Float *buffer, int length, double cutoff)
 {
     int j;
     double sum;
@@ -343,7 +338,7 @@
 
 static int sox_poly_start(sox_effect_t * effp)
 {
-    poly_t rate = (poly_t) effp->priv;
+    priv_t * rate = (priv_t *) effp->priv;
     static int l1[MF], l2[MF];
     double skip = 0;
     int total, size, uprate;
@@ -417,7 +412,7 @@
       skip *= s->up;
       skip += f_len;
       skip /= s->down;
-      
+
       size = (size * s->up) / s->down;  /* this is integer */
     }
     rate->oskip = skip/2;
@@ -494,7 +489,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)
 {
-  poly_t rate = (poly_t) effp->priv;
+  priv_t * rate = (priv_t *) effp->priv;
   polystage *s0,*s1;
 
   /* Sanity check:  how much can we tolerate? */
@@ -608,7 +603,7 @@
  */
 static int sox_poly_stop(sox_effect_t * effp)
 {
-    poly_t rate = (poly_t)effp->priv;
+    priv_t * rate = (priv_t *)effp->priv;
     sox_size_t k;
 
     for (k = 0; k <= rate->total; k++) {
@@ -632,7 +627,7 @@
   sox_poly_flow,
   sox_poly_drain,
   sox_poly_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_polyphase_effect_fn(void)
--- a/src/prc.c
+++ b/src/prc.c
@@ -1,9 +1,8 @@
-/*
- * Psion Record format (format of sound files used for EPOC machines).
+/* Psion Record format (format of sound files used for EPOC machines).
  * The file normally has no extension, so SoX uses .prc (Psion ReCord).
- * Based (heavily) on the wve.c format file. 
+ * Based (heavily) on the wve.c format file.
  * Hacked by Bert van Leeuwen (bert@e.co.za)
- * 
+ *
  * Header check improved, ADPCM encoding added, and other improvements
  * by Reuben Thomas <rrt@sc3d.org>, using file format info at
  * http://software.frodo.looijaard.name/psiconv/formats/
@@ -28,13 +27,13 @@
  *******************************************************************
  Copyright 1992 by Stichting Mathematisch Centrum, Amsterdam, The
  Netherlands.
- 
+
                         All Rights Reserved
 
  Permission to use, copy, modify, and distribute this software and its
  documentation for any purpose and without fee is hereby granted,
  provided that the above copyright notice appear in all copies and that
- both that copyright notice and this permission notice appear in 
+ both that copyright notice and this permission notice appear in
  supporting documentation, and that the names of Stichting Mathematisch
  Centrum or CWI not be used in advertising or publicity pertaining to
  distribution of the software without specific, written prior permission.
@@ -48,7 +47,7 @@
  OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  ******************************************************************/
 
- 
+
 #include "sox_i.h"
 
 #include "adpcms.h"
@@ -58,20 +57,20 @@
 #include <errno.h>
 #include <limits.h>
 
-typedef struct prcpriv {
+typedef struct {
   uint32_t nsamp, nbytes;
   short padding;
   short repeats;
   off_t data_start;         /* for seeking */
-  struct adpcm_io adpcm;
+  adpcm_io_t adpcm;
   unsigned frame_samp;     /* samples left to read in current frame */
-} *prc_t;
+} priv_t;
 
 static void prcwriteheader(sox_format_t * ft);
 
 static int seek(sox_format_t * ft, sox_size_t offset)
 {
-  prc_t p = (prc_t)ft->priv;
+  priv_t * p = (priv_t *)ft->priv;
   if (ft->encoding.encoding == SOX_ENCODING_ALAW)
     return lsx_offset_seek(ft, p->data_start, offset);
   return SOX_EOF;
@@ -122,7 +121,7 @@
 
 static int startread(sox_format_t * ft)
 {
-  prc_t p = (prc_t)ft->priv;
+  priv_t * p = (priv_t *)ft->priv;
   char head[sizeof(prc_header)];
   uint8_t byte;
   uint16_t reps;
@@ -151,7 +150,7 @@
     lsx_fail_errno(ft, SOX_EHDR, "Invalid application name string %.63s", appname);
     return SOX_EOF;
   }
-        
+
   lsx_readdw(ft, &len);
   p->nsamp = len;
   sox_debug("Number of samples: %d", len);
@@ -169,7 +168,7 @@
 
   lsx_readw(ft, &reps);    /* Number of repeats */
   sox_debug("Repeats: %d", reps);
-        
+
   lsx_readb(ft, &volume);
   sox_debug("Volume: %d", (unsigned)volume);
   if (volume < 1 || volume > 5)
@@ -192,7 +191,7 @@
   ft->signal.channels = 1;
 
   p->data_start = lsx_tell(ft);
-  ft->length = p->nsamp / ft->signal.channels;
+  ft->signal.length = p->nsamp / ft->signal.channels;
 
   if (ft->encoding.encoding == SOX_ENCODING_ALAW) {
     ft->encoding.bits_per_sample = 8;
@@ -246,7 +245,7 @@
 
 static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t samp)
 {
-  prc_t p = (prc_t)ft->priv;
+  priv_t * p = (priv_t *)ft->priv;
 
   sox_debug_more("length now = %d", p->nsamp);
 
@@ -286,7 +285,7 @@
 
 static int stopread(sox_format_t * ft)
 {
-  prc_t p = (prc_t)ft->priv;
+  priv_t * p = (priv_t *)ft->priv;
 
   if (ft->encoding.encoding == SOX_ENCODING_IMA_ADPCM)
     return sox_adpcm_stopread(ft, &p->adpcm);
@@ -305,7 +304,7 @@
 
 static int startwrite(sox_format_t * ft)
 {
-  prc_t p = (prc_t)ft->priv;
+  priv_t * p = (priv_t *)ft->priv;
 
   if (ft->encoding.encoding == SOX_ENCODING_ALAW) {
     if (lsx_rawstartwrite(ft))
@@ -314,7 +313,7 @@
     if (sox_adpcm_ima_start(ft, &p->adpcm))
       return SOX_EOF;
   }
-        
+
   p->nsamp = 0;
   p->nbytes = 0;
   if (p->repeats == 0)
@@ -360,7 +359,7 @@
 
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp)
 {
-  prc_t p = (prc_t)ft->priv;
+  priv_t * p = (priv_t *)ft->priv;
   /* Psion Record seems not to be able to handle frames > 800 samples */
   sox_size_t written = 0;
   sox_debug_more("length now = %d", p->nsamp);
@@ -387,7 +386,7 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-  prc_t p = (prc_t)ft->priv;
+  priv_t * p = (priv_t *)ft->priv;
 
   p->nbytes = lsx_tell(ft) - p->data_start;
 
@@ -406,7 +405,7 @@
 
 static void prcwriteheader(sox_format_t * ft)
 {
-  prc_t p = (prc_t)ft->priv;
+  priv_t * p = (priv_t *)ft->priv;
 
   lsx_writebuf(ft, prc_header, sizeof(prc_header));
   lsx_writes(ft, "\x2arecord.app");
@@ -418,7 +417,7 @@
     lsx_writedw(ft, 0);
   else
     lsx_writedw(ft, 0x100001a1); /* ADPCM */
-  
+
   lsx_writew(ft, 0);             /* Number of repeats */
   lsx_writeb(ft, 3);             /* Volume: use default value of Record.app */
   lsx_writeb(ft, 0);             /* Unused and seems always zero */
@@ -442,7 +441,7 @@
     names, SOX_FILE_LIT_END | SOX_FILE_MONO,
     startread, read_samples, stopread,
     startwrite, write_samples, stopwrite,
-    seek, write_encodings, write_rates
+    seek, write_encodings, write_rates, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/rabbit.c
+++ b/src/rabbit.c
@@ -1,5 +1,4 @@
-/*
- * libsamplerate (aka Secret Rabbit Code) support for sox
+/* libsamplerate (aka Secret Rabbit Code) support for sox
  * (c) Reuben Thomas <rrt@sc3d.org> 2006
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -24,7 +23,6 @@
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
-#include <math.h>
 #include <samplerate.h>
 
 /* Private data for resampling */
@@ -34,7 +32,7 @@
   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} */
-} *rabbit_t;
+} priv_t;
 
 /*
  * Process options
@@ -41,7 +39,7 @@
  */
 static int getopts(sox_effect_t * effp, int argc, char **argv)
 {
-  rabbit_t r = (rabbit_t) effp->priv;
+  priv_t * r = (priv_t *) effp->priv;
   char dummy;     /* To check for extraneous chars. */
 
   r->converter_type = SRC_SINC_BEST_QUALITY;
@@ -67,7 +65,7 @@
 
   r->out_rate = HUGE_VAL;
   if (argc) {
-    if (sscanf(*argv, "%lf %c", &r->out_rate, &dummy) != 1 || r->out_rate <= 0) 
+    if (sscanf(*argv, "%lf %c", &r->out_rate, &dummy) != 1 || r->out_rate <= 0)
       return lsx_usage(effp);
     argc--; argv++;
   }
@@ -80,13 +78,13 @@
  */
 static int start(sox_effect_t * effp)
 {
-  rabbit_t r = (rabbit_t) effp->priv;
+  priv_t * r = (priv_t *) effp->priv;
   int err = 0;
   double out_rate = r->out_rate != HUGE_VAL? r->out_rate : effp->out_signal.rate;
 
   if (effp->in_signal.rate == out_rate)
     return SOX_EFF_NULL;
-          
+
   effp->out_signal.channels = effp->in_signal.channels;
   effp->out_signal.rate = out_rate;
 
@@ -109,7 +107,7 @@
 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)
 {
-  rabbit_t r = (rabbit_t) effp->priv;
+  priv_t * r = (priv_t *) effp->priv;
   SRC_DATA *d = r->data;
   unsigned int channels = effp->in_signal.channels;
   sox_size_t i;
@@ -165,7 +163,7 @@
  */
 static int drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-  rabbit_t r = (rabbit_t) effp->priv;
+  priv_t * r = (priv_t *) effp->priv;
   static sox_size_t isamp = 0;
   r->data->end_of_input = 1;
   return flow(effp, NULL, obuf, &isamp, osamp);
@@ -176,7 +174,7 @@
  */
 static int stop(sox_effect_t * effp)
 {
-  rabbit_t r = (rabbit_t) effp->priv;
+  priv_t * r = (priv_t *) effp->priv;
 
   free(r->data);
   src_delete(r->state);
@@ -188,7 +186,7 @@
   static sox_effect_handler_t handler = {
     "rabbit", "[-c0|-c1|-c2|-c3|-c4] [rate]",
     SOX_EFF_RATE | SOX_EFF_MCHAN,
-    getopts, start, flow, drain, stop, NULL
+    getopts, start, flow, drain, stop, NULL, sizeof(priv_t)
   };
 
   return &handler;
--- a/src/raw-fmt.c
+++ b/src/raw-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
@@ -17,7 +16,7 @@
  */
 
 #include "sox_i.h"
- 
+
 static int raw_start(sox_format_t * ft) {
   return lsx_rawstart(ft, sox_false, sox_false, sox_true, SOX_ENCODING_UNKNOWN, 0);
 }
@@ -32,13 +31,11 @@
     SOX_ENCODING_ALAW, 8, 0,
     SOX_ENCODING_FLOAT, 64, 32, 0,
     0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
-    "Raw PCM, mu-law, or A-law",
-    names, 0,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
+    "Raw PCM, mu-law, or A-law", names, 0,
     raw_start, lsx_rawread , NULL,
     raw_start, lsx_rawwrite, NULL,
-    lsx_rawseek, encodings, NULL
+    lsx_rawseek, encodings, NULL, 0
   };
   return &handler;
 }
--- a/src/raw.c
+++ b/src/raw.c
@@ -1,5 +1,4 @@
-/*
- * libSoX raw I/O
+/* libSoX raw I/O
  *
  * Copyright 1991-2007 Lance Norskog And Sundry Contributors
  * This source code is freely redistributable and may be used for
@@ -53,8 +52,8 @@
     else ft->encoding.bits_per_sample = size;
   }
 
-  if (!ft->length && ft->mode == 'r' && default_length && ft->encoding.bits_per_sample)
-    ft->length = div_bits(lsx_filelength(ft), ft->encoding.bits_per_sample);
+  if (!ft->signal.length && ft->mode == 'r' && default_length && ft->encoding.bits_per_sample)
+    ft->signal.length = div_bits(lsx_filelength(ft), ft->encoding.bits_per_sample);
 
   return SOX_SUCCESS;
 }
@@ -130,8 +129,8 @@
         break;
       }
       break;
-      
-    case 16: 
+
+    case 16:
       switch (ft->encoding.encoding) {
       case SOX_ENCODING_SIGN2:
         return write ? sox_write_sw_samples : sox_read_sw_samples;
@@ -152,7 +151,7 @@
         break;
       }
       break;
-      
+
     case 32:
       switch (ft->encoding.encoding) {
       case SOX_ENCODING_SIGN2:
@@ -165,7 +164,7 @@
         break;
       }
       break;
-      
+
     case 64:
       switch (ft->encoding.encoding) {
       case SOX_ENCODING_FLOAT:
--- a/src/raw.h
+++ b/src/raw.h
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
@@ -29,7 +28,7 @@
     names, flags, \
     id ## _start, lsx_rawread , NULL, \
     id ## _start, lsx_rawwrite, NULL, \
-    NULL, write_encodings, NULL \
+    NULL, write_encodings, NULL, 0 \
   }; \
   return &handler; \
 }
--- a/src/remix.c
+++ b/src/remix.c
@@ -1,6 +1,4 @@
-/*
- * Effect: remix
- * Copyright (c) 2008 robs@users.sourceforge.net
+/* libSoX effect: remix   Copyright (c) 2008 robs@users.sourceforge.net
  *
  * 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
@@ -18,11 +16,9 @@
  */
 
 #include "sox_i.h"
-#include <math.h>
 #include <string.h>
 
-typedef struct remix
-{
+typedef struct {
   enum {semi, automatic, manual} mode;
   unsigned num_out_channels, min_in_channels;
   struct {
@@ -33,11 +29,9 @@
       double   multiplier;
     } * in_specs;
   } * out_specs;
-} * remix_t;
+} priv_t;
+#define p (*(priv_t *)effp->priv)
 
-assert_static(sizeof(struct remix) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ remix_PRIVSIZE_too_big);
-
 #define PARSE(SEP, SCAN, VAR, MIN, SEPARATORS) do {\
   end = strpbrk(text, SEPARATORS); \
   if (end == text) \
@@ -53,16 +47,15 @@
 
 static int parse(sox_effect_t * effp, char * * argv, unsigned channels)
 {
-  remix_t p = (remix_t) effp->priv;
   unsigned i, j;
 
-  p->min_in_channels = 0;
-  for (i = 0; i < p->num_out_channels; ++i) {
+  p.min_in_channels = 0;
+  for (i = 0; i < p.num_out_channels; ++i) {
     sox_bool mul_spec = sox_false;
     char * text, * end;
     if (argv) /* 1st parse only */
-      p->out_specs[i].str = lsx_strdup(argv[i]);
-    for (j = 0, text = p->out_specs[i].str; *text;) {
+      p.out_specs[i].str = lsx_strdup(argv[i]);
+    for (j = 0, text = p.out_specs[i].str; *text;) {
       static char const separators[] = "-vpi,";
       char sep1, sep2;
       int chan1 = 1, chan2 = channels, n;
@@ -85,37 +78,35 @@
         mul_spec = sox_true;
       }
       if (chan2 < chan1) {int t = chan1; chan1 = chan2; chan2 = t;}
-      p->out_specs[i].in_specs = lsx_realloc(p->out_specs[i].in_specs,
-          (j + chan2 - chan1 + 1) * sizeof(*p->out_specs[i].in_specs));
+      p.out_specs[i].in_specs = lsx_realloc(p.out_specs[i].in_specs,
+          (j + chan2 - chan1 + 1) * sizeof(*p.out_specs[i].in_specs));
       while (chan1 <= chan2) {
-        p->out_specs[i].in_specs[j].channel_num = chan1++ - 1;
-        p->out_specs[i].in_specs[j++].multiplier = multiplier;
+        p.out_specs[i].in_specs[j].channel_num = chan1++ - 1;
+        p.out_specs[i].in_specs[j++].multiplier = multiplier;
       }
-      p->min_in_channels = max(p->min_in_channels, (unsigned)chan2);
+      p.min_in_channels = max(p.min_in_channels, (unsigned)chan2);
     }
-    p->out_specs[i].num_in_channels = j;
-    for (j = 0; j < p->out_specs[i].num_in_channels; ++j)
-      if (p->out_specs[i].in_specs[j].multiplier == HUGE_VAL)
-        p->out_specs[i].in_specs[j].multiplier = (p->mode == automatic || (p->mode == semi && !mul_spec)) ?  1. / p->out_specs[i].num_in_channels : 1;
+    p.out_specs[i].num_in_channels = j;
+    for (j = 0; j < p.out_specs[i].num_in_channels; ++j)
+      if (p.out_specs[i].in_specs[j].multiplier == HUGE_VAL)
+        p.out_specs[i].in_specs[j].multiplier = (p.mode == automatic || (p.mode == semi && !mul_spec)) ?  1. / p.out_specs[i].num_in_channels : 1;
   }
-  effp->out_signal.channels = p->num_out_channels;
+  effp->out_signal.channels = p.num_out_channels;
   return SOX_SUCCESS;
 }
 
 static int create(sox_effect_t * effp, int argc, char * * argv)
 {
-  remix_t p = (remix_t) effp->priv;
-  if (argc && !strcmp(*argv, "-m")) p->mode = manual   , ++argv, --argc;
-  if (argc && !strcmp(*argv, "-a")) p->mode = automatic, ++argv, --argc;
-  p->out_specs = lsx_calloc(p->num_out_channels = argc, sizeof(*p->out_specs));
+  if (argc && !strcmp(*argv, "-m")) p.mode = manual   , ++argv, --argc;
+  if (argc && !strcmp(*argv, "-a")) p.mode = automatic, ++argv, --argc;
+  p.out_specs = lsx_calloc(p.num_out_channels = argc, sizeof(*p.out_specs));
   return parse(effp, argv, 1); /* No channels yet; parse with dummy */
 }
 
 static int start(sox_effect_t * effp)
 {
-  remix_t p = (remix_t) effp->priv;
   parse(effp, NULL, effp->in_signal.channels);
-  if (effp->in_signal.channels < p->min_in_channels) {
+  if (effp->in_signal.channels < p.min_in_channels) {
     sox_fail("too few input channels");
     return SOX_EOF;
   }
@@ -125,7 +116,6 @@
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
     sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
 {
-  remix_t p = (remix_t) effp->priv;
   unsigned i, j, len;
   len =  min(*isamp / effp->in_signal.channels, *osamp / effp->out_signal.channels);
   *isamp = len * effp->in_signal.channels;
@@ -133,8 +123,8 @@
 
   for (; len--; ibuf += effp->in_signal.channels) for (j = 0; j < effp->out_signal.channels; j++) {
     double out = 0;
-    for (i = 0; i < p->out_specs[j].num_in_channels; i++)
-      out += ibuf[p->out_specs[j].in_specs[i].channel_num] * p->out_specs[j].in_specs[i].multiplier;
+    for (i = 0; i < p.out_specs[j].num_in_channels; i++)
+      out += ibuf[p.out_specs[j].in_specs[i].channel_num] * p.out_specs[j].in_specs[i].multiplier;
     *obuf++ = SOX_ROUND_CLIP_COUNT(out, effp->clips);
   }
   return SOX_SUCCESS;
@@ -142,13 +132,12 @@
 
 static int kill(sox_effect_t * effp)
 {
-  remix_t p = (remix_t) effp->priv;
   unsigned i;
-  for (i = 0; i < p->num_out_channels; ++i) {
-    free(p->out_specs[i].str);
-    free(p->out_specs[i].in_specs);
+  for (i = 0; i < p.num_out_channels; ++i) {
+    free(p.out_specs[i].str);
+    free(p.out_specs[i].in_specs);
   }
-  free(p->out_specs);
+  free(p.out_specs);
   return SOX_SUCCESS;
 }
 
@@ -156,8 +145,7 @@
 {
   static sox_effect_handler_t handler = {
     "remix", "<0|in-chan[v|d|i volume]{,in-chan[v|d|i volume]}>",
-    SOX_EFF_MCHAN | SOX_EFF_CHAN,
-    create, start, flow, NULL, NULL, kill
+    SOX_EFF_MCHAN | SOX_EFF_CHAN, create, start, flow, NULL, NULL, kill, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/repeat.c
+++ b/src/repeat.c
@@ -1,7 +1,5 @@
-/*
-    Repeat effect file for SoX
-    Copyright (C) 2004 Jan Paul Schmidt <jps@fundament.org>
-
+/* libSoX repeat effect  Copyright (c) 2004 Jan Paul Schmidt <jps@fundament.org>
+ *
  * 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
@@ -20,191 +18,148 @@
 #include "sox_i.h"
 
 #include <stdio.h>
-#include <errno.h>
 #include <string.h>
-#include <sys/types.h> /* for off_t on OS/2 and possibly others */
+#include <sys/types.h>  /* for off_t on OS/2 and possibly others */
 
-typedef struct repeatstuff {
-        FILE *fp;
-        int first_drain;
-        sox_size_t total;
-        sox_size_t remaining;
-        int repeats;
-} *repeat_t;
+typedef struct {
+  FILE * tmp_file;
+  int first_drain;
+  sox_size_t total;
+  sox_size_t remaining;
+  int repeats;
+} priv_t;
+#define p ((priv_t *)effp->priv)
 
-static int sox_repeat_getopts(sox_effect_t * effp, int n, char **argv)
+static int getopts(sox_effect_t * effp, int argc, char **argv)
 {
-        repeat_t repeat = (repeat_t)effp->priv;
-
-        if (n != 1)
-          return lsx_usage(effp);
-
-        if (!(sscanf(argv[0], "%i", &repeat->repeats))) {
-                sox_fail("could not parse repeat parameter");
-                return (SOX_EOF);
-        }
-
-        if (repeat->repeats < 0) {
-                sox_fail("repeat parameter must be positive");
-                return (SOX_EOF);
-        }
-
-        return (SOX_SUCCESS);
+  do {NUMERIC_PARAMETER(repeats, 0, 1e6)} while (0);
+  return argc? lsx_usage(effp) : SOX_SUCCESS;
 }
 
-static int sox_repeat_start(sox_effect_t * effp)
+static int start(sox_effect_t * effp)
 {
-        repeat_t repeat = (repeat_t)effp->priv;
+  if (p->repeats == 0)
+    return SOX_EFF_NULL;
 
-        if (repeat->repeats == 0)
-          return SOX_EFF_NULL;
-
-        if ((repeat->fp = tmpfile()) == NULL) {
-                sox_fail("could not create temporary file");
-                return (SOX_EOF);
-        }
-
-        repeat->first_drain = 1;
-
-        return (SOX_SUCCESS);
+  if ((p->tmp_file = tmpfile()) == NULL) {
+    sox_fail("can't create temporary file: %s", strerror(errno));
+    return SOX_EOF;
+  }
+  p->first_drain = 1;
+  return SOX_SUCCESS;
 }
 
-static int sox_repeat_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf UNUSED,
-                sox_size_t *isamp, sox_size_t *osamp)
+static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
+    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
 {
-        repeat_t repeat = (repeat_t)effp->priv;
-
-        if (fwrite((char *)ibuf, sizeof(sox_sample_t), *isamp, repeat->fp) !=
-                        *isamp) {
-                sox_fail("write error on temporary file");
-                return (SOX_EOF);
-        }
-
-        *osamp = 0;
-
-        return (SOX_SUCCESS);
+  if (fwrite(ibuf, sizeof(*ibuf), *isamp, p->tmp_file) != *isamp) {
+    sox_fail("error writing temporary file: %s", strerror(errno));
+    return SOX_EOF;
+  }
+  (void)obuf, *osamp = 0; /* samples not output until drain */
+  return SOX_SUCCESS;
 }
 
-static int sox_repeat_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
+static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
 {
-        size_t read = 0;
-        sox_sample_t *buf;
-        sox_size_t samp;
-        sox_size_t done;
+  size_t read = 0;
+  sox_sample_t *buf;
+  sox_size_t samp;
+  sox_size_t done;
 
-        repeat_t repeat = (repeat_t)effp->priv;
+  if (p->first_drain == 1) {
+    p->first_drain = 0;
 
-        if (repeat->first_drain == 1) {
-                repeat->first_drain = 0;
+    fseeko(p->tmp_file, (off_t) 0, SEEK_END);
+    p->total = ftello(p->tmp_file);
 
-                fseeko(repeat->fp, (off_t)0, SEEK_END);
-                repeat->total = ftello(repeat->fp);
+    if ((p->total % sizeof(sox_sample_t)) != 0) {
+      sox_fail("corrupted temporary file");
+      return (SOX_EOF);
+    }
 
-                if ((repeat->total % sizeof(sox_sample_t)) != 0) {
-                        sox_fail("corrupted temporary file");
-                        return (SOX_EOF);
-                }
+    p->total /= sizeof(sox_sample_t);
+    p->remaining = p->total;
 
-                repeat->total /= sizeof(sox_sample_t);
-                repeat->remaining = repeat->total;
+    fseeko(p->tmp_file, (off_t) 0, SEEK_SET);
+  }
 
-                fseeko(repeat->fp, (off_t)0, SEEK_SET);
-        }
+  if (p->remaining == 0) {
+    if (p->repeats == 0) {
+      *osamp = 0;
+      return (SOX_EOF);
+    } else {
+      p->repeats--;
+      fseeko(p->tmp_file, (off_t) 0, SEEK_SET);
+      p->remaining = p->total;
+    }
+  }
+  if (*osamp > p->remaining) {
+    buf = obuf;
+    samp = p->remaining;
 
-        if (repeat->remaining == 0) {
-                if (repeat->repeats == 0) {
-                        *osamp = 0;
-                        return (SOX_EOF);
-                } else {
-                        repeat->repeats--;
-                        fseeko(repeat->fp, (off_t)0, SEEK_SET);
-                        repeat->remaining = repeat->total;
-                }
-        }
-        if (*osamp > repeat->remaining) {
-                buf = obuf;
-                samp = repeat->remaining;
+    read = fread((char *) buf, sizeof(sox_sample_t), samp, p->tmp_file);
+    if (read != samp) {
+      perror(strerror(errno));
+      sox_fail("read error on temporary file");
+      return (SOX_EOF);
+    }
 
-                read = fread((char *)buf, sizeof(sox_sample_t), samp,
-                                repeat->fp);
-                if (read != samp) {
-                        perror(strerror(errno));
-                        sox_fail("read error on temporary file");
-                        return(SOX_EOF);
-                }
+    done = samp;
+    buf = &obuf[samp];
+    p->remaining = 0;
 
-                done = samp;
-                buf = &obuf[samp];
-                repeat->remaining = 0;
+    while (p->repeats > 0) {
+      p->repeats--;
+      fseeko(p->tmp_file, (off_t) 0, SEEK_SET);
 
-                while (repeat->repeats > 0) {
-                        repeat->repeats--;
-                        fseeko(repeat->fp, (off_t)0, SEEK_SET);
-
-                        if (repeat->total >= *osamp - done) {
-                                samp = *osamp - done;
-                        } else {
-                                samp = repeat->total;
-                                if (samp > *osamp - done)
-                                        samp = *osamp - done;
-                        }
+      if (p->total >= *osamp - done) {
+        samp = *osamp - done;
+      } else {
+        samp = p->total;
+        if (samp > *osamp - done)
+          samp = *osamp - done;
+      }
 
-                        repeat->remaining = repeat->total - samp;
+      p->remaining = p->total - samp;
 
-                        read = fread((char *)buf, sizeof(sox_sample_t), samp,
-                                        repeat->fp);
-                        if (read != samp) {
-                                perror(strerror(errno));
-                                sox_fail("repeat2: read error on temporary "
-                                                "file\n");
-                                return(SOX_EOF);
-                        }
-
-                        done += samp;
-                        if (done == *osamp)
-                                break;
-                }
-                *osamp = done;
-        }
-        else {
-                read = fread((char *)obuf, sizeof(sox_sample_t), *osamp,
-                                repeat->fp);
-                if (read != *osamp) {
-                        perror(strerror(errno));
-                        sox_fail("repeat3: read error on temporary file");
-                        return(SOX_EOF);
-                }
-                repeat->remaining -= *osamp;
-        }
+      read = fread((char *) buf, sizeof(sox_sample_t), samp, p->tmp_file);
+      if (read != samp) {
+        perror(strerror(errno));
+        sox_fail("repeat2: read error on temporary " "file\n");
+        return (SOX_EOF);
+      }
 
-        if (repeat->remaining == 0)
-            return SOX_EOF;
-        else
-            return SOX_SUCCESS;
+      done += samp;
+      if (done == *osamp)
+        break;
+    }
+    *osamp = done;
+  } else {
+    read = fread((char *) obuf, sizeof(sox_sample_t), *osamp, p->tmp_file);
+    if (read != *osamp) {
+      perror(strerror(errno));
+      sox_fail("repeat3: read error on temporary file");
+      return (SOX_EOF);
+    }
+    p->remaining -= *osamp;
+  }
+
+  if (p->remaining == 0)
+    return SOX_EOF;
+  else
+    return SOX_SUCCESS;
 }
 
-static int sox_repeat_stop(sox_effect_t * effp)
+static int stop(sox_effect_t * effp)
 {
-        repeat_t repeat = (repeat_t)effp->priv;
-
-        fclose(repeat->fp);
-
-        return (SOX_SUCCESS);
+  fclose(p->tmp_file);
+  return SOX_SUCCESS;
 }
 
-static sox_effect_handler_t sox_repeat_effect = {
-  "repeat",
-  "count",
-  SOX_EFF_MCHAN | SOX_EFF_LENGTH,
-  sox_repeat_getopts,
-  sox_repeat_start,
-  sox_repeat_flow,
-  sox_repeat_drain,
-  sox_repeat_stop,
-  NULL
-};
-
 const sox_effect_handler_t *sox_repeat_effect_fn(void)
 {
-    return &sox_repeat_effect;
+  static sox_effect_handler_t effect = {"repeat", "count", SOX_EFF_MCHAN |
+    SOX_EFF_LENGTH, getopts, start, flow, drain, stop, NULL, sizeof(priv_t)};
+  return &effect;
 }
--- a/src/resample.c
+++ b/src/resample.c
@@ -1,5 +1,4 @@
-/*
- * libSoX rate change effect file.
+/* libSoX rate change effect file.
  * Spiffy rate changer using Smith & Wesson Bandwidth-Limited Interpolation.
  * The algorithm is described in "Bandlimited Interpolation -
  * Introduction and Algorithm" by Julian O. Smith III.
@@ -21,8 +20,8 @@
  * July 5, 1991
  * Copyright 1991 Lance Norskog And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Lance Norskog And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Lance Norskog And Sundry Contributors are not responsible for
  * the consequences of using this software.
  *
  * This source code is distributed in the hope that it will be useful,
@@ -39,7 +38,6 @@
 
 #include "sox_i.h"
 
-#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -94,7 +92,7 @@
 #define BUFFSIZE 8192 /*16384*/  /* Total I/O buffer size */
 
 /* Private data for Lerp via LCM file */
-typedef struct resamplestuff {
+typedef struct {
    double Factor;     /* Factor = Fout/Fin sample rates */
    double rolloff;    /* roll-off frequency */
    double beta;       /* passband/stopband tuning magic */
@@ -116,7 +114,7 @@
    long Xp;           /* X[Xp] is position to start filter application   */
    unsigned long Xsize,Ysize; /* size (doubles) of X[],Y[]         */
    double *X, *Y;      /* I/O buffers */
-} *resample_t;
+} priv_t;
 
 static void LpFilter(double c[],
                      long N,
@@ -132,8 +130,8 @@
                long Num,
                int Normalize);
 
-static long SrcUD(resample_t r, long Nx);
-static long SrcEX(resample_t r, long Nx);
+static long SrcUD(priv_t * r, long Nx);
+static long SrcEX(priv_t * r, long Nx);
 
 
 /*
@@ -141,7 +139,7 @@
  */
 static int getopts(sox_effect_t * effp, int n, char **argv)
 {
-        resample_t r = (resample_t) effp->priv;
+        priv_t * r = (priv_t *) effp->priv;
 
         /* These defaults are conservative with respect to aliasing. */
         r->rolloff = 0.80;
@@ -191,13 +189,13 @@
  */
 static int start(sox_effect_t * effp)
 {
-  resample_t r = (resample_t) effp->priv;
+  priv_t * r = (priv_t *) effp->priv;
   long Xoff, gcdrate;
   int i;
 
   if (effp->in_signal.rate == effp->out_signal.rate)
     return SOX_EFF_NULL;
-          
+
   effp->out_signal.channels = effp->in_signal.channels;
 
   r->Factor = effp->out_signal.rate / effp->in_signal.rate;
@@ -273,10 +271,10 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
                      sox_size_t *isamp, sox_size_t *osamp)
 {
-        resample_t r = (resample_t) effp->priv;
+        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);
@@ -299,10 +297,10 @@
         sox_debug_more("Nx %li",Nx);
 
         if (ibuf == NULL) {
-                for(i = r->Xread; i < Nx + r->Xread  ; i++) 
+                for(i = r->Xread; i < Nx + r->Xread  ; i++)
                         r->X[i] = 0;
         } else {
-                for(i = r->Xread; i < Nx + r->Xread  ; i++) 
+                for(i = r->Xread; i < Nx + r->Xread  ; i++)
                         r->X[i] = (double)(*ibuf++)/ISCALE;
         }
         last = i;
@@ -316,7 +314,7 @@
                 return (SOX_SUCCESS);
         }
         if (r->quadr < 0) { /* exact coeff's method */
-                long creep; 
+                long creep;
                 Nout = SrcEX(r, Nproc);
                 sox_debug_more("Nproc %li --> %li",Nproc,Nout);
                 /* Move converter Nproc samples back in time */
@@ -324,7 +322,7 @@
                 /* Advance by number of samples processed */
                 r->Xp += Nproc;
                 /* Calc time accumulation in Time */
-                creep = r->t/r->b - r->Xoff; 
+                creep = r->t/r->b - r->Xoff;
                 if (creep)
                 {
                   r->t -= creep * r->b;  /* Remove time accumulation   */
@@ -332,7 +330,7 @@
                   sox_debug_more("Nproc %ld, creep %ld",Nproc,creep);
                 }
         } else { /* approx coeff's method */
-                long creep; 
+                long creep;
                 Nout = SrcUD(r, Nproc);
                 sox_debug_more("Nproc %li --> %li",Nproc,Nout);
                 /* Move converter Nproc samples back in time */
@@ -340,7 +338,7 @@
                 /* Advance by number of samples processed */
                 r->Xp += Nproc;
                 /* Calc time accumulation in Time */
-                creep = r->Time - r->Xoff; 
+                creep = r->Time - r->Xoff;
                 if (creep)
                 {
                   r->Time -= creep;   /* Remove time accumulation   */
@@ -354,14 +352,14 @@
         /* Copy back portion of input signal that must be re-used */
         k = r->Xp - r->Xoff;
         sox_debug_more("k %li, last %li",k,last);
-        for (i=0; i<last - k; i++) 
+        for (i=0; i<last - k; i++)
             r->X[i] = r->X[i+k];
 
         /* Pos in input buff to read new data into */
-        r->Xread = i;                 
+        r->Xread = i;
         r->Xp = r->Xoff;
 
-        for(i=0; i < Nout; i++) { 
+        for(i=0; i < Nout; i++) {
                 double ftemp = r->Y[i] * ISCALE;
 
                 SOX_SAMPLE_CLIP_COUNT(ftemp, effp->clips);
@@ -380,7 +378,7 @@
  */
 static int drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-        resample_t r = (resample_t) effp->priv;
+        priv_t * r = (priv_t *) effp->priv;
         long isamp_res, osamp_res;
         sox_sample_t *Obuf;
         int rc;
@@ -415,22 +413,22 @@
 }
 
 /*
- * Do anything required when you stop reading samples.  
- * Don't close input file! 
+ * Do anything required when you stop reading samples.
+ * Don't close input file!
  */
 static int stop(sox_effect_t * effp)
 {
-        resample_t r = (resample_t) effp->priv;
-        
+        priv_t * r = (priv_t *) effp->priv;
+
         free(r->Imp - 1);
         free(r->X);
-        /* free(r->Y); Y is in same block starting at X */ 
+        /* free(r->Y); Y is in same block starting at X */
         return (SOX_SUCCESS);
 }
 
 /* over 90% of CPU time spent in this iprodUD() function */
 /* quadratic interpolation */
-static double qprodUD(const double Imp[], const double *Xp, long Inc, double T0, 
+static double qprodUD(const double Imp[], const double *Xp, long Inc, double T0,
                       long dhb, long ct)
 {
   const double f = 1.0/(1<<La);
@@ -462,7 +460,7 @@
 }
 
 /* linear interpolation */
-static double iprodUD(const double Imp[], const double *Xp, long Inc, 
+static double iprodUD(const double Imp[], const double *Xp, long Inc,
                       double T0, long dhb, long ct)
 {
   const double f = 1.0/(1<<La);
@@ -490,7 +488,7 @@
 /* From resample:filters.c */
 /* Sampling rate conversion subroutine */
 
-static long SrcUD(resample_t r, long Nx)
+static long SrcUD(priv_t * r, long Nx)
 {
    double *Ystart, *Y;
    double Factor;
@@ -534,7 +532,7 @@
 }
 
 /* exact coeff's */
-static double prodEX(const double Imp[], const double *Xp, 
+static double prodEX(const double Imp[], const double *Xp,
                      long Inc, long T0, long dhb, long ct)
 {
   double v;
@@ -551,7 +549,7 @@
   return v;
 }
 
-static long SrcEX(resample_t r, long Nx)
+static long SrcEX(priv_t * r, long Nx)
 {
    double *Ystart, *Y;
    double Factor;
@@ -586,7 +584,7 @@
    return (Y - Ystart);        /* Return the number of output samples */
 }
 
-int lsx_makeFilter(double Imp[], long Nwing, double Froll, double Beta, 
+int lsx_makeFilter(double Imp[], long Nwing, double Froll, double Beta,
                long Num, int Normalize)
 {
    double *ImpR;
@@ -617,7 +615,7 @@
          DCgain += ImpR[i];
       DCgain = 2*DCgain + ImpR[0];    /* DC gain of real coefficients */
       sox_debug("DCgain err=%.12f",DCgain-1.0);
-  
+
       DCgain = 1.0/DCgain;
       for (i=0; i<Mwing; i++)
          Imp[i] = ImpR[i]*DCgain;
@@ -701,7 +699,7 @@
       double x = M_PI*(double)i/(double)(Num);
       c[i] = sin(x*frq)/x;
    }
-  
+
    if (Beta>2) { /* Apply Kaiser window to filter coeffs: */
       double IBeta = 1.0/Izero(Beta);
       for (i=1; i<N; i++) {
@@ -720,7 +718,7 @@
 {
   static sox_effect_handler_t handler = {
      "resample", "[ -qs | -q | -ql ] [ rolloff [ beta ] ]",
-     SOX_EFF_RATE, getopts, start, flow, drain, stop, NULL
+     SOX_EFF_RATE, getopts, start, flow, drain, stop, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/reverb.c
+++ b/src/reverb.c
@@ -1,5 +1,4 @@
-/*
- * Effect: stereo reverberation
+/* libSoX effect: stereo reverberation
  * Copyright (c) 2007 robs@users.sourceforge.net
  * Filter design based on freeverb by Jezar at Dreampoint.
  *
@@ -20,7 +19,6 @@
 
 #include "sox_i.h"
 #include "fifo.h"
-#include <math.h>
 
 #define lsx_zalloc(var, n) var = lsx_calloc(n, sizeof(*var))
 #define filter_create(p, n) (p)->ptr=lsx_zalloc((p)->buffer, (p)->size=(size_t)(n))
@@ -57,7 +55,7 @@
   allpass_lengths[] = {225, 341, 441, 556};
 #define stereo_adjust 12
 
-typedef struct filter_array {
+typedef struct {
   filter_t comb   [array_length(comb_lengths)];
   filter_t allpass[array_length(allpass_lengths)];
 } filter_array_t;
@@ -103,7 +101,7 @@
     filter_delete(&p->comb[i]);
 }
 
-typedef struct reverb {
+typedef struct {
   float feedback;
   float hf_damping;
   float gain;
@@ -160,7 +158,7 @@
 
 /*------------------------------- SoX Wrapper --------------------------------*/
 
-typedef struct priv {
+typedef struct {
   double reverberance, hf_damping, pre_delay_ms;
   double stereo_depth, wet_gain_dB, room_scale;
   sox_bool wet_only;
@@ -171,14 +169,10 @@
     float * dry, * wet[2];
   } chan[2];
 } priv_t;
+#define p ((priv_t *)effp->priv)
 
-assert_static(sizeof(struct priv) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ EFFECT_PRIVSIZE_too_big);
-
 static int getopts(sox_effect_t * effp, int argc, char **argv)
 {
-  priv_t * p = (priv_t *) effp->priv;
-
   p->reverberance = p->hf_damping = 50; /* Set non-zero defaults */
   p->stereo_depth = p->room_scale = 100;
 
@@ -198,9 +192,8 @@
 
 static int start(sox_effect_t * effp)
 {
-  priv_t * p = (priv_t *) effp->priv;
   size_t i;
-  
+
   p->ichannels = p->ochannels = 1;
   effp->out_signal.rate = effp->in_signal.rate;
   if (effp->in_signal.channels > 2 && p->stereo_depth) {
@@ -223,13 +216,12 @@
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
                 sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
 {
-  priv_t * p = (priv_t *) effp->priv;
   sox_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)
     p->chan[c].dry = fifo_write(&p->chan[c].reverb.input_fifo, len, 0);
-  for (i = 0; i < len; ++i) for (c = 0; c < p->ichannels; ++c) 
+  for (i = 0; i < len; ++i) for (c = 0; c < p->ichannels; ++c)
     p->chan[c].dry[i] = SOX_SAMPLE_TO_FLOAT_32BIT(*ibuf++, effp->clips);
   for (c = 0; c < p->ichannels; ++c)
     reverb_process(&p->chan[c].reverb, len);
@@ -247,7 +239,6 @@
 
 static int stop(sox_effect_t * effp)
 {
-  priv_t * p = (priv_t *) effp->priv;
   size_t i;
   for (i = 0; i < p->ichannels; ++i)
     reverb_delete(&p->chan[i].reverb);
@@ -256,8 +247,7 @@
 
 sox_effect_handler_t const *sox_reverb_effect_fn(void)
 {
-  static sox_effect_handler_t handler = {
-    "reverb", 
+  static sox_effect_handler_t handler = {"reverb",
     "[-w|--wet-only]"
     " [reverberance (50%)"
     " [HF-damping (50%)"
@@ -265,7 +255,8 @@
     " [stereo-depth (100%)"
     " [pre-delay (0ms)"
     " [wet-gain (0dB)"
-    "]]]]]]", SOX_EFF_MCHAN, getopts, start, flow, NULL, stop, NULL
+    "]]]]]]",
+    SOX_EFF_MCHAN, getopts, start, flow, NULL, stop, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/reverse.c
+++ b/src/reverse.c
@@ -1,9 +1,8 @@
-/*
- * June 1, 1992
+/* June 1, 1992
  * Copyright 1992 Guido van Rossum And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Guido van Rossum And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Guido van Rossum And Sundry Contributors are not responsible for
  * the consequences of using this software.
  */
 
@@ -14,18 +13,14 @@
 #include "sox_i.h"
 #include <string.h>
 
-typedef struct reverse {
+typedef struct {
   off_t         pos;
   FILE          * tmp_file;
-} * priv_t;
+} priv_t;
+#define p ((priv_t *)effp->priv)
 
-assert_static(sizeof(struct reverse) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ reverse_PRIVSIZE_too_big);
-
 static int start(sox_effect_t * effp)
 {
-  priv_t p = (priv_t)effp->priv;
-
   p->pos = 0;
   p->tmp_file = tmpfile();
   if (p->tmp_file == NULL) {
@@ -38,8 +33,6 @@
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
     sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
 {
-  priv_t p = (priv_t)effp->priv;
-
   if (fwrite(ibuf, sizeof(*ibuf), *isamp, p->tmp_file) != *isamp) {
     sox_fail("error writing temporary file: %s", strerror(errno));
     return SOX_EOF;
@@ -50,7 +43,6 @@
 
 static int drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-  priv_t p = (priv_t) effp->priv;
   size_t i, j;
 
   if (p->pos == 0) {
@@ -78,8 +70,6 @@
 
 static int stop(sox_effect_t * effp)
 {
-  priv_t p = (priv_t)effp->priv;
-
   fclose(p->tmp_file); /* auto-deleted by tmpfile */
   return SOX_SUCCESS;
 }
@@ -87,7 +77,7 @@
 sox_effect_handler_t const * sox_reverse_effect_fn(void)
 {
   static sox_effect_handler_t handler = {
-    "reverse", NULL, 0, NULL, start, flow, drain, stop, NULL
+    "reverse", NULL, 0, NULL, start, flow, drain, stop, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/s1-fmt.c
+++ b/src/s1-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/s2-fmt.c
+++ b/src/s2-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/s3-fmt.c
+++ b/src/s3-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/s4-fmt.c
+++ b/src/s4-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/sf.c
+++ b/src/sf.c
@@ -1,5 +1,4 @@
-/*
- * File format: IRCAM SoundFile   (c) 2008 robs@users.sourceforge.net
+/* libSoX file format: IRCAM SoundFile   (c) 2008 robs@users.sourceforge.net
  *
  * See http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/IRCAM/IRCAM.html
  *
@@ -79,7 +78,7 @@
 
   if (lsx_readchars(ft, magic, sizeof(magic)))
     return SOX_EOF;
- 
+
   for (i = 0; id[i].desc && memcmp(magic, id[i].str, sizeof(magic)); ++i);
   if (!id[i].desc) {
     lsx_fail_errno(ft, SOX_EHDR, "sf: can't find IRCAM identifier");
@@ -90,7 +89,7 @@
 
   if (lsx_readf(ft, &rate) || lsx_readdw(ft, &channels) || lsx_readdw(ft, &ft_encoding))
     return SOX_EOF;
-  
+
   if (!(encoding = sox_enc(ft_encoding, &bits_per_sample))) {
     lsx_fail_errno(ft, SOX_EFMT, "sf: unsupported encoding %#x)", ft_encoding);
     return SOX_EOF;
@@ -104,7 +103,7 @@
         free(buf);
         return SOX_EOF;
       }
-      sox_append_comments(&ft->comments, buf);
+      sox_append_comments(&ft->oob.comments, buf);
       free(buf);
     }
     else if (lsx_skipbytes(ft, size))
@@ -112,13 +111,13 @@
   } while (code);
   if (lsx_skipbytes(ft, FIXED_HDR - (sox_size_t)lsx_tell(ft)))
     return SOX_EOF;
-  
+
   return lsx_check_read_params(ft, channels, rate, encoding, bits_per_sample, (off_t)0);
 }
 
 static int write_header(sox_format_t * ft)
 {
-  char * comment  = sox_cat_comments(ft->comments);
+  char * comment  = sox_cat_comments(ft->oob.comments);
   size_t len      = min(FIXED_HDR - 26, strlen(comment)) + 1; /* null-terminated */
   size_t info_len = max(4, (len + 3) & ~3u); /* Minimum & multiple of 4 bytes */
   int i = ft->encoding.reverse_bytes == MACHINE_IS_BIGENDIAN? 0 : 2;
@@ -149,7 +148,7 @@
     names, SOX_FILE_LIT_END,
     startread, lsx_rawread, NULL,
     write_header, lsx_rawwrite, NULL,
-    lsx_rawseek, write_encodings, NULL
+    lsx_rawseek, write_encodings, NULL, 0
   };
   return &handler;
 }
--- a/src/silence.c
+++ b/src/silence.c
@@ -4,7 +4,7 @@
  * Minor addition by Donnie Smith 13.08.2003
  *
  * This effect can delete samples from the start of a sound file
- * until it sees a specified count of samples exceed a given threshold 
+ * until it sees a specified count of samples exceed a given threshold
  * (any of the channels).
  * This effect can also delete samples from the end of a sound file
  * when it sees a specified count of samples below a given threshold
@@ -16,7 +16,6 @@
 #include "sox_i.h"
 
 #include <string.h>
-#include <math.h>
 
 /* Private data for silence effect. */
 
@@ -26,8 +25,7 @@
 #define SILENCE_COPY_FLUSH  3
 #define SILENCE_STOP        4
 
-typedef struct silencestuff
-{
+typedef struct {
     char        start;
     int         start_periods;
     char        *start_duration_str;
@@ -63,14 +61,14 @@
 
     /* State Machine */
     char        mode;
-} *silence_t;
+} priv_t;
 
 static void clear_rms(sox_effect_t * effp)
 
 {
-    silence_t silence = (silence_t) effp->priv;
+    priv_t * silence = (priv_t *) effp->priv;
 
-    memset(silence->window, 0, 
+    memset(silence->window, 0,
            silence->window_size * sizeof(double));
 
     silence->window_current = silence->window;
@@ -80,7 +78,7 @@
 
 static int sox_silence_getopts(sox_effect_t * effp, int n, char **argv)
 {
-    silence_t   silence = (silence_t) effp->priv;
+    priv_t *   silence = (priv_t *) effp->priv;
     int parse_count;
 
     /* check for option switches */
@@ -125,7 +123,7 @@
                     &silence->start_duration,'s') == NULL)
           return lsx_usage(effp);
 
-        parse_count = sscanf(argv[1], "%lf%c", &silence->start_threshold, 
+        parse_count = sscanf(argv[1], "%lf%c", &silence->start_threshold,
                 &silence->start_unit);
         if (parse_count < 1)
           return lsx_usage(effp);
@@ -166,7 +164,7 @@
                     &silence->stop_duration,'s') == NULL)
           return lsx_usage(effp);
 
-        parse_count = sscanf(argv[1], "%lf%c", &silence->stop_threshold, 
+        parse_count = sscanf(argv[1], "%lf%c", &silence->stop_threshold,
                              &silence->stop_unit);
         if (parse_count < 1)
           return lsx_usage(effp);
@@ -205,7 +203,7 @@
             sox_fail("Invalid unit specified");
             return(SOX_EOF);
         }
-        if ((silence->stop_unit == '%') && ((silence->stop_threshold < 0.0) || 
+        if ((silence->stop_unit == '%') && ((silence->stop_threshold < 0.0) ||
                     (silence->stop_threshold > 100.0)))
         {
             sox_fail("silence threshold should be between 0.0 and 100.0 %%");
@@ -222,13 +220,13 @@
 
 static int sox_silence_start(sox_effect_t * effp)
 {
-        silence_t       silence = (silence_t) effp->priv;
+        priv_t *       silence = (priv_t *) effp->priv;
 
         /* When you want to remove silence, small window sizes are
          * better or else RMS will look like non-silence at
          * aburpt changes from load to silence.
          */
-        silence->window_size = (effp->in_signal.rate / 50) * 
+        silence->window_size = (effp->in_signal.rate / 50) *
                                effp->in_signal.channels;
         silence->window = (double *)lsx_malloc(silence->window_size *
                                            sizeof(double));
@@ -308,7 +306,7 @@
 
 static sox_sample_t compute_rms(sox_effect_t * effp, sox_sample_t sample)
 {
-    silence_t silence = (silence_t) effp->priv;
+    priv_t * silence = (priv_t *) effp->priv;
     double new_sum;
     sox_sample_t rms;
 
@@ -323,7 +321,7 @@
 
 static void update_rms(sox_effect_t * effp, sox_sample_t sample)
 {
-    silence_t silence = (silence_t) effp->priv;
+    priv_t * silence = (priv_t *) effp->priv;
 
     silence->rms_sum -= *silence->window_current;
     *silence->window_current = ((double)sample * (double)sample);
@@ -336,10 +334,10 @@
 
 /* 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, 
+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)
 {
-    silence_t silence = (silence_t) effp->priv;
+    priv_t * silence = (priv_t *) effp->priv;
     int threshold;
     sox_size_t i, j;
     sox_size_t nrOfTicks, nrOfInSamplesRead, nrOfOutSamplesWritten;
@@ -357,8 +355,8 @@
              * prevent getting buffers out of sync.
              */
 silence_trim:
-            nrOfTicks = min((*isamp-nrOfInSamplesRead), 
-                            (*osamp-nrOfOutSamplesWritten)) / 
+            nrOfTicks = min((*isamp-nrOfInSamplesRead),
+                            (*osamp-nrOfOutSamplesWritten)) /
                            effp->in_signal.channels;
             for(i = 0; i < nrOfTicks; i++)
             {
@@ -367,7 +365,7 @@
                 {
                     threshold |= aboveThreshold(effp,
                                                 compute_rms(effp, ibuf[j]),
-                                                silence->start_threshold, 
+                                                silence->start_threshold,
                                                 silence->start_unit);
                 }
 
@@ -405,7 +403,7 @@
                     {
                         update_rms(effp, ibuf[j]);
                     }
-                    ibuf += effp->in_signal.channels; 
+                    ibuf += effp->in_signal.channels;
                     nrOfInSamplesRead += effp->in_signal.channels;
                 }
             } /* for nrOfTicks */
@@ -414,8 +412,8 @@
         case SILENCE_TRIM_FLUSH:
 silence_trim_flush:
             nrOfTicks = min((silence->start_holdoff_end -
-                             silence->start_holdoff_offset), 
-                             (*osamp-nrOfOutSamplesWritten)); 
+                             silence->start_holdoff_offset),
+                             (*osamp-nrOfOutSamplesWritten));
             for(i = 0; i < nrOfTicks; i++)
             {
                 *obuf++ = silence->start_holdoff[silence->start_holdoff_offset++];
@@ -442,9 +440,9 @@
              * Case A:
              *
              * Case 1a:
-             * If previous silence was detect then see if input sample is 
+             * If previous silence was detect then see if input sample is
              * above threshold.  If found then flush out hold off buffer
-             * and copy over to output buffer.  
+             * and copy over to output buffer.
              *
              * Case 1b:
              * If no previous silence detect then see if input sample
@@ -457,7 +455,7 @@
              * buffer.  Even though it wasn't put in output
              * buffer, inform user that input was consumed.
              *
-             * If hold off buffer is full after this then stop 
+             * If hold off buffer is full after this then stop
              * copying data and discard data in hold off buffer.
              *
              * Special leave_silence logic:
@@ -472,8 +470,8 @@
              *
              */
 silence_copy:
-            nrOfTicks = min((*isamp-nrOfInSamplesRead), 
-                            (*osamp-nrOfOutSamplesWritten)) / 
+            nrOfTicks = min((*isamp-nrOfInSamplesRead),
+                            (*osamp-nrOfOutSamplesWritten)) /
                            effp->in_signal.channels;
             if (silence->stop)
             {
@@ -483,9 +481,9 @@
                     threshold = 1;
                     for (j = 0; j < effp->in_signal.channels; j++)
                     {
-                        threshold &= aboveThreshold(effp, 
+                        threshold &= aboveThreshold(effp,
                                                     compute_rms(effp, ibuf[j]),
-                                                    silence->stop_threshold, 
+                                                    silence->stop_threshold,
                                                     silence->stop_unit);
                     }
 
@@ -534,15 +532,15 @@
                             nrOfInSamplesRead++;
                         }
 
-                        /* Check if holdoff buffer is greater than duration 
+                        /* Check if holdoff buffer is greater than duration
                          */
-                        if (silence->stop_holdoff_end >= 
+                        if (silence->stop_holdoff_end >=
                                 silence->stop_duration)
                         {
                             /* Increment found counter and see if this
                              * is the last period.  If so then exit.
                              */
-                            if (++silence->stop_found_periods >= 
+                            if (++silence->stop_found_periods >=
                                     silence->stop_periods)
                             {
                                 silence->stop_holdoff_offset = 0;
@@ -569,7 +567,7 @@
                             }
                             else
                             {
-                                /* Flush this buffer and start 
+                                /* Flush this buffer and start
                                  * looking again.
                                  */
                                 silence->mode = SILENCE_COPY_FLUSH;
@@ -593,7 +591,7 @@
         case SILENCE_COPY_FLUSH:
 silence_copy_flush:
             nrOfTicks = min((silence->stop_holdoff_end -
-                                silence->stop_holdoff_offset), 
+                                silence->stop_holdoff_offset),
                             (*osamp-nrOfOutSamplesWritten));
 
             for(i = 0; i < nrOfTicks; i++)
@@ -625,7 +623,7 @@
 
 static int sox_silence_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-    silence_t silence = (silence_t) effp->priv;
+    priv_t * silence = (priv_t *) effp->priv;
     sox_size_t i;
     sox_size_t nrOfTicks, nrOfOutSamplesWritten = 0;
 
@@ -632,10 +630,10 @@
     /* Only if in flush mode will there be possible samples to write
      * out during drain() call.
      */
-    if (silence->mode == SILENCE_COPY_FLUSH || 
+    if (silence->mode == SILENCE_COPY_FLUSH ||
         silence->mode == SILENCE_COPY)
     {
-        nrOfTicks = min((silence->stop_holdoff_end - 
+        nrOfTicks = min((silence->stop_holdoff_end -
                             silence->stop_holdoff_offset), *osamp);
         for(i = 0; i < nrOfTicks; i++)
         {
@@ -661,7 +659,7 @@
 
 static int sox_silence_stop(sox_effect_t * effp)
 {
-    silence_t silence = (silence_t) effp->priv;
+    priv_t * silence = (priv_t *) effp->priv;
 
     free(silence->window);
     free(silence->start_holdoff);
@@ -671,7 +669,7 @@
 
 static int kill(sox_effect_t * effp)
 {
-  silence_t silence = (silence_t) effp->priv;
+  priv_t * silence = (priv_t *) effp->priv;
 
   free(silence->start_duration_str);
   free(silence->stop_duration_str);
@@ -687,7 +685,7 @@
   sox_silence_flow,
   sox_silence_drain,
   sox_silence_stop,
-  kill
+  kill, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_silence_effect_fn(void)
--- a/src/skeleff.c
+++ b/src/skeleff.c
@@ -1,7 +1,6 @@
-/*
- * skeleff - Skeleton Effect.  Use as sample for new effects.
+/* libSoX effect: Skeleton effect used as sample for creating new effects.
  *
- * Copyright 1999 Chris Bagwell And Sundry Contributors
+ * Copyright 1999-2008 Chris Bagwell And SoX Contributors
  *
  * 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
@@ -21,13 +20,10 @@
 #include "sox_i.h"
 
 /* Private data for effect */
-typedef struct skeleff {
+typedef struct {
   int  localdata;
-} *skeleff_t;
+} priv_t;
 
-assert_static(sizeof(struct skeleff) <= SOX_MAX_EFFECT_PRIVSIZE, 
-              /* else */ skeleff_PRIVSIZE_too_big);
-
 /*
  * Process command-line options but don't do other
  * initialization now: effp->in_signal & effp->out_signal are not
@@ -35,7 +31,7 @@
  */
 static int getopts(sox_effect_t * effp, int n, char UNUSED **argv)
 {
-  skeleff_t UNUSED skeleff = (skeleff_t)effp->priv;
+  priv_t * UNUSED p = (priv_t *)effp->priv;
 
   if (n && n != 1)
     return lsx_usage(effp);
@@ -61,10 +57,10 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
                            sox_size_t *isamp, sox_size_t *osamp)
 {
-  skeleff_t UNUSED skeleff = (skeleff_t)effp->priv;
+  priv_t * UNUSED p = (priv_t *)effp->priv;
   sox_size_t len, done;
 
   switch (effp->out_signal.channels) {
@@ -81,10 +77,10 @@
         ibuf += 2;
         obuf += 2;
       }
-        
+
     *isamp = len * 2;
     *osamp = len * 2;
-        
+
     break;
   }
 
@@ -105,7 +101,7 @@
 }
 
 /*
- * Do anything required when you stop reading samples.  
+ * Do anything required when you stop reading samples.
  */
 static int stop(sox_effect_t UNUSED * effp)
 {
@@ -113,7 +109,7 @@
 }
 
 /*
- * Do anything required when you kill an effect.  
+ * Do anything required when you kill an effect.
  *      (free allocated memory, etc.)
  */
 static int kill(sox_effect_t UNUSED * effp)
@@ -121,26 +117,7 @@
   return SOX_SUCCESS;
 }
 
-
 /*
- * Effect descriptor.
- * If no specific processing is needed for any of
- * the 6 functions, then the function above can be deleted
- * and 0 used in place of the its name below.
- */
-static sox_effect_handler_t sox_skel_effect = {
-  "skel",
-  "[OPTION]",
-  SOX_EFF_MCHAN,
-  getopts,
-  start,
-  flow,
-  drain,
-  stop,
-  kill,
-};
-
-/*
  * Function returning effect descriptor. This should be the only
  * externally visible object.
  */
@@ -147,5 +124,15 @@
 const sox_effect_handler_t *sox_skel_effect_fn(void);
 const sox_effect_handler_t *sox_skel_effect_fn(void)
 {
+  /*
+   * Effect descriptor.
+   * If no specific processing is needed for any of
+   * the 6 functions, then the function above can be deleted
+   * and NULL used in place of the its name below.
+   */
+  static sox_effect_handler_t sox_skel_effect = {
+    "skel", "[OPTION]", SOX_EFF_MCHAN,
+    getopts, start, flow, drain, stop, kill, sizeof(priv_t)
+  };
   return &sox_skel_effect;
 }
--- a/src/skelform.c
+++ b/src/skelform.c
@@ -1,5 +1,4 @@
-/*
- * libSoX skeleton file format handler.
+/* libSoX skeleton file format handler.
  *
  * Copyright 1999 Chris Bagwell And Sundry Contributors
  *
@@ -23,14 +22,10 @@
 #include <string.h>
 
 /* Private data for SKEL file */
-typedef struct skelform
-{
+typedef struct {
   sox_size_t remaining_samples;
-} *skelform_t;
+} priv_t;
 
-assert_static(sizeof(struct skelform) <= SOX_MAX_FILE_PRIVSIZE, 
-              /* else */ skel_PRIVSIZE_too_big);
-
 /* Note that if any of your methods doesn't need to do anything, you
    can instead use the relevant sox_*_nothing* method */
 
@@ -43,7 +38,7 @@
  */
 static int startread(sox_format_t * ft)
 {
-  skelform_t sk = (skelform_t)ft->priv;
+  priv_t * sk = (priv_t *)ft->priv;
   sox_size_t samples_in_file;
 
   /* If you need to seek around the input file. */
@@ -62,7 +57,7 @@
   ft->signal.channels = 1; /* or 2 or 3 ... */
   ft->encoding.bits_per_sample = 8; /* or 16 ... */
   ft->encoding.encoding = SOX_ENCODING_UNSIGNED; /* or SIGN2 ... */
-  sox_append_comment(&ft->comments, "any comment in file header.");
+  sox_append_comment(&ft->oob.comments, "any comment in file header.");
 
   /* If your format doesn't have a header then samples_in_file
    * can be determined by the file size.
@@ -70,7 +65,7 @@
   samples_in_file = lsx_filelength(ft) / (ft->encoding.bits_per_sample >> 3);
 
   /* If you can detect the length of your file, record it here. */
-  ft->length = samples_in_file;
+  ft->signal.length = samples_in_file;
   sk->remaining_samples = samples_in_file;
 
   return SOX_SUCCESS;
@@ -82,7 +77,7 @@
  */
 static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-  skelform_t UNUSED sk = (skelform_t)ft->priv;
+  priv_t * UNUSED sk = (priv_t *)ft->priv;
   sox_size_t done;
   unsigned char sample;
 
@@ -121,7 +116,7 @@
 
 static int startwrite(sox_format_t * ft)
 {
-  skelform_t UNUSED sk = (skelform_t)ft->priv;
+  priv_t * UNUSED sk = (priv_t *)ft->priv;
 
   /* If you have to seek around the output file. */
   /* If header contains a length value then seeking will be
@@ -157,7 +152,7 @@
  */
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-  skelform_t sk = (skelform_t)ft->priv;
+  priv_t * sk = (priv_t *)ft->priv;
   sox_size_t done = 0;
 
   (void)sk;
@@ -216,7 +211,7 @@
     names, 0,
     startread, read_samples, stopread,
     startwrite, write_samples, stopwrite,
-    seek, encodings, NULL
+    seek, encodings, NULL, sizeof(priv_t)
   };
 
   return &handler;
--- a/src/smp.c
+++ b/src/smp.c
@@ -1,7 +1,6 @@
-/*
- * libSoX SampleVision file format handler.
+/* libSoX SampleVision file format handler.
  * Output is always in little-endian (80x86/VAX) order.
- * 
+ *
  * Derived from: libSoX skeleton handler file.
  *
  * Add: Loop point verbose info.  It's a start, anyway.
@@ -11,8 +10,8 @@
  * June 30, 1992
  * Copyright 1992 Leigh Smith And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Leigh Smith And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Leigh Smith And Sundry Contributors are not responsible for
  * the consequences of using this software.
  */
 
@@ -60,12 +59,12 @@
 };
 
 /* Private data for SMP file */
-typedef struct smpstuff {
+typedef struct {
   uint32_t NoOfSamps;           /* Sample data count in words */
   sox_size_t dataStart;
   /* comment memory resides in private data because it's small */
   char comment[COMMENTLEN + NAMELEN + 3];
-} *smp_t;
+} priv_t;
 
 static char *SVmagic = "SOUND SAMPLE DATA ", *SVvers = "2.1 ";
 
@@ -81,14 +80,14 @@
         lsx_readw(ft, (unsigned short *)&trash16); /* read reserved word */
         for(i = 0; i < 8; i++) {        /* read the 8 loops */
                 lsx_readdw(ft, &(trailer->loops[i].start));
-                ft->loops[i].start = trailer->loops[i].start;
+                ft->oob.loops[i].start = trailer->loops[i].start;
                 lsx_readdw(ft, &(trailer->loops[i].end));
-                ft->loops[i].length = 
+                ft->oob.loops[i].length =
                         trailer->loops[i].end - trailer->loops[i].start;
                 lsx_readb(ft, (unsigned char *)&(trailer->loops[i].type));
-                ft->loops[i].type = trailer->loops[i].type;
+                ft->oob.loops[i].type = trailer->loops[i].type;
                 lsx_readw(ft, (unsigned short *)&(trailer->loops[i].count));
-                ft->loops[i].count = trailer->loops[i].count;
+                ft->oob.loops[i].count = trailer->loops[i].count;
         }
         for(i = 0; i < 8; i++) {        /* read the 8 markers */
                 if (lsx_readbuf(ft, trailer->markers[i].name, MARKERLEN) != MARKERLEN)
@@ -114,17 +113,17 @@
         int i;
 
         for(i = 0; i < 8; i++) {        /* copy the 8 loops */
-            if (ft->loops[i].type != 0) {
-                trailer->loops[i].start = ft->loops[i].start;
+            if (ft->oob.loops[i].type != 0) {
+                trailer->loops[i].start = ft->oob.loops[i].start;
                 /* to mark it as not set */
-                trailer->loops[i].end = ft->loops[i].start + ft->loops[i].length;
-                trailer->loops[i].type = ft->loops[i].type;
-                trailer->loops[i].count = ft->loops[i].count;   
+                trailer->loops[i].end = ft->oob.loops[i].start + ft->oob.loops[i].length;
+                trailer->loops[i].type = ft->oob.loops[i].type;
+                trailer->loops[i].count = ft->oob.loops[i].count;
             } else {
                 /* set first loop start as FFFFFFFF */
-                trailer->loops[i].start = ~0u;   
+                trailer->loops[i].start = ~0u;
                 /* to mark it as not set */
-                trailer->loops[i].end = 0;      
+                trailer->loops[i].end = 0;
                 trailer->loops[i].type = 0;
                 trailer->loops[i].count = 0;
             }
@@ -169,10 +168,10 @@
         return(SOX_SUCCESS);
 }
 
-static int sox_smpseek(sox_format_t * ft, sox_size_t offset) 
+static int sox_smpseek(sox_format_t * ft, sox_size_t offset)
 {
     sox_size_t new_offset, channel_block, alignment;
-    smp_t smp = (smp_t) ft->priv;
+    priv_t * smp = (priv_t *) ft->priv;
 
     new_offset = offset * (ft->encoding.bits_per_sample >> 3);
     /* Make sure request aligns to a channel block (ie left+right) */
@@ -189,20 +188,20 @@
     ft->sox_errno = lsx_seeki(ft, (sox_ssize_t)new_offset, SEEK_SET);
 
     if( ft->sox_errno == SOX_SUCCESS )
-        smp->NoOfSamps = ft->length - (new_offset / (ft->encoding.bits_per_sample >> 3));
+        smp->NoOfSamps = ft->signal.length - (new_offset / (ft->encoding.bits_per_sample >> 3));
 
     return(ft->sox_errno);
 }
 /*
  * Do anything required before you start reading samples.
- * Read file header. 
- *      Find out sampling rate, 
- *      size and encoding of samples, 
+ * Read file header.
+ *      Find out sampling rate,
+ *      size and encoding of samples,
  *      mono/stereo/quad.
  */
-static int sox_smpstartread(sox_format_t * ft) 
+static int sox_smpstartread(sox_format_t * ft)
 {
-        smp_t smp = (smp_t) ft->priv;
+        priv_t * smp = (priv_t *) ft->priv;
         int namelen, commentlen;
         sox_size_t samplestart, i;
         struct smpheader header;
@@ -243,7 +242,7 @@
           ;
         sprintf(smp->comment, "%.*s: %.*s", namelen+1, header.name,
                 commentlen+1, header.comments);
-        sox_append_comments(&ft->comments, smp->comment);
+        sox_append_comments(&ft->oob.comments, smp->comment);
 
         /* Extract out the sample size (always intel format) */
         lsx_readdw(ft, &(smp->NoOfSamps));
@@ -264,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, (sox_ssize_t)samplestart, 0) == -1)
         {
                 lsx_fail_errno(ft,errno,"SMP unable to seek back to start of sample data");
                 return(SOX_EOF);
@@ -275,7 +274,7 @@
         ft->encoding.encoding = SOX_ENCODING_SIGN2;
         ft->signal.channels = 1;
         smp->dataStart = samplestart;
-        ft->length = smp->NoOfSamps;
+        ft->signal.length = smp->NoOfSamps;
 
         sox_report("SampleVision trailer:");
         for(i = 0; i < 8; i++) if (1 || trailer.loops[i].count) {
@@ -290,23 +289,23 @@
         }
         sox_report("MIDI Note number: %d", trailer.MIDInote);
 
-        ft->instr.nloops = 0;
-        for(i = 0; i < 8; i++) 
-                if (trailer.loops[i].type) 
-                        ft->instr.nloops++;
-        for(i = 0; i < ft->instr.nloops; i++) {
-                ft->loops[i].type = trailer.loops[i].type;
-                ft->loops[i].count = trailer.loops[i].count;
-                ft->loops[i].start = trailer.loops[i].start;
-                ft->loops[i].length = trailer.loops[i].end 
+        ft->oob.instr.nloops = 0;
+        for(i = 0; i < 8; i++)
+                if (trailer.loops[i].type)
+                        ft->oob.instr.nloops++;
+        for(i = 0; i < ft->oob.instr.nloops; i++) {
+                ft->oob.loops[i].type = trailer.loops[i].type;
+                ft->oob.loops[i].count = trailer.loops[i].count;
+                ft->oob.loops[i].start = trailer.loops[i].start;
+                ft->oob.loops[i].length = trailer.loops[i].end
                         - trailer.loops[i].start;
         }
-        ft->instr.MIDIlow = ft->instr.MIDIhi =
-                ft->instr.MIDInote = trailer.MIDInote;
-        if (ft->instr.nloops > 0)
-                ft->instr.loopmode = SOX_LOOP_8;
+        ft->oob.instr.MIDIlow = ft->oob.instr.MIDIhi =
+                ft->oob.instr.MIDInote = trailer.MIDInote;
+        if (ft->oob.instr.nloops > 0)
+                ft->oob.instr.loopmode = SOX_LOOP_8;
         else
-                ft->instr.loopmode = SOX_LOOP_NONE;
+                ft->oob.instr.loopmode = SOX_LOOP_NONE;
 
         return(SOX_SUCCESS);
 }
@@ -317,12 +316,12 @@
  * 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 sox_size_t sox_smpread(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-        smp_t smp = (smp_t) ft->priv;
+        priv_t * smp = (priv_t *) ft->priv;
         unsigned short datum;
         sox_size_t done = 0;
-        
+
         for(; done < len && smp->NoOfSamps; done++, smp->NoOfSamps--) {
                 lsx_readw(ft, &datum);
                 /* scale signed up to long's range */
@@ -331,11 +330,11 @@
         return done;
 }
 
-static int sox_smpstartwrite(sox_format_t * ft) 
+static int sox_smpstartwrite(sox_format_t * ft)
 {
-        smp_t smp = (smp_t) ft->priv;
+        priv_t * smp = (priv_t *) ft->priv;
         struct smpheader header;
-        char * comment = sox_cat_comments(ft->comments);
+        char * comment = sox_cat_comments(ft->oob.comments);
 
         /* If you have to seek around the output file */
         if (! ft->seekable)
@@ -362,9 +361,9 @@
         return(SOX_SUCCESS);
 }
 
-static sox_size_t sox_smpwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len) 
+static sox_size_t sox_smpwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-        smp_t smp = (smp_t) ft->priv;
+        priv_t * smp = (priv_t *) ft->priv;
         int datum;
         sox_size_t done = 0;
 
@@ -378,9 +377,9 @@
         return(done);
 }
 
-static int sox_smpstopwrite(sox_format_t * ft) 
+static int sox_smpstopwrite(sox_format_t * ft)
 {
-        smp_t smp = (smp_t) ft->priv;
+        priv_t * smp = (priv_t *) ft->priv;
         struct smptrailer trailer;
 
         /* Assign the trailer data */
@@ -400,13 +399,11 @@
 {
   static char const * const names[] = {"smp", NULL};
   static unsigned const write_encodings[] = {SOX_ENCODING_SIGN2, 16, 0, 0};
-  static sox_format_handler_t handler = {
-    SOX_LIB_VERSION_CODE,
-    "Turtle Beach SampleVision",
-    names, SOX_FILE_LIT_END | SOX_FILE_MONO,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
+    "Turtle Beach SampleVision", names, SOX_FILE_LIT_END | SOX_FILE_MONO,
     sox_smpstartread, sox_smpread, NULL,
     sox_smpstartwrite, sox_smpwrite, sox_smpstopwrite,
-    sox_smpseek, write_encodings, NULL
+    sox_smpseek, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/sndfile.c
+++ b/src/sndfile.c
@@ -1,5 +1,4 @@
-/*
- * libSoX libsndfile formats.
+/* libSoX libsndfile formats.
  *
  * Copyright 2007 Reuben Thomas <rrt@sc3d.org>
  * Copyright 1999-2005 Erik de Castro Lopo <eridk@mega-nerd.com>
@@ -36,23 +35,19 @@
 #endif
 
 /* Private data for sndfile files */
-typedef struct sndfile
-{
+typedef struct {
   SNDFILE *sf_file;
   SF_INFO *sf_info;
   char * log_buffer;
   char const * log_buffer_ptr;
-} *sndfile_t;
+} priv_t;
 
-assert_static(sizeof(struct sndfile) <= SOX_MAX_FILE_PRIVSIZE, 
-              /* else */ sndfile_PRIVSIZE_too_big);
-
 /*
  * Drain LSF's wonderful log buffer
  */
 static void drain_log_buffer(sox_format_t * ft)
 {
-  sndfile_t sf = (sndfile_t)ft->priv;
+  priv_t * sf = (priv_t *)ft->priv;
 
   sf_command(sf->sf_file, SFC_GET_LOG_INFO, sf->log_buffer, LOG_MAX);
   while (*sf->log_buffer_ptr) {
@@ -81,7 +76,7 @@
 {
   *size = 0;                   /* Default */
   format &= SF_FORMAT_SUBMASK;
-  
+
   switch (format) {
   case SF_FORMAT_PCM_S8:
     *size = 8;
@@ -193,12 +188,12 @@
   if ((cptr = strrchr(name, '.')) != NULL) {
     strncpy(buffer, cptr + 1, FILE_TYPE_BUFLEN);
     buffer[FILE_TYPE_BUFLEN] = '\0';
-  
+
     for (k = 0; buffer[k]; k++)
       buffer[k] = tolower((buffer[k]));
   } else
     strncpy(buffer, name, FILE_TYPE_BUFLEN);
-  
+
   for (k = 0; k < (int)(sizeof(format_map) / sizeof(format_map [0])); k++) {
     if (strcmp(buffer, format_map[k].ext) == 0)
       return format_map[k].format;
@@ -257,7 +252,7 @@
 
 static void start(sox_format_t * ft)
 {
-  sndfile_t sf = (sndfile_t)ft->priv;
+  priv_t * sf = (priv_t *)ft->priv;
   int subtype = sndfile_format(ft->encoding.encoding, ft->encoding.bits_per_sample? ft->encoding.bits_per_sample : ft->signal.precision);
   sf->log_buffer_ptr = sf->log_buffer = lsx_malloc(LOG_MAX);
   sf->sf_info = (SF_INFO *)lsx_calloc(1, sizeof(SF_INFO));
@@ -272,7 +267,7 @@
   sf->sf_info->samplerate = ft->signal.rate;
   sf->sf_info->channels = ft->signal.channels;
   if (ft->signal.channels)
-    sf->sf_info->frames = ft->length / ft->signal.channels;
+    sf->sf_info->frames = ft->signal.length / ft->signal.channels;
 }
 
 /*
@@ -280,7 +275,7 @@
  */
 static int startread(sox_format_t * ft)
 {
-  sndfile_t sf = (sndfile_t)ft->priv;
+  priv_t * sf = (priv_t *)ft->priv;
 
   start(ft);
 
@@ -299,7 +294,7 @@
   /* Copy format info */
   ft->encoding.encoding = sox_encoding_and_size((unsigned)sf->sf_info->format, &ft->encoding.bits_per_sample);
   ft->signal.channels = sf->sf_info->channels;
-  ft->length = sf->sf_info->frames * sf->sf_info->channels;
+  ft->signal.length = sf->sf_info->frames * sf->sf_info->channels;
 
   /* FIXME: it would be better if LSF were able to do this */
   if ((sf->sf_info->format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW) {
@@ -319,7 +314,7 @@
  */
 static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-  sndfile_t sf = (sndfile_t)ft->priv;
+  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);
@@ -330,7 +325,7 @@
  */
 static int stopread(sox_format_t * ft)
 {
-  sndfile_t sf = (sndfile_t)ft->priv;
+  priv_t * sf = (priv_t *)ft->priv;
   sf_stop(sf->sf_file);
   drain_log_buffer(ft);
   sf_close(sf->sf_file);
@@ -339,7 +334,7 @@
 
 static int startwrite(sox_format_t * ft)
 {
-  sndfile_t sf = (sndfile_t)ft->priv;
+  priv_t * sf = (priv_t *)ft->priv;
 
   start(ft);
   /* If output format is invalid, try to find a sensible default */
@@ -386,7 +381,7 @@
  */
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-  sndfile_t sf = (sndfile_t)ft->priv;
+  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);
@@ -397,7 +392,7 @@
  */
 static int stopwrite(sox_format_t * ft)
 {
-  sndfile_t sf = (sndfile_t)ft->priv;
+  priv_t * sf = (priv_t *)ft->priv;
   sf_stop(sf->sf_file);
   drain_log_buffer(ft);
   sf_close(sf->sf_file);
@@ -406,7 +401,7 @@
 
 static int seek(sox_format_t * ft, sox_size_t offset)
 {
-  sndfile_t sf = (sndfile_t)ft->priv;
+  priv_t * sf = (priv_t *)ft->priv;
   sf_seek(sf->sf_file, (sf_count_t)(offset / ft->signal.channels), SEEK_CUR);
   return SOX_SUCCESS;
 }
@@ -458,13 +453,11 @@
     SOX_ENCODING_GSM, 0,
     0};
 
-  static sox_format_handler_t const format = {
-    SOX_LIB_VERSION_CODE,
-    "Pseudo format to use libsndfile",
-    names, SOX_FILE_NOSTDIO,
+  static sox_format_handler_t const format = {SOX_LIB_VERSION_CODE,
+    "Pseudo format to use libsndfile", names, SOX_FILE_NOSTDIO,
     startread, read_samples, stopread,
     startwrite, write_samples, stopwrite,
-    seek, write_encodings, NULL
+    seek, write_encodings, NULL, sizeof(priv_t)
   };
 
   return &format;
--- a/src/sounder.c
+++ b/src/sounder.c
@@ -1,5 +1,4 @@
-/*
- * Sounder format handler          (c) 2008 robs@users.sourceforge.net
+/* libSoX Sounder format handler          (c) 2008 robs@users.sourceforge.net
  * Based on description in soundr3b.zip.
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -50,7 +49,7 @@
     names, SOX_FILE_LIT_END | SOX_FILE_MONO,
     start_read, lsx_rawread, NULL,
     write_header, lsx_rawwrite, NULL,
-    lsx_rawseek, write_encodings, NULL
+    lsx_rawseek, write_encodings, NULL, 0
   };
   return &handler;
 }
--- a/src/soundtool.c
+++ b/src/soundtool.c
@@ -1,5 +1,4 @@
-/*
- * Sounder format handler          (c) 2008 robs@users.sourceforge.net
+/* libSoX SoundTool format handler          (c) 2008 robs@users.sourceforge.net
  * Based on description in sndtl26.zip.
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -39,15 +38,15 @@
     return SOX_EOF;
   }
   comments[text_field_len] = '\0'; /* Be defensive against incorrect files */
-  sox_append_comments(&ft->comments, comments);
+  sox_append_comments(&ft->oob.comments, comments);
   return lsx_check_read_params(ft, 1, (sox_rate_t)rate, SOX_ENCODING_UNSIGNED, 8, (off_t)0);
 }
 
 static int write_header(sox_format_t * ft)
 {
-  char * comment = sox_cat_comments(ft->comments);
+  char * comment = sox_cat_comments(ft->oob.comments);
   char text_buf[text_field_len];
-  sox_size_t length = ft->olength? ft->olength:ft->length;
+  sox_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);
@@ -73,7 +72,7 @@
     names, SOX_FILE_LIT_END | SOX_FILE_MONO | SOX_FILE_REWIND,
     start_read, lsx_rawread, NULL,
     write_header, lsx_rawwrite, NULL,
-    lsx_rawseek, write_encodings, NULL
+    lsx_rawseek, write_encodings, NULL, 0
   };
   return &handler;
 }
--- a/src/sox.c
+++ b/src/sox.c
@@ -1,5 +1,4 @@
-/*
- * SoX - The Swiss Army Knife of Audio Manipulation.
+/* SoX - The Swiss Army Knife of Audio Manipulation.
  *
  * This is the main function for the command line sox program.
  *
@@ -87,8 +86,7 @@
 
 /* Input & output files */
 
-typedef struct file_info
-{
+typedef struct {
   char * filename;
 
   /* fopts */
@@ -97,16 +95,16 @@
   sox_encodinginfo_t encoding;
   double volume;
   double replay_gain;
-  rg_mode replay_gain_mode;
-  sox_comments_t comments;
+  sox_oob_t oob;
 
   sox_format_t * ft;  /* libSoX file descriptor */
   sox_size_t volume_clips;
-} * file_t;
+  rg_mode replay_gain_mode;
+} file_t;
 
 #define MAX_INPUT_FILES 32
 #define MAX_FILES MAX_INPUT_FILES + 2 /* 1 output file plus record input */
-static file_t files[MAX_FILES]; /* Array tracking input and output files */
+static file_t * files[MAX_FILES]; /* Array tracking input and output files */
 #define ofile files[file_count - 1]
 static size_t file_count = 0;
 static size_t input_count = 0;
@@ -125,7 +123,7 @@
  * a resample effect, a channel mixing effect, the input, and the output.
  */
 #define MAX_USER_EFF (SOX_MAX_EFFECTS - 4)
-static sox_effect_t user_efftab[MAX_USER_EFF];
+static sox_effect_t * user_efftab[MAX_USER_EFF];
 static unsigned nuser_effects;
 static sox_effects_chain_t ofile_effects_chain;
 
@@ -188,12 +186,12 @@
   return string[i];
 }
 
-static void play_file_info(sox_format_t * ft, file_t f, sox_bool full)
+static void play_file_info(sox_format_t * ft, file_t * f, sox_bool full)
 {
   FILE * const output = sox_mode == sox_soxi? stdout : stderr;
   char const * text;
   char buffer[30];
-  sox_size_t ws = ft->length / ft->signal.channels;
+  sox_size_t ws = ft->signal.length / ft->signal.channels;
   (void)full;
 
   fprintf(output, "\n");
@@ -205,11 +203,11 @@
   }
 
   fprintf(output, "  Encoding: %-14s", sox_encodings_short_str[ft->encoding.encoding]);
-  text = sox_find_comment(f->ft->comments, "Comment");
+  text = sox_find_comment(f->ft->oob.comments, "Comment");
   if (!text)
-    text = sox_find_comment(f->ft->comments, "Description");
+    text = sox_find_comment(f->ft->oob.comments, "Description");
   if (!text)
-    text = sox_find_comment(f->ft->comments, "Year");
+    text = sox_find_comment(f->ft->oob.comments, "Year");
   if (text)
     fprintf(output, "Info: %s", text);
   fprintf(output, "\n");
@@ -216,10 +214,10 @@
 
   sprintf(buffer, "  Channels: %u @ %u-bit", ft->signal.channels, ft->signal.precision);
   fprintf(output, "%-25s", buffer);
-  text = sox_find_comment(f->ft->comments, "Tracknumber");
+  text = sox_find_comment(f->ft->oob.comments, "Tracknumber");
   if (text) {
     fprintf(output, "Track: %s", text);
-    text = sox_find_comment(f->ft->comments, "Tracktotal");
+    text = sox_find_comment(f->ft->oob.comments, "Tracktotal");
     if (text)
       fprintf(output, " of %s", text);
   }
@@ -227,7 +225,7 @@
 
   sprintf(buffer, "Samplerate: %gHz", ft->signal.rate);
   fprintf(output, "%-25s", buffer);
-  text = sox_find_comment(f->ft->comments, "Album");
+  text = sox_find_comment(f->ft->oob.comments, "Album");
   if (text)
     fprintf(output, "Album: %s", text);
   fprintf(output, "\n");
@@ -238,19 +236,19 @@
     fprintf(output, "%-24s", buffer);
   } else
     fprintf(output, "%-24s", "Replaygain: off");
-  text = sox_find_comment(f->ft->comments, "Artist");
+  text = sox_find_comment(f->ft->oob.comments, "Artist");
   if (text)
     fprintf(output, "Artist: %s", text);
   fprintf(output, "\n");
 
-  fprintf(output, "  Duration: %-13s", ft->length? str_time((double)ws / ft->signal.rate) : "unknown");
-  text = sox_find_comment(f->ft->comments, "Title");
+  fprintf(output, "  Duration: %-13s", ft->signal.length? str_time((double)ws / ft->signal.rate) : "unknown");
+  text = sox_find_comment(f->ft->oob.comments, "Title");
   if (text)
     fprintf(output, "Title: %s", text);
   fprintf(output, "\n\n");
 }
 
-static void display_file_info(sox_format_t * ft, file_t f, sox_bool full)
+static void display_file_info(sox_format_t * ft, file_t * f, sox_bool full)
 {
   static char const * const no_yes[] = {"no", "yes"};
   FILE * const output = sox_mode == sox_soxi? stdout : stderr;
@@ -274,8 +272,8 @@
     ft->signal.rate,
     ft->signal.precision);
 
-  if (ft->length && ft->signal.channels && ft->signal.rate) {
-    sox_size_t ws = ft->length / ft->signal.channels;
+  if (ft->signal.length && ft->signal.channels && ft->signal.rate) {
+    sox_size_t ws = ft->signal.length / ft->signal.channels;
     fprintf(output,
       "Duration       : %s = %u samples %c %g CDDA sectors\n",
       str_time((double)ws / ft->signal.rate),
@@ -309,19 +307,19 @@
   if (f && f->volume != HUGE_VAL)
     fprintf(output, "Level adjust   : %g (linear gain)\n" , f->volume);
 
-  if (!(ft->handler.flags & SOX_FILE_DEVICE) && ft->comments) {
-    if (sox_num_comments(ft->comments) > 1) {
-      sox_comments_t p = ft->comments;
+  if (!(ft->handler.flags & SOX_FILE_DEVICE) && ft->oob.comments) {
+    if (sox_num_comments(ft->oob.comments) > 1) {
+      sox_comments_t p = ft->oob.comments;
       fprintf(output, "Comments       : \n");
       do fprintf(output, "%s\n", *p);
       while (*++p);
     }
-    else fprintf(output, "Comment        : '%s'\n", ft->comments[0]);
+    else fprintf(output, "Comment        : '%s'\n", ft->oob.comments[0]);
   }
   fprintf(output, "\n");
 }
 
-static void report_file_info(file_t f)
+static void report_file_info(file_t * f)
 {
   if (sox_globals.verbosity > 2)
     display_file_info(f->ft, f, sox_true);
@@ -344,7 +342,7 @@
       strerror(ft->sox_errno) : sox_strerror[ft->sox_errno - SOX_EHDR]);
 }
 
-static void progress_to_file(file_t f)
+static void progress_to_file(file_t * f)
 {
   if (user_skip) {
     user_skip = sox_false;
@@ -351,7 +349,7 @@
     fprintf(stderr, "\nSkipped (Ctrl-C twice to quit).\n");
   }
   read_wide_samples = 0;
-  input_wide_samples = f->ft->length / f->ft->signal.channels;
+  input_wide_samples = f->ft->signal.length / f->ft->signal.channels;
   if (show_progress && (sox_globals.verbosity < 3 ||
                         (combine_method <= sox_concatenate && input_count > 1)))
     display_file_info(f->ft, f, sox_false);
@@ -371,7 +369,7 @@
   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, sox_size_t ws, file_t * f)
 {
   sox_size_t s = ws * f->ft->signal.channels;
 
@@ -387,9 +385,6 @@
   sox_sample_t *ibuf[MAX_INPUT_FILES];
 } * input_combiner_t;
 
-assert_static(sizeof(struct input_combiner) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ input_combiner_PRIVSIZE_too_big);
-
 static int combiner_start(sox_effect_t *effp)
 {
   input_combiner_t z = (input_combiner_t) effp->priv;
@@ -493,7 +488,7 @@
 {
   static sox_effect_handler_t handler = {
     "input", 0, SOX_EFF_MCHAN,
-    0, combiner_start, 0, combiner_drain, combiner_stop, 0
+    0, combiner_start, 0, combiner_drain, combiner_stop, 0, 0
   };
   return &handler;
 }
@@ -530,7 +525,7 @@
 static sox_effect_handler_t const * output_effect_fn(void)
 {
   static sox_effect_handler_t handler = {
-    "output", 0, SOX_EFF_MCHAN, NULL, NULL, output_flow, NULL, NULL, NULL
+    "output", 0, SOX_EFF_MCHAN, NULL, NULL, output_flow, NULL, NULL, NULL, 0
   };
   return &handler;
 }
@@ -537,14 +532,14 @@
 
 static void add_auto_effect(sox_effects_chain_t * chain, char const * name, sox_signalinfo_t * signal)
 {
-  sox_effect_t eff;
+  sox_effect_t * effp;
 
   /* Auto effect should always succeed here */
-  sox_create_effect(&eff, sox_find_effect(name));
-  eff.handler.getopts(&eff, 0, NULL);          /* Set up with default opts */
+  effp = sox_create_effect(sox_find_effect(name));
+  effp->handler.getopts(effp, 0, NULL);          /* Set up with default opts */
 
   /* But could fail here */
-  if (sox_add_effect(chain, &eff, signal, &ofile->ft->signal) != SOX_SUCCESS)
+  if (sox_add_effect(chain, effp, signal, &ofile->ft->signal) != SOX_SUCCESS)
     exit(2);
 }
 
@@ -553,18 +548,18 @@
 {
   sox_signalinfo_t signal = combiner_signal;
   unsigned i, min_chan = 0, min_rate = 0;
-  sox_effect_t eff;
+  sox_effect_t * effp;
 
   /* Find points after which we might add effects to change rate/chans */
   for (i = 0; i < nuser_effects; i++) {
-    if (user_efftab[i].handler.flags & (SOX_EFF_CHAN|SOX_EFF_MCHAN))
+    if (user_efftab[i]->handler.flags & (SOX_EFF_CHAN | SOX_EFF_MCHAN))
       min_chan = i + 1;
-    if (user_efftab[i].handler.flags & SOX_EFF_RATE)
+    if (user_efftab[i]->handler.flags & SOX_EFF_RATE)
       min_rate = i + 1;
   }
   /* 1st `effect' in the chain is the input combiner_signal */
-  sox_create_effect(&eff, input_combiner_effect_fn());
-  sox_add_effect(chain, &eff, &signal, &ofile->ft->signal);
+  effp = sox_create_effect(input_combiner_effect_fn());
+  sox_add_effect(chain, effp, &signal, &ofile->ft->signal);
 
   /* Add auto effects if appropriate; add user specified effects */
   for (i = 0; i <= nuser_effects; i++) {
@@ -578,7 +573,7 @@
       add_auto_effect(chain, "resample", &signal);
 
     if (i < nuser_effects)
-      if (sox_add_effect(chain, &user_efftab[i], &signal, &ofile->ft->signal) != SOX_SUCCESS)
+      if (sox_add_effect(chain, user_efftab[i], &signal, &ofile->ft->signal) != SOX_SUCCESS)
         exit(2);
   }
   /* Add auto effects if still needed at this point */
@@ -588,8 +583,8 @@
     add_auto_effect(chain, "mixer", &signal);     /* Must be increasing channels */
 
   /* Last `effect' in the chain is the output file */
-  sox_create_effect(&eff, output_effect_fn());
-  if (sox_add_effect(chain, &eff, &signal, &ofile->ft->signal) != SOX_SUCCESS)
+  effp = sox_create_effect(output_effect_fn());
+  if (sox_add_effect(chain, effp, &signal, &ofile->ft->signal) != SOX_SUCCESS)
     exit(2);
 
   for (i = 0; i < chain->length; ++i) {
@@ -720,7 +715,7 @@
   return user_abort? SOX_EOF : SOX_SUCCESS;
 }
 
-static void optimize_trim(void)          
+static void optimize_trim(void)
 {
   /* Speed hack.  If the "trim" effect is the first effect then
    * peek inside its "effect descriptor" and see what the
@@ -731,21 +726,21 @@
    * complex and problably never used.
    * This hack is a huge time savings when trimming
    * gigs of audio data into 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]);
-      if (offset && sox_seek(files[0]->ft, offset, SOX_SEEK_SET) == SOX_SUCCESS) { 
+      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 reset the start location of 
+        /* Assuming a failed seek stayed where it was.  If the
+         * seek worked then reset the start location of
          * trim so that it thinks user didn't request a skip.
-         */ 
+         */
         sox_trim_clear_start(&ofile_effects_chain.effects[1][0]);
         sox_debug("optimize_trim successful");
-      }    
-    }        
-  }    
+      }
+    }
+  }
 }
 
 static sox_bool overwrite_permitted(char const * filename)
@@ -764,23 +759,23 @@
   return c == 'y' || c == 'Y';
 }
 
-static void open_output_file(sox_size_t olen)
+static void open_output_file(void)
 {
-  sox_loopinfo_t loops[SOX_MAX_NLOOPS];
   double factor;
   int i;
-  sox_comments_t comments = sox_copy_comments(files[0]->ft->comments);
-  sox_comments_t p = ofile->comments;
+  sox_comments_t p = ofile->oob.comments;
+  sox_oob_t oob = files[0]->ft->oob;
+  oob.comments = sox_copy_comments(files[0]->ft->oob.comments);
 
-  if (!comments && !p)
-    sox_append_comment(&comments, "Processed by SoX");
+  if (!oob.comments && !p)
+    sox_append_comment(&oob.comments, "Processed by SoX");
   else if (p) {
     if (!(*p)[0]) {
-      sox_delete_comments(&comments);
+      sox_delete_comments(&oob.comments);
       ++p;
     }
     while (*p)
-      sox_append_comment(&comments, *p++);
+      sox_append_comment(&oob.comments, *p++);
   }
 
   /*
@@ -791,22 +786,13 @@
    */
   factor = (double) ofile->signal.rate / combiner_signal.rate;
   for (i = 0; i < SOX_MAX_NLOOPS; i++) {
-    loops[i].start = files[0]->ft->loops[i].start * factor;
-    loops[i].length = files[0]->ft->loops[i].length * factor;
-    loops[i].count = files[0]->ft->loops[i].count;
-    loops[i].type = files[0]->ft->loops[i].type;
+    oob.loops[i].start = oob.loops[i].start * factor;
+    oob.loops[i].length = oob.loops[i].length * factor;
   }
 
-  ofile->ft = sox_open_write(overwrite_permitted,
-                        ofile->filename,
-                        &ofile->signal,
-                        &ofile->encoding,
-                        ofile->filetype,
-                        comments,
-                        olen,
-                        &files[0]->ft->instr,
-                        loops);
-  sox_delete_comments(&comments);
+  ofile->ft = sox_open_write(ofile->filename, &ofile->signal, &ofile->encoding,
+      ofile->filetype, &oob, overwrite_permitted);
+  sox_delete_comments(&oob.comments);
 
   if (!ofile->ft)
     /* sox_open_write() will call sox_warn for most errors.
@@ -861,11 +847,11 @@
       max_channels = max(max_channels, files[i]->ft->signal.channels);
       min_rate = min(min_rate, files[i]->ft->signal.rate);
       max_rate = max(max_rate, files[i]->ft->signal.rate);
-      known_length = known_length && files[i]->ft->length != 0;
+      known_length = known_length && files[i]->ft->signal.length != 0;
       if (combine_method == sox_concatenate)
-        olen += files[i]->ft->length / files[i]->ft->signal.channels;
+        olen += files[i]->ft->signal.length / files[i]->ft->signal.channels;
       else
-        olen = max(olen, files[i]->ft->length / files[i]->ft->signal.channels);
+        olen = max(olen, files[i]->ft->signal.length / files[i]->ft->signal.channels);
     }
     if (min_rate != max_rate)
       sox_fail("Input files must have the same sample-rate");
@@ -879,7 +865,7 @@
     if (min_rate != max_rate)
       exit(1);
 
-    combiner_signal.channels = 
+    combiner_signal.channels =
       combine_method == sox_merge? total_channels : max_channels;
   }
 
@@ -889,7 +875,7 @@
   if (ofile->signal.channels == 0) {
     unsigned j;
     for (j = 0; j < nuser_effects && !ofile->signal.channels; ++j)
-      ofile->signal.channels = user_efftab[nuser_effects - 1 - j].out_signal.channels;
+      ofile->signal.channels = user_efftab[nuser_effects - 1 - j]->out_signal.channels;
     if (ofile->signal.channels == 0)
       ofile->signal.channels = combiner_signal.channels;
   }
@@ -908,13 +894,13 @@
   }
 
   for (i = 0; i < nuser_effects; i++)
-    known_length = known_length && !(user_efftab[i].handler.flags & SOX_EFF_LENGTH);
+    known_length = known_length && !(user_efftab[i]->handler.flags & SOX_EFF_LENGTH);
 
   if (!known_length)
     olen = 0;
+  ofile->signal.length = (sox_size_t)(olen * ofile->signal.channels * ofile->signal.rate / combiner_signal.rate + .5);
+  open_output_file();
 
-  open_output_file((sox_size_t)(olen * ofile->signal.channels * ofile->signal.rate / combiner_signal.rate + .5));
-
   ofile_effects_chain.global_info = sox_effects_globals;
   ofile_effects_chain.in_enc = &combiner_encoding;
   ofile_effects_chain.out_enc = &ofile->ft->encoding;
@@ -925,7 +911,7 @@
   signal(SIGINT, sigint);
   /* FIXME: For SIGTERM at least we really should guarantee to stop quickly */
   signal(SIGTERM, sigint); /* Stop gracefully even in extremis */
-  
+
   flowstatus = sox_flow_effects(&ofile_effects_chain, update_status);
 
   sox_delete_effects(&ofile_effects_chain);
@@ -1266,7 +1252,7 @@
   return p->value;
 }
 
-static sox_bool parse_gopts_and_fopts(file_t f, int argc, char **argv)
+static sox_bool parse_gopts_and_fopts(file_t * f, int argc, char **argv)
 {
   while (sox_true) {
     int c, option_index;
@@ -1281,7 +1267,7 @@
       switch (option_index) {
       case 0:
         if (optarg)
-          sox_append_comment(&f->comments, optarg);
+          sox_append_comment(&f->oob.comments, optarg);
         break;
 
       case 1:
@@ -1298,14 +1284,14 @@
         break;
 
       case 3:
-        sox_append_comment(&f->comments, "");
-        read_comment_file(&f->comments, optarg);
+        sox_append_comment(&f->oob.comments, "");
+        read_comment_file(&f->oob.comments, optarg);
         break;
 
       case 4:
-        sox_append_comment(&f->comments, "");
+        sox_append_comment(&f->oob.comments, "");
         if (optarg)
-          sox_append_comment(&f->comments, optarg);
+          sox_append_comment(&f->oob.comments, optarg);
         break;
 
       case 5:
@@ -1471,7 +1457,7 @@
   return name? from_env? from_env : name : NULL;
 }
 
-static char const * set_default_device(file_t f)
+static char const * set_default_device(file_t * f)
 {
   /* Default audio driver type in order of preference: */
   if (!f->filetype) f->filetype = getenv("AUDIODRIVER");
@@ -1488,9 +1474,9 @@
   return device_name(f->filetype);
 }
 
-static int add_file(struct file_info const * const opts, char const * const filename)
+static int add_file(file_t const * const opts, char const * const filename)
 {
-  file_t f = lsx_malloc(sizeof(*f));
+  file_t * f = lsx_malloc(sizeof(*f));
 
   if (file_count >= MAX_FILES) {
     sox_fail("too many files; maximum is %d input files (and 1 output file)", MAX_INPUT_FILES);
@@ -1504,7 +1490,7 @@
   return 0;
 }
 
-static void init_file(file_t f)
+static void init_file(file_t * f)
 {
   memset(f, 0, sizeof(*f));
   sox_init_encodinginfo(&f->encoding);
@@ -1514,7 +1500,7 @@
 
 static void parse_options_and_filenames(int argc, char **argv)
 {
-  struct file_info opts, opts_none;
+  file_t opts, opts_none;
   init_file(&opts), init_file(&opts_none);
 
   if (sox_mode == sox_rec)
@@ -1523,7 +1509,7 @@
   for (; optind < argc && !sox_find_effect(argv[optind]); init_file(&opts)) {
     if (parse_gopts_and_fopts(&opts, argc, argv)) { /* is null file? */
       if (opts.filetype != NULL && strcmp(opts.filetype, "null") != 0)
-        sox_warn("Ignoring `-t %s'.", opts.filetype);
+        sox_warn("ignoring `-t %s'.", opts.filetype);
       opts.filetype = "null";
       add_file(&opts, "");
     }
@@ -1543,7 +1529,7 @@
 static void parse_effects(int argc, char **argv)
 {
   for (nuser_effects = 0; optind < argc; ++nuser_effects) {
-    sox_effect_t *e = &user_efftab[nuser_effects];
+    sox_effect_t * e;
     int i;
 
     if (nuser_effects >= MAX_USER_EFF) {
@@ -1552,7 +1538,7 @@
     }
 
     /* Name should always be correct! */
-    sox_create_effect(e, sox_find_effect(argv[optind++]));
+    e = sox_create_effect(sox_find_effect(argv[optind++]));
 
     for (i = 0; i < argc - optind && !sox_find_effect(argv[optind + i]); ++i);
     if (e->handler.getopts(e, i, &argv[optind]) == SOX_EOF)
@@ -1561,7 +1547,8 @@
     optind += i; /* Skip past the effect arguments */
 
     if (e->handler.flags & SOX_EFF_DEPRECATED)
-      sox_warn("Effect `%s' is deprecated; see sox(1) for an alternative", e->handler.name);
+      sox_warn("effect `%s' is deprecated; see sox(1) for an alternative", e->handler.name);
+    user_efftab[nuser_effects] = e;
   }
 }
 
@@ -1575,7 +1562,7 @@
 
   if (!ft)
     return 1;
-  ws = ft->length / max(ft->signal.channels, 1);
+  ws = ft->signal.length / max(ft->signal.channels, 1);
   switch (*type) {
     case rate: printf("%g\n", ft->signal.rate); break;
     case channels: printf("%u\n", ft->signal.channels); break;
@@ -1583,8 +1570,8 @@
     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_str[ft->encoding.encoding]); break;
-    case annotation: if (ft->comments) {
-      sox_comments_t p = ft->comments;
+    case annotation: if (ft->oob.comments) {
+      sox_comments_t p = ft->oob.comments;
       do printf("%s\n", *p); while (*++p);
     }
     break;
@@ -1624,7 +1611,7 @@
   return num_errors;
 }
 
-static void set_replay_gain(sox_comments_t comments, file_t f)
+static void set_replay_gain(sox_comments_t comments, file_t * f)
 {
   rg_mode rg = replay_gain_mode;
   int try = 2; /* Will try to find the other GAIN if preferred one not found */
@@ -1684,7 +1671,7 @@
 
   if (sox_format_init() != SOX_SUCCESS)
     exit(1);
- 
+
   if (sox_mode == sox_soxi)
     exit(soxi(argc, argv));
 
@@ -1692,7 +1679,7 @@
 
   if (sox_globals.verbosity > 2)
     display_SoX_version(stderr);
- 
+
   /* Make sure we got at least the required # of input filenames */
   input_count = file_count ? file_count - 1 : 0;
   if (input_count < (combine_method <= sox_concatenate ? 1 : 2))
@@ -1702,7 +1689,7 @@
   for (i = 0; i < input_count; ++i) {
     if (files[i]->encoding.compression != HUGE_VAL)
       usage("A compression factor can be given only for an output file");
-    if (files[i]->comments != NULL)
+    if (files[i]->oob.comments != NULL)
       usage("Comments can be given only for an output file");
   }
   if (ofile->volume != HUGE_VAL)
@@ -1712,7 +1699,7 @@
   signal(SIGINT, SIG_IGN); /* So child pipes aren't killed by track skip */
   for (i = 0; i < input_count; i++) {
     int j = input_count - 1 - i; /* Open in reverse order 'cos of rec (below) */
-    file_t f = files[j];
+    file_t * f = files[j];
 
     /* When mixing audio, default to input side volume adjustments that will
      * make sure no clipping will occur.  Users probably won't be happy with
@@ -1738,15 +1725,15 @@
   /* Simple heuristic to determine if replay-gain should be in album mode */
   if (sox_mode == sox_play && replay_gain_mode == RG_track && input_count > 1 &&
       cmp_comment_text(
-        sox_find_comment(files[0]->ft->comments, "artist"),
-        sox_find_comment(files[1]->ft->comments, "artist")) &&
+        sox_find_comment(files[0]->ft->oob.comments, "artist"),
+        sox_find_comment(files[1]->ft->oob.comments, "artist")) &&
       cmp_comment_text(
-        sox_find_comment(files[0]->ft->comments, "album"),
-        sox_find_comment(files[1]->ft->comments, "album")))
+        sox_find_comment(files[0]->ft->oob.comments, "album"),
+        sox_find_comment(files[1]->ft->oob.comments, "album")))
     replay_gain_mode = RG_album;
 
   for (i = 0; i < input_count; i++)
-    set_replay_gain(files[i]->ft->comments, files[i]);
+    set_replay_gain(files[i]->ft->oob.comments, files[i]);
   signal(SIGINT, SIG_DFL);
 
   /* Loop through the rest of the arguments looking for effects */
@@ -1763,7 +1750,7 @@
   for (i = 0; i < input_count; i++) {
     unsigned j;
     for (j =0; j < nuser_effects && !files[i]->ft->signal.channels; ++j)
-      files[i]->ft->signal.channels = user_efftab[j].in_signal.channels;
+      files[i]->ft->signal.channels = user_efftab[j]->in_signal.channels;
     if (!files[i]->ft->signal.channels)
       ++files[i]->ft->signal.channels;
   }
--- a/src/sox.h
+++ b/src/sox.h
@@ -1,5 +1,4 @@
-/*
- * libSoX Library Public Interface
+/* libSoX Library Public Interface
  *
  * Copyright 1999-2007 Chris Bagwell and SoX Contributors.
  *
@@ -77,14 +76,14 @@
 
 /*                Conversions: Linear PCM <--> sox_sample_t
  *
- *   I/O       I/O     sox_sample_t Clips?    I/O     sox_sample_t Clips? 
- *  Format   Minimum     Minimum     I O    Maximum     Maximum     I O      
- *  ------  ---------  ------------ -- --   --------  ------------ -- --  
- *  Float      -1     -1.00000000047 y y       1           1        y n         
- *  Int8      -128        -128       n n      127     127.9999999   n y   
- *  Int16    -32768      -32768      n n     32767    32767.99998   n y   
- *  Int24   -8388608    -8388608     n n    8388607   8388607.996   n y   
- *  Int32  -2147483648 -2147483648   n n   2147483647 2147483647    n n   
+ *   I/O       I/O     sox_sample_t Clips?    I/O     sox_sample_t Clips?
+ *  Format   Minimum     Minimum     I O    Maximum     Maximum     I O
+ *  ------  ---------  ------------ -- --   --------  ------------ -- --
+ *  Float      -1     -1.00000000047 y y       1           1        y n
+ *  Int8      -128        -128       n n      127     127.9999999   n y
+ *  Int16    -32768      -32768      n n     32767    32767.99998   n y
+ *  Int24   -8388608    -8388608     n n    8388607   8388607.996   n y
+ *  Int32  -2147483648 -2147483648   n n   2147483647 2147483647    n n
  *
  * Conversions are as accurate as possible (with rounding).
  *
@@ -91,7 +90,7 @@
  * Rounding: halves toward +inf, all others to nearest integer.
  *
  * Clips? shows whether on not there is the possibility of a conversion
- * clipping to the minimum or maximum value when inputing from or outputing 
+ * clipping to the minimum or maximum value when inputing from or outputing
  * to a given type.
  *
  * Unsigned integers are converted to and from signed integers by flipping
@@ -173,8 +172,7 @@
 
 typedef void (*sox_output_message_handler_t)(unsigned level, const char *filename, const char *fmt, va_list ap);
 
-typedef struct /* Global parameters (for effects & formats) */
-{
+typedef struct { /* Global parameters (for effects & formats) */
 /* public: */
   unsigned     verbosity;
   sox_output_message_handler_t output_message_handler;
@@ -195,14 +193,15 @@
 typedef double sox_rate_t;
 
 typedef struct { /* Signal parameters; 0 if unknown */
-  sox_rate_t rate;         /* sampling rate */
-  unsigned channels;       /* number of sound channels */
-  unsigned precision;      /* in bits */
+  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 */
 } sox_signalinfo_t;
 
 typedef enum {
   SOX_ENCODING_UNKNOWN   ,
-  
+
   SOX_ENCODING_SIGN2     , /* signed linear 2's comp: Mac */
   SOX_ENCODING_UNSIGNED  , /* unsigned linear: Sound Blaster */
   SOX_ENCODING_FLOAT     , /* floating point (binary format) */
@@ -320,6 +319,7 @@
   int          (*seek)(sox_format_t * ft, sox_size_t offset);
   unsigned     const * write_formats;
   sox_rate_t   const * write_rates;
+  size_t       priv_size;
 } sox_format_handler_t;
 
 /*
@@ -326,9 +326,6 @@
  *  Format information for input and output files.
  */
 
-#define SOX_MAX_FILE_PRIVSIZE    1000
-#define SOX_MAX_NLOOPS           8
-
 typedef char * * sox_comments_t;
 
 size_t sox_num_comments(sox_comments_t comments);
@@ -339,29 +336,34 @@
 char * sox_cat_comments(sox_comments_t comments);
 char const * sox_find_comment(sox_comments_t comments, char const * id);
 
-struct sox_format {
-  /* Placing priv at the start of this structure ensures that it gets aligned
-   * in memory in the optimal way for any structure to be cast over it. */
-  char   priv[SOX_MAX_FILE_PRIVSIZE];    /* format's private data area */
+#define SOX_MAX_NLOOPS           8
 
-  sox_signalinfo_t signal;          /* signal specifications */
-  sox_encodinginfo_t encoding;      /* encoding specifications */
-  sox_instrinfo_t  instr;           /* instrument specification */
-  sox_loopinfo_t   loops[SOX_MAX_NLOOPS];/* Looping specification */
-  sox_bool         seekable;        /* can seek on this file */
-  char             mode;            /* read or write mode */
-  sox_size_t       length;          /* samples * chans in file; 0 if unknown */
-  sox_size_t       olength;         /* samples * chans in file; 0 if unknown */
-  sox_size_t       clips;           /* increment if clipping occurs */
-  char             *filename;       /* file name */
-  char             *filetype;       /* type of file */
-  sox_comments_t       comments;        /* comment strings */
-  FILE             *fp;             /* File stream pointer */
-  int              sox_errno;       /* Failure error codes */
-  char             sox_errstr[256]; /* Extend Failure text */
+typedef struct {
+  /* Decoded: */
+  sox_comments_t   comments;              /* Comment strings */
+  sox_instrinfo_t  instr;                 /* Instrument specification */
+  sox_loopinfo_t   loops[SOX_MAX_NLOOPS]; /* Looping specification */
+
+  /* TBD: Non-decoded chunks, etc: */
+} sox_oob_t;                              /* Out Of Band data */
+
+struct sox_format {
+  char             * filename;      /* File name */
+  sox_signalinfo_t signal;          /* Signal specifications */
+  sox_encodinginfo_t encoding;      /* Encoding specifications */
+  char             * filetype;      /* Type of file */
+  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 */
+  int              sox_errno;       /* Failure error code */
+  char             sox_errstr[256]; /* Failure error text */
+  FILE             * fp;            /* File stream pointer */
   long             tell;
   long             data_start;
-  sox_format_handler_t handler;  /* format struct for this file */
+  sox_format_handler_t handler;     /* Format handler for this file */
+  void             * priv;          /* Format handler's private data area */
 };
 
 /* File flags field */
@@ -392,15 +394,12 @@
     char               const * filetype,
     sox_encodinginfo_t const * encoding);
 sox_format_t * sox_open_write(
-    sox_bool (*overwrite_permitted)(const char *filename),
     char               const * path,
     sox_signalinfo_t   const * signal,
     sox_encodinginfo_t const * encoding,
     char               const * filetype,
-    sox_comments_t                 comments,
-    sox_size_t                 length,
-    sox_instrinfo_t    const * instr,
-    sox_loopinfo_t     const * loops);
+    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);
 int sox_close(sox_format_t * ft);
@@ -417,7 +416,6 @@
  */
 
 #define SOX_MAX_EFFECTS 20
-#define SOX_MAX_EFFECT_PRIVSIZE (2 * SOX_MAX_FILE_PRIVSIZE)
 
 #define SOX_EFF_CHAN     1           /* Effect can alter # of channels */
 #define SOX_EFF_RATE     2           /* Effect can alter sample rate */
@@ -449,13 +447,10 @@
   int (*drain)(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp);
   int (*stop)(sox_effect_t * effp);
   int (*kill)(sox_effect_t * effp);
+  size_t       priv_size;
 } sox_effect_handler_t;
 
 struct sox_effect {
-  /* Placing priv at the start of this structure ensures that it gets aligned
-   * in memory in the optimal way for any structure to be cast over it. */
-  char priv[SOX_MAX_EFFECT_PRIVSIZE];    /* private area for effect */
-
   sox_effects_globals_t    * global_info; /* global parameters */
   sox_signalinfo_t         in_signal;
   sox_signalinfo_t         out_signal;
@@ -468,10 +463,11 @@
   sox_size_t               clips;         /* increment if clipping occurs */
   sox_size_t               flows;         /* 1 if MCHAN, # chans otherwise */
   sox_size_t               flow;          /* flow # */
+  void                     * priv;        /* Effect's private data area */
 };
 
-sox_effect_handler_t const *sox_find_effect(char const * name);
-void sox_create_effect(sox_effect_t * effp, sox_effect_handler_t const *e);
+sox_effect_handler_t const * sox_find_effect(char const * name);
+sox_effect_t * sox_create_effect(sox_effect_handler_t const * eh);
 
 /* Effects chain */
 
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -1,5 +1,4 @@
-/*
- * libSoX Internal header
+/* libSoX Internal header
  *
  *   This file is meant for libSoX internal use only
  *
@@ -129,8 +128,7 @@
 ;
 #endif
 
-typedef struct sox_formats_globals /* Global parameters (for formats) */
-{
+typedef struct sox_formats_globals { /* Global parameters (for formats) */
   sox_globals_t * global_info;
 } sox_formats_globals;
 
--- a/src/sox_sample_test.c
+++ b/src/sox_sample_test.c
@@ -1,5 +1,4 @@
-/*
- * Copyright (c) 2006 robs@users.sourceforge.net
+/* libSoX test code    copyright (c) 2006 robs@users.sourceforge.net
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
--- a/src/sox_sample_test.h
+++ b/src/sox_sample_test.h
@@ -1,16 +1,15 @@
-/*
- * Copyright (c) 2006 robs@users.sourceforge.net
+/* libSoX test code    copyright (c) 2006 robs@users.sourceforge.net
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation; either version 2 of the License, or (at your
  * option) any later version.
- * 
+ *
  * This program 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 General
  * Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
@@ -136,13 +135,13 @@
   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 
+#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()
 {
@@ -198,8 +197,8 @@
   return 0;
 }
 
-#if defined __SUNPRO_CC 
-  #pragma enable_warn 
-#elif defined _MSC_VER 
-  #pragma warning(pop) 
-#endif 
+#if defined __SUNPRO_CC
+  #pragma enable_warn
+#elif defined _MSC_VER
+  #pragma warning(pop)
+#endif
--- a/src/speed.c
+++ b/src/speed.c
@@ -1,4 +1,6 @@
-/*
+/* libSoX Effect: Adjust the audio speed (pitch and tempo together)
+ * (c) 2006 robs@users.sourceforge.net
+ *
  * 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
@@ -12,11 +14,7 @@
  * 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
- */
-
-/* libSoX Effect: Adjust the audio speed (pitch and tempo together)
  *
- * (c) 2006 robs@users.sourceforge.net
  *
  * Adjustment is given as the ratio of the new speed to the old speed, or as
  * a number of cents (100ths of a semitone) to change.  Speed change is
@@ -24,7 +22,6 @@
  */
 
 #include "sox_i.h"
-#include <math.h>
 #include <string.h>
 
 static int getopts(sox_effect_t * effp, int n, char * * argv)
@@ -50,10 +47,10 @@
   return lsx_usage(effp);
 }
 
-sox_effect_handler_t const *sox_speed_effect_fn(void)
+sox_effect_handler_t const * sox_speed_effect_fn(void)
 {
   static sox_effect_handler_t handler = {
-    "speed", "factor[c]", SOX_EFF_NULL|SOX_EFF_LENGTH,
-    getopts, 0, 0, 0, 0, 0};
+    "speed", "factor[c]", SOX_EFF_NULL | SOX_EFF_LENGTH,
+    getopts, 0, 0, 0, 0, 0, 0};
   return &handler;
 }
--- a/src/sphere.c
+++ b/src/sphere.c
@@ -1,5 +1,4 @@
-/*
- * NIST Sphere file format handler.
+/* libSoX NIST Sphere file format handler.
  *
  * August 7, 2000
  *
@@ -138,7 +137,7 @@
 static int write_header(sox_format_t * ft)
 {
   char buf[128];
-  long samples = (ft->olength ? ft->olength : ft->length) / ft->signal.channels;
+  long samples = (ft->olength ? ft->olength : ft->signal.length) / ft->signal.channels;
 
   lsx_writes(ft, "NIST_1A\n");
   lsx_writes(ft, "   1024\n");
@@ -183,13 +182,11 @@
     SOX_ENCODING_ULAW, 8, 0,
     0
   };
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
-    "SPeech HEader Resources; defined by NIST",
-    names, SOX_FILE_REWIND,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
+    "SPeech HEader Resources; defined by NIST", names, SOX_FILE_REWIND,
     start_read, lsx_rawread, NULL,
     write_header, lsx_rawwrite, NULL,
-    lsx_rawseek, write_encodings, NULL
+    lsx_rawseek, write_encodings, NULL, 0
   };
   return &handler;
 }
--- a/src/splice.c
+++ b/src/splice.c
@@ -1,5 +1,4 @@
-/*
- * Effect: splice with a WSOL method.
+/* libSoX effect: splice with a WSOL method.
  * Copyright (c) 2008 robs@users.sourceforge.net
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -68,8 +67,7 @@
   return overlap + offset;
 }
 
-typedef struct splice
-{
+typedef struct {
   unsigned nsplices;     /* Number of splices requested */
   struct {
     char * str;          /* Command-line argument to parse for this splice */
@@ -84,48 +82,45 @@
   sox_size_t max_buffer_size;
   float * buffer;
   unsigned state;
-} * splice_t;
+} priv_t;
+#define p (*(priv_t *)effp->priv)
 
-assert_static(sizeof(struct splice) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ splice_PRIVSIZE_too_big);
-
 static int parse(sox_effect_t * effp, char * * argv, sox_rate_t rate)
 {
-  splice_t p = (splice_t) effp->priv;
   char const * next;
   sox_size_t i, buffer_size;
 
-  p->max_buffer_size = 0;
-  for (i = 0; i < p->nsplices; ++i) {
+  p.max_buffer_size = 0;
+  for (i = 0; i < p.nsplices; ++i) {
     if (argv) /* 1st parse only */
-      p->splices[i].str = lsx_strdup(argv[i]);
+      p.splices[i].str = lsx_strdup(argv[i]);
 
-    p->splices[i].overlap = p->splices[i].search = rate * 0.01 + .5;
+    p.splices[i].overlap = p.splices[i].search = rate * 0.01 + .5;
 
-    next = lsx_parsesamples(rate, p->splices[i].str, &p->splices[i].start, 't');
+    next = lsx_parsesamples(rate, p.splices[i].str, &p.splices[i].start, 't');
     if (next == NULL) break;
 
     if (*next == ',') {
-      next = lsx_parsesamples(rate, next + 1, &p->splices[i].overlap, 't');
+      next = lsx_parsesamples(rate, next + 1, &p.splices[i].overlap, 't');
       if (next == NULL) break;
-      p->splices[i].overlap *= 2;
+      p.splices[i].overlap *= 2;
       if (*next == ',') {
-        next = lsx_parsesamples(rate, next + 1, &p->splices[i].search, 't');
+        next = lsx_parsesamples(rate, next + 1, &p.splices[i].search, 't');
         if (next == NULL) break;
-        p->splices[i].search *= 2;
+        p.splices[i].search *= 2;
       }
     }
     if (*next != '\0') break;
-    p->splices[i].overlap = max(p->splices[i].overlap + 4, 16);
-    p->splices[i].overlap &= ~7; /* Make divisible by 8 for loop optimisation */
+    p.splices[i].overlap = max(p.splices[i].overlap + 4, 16);
+    p.splices[i].overlap &= ~7; /* Make divisible by 8 for loop optimisation */
 
-    if (i > 0 && p->splices[i].start <= p->splices[i-1].start) break;
-    if (p->splices[i].start < p->splices[i].overlap) break;
-    p->splices[i].start -= p->splices[i].overlap;
-    buffer_size = 2 * p->splices[i].overlap + p->splices[i].search;
-    p->max_buffer_size = max(p->max_buffer_size, buffer_size);
+    if (i > 0 && p.splices[i].start <= p.splices[i-1].start) break;
+    if (p.splices[i].start < p.splices[i].overlap) break;
+    p.splices[i].start -= p.splices[i].overlap;
+    buffer_size = 2 * p.splices[i].overlap + p.splices[i].search;
+    p.max_buffer_size = max(p.max_buffer_size, buffer_size);
   }
-  if (i < p->nsplices)
+  if (i < p.nsplices)
     return lsx_usage(effp);
   return SOX_SUCCESS;
 }
@@ -132,22 +127,20 @@
 
 static int create(sox_effect_t * effp, int n, char * * argv)
 {
-  splice_t p = (splice_t) effp->priv;
-  p->splices = lsx_calloc(p->nsplices = n, sizeof(*p->splices));
+  p.splices = lsx_calloc(p.nsplices = n, sizeof(*p.splices));
   return parse(effp, argv, 96000.); /* No rate yet; parse with dummy */
 }
 
 static int start(sox_effect_t * effp)
 {
-  splice_t p = (splice_t) effp->priv;
   unsigned i;
 
   parse(effp, 0, effp->in_signal.rate); /* Re-parse now rate is known */
-  p->buffer = lsx_calloc(p->max_buffer_size * effp->in_signal.channels, sizeof(*p->buffer));
-  p->in_pos = p->buffer_pos = p->splices_pos = 0;
-  p->state = p->splices_pos != p->nsplices && p->in_pos == p->splices[p->splices_pos].start;
-  for (i = 0; i < p->nsplices; ++i)
-    if (p->splices[i].overlap)
+  p.buffer = lsx_calloc(p.max_buffer_size * effp->in_signal.channels, sizeof(*p.buffer));
+  p.in_pos = p.buffer_pos = p.splices_pos = 0;
+  p.state = p.splices_pos != p.nsplices && p.in_pos == p.splices[p.splices_pos].start;
+  for (i = 0; i < p.nsplices; ++i)
+    if (p.splices[i].overlap)
       return SOX_SUCCESS;
   return SOX_EFF_NULL;
 }
@@ -155,7 +148,6 @@
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
     sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
 {
-  splice_t p = (splice_t) effp->priv;
   sox_size_t c, idone = 0, odone = 0;
   *isamp /= effp->in_signal.channels;
   *osamp /= effp->in_signal.channels;
@@ -162,10 +154,10 @@
 
   while (sox_true) {
 copying:
-    if (p->state == 0) {
-      for (; idone < *isamp && odone < *osamp; ++idone, ++odone, ++p->in_pos) {
-        if (p->splices_pos != p->nsplices && p->in_pos == p->splices[p->splices_pos].start) {
-          p->state = 1;
+    if (p.state == 0) {
+      for (; idone < *isamp && odone < *osamp; ++idone, ++odone, ++p.in_pos) {
+        if (p.splices_pos != p.nsplices && p.in_pos == p.splices[p.splices_pos].start) {
+          p.state = 1;
           goto buffering;
         }
         for (c = 0; c < effp->in_signal.channels; ++c)
@@ -175,36 +167,36 @@
     }
 
 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;
-      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,
+    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;
+      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;
-          p->state = 2;
+          p.state = 2;
           goto flushing;
           break;
         }
         for (c = 0; c < effp->in_signal.channels; ++c)
-          p->buffer[p->buffer_pos++] = SOX_SAMPLE_TO_FLOAT_32BIT(*ibuf++, effp->clips);
+          p.buffer[p.buffer_pos++] = SOX_SAMPLE_TO_FLOAT_32BIT(*ibuf++, effp->clips);
       }
       break;
     }
 
 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;
+    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;
       for (; odone < *osamp; ++odone) {
-        if (p->buffer_pos == buffer_size) {
-          p->buffer_pos = 0;
-          ++p->splices_pos;
-          p->state = p->splices_pos != p->nsplices && p->in_pos == p->splices[p->splices_pos].start;
+        if (p.buffer_pos == buffer_size) {
+          p.buffer_pos = 0;
+          ++p.splices_pos;
+          p.state = p.splices_pos != p.nsplices && p.in_pos == p.splices[p.splices_pos].start;
           goto copying;
         }
         for (c = 0; c < effp->in_signal.channels; ++c)
-          *obuf++ = SOX_FLOAT_32BIT_TO_SAMPLE(p->buffer[p->buffer_pos++], effp->clips);
+          *obuf++ = SOX_FLOAT_32BIT_TO_SAMPLE(p.buffer[p.buffer_pos++], effp->clips);
       }
       break;
     }
@@ -223,20 +215,18 @@
 
 static int stop(sox_effect_t * effp)
 {
-  splice_t p = (splice_t) effp->priv;
-  if (p->splices_pos != p->nsplices)
-    sox_warn("Input audio too short; splices not made: %u", p->nsplices - p->splices_pos);
-  free(p->buffer);
+  if (p.splices_pos != p.nsplices)
+    sox_warn("Input audio too short; splices not made: %u", p.nsplices - p.splices_pos);
+  free(p.buffer);
   return SOX_SUCCESS;
 }
 
 static int kill(sox_effect_t * effp)
 {
-  splice_t p = (splice_t) effp->priv;
   unsigned i;
-  for (i = 0; i < p->nsplices; ++i)
-    free(p->splices[i].str);
-  free(p->splices);
+  for (i = 0; i < p.nsplices; ++i)
+    free(p.splices[i].str);
+  free(p.splices);
   return SOX_SUCCESS;
 }
 
@@ -244,7 +234,7 @@
 {
   static sox_effect_handler_t handler = {
     "splice", "{position[,excess[,leaway]]}", SOX_EFF_MCHAN|SOX_EFF_LENGTH,
-    create, start, flow, drain, stop, kill
+    create, start, flow, drain, stop, kill, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/stat.c
+++ b/src/stat.c
@@ -1,5 +1,4 @@
-/*
- * libSoX statistics "effect" file.
+/* libSoX statistics "effect" file.
  *
  * Compute various statistics on file and print them.
  *
@@ -15,12 +14,11 @@
 
 #include "sox_i.h"
 
-#include <math.h>
 #include <string.h>
 #include "FFT.h"
 
 /* Private data for stat effect */
-typedef struct statstuff {
+typedef struct {
   double min, max, mid;
   double asum;
   double sum1, sum2;            /* amplitudes */
@@ -37,7 +35,7 @@
   float *re_out;
   unsigned long fft_size;
   unsigned long fft_offset;
-} *stat_t;
+} priv_t;
 
 
 /*
@@ -45,7 +43,7 @@
  */
 static int sox_stat_getopts(sox_effect_t * effp, int n, char **argv)
 {
-  stat_t stat = (stat_t) effp->priv;
+  priv_t * stat = (priv_t *) effp->priv;
 
   stat->scale = SOX_SAMPLE_MAX;
   stat->volume = 0;
@@ -85,7 +83,7 @@
  */
 static int sox_stat_start(sox_effect_t * effp)
 {
-  stat_t stat = (stat_t) effp->priv;
+  priv_t * stat = (priv_t *) effp->priv;
   int i;
 
   stat->min = stat->max = stat->mid = 0;
@@ -120,7 +118,7 @@
 {
   float ffa = rate / samples;
   unsigned i;
-  
+
   PowerSpectrum(samples, re_in, re_out);
   for (i = 0; i < samples / 2; i++)
     fprintf(stderr, "%f  %f\n", ffa * i, re_out[i]);
@@ -133,7 +131,7 @@
 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)
 {
-  stat_t stat = (stat_t) effp->priv;
+  priv_t * stat = (priv_t *) effp->priv;
   int done, x, len = min(*isamp, *osamp);
   short count = 0;
 
@@ -204,7 +202,7 @@
  */
 static int sox_stat_drain(sox_effect_t * effp, sox_sample_t *obuf UNUSED, sox_size_t *osamp)
 {
-  stat_t stat = (stat_t) effp->priv;
+  priv_t * stat = (priv_t *) effp->priv;
 
   /* When we run out of samples, then we need to pad buffer with
    * zeros and then run FFT one last time to process any unprocessed
@@ -215,7 +213,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);
   }
 
@@ -229,7 +227,7 @@
  */
 static int sox_stat_stop(sox_effect_t * effp)
 {
-  stat_t stat = (stat_t) effp->priv;
+  priv_t * stat = (priv_t *) effp->priv;
   double amp, scale, rms = 0, freq;
   double x, ct;
 
@@ -328,7 +326,7 @@
   sox_stat_flow,
   sox_stat_drain,
   sox_stat_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_stat_effect_fn(void)
--- a/src/stretch.c
+++ b/src/stretch.c
@@ -1,7 +1,6 @@
-/*
+/* libSoX Basic time stretcher.
  * (c) march/april 2000 Fabien COELHO <fabien@coelho.net> for sox.
  *
- * Basic time stretcher.
  * cross fade samples so as to go slower or faster.
  *
  * The filter is based on 6 parameters:
@@ -15,7 +14,7 @@
  * I decided of the default values of these parameters based
  * on some small non extensive tests. maybe better defaults
  * can be suggested.
- * 
+ *
  * It cannot handle different number of channels.
  * It cannot handle rate change.
  */
@@ -30,7 +29,7 @@
 
 #define DEFAULT_STRETCH_WINDOW          20.0  /* ms */
 
-/* I'm planing to put some common fading stuff outside. 
+/* I'm planing to put some common fading stuff outside.
    It's also used in pitch.c
  */
 typedef enum { sox_linear_fading } sox_fading_t;
@@ -39,8 +38,7 @@
 
 typedef enum { input_state, output_state } stretch_status_t;
 
-typedef struct 
-{
+typedef struct {
   /* options
    * FIXME: maybe shift could be allowed > 1.0 with factor < 1.0 ???
    */
@@ -57,23 +55,23 @@
   sox_size_t index;        /* next available element */
   sox_sample_t *ibuf;      /* input buffer */
   sox_size_t ishift;       /* input shift */
-  
+
   sox_size_t oindex;       /* next evailable element */
   double * obuf;   /* output buffer */
   sox_size_t oshift;       /* output shift */
-  
+
   sox_size_t fsize;        /* fading size */
   double * fbuf;   /* fading, 1.0 -> 0.0 */
-  
-} *stretch_t;
 
+} priv_t;
+
 /*
  * Process options
  */
-static int sox_stretch_getopts(sox_effect_t * effp, int n, char **argv) 
+static int sox_stretch_getopts(sox_effect_t * effp, int n, char **argv)
 {
-  stretch_t stretch = (stretch_t) effp->priv; 
-    
+  priv_t * stretch = (priv_t *) effp->priv;
+
   /* default options */
   stretch->factor = 1.0; /* default is no change */
   stretch->window = DEFAULT_STRETCH_WINDOW;
@@ -104,7 +102,7 @@
   /* default shift depends whether we go slower or faster */
   stretch->shift = (stretch->factor <= 1.0) ?
     DEFAULT_FAST_SHIFT_RATIO: DEFAULT_SLOW_SHIFT_RATIO;
- 
+
   if (n > 3 && !sscanf(argv[3], "%lf", &stretch->shift)) {
     sox_fail("error while parsing shift ratio");
     return lsx_usage(effp);
@@ -115,7 +113,7 @@
     return lsx_usage(effp);
   }
 
-  /* default fading stuff... 
+  /* default fading stuff...
      it makes sense for factor >= 0.5 */
   if (stretch->factor < 1.0)
     stretch->fading = 1.0 - (stretch->factor * stretch->shift);
@@ -123,7 +121,7 @@
     stretch->fading = 1.0 - stretch->shift;
   if (stretch->fading > 0.5)
     stretch->fading = 0.5;
-  
+
   if (n > 4 && !sscanf(argv[4], "%lf", &stretch->fading)) {
     sox_fail("error while parsing fading ratio");
     return lsx_usage(effp);
@@ -133,7 +131,7 @@
     sox_fail("error with fading ratio value");
     return lsx_usage(effp);
   }
-  
+
   return SOX_SUCCESS;
 }
 
@@ -142,7 +140,7 @@
  */
 static int sox_stretch_start(sox_effect_t * effp)
 {
-  stretch_t stretch = (stretch_t)effp->priv;
+  priv_t * stretch = (priv_t *)effp->priv;
   sox_size_t i;
 
   if (stretch->factor == 1)
@@ -171,7 +169,7 @@
   stretch->obuf = (double *)lsx_malloc(stretch->size * sizeof(double));
   stretch->fsize = (int)(stretch->fading * stretch->size);
   stretch->fbuf = (double *)lsx_malloc(stretch->fsize * sizeof(double));
-        
+
   /* initialize buffers */
   for (i = 0; i<stretch->size; i++)
     stretch->ibuf[i] = 0;
@@ -198,7 +196,7 @@
 }
 
 /* accumulates input ibuf to output obuf with fading fbuf */
-static void combine(stretch_t stretch)
+static void combine(priv_t * stretch)
 {
   int i, size, fsize;
 
@@ -221,20 +219,20 @@
 /*
  * Processes flow.
  */
-static int sox_stretch_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
-  stretch_t stretch = (stretch_t) effp->priv;
+  priv_t * stretch = (priv_t *) effp->priv;
   sox_size_t iindex = 0, oindex = 0;
   sox_size_t i;
 
   while (iindex<*isamp && oindex<*osamp) {
     if (stretch->state == input_state) {
-      sox_size_t tocopy = min(*isamp-iindex, 
+      sox_size_t tocopy = min(*isamp-iindex,
                              stretch->size-stretch->index);
 
       memcpy(stretch->ibuf + stretch->index, ibuf + iindex, tocopy * sizeof(sox_sample_t));
-      
+
       iindex += tocopy;
       stretch->index += tocopy;
 
@@ -247,7 +245,7 @@
           stretch->ibuf[i] = stretch->ibuf[i+stretch->ishift];
 
         stretch->index -= stretch->ishift;
-        
+
         /* switch to output state */
         stretch->state = output_state;
       }
@@ -271,7 +269,7 @@
         /* pad with 0 */
         for (; i < stretch->size; i++)
           stretch->obuf[i] = 0.0;
-                    
+
         stretch->state = input_state;
       }
     }
@@ -290,25 +288,25 @@
  */
 static int sox_stretch_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
 {
-  stretch_t stretch = (stretch_t) effp->priv;
+  priv_t * stretch = (priv_t *) effp->priv;
   sox_size_t i;
   sox_size_t oindex = 0;
-  
+
   if (stretch->state == input_state) {
     for (i=stretch->index; i<stretch->size; i++)
       stretch->ibuf[i] = 0;
-    
+
     combine(stretch);
-    
+
     stretch->state = output_state;
   }
-  
+
   while (oindex<*osamp && stretch->oindex<stretch->index) {
     float f = stretch->obuf[stretch->oindex++];
     SOX_SAMPLE_CLIP_COUNT(f, effp->clips);
     obuf[oindex++] = f;
   }
-    
+
   *osamp = oindex;
 
   if (stretch->oindex == stretch->index)
@@ -319,12 +317,12 @@
 
 
 /*
- * Do anything required when you stop reading samples.  
- * Don't close input file! 
+ * Do anything required when you stop reading samples.
+ * Don't close input file!
  */
 static int sox_stretch_stop(sox_effect_t * effp)
 {
-  stretch_t stretch = (stretch_t) effp->priv;
+  priv_t * stretch = (priv_t *) effp->priv;
 
   free(stretch->ibuf);
   free(stretch->obuf);
@@ -344,7 +342,7 @@
   sox_stretch_flow,
   sox_stretch_drain,
   sox_stretch_stop,
-  NULL
+  NULL, sizeof(priv_t)
 };
 
 const sox_effect_handler_t *sox_stretch_effect_fn(void)
--- a/src/sunaudio.c
+++ b/src/sunaudio.c
@@ -1,4 +1,4 @@
-/* Direct to Sun Audio Driver
+/* libSoX direct to Sun Audio Driver
  *
  * Added by Chris Bagwell (cbagwell@sprynet.com) on 2/26/96
  * Based on oss handler.
@@ -35,6 +35,7 @@
 #include <fcntl.h>
 #include <string.h>
 
+typedef sox_fileinfo_t priv_t;
 /*
  * Do anything required before you start reading samples.
  * Read file header.
@@ -44,7 +45,7 @@
  */
 static int sox_sunstartread(sox_format_t * ft)
 {
-    sox_fileinfo_t *file = (sox_fileinfo_t *)ft->priv;
+    priv_t *file = (priv_t *)ft->priv;
     sox_size_t samplesize, encoding;
     audio_info_t audio_if;
 #ifdef __SVR4
@@ -104,7 +105,7 @@
                 return (SOX_EOF);
         }
         if ((ft->encoding.encoding == SOX_ENCODING_ULAW ||
-             ft->encoding.encoding == SOX_ENCODING_ALAW) && 
+             ft->encoding.encoding == SOX_ENCODING_ALAW) &&
             ft->signal.channels == 2)
         {
             sox_report("Warning: only support mono for ULAW and ALAW data.  Forcing to mono.");
@@ -180,7 +181,7 @@
 
 static int sox_sunstartwrite(sox_format_t * ft)
 {
-    sox_fileinfo_t *file = (sox_fileinfo_t *)ft->priv;
+    priv_t *file = (priv_t *)ft->priv;
     sox_size_t samplesize, encoding;
     audio_info_t audio_if;
 #ifdef __SVR4
@@ -228,10 +229,10 @@
         }
     }
 
-    if (ft->encoding.bits_per_sample == 8) 
+    if (ft->encoding.bits_per_sample == 8)
     {
         samplesize = 8;
-        if (ft->encoding.encoding == SOX_ENCODING_UNKNOWN) 
+        if (ft->encoding.encoding == SOX_ENCODING_UNKNOWN)
             ft->encoding.encoding = SOX_ENCODING_ULAW;
         else if (ft->encoding.encoding != SOX_ENCODING_ULAW &&
             ft->encoding.encoding != SOX_ENCODING_ALAW &&
@@ -241,7 +242,7 @@
             ft->encoding.encoding = SOX_ENCODING_ULAW;
         }
         if ((ft->encoding.encoding == SOX_ENCODING_ULAW ||
-             ft->encoding.encoding == SOX_ENCODING_ALAW) && 
+             ft->encoding.encoding == SOX_ENCODING_ALAW) &&
             ft->signal.channels == 2)
         {
             sox_report("Warning: only support mono for ULAW and ALAW data.  Forcing to mono.");
@@ -251,7 +252,7 @@
     }
     else if (ft->encoding.bits_per_sample == 16) {
         samplesize = 16;
-        if (ft->encoding.encoding == SOX_ENCODING_UNKNOWN) 
+        if (ft->encoding.encoding == SOX_ENCODING_UNKNOWN)
             ft->encoding.encoding = SOX_ENCODING_SIGN2;
         else if (ft->encoding.encoding != SOX_ENCODING_SIGN2) {
             sox_report("Sun Audio driver only supports Signed Linear for words.");
@@ -315,13 +316,11 @@
     SOX_ENCODING_ALAW, 8, 0,
     SOX_ENCODING_SIGN2, 8, 16, 0,
     0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
-    "Sun audio device driver",
-    names, SOX_FILE_DEVICE,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
+    "Sun audio device driver", names, SOX_FILE_DEVICE,
     sox_sunstartread, lsx_rawread, lsx_rawstopread,
     sox_sunstartwrite, lsx_rawwrite, lsx_rawstopwrite,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/swap.c
+++ b/src/swap.c
@@ -1,12 +1,11 @@
-/*
- * swap - effect to swap ordering of channels in multi-channel audio.
+/* libSoX swap - effect to swap ordering of channels in multi-channel audio.
  *
  * Written by Chris Bagwell (cbagwell@sprynet.com) - March 16, 1999
  *
   * Copyright 1999 Chris Bagwell And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Chris Bagwell And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Chris Bagwell And Sundry Contributors are not responsible for
  * the consequences of using this software.
  */
 
@@ -13,10 +12,10 @@
 
 #include "sox_i.h"
 
-typedef struct swapstuff {
-    int         order[4];
-    int         def_opts;
-} *swap_t;
+typedef struct {
+  int         order[4];
+  int         def_opts;
+} priv_t;
 
 /*
  * Process options
@@ -24,9 +23,9 @@
  * Don't do initialization now.
  * The 'info' fields are not yet filled in.
  */
-static int sox_swap_getopts(sox_effect_t * effp, int n, char **argv) 
+static int sox_swap_getopts(sox_effect_t * effp, int n, char **argv)
 {
-    swap_t swap = (swap_t) effp->priv;
+    priv_t * swap = (priv_t *) effp->priv;
 
     swap->order[0] = swap->order[1] = swap->order[2] = swap->order[3] = 0;
     if (n)
@@ -59,7 +58,7 @@
  */
 static int sox_swap_start(sox_effect_t * effp)
 {
-    swap_t swap = (swap_t) effp->priv;
+    priv_t * swap = (priv_t *) effp->priv;
     int i;
 
     if (effp->out_signal.channels == 1)
@@ -128,10 +127,10 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int sox_swap_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
-    swap_t swap = (swap_t) effp->priv;
+    priv_t * swap = (priv_t *) effp->priv;
     int len, done;
 
     switch (effp->out_signal.channels)
@@ -149,12 +148,12 @@
             ibuf += 2;
             obuf += 2;
         }
-        
+
         *isamp = len * 2;
         *osamp = len * 2;
-        
+
         break;
-        
+
     case 4:
         /* Length to process will be buffer length / 4 since we
          * work with four samples at a time.
@@ -172,25 +171,18 @@
         }
         *isamp = len * 4;
         *osamp = len * 4;
-        
+
         break;
     }
     return (SOX_SUCCESS);
 }
 
-static sox_effect_handler_t sox_swap_effect = {
-  "swap",
-  "[1 2 | 1 2 3 4]",
-  SOX_EFF_MCHAN,
-  sox_swap_getopts,
-  sox_swap_start,
-  sox_swap_flow,
-  NULL,
-  NULL,
-  NULL  
-};
-
 const sox_effect_handler_t *sox_swap_effect_fn(void)
 {
-    return &sox_swap_effect;
+  static sox_effect_handler_t handler = {
+    "swap", "[1 2 | 1 2 3 4]", SOX_EFF_MCHAN,
+    sox_swap_getopts, sox_swap_start, sox_swap_flow,
+    NULL, NULL, NULL, sizeof(priv_t)
+  };
+  return &handler;
 }
--- a/src/synth.c
+++ b/src/synth.c
@@ -1,5 +1,4 @@
-/*
- * synth - Synthesizer Effect.
+/* libSoX synth - Synthesizer Effect.
  *
  * Copyright (c) Jan 2001  Carsten Borchardt
  * Copyright (c) 2001-2007 SoX contributors
@@ -12,7 +11,6 @@
 #include "sox_i.h"
 
 #include <string.h>
-#include <math.h>
 #include <ctype.h>
 
 typedef enum {
@@ -173,7 +171,7 @@
   sox_size_t    samples_to_do;
   channel_t     channels;
   sox_size_t    number_of_channels;
-} * synth_t;
+} priv_t;
 
 
 
@@ -283,7 +281,7 @@
 
 static int getopts(sox_effect_t * effp, int argc, char **argv)
 {
-  synth_t synth = (synth_t) effp->priv;
+  priv_t * synth = (priv_t *) effp->priv;
   int argn = 0;
 
   /* Get duration if given (if first arg starts with digit) */
@@ -384,7 +382,7 @@
 
 static int start(sox_effect_t * effp)
 {
-  synth_t synth = (synth_t) effp->priv;
+  priv_t * synth = (priv_t *) effp->priv;
   size_t i;
 
   synth->max = lsx_sample_max(effp->out_encoding);
@@ -412,7 +410,7 @@
 
 
 
-static sox_sample_t do_synth(sox_sample_t synth_input, synth_t synth, unsigned c, double rate)
+static sox_sample_t do_synth(sox_sample_t synth_input, priv_t * synth, unsigned c, double rate)
 {
   channel_t chan = &synth->channels[c];
   double synth_out;              /* [-1, 1] */
@@ -557,7 +555,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)
 {
-  synth_t synth = (synth_t) effp->priv;
+  priv_t * synth = (priv_t *) effp->priv;
   unsigned len = min(*isamp, *osamp) / effp->in_signal.channels;
   unsigned c, done;
   int result = SOX_SUCCESS;
@@ -576,7 +574,7 @@
 
 static int stop(sox_effect_t * effp)
 {
-  synth_t synth = (synth_t) effp->priv;
+  priv_t * synth = (priv_t *) effp->priv;
   free(synth->channels);
   return SOX_SUCCESS;
 }
@@ -585,7 +583,7 @@
 
 static int kill(sox_effect_t * effp)
 {
-  synth_t synth = (synth_t) effp->priv;
+  priv_t * synth = (priv_t *) effp->priv;
   free(synth->getopts_channels);
   free(synth->length_str);
   return SOX_SUCCESS;
@@ -598,7 +596,7 @@
   static sox_effect_handler_t handler = {
     "synth", "[len] {type [combine] [freq[-freq2] [off [ph [p1 [p2 [p3]]]]]]}",
     SOX_EFF_MCHAN | SOX_EFF_PREC |SOX_EFF_LENGTH,
-    getopts, start, flow, 0, stop, kill
+    getopts, start, flow, 0, stop, kill, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/tempo.c
+++ b/src/tempo.c
@@ -1,5 +1,4 @@
-/*
- * Effect: change tempo (alter duration, maintain pitch) with a WSOLA method.
+/* libSoX effect: change tempo (alter duration, maintain pitch)
  * Copyright (c) 2007 robs@users.sourceforge.net
  * Based on ideas from Olli Parviainen's SoundTouch Library.
  *
@@ -20,7 +19,6 @@
 
 #include "sox_i.h"
 #include "fifo.h"
-#include <math.h>
 
 typedef struct {
   /* Configuration parameters: */
@@ -200,19 +198,15 @@
 
 /*------------------------------- SoX Wrapper --------------------------------*/
 
-typedef struct tempo {
+typedef struct {
   tempo_t     * tempo;
   sox_bool    quick_search;
   double      factor, segment_ms, search_ms, overlap_ms;
 } priv_t;
+#define p ((priv_t *)effp->priv)
 
-assert_static(sizeof(struct tempo) <= SOX_MAX_EFFECT_PRIVSIZE,
-              /* else */ tempo_PRIVSIZE_too_big);
-
 static int getopts(sox_effect_t * effp, int argc, char **argv)
 {
-  priv_t * p = (priv_t *) effp->priv;
-
   p->segment_ms = 82; /* Set non-zero defaults: */
   p->search_ms  = 14;
   p->overlap_ms = 12;
@@ -231,8 +225,6 @@
 
 static int start(sox_effect_t * effp)
 {
-  priv_t * p = (priv_t *) effp->priv;
-
   if (p->factor == 1)
     return SOX_EFF_NULL;
 
@@ -245,7 +237,6 @@
 static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
                 sox_sample_t * obuf, sox_size_t * isamp, sox_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;
@@ -269,13 +260,13 @@
 static int drain(sox_effect_t * effp, sox_sample_t * obuf, sox_size_t * osamp)
 {
   static sox_size_t isamp = 0;
-  tempo_flush(((priv_t *)effp->priv)->tempo);
+  tempo_flush(p->tempo);
   return flow(effp, 0, obuf, &isamp, osamp);
 }
 
 static int stop(sox_effect_t * effp)
 {
-  tempo_delete(((priv_t *)effp->priv)->tempo);
+  tempo_delete(p->tempo);
   return SOX_SUCCESS;
 }
 
@@ -283,7 +274,7 @@
 {
   static sox_effect_handler_t handler = {
     "tempo", "[-q] factor [segment-ms [search-ms [overlap-ms]]]",
-    SOX_EFF_MCHAN | SOX_EFF_LENGTH, getopts, start, flow, drain, stop, NULL
+    SOX_EFF_MCHAN | SOX_EFF_LENGTH, getopts, start, flow, drain, stop, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/tremolo.c
+++ b/src/tremolo.c
@@ -1,4 +1,5 @@
-/*
+/* libSoX effect: tremolo  (c) 2007 robs@users.sourceforge.net
+ *
  * 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
@@ -14,11 +15,9 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-/* Effect: tremolo  (c) 2007 robs@users.sourceforge.net */
-
 #include "sox_i.h"
 
-static int getopts(sox_effect_t * effp, int n, char * * argv) 
+static int getopts(sox_effect_t * effp, int n, char * * argv)
 {
   double speed, depth = 40;
   char dummy;     /* To check for extraneous chars. */
--- a/src/trim.c
+++ b/src/trim.c
@@ -1,9 +1,8 @@
-/*
- * July 5, 1991
+/* July 5, 1991
  * Copyright 1991 Lance Norskog And Sundry Contributors
  * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Lance Norskog And Sundry Contributors are not responsible for 
+ * any purpose.  This copyright notice must be maintained.
+ * Lance Norskog And Sundry Contributors are not responsible for
  * the consequences of using this software.
  */
 
@@ -22,14 +21,14 @@
     /* internal stuff */
     sox_size_t index;
     sox_size_t trimmed;
-} * trim_t;
+} priv_t;
 
 /*
  * Process options
  */
-static int sox_trim_getopts(sox_effect_t * effp, int n, char **argv) 
+static int sox_trim_getopts(sox_effect_t * effp, int n, char **argv)
 {
-    trim_t trim = (trim_t) effp->priv;
+    priv_t * trim = (priv_t *) effp->priv;
 
     /* Do not know sample rate yet so hold off on completely parsing
      * time related strings.
@@ -60,7 +59,7 @@
  */
 static int sox_trim_start(sox_effect_t * effp)
 {
-    trim_t trim = (trim_t) effp->priv;
+    priv_t * trim = (priv_t *) effp->priv;
 
     if (lsx_parsesamples(effp->in_signal.rate, trim->start_str,
                         &trim->start, 't') == NULL)
@@ -92,7 +91,7 @@
  * Place in buf[].
  * Return number of samples read.
  */
-static int sox_trim_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+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)
 {
     int result = SOX_SUCCESS;
@@ -100,7 +99,7 @@
     int offset = 0;
     int done;
 
-    trim_t trim = (trim_t) effp->priv;
+    priv_t * trim = (priv_t *) effp->priv;
 
     /* Compute the most samples we can process this time */
     done = ((*isamp < *osamp) ? *isamp : *osamp);
@@ -149,7 +148,7 @@
 
 static int kill(sox_effect_t * effp)
 {
-    trim_t trim = (trim_t) effp->priv;
+    priv_t * trim = (priv_t *) effp->priv;
 
     free(trim->start_str);
     free(trim->length_str);
@@ -157,31 +156,24 @@
     return (SOX_SUCCESS);
 }
 
-sox_size_t sox_trim_get_start(sox_effect_t * effp)          
-{        
-    trim_t trim = (trim_t)effp->priv;    
-    return trim->start;          
-}        
+sox_size_t sox_trim_get_start(sox_effect_t * effp)
+{
+    priv_t * trim = (priv_t *)effp->priv;
+    return trim->start;
+}
 
-void sox_trim_clear_start(sox_effect_t * effp)     
-{        
-    trim_t trim = (trim_t)effp->priv;    
-    trim->start = 0;     
+void sox_trim_clear_start(sox_effect_t * effp)
+{
+    priv_t * trim = (priv_t *)effp->priv;
+    trim->start = 0;
 }
 
-static sox_effect_handler_t sox_trim_effect = {
-  "trim",
-  "start [length]",
-  SOX_EFF_MCHAN|SOX_EFF_LENGTH,
-  sox_trim_getopts,
-  sox_trim_start,
-  sox_trim_flow,
-  NULL,
-  NULL,
-  kill
-};
-
 const sox_effect_handler_t *sox_trim_effect_fn(void)
 {
-    return &sox_trim_effect;
+  static sox_effect_handler_t handler = {
+    "trim", "start [length]", SOX_EFF_MCHAN|SOX_EFF_LENGTH,
+    sox_trim_getopts, sox_trim_start, sox_trim_flow,
+    NULL, NULL, kill, sizeof(priv_t)
+  };
+  return &handler;
 }
--- a/src/tx16w.c
+++ b/src/tx16w.c
@@ -1,9 +1,9 @@
-/* Yamaha TX-16W sampler file support
+/* libSoX Yamaha TX-16W sampler file support
  *
  * May 20, 1993
  * Copyright 1993 Rob Talley   (rob@aii.com)
  * This source code is freely redistributable and may be used for
- * any purpose. This copyright notice and the following copyright 
+ * any purpose. This copyright notice and the following copyright
  * notice must be maintained intact. No warranty whatsoever is
  * provided. This code is furnished AS-IS as a component of the
  * larger work Copyright 1991 Lance Norskog and Sundry Contributors.
@@ -40,13 +40,13 @@
 #define TXMAXLEN 0x3FF80
 
 /* Private data for TX16 file */
-typedef struct txwstuff {
+typedef struct {
   sox_size_t   samples_out;
   sox_size_t   bytes_out;
   sox_size_t   rest;                 /* bytes remaining in sample file */
   sox_sample_t odd;
   sox_bool     odd_flag;
-} * txw_t;
+} priv_t;
 
 struct WaveHeader_ {
   char filetype[6]; /* = "LM8953", */
@@ -65,8 +65,8 @@
 
 /*
  * Do anything required before you start reading samples.
- * Read file header. 
- *      Find out sampling rate, 
+ * Read file header.
+ *      Find out sampling rate,
  *      size and encoding of samples,
  *      mono/stereo/quad.
  */
@@ -81,7 +81,7 @@
     int blewIt;
     uint32_t trash;
 
-    txw_t sk = (txw_t) ft->priv;
+    priv_t * sk = (priv_t *) ft->priv;
     /* If you need to seek around the input file. */
     if (! ft->seekable)
     {
@@ -91,7 +91,7 @@
 
     /* This is dumb but portable, just count the bytes til EOF */
     while (lsx_read_b_buf(ft, (unsigned char *)&trash, 1) == 1)
-        num_samp_bytes++; 
+        num_samp_bytes++;
     num_samp_bytes -= 32;         /* calculate num samples by sub header size */
     lsx_seeki(ft, 0, 0);           /* rewind file */
     sk->rest = num_samp_bytes;    /* set how many sample bytes to read */
@@ -115,7 +115,7 @@
     for( c = 0; c < 8; c++ )
         lsx_readb(ft, (unsigned char *)&(gunk[c]));
     /*
-     * We should now be pointing at start of raw sample data in file 
+     * We should now be pointing at start of raw sample data in file
      */
 
     /* Check to make sure we got a good filetype ID from file */
@@ -184,7 +184,7 @@
 
 static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-    txw_t sk = (txw_t) ft->priv;
+    priv_t * sk = (priv_t *) ft->priv;
     sox_size_t done = 0;
     unsigned char uc1,uc2,uc3;
     unsigned short s1,s2;
@@ -204,7 +204,7 @@
     /*
      * This is ugly but it's readable!
      * Read three bytes from stream, then decompose these into
-     * two unsigned short samples. 
+     * two unsigned short samples.
      * TCC 3.0 appeared to do unwanted things, so we really specify
      *  exactly what we want to happen.
      * Convert unsigned short to sox_sample_t then shift up the result
@@ -234,7 +234,7 @@
 
 static int startwrite(sox_format_t * ft)
 {
-  txw_t sk = (txw_t) ft->priv;
+  priv_t * sk = (priv_t *) ft->priv;
     struct WaveHeader_ WH;
 
     sox_debug("tx16w selected output");
@@ -258,7 +258,7 @@
 
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len0)
 {
-  txw_t sk = (txw_t) ft->priv;
+  priv_t * sk = (priv_t *) ft->priv;
   sox_size_t last_i, i = 0, len = min(len0, TXMAXLEN - sk->samples_out);
   sox_sample_t w1, w2;
 
@@ -291,7 +291,7 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-  txw_t sk = (txw_t) ft->priv;
+  priv_t * sk = (priv_t *) ft->priv;
     struct WaveHeader_ WH;
     int AttackLength, LoopLength, i;
 
@@ -316,7 +316,7 @@
 
     WH.format = 0xC9;   /* loop off */
 
-    /* the actual sample rate is not that important ! */  
+    /* the actual sample rate is not that important ! */
     if (ft->signal.rate < 24000)      WH.sample_rate = 3;
     else if (ft->signal.rate < 41000) WH.sample_rate = 1;
     else                            WH.sample_rate = 2;
@@ -333,7 +333,7 @@
             LoopLength   +=0x40;
             AttackLength -= 0x40;
         }
-    }    
+    }
     else if (sk->samples_out >= 0x80) {
         AttackLength                       = sk->samples_out -0x40;
         LoopLength                         = 0x40;
@@ -377,13 +377,11 @@
   static char const * const names[] = {"txw", NULL};
   static sox_rate_t   const write_rates[] = {1e5/6, 1e5/3, 1e5/2, 0};
   static unsigned const write_encodings[] = {SOX_ENCODING_SIGN2, 12, 0, 0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
-    "Yamaha TX-16W sampler",
-    names, SOX_FILE_MONO,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
+    "Yamaha TX-16W sampler", names, SOX_FILE_MONO,
     startread, read_samples, NULL,
     startwrite, write_samples, stopwrite,
-    NULL, write_encodings, write_rates
+    NULL, write_encodings, write_rates, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/u1-fmt.c
+++ b/src/u1-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/u2-fmt.c
+++ b/src/u2-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/u3-fmt.c
+++ b/src/u3-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/u4-fmt.c
+++ b/src/u4-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/ul-fmt.c
+++ b/src/ul-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File formats: raw         (c) 2007-8 SoX contributors
+/* libSoX file formats: raw         (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/util.h
+++ b/src/util.h
@@ -1,5 +1,4 @@
-/*
- * General purpose, i.e. non SoX specific, utility functions and macros
+/* General purpose, i.e. non SoX specific, utility functions and macros
  *
  * (c) 2006-8 Chris Bagwell and SoX contributors
  *
@@ -72,6 +71,11 @@
 #define array_length(a) (sizeof(a)/sizeof(a[0]))
 #define sqr(a) ((a) * (a))
 
+#define dB_to_linear(x) exp((x) * M_LN10 * 0.05)
+#define linear_to_dB(x) (log10(x) * 20)
+
+#include <math.h>
+
 #ifndef M_PI
 #define M_PI    3.14159265358979323846
 #endif
@@ -81,8 +85,9 @@
 #ifndef M_LN10
 #define M_LN10  2.30258509299404568402  /* natural log of 10 */
 #endif
-#define dB_to_linear(x) exp((x) * M_LN10 * 0.05)
-#define linear_to_dB(x) (log10(x) * 20)
+#ifndef M_SQRT2
+#define M_SQRT2  sqrt(2.)
+#endif
 
 #ifdef WORDS_BIGENDIAN
 #define MACHINE_IS_BIGENDIAN 1
--- a/src/voc.c
+++ b/src/voc.c
@@ -1,5 +1,6 @@
-/*
+/* libSoX Sound Blaster VOC handler sources.
  * Copyright 1991 Lance Norskog And Sundry Contributors
+ *
  * This source code is freely redistributable and may be used for
  * any purpose.  This copyright notice must be maintained.
  * Lance Norskog And Sundry Contributors are not responsible for
@@ -32,10 +33,6 @@
  *
  */
 
-/*
- * libSoX Sound Blaster VOC handler sources.
- */
-
 /*------------------------------------------------------------------------
 The following is taken from the Audio File Formats FAQ dated 2-Jan-1995
 and submitted by Guido van Rossum <guido@cwi.nl>.
@@ -164,7 +161,7 @@
 #include <string.h>
 
 /* Private data for VOC file */
-typedef struct vocstuff {
+typedef struct {
   long block_remaining;         /* bytes remaining in current block */
   long rate;                    /* rate code (byte) of this chunk */
   int silent;                   /* sound or silence? */
@@ -177,7 +174,7 @@
   long total_size;              /* total size of all audio in file */
   int extended;                 /* Has an extended block been read? */
   adpcm_t adpcm;
-} *vs_t;
+} priv_t;
 
 #define VOC_TERM        0
 #define VOC_DATA        1
@@ -217,7 +214,7 @@
 {
   int rtn = SOX_SUCCESS;
   char header[20];
-  vs_t v = (vs_t) ft->priv;
+  priv_t * v = (priv_t *) ft->priv;
   unsigned short sbseek;
   int rc;
   int ii;                       /* for getting rid of lseek */
@@ -315,7 +312,7 @@
 static sox_size_t read_samples(sox_format_t * ft, sox_sample_t * buf,
                                sox_size_t len)
 {
-  vs_t v = (vs_t) ft->priv;
+  priv_t * v = (priv_t *) ft->priv;
   sox_size_t done = 0;
   int rc = 0;
   int16_t sw;
@@ -455,7 +452,7 @@
  */
 static int startwrite(sox_format_t * ft)
 {
-  vs_t v = (vs_t) ft->priv;
+  priv_t * v = (priv_t *) ft->priv;
 
   if (!ft->seekable) {
     lsx_fail_errno(ft, SOX_EOF,
@@ -480,7 +477,7 @@
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t * buf,
                                 sox_size_t len)
 {
-  vs_t v = (vs_t) ft->priv;
+  priv_t * v = (priv_t *) ft->priv;
   unsigned char uc;
   int16_t sw;
   sox_size_t done = 0;
@@ -510,7 +507,7 @@
  *-----------------------------------------------------------------*/
 static void blockstop(sox_format_t * ft)
 {
-  vs_t v = (vs_t) ft->priv;
+  priv_t * v = (priv_t *) ft->priv;
   sox_sample_t datum;
 
   lsx_writeb(ft, 0);    /* End of file block code */
@@ -553,7 +550,7 @@
  *-----------------------------------------------------------------*/
 static int getblock(sox_format_t * ft)
 {
-  vs_t v = (vs_t) ft->priv;
+  priv_t * v = (priv_t *) ft->priv;
   unsigned char uc, block;
   uint24_t sblen;
   uint16_t new_rate_16;
@@ -729,7 +726,7 @@
  *-----------------------------------------------------------------*/
 static void blockstart(sox_format_t * ft)
 {
-  vs_t v = (vs_t) ft->priv;
+  priv_t * v = (priv_t *) ft->priv;
 
   v->blockseek = lsx_tell(ft);
   if (v->silent) {
@@ -788,13 +785,12 @@
     SOX_ENCODING_UNSIGNED, 8, 0,
     0
   };
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
     "Creative Technology Sound Blaster format",
     names, SOX_FILE_LIT_END | SOX_FILE_MONO | SOX_FILE_STEREO,
     startread, read_samples, NULL,
     startwrite, write_samples, stopwrite,
-    NULL, write_encodings, NULL
+    NULL, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/vol.c
+++ b/src/vol.c
@@ -1,5 +1,4 @@
-/*
- * Copyright (c) 20/03/2000 Fabien COELHO <fabien@coelho.net>
+/* Copyright (c) 20/03/2000 Fabien COELHO <fabien@coelho.net>
  * Copyright (c) 2000-2007 SoX contributors
  *
  * SoX vol effect; change volume with basic linear amplitude formula.
@@ -15,7 +14,6 @@
   "\tis only used on peaks (to prevent clipping); default is no limiter."
 
 #include "sox_i.h"
-#include <math.h>
 
 typedef struct {
   double    gain; /* amplitude gain. */
@@ -24,7 +22,7 @@
   double    limitergain;
   int       limited; /* number of limited values to report. */
   int       totalprocessed;
-} * vol_t;
+} priv_t;
 
 enum {vol_amplitude, vol_dB, vol_power};
 
@@ -37,9 +35,9 @@
 /*
  * Process options: gain (float) type (amplitude, power, dB)
  */
-static int getopts(sox_effect_t * effp, int argc, char **argv) 
+static int getopts(sox_effect_t * effp, int argc, char **argv)
 {
-  vol_t     vol = (vol_t) effp->priv; 
+  priv_t *     vol = (priv_t *) effp->priv;
   char      type_string[11];
   char *    type_ptr = type_string;
   char      dummy;             /* To check for extraneous chars. */
@@ -47,7 +45,7 @@
 
   vol->gain = 1;               /* Default is no change. */
   vol->uselimiter = sox_false; /* Default is no limiter. */
-  
+
   /* Get the vol, and the type if it's in the same arg. */
   if (!argc || (have_type = sscanf(argv[0], "%lf %10s %c", &vol->gain, type_string, &dummy) - 1) > 1)
     return lsx_usage(effp);
@@ -75,13 +73,13 @@
   if (argc) {
     if (fabs(vol->gain) < 1 || sscanf(*argv, "%lf %c", &vol->limitergain, &dummy) != 1 || vol->limitergain <= 0 || vol->limitergain >= 1)
       return lsx_usage(effp);
-    
+
     vol->uselimiter = sox_true;
-    /* The following equation is derived so that there is no 
+    /* The following equation is derived so that there is no
      * discontinuity in output amplitudes */
-    /* and a SOX_SAMPLE_MAX input always maps to a SOX_SAMPLE_MAX output 
+    /* and a SOX_SAMPLE_MAX input always maps to a SOX_SAMPLE_MAX output
      * when the limiter is activated. */
-    /* (NOTE: There **WILL** be a discontinuity in the slope 
+    /* (NOTE: There **WILL** be a discontinuity in the slope
      * of the output amplitudes when using the limiter.) */
     vol->limiterthreshhold = SOX_SAMPLE_MAX * (1.0 - vol->limitergain) / (fabs(vol->gain) - vol->limitergain);
   }
@@ -94,8 +92,8 @@
  */
 static int start(sox_effect_t * effp)
 {
-    vol_t vol = (vol_t) effp->priv;
-    
+    priv_t * vol = (priv_t *) effp->priv;
+
     if (vol->gain == 1)
       return SOX_EFF_NULL;
 
@@ -108,28 +106,28 @@
 /*
  * Process data.
  */
-static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf, 
+static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
                 sox_size_t *isamp, sox_size_t *osamp)
 {
-    vol_t vol = (vol_t) effp->priv;
+    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;
-    
+
     len = min(*osamp, *isamp);
 
     /* report back dealt with amount. */
     *isamp = len; *osamp = len;
-    
+
     if (vol->uselimiter)
     {
         vol->totalprocessed += len;
-        
+
         for (;len>0; len--)
             {
                 sample = *ibuf++;
-                
+
                 if (sample > limiterthreshhold)
                 {
                         sample =  (SOX_SAMPLE_MAX - vol->limitergain * (SOX_SAMPLE_MAX - sample));
@@ -168,9 +166,9 @@
 
 static int stop(sox_effect_t * effp)
 {
-  vol_t vol = (vol_t) effp->priv;
+  priv_t * vol = (priv_t *) effp->priv;
   if (vol->limited) {
-    sox_warn("limited %d values (%d percent).", 
+    sox_warn("limited %d values (%d percent).",
          vol->limited, (int) (vol->limited * 100.0 / vol->totalprocessed));
   }
   return SOX_SUCCESS;
@@ -179,12 +177,12 @@
 sox_effect_handler_t const * sox_vol_effect_fn(void)
 {
   static sox_effect_handler_t handler = {
-    "vol", vol_usage, SOX_EFF_MCHAN, getopts, start, flow, 0, stop, 0
+    "vol", vol_usage, SOX_EFF_MCHAN, getopts, start, flow, 0, stop, 0, sizeof(priv_t)
   };
   return &handler;
 }
 
-static int gain_getopts(sox_effect_t * effp, int argc, char * * argv) 
+static int gain_getopts(sox_effect_t * effp, int argc, char * * argv)
 {
   char * args[] = {0, "dB"};
 
--- a/src/vorbis.c
+++ b/src/vorbis.c
@@ -1,5 +1,4 @@
-/*
- * Ogg Vorbis sound format handler
+/* libSoX Ogg Vorbis sound format handler
  * Copyright 2001, Stan Seibert <indigo@aztec.asu.edu>
  *
  * Portions from oggenc, (c) Michael Smith <msmith@labyrinth.net.au>,
@@ -20,7 +19,6 @@
 #include "sox_i.h"
 
 #include <stdio.h>
-#include <math.h>
 #include <string.h>
 #include <errno.h>
 
@@ -39,7 +37,7 @@
 #define HEADER_OK   1
 
 /* Private data for Ogg Vorbis file */
-typedef struct vorbis_enc {
+typedef struct {
   ogg_stream_state os;
   ogg_page og;
   ogg_packet op;
@@ -49,7 +47,7 @@
   vorbis_info vi;
 } vorbis_enc_t;
 
-typedef struct vorbisstuff {
+typedef struct {
   /* Decoding data */
   OggVorbis_File *vf;
   char *buf;
@@ -60,7 +58,7 @@
   int eof;
 
   vorbis_enc_t *vorbis_enc_data;
-} *vorbis_t;
+} priv_t;
 
 /******** Callback functions used in ov_open_callbacks ************/
 static int myclose(void *datasource UNUSED)
@@ -90,7 +88,7 @@
  */
 static int startread(sox_format_t * ft)
 {
-  vorbis_t vb = (vorbis_t) ft->priv;
+  priv_t * vb = (priv_t *) ft->priv;
   vorbis_info *vi;
   vorbis_comment *vc;
   int i;
@@ -125,11 +123,11 @@
    * "frame"-ish results so we must * channels.
    */
   if (ft->seekable)
-    ft->length = ov_pcm_total(vb->vf, -1) * ft->signal.channels;
+    ft->signal.length = ov_pcm_total(vb->vf, -1) * ft->signal.channels;
 
   /* Record comments */
   for (i = 0; i < vc->comments; i++)
-    sox_append_comment(&ft->comments, vc->user_comments[i]);
+    sox_append_comment(&ft->oob.comments, vc->user_comments[i]);
 
   /* Setup buffer */
   vb->buf_len = DEF_BUF_LEN;
@@ -147,7 +145,7 @@
 /* Refill the buffer with samples.  Returns BUF_EOF if the end of the
  * vorbis data was reached while the buffer was being filled,
  * BUF_ERROR is something bad happens, and BUF_DATA otherwise */
-static int refill_buffer(vorbis_t vb)
+static int refill_buffer(priv_t * vb)
 {
   int num_read;
 
@@ -179,7 +177,7 @@
 
 static sox_size_t read_samples(sox_format_t * ft, sox_sample_t * buf, sox_size_t len)
 {
-  vorbis_t vb = (vorbis_t) ft->priv;
+  priv_t * vb = (priv_t *) ft->priv;
   sox_size_t i;
   int ret;
   sox_sample_t l;
@@ -211,7 +209,7 @@
  */
 static int stopread(sox_format_t * ft)
 {
-  vorbis_t vb = (vorbis_t) ft->priv;
+  priv_t * vb = (priv_t *) ft->priv;
 
   free(vb->buf);
   ov_clear(vb->vf);
@@ -242,17 +240,17 @@
   int i, ret = HEADER_OK;
 
   memset(&vc, 0, sizeof(vc));
-  vc.comments = sox_num_comments(ft->comments);
+  vc.comments = sox_num_comments(ft->oob.comments);
   if (vc.comments) {     /* Make the comment structure */
     vc.comment_lengths = lsx_calloc((size_t)vc.comments, sizeof(*vc.comment_lengths));
     vc.user_comments = lsx_calloc((size_t)vc.comments, sizeof(*vc.user_comments));
     for (i = 0; i < vc.comments; ++i) {
       static const char prepend[] = "Comment=";
-      char * text = lsx_calloc(strlen(prepend) + strlen(ft->comments[i]) + 1, sizeof(*text));
+      char * text = lsx_calloc(strlen(prepend) + strlen(ft->oob.comments[i]) + 1, sizeof(*text));
       /* Prepend `Comment=' if no field-name already in the comment */
-      if (!strchr(ft->comments[i], '='))
+      if (!strchr(ft->oob.comments[i], '='))
         strcpy(text, prepend);
-      vc.user_comments[i] = strcat(text, ft->comments[i]);
+      vc.user_comments[i] = strcat(text, ft->oob.comments[i]);
       vc.comment_lengths[i] = strlen(text);
     }
   }
@@ -275,7 +273,7 @@
 
 static int startwrite(sox_format_t * ft)
 {
-  vorbis_t vb = (vorbis_t) ft->priv;
+  priv_t * vb = (priv_t *) ft->priv;
   vorbis_enc_t *ve;
   long rate;
   double quality = 3;           /* Default compression quality gives ~112kbps */
@@ -321,7 +319,7 @@
 static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t * buf,
                         sox_size_t len)
 {
-  vorbis_t vb = (vorbis_t) ft->priv;
+  priv_t * vb = (priv_t *) ft->priv;
   vorbis_enc_t *ve = vb->vorbis_enc_data;
   sox_size_t samples = len / ft->signal.channels;
   float **buffer = vorbis_analysis_buffer(&ve->vd, (int) samples);
@@ -371,7 +369,7 @@
 
 static int stopwrite(sox_format_t * ft)
 {
-  vorbis_t vb = (vorbis_t) ft->priv;
+  priv_t * vb = (priv_t *) ft->priv;
   vorbis_enc_t *ve = vb->vorbis_enc_data;
 
   /* Close out the remaining data */
@@ -387,7 +385,7 @@
 
 static int seek(sox_format_t * ft, sox_size_t offset)
 {
-  vorbis_t vb = (vorbis_t) ft->priv;
+  priv_t * vb = (priv_t *) ft->priv;
 
   return ov_pcm_seek(vb->vf, (ogg_int64_t)(offset / ft->signal.channels))? SOX_EOF:SOX_SUCCESS;
 }
@@ -396,13 +394,11 @@
 {
   static const char *names[] = {"vorbis", "ogg", NULL};
   static unsigned encodings[] = {SOX_ENCODING_VORBIS, 0, 0};
-  static sox_format_handler_t handler = {
-    SOX_LIB_VERSION_CODE,
-    "Xiph's ogg-vorbis lossy compression",
-    names, 0,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
+    "Xiph's ogg-vorbis lossy compression", names, 0,
     startread, read_samples, stopread,
     startwrite, write_samples, stopwrite,
-    seek, encodings, NULL
+    seek, encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/vorbis1.h
+++ b/src/vorbis1.h
@@ -1,5 +1,4 @@
-/*
- * This library is free software; you can redistribute it and/or modify it
+/* 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.
@@ -14,19 +13,19 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#if defined __GNUC__ 
-  #pragma GCC system_header 
-#elif defined __SUNPRO_CC 
-  #pragma disable_warn 
-#elif defined _MSC_VER 
-  #pragma warning(push, 1) 
-#endif 
+#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 
+#if defined __SUNPRO_CC
+  #pragma enable_warn
+#elif defined _MSC_VER
+  #pragma warning(pop)
+#endif
--- a/src/vox-fmt.c
+++ b/src/vox-fmt.c
@@ -1,5 +1,4 @@
-/*
- * File format: raw Dialogic/OKI ADPCM        (c) 2007-8 SoX contributors
+/* libSoX file format: raw Dialogic/OKI ADPCM        (c) 2007-8 SoX contributors
  *
  * 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
@@ -17,6 +16,7 @@
  */
 
 #include "sox_i.h"
+#include "adpcms.h"
 #include "vox.h"
 
 SOX_FORMAT_HANDLER(vox)
@@ -23,13 +23,11 @@
 {
   static char const * const names[] = {"vox", NULL};
   static unsigned const write_encodings[] = {SOX_ENCODING_OKI_ADPCM, 4, 0, 0};
-  static sox_format_handler_t handler = {
-    SOX_LIB_VERSION_CODE,
-    "Raw OKI/Dialogic ADPCM",
-    names, SOX_FILE_MONO,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
+    "Raw OKI/Dialogic ADPCM", names, SOX_FILE_MONO,
     sox_vox_start, sox_vox_read, sox_vox_stopread,
     sox_vox_start, sox_vox_write, sox_vox_stopwrite,
-    lsx_rawseek, write_encodings, NULL
+    lsx_rawseek, write_encodings, NULL, sizeof(adpcm_io_t)
   };
   return &handler;
 }
--- a/src/vox.c
+++ b/src/vox.c
@@ -1,5 +1,4 @@
-/*
- * SoX file format handler for Dialogic/Oki ADPCM VOX files.
+/* libSoX file format handler for Dialogic/Oki ADPCM VOX files.
  *
  * Copyright 1991-2007 Tony Seebregts And Sundry Contributors
  *
@@ -14,35 +13,35 @@
 #include "vox.h"
 #include "adpcms.h"
 
-/* .vox doesn't need any private state over and above adpcm_io_t, so
+/* .vox doesn't need any private state over and above adpcm_io_t *, so
    just have simple wrappers that pass it on directly. */
 
 int sox_vox_start(sox_format_t * ft)
 {
-  return sox_adpcm_oki_start(ft, (adpcm_io_t)ft->priv);
+  return sox_adpcm_oki_start(ft, (adpcm_io_t *)ft->priv);
 }
 
 int sox_ima_start(sox_format_t * ft)
 {
-  return sox_adpcm_ima_start(ft, (adpcm_io_t)ft->priv);
+  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)
 {
-  return sox_adpcm_read(ft, (adpcm_io_t)ft->priv, buffer, len);
+  return sox_adpcm_read(ft, (adpcm_io_t *)ft->priv, buffer, len);
 }
 
 int sox_vox_stopread(sox_format_t * ft)
 {
-  return sox_adpcm_stopread(ft, (adpcm_io_t)ft->priv);
+  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)
 {
-  return sox_adpcm_write(ft, (adpcm_io_t)ft->priv, buffer, length);
+  return sox_adpcm_write(ft, (adpcm_io_t *)ft->priv, buffer, length);
 }
 
 int sox_vox_stopwrite(sox_format_t * ft)
 {
-  return sox_adpcm_stopwrite(ft, (adpcm_io_t)ft->priv);
+  return sox_adpcm_stopwrite(ft, (adpcm_io_t *)ft->priv);
 }
--- a/src/vox.h
+++ b/src/vox.h
@@ -1,5 +1,4 @@
-/*
- * (c) 2007-8 SoX contributors
+/* (c) 2007-8 SoX contributors
  *
  * 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
--- a/src/wav.c
+++ b/src/wav.c
@@ -1,5 +1,4 @@
-/*
- * Microsoft's WAVE sound format handler
+/* libSoX microsoft's WAVE sound format handler
  *
  * Copyright 1998-2006 Chris Bagwell and SoX Contributors
  * Copyright 1997 Graeme W. Gill, 93/5/17
@@ -21,7 +20,6 @@
 #include <unistd.h>             /* For SEEK_* defines if not found in stdio */
 #endif
 
-#include "wav.h"
 #include "ima_rw.h"
 #include "adpcm.h"
 #ifdef EXTERNAL_GSM
@@ -30,11 +28,33 @@
 #include "../libgsm/gsm.h"
 #endif
 
+#define	WAVE_FORMAT_UNKNOWN		(0x0000U)
+#define	WAVE_FORMAT_PCM			(0x0001U)
+#define	WAVE_FORMAT_ADPCM		(0x0002U)
+#define WAVE_FORMAT_IEEE_FLOAT          (0x0003U)
+#define	WAVE_FORMAT_ALAW		(0x0006U)
+#define	WAVE_FORMAT_MULAW		(0x0007U)
+#define	WAVE_FORMAT_OKI_ADPCM		(0x0010U)
+#define WAVE_FORMAT_IMA_ADPCM		(0x0011U)
+#define	WAVE_FORMAT_DIGISTD		(0x0015U)
+#define	WAVE_FORMAT_DIGIFIX		(0x0016U)
+#define WAVE_FORMAT_DOLBY_AC2           (0x0030U)
+#define WAVE_FORMAT_GSM610              (0x0031U)
+#define WAVE_FORMAT_ROCKWELL_ADPCM      (0x003bU)
+#define WAVE_FORMAT_ROCKWELL_DIGITALK   (0x003cU)
+#define WAVE_FORMAT_G721_ADPCM          (0x0040U)
+#define WAVE_FORMAT_G728_CELP           (0x0041U)
+#define WAVE_FORMAT_MPEG                (0x0050U)
+#define WAVE_FORMAT_MPEGLAYER3          (0x0055U)
+#define WAVE_FORMAT_G726_ADPCM          (0x0064U)
+#define WAVE_FORMAT_G722_ADPCM          (0x0065U)
+#define WAVE_FORMAT_EXTENSIBLE          (0xfffeU)
+
 /* To allow padding to samplesPerBlock. Works, but currently never true. */
 static sox_size_t pad_nsamps = sox_false;
 
 /* Private data for .wav file */
-typedef struct wavstuff {
+typedef struct {
     sox_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 */
@@ -55,7 +75,7 @@
     short         *samples;         /* interleaved samples buffer */
     short         *samplePtr;       /* Pointer to current sample  */
     short         *sampleTop;       /* End of samples-buffer      */
-    unsigned short blockSamplesRemaining;/* Samples remaining per channel */    
+    unsigned short blockSamplesRemaining;/* Samples remaining per channel */
     int            state[16];       /* step-size info for *ADPCM writes */
 
     /* following used by GSM 6.10 wav */
@@ -63,7 +83,7 @@
     gsm_signal     *gsmsample;
     int            gsmindex;
     sox_size_t      gsmbytecount;    /* counts bytes written to data block */
-} *wav_t;
+} priv_t;
 
 static char *wav_format_str(unsigned wFormatTag);
 
@@ -81,7 +101,7 @@
  */
 static unsigned short  ImaAdpcmReadBlock(sox_format_t * ft)
 {
-    wav_t       wav = (wav_t) ft->priv;
+    priv_t *       wav = (priv_t *) ft->priv;
     size_t bytesRead;
     int samplesThisBlock;
 
@@ -88,21 +108,21 @@
     /* Pull in the packet and check the header */
     bytesRead = lsx_readbuf(ft, wav->packet, wav->blockAlign);
     samplesThisBlock = wav->samplesPerBlock;
-    if (bytesRead < wav->blockAlign) 
-    { 
+    if (bytesRead < wav->blockAlign)
+    {
         /* 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);
-        if (samplesThisBlock == 0) 
+        if (samplesThisBlock == 0)
         {
             sox_warn("Premature EOF on .wav input file");
             return 0;
         }
     }
-    
+
     wav->samplePtr = wav->samples;
-    
+
     /* For a full block, the following should be true: */
     /* wav->samplesPerBlock = blockAlign - 8byte header + 1 sample in header */
     lsx_ima_block_expand_i(ft->signal.channels, wav->packet, wav->samples, samplesThisBlock);
@@ -121,7 +141,7 @@
  */
 static unsigned short  AdpcmReadBlock(sox_format_t * ft)
 {
-    wav_t       wav = (wav_t) ft->priv;
+    priv_t *       wav = (priv_t *) ft->priv;
     size_t bytesRead;
     int samplesThisBlock;
     const char *errmsg;
@@ -129,19 +149,19 @@
     /* Pull in the packet and check the header */
     bytesRead = lsx_readbuf(ft, wav->packet, wav->blockAlign);
     samplesThisBlock = wav->samplesPerBlock;
-    if (bytesRead < wav->blockAlign) 
+    if (bytesRead < wav->blockAlign)
     {
         /* 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);
-        if (samplesThisBlock == 0) 
+        if (samplesThisBlock == 0)
         {
             sox_warn("Premature EOF on .wav input file");
             return 0;
         }
     }
-    
+
     errmsg = lsx_ms_adpcm_block_expand_i(ft->signal.channels, wav->nCoefs, wav->lsx_ms_adpcm_i_coefs, wav->packet, wav->samples, samplesThisBlock);
 
     if (errmsg)
@@ -156,7 +176,7 @@
 
 static int xxxAdpcmWriteBlock(sox_format_t * ft)
 {
-    wav_t wav = (wav_t) ft->priv;
+    priv_t * wav = (priv_t *) ft->priv;
     sox_size_t chans, ct;
     short *p;
 
@@ -163,7 +183,7 @@
     chans = ft->signal.channels;
     p = wav->samplePtr;
     ct = p - wav->samples;
-    if (ct>=chans) { 
+    if (ct>=chans) {
         /* zero-fill samples if needed to complete block */
         for (p = wav->samplePtr; p < wav->sampleTop; p++) *p=0;
         /* compress the samples to wav->packet */
@@ -194,9 +214,9 @@
 /****************************************************************************/
 /* create the gsm object, malloc buffer for 160*2 samples */
 static int wavgsminit(sox_format_t * ft)
-{       
+{
     int valueP=1;
-    wav_t       wav = (wav_t) ft->priv;
+    priv_t *       wav = (priv_t *) ft->priv;
     wav->gsmbytecount=0;
     wav->gsmhandle=gsm_create();
     if (!wav->gsmhandle)
@@ -204,7 +224,7 @@
         lsx_fail_errno(ft,SOX_EOF,"cannot create GSM object");
         return (SOX_EOF);
     }
-        
+
     if(gsm_option(wav->gsmhandle,GSM_OPT_WAV49,&valueP) == -1){
         lsx_fail_errno(ft,SOX_EOF,"error setting gsm_option for WAV49 format. Recompile gsm library with -DWAV49 option and relink sox");
         return (SOX_EOF);
@@ -217,8 +237,8 @@
 
 /*destroy the gsm object and free the buffer */
 static void wavgsmdestroy(sox_format_t * ft)
-{       
-    wav_t       wav = (wav_t) ft->priv;
+{
+    priv_t *       wav = (priv_t *) ft->priv;
     gsm_destroy(wav->gsmhandle);
     free(wav->gsmsample);
 }
@@ -225,7 +245,7 @@
 
 static sox_size_t wavgsmread(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-    wav_t       wav = (wav_t) ft->priv;
+    priv_t *       wav = (priv_t *) ft->priv;
     size_t done=0;
     int bytes;
     gsm_byte    frame[65];
@@ -239,7 +259,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, 65);
         if (bytes <=0)
             return done;
         if (bytes<65) {
@@ -270,7 +290,7 @@
 static int wavgsmflush(sox_format_t * ft)
 {
     gsm_byte    frame[65];
-    wav_t       wav = (wav_t) ft->priv;
+    priv_t *       wav = (priv_t *) ft->priv;
 
     /* zero fill as needed */
     while(wav->gsmindex<160*2)
@@ -293,7 +313,7 @@
 
 static sox_size_t wavgsmwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-    wav_t wav = (wav_t) ft->priv;
+    priv_t * wav = (priv_t *) ft->priv;
     size_t done = 0;
     int rc;
 
@@ -301,7 +321,7 @@
 
     while (done < len) {
         while ((wav->gsmindex < 160*2) && (done < len))
-            wav->gsmsample[(wav->gsmindex)++] = 
+            wav->gsmsample[(wav->gsmindex)++] =
                 SOX_SAMPLE_TO_SIGNED_16BIT(buf[done++], ft->clips);
 
         if (wav->gsmindex < 160*2)
@@ -310,7 +330,7 @@
         rc = wavgsmflush(ft);
         if (rc)
             return 0;
-    }     
+    }
     return done;
 
 }
@@ -317,7 +337,7 @@
 
 static void wavgsmstopwrite(sox_format_t * ft)
 {
-    wav_t       wav = (wav_t) ft->priv;
+    priv_t *       wav = (priv_t *) ft->priv;
 
     ft->sox_errno = SOX_SUCCESS;
 
@@ -345,7 +365,7 @@
     {
         if (lsx_reads(ft, magic, 4) == SOX_EOF)
         {
-            lsx_fail_errno(ft, SOX_EHDR, "WAVE file has missing %s chunk", 
+            lsx_fail_errno(ft, SOX_EHDR, "WAVE file has missing %s chunk",
                           Label);
             return SOX_EOF;
         }
@@ -352,7 +372,7 @@
         sox_debug("WAV Chunk %s", magic);
         if (lsx_readdw(ft, len) == SOX_EOF)
         {
-            lsx_fail_errno(ft, SOX_EHDR, "WAVE file %s chunk is too short", 
+            lsx_fail_errno(ft, SOX_EHDR, "WAVE file %s chunk is too short",
                           magic);
             return SOX_EOF;
         }
@@ -363,7 +383,7 @@
         /* skip to next chunk */
         if (*len == 0 || lsx_seeki(ft, (sox_ssize_t)(*len), SEEK_CUR) != SOX_SUCCESS)
         {
-            lsx_fail_errno(ft,SOX_EHDR, 
+            lsx_fail_errno(ft,SOX_EHDR,
                           "WAV chunk appears to have invalid size %d.", *len);
             return SOX_EOF;
         }
@@ -380,14 +400,14 @@
 
 /*
  * Do anything required before you start reading samples.
- * Read file header. 
- *      Find out sampling rate, 
- *      size and encoding of samples, 
+ * Read file header.
+ *      Find out sampling rate,
+ *      size and encoding of samples,
  *      mono/stereo/quad.
  */
-static int startread(sox_format_t * ft) 
+static int startread(sox_format_t * ft)
 {
-    wav_t       wav = (wav_t) ft->priv;
+    priv_t *       wav = (priv_t *) ft->priv;
     char        magic[5];
     uint32_t    len;
 
@@ -417,7 +437,7 @@
     }
 
     /* RIFX is a Big-endian RIFF */
-    if (strncmp("RIFX", magic, 4) == 0) 
+    if (strncmp("RIFX", magic, 4) == 0)
     {
         sox_debug("Found RIFX header");
         ft->encoding.reverse_bytes = MACHINE_IS_LITTLEENDIAN;
@@ -439,7 +459,7 @@
         return SOX_EOF;
     }
     wFmtSize = len;
-    
+
     if (wFmtSize < 16)
     {
         lsx_fail_errno(ft,SOX_EHDR,"WAVE file fmt chunk is too short");
@@ -493,7 +513,7 @@
     case WAVE_FORMAT_UNKNOWN:
         lsx_fail_errno(ft,SOX_EHDR,"WAVE file is in unsupported Microsoft Official Unknown format.");
         return SOX_EOF;
-        
+
     case WAVE_FORMAT_PCM:
         /* Default (-1) depends on sample size.  Set that later on. */
         if (ft->encoding.encoding != SOX_ENCODING_UNKNOWN && ft->encoding.encoding != SOX_ENCODING_UNSIGNED &&
@@ -500,7 +520,7 @@
             ft->encoding.encoding != SOX_ENCODING_SIGN2)
             sox_report("User options overriding encoding read in .wav header");
         break;
-        
+
     case WAVE_FORMAT_IMA_ADPCM:
         if (ft->encoding.encoding == SOX_ENCODING_UNKNOWN || ft->encoding.encoding == SOX_ENCODING_IMA_ADPCM)
             ft->encoding.encoding = SOX_ENCODING_IMA_ADPCM;
@@ -521,7 +541,7 @@
         else
             sox_report("User options overriding encoding read in .wav header");
         break;
-        
+
     case WAVE_FORMAT_ALAW:
         if (ft->encoding.encoding == SOX_ENCODING_UNKNOWN || ft->encoding.encoding == SOX_ENCODING_ALAW)
             ft->encoding.encoding = SOX_ENCODING_ALAW;
@@ -528,7 +548,7 @@
         else
             sox_report("User options overriding encoding read in .wav header");
         break;
-        
+
     case WAVE_FORMAT_MULAW:
         if (ft->encoding.encoding == SOX_ENCODING_UNKNOWN || ft->encoding.encoding == SOX_ENCODING_ULAW)
             ft->encoding.encoding = SOX_ENCODING_ULAW;
@@ -535,7 +555,7 @@
         else
             sox_report("User options overriding encoding read in .wav header");
         break;
-        
+
     case WAVE_FORMAT_OKI_ADPCM:
         return wavfail(ft, "OKI ADPCM");
     case WAVE_FORMAT_DIGISTD:
@@ -581,14 +601,14 @@
         ft->signal.rate = dwSamplesPerSecond;
     else
         sox_report("User options overriding rate read in .wav header");
-    
 
+
     wav->lsx_ms_adpcm_i_coefs = NULL;
     wav->packet = NULL;
     wav->samples = NULL;
 
-    /* non-PCM formats expect alaw and mulaw formats have extended fmt chunk.  
-     * Check for those cases. 
+    /* non-PCM formats expect alaw and mulaw formats have extended fmt chunk.
+     * Check for those cases.
      */
     if (wav->formatTag != WAVE_FORMAT_PCM &&
         wav->formatTag != WAVE_FORMAT_ALAW &&
@@ -740,12 +760,12 @@
       if (ft->encoding.encoding == SOX_ENCODING_UNKNOWN)
         ft->encoding.encoding = SOX_ENCODING_UNSIGNED;
       break;
-        
+
     case 2: case 3: case 4:
       if (ft->encoding.encoding == SOX_ENCODING_UNKNOWN)
         ft->encoding.encoding = SOX_ENCODING_SIGN2;
       break;
-        
+
     default:
       lsx_fail_errno(ft,SOX_EFMT,"Sorry, don't understand .wav size");
       return SOX_EOF;
@@ -772,35 +792,35 @@
     {
 
     case WAVE_FORMAT_ADPCM:
-        wav->numSamples = 
-            lsx_ms_adpcm_samples_in(dwDataLength, ft->signal.channels, 
+        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);
         wav->blockSamplesRemaining = 0;        /* Samples left in buffer */
-        ft->length = wav->numSamples*ft->signal.channels;
+        ft->signal.length = wav->numSamples*ft->signal.channels;
         break;
 
     case WAVE_FORMAT_IMA_ADPCM:
         /* 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->numSamples =
+            lsx_ima_samples_in(dwDataLength, ft->signal.channels,
                          wav->blockAlign, wav->samplesPerBlock);
         sox_debug_more("datalen %d, numSamples %d",dwDataLength, wav->numSamples);
         wav->blockSamplesRemaining = 0;        /* Samples left in buffer */
         lsx_ima_init_table();
-        ft->length = wav->numSamples*ft->signal.channels;
+        ft->signal.length = wav->numSamples*ft->signal.channels;
         break;
 
     case WAVE_FORMAT_GSM610:
         wav->numSamples = ((dwDataLength / wav->blockAlign) * wav->samplesPerBlock);
         wavgsminit(ft);
-        ft->length = wav->numSamples*ft->signal.channels;
+        ft->signal.length = wav->numSamples*ft->signal.channels;
         break;
 
     default:
         wav->numSamples = div_bits(dwDataLength, ft->encoding.bits_per_sample) / ft->signal.channels;
-        ft->length = wav->numSamples * ft->signal.channels;
+        ft->signal.length = wav->numSamples * ft->signal.channels;
     }
 
     sox_debug("Reading Wave file: %s format, %d channel%s, %d samp/sec",
@@ -820,7 +840,7 @@
 
         case WAVE_FORMAT_IMA_ADPCM:
             sox_debug("        %d Extsize, %d Samps/block, %d bytes/block %d Samps/chan",
-                      wExtSize, wav->samplesPerBlock, bytesPerBlock, 
+                      wExtSize, wav->samplesPerBlock, bytesPerBlock,
                       wav->numSamples);
             break;
 
@@ -834,10 +854,10 @@
     }
 
     /* Horrible way to find Cool Edit marker points. Taken from Quake source*/
-    ft->loops[0].start = ~0u;
+    ft->oob.loops[0].start = ~0u;
     if(ft->seekable){
-        /*Got this from the quake source.  I think it 32bit aligns the chunks 
-         * doubt any machine writing Cool Edit Chunks writes them at an odd 
+        /*Got this from the quake source.  I think it 32bit aligns the chunks
+         * 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 &&
@@ -887,8 +907,8 @@
                             strcat(wav->comment,text);
                         }
                         if (strlen(text) < len)
-                           lsx_seeki(ft, (sox_ssize_t)(len - strlen(text)), SEEK_CUR); 
-                    } 
+                           lsx_seeki(ft, (sox_ssize_t)(len - strlen(text)), SEEK_CUR);
+                    }
                     else if (strncmp(magic,"ISFT",4) == 0)
                     {
                         sox_debug("Chunk ISFT");
@@ -906,24 +926,24 @@
                             strcat(wav->comment,text);
                         }
                         if (strlen(text) < len)
-                           lsx_seeki(ft, (sox_ssize_t)(len - strlen(text)), SEEK_CUR); 
-                    } 
+                           lsx_seeki(ft, (sox_ssize_t)(len - strlen(text)), SEEK_CUR);
+                    }
                     else if (strncmp(magic,"cue ",4) == 0)
                     {
                         sox_debug("Chunk cue ");
                         lsx_seeki(ft,(sox_ssize_t)(len-4),SEEK_CUR);
                         lsx_readdw(ft,&dwLoopPos);
-                        ft->loops[0].start = dwLoopPos;
-                    } 
+                        ft->oob.loops[0].start = dwLoopPos;
+                    }
                     else if (strncmp(magic,"ltxt",4) == 0)
                     {
                         sox_debug("Chunk ltxt");
                         lsx_readdw(ft,&dwLoopPos);
-                        ft->loops[0].length = dwLoopPos - ft->loops[0].start;
+                        ft->oob.loops[0].length = dwLoopPos - ft->oob.loops[0].start;
                         if (len > 4)
-                           lsx_seeki(ft, (sox_ssize_t)(len - 4), SEEK_CUR); 
-                    } 
-                    else 
+                           lsx_seeki(ft, (sox_ssize_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;
@@ -934,7 +954,7 @@
         }
         lsx_clearerr(ft);
         lsx_seeki(ft,(sox_ssize_t)wav->dataStart,SEEK_SET);
-    }   
+    }
     return lsx_rawstartread(ft);
 }
 
@@ -946,13 +966,13 @@
  * Return number of samples read.
  */
 
-static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len) 
+static sox_size_t read_samples(sox_format_t * ft, sox_sample_t *buf, sox_size_t len)
 {
-        wav_t   wav = (wav_t) ft->priv;
+        priv_t *   wav = (priv_t *) ft->priv;
         sox_size_t done;
 
         ft->sox_errno = SOX_SUCCESS;
-        
+
         /* If file is in ADPCM encoding then read in multiple blocks else */
         /* read as much as possible and return quickly. */
         switch (ft->encoding.encoding)
@@ -960,13 +980,13 @@
         case SOX_ENCODING_IMA_ADPCM:
         case SOX_ENCODING_MS_ADPCM:
 
-            if (!wav->ignoreSize && len > (wav->numSamples*ft->signal.channels)) 
+            if (!wav->ignoreSize && len > (wav->numSamples*ft->signal.channels))
                 len = (wav->numSamples*ft->signal.channels);
 
             done = 0;
             while (done < len) { /* Still want data? */
                 /* See if need to read more from disk */
-                if (wav->blockSamplesRemaining == 0) { 
+                if (wav->blockSamplesRemaining == 0) {
                     if (wav->formatTag == WAVE_FORMAT_IMA_ADPCM)
                         wav->blockSamplesRemaining = ImaAdpcmReadBlock(ft);
                     else
@@ -1008,7 +1028,7 @@
             break;
 
         case SOX_ENCODING_GSM:
-            if (!wav->ignoreSize && len > wav->numSamples*ft->signal.channels) 
+            if (!wav->ignoreSize && len > wav->numSamples*ft->signal.channels)
                 len = (wav->numSamples*ft->signal.channels);
 
             done = wavgsmread(ft, buf, len);
@@ -1017,7 +1037,7 @@
         break;
 
         default: /* assume PCM or float encoding */
-            if (!wav->ignoreSize && len > wav->numSamples*ft->signal.channels) 
+            if (!wav->ignoreSize && len > wav->numSamples*ft->signal.channels)
                 len = (wav->numSamples*ft->signal.channels);
 
             done = lsx_rawread(ft, buf, len);
@@ -1039,12 +1059,12 @@
 }
 
 /*
- * Do anything required when you stop reading samples.  
- * Don't close input file! 
+ * Do anything required when you stop reading samples.
+ * Don't close input file!
  */
-static int stopread(sox_format_t * ft) 
+static int stopread(sox_format_t * ft)
 {
-    wav_t       wav = (wav_t) ft->priv;
+    priv_t *       wav = (priv_t *) ft->priv;
 
     ft->sox_errno = SOX_SUCCESS;
 
@@ -1068,9 +1088,9 @@
     return SOX_SUCCESS;
 }
 
-static int startwrite(sox_format_t * ft) 
+static int startwrite(sox_format_t * ft)
 {
-    wav_t wav = (wav_t) ft->priv;
+    priv_t * wav = (priv_t *) ft->priv;
     int rc;
 
     ft->sox_errno = SOX_SUCCESS;
@@ -1086,7 +1106,7 @@
 
     wav->numSamples = 0;
     wav->dataLength = 0;
-    if (!ft->length && !ft->seekable)
+    if (!ft->signal.length && !ft->seekable)
         sox_warn("Length in output .wav header will be wrong since can't seek to fix it");
 
     rc = wavwritehdr(ft, 0);  /* also calculates various wav->* info */
@@ -1125,15 +1145,15 @@
 }
 
 /* wavwritehdr:  write .wav headers as follows:
- 
+
 bytes      variable      description
 0  - 3     'RIFF'/'RIFX' Little/Big-endian
 4  - 7     wRiffLength   length of file minus the 8 byte riff header
 8  - 11    'WAVE'
 12 - 15    'fmt '
-16 - 19    wFmtSize       length of format chunk minus 8 byte header 
+16 - 19    wFmtSize       length of format chunk minus 8 byte header
 20 - 21    wFormatTag     identifies PCM, ULAW etc
-22 - 23    wChannels      
+22 - 23    wChannels
 24 - 27    dwSamplesPerSecond  samples per second per channel
 28 - 31    dwAvgBytesPerSec    non-trivial for compressed formats
 32 - 33    wBlockAlign         basic block size
@@ -1158,7 +1178,7 @@
 
 GSM6.10  format:
 36 - 37    wExtSize = 2 the length in bytes of the format-dependent extension
-38 - 39    320           number of samples per  block 
+38 - 39    320           number of samples per  block
 40 - 43    'fact'
 44 - 47    dwFactSize = 4  length of the fact chunk minus 8 byte header
 48 - 51    dwSamplesWritten   actual number of samples written out
@@ -1165,15 +1185,15 @@
 52 - 55    'data'
 56 - 59     dwDataLength  length of data chunk minus 8 byte header
 60 - (dwDataLength + 59)  the data
-(+ a padding byte if dwDataLength is odd) 
+(+ a padding byte if dwDataLength is odd)
 
 
 note that header contains (up to) 3 separate ways of describing the
 length of the file, all derived here from the number of (input)
-samples wav->numSamples in a way that is non-trivial for the blocked 
+samples wav->numSamples in a way that is non-trivial for the blocked
 and padded compressed formats:
 
-wRiffLength -      (riff header) the length of the file, minus 8 
+wRiffLength -      (riff header) the length of the file, minus 8
 dwSamplesWritten - (fact header) the number of samples written (after padding
                    to a complete block eg for GSM)
 dwDataLength     - (data chunk header) the number of (valid) data bytes written
@@ -1182,12 +1202,12 @@
 
 #define MS_UNSPEC 0x7ffff000  /* Unspecified data size (this is a kludge) */
 
-static int wavwritehdr(sox_format_t * ft, int second_header) 
+static int wavwritehdr(sox_format_t * ft, int second_header)
 {
-    wav_t       wav = (wav_t) ft->priv;
+    priv_t *       wav = (priv_t *) ft->priv;
 
     /* variables written to wav file header */
-    /* RIFF header */    
+    /* RIFF header */
     uint32_t wRiffLength ;  /* length of file after 8 byte riff header */
     /* fmt chunk */
     uint16_t wFmtSize = 16;       /* size field of the fmt chunk */
@@ -1271,7 +1291,7 @@
             {
                 sox_report("Overriding GSM audio from %d channel to 1",wChannels);
                 if (!second_header)
-                  ft->length /= max(1, ft->signal.channels);
+                  ft->signal.length /= max(1, ft->signal.channels);
                 wChannels = ft->signal.channels = 1;
             }
             wFormatTag = WAVE_FORMAT_GSM610;
@@ -1288,12 +1308,12 @@
     wav->blockAlign = wBlockAlign;
     wav->samplesPerBlock = wSamplesPerBlock;
 
-    if (!second_header && !ft->length) {       /* adjust for blockAlign */
+    if (!second_header && !ft->signal.length) {       /* adjust for blockAlign */
         blocksWritten = dwDataLength/wBlockAlign;
         dwDataLength = blocksWritten * wBlockAlign;
         dwSamplesWritten = blocksWritten * wSamplesPerBlock;
     } else {    /* fixup with real length */
-        dwSamplesWritten = second_header? wav->numSamples : ft->length;
+        dwSamplesWritten = second_header? wav->numSamples : ft->signal.length;
         blocksWritten = (dwSamplesWritten+wSamplesPerBlock-1)/wSamplesPerBlock;
         dwDataLength = blocksWritten * wBlockAlign;
     }
@@ -1309,7 +1329,7 @@
     else if (wFormatTag != WAVE_FORMAT_PCM)
         wFmtSize += 2+wExtSize; /* plus ExtData */
 
-    wRiffLength = 4 + (8+wFmtSize) + (8+dwDataLength); 
+    wRiffLength = 4 + (8+wFmtSize) + (8+dwDataLength);
     if (wFormatTag != WAVE_FORMAT_PCM) /* PCM omits the "fact" chunk */
         wRiffLength += (8+dwFactSize);
 
@@ -1350,7 +1370,7 @@
       lsx_writew(ft, wFormatTag);
       lsx_writebuf(ft, guids[!strcmp(ft->filetype, "amb")], 14);
     }
-    else 
+    else
     /* if not PCM, we need to write out wExtSize even if wExtSize=0 */
     if (wFormatTag != WAVE_FORMAT_PCM)
         lsx_writew(ft,wExtSize);
@@ -1379,7 +1399,7 @@
     /* if not PCM, write the 'fact' chunk */
     if (isExtensible || wFormatTag != WAVE_FORMAT_PCM){
         lsx_writes(ft, "fact");
-        lsx_writedw(ft,dwFactSize); 
+        lsx_writedw(ft,dwFactSize);
         lsx_writedw(ft,dwSamplesWritten);
     }
 
@@ -1407,9 +1427,9 @@
     return SOX_SUCCESS;
 }
 
-static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len) 
+static sox_size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, sox_size_t len)
 {
-        wav_t   wav = (wav_t) ft->priv;
+        priv_t *   wav = (priv_t *) ft->priv;
         sox_ssize_t total_len = len;
 
         ft->sox_errno = SOX_SUCCESS;
@@ -1448,9 +1468,9 @@
         }
 }
 
-static int stopwrite(sox_format_t * ft) 
+static int stopwrite(sox_format_t * ft)
 {
-        wav_t   wav = (wav_t) ft->priv;
+        priv_t *   wav = (priv_t *) ft->priv;
 
         ft->sox_errno = SOX_SUCCESS;
 
@@ -1473,7 +1493,7 @@
         /* All samples are already written out. */
         /* If file header needs fixing up, for example it needs the */
         /* the number of samples in a field, seek back and write them here. */
-        if (ft->length && wav->numSamples == ft->length)
+        if (ft->signal.length && wav->numSamples == ft->signal.length)
           return SOX_SUCCESS;
         if (!ft->seekable)
           return SOX_EOF;
@@ -1490,7 +1510,7 @@
 /*
  * Return a string corresponding to the wave format type.
  */
-static char *wav_format_str(unsigned wFormatTag) 
+static char *wav_format_str(unsigned wFormatTag)
 {
         switch (wFormatTag)
         {
@@ -1539,9 +1559,9 @@
         }
 }
 
-static int seek(sox_format_t * ft, sox_size_t offset) 
+static int seek(sox_format_t * ft, sox_size_t offset)
 {
-    wav_t   wav = (wav_t) ft->priv;
+    priv_t *   wav = (priv_t *) ft->priv;
     int new_offset, channel_block, alignment;
 
     switch (wav->formatTag)
@@ -1552,12 +1572,12 @@
             break;
 
         case WAVE_FORMAT_GSM610:
-            {   
+            {
                 sox_size_t gsmoff;
 
                 /* rounding bytes to blockAlign so that we
                  * don't have to decode partial block. */
-                gsmoff = offset * wav->blockAlign / wav->samplesPerBlock + 
+                gsmoff = offset * wav->blockAlign / wav->samplesPerBlock +
                          wav->blockAlign * ft->signal.channels / 2;
                 gsmoff -= gsmoff % (wav->blockAlign * ft->signal.channels);
 
@@ -1567,10 +1587,10 @@
 
                 /* offset is in samples */
                 new_offset = offset;
-                alignment = offset % wav->samplesPerBlock;                
+                alignment = offset % wav->samplesPerBlock;
                 if (alignment != 0)
                     new_offset += (wav->samplesPerBlock - alignment);
-                wav->numSamples = ft->length - (new_offset / ft->signal.channels);
+                wav->numSamples = ft->signal.length - (new_offset / ft->signal.channels);
             }
             break;
 
@@ -1590,7 +1610,7 @@
             ft->sox_errno = lsx_seeki(ft, new_offset, SEEK_SET);
 
             if( ft->sox_errno == SOX_SUCCESS )
-                wav->numSamples = (ft->length / ft->signal.channels) -
+                wav->numSamples = (ft->signal.length / ft->signal.channels) -
                                   (new_offset / (ft->encoding.bits_per_sample >> 3) / ft->signal.channels);
     }
 
@@ -1610,13 +1630,11 @@
     SOX_ENCODING_IMA_ADPCM, 4, 0,
     SOX_ENCODING_FLOAT, 32, 0,
     0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
-    "Microsoft audio format",
-    names, SOX_FILE_LIT_END,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
+    "Microsoft audio format", names, SOX_FILE_LIT_END,
     startread, read_samples, stopread,
     startwrite, write_samples, stopwrite,
-    seek, write_encodings, NULL
+    seek, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/wavpack.c
+++ b/src/wavpack.c
@@ -1,5 +1,4 @@
-/*
- * File format: WavPack   (c) 2008 robs@users.sourceforge.net
+/* libSoX file format: WavPack   (c) 2008 robs@users.sourceforge.net
  *
  * 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
@@ -24,22 +23,20 @@
   sox_size_t first_block_size;
 } priv_t;
 
-assert_static(sizeof(priv_t) <= SOX_MAX_FILE_PRIVSIZE, WAVPACK_PRIV_TOO_BIG);
-
 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, (sox_size_t)len);}
 static uint32_t ft_tell(void * ft) {
-  return lsx_tell((sox_format_t *)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, (sox_ssize_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, offset, mode);}
 static int ft_unreadb(void * ft, int b) {
-  return lsx_unreadb((sox_format_t *)ft, (unsigned)b);} 
+  return lsx_unreadb((sox_format_t *)ft, (unsigned)b);}
 static uint32_t ft_filelength(void * ft) {
-  return lsx_filelength((sox_format_t *)ft);} 
+  return lsx_filelength((sox_format_t *)ft);}
 static int ft_is_seekable(void *ft) {
-  return ((sox_format_t *)ft)->seekable;} 
+  return ((sox_format_t *)ft)->seekable;}
 static int32_t ft_write_b_buf(void * ft, void * buf, int32_t len) {
   priv_t * p = (priv_t *)((sox_format_t *)ft)->priv;
   if (!p->first_block_size)
@@ -63,8 +60,8 @@
     sox_warn("`%s': overriding sample rate", ft->filename);
   else ft->signal.rate = WavpackGetSampleRate(p->codec);
 
-  ft->length = WavpackGetNumSamples(p->codec) * ft->signal.channels;
-  ft->encoding.encoding = (WavpackGetMode(p->codec) & MODE_FLOAT)? 
+  ft->signal.length = WavpackGetNumSamples(p->codec) * ft->signal.channels;
+  ft->encoding.encoding = (WavpackGetMode(p->codec) & MODE_FLOAT)?
     SOX_ENCODING_WAVPACKF : SOX_ENCODING_WAVPACK;
   return SOX_SUCCESS;
 }
@@ -106,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->length? ft->length / ft->signal.channels : (uint32_t)-1)) {
+  if (!WavpackSetConfiguration(p->codec, &config, ft->signal.length? ft->signal.length / ft->signal.channels : (uint32_t)-1)) {
     lsx_fail_errno(ft, SOX_EHDR, WavpackGetErrorMessage(p->codec));
     return SOX_EOF;
   }
@@ -169,13 +166,12 @@
     SOX_ENCODING_WAVPACK, 8, 16, 24, 32, 0,
     SOX_ENCODING_WAVPACKF, 32, 0,
     0};
-  static sox_format_handler_t handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t handler = {SOX_LIB_VERSION_CODE,
     "Lossless, lossy, and hybrid audio compression",
     names, 0,
     start_read, read_samples, stop_read,
     start_write, write_samples, stop_write,
-    seek, write_encodings, NULL
+    seek, write_encodings, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/wve.c
+++ b/src/wve.c
@@ -1,5 +1,4 @@
-/*
- * File format: Psion wve   (c) 2008 robs@users.sourceforge.net
+/* libSoX file format: Psion wve   (c) 2008 robs@users.sourceforge.net
  *
  * See http://filext.com/file-extension/WVE
  *
@@ -42,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->length)
+      || lsx_writedw(ft, ft->olength? ft->olength:ft->signal.length)
       || lsx_writechars(ft, ID2, sizeof(ID2))? SOX_EOF:SOX_SUCCESS;
 }
 
@@ -51,13 +50,12 @@
   static char const * const names[] = {"wve", NULL};
   static sox_rate_t   const write_rates[] = {8000, 0};
   static unsigned     const write_encodings[] = {SOX_ENCODING_ALAW, 8, 0, 0};
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
     "Psion 3 audio format",
     names, SOX_FILE_BIG_END | SOX_FILE_MONO | SOX_FILE_REWIND,
     start_read, lsx_rawread, NULL,
     write_header, lsx_rawwrite, NULL,
-    lsx_rawseek, write_encodings, write_rates
+    lsx_rawseek, write_encodings, write_rates, 0
   };
   return &handler;
 }
--- a/src/xa.c
+++ b/src/xa.c
@@ -1,6 +1,5 @@
-/*
- * xa.c  Support for Maxis .XA file format
- * 
+/* libSoX xa.c  Support for Maxis .XA file format
+ *
  *      Copyright (C) 2006 Dwayne C. Litzenberger <dlitz@dlitz.net>
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -16,10 +15,9 @@
  * 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
- *
  */
 
-/* Thanks to Valery V. Anisimovsky <samael@avn.mccme.ru> for the 
+/* Thanks to Valery V. Anisimovsky <samael@avn.mccme.ru> for the
  * "Maxis XA Audio File Format Description", dated 5-01-2002. */
 
 #include "sox_i.h"
@@ -54,7 +52,7 @@
 } xa_state_t;
 
 /* Private data for .xa file */
-typedef struct xastuff {
+typedef struct {
     xa_header_t header;
     xa_state_t *state;
     unsigned int blockSize;
@@ -61,7 +59,7 @@
     unsigned int bufPos;    /* position within the current block */
     unsigned char *buf;     /* buffer for the current block */
     unsigned int bytesDecoded;  /* number of decompressed bytes read */
-} *xa_t;
+} priv_t;
 
 /* coefficients for EA ADPCM */
 static int32_t EA_ADPCM_Table[]= {
@@ -86,7 +84,7 @@
 
 static int startread(sox_format_t * ft)
 {
-    xa_t xa = (xa_t) ft->priv;
+    priv_t * xa = (priv_t *) ft->priv;
     char *magic = xa->header.magic;
 
     /* Check for the magic value */
@@ -98,7 +96,7 @@
         lsx_fail_errno(ft, SOX_EHDR, "XA: Header not found");
         return SOX_EOF;
     }
-    
+
     /* Read the rest of the header */
     if (lsx_readdw(ft, &xa->header.outSize) != SOX_SUCCESS) return SOX_EOF;
     if (lsx_readw(ft, &xa->header.tag) != SOX_SUCCESS) return SOX_EOF;
@@ -126,25 +124,25 @@
 
     /* Populate the sox_soundstream structure */
     ft->encoding.encoding = SOX_ENCODING_SIGN2;
-    
+
     if (!ft->encoding.bits_per_sample || ft->encoding.bits_per_sample == xa->header.bits) {
         ft->encoding.bits_per_sample = xa->header.bits;
     } else {
         sox_report("User options overriding size read in .xa header");
     }
-    
+
     if (ft->signal.channels == 0 || ft->signal.channels == xa->header.channels) {
         ft->signal.channels = xa->header.channels;
     } else {
         sox_report("User options overriding channels read in .xa header");
     }
-    
+
     if (ft->signal.rate == 0 || ft->signal.rate == xa->header.sampleRate) {
         ft->signal.rate = xa->header.sampleRate;
     } else {
         sox_report("User options overriding rate read in .xa header");
     }
-    
+
     /* Check for supported formats */
     if (ft->encoding.bits_per_sample != 16) {
         lsx_fail_errno(ft, SOX_EFMT, "%d-bit sample resolution not supported.",
@@ -151,7 +149,7 @@
             ft->encoding.bits_per_sample);
         return SOX_EOF;
     }
-    
+
     /* Validate the header */
     if (xa->header.bits != ft->encoding.bits_per_sample) {
         sox_report("Invalid sample resolution %d bits.  Assuming %d bits.",
@@ -175,23 +173,23 @@
 
     /* Allocate memory for the block buffer */
     xa->buf = (unsigned char *)lsx_calloc(1, xa->blockSize);
-    
+
     /* Allocate memory for the state */
     xa->state = (xa_state_t *)lsx_calloc(sizeof(xa_state_t), ft->signal.channels);
-    
+
     /* Final initialization */
     xa->bytesDecoded = 0;
-    
+
     return SOX_SUCCESS;
 }
 
-/* 
+/*
  * 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)
 {
-    xa_t xa = (xa_t) ft->priv;
+    priv_t * xa = (priv_t *) ft->priv;
     int32_t sample;
     unsigned char inByte;
     size_t i, done, bytes;
@@ -216,7 +214,7 @@
                 }
             }
             xa->bufPos = 0;
-            
+
             for (i = 0; i < ft->signal.channels; i++) {
                 inByte = xa->buf[i];
                 xa->state[i].c1 = EA_ADPCM_Table[HNIBBLE(inByte)];
@@ -236,7 +234,7 @@
                 sample = clip16(sample);
                 xa->state[i].prevSample = xa->state[i].curSample;
                 xa->state[i].curSample = sample;
-                
+
                 buf[done++] = SOX_SIGNED_16BIT_TO_SAMPLE(sample,);
                 xa->bytesDecoded += (ft->encoding.bits_per_sample >> 3);
             }
@@ -250,7 +248,7 @@
                 sample = clip16(sample);
                 xa->state[i].prevSample = xa->state[i].curSample;
                 xa->state[i].curSample = sample;
-                
+
                 buf[done++] = SOX_SIGNED_16BIT_TO_SAMPLE(sample,);
                 xa->bytesDecoded += (ft->encoding.bits_per_sample >> 3);
             }
@@ -266,7 +264,7 @@
 
 static int stopread(sox_format_t * ft)
 {
-    xa_t xa = (xa_t) ft->priv;
+    priv_t * xa = (priv_t *) ft->priv;
 
     ft->sox_errno = SOX_SUCCESS;
 
@@ -275,7 +273,7 @@
     xa->buf = NULL;
     free(xa->state);
     xa->state = NULL;
-    
+
     return SOX_SUCCESS;
 }
 
@@ -282,13 +280,12 @@
 SOX_FORMAT_HANDLER(xa)
 {
   static char const * const names[] = {"xa", NULL };
-  static sox_format_handler_t const handler = {
-    SOX_LIB_VERSION_CODE,
+  static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
     "16-bit ADPCM audio files used by Maxis games",
     names, SOX_FILE_LIT_END,
     startread, read_samples, stopread,
     NULL, NULL, NULL,
-    NULL, NULL, NULL
+    NULL, NULL, NULL, sizeof(priv_t)
   };
   return &handler;
 }
--- a/src/xmalloc.c
+++ b/src/xmalloc.c
@@ -1,23 +1,21 @@
-/* Memory allocation functions
-   Copyright (c) 2005-2006 Reuben Thomas.
-   All rights reserved.
-
-   This file is part of SoX.
-
-   SoX is free software; you can redistribute it and/or modify it under
-   the terms of the GNU General Public License as published by the Free
-   Software Foundation; either version 2, or (at your option) any later
-   version.
-
-   SoX 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 General Public License
-   for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with SoX; see the file COPYING.  If not, write to the Free
-   Software Foundation, Fifth Floor, 51 Franklin Street, Boston, MA
-   02111-1301, USA.  */
+/* SoX Memory allocation functions
+ *
+ * Copyright (c) 2005-2006 Reuben Thomas.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program 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 General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #include "sox_i.h"
 #include <stdlib.h>
--- a/src/xmalloc.h
+++ b/src/xmalloc.h
@@ -1,32 +1,32 @@
-/* Memory allocation functions
-   Copyright (c) 2005-2006 Reuben Thomas.
-   All rights reserved.
+/* libSoX Memory allocation functions
+ *
+ * Copyright (c) 2005-2006 Reuben Thomas.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program 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 General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
-   This file is part of SoX.
+#ifndef LSX_MALLOC_H
+#define LSX_MALLOC_H
 
-   SoX is free software; you can redistribute it and/or modify it under
-   the terms of the GNU General Public License as published by the Free
-   Software Foundation; either version 2, or (at your option) any later
-   version.
-
-   SoX 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 General Public License
-   for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with SoX; see the file COPYING.  If not, write to the Free
-   Software Foundation, Fifth Floor, 51 Franklin Street, Boston, MA
-   02111-1301, USA.  */
-
-#ifndef XMALLOC_H
-
 #include <stddef.h>
 #include <string.h>
 
-void *lsx_realloc(void *ptr, size_t newsize);
+void *  lsx_realloc(void *ptr, size_t newsize);
 #define lsx_malloc(size) lsx_realloc(NULL, (size))
 #define lsx_calloc(n,s) ((n)*(s)? memset(lsx_malloc((n)*(s)),0,(n)*(s)) : NULL)
-#define lsx_strdup(s) ((s)? strcpy((char *)lsx_malloc(strlen(s) + 1), s) : NULL)
+#define lsx_strdup(p) ((p)? strcpy((char *)lsx_malloc(strlen(p) + 1), p) : NULL)
+#define lsx_memdup(p,s) ((p)? memcpy(lsx_malloc(s), p, s) : NULL)
 
 #endif