shithub: sox

Download patch

ref: abde517163c601b461c47533fef2e35a2dbac535
parent: 408b4f3abef139edb0cdd2ae4c09778d42566fe4
author: robs <robs>
date: Fri Mar 21 09:34:20 EDT 2008

fix (I hope) [1913986] Error during make of static sox

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,7 +52,6 @@
 check_function_exists("gettimeofday"     HAVE_GETTIMEOFDAY)
 check_function_exists("popen"            HAVE_POPEN)
 check_function_exists("strcasecmp"       HAVE_STRCASECMP)
-check_function_exists("strdup"           HAVE_STRDUP)
 check_function_exists("strrstr"          HAVE_STRRSTR)
 check_function_exists("vsnprintf"        HAVE_VSNPRINTF)
 
--- a/libgsm/Makefile.am
+++ b/libgsm/Makefile.am
@@ -29,12 +29,13 @@
 if EXTERNAL_GSM
 EXTRA_DIST = add.c code.c decode.c long_term.c lpc.c preprocess.c \
 	     rpe.c gsm_destroy.c gsm_decode.c gsm_encode.c gsm_create.c \
-	     gsm_option.c short_term.c table.c private.h gsm.h CMakeLists.txt
+	     gsm_option.c short_term.c table.c private.h gsm.h CMakeLists.txt \
+	     aliases.h
 else
 noinst_LTLIBRARIES = libgsm.la
 noinst_HEADERS = gsm.h
 libgsm_la_SOURCES = add.c code.c decode.c long_term.c lpc.c preprocess.c \
 		rpe.c gsm_destroy.c gsm_decode.c gsm_encode.c gsm_create.c \
-		gsm_option.c short_term.c table.c private.h
+		gsm_option.c short_term.c table.c private.h aliases.h
 EXTRA_DIST = CMakeLists.txt
 endif
--- /dev/null
+++ b/libgsm/aliases.h
@@ -1,0 +1,40 @@
+#define gsm_add lsx_gsm_add
+#define gsm_sub lsx_gsm_sub
+#define gsm_mult lsx_gsm_mult
+#define gsm_mult_r lsx_gsm_mult_r
+#define gsm_abs lsx_gsm_abs
+#define gsm_L_mult lsx_gsm_L_mult
+#define gsm_L_add lsx_gsm_L_add
+#define gsm_L_sub lsx_gsm_L_sub
+#define gsm_norm lsx_gsm_norm
+#define gsm_L_asl lsx_gsm_L_asl
+#define gsm_L_asr lsx_gsm_L_asr
+#define gsm_asl lsx_gsm_asl
+#define gsm_asr lsx_gsm_asr
+#define gsm_div lsx_gsm_div
+#define Gsm_Coder lsx_Gsm_Coder
+#define Gsm_Decoder lsx_Gsm_Decoder
+#define gsm_create lsx_gsm_create
+#define gsm_decode lsx_gsm_decode
+#define gsm_destroy lsx_gsm_destroy
+#define gsm_encode lsx_gsm_encode
+#define gsm_option lsx_gsm_option
+#define Gsm_Long_Term_Predictor lsx_Gsm_Long_Term_Predictor
+#define Gsm_Long_Term_Synthesis_Filtering lsx_Gsm_Long_Term_Synthesis_Filtering
+#define Gsm_LPC_Analysis lsx_Gsm_LPC_Analysis
+#define Gsm_Preprocess lsx_Gsm_Preprocess
+#define Gsm_RPE_Encoding lsx_Gsm_RPE_Encoding
+#define Gsm_RPE_Decoding lsx_Gsm_RPE_Decoding
+#define Gsm_Short_Term_Analysis_Filter lsx_Gsm_Short_Term_Analysis_Filter
+#define Gsm_Short_Term_Synthesis_Filter lsx_Gsm_Short_Term_Synthesis_Filter
+#define gsm_A lsx_gsm_A
+#define gsm_B lsx_gsm_B
+#define gsm_MIC lsx_gsm_MIC
+#define gsm_MAC lsx_gsm_MAC
+#define gsm_INVA lsx_gsm_INVA
+#define gsm_DLB lsx_gsm_DLB
+#define gsm_QLB lsx_gsm_QLB
+#define gsm_H lsx_gsm_H
+#define gsm_NRFAC lsx_gsm_NRFAC
+#define gsm_FAC lsx_gsm_FAC
+
--- a/libgsm/gsm.h
+++ b/libgsm/gsm.h
@@ -4,10 +4,12 @@
  * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  */
 
-/*$Header: /cvsroot/sox/sox/libgsm/gsm.h,v 1.1 2007/09/06 16:50:55 cbagwell Exp $*/
+/*$Header: /cvsroot/sox/sox/libgsm/gsm.h,v 1.2 2008/03/21 13:34:21 robs Exp $*/
 
 #ifndef	GSM_H
 #define	GSM_H
+
+#include "aliases.h"
 
 #ifdef __cplusplus
 #	define	NeedFunctionPrototypes	1
--- a/libgsm/private.h
+++ b/libgsm/private.h
@@ -1,3 +1,4 @@
+#include "aliases.h"
 /*
  * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
@@ -4,7 +5,7 @@
  * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  */
 
-/*$Header: /cvsroot/sox/sox/libgsm/private.h,v 1.2 2007/11/04 16:32:36 robs Exp $*/
+/*$Header: /cvsroot/sox/sox/libgsm/private.h,v 1.3 2008/03/21 13:34:21 robs Exp $*/
 
 #ifndef	PRIVATE_H
 #define	PRIVATE_H
--- a/lpc10/lpc10.h
+++ b/lpc10/lpc10.h
@@ -1,6 +1,9 @@
 /*
 
 $Log: lpc10.h,v $
+Revision 1.3  2008/03/21 13:34:21  robs
+fix (I hope) [1913986] Error during make of static sox
+
 Revision 1.2  2007/12/26 16:12:42  robs
 support out-of-source-build
 
@@ -21,6 +24,50 @@
 #define __LPC10_H__
 
 #include "soxstdint.h"
+
+/* aliases */
+#define analys_ lsx_lpc10_analys_
+#define bsynz_ lsx_lpc10_bsynz_
+#define chanrd_ lsx_lpc10_chanrd_
+#define chanwr_ lsx_lpc10_chanwr_
+#define contrl_ lsx_lpc10_contrl_
+#define create_lpc10_decoder_state lsx_lpc10_create_decoder_state
+#define create_lpc10_encoder_state lsx_lpc10_create_encoder_state
+#define dcbias_ lsx_lpc10_dcbias_
+#define decode_ lsx_lpc10_decode_
+#define deemp_ lsx_lpc10_deemp_
+#define difmag_ lsx_lpc10_difmag_
+#define dyptrk_ lsx_lpc10_dyptrk_
+#define encode_ lsx_lpc10_encode_
+#define energy_ lsx_lpc10_energy_
+#define ham84_ lsx_lpc10_ham84_
+#define hp100_ lsx_lpc10_hp100_
+#define i_nint lsx_lpc10_i_nint
+#define init_lpc10_decoder_state lsx_lpc10_init_decoder_state
+#define init_lpc10_encoder_state lsx_lpc10_init_encoder_state
+#define invert_ lsx_lpc10_invert_
+#define irc2pc_ lsx_lpc10_irc2pc_
+#define ivfilt_ lsx_lpc10_ivfilt_
+#define lpc10_decode lsx_lpc10_decode
+#define lpc10_encode lsx_lpc10_encode
+#define lpcini_ lsx_lpc10_lpcini_
+#define lpfilt_ lsx_lpc10_lpfilt_
+#define median_ lsx_lpc10_median_
+#define mload_ lsx_lpc10_mload_
+#define onset_ lsx_lpc10_onset_
+#define pitsyn_ lsx_lpc10_pitsyn_
+#define placea_ lsx_lpc10_placea_
+#define placev_ lsx_lpc10_placev_
+#define pow_ii lsx_lpc10_pow_ii
+#define preemp_ lsx_lpc10_preemp_
+#define prepro_ lsx_lpc10_prepro_
+#define random_ lsx_lpc10_random_
+#define rcchk_ lsx_lpc10_rcchk_
+#define r_sign lsx_lpc10_r_sign
+#define synths_ lsx_lpc10_synths_
+#define tbdm_ lsx_lpc10_tbdm_
+#define voicin_ lsx_lpc10_voicin_
+#define vparms_ lsx_lpc10_vparms_
 
 #define LPC10_SAMPLES_PER_FRAME 180
 #define LPC10_BITS_IN_COMPRESSED_FRAME 54
--- a/soxeffect.7
+++ b/soxeffect.7
@@ -853,12 +853,12 @@
 channels are involved, a script such as the following is useful:
 .EX
 #!/bin/sh                        # This is a Bourne shell script
-chans=$(soxi -c "$1")
+chans=\`soxi -c "$1"\`
 while [ $chans -ge 1 ]; do
-  chans0=$(printf %02i $chans)   # 2 digits hence up to 99 chans
-  out=$(echo "$1"|sed "s/\\(.*\\)\\.\\(.*\\)/\\1-$chans0.\\2/")
+  chans0=\`printf %02i $chans\`   # 2 digits hence up to 99 chans
+  out=\`echo "$1"|sed "s/\\(.*\\)\\.\\(.*\\)/\\1-$chans0.\\2/"\`
   sox "$1" "$out" remix $chans
-  chans=$(expr $chans - 1)
+  chans=\`expr $chans - 1\`
 done
 .EE
 If a file
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -88,7 +88,7 @@
                         lsx_readdw(ft, &chunksize);
                         if (chunksize & 1)
                                 chunksize++;
-                        chunk_buf = (char *) xmalloc(chunksize + 2);
+                        chunk_buf = (char *) lsx_malloc(chunksize + 2);
                         if (lsx_readbuf(ft, chunk_buf,(size_t)chunksize)
                                         != chunksize)
                         {
@@ -106,7 +106,7 @@
                         lsx_readdw(ft, &chunksize);
                         if (chunksize & 1)
                                 chunksize++;
-                        chunk_buf = (char *) xmalloc(chunksize + 1);
+                        chunk_buf = (char *) lsx_malloc(chunksize + 1);
                         if (lsx_readbuf(ft, chunk_buf,(size_t)chunksize)
                                         != chunksize)
                         {
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -44,9 +44,9 @@
 )
 add_library(lib${PROJECT_NAME}
   effects                 ${formats_srcs}         ${optional_srcs}
-  effects_i               getopt                  util
+  effects_i               getopt                  soxstdint
   ${effects_srcs}         getopt1                 xmalloc
-  formats                 libsox soxstdint
+  formats                 libsox
   formats_i               libsox_i
 )
 add_executable(${PROJECT_NAME} ${PROJECT_NAME}.c)
--- a/src/FFT.c
+++ b/src/FFT.c
@@ -97,12 +97,12 @@
 {
    unsigned len, b;
    
-   gFFTBitTable = xcalloc(MaxFastBits, sizeof(*gFFTBitTable));
+   gFFTBitTable = lsx_calloc(MaxFastBits, sizeof(*gFFTBitTable));
    
    for (b = 1, len = 2; b <= MaxFastBits; b++) {
       unsigned i;
 
-      gFFTBitTable[b - 1] = xcalloc(len, sizeof(**gFFTBitTable));
+      gFFTBitTable[b - 1] = lsx_calloc(len, sizeof(**gFFTBitTable));
       for (i = 0; i < len; i++)
         gFFTBitTable[b - 1][i] = ReverseBits(i, b);
 
@@ -238,7 +238,7 @@
    float h1r, h1i, h2r, h2i;
    float *tmpReal, *tmpImag;
 
-   tmpReal = (float*)xcalloc(NumSamples, sizeof(float));
+   tmpReal = (float*)lsx_calloc(NumSamples, sizeof(float));
    tmpImag = tmpReal + Half;
 
    for (i = 0; i < Half; i++) {
@@ -299,7 +299,7 @@
 
   theta = M_PI / Half;
 
-  tmpReal = (float*)xcalloc(Half * 4, sizeof(float));
+  tmpReal = (float*)lsx_calloc(Half * 4, sizeof(float));
   tmpImag = tmpReal + Half;
   RealOut = tmpImag + Half;
   ImagOut = RealOut + Half;
--- a/src/FFT.h
+++ b/src/FFT.h
@@ -1,3 +1,11 @@
+/* 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
  *
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -211,7 +211,7 @@
 libsox_la_SOURCES = adpcms.c adpcms.h aiff.c aiff.h cvsd.c cvsd.h cvsdfilt.h \
 	  g711.c g711.h g721.c g723_24.c g723_40.c g72x.c g72x.h vox.c vox.h \
 	  raw.c raw.h formats.c formats.h formats_i.c sox_i.h skelform.c \
-	  util.c xmalloc.c xmalloc.h getopt.c getopt1.c getopt.h \
+	  xmalloc.c xmalloc.h getopt.c getopt1.c getopt.h \
 	  soxconfig.h util.h libsox.c libsox_i.c
 libsox_la_CFLAGS = 
 
--- a/src/adpcm.c
+++ b/src/adpcm.c
@@ -41,7 +41,7 @@
 
 typedef struct MsState {
         sox_sample_t  step;      /* step size */
-        short iCoef[2];
+        short lsx_ms_adpcm_i_coef[2];
 } MsState_t;
 
 #define lsbshortldi(x,p) { (x)=((short)((int)(p)[0] + ((int)(p)[1]<<8))); (p) += 2; }
@@ -59,11 +59,11 @@
         768, 614, 512, 409, 307, 230, 230, 230
 };
 
-/* TODO : The first 7 iCoef sets are always hardcoded and must
+/* TODO : The first 7 lsx_ms_adpcm_i_coef sets are always hardcoded and must
    appear in the actual WAVE file.  They should be read in
    in case a sound program added extras to the list. */
 
-const short iCoef[7][2] = {
+const short lsx_ms_adpcm_i_coef[7][2] = {
                         { 256,   0},
                         { 512,-256},
                         {   0,   0},
@@ -90,8 +90,8 @@
 
         /** make linear prediction for next sample **/
         vlin =
-                        ((sample1 * state->iCoef[0]) +
-                         (sample2 * state->iCoef[1])) >> 8;
+                        ((sample1 * state->lsx_ms_adpcm_i_coef[0]) +
+                         (sample2 * state->lsx_ms_adpcm_i_coef[1])) >> 8;
         /** then add the code*step adjustment **/
         c -= (c & 0x08) << 1;
         sample = (c * step) + vlin;
@@ -102,11 +102,11 @@
         return (sample);
 }
 
-/* AdpcmBlockExpandI() outputs interleaved samples into one output buffer */
-const char *AdpcmBlockExpandI(
+/* lsx_ms_adpcm_block_expand_i() outputs interleaved samples into one output buffer */
+const char *lsx_ms_adpcm_block_expand_i(
         unsigned chans,          /* total channels             */
         int nCoef,
-        const short *iCoef,
+        const short *lsx_ms_adpcm_i_coef,
         const unsigned char *ibuff,/* input buffer[blockAlign]   */
         SAMPL *obuff,       /* output samples, n*chans    */
         int n               /* samples to decode PER channel */
@@ -125,8 +125,8 @@
                         errmsg = "MSADPCM bpred >= nCoef, arbitrarily using 0\n";
                         bpred = 0;
                 }
-                state[ch].iCoef[0] = iCoef[(int)bpred*2+0];
-                state[ch].iCoef[1] = iCoef[(int)bpred*2+1];
+                state[ch].lsx_ms_adpcm_i_coef[0] = lsx_ms_adpcm_i_coef[(int)bpred*2+0];
+                state[ch].lsx_ms_adpcm_i_coef[1] = lsx_ms_adpcm_i_coef[(int)bpred*2+1];
 
         }
 
@@ -170,7 +170,7 @@
         unsigned ch,              /* channel number to encode, REQUIRE 0 <= ch < chans  */
         unsigned chans,           /* total channels */
         SAMPL v[2],          /* values to use as starting 2 */
-        const short iCoef[2],/* lin predictor coeffs */
+        const short lsx_ms_adpcm_i_coef[2],/* lin predictor coeffs */
         const SAMPL *ibuff,  /* ibuff[] is interleaved input samples */
         int n,               /* samples to encode PER channel */
         int *iostep,         /* input/output step, REQUIRE 16 <= *st <= 0x7fff */
@@ -210,7 +210,7 @@
                 int vlin,d,dp,c;
 
           /* make linear prediction for next sample */
-                vlin = (v0 * iCoef[0] + v1 * iCoef[1]) >> 8;
+                vlin = (v0 * lsx_ms_adpcm_i_coef[0] + v1 * lsx_ms_adpcm_i_coef[1]) >> 8;
                 d = *ip - vlin;  /* difference between linear prediction and current sample */
                 dp = d + (step<<3) + (step>>1);
                 c = 0;
@@ -275,13 +275,13 @@
         for (k=0; k<7; k++) {
                 int d0,d1;
                 ss = s0 = *st;
-                d0=AdpcmMashS(ch, chans, v, iCoef[k], ip, n, &ss, NULL); /* with step s0 */
+                d0=AdpcmMashS(ch, chans, v, lsx_ms_adpcm_i_coef[k], ip, n, &ss, NULL); /* with step s0 */
 
                 s1 = s0;
-                AdpcmMashS(ch, chans, v, iCoef[k], ip, n0, &s1, NULL);
+                AdpcmMashS(ch, chans, v, lsx_ms_adpcm_i_coef[k], ip, n0, &s1, NULL);
                 sox_debug_more(" s32 %d\n",s1);
                 ss = s1 = (3*s0+s1)/4;
-                d1=AdpcmMashS(ch, chans, v, iCoef[k], ip, n, &ss, NULL); /* with step s1 */
+                d1=AdpcmMashS(ch, chans, v, lsx_ms_adpcm_i_coef[k], ip, n, &ss, NULL); /* with step s1 */
                 if (!k || d0<dmin || d1<dmin) {
                         kmin = k;
                         if (d0<=d1) {
@@ -295,11 +295,11 @@
         }
         *st = smin;
         sox_debug_more("kmin %d, smin %5d, ",kmin,smin);
-        d=AdpcmMashS(ch, chans, v, iCoef[kmin], ip, n, st, obuff);
+        d=AdpcmMashS(ch, chans, v, lsx_ms_adpcm_i_coef[kmin], ip, n, st, obuff);
         obuff[ch] = kmin;
 }
 
-void AdpcmBlockMashI(
+void lsx_ms_adpcm_block_mash_i(
         unsigned chans,          /* total channels */
         const SAMPL *ip,    /* ip[n*chans] is interleaved input samples */
         int n,              /* samples to encode PER channel */
@@ -321,7 +321,7 @@
 }
 
 /*
- * AdpcmSamplesIn(dataLen, chans, blockAlign, samplesPerBlock)
+ * lsx_ms_adpcm_samples_in(dataLen, chans, blockAlign, samplesPerBlock)
  *  returns the number of samples/channel which would be
  *  in the dataLen, given the other parameters ...
  *  if input samplesPerBlock is 0, then returns the max
@@ -328,7 +328,7 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing usage.
  */
-sox_size_t AdpcmSamplesIn(
+sox_size_t lsx_ms_adpcm_samples_in(
         sox_size_t dataLen,
         sox_size_t chans,
         sox_size_t blockAlign,
@@ -352,7 +352,7 @@
         return n;
 }
 
-sox_size_t AdpcmBytesPerBlock(
+sox_size_t lsx_ms_adpcm_bytes_per_block(
         sox_size_t chans,
         sox_size_t samplesPerBlock
 )
--- a/src/adpcm.h
+++ b/src/adpcm.h
@@ -8,19 +8,19 @@
 #endif
 
 /* default coef sets */
-extern const short iCoef[7][2];
+extern const short lsx_ms_adpcm_i_coef[7][2];
 
-/* AdpcmBlockExpandI() outputs interleaved samples into one output buffer */
-extern const char *AdpcmBlockExpandI(
+/* lsx_ms_adpcm_block_expand_i() outputs interleaved samples into one output buffer */
+extern const char *lsx_ms_adpcm_block_expand_i(
 	unsigned chans,          /* total channels             */
 	int nCoef,
-	const short *iCoef,
+	const short *lsx_ms_adpcm_i_coef,
 	const unsigned char *ibuff,/* input buffer[blockAlign]   */
 	SAMPL *obuff,       /* output samples, n*chans    */
 	int n               /* samples to decode PER channel, REQUIRE n % 8 == 1  */
 );
 
-extern void AdpcmBlockMashI(
+extern void lsx_ms_adpcm_block_mash_i(
 	unsigned chans,          /* total channels */
 	const SAMPL *ip,    /* ip[n*chans] is interleaved input samples */
 	int n,              /* samples to encode PER channel, REQUIRE */
@@ -32,7 +32,7 @@
 /* Some helper functions for computing samples/block and blockalign */
 
 /*
- * AdpcmSamplesIn(dataLen, chans, blockAlign, samplesPerBlock)
+ * lsx_ms_adpcm_samples_in(dataLen, chans, blockAlign, samplesPerBlock)
  *  returns the number of samples/channel which would be
  *  in the dataLen, given the other parameters ...
  *  if input samplesPerBlock is 0, then returns the max
@@ -39,7 +39,7 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing usage.
  */
-extern sox_size_t AdpcmSamplesIn(
+extern sox_size_t lsx_ms_adpcm_samples_in(
 	sox_size_t dataLen,
 	sox_size_t chans,
 	sox_size_t blockAlign,
@@ -47,11 +47,11 @@
 );
 
 /*
- * sox_size_t AdpcmBytesPerBlock(chans, samplesPerBlock)
+ * sox_size_t lsx_ms_adpcm_bytes_per_block(chans, samplesPerBlock)
  *   return minimum blocksize which would be required
  *   to encode number of chans with given samplesPerBlock
  */
-extern sox_size_t AdpcmBytesPerBlock(
+extern sox_size_t lsx_ms_adpcm_bytes_per_block(
 	sox_size_t chans,
 	sox_size_t samplesPerBlock
 );
--- a/src/adpcms.c
+++ b/src/adpcms.c
@@ -54,7 +54,7 @@
   { 5, 2, 0, cl2_steps, cl2_changes , ~255},
 };
 
-void adpcm_init(adpcm_t * p, int type, int first_sample)
+void lsx_adpcm_init(adpcm_t * p, int type, int first_sample)
 {
   p->setup = setup_table[type];
   p->last_output = first_sample;
@@ -65,7 +65,7 @@
 #define min_sample -0x8000
 #define max_sample 0x7fff
 
-int adpcm_decode(int code, adpcm_t * p)
+int lsx_adpcm_decode(int code, adpcm_t * p)
 {
   int s = ((code & (p->setup.sign - 1)) << 1) | 1;
   s = ((p->setup.steps[p->step_index] * s) >> (p->setup.shift + 1)) & p->setup.mask;
@@ -86,7 +86,7 @@
   return p->last_output = s;
 }
 
-int adpcm_encode(int sample, adpcm_t * p)
+int lsx_adpcm_encode(int sample, adpcm_t * p)
 {
   int delta = sample - p->last_output;
   int sign = 0;
@@ -97,7 +97,7 @@
   }
   code = (delta << p->setup.shift) / p->setup.steps[p->step_index];
   code = sign | min(code, p->setup.sign - 1);
-  adpcm_decode(code, p); /* Update encoder state */
+  lsx_adpcm_decode(code, p); /* Update encoder state */
   return code;
 }
 
@@ -127,7 +127,7 @@
   state->store.byte = 0;
   state->store.flag = 0;
 
-  adpcm_init(&state->encoder, (type == SOX_ENCODING_OKI_ADPCM) ? 1 : 0, 0);
+  lsx_adpcm_init(&state->encoder, (type == SOX_ENCODING_OKI_ADPCM) ? 1 : 0, 0);
 }
 
 /******************************************************************************
@@ -150,7 +150,7 @@
 static int adpcm_start(sox_format_t * ft, adpcm_io_t state, sox_encoding_t type)
 {
   /* setup file info */
-  state->file.buf = (char *) xmalloc(sox_globals.bufsiz);
+  state->file.buf = (char *) lsx_malloc(sox_globals.bufsiz);
   state->file.size = sox_globals.bufsiz;
   ft->signal.channels = 1;
 
@@ -189,17 +189,17 @@
   int16_t word;
 
   if (len && state->store.flag) {
-    word = adpcm_decode(state->store.byte, &state->encoder);
+    word = lsx_adpcm_decode(state->store.byte, &state->encoder);
     *buffer++ = SOX_SIGNED_16BIT_TO_SAMPLE(word, ft->clips);
     state->store.flag = 0;
     ++n;
   }
   while (n < len && lsx_read_b_buf(ft, &byte, 1) == 1) {
-    word = adpcm_decode(byte >> 4, &state->encoder);
+    word = lsx_adpcm_decode(byte >> 4, &state->encoder);
     *buffer++ = SOX_SIGNED_16BIT_TO_SAMPLE(word, ft->clips);
 
     if (++n < len) {
-      word = adpcm_decode(byte, &state->encoder);
+      word = lsx_adpcm_decode(byte, &state->encoder);
       *buffer++ = SOX_SIGNED_16BIT_TO_SAMPLE(word, ft->clips);
       ++n;
     } else {
@@ -255,7 +255,7 @@
     word = SOX_SAMPLE_TO_SIGNED_16BIT(*buffer++, ft->clips);
 
     byte <<= 4;
-    byte |= adpcm_encode(word, &state->encoder) & 0x0F;
+    byte |= lsx_adpcm_encode(word, &state->encoder) & 0x0F;
 
     flag = !flag;
 
--- a/src/adpcms.h
+++ b/src/adpcms.h
@@ -32,9 +32,9 @@
   int errors;
 } adpcm_t;
 
-void adpcm_init(adpcm_t * p, int type, int first_sample);
-int adpcm_decode(int code, adpcm_t * p);
-int adpcm_encode(int sample, adpcm_t * p);
+void lsx_adpcm_init(adpcm_t * p, int type, int first_sample);
+int lsx_adpcm_decode(int code, adpcm_t * p);
+int lsx_adpcm_encode(int sample, adpcm_t * p);
 
 typedef struct adpcm_io {
   adpcm_t encoder;
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -517,7 +517,7 @@
   uint32_t chunksize;
   lsx_readdw(ft, &chunksize);
   /* allocate enough memory to hold the text including a terminating \0 */
-  *text = (char *) xmalloc((size_t) chunksize + 1);
+  *text = (char *) lsx_malloc((size_t) chunksize + 1);
   if (lsx_readbuf(ft, *text, chunksize) != chunksize)
   {
     lsx_fail_errno(ft,SOX_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
@@ -567,10 +567,10 @@
     totalCommentLength += commentLength;
     /* allocate enough memory to hold the text including a terminating \0 */
     if(commentIndex == 0) {
-      *text = (char *) xmalloc((size_t) totalCommentLength + 1);
+      *text = (char *) lsx_malloc((size_t) totalCommentLength + 1);
     }
     else {
-      *text = xrealloc(*text, (size_t) totalCommentLength + 1);
+      *text = lsx_realloc(*text, (size_t) totalCommentLength + 1);
     }
 
     if (lsx_readbuf(ft, *text + totalCommentLength - commentLength, commentLength) != commentLength) {
--- a/src/alsa.c
+++ b/src/alsa.c
@@ -372,7 +372,7 @@
     alsa->buf_size = buffer_size * (ft->encoding.bits_per_sample >> 3) * ft->signal.channels;
     alsa->period_size = period_size;
     alsa->frames_this_period = 0;
-    alsa->buf = xmalloc(alsa->buf_size);
+    alsa->buf = lsx_malloc(alsa->buf_size);
 
     return (SOX_SUCCESS);
 
@@ -648,7 +648,7 @@
 
   /* Pad to hardware period: */
   sox_size_t npad = (alsa->period_size - alsa->frames_this_period) * ft->signal.channels;
-  sox_sample_t * buf = xcalloc(npad, sizeof(*buf)); /* silent samples */
+  sox_sample_t * buf = lsx_calloc(npad, sizeof(*buf)); /* silent samples */
   write_samples(ft, buf, npad);
   free(buf);
 
--- a/src/ao.c
+++ b/src/ao.c
@@ -40,7 +40,7 @@
   lsx_set_signal_defaults(&ft->signal);
   ao->buf_size = sox_globals.bufsiz - (sox_globals.bufsiz % (ft->encoding.bits_per_sample >> 3));
   ao->buf_size *= (ft->encoding.bits_per_sample >> 3);
-  ao->buf = xmalloc(ao->buf_size);
+  ao->buf = lsx_malloc(ao->buf_size);
 
   if (!ao->buf)
   {
--- a/src/au.c
+++ b/src/au.c
@@ -178,7 +178,7 @@
 
   if (hdr_size > FIXED_HDR) {
     size_t info_size = hdr_size - FIXED_HDR;
-    char * buf = xcalloc(1, info_size + 1); /* +1 ensures null-terminated */
+    char * buf = lsx_calloc(1, info_size + 1); /* +1 ensures null-terminated */
     if (lsx_readchars(ft, buf, info_size) != SOX_SUCCESS) {
       free(buf);
       return SOX_EOF;
--- a/src/chorus.c
+++ b/src/chorus.c
@@ -199,7 +199,7 @@
                         return (SOX_EOF);
                 }
                 chorus->length[i] = effp->in_signal.rate / chorus->speed[i];
-                chorus->lookup_tab[i] = (int *) xmalloc(sizeof (int) * chorus->length[i]);
+                chorus->lookup_tab[i] = (int *) lsx_malloc(sizeof (int) * chorus->length[i]);
 
                 if (chorus->modulation[i] == MOD_SINE)
                   lsx_generate_wave_table(SOX_WAVE_SINE, SOX_INT, chorus->lookup_tab[i],
@@ -223,7 +223,7 @@
         sox_warn("chorus: warning >>> gain-out can cause saturation or clipping of output <<<");
 
 
-        chorus->chorusbuf = (float *) xmalloc(sizeof (float) * chorus->maxsamples);
+        chorus->chorusbuf = (float *) lsx_malloc(sizeof (float) * chorus->maxsamples);
         for ( i = 0; i < chorus->maxsamples; i++ )
                 chorus->chorusbuf[i] = 0.0;
 
--- a/src/compand.c
+++ b/src/compand.c
@@ -78,7 +78,7 @@
     return SOX_EOF;
   }
   pairs = 1 + commas/2;
-  l->channels = xcalloc(pairs, sizeof(*l->channels));
+  l->channels = lsx_calloc(pairs, sizeof(*l->channels));
   l->expectedChannels = pairs;
 
   /* Now tokenise the rates string and set up these arrays.  Keep
@@ -151,7 +151,7 @@
   /* Allocate the delay buffer */
   l->delay_buf_size = l->delay * effp->out_signal.rate * effp->out_signal.channels;
   if (l->delay_buf_size > 0)
-    l->delay_buf = xcalloc((sox_size_t)l->delay_buf_size, sizeof(*l->delay_buf));
+    l->delay_buf = lsx_calloc((sox_size_t)l->delay_buf_size, sizeof(*l->delay_buf));
   l->delay_buf_index = 0;
   l->delay_buf_cnt = 0;
   l->delay_buf_full= 0;
--- a/src/compandt.c
+++ b/src/compandt.c
@@ -170,7 +170,7 @@
   ++pairs;    /* allow room for extra pair at the beginning */
   pairs *= 2; /* allow room for the auto-curves */
   ++pairs;    /* allow room for 0,0 at end */
-  t->segments = xcalloc(pairs, sizeof(*t->segments));
+  t->segments = lsx_calloc(pairs, sizeof(*t->segments));
 
 #define s(n) t->segments[2*((n)+1)]
   for (i = 0, text = strtok(points, ","); text != NULL; ++i) {
--- a/src/deemph.plt
+++ b/src/deemph.plt
@@ -2,7 +2,8 @@
 #
 # 09/02/98 (c) Heiko Eissfeldt
 #
-# 18/03/07 robs@users.sourceforge.net: changed to biquad for better accuracy.
+# 18/03/07 robs@users.sourceforge.net: changed to biquad for slightly
+# better accuracy.
 #
 # License: LGPL (Lesser Gnu Public License)
 #
--- a/src/delay.c
+++ b/src/delay.c
@@ -46,9 +46,9 @@
   sox_size_t delay, max_samples = 0;
   unsigned i;
 
-  p->argv = xcalloc(p->argc = argc, sizeof(*p->argv));
+  p->argv = lsx_calloc(p->argc = argc, sizeof(*p->argv));
   for (i = 0; i < p->argc; ++i) {
-    char const * next = lsx_parsesamples(96000., p->argv[i] = xstrdup(argv[i]), &delay, 't');
+    char const * next = lsx_parsesamples(96000., p->argv[i] = lsx_strdup(argv[i]), &delay, 't');
     if (!next || *next) {
       kill(effp);
       return lsx_usage(effp);
@@ -80,7 +80,7 @@
   lsx_parsesamples(effp->in_signal.rate, p->max_arg, &max_delay, 't');
   p->buffer_index = p->delay = 0;
   p->pad = max_delay - p->buffer_size;
-  p->buffer = xmalloc(p->buffer_size * sizeof(*p->buffer));
+  p->buffer = lsx_malloc(p->buffer_size * sizeof(*p->buffer));
   return SOX_SUCCESS;
 }
 
--- a/src/echo.c
+++ b/src/echo.c
@@ -158,7 +158,7 @@
                 if ( echo->samples[i] > echo->maxsamples )
                         echo->maxsamples = echo->samples[i];
         }
-        echo->delay_buf = (double *) xmalloc(sizeof (double) * echo->maxsamples);
+        echo->delay_buf = (double *) lsx_malloc(sizeof (double) * echo->maxsamples);
         for ( j = 0; j < echo->maxsamples; ++j )
                 echo->delay_buf[j] = 0.0;
         /* Be nice and check the hint with warning, if... */
--- a/src/echos.c
+++ b/src/echos.c
@@ -152,7 +152,7 @@
                 echos->pointer[i] = echos->sumsamples;
                 echos->sumsamples += echos->samples[i];
         }
-        echos->delay_buf = (double *) xmalloc(sizeof (double) * echos->sumsamples);
+        echos->delay_buf = (double *) lsx_malloc(sizeof (double) * echos->sumsamples);
         for ( j = 0; j < echos->sumsamples; ++j )
                 echos->delay_buf[j] = 0.0;
         /* Be nice and check the hint with warning, if... */
--- a/src/effects.c
+++ b/src/effects.c
@@ -87,7 +87,7 @@
     sox_encodinginfo_t const * in_enc,
     sox_encodinginfo_t const * out_enc)
 {
-  sox_effects_chain_t * result = xcalloc(1, sizeof(sox_effects_chain_t));
+  sox_effects_chain_t * result = lsx_calloc(1, sizeof(sox_effects_chain_t));
   result->global_info = sox_effects_globals;
   result->in_enc = in_enc;
   result->out_enc = out_enc;
@@ -154,7 +154,7 @@
     return SOX_EOF;
   }
   chain->effects[chain->length] =
-    xcalloc(effp->flows, sizeof(chain->effects[chain->length][0]));
+    lsx_calloc(effp->flows, sizeof(chain->effects[chain->length][0]));
   chain->effects[chain->length][0] = *effp;
 
   for (f = 1; f < effp->flows; ++f) {
@@ -289,16 +289,16 @@
   sox_bool draining = sox_true;
 
   for (e = 0; e < chain->length; ++e) {
-    chain->effects[e][0].obuf = xmalloc(sox_globals.bufsiz * sizeof(chain->effects[e][0].obuf[0]));
+    chain->effects[e][0].obuf = lsx_malloc(sox_globals.bufsiz * sizeof(chain->effects[e][0].obuf[0]));
     chain->effects[e][0].obeg = chain->effects[e][0].oend = 0;
     max_flows = max(max_flows, chain->effects[e][0].flows);
   }
 
-  chain->ibufc = xcalloc(max_flows, sizeof(*chain->ibufc));
-  chain->obufc = xcalloc(max_flows, sizeof(*chain->obufc));
+  chain->ibufc = lsx_calloc(max_flows, sizeof(*chain->ibufc));
+  chain->obufc = lsx_calloc(max_flows, sizeof(*chain->obufc));
   for (f = 0; f < max_flows; ++f) {
-    chain->ibufc[f] = xcalloc(sox_globals.bufsiz / 2, sizeof(chain->ibufc[f][0]));
-    chain->obufc[f] = xcalloc(sox_globals.bufsiz / 2, sizeof(chain->obufc[f][0]));
+    chain->ibufc[f] = lsx_calloc(sox_globals.bufsiz / 2, sizeof(chain->ibufc[f][0]));
+    chain->obufc[f] = lsx_calloc(sox_globals.bufsiz / 2, sizeof(chain->obufc[f][0]));
   }
 
   e = chain->length - 1;
--- a/src/fade.c
+++ b/src/fade.c
@@ -73,7 +73,7 @@
         fade->out_fadetype = 'l';
     }
 
-    fade->in_stop_str = (char *)xmalloc(strlen(argv[0])+1);
+    fade->in_stop_str = (char *)lsx_malloc(strlen(argv[0])+1);
     strcpy(fade->in_stop_str,argv[0]);
     /* Do a dummy parse to see if it will fail */
     if (lsx_parsesamples(0., fade->in_stop_str, &fade->in_stop, 't') == NULL)
@@ -86,7 +86,7 @@
         /* See if there is fade-in/fade-out times/curves specified. */
         if(t_argno == 1)
         {
-            fade->out_stop_str = (char *)xmalloc(strlen(argv[t_argno])+1);
+            fade->out_stop_str = (char *)lsx_malloc(strlen(argv[t_argno])+1);
             strcpy(fade->out_stop_str,argv[t_argno]);
 
             /* Do a dummy parse to see if it will fail */
@@ -96,7 +96,7 @@
         }
         else
         {
-            fade->out_start_str = (char *)xmalloc(strlen(argv[t_argno])+1);
+            fade->out_start_str = (char *)lsx_malloc(strlen(argv[t_argno])+1);
             strcpy(fade->out_start_str,argv[t_argno]);
 
             /* Do a dummy parse to see if it will fail */
--- a/src/ffmpeg.c
+++ b/src/ffmpeg.c
@@ -155,7 +155,7 @@
   int ret;
   int i;
 
-  ffmpeg->audio_buf = xcalloc(1, AVCODEC_MAX_AUDIO_FRAME_SIZE);
+  ffmpeg->audio_buf = lsx_calloc(1, AVCODEC_MAX_AUDIO_FRAME_SIZE);
 
   /* Signal audio stream not found */
   ffmpeg->audio_index = -1;
@@ -302,7 +302,7 @@
     return SOX_EOF;
   }
 
-  ffmpeg->audio_buf = xmalloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
+  ffmpeg->audio_buf = lsx_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
 
   /* ugly hack for PCM codecs (will be removed ASAP with new PCM
      support to compute the input frame size in samples */
@@ -321,7 +321,7 @@
   } else
     ffmpeg->audio_input_frame_size = c->frame_size;
 
-  ffmpeg->samples = xmalloc((size_t)(ffmpeg->audio_input_frame_size * 2 * c->channels));
+  ffmpeg->samples = lsx_malloc((size_t)(ffmpeg->audio_input_frame_size * 2 * c->channels));
 
   return SOX_SUCCESS;
 }
--- a/src/fifo.h
+++ b/src/fifo.h
@@ -30,12 +30,12 @@
 
 #define FIFO_MIN 0x4000
 
-static void fifo_clear(fifo_t * f)
+UNUSED static void fifo_clear(fifo_t * f)
 {
   f->end = f->begin = 0;
 }
 
-static void * fifo_reserve(fifo_t * f, size_t n)
+UNUSED static void * fifo_reserve(fifo_t * f, size_t n)
 {
   n *= f->item_size;
 
@@ -56,11 +56,11 @@
       continue;
     }
     f->allocation += n;
-    f->data = xrealloc(f->data, f->allocation);
+    f->data = lsx_realloc(f->data, f->allocation);
   }
 }
 
-static void * fifo_write(fifo_t * f, size_t n, void const * data)
+UNUSED static void * fifo_write(fifo_t * f, size_t n, void const * data)
 {
   void * s = fifo_reserve(f, n);
   if (data)
@@ -68,18 +68,18 @@
   return s;
 }
 
-static void UNUSED fifo_trim(fifo_t * f, size_t n)
+UNUSED static void fifo_trim(fifo_t * f, size_t n)
 {
   n *= f->item_size;
   f->end = f->begin + n;
 }
 
-static size_t UNUSED fifo_occupancy(fifo_t * f)
+UNUSED static size_t fifo_occupancy(fifo_t * f)
 {
   return (f->end - f->begin) / f->item_size;
 }
 
-static void * fifo_read(fifo_t * f, size_t n, void * data)
+UNUSED static void * fifo_read(fifo_t * f, size_t n, void * data)
 {
   char * ret = f->data + f->begin;
   n *= f->item_size;
@@ -93,16 +93,16 @@
 
 #define fifo_read_ptr(f) fifo_read(f, 0, NULL)
 
-static void fifo_delete(fifo_t * f)
+UNUSED static void fifo_delete(fifo_t * f)
 {
   free(f->data);
 }
 
-static void fifo_create(fifo_t * f, size_t item_size)
+UNUSED static void fifo_create(fifo_t * f, size_t item_size)
 {
   f->item_size = item_size;
   f->allocation = FIFO_MIN;
-  f->data = xmalloc(f->allocation);
+  f->data = lsx_malloc(f->allocation);
   fifo_clear(f);
 }
 
--- a/src/filter.c
+++ b/src/filter.c
@@ -43,9 +43,9 @@
         double *X, *Y;/* I/O buffers */
 } *filter_t;
 
-/* makeFilter() declared in resample.c */
+/* lsx_makeFilter() declared in resample.c */
 extern int 
-makeFilter(double Fp[], long Nwing, double Froll, double Beta, long Num, int Normalize);
+lsx_makeFilter(double Fp[], long Nwing, double Froll, double Beta, long Num, int Normalize);
 
 static void FiltWin(filter_t f, long Nx);
 
@@ -114,9 +114,9 @@
         }
         
         Xh = f->Nwin/2;
-        Fp0 = (double *) xmalloc(sizeof(double) * (Xh + 2)) + 1;
+        Fp0 = (double *) lsx_malloc(sizeof(double) * (Xh + 2)) + 1;
         if (f->freq0 > (sox_sample_t)f->rate/200) {
-                Xh0 = makeFilter(Fp0, Xh, 2.0*(double)f->freq0/f->rate, f->beta, 1, 0);
+                Xh0 = lsx_makeFilter(Fp0, Xh, 2.0*(double)f->freq0/f->rate, f->beta, 1, 0);
                 if (Xh0 <= 1)
                 {
                         sox_fail("filter: Unable to make low filter");
@@ -125,10 +125,10 @@
         } else {
                 Xh0 = 0;
         }
-        Fp1 = (double *) xmalloc(sizeof(double) * (Xh + 2)) + 1;
-        /* need Fp[-1] and Fp[Xh] for makeFilter */
+        Fp1 = (double *) lsx_malloc(sizeof(double) * (Xh + 2)) + 1;
+        /* need Fp[-1] and Fp[Xh] for lsx_makeFilter */
         if (f->freq1 < (sox_sample_t)f->rate/2) {
-                Xh1 = makeFilter(Fp1, Xh, 2.0*(double)f->freq1/f->rate, f->beta, 1, 0);
+                Xh1 = lsx_makeFilter(Fp1, Xh, 2.0*(double)f->freq1/f->rate, f->beta, 1, 0);
                 if (Xh1 <= 1)
                 {
                         sox_fail("filter: Unable to make high filter");
@@ -158,7 +158,7 @@
         f->Xh = Xh;
         f->Xt = Xh;
 
-        f->X = (double *) xmalloc(sizeof(double) * (2*BUFFSIZE + 2*Xh));
+        f->X = (double *) lsx_malloc(sizeof(double) * (2*BUFFSIZE + 2*Xh));
         f->Y = f->X + BUFFSIZE + 2*Xh;
 
         /* Need Xh zeros at beginning of X */
--- a/src/flac.c
+++ b/src/flac.c
@@ -322,7 +322,7 @@
     lsx_fail_errno(ft, SOX_ENOMEM, "FLAC ERROR creating the encoder instance");
     return SOX_EOF;
   }
-  encoder->decoded_samples = xmalloc(sox_globals.bufsiz * sizeof(FLAC__int32));
+  encoder->decoded_samples = lsx_malloc(sox_globals.bufsiz * sizeof(FLAC__int32));
 
   encoder->bits_per_sample = ft->encoding.bits_per_sample;
 
@@ -416,7 +416,7 @@
     encoder->metadata[encoder->num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
     for (i = 0; ft->comments[i]; ++i) {
       static const char prepend[] = "Comment=";
-      char * text = xcalloc(strlen(prepend) + strlen(ft->comments[i]) + 1, sizeof(*text));
+      char * text = lsx_calloc(strlen(prepend) + strlen(ft->comments[i]) + 1, sizeof(*text));
       /* Prepend `Comment=' if no field-name already in the comment */
       if (!strchr(ft->comments[i], '='))
         strcpy(text, prepend);
--- a/src/flanger.c
+++ b/src/flanger.c
@@ -181,11 +181,11 @@
   ++f->delay_buf_length;  /* Need 0 to n, i.e. n + 1. */
   ++f->delay_buf_length;  /* Quadratic interpolator needs one more. */
   for (c = 0; c < channels; ++c)
-    f->delay_bufs[c] = xcalloc(f->delay_buf_length, sizeof(*f->delay_bufs[0]));
+    f->delay_bufs[c] = lsx_calloc(f->delay_buf_length, sizeof(*f->delay_bufs[0]));
 
   /* Create the LFO lookup table: */
   f->lfo_length = effp->in_signal.rate / f->speed;
-  f->lfo = xcalloc(f->lfo_length, sizeof(*f->lfo));
+  f->lfo = lsx_calloc(f->lfo_length, sizeof(*f->lfo));
   lsx_generate_wave_table(
       f->wave_shape,
       SOX_FLOAT,
--- a/src/formats.c
+++ b/src/formats.c
@@ -205,9 +205,9 @@
 void sox_append_comment(sox_comments_t * comments, char const * comment)
 {
   size_t n = sox_num_comments(*comments);
-  *comments = xrealloc(*comments, (n + 2) * sizeof(**comments));
+  *comments = lsx_realloc(*comments, (n + 2) * sizeof(**comments));
   assert(comment);
-  (*comments)[n++] = xstrdup(comment);
+  (*comments)[n++] = lsx_strdup(comment);
   (*comments)[n] = 0;
 }
 
@@ -217,7 +217,7 @@
   if (comment) {
     while ((end = strchr(comment, '\n'))) {
       size_t len = end - comment;
-      char * c = xmalloc((len + 1) * sizeof(*c));
+      char * c = lsx_malloc((len + 1) * sizeof(*c));
       strncpy(c, comment, len);
       c[len] = '\0';
       sox_append_comment(comments, c);
@@ -257,7 +257,7 @@
   if (p) while (*p)
     len += strlen(*p++) + 1;
 
-  result = xcalloc(len? len : 1, sizeof(*result));
+  result = lsx_calloc(len? len : 1, sizeof(*result));
 
   if ((p = comments) && *p) {
     strcpy(result, *p);
@@ -366,7 +366,7 @@
     FILE * f = NULL;
 #ifdef HAVE_POPEN
     char const * const command_format = "wget --no-check-certificate -q -O- \"%s\"";
-    char * command = xmalloc(strlen(command_format) + strlen(identifier)); 
+    char * command = lsx_malloc(strlen(command_format) + strlen(identifier)); 
     sprintf(command, command_format, identifier); 
     f = popen(command, "r"); 
     free(command);
@@ -384,7 +384,7 @@
     sox_encodinginfo_t const * encoding,
     char               const * filetype)
 {
-  sox_format_t * ft = xcalloc(1, sizeof(*ft));
+  sox_format_t * ft = lsx_calloc(1, sizeof(*ft));
   sox_format_handler_t const * handler;
 
   if (filetype) {
@@ -453,8 +453,8 @@
   else sox_init_encodinginfo(&ft->encoding);
   set_endiannesses(ft);
 
-  ft->filetype = xstrdup(filetype);
-  ft->filename = xstrdup(path);
+  ft->filetype = lsx_strdup(filetype);
+  ft->filename = lsx_strdup(path);
 
   /* Read and write starters can change their formats. */
   if (ft->handler.startread && (*ft->handler.startread)(ft) != SOX_SUCCESS) {
@@ -675,7 +675,7 @@
     sox_instrinfo_t    const * instr,
     sox_loopinfo_t     const * loops)
 {
-  sox_format_t * ft = xcalloc(sizeof(*ft), 1);
+  sox_format_t * ft = lsx_calloc(sizeof(*ft), 1);
   sox_format_handler_t const * handler;
   int i;
 
@@ -748,8 +748,8 @@
   else sox_init_encodinginfo(&ft->encoding);
   set_endiannesses(ft);
 
-  ft->filetype = xstrdup(filetype);
-  ft->filename = xstrdup(path);
+  ft->filetype = lsx_strdup(filetype);
+  ft->filename = lsx_strdup(path);
 
   ft->comments = sox_copy_comments(comments);
 
@@ -847,6 +847,12 @@
     return SOX_EOF; /* FIXME: return SOX_EBADF */
 }
 
+static int strcaseends(char const * str, char const * end)
+{
+  size_t str_len = strlen(str), end_len = strlen(end);
+  return str_len >= end_len && !strcasecmp(str + str_len - end_len, end);
+}
+
 sox_bool sox_is_playlist(char const * filename)
 {
   return strcaseends(filename, ".m3u") || strcaseends(filename, ".pls");
@@ -857,8 +863,8 @@
   sox_bool const is_pls = strcaseends(listname, ".pls");
   int const comment_char = "#;"[is_pls];
   size_t text_length = 100;
-  char * text = xmalloc(text_length + 1);
-  char * dirname = xstrdup(listname);
+  char * text = lsx_malloc(text_length + 1);
+  char * dirname = lsx_strdup(listname);
   char * slash_pos = LAST_SLASH(dirname);
   FILE * file = xfopen(listname, "r");
   char * filename;
@@ -882,7 +888,7 @@
       break;
     while (c != EOF && !strchr("\r\n", c) && c != comment_char) {
       if (i == text_length)
-        text = xrealloc(text, (text_length <<= 1) + 1);
+        text = lsx_realloc(text, (text_length <<= 1) + 1);
       text[i++] = c;
       if (!strchr(" \t\f", c))
         end = i;
@@ -907,9 +913,9 @@
       char const * id = text + begin;
 
       if (!dirname[0] || is_uri(id) || IS_ABSOLUTE(id))
-        filename = xstrdup(id);
+        filename = lsx_strdup(id);
       else {
-        filename = xmalloc(strlen(dirname) + strlen(id) + 2); 
+        filename = lsx_malloc(strlen(dirname) + strlen(id) + 2); 
         sprintf(filename, "%s/%s", dirname, id); 
       }
       if (sox_is_playlist(filename))
--- a/src/formats_i.c
+++ b/src/formats_i.c
@@ -352,7 +352,7 @@
       sox_format_t * ft, ctype *buf, sox_size_t len) \
   { \
     sox_size_t n, nread; \
-    uint8_t *data = xmalloc(size * len); \
+    uint8_t *data = lsx_malloc(size * len); \
     nread = lsx_readbuf(ft, data, len * size) / size; \
     for (n = 0; n < nread; n++) \
       buf[n] = sox_unpack ## size(data + n * size); \
@@ -421,7 +421,7 @@
       sox_format_t * ft, ctype *buf, sox_size_t len) \
   { \
     sox_size_t n, nwritten; \
-    uint8_t *data = xmalloc(size * len); \
+    uint8_t *data = lsx_malloc(size * len); \
     for (n = 0; n < len; n++) \
       sox_pack ## size(data + n * size, buf[n]); \
     nwritten = lsx_writebuf(ft, data, len * size); \
--- a/src/g711.c
+++ b/src/g711.c
@@ -14,7 +14,7 @@
 #include "sox_i.h"
 #include "g711.h"
 
-int16_t _sox_alaw2linear16[256] = {
+int16_t lsx_alaw2linear16[256] = {
      -5504,   -5248,   -6016,   -5760,   -4480,   -4224,   -4992,
      -4736,   -7552,   -7296,   -8064,   -7808,   -6528,   -6272,
      -7040,   -6784,   -2752,   -2624,   -3008,   -2880,   -2240,
@@ -54,7 +54,7 @@
        816,     784,     880,     848
 };
 
-uint8_t _sox_13linear2alaw[0x2000] = {
+uint8_t lsx_13linear2alaw[0x2000] = {
    0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
    0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
    0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
@@ -740,7 +740,7 @@
    0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
 };
 
-int16_t _sox_ulaw2linear16[256] = {
+int16_t lsx_ulaw2linear16[256] = {
     -32124,  -31100,  -30076,  -29052,  -28028,  -27004,  -25980,
     -24956,  -23932,  -22908,  -21884,  -20860,  -19836,  -18812,
     -17788,  -16764,  -15996,  -15484,  -14972,  -14460,  -13948,
@@ -780,7 +780,7 @@
         24,      16,       8,       0
 };
 
-uint8_t _sox_14linear2ulaw[0x4000] = {
+uint8_t lsx_14linear2ulaw[0x4000] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -2366,7 +2366,7 @@
     int x, y, find2a = 0;
 
     y = 0;
-    printf("int16_t _sox_alaw2linear16[256] = {\n  ");
+    printf("int16_t lsx_alaw2linear16[256] = {\n  ");
     for (x = 0; x < 256; x++)
     {
 	printf("%8d,", sox_alaw2linear16(x));
@@ -2378,7 +2378,7 @@
 	}
     }
 
-    printf("\n};\n\nuint8_t _sox_13linear2alaw[0x2000] = {\n  ");
+    printf("\n};\n\nuint8_t lsx_13linear2alaw[0x2000] = {\n  ");
     y = 0;
     for (x = 0; x < 0x2000; x++)
     {
@@ -2391,7 +2391,7 @@
 	}
     }
 
-    printf("\n};\n\nint16_t _sox_ulaw2linear16[256] = {\n  ");
+    printf("\n};\n\nint16_t lsx_ulaw2linear16[256] = {\n  ");
     y = 0;
     for (x = 0; x < 256; x++)
     {
@@ -2404,7 +2404,7 @@
 	}
     }
 
-    printf("\n};\n\nuint8_t _sox_14linear2ulaw[0x4000] = {\n  ");
+    printf("\n};\n\nuint8_t lsx_14linear2ulaw[0x4000] = {\n  ");
     y = 0;
     for (x = 0; x < 0x4000; x++)
     {
--- a/src/g711.h
+++ b/src/g711.h
@@ -10,12 +10,12 @@
  * implied warranty.
  */
 
-extern uint8_t _sox_13linear2alaw[0x2000];
-extern int16_t _sox_alaw2linear16[256];
-#define sox_13linear2alaw(sw) (_sox_13linear2alaw[((sw) + 0x1000)])
-#define sox_alaw2linear16(uc) (_sox_alaw2linear16[uc])
+extern uint8_t lsx_13linear2alaw[0x2000];
+extern int16_t lsx_alaw2linear16[256];
+#define sox_13linear2alaw(sw) (lsx_13linear2alaw[((sw) + 0x1000)])
+#define sox_alaw2linear16(uc) (lsx_alaw2linear16[uc])
 
-extern uint8_t _sox_14linear2ulaw[0x4000];
-extern int16_t _sox_ulaw2linear16[256];
-#define sox_14linear2ulaw(sw) (_sox_14linear2ulaw[((sw) + 0x2000)])
-#define sox_ulaw2linear16(uc) (_sox_ulaw2linear16[uc])
+extern uint8_t lsx_14linear2ulaw[0x4000];
+extern int16_t lsx_ulaw2linear16[256];
+#define sox_14linear2ulaw(sw) (lsx_14linear2ulaw[((sw) + 0x2000)])
+#define sox_ulaw2linear16(uc) (lsx_ulaw2linear16[uc])
--- a/src/g72x.h
+++ b/src/g72x.h
@@ -33,6 +33,23 @@
 #ifndef _G72X_H
 #define	_G72X_H
 
+/* aliases */
+#define g721_decoder lsx_g721_decoder
+#define g721_encoder lsx_g721_encoder
+#define g723_24_decoder lsx_g723_24_decoder
+#define g723_24_encoder lsx_g723_24_encoder
+#define g723_40_decoder lsx_g723_40_decoder
+#define g723_40_encoder lsx_g723_40_encoder
+#define g72x_init_state lsx_g72x_init_state
+#define predictor_pole lsx_g72x_predictor_pole
+#define predictor_zero lsx_g72x_predictor_zero
+#define quantize lsx_g72x_quantize
+#define reconstruct lsx_g72x_reconstruct
+#define step_size lsx_g72x_step_size
+#define tandem_adjust_alaw lsx_g72x_tandem_adjust_alaw
+#define tandem_adjust_ulaw lsx_g72x_tandem_adjust_ulaw
+#define update lsx_g72x_update
+
 #define	AUDIO_ENCODING_ULAW	(1)	/* ISDN u-law */
 #define	AUDIO_ENCODING_ALAW	(2)	/* ISDN A-law */
 #define	AUDIO_ENCODING_LINEAR	(3)	/* PCM 2's-complement (0-center) */
--- a/src/getopt.c
+++ b/src/getopt.c
@@ -260,7 +260,7 @@
 #ifdef _LIBC
 /* Stored original parameters.
    XXX This is no good solution.  We should rather copy the args so
-   that we can compare them later.  But we must not use xmalloc(3).  */
+   that we can compare them later.  But we must not use malloc(3).  */
 extern int __libc_argc;
 extern char **__libc_argv;
 
@@ -325,7 +325,7 @@
     {
       /* We must extend the array.  The user plays games with us and
          presents new arguments.  */
-      char *new_str = xmalloc (top + 1);
+      char *new_str = lsx_malloc (top + 1);
       if (new_str == NULL)
         nonoption_flags_len = nonoption_flags_max_len = 0;
       else
@@ -437,7 +437,7 @@
               if (nonoption_flags_max_len < argc)
                 nonoption_flags_max_len = argc;
               __getopt_nonoption_flags =
-                (char *) xmalloc (nonoption_flags_max_len);
+                (char *) lsx_malloc (nonoption_flags_max_len);
               if (__getopt_nonoption_flags == NULL)
                 nonoption_flags_max_len = -1;
               else
--- a/src/gsm.c
+++ b/src/gsm.c
@@ -80,8 +80,8 @@
                         return (SOX_EOF);
                 }
         }
-        p->frames = (gsm_byte*) xmalloc(p->channels*FRAMESIZE);
-        p->samples = (gsm_signal*) xmalloc(BLOCKSIZE * (p->channels+1) * sizeof(gsm_signal));
+        p->frames = (gsm_byte*) lsx_malloc(p->channels*FRAMESIZE);
+        p->samples = (gsm_signal*) lsx_malloc(BLOCKSIZE * (p->channels+1) * sizeof(gsm_signal));
         p->sampleTop = p->samples + BLOCKSIZE*p->channels;
         p->samplePtr = (w)? p->samples : p->sampleTop;
         return (SOX_SUCCESS);
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -138,7 +138,7 @@
         ft->signal.channels = 1;
 
         /* Allocate memory for the dictionary */
-        p->dictionary = (dictent *)xmalloc(511 * sizeof(dictent));
+        p->dictionary = (dictent *)lsx_malloc(511 * sizeof(dictent));
 
         /* Read dictionary */
         for(i = 0; i < dictsize; i++) {
@@ -248,7 +248,7 @@
 }
 
 struct writepriv {
-  unsigned char *data;          /* Buffer allocated with xmalloc */
+  unsigned char *data;          /* Buffer allocated with lsx_malloc */
   sox_size_t size;               /* Size of allocated buffer */
   sox_size_t pos;                /* Where next byte goes */
 };
@@ -261,7 +261,7 @@
 
   p->size = BUFINCR;
   p->pos = 0;
-  p->data = xmalloc(p->size);
+  p->data = lsx_malloc(p->size);
   return SOX_SUCCESS;
 }
 
@@ -276,7 +276,7 @@
 
   if (p->pos + len > p->size) {
     p->size = ((p->pos + len) / BUFINCR + 1) * BUFINCR;
-    p->data = (unsigned char *)xrealloc(p->data, p->size);
+    p->data = (unsigned char *)lsx_realloc(p->data, p->size);
   }
 
   for (i = 0; i < len; i++) {
@@ -394,7 +394,7 @@
   l = (((l + 31) >> 5) << 2) + 24 + dictsize * 4;
   sox_debug("  Original size: %6d bytes", *dl);
   sox_debug("Compressed size: %6d bytes", l);
-  datafork = (unsigned char *)xmalloc((unsigned)l);
+  datafork = (unsigned char *)lsx_malloc((unsigned)l);
   ddf = datafork + 22;
   for(i = 0; i < dictsize; i++) {
     put16_be(&ddf, newdict[i].dict_leftson);
--- a/src/ima_rw.c
+++ b/src/ima_rw.c
@@ -52,7 +52,7 @@
 
 static unsigned char imaStateAdjustTable[ISSTMAX+1][8];
 
-void initImaTable(void)
+void lsx_ima_init_table(void)
 {
         int i,j,k;
         for (i=0; i<=ISSTMAX; i++) {
@@ -132,8 +132,8 @@
         return;
 }
 
-/* ImaBlockExpandI() outputs interleaved samples into one output buffer */
-void ImaBlockExpandI(
+/* lsx_ima_block_expand_i() outputs interleaved samples into one output buffer */
+void lsx_ima_block_expand_i(
         unsigned chans,          /* total channels             */
         const unsigned char *ibuff,/* input buffer[blockAlign]   */
         SAMPL *obuff,       /* output samples, n*chans    */
@@ -145,8 +145,8 @@
                 ImaExpandS(ch, chans, ibuff, obuff+ch, n, chans);
 }
 
-/* ImaBlockExpandM() outputs non-interleaved samples into chan separate output buffers */
-void ImaBlockExpandM(
+/* lsx_ima_block_expand_m() outputs non-interleaved samples into chan separate output buffers */
+void lsx_ima_block_expand_m(
         unsigned chans,          /* total channels             */
         const unsigned char *ibuff,/* input buffer[blockAlign]   */
         SAMPL **obuffs,     /* chan output sample buffers, each takes n samples */
@@ -299,7 +299,7 @@
 }
 
 /* mash one block.  if you want to use opt>0, 9 is a reasonable value */
-void ImaBlockMashI(
+void lsx_ima_block_mash_i(
         unsigned chans,          /* total channels */
         const SAMPL *ip,    /* ip[] is interleaved input samples */
         int n,              /* samples to encode PER channel, REQUIRE n % 8 == 1 */
@@ -314,7 +314,7 @@
 }
 
 /*
- * ImaSamplesIn(dataLen, chans, blockAlign, samplesPerBlock)
+ * lsx_ima_samples_in(dataLen, chans, blockAlign, samplesPerBlock)
  *  returns the number of samples/channel which would go
  *  in the dataLen, given the other parameters ...
  *  if input samplesPerBlock is 0, then returns the max
@@ -321,7 +321,7 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing.
  */
-sox_size_t ImaSamplesIn(
+sox_size_t lsx_ima_samples_in(
   sox_size_t dataLen,
   sox_size_t chans,
   sox_size_t blockAlign,
@@ -349,11 +349,11 @@
 }
 
 /*
- * sox_size_t ImaBytesPerBlock(chans, samplesPerBlock)
+ * sox_size_t lsx_ima_bytes_per_block(chans, samplesPerBlock)
  *   return minimum blocksize which would be required
  *   to encode number of chans with given samplesPerBlock
  */
-sox_size_t ImaBytesPerBlock(
+sox_size_t lsx_ima_bytes_per_block(
   sox_size_t chans,
   sox_size_t samplesPerBlock
 )
--- a/src/ima_rw.h
+++ b/src/ima_rw.h
@@ -26,13 +26,13 @@
 #endif
 
 /*
- * call initImaTable() before any other Ima* functions,
+ * call lsx_ima_init_table() before any other Ima* functions,
  * to create the fast lookup tables
  */
-extern void initImaTable(void);
+extern void lsx_ima_init_table(void);
 
-/* ImaBlockExpandI() outputs interleaved samples into one output buffer */
-extern void ImaBlockExpandI(
+/* lsx_ima_block_expand_i() outputs interleaved samples into one output buffer */
+extern void lsx_ima_block_expand_i(
 	unsigned chans,          /* total channels             */
 	const unsigned char *ibuff,/* input buffer[blockAlign]   */
 	SAMPL *obuff,       /* output samples, n*chans    */
@@ -39,8 +39,8 @@
 	int n               /* samples to decode PER channel, REQUIRE n % 8 == 1  */
 );
 
-/* ImaBlockExpandM() outputs non-interleaved samples into chan separate output buffers */
-extern void ImaBlockExpandM(
+/* lsx_ima_block_expand_m() outputs non-interleaved samples into chan separate output buffers */
+extern void lsx_ima_block_expand_m(
 	unsigned chans,          /* total channels             */
 	const unsigned char *ibuff,/* input buffer[blockAlign]   */
 	SAMPL **obuffs,     /* chan output sample buffers, each takes n samples */
@@ -48,7 +48,7 @@
 );
 
 /* mash one block.  if you want to use opt>0, 9 is a reasonable value */
-extern void ImaBlockMashI(
+extern void lsx_ima_block_mash_i(
 	unsigned chans,          /* total channels */
 	const SAMPL *ip,    /* ip[] is interleaved input samples */
 	int n,              /* samples to encode PER channel, REQUIRE n % 8 == 1 */
@@ -60,7 +60,7 @@
 /* Some helper functions for computing samples/block and blockalign */
 
 /*
- * ImaSamplesIn(dataLen, chans, blockAlign, samplesPerBlock)
+ * lsx_ima_samples_in(dataLen, chans, blockAlign, samplesPerBlock)
  *  returns the number of samples/channel which would go
  *  in the dataLen, given the other parameters ...
  *  if input samplesPerBlock is 0, then returns the max
@@ -67,7 +67,7 @@
  *  samplesPerBlock which would go into a block of size blockAlign
  *  Yes, it is confusing usage.
  */
-extern sox_size_t ImaSamplesIn(
+extern sox_size_t lsx_ima_samples_in(
 	sox_size_t dataLen,
 	sox_size_t chans,
 	sox_size_t blockAlign,
@@ -75,11 +75,11 @@
 );
 
 /*
- * sox_size_t ImaBytesPerBlock(chans, samplesPerBlock)
+ * sox_size_t lsx_ima_bytes_per_block(chans, samplesPerBlock)
  *   return minimum blocksize which would be required
  *   to encode number of chans with given samplesPerBlock
  */
-extern sox_size_t ImaBytesPerBlock(
+extern sox_size_t lsx_ima_bytes_per_block(
 	sox_size_t chans,
 	sox_size_t samplesPerBlock
 );
--- a/src/ladspa.c
+++ b/src/ladspa.c
@@ -139,7 +139,7 @@
   }
 
   /* Scan the ports to check there's one input and one output */
-  l_st->control = xcalloc(l_st->desc->PortCount, sizeof(LADSPA_Data));
+  l_st->control = lsx_calloc(l_st->desc->PortCount, sizeof(LADSPA_Data));
   for (i = 0; i < l_st->desc->PortCount; i++) {
     const LADSPA_PortDescriptor port = l_st->desc->PortDescriptors[i];
 
@@ -231,7 +231,7 @@
   *osamp = *isamp = len;
 
   if (len) {
-    LADSPA_Data *buf = xmalloc(sizeof(LADSPA_Data) * len);
+    LADSPA_Data *buf = lsx_malloc(sizeof(LADSPA_Data) * len);
     
     /* Insert input if effect takes it */
     if (l_st->input_port != ULONG_MAX) {
--- a/src/libsox_i.c
+++ b/src/libsox_i.c
@@ -1,5 +1,6 @@
 /*
  * 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
  * Copyright 1991 Lance Norskog And Sundry Contributors
@@ -11,4 +12,21 @@
  */
 
 #include "sox_i.h"
-#include <string.h>
+#include <ctype.h>
+
+#ifndef HAVE_STRCASECMP
+int lsx_strcasecmp(const char * s1, const char * s2)
+{
+  while (*s1 && (toupper(*s1) == toupper(*s2)))
+    s1++, s2++;
+  return toupper(*s1) - toupper(*s2);
+}
+
+int lsx_strncasecmp(char const * s1, char const * s2, size_t n)
+{
+  while (--n && *s1 && (toupper(*s1) == toupper(*s2)))
+    s1++, s2++;
+  return toupper(*s1) - toupper(*s2);
+}
+#endif
+
--- a/src/maud.c
+++ b/src/maud.c
@@ -161,7 +161,7 @@
                         lsx_readdw(ft, &chunksize);
                         if (chunksize & 1)
                                 chunksize++;
-                        chunk_buf = (char *) xmalloc(chunksize + 1);
+                        chunk_buf = (char *) lsx_malloc(chunksize + 1);
                         if (lsx_readbuf(ft, chunk_buf, chunksize) 
                             != chunksize)
                         {
--- a/src/mcompand.c
+++ b/src/mcompand.c
@@ -95,8 +95,8 @@
 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 *)xcalloc(nchan, sizeof(struct xy));
-  butterworth->xy_high = (struct xy *)xcalloc(nchan, sizeof(struct xy));
+  butterworth->xy_low = (struct xy *)lsx_calloc(nchan, sizeof(struct xy));
+  butterworth->xy_high = (struct xy *)lsx_calloc(nchan, sizeof(struct xy));
 
   /* lowpass setup */
   butterworth->frequency_low = frequency/1.3;
@@ -240,9 +240,9 @@
       }
 
       rates = 1 + commas/2;
-      l->attackRate = (double *)xmalloc(sizeof(double) * rates);
-      l->decayRate  = (double *)xmalloc(sizeof(double) * rates);
-      l->volume = (double *)xmalloc(sizeof(double) * rates);
+      l->attackRate = (double *)lsx_malloc(sizeof(double) * rates);
+      l->decayRate  = (double *)lsx_malloc(sizeof(double) * rates);
+      l->volume = (double *)lsx_malloc(sizeof(double) * rates);
       l->expectedChannels = rates;
       l->delay_buf = NULL;
 
@@ -320,7 +320,7 @@
   }
   c->nBands = (n+1)>>1;
 
-  c->bands = (struct comp_band *)xcalloc(c->nBands, sizeof(struct comp_band));
+  c->bands = (struct comp_band *)lsx_calloc(c->nBands, sizeof(struct comp_band));
 
   for (i=0;i<c->nBands;++i) {
     len = strlen(argv[i<<1]);
@@ -383,7 +383,7 @@
 
     /* Allocate the delay buffer */
     if (c->delay_buf_size > 0)
-      l->delay_buf = (sox_sample_t *)xcalloc(sizeof(long), c->delay_buf_size);
+      l->delay_buf = (sox_sample_t *)lsx_calloc(sizeof(long), c->delay_buf_size);
     l->delay_buf_ptr = 0;
     l->delay_buf_cnt = 0;
 
@@ -489,13 +489,13 @@
   double out;
 
   if (c->band_buf_len < len) {
-    c->band_buf1 = (sox_sample_t *)xrealloc(c->band_buf1,len*sizeof(sox_sample_t));
-    c->band_buf2 = (sox_sample_t *)xrealloc(c->band_buf2,len*sizeof(sox_sample_t));
-    c->band_buf3 = (sox_sample_t *)xrealloc(c->band_buf3,len*sizeof(sox_sample_t));
+    c->band_buf1 = (sox_sample_t *)lsx_realloc(c->band_buf1,len*sizeof(sox_sample_t));
+    c->band_buf2 = (sox_sample_t *)lsx_realloc(c->band_buf2,len*sizeof(sox_sample_t));
+    c->band_buf3 = (sox_sample_t *)lsx_realloc(c->band_buf3,len*sizeof(sox_sample_t));
     c->band_buf_len = len;
   }
 
-  ibuf_copy = (sox_sample_t *)xmalloc(*isamp * sizeof(sox_sample_t));
+  ibuf_copy = (sox_sample_t *)lsx_malloc(*isamp * sizeof(sox_sample_t));
   memcpy(ibuf_copy, ibuf, *isamp * sizeof(sox_sample_t));
 
   /* split ibuf into bands using butterworths, pipe each band through sox_mcompand_flow_1, then add back together and write to obuf */
--- a/src/mp3-duration.h
+++ b/src/mp3-duration.h
@@ -60,7 +60,7 @@
     if ((tag = id3_file_tag(id3struct)) && tag->frames)
       for (i = 0; list[i][0]; ++i) 
         if ((utf8 = utf8_id3tag_findframe(tag, list[i][0], 0))) {
-          char * comment = xmalloc(strlen(list[i][1]) + 1 + strlen((char *)utf8) + 1);
+          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);
           free(comment);
--- a/src/mp3.c
+++ b/src/mp3.c
@@ -169,11 +169,11 @@
     p->Timer = NULL;
     p->InputBuffer = NULL;
 
-    p->Stream=(struct mad_stream *)xmalloc(sizeof(struct mad_stream));
-    p->Frame=(struct mad_frame *)xmalloc(sizeof(struct mad_frame));
-    p->Synth=(struct mad_synth *)xmalloc(sizeof(struct mad_synth));
-    p->Timer=(mad_timer_t *)xmalloc(sizeof(mad_timer_t));
-    p->InputBuffer=(unsigned char *)xmalloc(INPUT_BUFFER_SIZE);
+    p->Stream=(struct mad_stream *)lsx_malloc(sizeof(struct mad_stream));
+    p->Frame=(struct mad_frame *)lsx_malloc(sizeof(struct mad_frame));
+    p->Synth=(struct mad_synth *)lsx_malloc(sizeof(struct mad_synth));
+    p->Timer=(mad_timer_t *)lsx_malloc(sizeof(mad_timer_t));
+    p->InputBuffer=(unsigned char *)lsx_malloc(INPUT_BUFFER_SIZE);
 
     if (ft->seekable) {
 #if HAVE_ID3TAG && HAVE_UNISTD_H
@@ -435,10 +435,10 @@
      * different scalling between 32-bit and 64-bit CPU's.
      *
      * We might as well scale it ourselfs to 16-bit to allow
-     * xmalloc()'ing a smaller buffer and call a consistent
+     * lsx_malloc()'ing a smaller buffer and call a consistent
      * interface.
      */
-    buffer_l = (short signed int *)xmalloc(nsamples * sizeof(short signed int));
+    buffer_l = (short signed int *)lsx_malloc(nsamples * sizeof(short signed int));
 
     if (ft->signal.channels == 2)
     {
@@ -446,7 +446,7 @@
          * them out into seperate buffers.
          */
         if ((buffer_r = 
-             (short signed int *)xmalloc(nsamples*
+             (short signed int *)lsx_malloc(nsamples*
                                           sizeof(short signed int))) == NULL)
         {
             lsx_fail_errno(ft,SOX_ENOMEM,"Memory allocation failed");
@@ -470,7 +470,7 @@
     }
 
     mp3buffer_size = 1.25 * nsamples + 7200;
-    if ((mp3buffer=(char *)xmalloc(mp3buffer_size)) == NULL)
+    if ((mp3buffer=(char *)lsx_malloc(mp3buffer_size)) == NULL)
     {
         lsx_fail_errno(ft,SOX_ENOMEM,"Memory allocation failed");
         goto end2;
--- a/src/noiseprof.c
+++ b/src/noiseprof.c
@@ -74,12 +74,12 @@
     return SOX_EOF;
   }
 
-  data->chandata = (chandata_t*)xcalloc(channels, sizeof(*(data->chandata)));
+  data->chandata = (chandata_t*)lsx_calloc(channels, sizeof(*(data->chandata)));
   data->bufdata = 0;
   for (i = 0; i < channels; i ++) {
-    data->chandata[i].sum = (float*)xcalloc(FREQCOUNT, sizeof(float));
-    data->chandata[i].profilecount = (int*)xcalloc(FREQCOUNT, sizeof(int));
-    data->chandata[i].window = (float*)xcalloc(WINDOWSIZE, sizeof(float));
+    data->chandata[i].sum = (float*)lsx_calloc(FREQCOUNT, sizeof(float));
+    data->chandata[i].profilecount = (int*)lsx_calloc(FREQCOUNT, sizeof(int));
+    data->chandata[i].window = (float*)lsx_calloc(WINDOWSIZE, sizeof(float));
   }
 
   return SOX_SUCCESS;
@@ -87,7 +87,7 @@
 
 /* Collect statistics from the complete window on channel chan. */
 static void collect_data(chandata_t* chan) {
-    float *out = (float*)xcalloc(FREQCOUNT, sizeof(float));
+    float *out = (float*)lsx_calloc(FREQCOUNT, sizeof(float));
     int i;
 
     PowerSpectrum(WINDOWSIZE, chan->window, out);
--- a/src/noisered.c
+++ b/src/noisered.c
@@ -66,11 +66,11 @@
     sox_size_t i;
     FILE* ifp;
 
-    data->chandata = (chandata_t*)xcalloc(channels, sizeof(*(data->chandata)));
+    data->chandata = (chandata_t*)lsx_calloc(channels, sizeof(*(data->chandata)));
     data->bufdata = 0;
     for (i = 0; i < channels; i ++) {
-        data->chandata[i].noisegate = (float*)xcalloc(FREQCOUNT, sizeof(float));
-        data->chandata[i].smoothing = (float*)xcalloc(FREQCOUNT, sizeof(float));
+        data->chandata[i].noisegate = (float*)lsx_calloc(FREQCOUNT, sizeof(float));
+        data->chandata[i].smoothing = (float*)lsx_calloc(FREQCOUNT, sizeof(float));
         data->chandata[i].lastwindow = NULL;
     }
 
@@ -131,7 +131,7 @@
     float *smoothing = chan->smoothing;
     int i;
 
-    inr = (float*)xcalloc(WINDOWSIZE * 5, sizeof(float));
+    inr = (float*)lsx_calloc(WINDOWSIZE * 5, sizeof(float));
     ini = inr + WINDOWSIZE;
     outr = ini + WINDOWSIZE;
     outi = outr + WINDOWSIZE;
@@ -208,7 +208,7 @@
     chandata_t *chan = &(data->chandata[chan_num]);
     int first = (chan->lastwindow == NULL);
 
-    if ((nextwindow = (float*)xcalloc(WINDOWSIZE, sizeof(float))) == NULL)
+    if ((nextwindow = (float*)lsx_calloc(WINDOWSIZE, sizeof(float))) == NULL)
         return SOX_EOF;
     
     memcpy(nextwindow, chan->window+WINDOWSIZE/2,
@@ -264,7 +264,7 @@
         sox_size_t j;
 
         if (chan->window == NULL)
-            chan->window = (float*)xcalloc(WINDOWSIZE, sizeof(float));
+            chan->window = (float*)lsx_calloc(WINDOWSIZE, sizeof(float));
         
         for (j = 0; j < ncopy; j ++)
             chan->window[oldbuf + j] =
--- a/src/oss.c
+++ b/src/oss.c
@@ -194,7 +194,7 @@
     }
     file->count = 0;
     file->pos = 0;
-    file->buf = (char *)xmalloc(file->size);
+    file->buf = (char *)lsx_malloc(file->size);
 
     if (ioctl(fileno(ft->fp), SNDCTL_DSP_SYNC, NULL) < 0) {
         lsx_fail_errno(ft,SOX_EOF,"Unable to sync dsp");
--- a/src/pad.c
+++ b/src/pad.c
@@ -43,7 +43,7 @@
 
   for (i = 0; i < p->npads; ++i) {
     if (argv) /* 1st parse only */
-      p->pads[i].str = xstrdup(argv[i]);
+      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')
@@ -63,7 +63,7 @@
 static int create(sox_effect_t * effp, int n, char * * argv)
 {
   pad_t p = (pad_t) effp->priv;
-  p->pads = xcalloc(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 */
 }
 
--- a/src/pan.c
+++ b/src/pan.c
@@ -69,7 +69,7 @@
     char ich, och;
     double left, right, dir, hdir;
     
-    ibuf_copy = (sox_sample_t *)xmalloc(*isamp * sizeof(sox_sample_t));
+    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   */
--- a/src/phaser.c
+++ b/src/phaser.c
@@ -151,10 +151,10 @@
                 sox_warn("phaser: warning >>> gain-out can cause saturation or clipping of output <<<");
 
         phaser->length = effp->in_signal.rate / phaser->speed;
-        phaser->phaserbuf = (double *) xmalloc(sizeof (double) * phaser->maxsamples);
+        phaser->phaserbuf = (double *) lsx_malloc(sizeof (double) * phaser->maxsamples);
         for ( i = 0; i < phaser->maxsamples; i++ )
                 phaser->phaserbuf[i] = 0.0;
-        phaser->lookup_tab = (int *) xmalloc(sizeof (int) * phaser->length);
+        phaser->lookup_tab = (int *) lsx_malloc(sizeof (int) * phaser->length);
 
         if (phaser->modulation == MOD_SINE)
           lsx_generate_wave_table(SOX_WAVE_SINE, SOX_INT, phaser->lookup_tab,
--- a/src/pitch.c
+++ b/src/pitch.c
@@ -347,10 +347,10 @@
 
     pitch->size = pitch->step + 2*pitch->overlap;
 
-    pitch->fade = (double *) xmalloc(pitch->step*sizeof(double));
-    pitch->tmp  = (double *) xmalloc(pitch->step*sizeof(double));
-    pitch->acc  = (double *) xmalloc(pitch->step*sizeof(double));
-    pitch->buf  = (sox_sample_t *) xmalloc(pitch->size*sizeof(sox_sample_t));
+    pitch->fade = (double *) lsx_malloc(pitch->step*sizeof(double));
+    pitch->tmp  = (double *) lsx_malloc(pitch->step*sizeof(double));
+    pitch->acc  = (double *) lsx_malloc(pitch->step*sizeof(double));
+    pitch->buf  = (sox_sample_t *) lsx_malloc(pitch->size*sizeof(sox_sample_t));
     pitch->index = pitch->overlap;
 
     /* default initial signal */
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -388,7 +388,7 @@
       int j, prod, f_cutoff, f_len;
       polystage *s;
 
-      rate->stage[k] = s = (polystage*) xmalloc(sizeof(polystage));
+      rate->stage[k] = s = (polystage*) lsx_malloc(sizeof(polystage));
       s->up = l1[k];
       s->down = l2[k];
       f_cutoff = max(s->up, s->down);
@@ -402,8 +402,8 @@
       sox_debug("Poly:  stage %d:  Up by %d, down by %d,  i_samps %d, hsize %d",
               k+1,s->up,s->down,size, s->hsize);
       s->filt_len = f_len;
-      s->filt_array = (Float *) xmalloc(sizeof(Float) * f_len);
-      s->window = (Float *) xmalloc(sizeof(Float) * (s->hsize+size));
+      s->filt_array = (Float *) lsx_malloc(sizeof(Float) * f_len);
+      s->window = (Float *) lsx_malloc(sizeof(Float) * (s->hsize+size));
       /* zero past_history section of window */
       for(j = 0; j < s->hsize; j++)
         s->window[j] = 0.0;
@@ -423,7 +423,7 @@
     rate->oskip = skip/2;
     { /* bogus last stage is for output buffering */
       polystage *s;
-      rate->stage[k] = s = (polystage*) xmalloc(sizeof(polystage));
+      rate->stage[k] = s = (polystage*) lsx_malloc(sizeof(polystage));
       s->up = s->down = 0;
       s->size = size;
       s->hsize = 0;
@@ -430,7 +430,7 @@
       s->held = 0;
       s->filt_len = 0;
       s->filt_array = NULL;
-      s->window = (Float *) xmalloc(sizeof(Float) * size);
+      s->window = (Float *) lsx_malloc(sizeof(Float) * size);
     }
     sox_debug("Poly:  output samples %d, oskip %d",size, rate->oskip);
     return (SOX_SUCCESS);
--- a/src/rabbit.c
+++ b/src/rabbit.c
@@ -90,7 +90,7 @@
   effp->out_signal.channels = effp->in_signal.channels;
   effp->out_signal.rate = out_rate;
 
-  r->data = (SRC_DATA *)xcalloc(1, sizeof(SRC_DATA));
+  r->data = (SRC_DATA *)lsx_calloc(1, sizeof(SRC_DATA));
   r->data->src_ratio = out_rate / effp->in_signal.rate;
   r->i_alloc = r->o_alloc = 0;
   r->state = src_new(r->converter_type, (int)effp->in_signal.channels, &err);
@@ -123,11 +123,11 @@
   }
 
   if (r->i_alloc < isamples) {
-    d->data_in = xrealloc(d->data_in, isamples * sizeof(float));
+    d->data_in = lsx_realloc(d->data_in, isamples * sizeof(float));
     r->i_alloc = isamples;
   }
   if (r->o_alloc < osamples) {
-    d->data_out = xrealloc(d->data_out, osamples * sizeof(float));
+    d->data_out = lsx_realloc(d->data_out, osamples * sizeof(float));
     r->o_alloc = osamples;
     d->output_frames = osamples / channels;
   }
--- a/src/raw.c
+++ b/src/raw.c
@@ -64,7 +64,7 @@
       sox_format_t * ft, sox_sample_t *buf, sox_size_t len) \
   { \
     sox_size_t n, nread; \
-    ctype *data = xmalloc(sizeof(ctype) * len); \
+    ctype *data = lsx_malloc(sizeof(ctype) * len); \
     nread = lsx_read_ ## type ## _buf(ft, (uctype *)data, len); \
     for (n = 0; n < nread; n++) \
       *buf++ = cast(data[n], ft->clips); \
@@ -90,7 +90,7 @@
       sox_format_t * ft, sox_sample_t *buf, sox_size_t len) \
   { \
     sox_size_t n, nwritten; \
-    ctype *data = xmalloc(sizeof(ctype) * len); \
+    ctype *data = lsx_malloc(sizeof(ctype) * len); \
     for (n = 0; n < len; n++) \
       data[n] = cast(buf[n], ft->clips); \
     nwritten = lsx_write_ ## type ## _buf(ft, (uctype *)data, len); \
--- a/src/remix.c
+++ b/src/remix.c
@@ -61,7 +61,7 @@
     sox_bool mul_spec = sox_false;
     char * text, * end;
     if (argv) /* 1st parse only */
-      p->out_specs[i].str = xstrdup(argv[i]);
+      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;
@@ -85,7 +85,7 @@
         mul_spec = sox_true;
       }
       if (chan2 < chan1) {int t = chan1; chan1 = chan2; chan2 = t;}
-      p->out_specs[i].in_specs = xrealloc(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;
@@ -107,7 +107,7 @@
   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 = xcalloc(p->num_out_channels = argc, sizeof(*p->out_specs));
+  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 */
 }
 
--- a/src/resample.c
+++ b/src/resample.c
@@ -124,8 +124,8 @@
                      double Beta,
                      long Num);
 
-/* makeFilter is used by filter.c */
-int makeFilter(double Imp[],
+/* lsx_makeFilter is used by filter.c */
+int lsx_makeFilter(double Imp[],
                long Nwing,
                double Froll,
                double Beta,
@@ -215,10 +215,10 @@
   /* Nwing: # of filter coeffs in right wing */
   r->Nwing = r->Nq * (r->Nmult / 2 + 1) + 1;
 
-  r->Imp = (double *) xmalloc(sizeof(double) * (r->Nwing + 2)) + 1;
+  r->Imp = (double *) lsx_malloc(sizeof(double) * (r->Nwing + 2)) + 1;
   /* need Imp[-1] and Imp[Nwing] for quadratic interpolation */
   /* returns error # <=0, or adjusted wing-len > 0 */
-  i = makeFilter(r->Imp, r->Nwing, r->rolloff, r->beta, r->Nq, 1);
+  i = lsx_makeFilter(r->Imp, r->Nwing, r->rolloff, r->beta, r->Nq, 1);
   if (i <= 0) {
     sox_fail("Unable to make filter");
     return (SOX_EOF);
@@ -260,7 +260,7 @@
   r->Ysize = BUFFSIZE - r->Xsize;
   sox_debug("Xsize %li, Ysize %li, Xoff %li", r->Xsize, r->Ysize, r->Xoff);
 
-  r->X = (double *) xmalloc(sizeof(double) * (BUFFSIZE));
+  r->X = (double *) lsx_malloc(sizeof(double) * (BUFFSIZE));
   r->Y = r->X + r->Xsize;
 
   /* Need Xoff zeros at beginning of sample */
@@ -586,7 +586,7 @@
    return (Y - Ystart);        /* Return the number of output samples */
 }
 
-int 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;
@@ -603,7 +603,7 @@
    if (Mwing==0)
       return(-4);
 
-   ImpR = (double *) xmalloc(sizeof(double) * Mwing);
+   ImpR = (double *) lsx_malloc(sizeof(double) * Mwing);
 
    /* Design a Nuttall or Kaiser windowed Sinc low-pass filter */
    LpFilter(ImpR, Mwing, Froll, Beta, Num);
--- a/src/reverb.c
+++ b/src/reverb.c
@@ -20,10 +20,10 @@
 
 #include "sox_i.h"
 #include "fifo.h"
-#include "xmalloc.h"
 #include <math.h>
 
-#define filter_create(p, n) (p)->ptr=Xcalloc((p)->buffer, (p)->size=(size_t)(n))
+#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))
 #define filter_advance(p) if (--(p)->ptr < (p)->buffer) (p)->ptr += (p)->size
 #define filter_delete(p) free((p)->buffer)
 
@@ -136,7 +136,7 @@
   memset(fifo_write(&p->input_fifo, delay, 0), 0, delay * sizeof(float));
   for (i = 0; i <= ceil(depth); ++i) {
     filter_array_create(p->chan + i, sample_rate_Hz, scale, i * depth);
-    out[i] = Xcalloc(p->out[i], buffer_size);
+    out[i] = lsx_zalloc(p->out[i], buffer_size);
   }
 }
 
--- a/src/sf.c
+++ b/src/sf.c
@@ -99,7 +99,7 @@
     if (lsx_readw(ft, &code) || lsx_readw(ft, &size))
       return SOX_EOF;
     if (code == SF_COMMENT) {
-      char * buf = xcalloc(1, (size_t)size + 1); /* +1 ensures null-terminated */
+      char * buf = lsx_calloc(1, (size_t)size + 1); /* +1 ensures null-terminated */
       if (lsx_readchars(ft, buf, size) != SOX_SUCCESS) {
         free(buf);
         return SOX_EOF;
--- a/src/silence.c
+++ b/src/silence.c
@@ -118,7 +118,7 @@
          * parse the duration info yet.  So save argument off
          * for future processing.
          */
-        silence->start_duration_str = (char *)xmalloc(strlen(argv[0])+1);
+        silence->start_duration_str = (char *)lsx_malloc(strlen(argv[0])+1);
         strcpy(silence->start_duration_str,argv[0]);
         /* Perform a fake parse to do error checking */
         if (lsx_parsesamples(0.,silence->start_duration_str,
@@ -159,7 +159,7 @@
          * parse the duration info yet.  So save argument off
          * for future processing.
          */
-        silence->stop_duration_str = (char *)xmalloc(strlen(argv[0])+1);
+        silence->stop_duration_str = (char *)lsx_malloc(strlen(argv[0])+1);
         strcpy(silence->stop_duration_str,argv[0]);
         /* Perform a fake parse to do error checking */
         if (lsx_parsesamples(0.,silence->stop_duration_str,
@@ -230,7 +230,7 @@
          */
         silence->window_size = (effp->in_signal.rate / 50) * 
                                effp->in_signal.channels;
-        silence->window = (double *)xmalloc(silence->window_size *
+        silence->window = (double *)lsx_malloc(silence->window_size *
                                            sizeof(double));
 
         clear_rms(effp);
@@ -254,12 +254,12 @@
         else
             silence->mode = SILENCE_COPY;
 
-        silence->start_holdoff = (sox_sample_t *)xmalloc(sizeof(sox_sample_t)*silence->start_duration);
+        silence->start_holdoff = (sox_sample_t *)lsx_malloc(sizeof(sox_sample_t)*silence->start_duration);
         silence->start_holdoff_offset = 0;
         silence->start_holdoff_end = 0;
         silence->start_found_periods = 0;
 
-        silence->stop_holdoff = (sox_sample_t *)xmalloc(sizeof(sox_sample_t)*silence->stop_duration);
+        silence->stop_holdoff = (sox_sample_t *)lsx_malloc(sizeof(sox_sample_t)*silence->stop_duration);
         silence->stop_holdoff_offset = 0;
         silence->stop_holdoff_end = 0;
         silence->stop_found_periods = 0;
--- a/src/smp.c
+++ b/src/smp.c
@@ -67,7 +67,7 @@
   char comment[COMMENTLEN + NAMELEN + 3];
 } *smp_t;
 
-char *SVmagic = "SOUND SAMPLE DATA ", *SVvers = "2.1 ";
+static char *SVmagic = "SOUND SAMPLE DATA ", *SVvers = "2.1 ";
 
 /*
  * Read the SampleVision trailer structure.
--- a/src/sndfile.c
+++ b/src/sndfile.c
@@ -259,8 +259,8 @@
 {
   sndfile_t sf = (sndfile_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 = xmalloc(LOG_MAX);
-  sf->sf_info = (SF_INFO *)xcalloc(1, sizeof(SF_INFO));
+  sf->log_buffer_ptr = sf->log_buffer = lsx_malloc(LOG_MAX);
+  sf->sf_info = (SF_INFO *)lsx_calloc(1, sizeof(SF_INFO));
 
   /* Copy format info */
   if (subtype) {
--- a/src/sox.c
+++ b/src/sox.c
@@ -401,7 +401,7 @@
   else {
     ws = 0;
     for (i = 0; i < input_count; i++) {
-      z->ibuf[i] = (sox_sample_t *)xmalloc(sox_globals.bufsiz * sizeof(sox_sample_t));
+      z->ibuf[i] = (sox_sample_t *)lsx_malloc(sox_globals.bufsiz * sizeof(sox_sample_t));
       progress_to_file(files[i]);
       ws = max(ws, input_wide_samples);
     }
@@ -954,7 +954,7 @@
     while (*names++)
       formats++;
   }
-  format_list = (const char **)xmalloc(formats * sizeof(char *));
+  format_list = (const char **)lsx_malloc(formats * sizeof(char *));
 
   printf("AUDIO FILE FORMATS:");
   for (i = formats = 0; sox_format_fns[i].fn; ++i) {
@@ -1167,7 +1167,7 @@
 {
   int c;
   size_t text_length = 100;
-  char * text = xmalloc(text_length + 1);
+  char * text = lsx_malloc(text_length + 1);
   FILE * file = fopen(filename, "rt");
 
   if (file == NULL) {
@@ -1179,7 +1179,7 @@
 
     while ((c = getc(file)) != EOF && !strchr("\r\n", c)) {
       if (i == text_length)
-        text = xrealloc(text, (text_length <<= 1) + 1);
+        text = lsx_realloc(text, (text_length <<= 1) + 1);
       text[i++] = c;
     }
     if (ferror(file)) {
@@ -1253,10 +1253,10 @@
   enum_item const * p = find_enum_text(optarg, items);
   if (p == NULL) {
     unsigned len = 1;
-    char * set = xmalloc(len);
+    char * set = lsx_malloc(len);
     *set = 0;
     for (p = items; p->text; ++p) {
-      set = xrealloc(set, len += 2 + strlen(p->text));
+      set = lsx_realloc(set, len += 2 + strlen(p->text));
       strcat(set, ", "); strcat(set, p->text);
     }
     sox_fail("--%s: '%s' is not one of: %s.",
@@ -1491,7 +1491,7 @@
 
 static int add_file(struct file_info const * const opts, char const * const filename)
 {
-  file_t f = xmalloc(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);
@@ -1500,7 +1500,7 @@
   *f = *opts;
   if (!filename)
     usage("missing filename"); /* No return */
-  f->filename = xstrdup(filename);
+  f->filename = lsx_strdup(filename);
   files[file_count++] = f;
   return 0;
 }
@@ -1657,6 +1657,12 @@
 static sox_bool cmp_comment_text(char const * c1, char const * c2)
 {
   return c1 && c2 && !strcasecmp(c1, c2);
+}
+
+static int strends(char const * str, char const * end)
+{
+  size_t str_len = strlen(str), end_len = strlen(end);
+  return str_len >= end_len && !strcmp(str + str_len - end_len, end);
 }
 
 int main(int argc, char **argv)
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -52,10 +52,8 @@
 #ifndef HAVE_STRCASECMP
 int strcasecmp(const char *s1, const char *s2);
 int strncasecmp(char const * s1, char const * s2, size_t n);
-#endif
-
-#ifndef HAVE_STRDUP
-char *strdup(const char *s);
+#define strcasecmp lsx_strcasecmp
+#define strncasecmp lsx_strncasecmp
 #endif
 
 #ifdef HAVE_BYTESWAP_H
--- a/src/soxconfig.h.cmake
+++ b/src/soxconfig.h.cmake
@@ -24,7 +24,6 @@
 #cmakedefine HAVE_SNDFILE_H           1
 #cmakedefine HAVE_STDINT_H            1
 #cmakedefine HAVE_STRCASECMP          1
-#cmakedefine HAVE_STRDUP              1
 #cmakedefine HAVE_STRINGS_H           1
 #cmakedefine HAVE_STRING_H            1
 #cmakedefine HAVE_STRRSTR             1
--- a/src/sphere.c
+++ b/src/sphere.c
@@ -34,7 +34,7 @@
 
   /* Determine header size, and allocate a buffer large enough to hold it. */
   sscanf(fldsval, "%u", &header_size);
-  buf = xmalloc(header_size);
+  buf = lsx_malloc(header_size);
 
   /* Skip what we have read so far */
   header_size -= 16;
--- a/src/splice.c
+++ b/src/splice.c
@@ -98,7 +98,7 @@
   p->max_buffer_size = 0;
   for (i = 0; i < p->nsplices; ++i) {
     if (argv) /* 1st parse only */
-      p->splices[i].str = xstrdup(argv[i]);
+      p->splices[i].str = lsx_strdup(argv[i]);
 
     p->splices[i].overlap = p->splices[i].search = rate * 0.01 + .5;
 
@@ -133,7 +133,7 @@
 static int create(sox_effect_t * effp, int n, char * * argv)
 {
   splice_t p = (splice_t) effp->priv;
-  p->splices = xcalloc(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 */
 }
 
@@ -143,7 +143,7 @@
   unsigned i;
 
   parse(effp, 0, effp->in_signal.rate); /* Re-parse now rate is known */
-  p->buffer = xcalloc(p->max_buffer_size * effp->in_signal.channels, sizeof(*p->buffer));
+  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)
--- a/src/stat.c
+++ b/src/stat.c
@@ -106,8 +106,8 @@
 
   if (stat->fft) {
     stat->fft_offset = 0;
-    stat->re_in = (float *)xmalloc(sizeof(float) * stat->fft_size);
-    stat->re_out = (float *)xmalloc(sizeof(float) * (stat->fft_size / 2));
+    stat->re_in = (float *)lsx_malloc(sizeof(float) * stat->fft_size);
+    stat->re_out = (float *)lsx_malloc(sizeof(float) * (stat->fft_size / 2));
   }
 
   return SOX_SUCCESS;
--- a/src/stretch.c
+++ b/src/stretch.c
@@ -153,7 +153,7 @@
   stretch->size = (int)(effp->out_signal.rate * 0.001 * stretch->window);
   /* start in the middle of an input to avoid initial fading... */
   stretch->index = stretch->size / 2;
-  stretch->ibuf = (sox_sample_t *)xmalloc(stretch->size * sizeof(sox_sample_t));
+  stretch->ibuf = (sox_sample_t *)lsx_malloc(stretch->size * sizeof(sox_sample_t));
 
   /* the shift ratio deal with the longest of ishift/oshift
      hence ishift<=size and oshift<=size. */
@@ -168,9 +168,9 @@
   assert(stretch->oshift <= stretch->size);
 
   stretch->oindex = stretch->index; /* start as synchronized */
-  stretch->obuf = (double *)xmalloc(stretch->size * sizeof(double));
+  stretch->obuf = (double *)lsx_malloc(stretch->size * sizeof(double));
   stretch->fsize = (int)(stretch->fading * stretch->size);
-  stretch->fbuf = (double *)xmalloc(stretch->fsize * sizeof(double));
+  stretch->fbuf = (double *)lsx_malloc(stretch->fsize * sizeof(double));
         
   /* initialize buffers */
   for (i = 0; i<stretch->size; i++)
--- a/src/sunaudio.c
+++ b/src/sunaudio.c
@@ -58,7 +58,7 @@
     file->count = 0;
     file->pos = 0;
     file->size = 1024;
-    file->buf = xmalloc (file->size);
+    file->buf = lsx_malloc (file->size);
 
     if (ft->encoding.encoding == SOX_ENCODING_UNKNOWN) ft->encoding.encoding = SOX_ENCODING_ULAW;
 
@@ -194,7 +194,7 @@
     file->count = 0;
     file->pos = 0;
     file->size = 1024;
-    file->buf = xmalloc (file->size);
+    file->buf = lsx_malloc (file->size);
 
 #ifdef __SVR4
     /* Read in old values, change to what we need and then send back */
--- a/src/synth.c
+++ b/src/synth.c
@@ -30,7 +30,7 @@
   synth_brownnoise
 } type_t;
 
-enum_item const synth_type[] = {
+static enum_item const synth_type[] = {
   ENUM_ITEM(synth_, sine)
   ENUM_ITEM(synth_, square)
   ENUM_ITEM(synth_, sawtooth)
@@ -47,7 +47,7 @@
 
 typedef enum {synth_create, synth_mix, synth_amod, synth_fmod} combine_t;
 
-enum_item const combine_type[] = {
+static enum_item const combine_type[] = {
   ENUM_ITEM(synth_, create)
   ENUM_ITEM(synth_, mix)
   ENUM_ITEM(synth_, amod)
@@ -288,7 +288,7 @@
 
   /* Get duration if given (if first arg starts with digit) */
   if (argc && (isdigit((int)argv[argn][0]) || argv[argn][0] == '.')) {
-    synth->length_str = xmalloc(strlen(argv[argn]) + 1);
+    synth->length_str = lsx_malloc(strlen(argv[argn]) + 1);
     strcpy(synth->length_str, argv[argn]);
     /* Do a dummy parse of to see if it will fail */
     if (lsx_parsesamples(0., synth->length_str, &synth->samples_to_do, 't') == NULL)
@@ -305,7 +305,7 @@
       sox_fail("no type given");
       return SOX_EOF;
     }
-    synth->getopts_channels = xrealloc(synth->getopts_channels, sizeof(*synth->getopts_channels) * (synth->getopts_nchannels + 1));
+    synth->getopts_channels = lsx_realloc(synth->getopts_channels, sizeof(*synth->getopts_channels) * (synth->getopts_nchannels + 1));
     chan = &synth->getopts_channels[synth->getopts_nchannels++];
     create_channel(chan);
     chan->type = p->value;
@@ -370,7 +370,7 @@
 
   /* If no channel parameters were given, create one default channel: */
   if (!synth->getopts_nchannels) {
-    synth->getopts_channels = xmalloc(sizeof(*synth->getopts_channels));
+    synth->getopts_channels = lsx_malloc(sizeof(*synth->getopts_channels));
     create_channel(&synth->getopts_channels[synth->getopts_nchannels++]);
   }
 
@@ -395,7 +395,7 @@
       return lsx_usage(effp);
 
   synth->number_of_channels = effp->in_signal.channels;
-  synth->channels = xcalloc(synth->number_of_channels, sizeof(*synth->channels));
+  synth->channels = lsx_calloc(synth->number_of_channels, sizeof(*synth->channels));
   for (i = 0; i < synth->number_of_channels; ++i) {
     channel_t chan = &synth->channels[i];
     *chan = synth->getopts_channels[i % synth->getopts_nchannels];
--- a/src/tempo.c
+++ b/src/tempo.c
@@ -20,7 +20,6 @@
 
 #include "sox_i.h"
 #include "fifo.h"
-#include "xmalloc.h"
 #include <math.h>
 
 typedef struct {
@@ -153,7 +152,7 @@
 {
   size_t samples_out = t->samples_in / t->factor + .5;
   size_t remaining = samples_out - t->samples_out;
-  float * buff = xcalloc(128 * t->channels, sizeof(*buff));
+  float * buff = lsx_calloc(128 * t->channels, sizeof(*buff));
 
   if ((int)remaining > 0) {
     while (fifo_occupancy(&t->output_fifo) < remaining) {
@@ -177,7 +176,7 @@
   t->search  = sample_rate * search_ms / 1000 + .5;
   t->overlap = max(sample_rate * overlap_ms / 1000 + 4.5, 16);
   t->overlap &= ~7; /* Make divisible by 8 for loop optimisation */
-  t->overlap_buf = xmalloc(t->overlap * t->channels * sizeof(*t->overlap_buf));
+  t->overlap_buf = lsx_malloc(t->overlap * t->channels * sizeof(*t->overlap_buf));
   max_skip = ceil(factor * (t->segment - t->overlap));
   t->process_size = max(max_skip + t->overlap, t->segment) + t->search;
 }
@@ -192,7 +191,7 @@
 
 static tempo_t * tempo_create(size_t channels)
 {
-  tempo_t * t = xcalloc(1, sizeof(*t));
+  tempo_t * t = lsx_calloc(1, sizeof(*t));
   t->channels = channels;
   fifo_create(&t->input_fifo, t->channels * sizeof(float));
   fifo_create(&t->output_fifo, t->channels * sizeof(float));
--- a/src/tests.sh
+++ b/src/tests.sh
@@ -103,13 +103,13 @@
           cmp -s $intermediateReference intermediate.$format2Ext
           if [ "$?" != "0" ]
           then
-            echo "*FAIL* channels=$channels \"$format1Text\" ---> \"$format2Text\"."
+            echo "*FAIL vector* channels=$channels \"$format1Text\" ---> \"$format2Text\"."
             exit 1    # This allows failure inspection.
           fi
 	  vectors=`expr $vectors + 1`
         fi
 
-        if execute cmp -s input.$format1Ext output.$format1Ext
+        if cmp -s input.$format1Ext output.$format1Ext
         then
           echo "ok     channels=$channels \"$format1Text\" <--> \"$format2Text\"."
         else
--- a/src/trim.c
+++ b/src/trim.c
@@ -36,13 +36,13 @@
      */
     switch (n) {
         case 2:
-            trim->length_str = (char *)xmalloc(strlen(argv[1])+1);
+            trim->length_str = (char *)lsx_malloc(strlen(argv[1])+1);
             strcpy(trim->length_str,argv[1]);
             /* Do a dummy parse to see if it will fail */
             if (lsx_parsesamples(0., trim->length_str, &trim->length, 't') == NULL)
               return lsx_usage(effp);
         case 1:
-            trim->start_str = (char *)xmalloc(strlen(argv[0])+1);
+            trim->start_str = (char *)lsx_malloc(strlen(argv[0])+1);
             strcpy(trim->start_str,argv[0]);
             /* Do a dummy parse to see if it will fail */
             if (lsx_parsesamples(0., trim->start_str, &trim->start, 't') == NULL)
--- a/src/util.c
+++ /dev/null
@@ -1,81 +1,0 @@
-/*
- * General purpose, i.e. non SoX specific, utility functions
- *
- * (c) 2006-8 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
- * the Free Software Foundation; either version 2 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,
- * Fifth Floor, 51 Franklin Street, Boston, MA 02111-1301, USA.
- */
-
-#include "soxconfig.h"
-#include "util.h"
-#include <string.h>
-
-#ifndef HAVE_STRCASECMP
-int strcasecmp(const char * s1, const char * s2)
-{
-  while (*s1 && (toupper(*s1) == toupper(*s2)))
-    s1++, s2++;
-  return toupper(*s1) - toupper(*s2);
-}
-
-int strncasecmp(char const * s1, char const * s2, size_t n)
-{
-  while (--n && *s1 && (toupper(*s1) == toupper(*s2)))
-    s1++, s2++;
-  return toupper(*s1) - toupper(*s2);
-}
-#endif
-
-#ifndef HAVE_STRDUP
-char * strdup(char const * s)
-{
-  return strcpy((char *)xmalloc(strlen(s) + 1), s);
-}
-#endif
-
-int strcaseends(char const * str, char const * end)
-{
-  size_t str_len = strlen(str), end_len = strlen(end);
-  return str_len >= end_len && !strcasecmp(str + str_len - end_len, end);
-}
-
-int strends(char const * str, char const * end)
-{
-  size_t str_len = strlen(str), end_len = strlen(end);
-  return str_len >= end_len && !strcmp(str + str_len - end_len, end);
-}
-
-enum_item const * find_enum_text(char const * text, enum_item const * enum_items)
-{
-  enum_item const * result = NULL; /* Assume not found */
-
-  while (enum_items->text) {
-    if (strncasecmp(text, enum_items->text, strlen(text)) == 0) {
-      if (result != NULL && result->value != enum_items->value)
-        return NULL;        /* Found ambiguity */
-      result = enum_items;  /* Found match */
-    }
-    ++enum_items;
-  }
-  return result;
-}
-
-enum_item const * find_enum_value(unsigned value, enum_item const * enum_items)
-{
-  for (;enum_items->text; ++enum_items)
-    if (value == enum_items->value)
-      return enum_items;
-  return NULL;
-}
--- a/src/util.h
+++ b/src/util.h
@@ -23,9 +23,11 @@
 #ifdef __GNUC__
 #define NORET __attribute__((noreturn))
 #define PRINTF __attribute__ ((format (printf, 1, 2)))
+#define UNUSED __attribute__ ((unused))
 #else
 #define NORET
 #define PRINTF
+#define UNUSED
 #endif
 
 #ifdef _MSC_VER
@@ -90,11 +92,28 @@
 #define MACHINE_IS_LITTLEENDIAN 1
 #endif
 
-int strcaseends(char const * str, char const * end);
-int strends(char const * str, char const * end);
-
 typedef struct {char const *text; unsigned value;} enum_item;
 #define ENUM_ITEM(prefix, item) {#item, prefix##item},
-enum_item const * find_enum_text(
-    char const * text, enum_item const * enum_items);
-enum_item const * find_enum_value(unsigned value, enum_item const * enum_items);
+
+UNUSED static enum_item const * find_enum_text(char const * text, enum_item const * enum_items)
+{
+  enum_item const * result = NULL; /* Assume not found */
+
+  while (enum_items->text) {
+    if (strncasecmp(text, enum_items->text, strlen(text)) == 0) {
+      if (result != NULL && result->value != enum_items->value)
+        return NULL;        /* Found ambiguity */
+      result = enum_items;  /* Found match */
+    }
+    ++enum_items;
+  }
+  return result;
+}
+
+UNUSED static enum_item const * find_enum_value(unsigned value, enum_item const * enum_items)
+{
+  for (;enum_items->text; ++enum_items)
+    if (value == enum_items->value)
+      return enum_items;
+  return NULL;
+}
--- a/src/voc.c
+++ b/src/voc.c
@@ -356,7 +356,7 @@
             return done;
           }
           *buf = SOX_UNSIGNED_8BIT_TO_SAMPLE(uc,);
-          adpcm_init(&v->adpcm, 6 - v->size, SOX_SAMPLE_TO_SIGNED_16BIT(*buf, ft->clips));
+          lsx_adpcm_init(&v->adpcm, 6 - v->size, SOX_SAMPLE_TO_SIGNED_16BIT(*buf, ft->clips));
           ++buf;
           --v->block_remaining;
           ++done;
@@ -372,13 +372,13 @@
               int u = uc;
 
               *buf++ =
-                  SOX_SIGNED_16BIT_TO_SAMPLE(adpcm_decode (u >> 6, &v->adpcm),);
+                  SOX_SIGNED_16BIT_TO_SAMPLE(lsx_adpcm_decode (u >> 6, &v->adpcm),);
               *buf++ =
-                  SOX_SIGNED_16BIT_TO_SAMPLE(adpcm_decode (u >> 4, &v->adpcm),);
+                  SOX_SIGNED_16BIT_TO_SAMPLE(lsx_adpcm_decode (u >> 4, &v->adpcm),);
               *buf++ =
-                  SOX_SIGNED_16BIT_TO_SAMPLE(adpcm_decode (u >> 2, &v->adpcm),);
+                  SOX_SIGNED_16BIT_TO_SAMPLE(lsx_adpcm_decode (u >> 2, &v->adpcm),);
               *buf++ =
-                  SOX_SIGNED_16BIT_TO_SAMPLE(adpcm_decode (u     , &v->adpcm),);
+                  SOX_SIGNED_16BIT_TO_SAMPLE(lsx_adpcm_decode (u     , &v->adpcm),);
             }
             break;
           case 3:
@@ -386,11 +386,11 @@
               int u = uc;
 
               *buf++ =
-                  SOX_SIGNED_16BIT_TO_SAMPLE(adpcm_decode (u >> 5, &v->adpcm),);
+                  SOX_SIGNED_16BIT_TO_SAMPLE(lsx_adpcm_decode (u >> 5, &v->adpcm),);
               *buf++ =
-                  SOX_SIGNED_16BIT_TO_SAMPLE(adpcm_decode (u >> 2, &v->adpcm),);
+                  SOX_SIGNED_16BIT_TO_SAMPLE(lsx_adpcm_decode (u >> 2, &v->adpcm),);
               *buf++ =                              /* A bit from nowhere! */
-                  SOX_SIGNED_16BIT_TO_SAMPLE(adpcm_decode (u << 1, &v->adpcm),);
+                  SOX_SIGNED_16BIT_TO_SAMPLE(lsx_adpcm_decode (u << 1, &v->adpcm),);
             }
             break;
           case 4:
@@ -398,9 +398,9 @@
               int u = uc;
 
               *buf++ =
-                  SOX_SIGNED_16BIT_TO_SAMPLE(adpcm_decode (u >> 4, &v->adpcm),);
+                  SOX_SIGNED_16BIT_TO_SAMPLE(lsx_adpcm_decode (u >> 4, &v->adpcm),);
               *buf++ =
-                  SOX_SIGNED_16BIT_TO_SAMPLE(adpcm_decode (u     , &v->adpcm),);
+                  SOX_SIGNED_16BIT_TO_SAMPLE(lsx_adpcm_decode (u     , &v->adpcm),);
             }
             break;
         }
--- a/src/vorbis.c
+++ b/src/vorbis.c
@@ -103,7 +103,7 @@
   };
 
   /* Allocate space for decoding structure */
-  vb->vf = (OggVorbis_File *) xmalloc(sizeof(OggVorbis_File));
+  vb->vf = (OggVorbis_File *) lsx_malloc(sizeof(OggVorbis_File));
 
   /* Init the decoder */
   if (ov_open_callbacks((void *) ft->fp, vb->vf, NULL, 0, callbacks) < 0) {
@@ -133,7 +133,7 @@
 
   /* Setup buffer */
   vb->buf_len = DEF_BUF_LEN;
-  vb->buf = xcalloc(vb->buf_len, sizeof(char));
+  vb->buf = lsx_calloc(vb->buf_len, sizeof(char));
   vb->start = vb->end = 0;
 
   /* Fill in other info */
@@ -244,11 +244,11 @@
   memset(&vc, 0, sizeof(vc));
   vc.comments = sox_num_comments(ft->comments);
   if (vc.comments) {     /* Make the comment structure */
-    vc.comment_lengths = xcalloc((size_t)vc.comments, sizeof(*vc.comment_lengths));
-    vc.user_comments = xcalloc((size_t)vc.comments, sizeof(*vc.user_comments));
+    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 = xcalloc(strlen(prepend) + strlen(ft->comments[i]) + 1, sizeof(*text));
+      char * text = lsx_calloc(strlen(prepend) + strlen(ft->comments[i]) + 1, sizeof(*text));
       /* Prepend `Comment=' if no field-name already in the comment */
       if (!strchr(ft->comments[i], '='))
         strcpy(text, prepend);
@@ -283,7 +283,7 @@
   ft->encoding.encoding = SOX_ENCODING_VORBIS;
 
   /* Allocate memory for all of the structures */
-  ve = vb->vorbis_enc_data = (vorbis_enc_t *) xmalloc(sizeof(vorbis_enc_t));
+  ve = vb->vorbis_enc_data = (vorbis_enc_t *) lsx_malloc(sizeof(vorbis_enc_t));
 
   vorbis_info_init(&ve->vi);
 
--- a/src/wav.c
+++ b/src/wav.c
@@ -2,9 +2,9 @@
  * Microsoft's WAVE sound format handler
  *
  * Copyright 1998-2006 Chris Bagwell and SoX Contributors
- * Copyright 1991 Lance Norskog And Sundry Contributors
- * Copyright 1992 Rick Richardson
  * Copyright 1997 Graeme W. Gill, 93/5/17
+ * Copyright 1992 Rick Richardson
+ * Copyright 1991 Lance Norskog And Sundry Contributors
  *
  * Info for format tags can be found at:
  *   http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
@@ -50,7 +50,7 @@
 
     /* following used by *ADPCM wav files */
     unsigned short nCoefs;          /* ADPCM: number of coef sets */
-    short         *iCoefs;          /* ADPCM: coef sets           */
+    short         *lsx_ms_adpcm_i_coefs;          /* ADPCM: coef sets           */
     unsigned char *packet;          /* Temporary buffer for packets */
     short         *samples;         /* interleaved samples buffer */
     short         *samplePtr;       /* Pointer to current sample  */
@@ -93,7 +93,7 @@
         /* If it looks like a valid header is around then try and */
         /* work with partial blocks.  Specs say it should be null */
         /* padded but I guess this is better than trailing quiet. */
-        samplesThisBlock = ImaSamplesIn(0, ft->signal.channels, bytesRead, 0);
+        samplesThisBlock = lsx_ima_samples_in(0, ft->signal.channels, bytesRead, 0);
         if (samplesThisBlock == 0) 
         {
             sox_warn("Premature EOF on .wav input file");
@@ -105,7 +105,7 @@
     
     /* For a full block, the following should be true: */
     /* wav->samplesPerBlock = blockAlign - 8byte header + 1 sample in header */
-    ImaBlockExpandI(ft->signal.channels, wav->packet, wav->samples, samplesThisBlock);
+    lsx_ima_block_expand_i(ft->signal.channels, wav->packet, wav->samples, samplesThisBlock);
     return samplesThisBlock;
 
 }
@@ -134,7 +134,7 @@
         /* If it looks like a valid header is around then try and */
         /* work with partial blocks.  Specs say it should be null */
         /* padded but I guess this is better than trailing quiet. */
-        samplesThisBlock = AdpcmSamplesIn(0, ft->signal.channels, bytesRead, 0);
+        samplesThisBlock = lsx_ms_adpcm_samples_in(0, ft->signal.channels, bytesRead, 0);
         if (samplesThisBlock == 0) 
         {
             sox_warn("Premature EOF on .wav input file");
@@ -142,7 +142,7 @@
         }
     }
     
-    errmsg = AdpcmBlockExpandI(ft->signal.channels, wav->nCoefs, wav->iCoefs, wav->packet, wav->samples, samplesThisBlock);
+    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)
         sox_warn((char*)errmsg);
@@ -168,9 +168,9 @@
         for (p = wav->samplePtr; p < wav->sampleTop; p++) *p=0;
         /* compress the samples to wav->packet */
         if (wav->formatTag == WAVE_FORMAT_ADPCM) {
-            AdpcmBlockMashI(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, wav->blockAlign);
+            lsx_ms_adpcm_block_mash_i(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, wav->blockAlign);
         }else{ /* WAVE_FORMAT_IMA_ADPCM */
-            ImaBlockMashI(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, 9);
+            lsx_ima_block_mash_i(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, 9);
         }
         /* write the compressed packet */
         if (lsx_writebuf(ft, wav->packet, wav->blockAlign) != wav->blockAlign)
@@ -210,7 +210,7 @@
         return (SOX_EOF);
     }
 
-    wav->gsmsample=(gsm_signal*)xmalloc(sizeof(gsm_signal)*160*2);
+    wav->gsmsample=(gsm_signal*)lsx_malloc(sizeof(gsm_signal)*160*2);
     wav->gsmindex=0;
     return (SOX_SUCCESS);
 }
@@ -583,7 +583,7 @@
         sox_report("User options overriding rate read in .wav header");
     
 
-    wav->iCoefs = NULL;
+    wav->lsx_ms_adpcm_i_coefs = NULL;
     wav->packet = NULL;
     wav->samples = NULL;
 
@@ -624,7 +624,7 @@
         }
 
         lsx_readw(ft, &(wav->samplesPerBlock));
-        bytesPerBlock = AdpcmBytesPerBlock(ft->signal.channels, wav->samplesPerBlock);
+        bytesPerBlock = lsx_ms_adpcm_bytes_per_block(ft->signal.channels, wav->samplesPerBlock);
         if (bytesPerBlock > wav->blockAlign)
         {
             lsx_fail_errno(ft,SOX_EOF,"format[%s]: samplesPerBlock(%d) incompatible with blockAlign(%d)",
@@ -637,7 +637,7 @@
             lsx_fail_errno(ft,SOX_EOF,"ADPCM file nCoefs (%.4hx) makes no sense", wav->nCoefs);
             return SOX_EOF;
         }
-        wav->packet = (unsigned char *)xmalloc(wav->blockAlign);
+        wav->packet = (unsigned char *)lsx_malloc(wav->blockAlign);
 
         len -= 4;
 
@@ -647,19 +647,19 @@
             return SOX_EOF;
         }
 
-        wav->samples = (short *)xmalloc(wChannels*wav->samplesPerBlock*sizeof(short));
+        wav->samples = (short *)lsx_malloc(wChannels*wav->samplesPerBlock*sizeof(short));
 
-        /* nCoefs, iCoefs used by adpcm.c */
-        wav->iCoefs = (short *)xmalloc(wav->nCoefs * 2 * sizeof(short));
+        /* nCoefs, lsx_ms_adpcm_i_coefs used by adpcm.c */
+        wav->lsx_ms_adpcm_i_coefs = (short *)lsx_malloc(wav->nCoefs * 2 * sizeof(short));
         {
             int i, errct=0;
             for (i=0; len>=2 && i < 2*wav->nCoefs; i++) {
-                lsx_readw(ft, (unsigned short *)&(wav->iCoefs[i]));
+                lsx_readw(ft, (unsigned short *)&(wav->lsx_ms_adpcm_i_coefs[i]));
                 len -= 2;
-                if (i<14) errct += (wav->iCoefs[i] != iCoef[i/2][i%2]);
-                /* sox_debug("iCoefs[%2d] %4d",i,wav->iCoefs[i]); */
+                if (i<14) errct += (wav->lsx_ms_adpcm_i_coefs[i] != lsx_ms_adpcm_i_coef[i/2][i%2]);
+                /* sox_debug("lsx_ms_adpcm_i_coefs[%2d] %4d",i,wav->lsx_ms_adpcm_i_coefs[i]); */
             }
-            if (errct) sox_warn("base iCoefs differ in %d/14 positions",errct);
+            if (errct) sox_warn("base lsx_ms_adpcm_i_coefs differ in %d/14 positions",errct);
         }
 
         bytespersample = 2;  /* AFTER de-compression */
@@ -680,7 +680,7 @@
         }
 
         lsx_readw(ft, &(wav->samplesPerBlock));
-        bytesPerBlock = ImaBytesPerBlock(ft->signal.channels, wav->samplesPerBlock);
+        bytesPerBlock = lsx_ima_bytes_per_block(ft->signal.channels, wav->samplesPerBlock);
         if (bytesPerBlock > wav->blockAlign || wav->samplesPerBlock%8 != 1)
         {
             lsx_fail_errno(ft,SOX_EOF,"format[%s]: samplesPerBlock(%d) incompatible with blockAlign(%d)",
@@ -688,10 +688,10 @@
             return SOX_EOF;
         }
 
-        wav->packet = (unsigned char *)xmalloc(wav->blockAlign);
+        wav->packet = (unsigned char *)lsx_malloc(wav->blockAlign);
         len -= 2;
 
-        wav->samples = (short *)xmalloc(wChannels*wav->samplesPerBlock*sizeof(short));
+        wav->samples = (short *)lsx_malloc(wChannels*wav->samplesPerBlock*sizeof(short));
 
         bytespersample = 2;  /* AFTER de-compression */
         break;
@@ -773,7 +773,7 @@
 
     case WAVE_FORMAT_ADPCM:
         wav->numSamples = 
-            AdpcmSamplesIn(dwDataLength, ft->signal.channels, 
+            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 */
@@ -784,11 +784,11 @@
         /* Compute easiest part of number of samples.  For every block, there
            are samplesPerBlock samples to read. */
         wav->numSamples = 
-            ImaSamplesIn(dwDataLength, ft->signal.channels, 
+            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 */
-        initImaTable();
+        lsx_ima_init_table();
         ft->length = wav->numSamples*ft->signal.channels;
         break;
 
@@ -843,7 +843,7 @@
         if (lsx_seeki(ft, (sox_ssize_t)len, SEEK_CUR) == SOX_SUCCESS &&
             findChunk(ft, "LIST", &len) != SOX_EOF)
         {
-            wav->comment = (char*)xmalloc(256);
+            wav->comment = (char*)lsx_malloc(256);
             /* Initialize comment to a NULL string */
             wav->comment[0] = 0;
             while(!lsx_eof(ft))
@@ -1050,7 +1050,7 @@
 
     free(wav->packet);
     free(wav->samples);
-    free(wav->iCoefs);
+    free(wav->lsx_ms_adpcm_i_coefs);
     free(wav->comment);
     wav->comment = NULL;
 
@@ -1095,13 +1095,13 @@
 
     wav->packet = NULL;
     wav->samples = NULL;
-    wav->iCoefs = NULL;
+    wav->lsx_ms_adpcm_i_coefs = NULL;
     switch (wav->formatTag)
     {
         size_t ch, sbsize;
 
         case WAVE_FORMAT_IMA_ADPCM:
-            initImaTable();
+            lsx_ima_init_table();
         /* intentional case fallthru! */
         case WAVE_FORMAT_ADPCM:
             /* #channels already range-checked for overflow in wavwritehdr() */
@@ -1108,8 +1108,8 @@
             for (ch=0; ch<ft->signal.channels; ch++)
                 wav->state[ch] = 0;
             sbsize = ft->signal.channels * wav->samplesPerBlock;
-            wav->packet = (unsigned char *)xmalloc(wav->blockAlign);
-            wav->samples = (short *)xmalloc(sbsize*sizeof(short));
+            wav->packet = (unsigned char *)lsx_malloc(wav->blockAlign);
+            wav->samples = (short *)lsx_malloc(sbsize*sizeof(short));
             wav->sampleTop = wav->samples + sbsize;
             wav->samplePtr = wav->samples;
             break;
@@ -1251,7 +1251,7 @@
             wBlockAlign = wChannels * 256; /* reasonable default */
             wBitsPerSample = 4;
             wExtSize = 2;
-            wSamplesPerBlock = ImaSamplesIn(0, wChannels, wBlockAlign, 0);
+            wSamplesPerBlock = lsx_ima_samples_in(0, wChannels, wBlockAlign, 0);
             break;
         case SOX_ENCODING_MS_ADPCM:
             if (wChannels>16)
@@ -1264,7 +1264,7 @@
             wBlockAlign = max(wBlockAlign, 1) * wChannels * 256;
             wBitsPerSample = 4;
             wExtSize = 4+4*7;      /* Ext fmt data length */
-            wSamplesPerBlock = AdpcmSamplesIn(0, wChannels, wBlockAlign, 0);
+            wSamplesPerBlock = lsx_ms_adpcm_samples_in(0, wChannels, wBlockAlign, 0);
             break;
         case SOX_ENCODING_GSM:
             if (wChannels!=1)
@@ -1365,8 +1365,8 @@
         lsx_writew(ft, wSamplesPerBlock);
         lsx_writew(ft, 7); /* nCoefs */
         for (i=0; i<7; i++) {
-            lsx_writew(ft, (uint16_t)(iCoef[i][0]));
-            lsx_writew(ft, (uint16_t)(iCoef[i][1]));
+            lsx_writew(ft, (uint16_t)(lsx_ms_adpcm_i_coef[i][0]));
+            lsx_writew(ft, (uint16_t)(lsx_ms_adpcm_i_coef[i][1]));
         }
         break;
         case WAVE_FORMAT_GSM610:
@@ -1468,7 +1468,7 @@
         }
         free(wav->packet);
         free(wav->samples);
-        free(wav->iCoefs);
+        free(wav->lsx_ms_adpcm_i_coefs);
 
         /* All samples are already written out. */
         /* If file header needs fixing up, for example it needs the */
--- a/src/xa.c
+++ b/src/xa.c
@@ -175,10 +175,10 @@
     xa->bufPos = xa->blockSize;
 
     /* Allocate memory for the block buffer */
-    xa->buf = (unsigned char *)xcalloc(1, xa->blockSize);
+    xa->buf = (unsigned char *)lsx_calloc(1, xa->blockSize);
     
     /* Allocate memory for the state */
-    xa->state = (xa_state_t *)xcalloc(sizeof(xa_state_t), ft->signal.channels);
+    xa->state = (xa_state_t *)lsx_calloc(sizeof(xa_state_t), ft->signal.channels);
     
     /* Final initialization */
     xa->bytesDecoded = 0;
--- a/src/xmalloc.c
+++ b/src/xmalloc.c
@@ -20,21 +20,21 @@
    02111-1301, USA.  */
 
 #include "sox_i.h"
-
 #include <stdlib.h>
-#include <string.h>
 
-#include "xmalloc.h"
-
-
-/*
- * Resize an allocated memory area; abort if not possible.
+/* Resize an allocated memory area; abort if not possible.
+ *
+ * For malloc, `If the size of the space requested is zero, the behavior is
+ * implementation defined: either a null pointer is returned, or the
+ * behavior is as if the size were some nonzero value, except that the
+ * returned pointer shall not be used to access an object'
  */
-void *xrealloc(void *ptr, size_t newsize)
+void *lsx_realloc(void *ptr, size_t newsize)
 {
-  /* Behaviour in this case is unspecified for malloc */
-  if (ptr && newsize == 0)
+  if (ptr && newsize == 0) {
+    free(ptr);
     return NULL;
+  }
 
   if ((ptr = realloc(ptr, newsize)) == NULL) {
     sox_fail("out of memory");
@@ -42,38 +42,4 @@
   }
 
   return ptr;
-}
-
-/*
- * Perform a calloc; abort if not possible.
- */
-void *xcalloc(size_t nmemb, size_t size)
-{
-  void *ptr = calloc(nmemb, size);
-
-  if (ptr == NULL) {
-    sox_fail("out of memory");
-    exit(2);
-  }
-
-  return ptr;
-}
-
-/*
- * Perform a strdup; abort if not possible.
- */
-char *xstrdup(const char *s)
-{
-  char * t;
-
-  if (s == NULL)
-    return NULL;
-
-  t = strdup(s);
-  if (t == NULL) {
-    sox_fail("out of memory");
-    exit(2);
-  }
-
-  return t;
 }
--- a/src/xmalloc.h
+++ b/src/xmalloc.h
@@ -22,13 +22,11 @@
 #ifndef XMALLOC_H
 
 #include <stddef.h>
+#include <string.h>
 
-#define xmalloc(size) xrealloc(NULL, (size))
-
-void *xcalloc(size_t nmemb, size_t size);
-void *xrealloc(void *ptr, size_t newsize);
-char *xstrdup(const char *s);
-
-#define Xcalloc(var, n) var = xcalloc(n, sizeof(*var))
+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)
 
 #endif