shithub: sox

Download patch

ref: 0a33c800bb999148b32439fdfdc6bbbeaf5f898d
parent: 415d218a501c7bdb5bc25c8a2ed4dd8b1e65b8d8
author: cbagwell <cbagwell>
date: Mon Sep 27 22:33:09 EDT 2004

c++ and libary cleanups

--- a/src/au.c
+++ b/src/au.c
@@ -55,7 +55,7 @@
         st_size_t dataStart;
         /* For G72x decoding: */
         struct g72x_state state;
-        int (*dec_routine)();
+        int (*dec_routine)(int i, int out_coding, struct g72x_state *state_ptr);
         int dec_bits;
         unsigned int in_buffer;
         int in_bits;
@@ -244,7 +244,7 @@
                 buf = (char *) malloc(hdr_size+1);              
                 for(i = 0; i < hdr_size; i++) {
                         st_readb(ft, (unsigned char *)&(buf[i]));
-                        if (feof(ft->fp))
+                        if (st_eof(ft))
                         {
                                 st_fail_errno(ft,ST_EOF,"Unexpected EOF in Sun/NeXT header info.");
                                 return(ST_EOF);
@@ -264,7 +264,7 @@
         /* Needed for seeking */
         ft->length = data_size/ft->info.size;
         if(ft->seekable)
-                p->dataStart = ftell(ft->fp);
+                p->dataStart = st_tell(ft);
 
         /* Needed for rawread() */
         rc = st_rawstartread(ft);
@@ -370,7 +370,7 @@
         /* Attempt to update header */
         if (ft->seekable)
         {
-          if (fseek(ft->fp, 0L, 0) != 0)
+          if (st_seek(ft, 0L, 0) != 0)
           {
                 st_fail_errno(ft,errno,"Can't rewind output file to rewrite Sun header.");
                 return(ST_EOF);
--- a/src/auto.c
+++ b/src/auto.c
@@ -37,137 +37,137 @@
      */
     if (ft->seekable)
     {
-	/* Most files only have 4-byte magic headers at first of
-	 * file.  So we start checking for those filetypes first.
-	 */
-	memset(header,0,4);
-	if (fread(header, 1, 4, ft->fp) == 4)
-	{
-	    /* Look for .snd or dns. header of AU files */
-	    if ((strncmp(header, ".snd", 4) == 0) ||
-		    (strncmp(header, "dns.", 4) == 0) ||
-		    ((header[0] == '\0') && (strncmp(header+1, "ds.", 3) == 0))) 
-	    {
-		type = "au";
-	    }
-	    else if (strncmp(header, "FORM", 4) == 0) 
-	    {
-		/* Need to read more data to see what type of FORM file */
-		if (fread(header, 1, 8, ft->fp) == 8)
-		{
-		    if (strncmp(header + 4, "AIFF", 4) == 0)
-			type = "aiff";
-		    else if (strncmp(header + 4, "AIFC", 4) == 0)
-			type = "aiff";
-			else if (strncmp(header + 4, "8SVX", 4) == 0)
-			type = "8svx";
-		    else if (strncmp(header + 4, "MAUD", 4) == 0)
-			type = "maud";
-		}
-	    }
-	    else if (strncmp(header, "RIFF", 4) == 0)
-	    {
-		if (fread(header, 1, 8, ft->fp) == 8)
-		{
-		    if (strncmp(header + 4, "WAVE", 4) == 0)
-			type = "wav";
-		}
-	    }
-	    else if (strncmp(header, "Crea", 4) == 0) 
-	    {
-		if (fread(header, 1, 15, ft->fp) == 15)
-		{
-		    if (strncmp(header, "tive Voice File", 15) == 0) 
-			type = "voc";
-		}
-	    }
-	    else if (strncmp(header, "SOUN", 4) == 0)
-	    {
-		/* Check for SOUND magic header */
-		if (fread(header, 1, 1, ft->fp) == 1 && *header == 'D')
-		{
-		    /* Once we've found SOUND see if its smp or sndt */
-		    if (fread(header, 1, 12, ft->fp) == 12)
-		    {
-			if (strncmp(header, " SAMPLE DATA", 12) == 0)
-    			    type = "smp";
-			else
-			    type = "sndt";
-		    }
-		    else
-			type = "sndt";
-		}
-	    }
-	    else if (strncmp(header, "2BIT", 4) == 0) 
-	    {
-		type = "avr";
-	    }
-	    else if (strncmp(header, "NIST", 4) == 0) 
-	    {
-		if (fread(header, 1, 3, ft->fp) == 3)
-		{
-		    if (strncmp(header, "_1A", 3) == 0) 
-			type = "sph";
-		}
-	    }
-	    else if (strncmp(header, "ALaw", 4) == 0)
-	    {
-		if (fread(header, 1, 11, ft->fp) == 11)
-		{
-		    if (strncmp(header, "SoundFile**", 11) == 0)
-		    {
-			type = "wve";
-		    }
-		}
-	    }
-	    else if (strncmp(header, "Ogg", 3) == 0)
-	    {
-	    	type = "ogg";
+        /* Most files only have 4-byte magic headers at first of
+         * file.  So we start checking for those filetypes first.
+         */
+        memset(header,0,4);
+        if (st_read(ft, header, 1, 4) == 4)
+        {
+            /* Look for .snd or dns. header of AU files */
+            if ((strncmp(header, ".snd", 4) == 0) ||
+                    (strncmp(header, "dns.", 4) == 0) ||
+                    ((header[0] == '\0') && (strncmp(header+1, "ds.", 3) == 0))) 
+            {
+                type = "au";
+            }
+            else if (strncmp(header, "FORM", 4) == 0) 
+            {
+                /* Need to read more data to see what type of FORM file */
+                if (st_read(ft, header, 1, 8) == 8)
+                {
+                    if (strncmp(header + 4, "AIFF", 4) == 0)
+                        type = "aiff";
+                    else if (strncmp(header + 4, "AIFC", 4) == 0)
+                        type = "aiff";
+                        else if (strncmp(header + 4, "8SVX", 4) == 0)
+                        type = "8svx";
+                    else if (strncmp(header + 4, "MAUD", 4) == 0)
+                        type = "maud";
+                }
+            }
+            else if (strncmp(header, "RIFF", 4) == 0)
+            {
+                if (st_read(ft, header, 1, 8) == 8)
+                {
+                    if (strncmp(header + 4, "WAVE", 4) == 0)
+                        type = "wav";
+                }
+            }
+            else if (strncmp(header, "Crea", 4) == 0) 
+            {
+                if (st_read(ft, header, 1, 15) == 15)
+                {
+                    if (strncmp(header, "tive Voice File", 15) == 0) 
+                        type = "voc";
+                }
+            }
+            else if (strncmp(header, "SOUN", 4) == 0)
+            {
+                /* Check for SOUND magic header */
+                if (st_read(ft, header, 1, 1) == 1 && *header == 'D')
+                {
+                    /* Once we've found SOUND see if its smp or sndt */
+                    if (st_read(ft, header, 1, 12) == 12)
+                    {
+                        if (strncmp(header, " SAMPLE DATA", 12) == 0)
+                            type = "smp";
+                        else
+                            type = "sndt";
+                    }
+                    else
+                        type = "sndt";
+                }
+            }
+            else if (strncmp(header, "2BIT", 4) == 0) 
+            {
+                type = "avr";
+            }
+            else if (strncmp(header, "NIST", 4) == 0) 
+            {
+                if (st_read(ft, header, 1, 3) == 3)
+                {
+                    if (strncmp(header, "_1A", 3) == 0) 
+                        type = "sph";
+                }
+            }
+            else if (strncmp(header, "ALaw", 4) == 0)
+            {
+                if (st_read(ft, header, 1, 11) == 11)
+                {
+                    if (strncmp(header, "SoundFile**", 11) == 0)
+                    {
+                        type = "wve";
+                    }
+                }
+            }
+            else if (strncmp(header, "Ogg", 3) == 0)
+            {
+                type = "ogg";
           }
-	} /* read 4-byte header */
+        } /* read 4-byte header */
 
-	/* If we didn't find type yet then start looking for file
-	 * formats that the magic header is deeper in the file.
-	 */
-	if (type == 0)
-	{
-	    loop = 61;
-	    while (loop--)
-	    {
-		if (fread(header, 1, 1, ft->fp) != 1)
-		    loop = 0;
-	    }
-	    if (fread(header, 1, 4, ft->fp) == 4 && 
-		strncmp(header, "FSSD", 4) == 0)
-	    {
-		loop = 63;
-		while (loop--)
-		{
-		    if (fread(header, 1, 1, ft->fp) != 1)
-			loop = 0;
-		}
-		if (fread(header, 1, 4, ft->fp) == 0 && 
-		    strncmp(header, "HCOM", 4) == 0)
-		    type = "hcom";
-	    }
-	}
-	rewind(ft->fp);
+        /* If we didn't find type yet then start looking for file
+         * formats that the magic header is deeper in the file.
+         */
+        if (type == 0)
+        {
+            loop = 61;
+            while (loop--)
+            {
+                if (st_read(ft, header, 1, 1) != 1)
+                    loop = 0;
+            }
+            if (st_read(ft, header, 1, 4) == 4 && 
+                strncmp(header, "FSSD", 4) == 0)
+            {
+                loop = 63;
+                while (loop--)
+                {
+                    if (st_read(ft, header, 1, 1) != 1)
+                        loop = 0;
+                }
+                if (st_read(ft, header, 1, 4) == 0 && 
+                    strncmp(header, "HCOM", 4) == 0)
+                    type = "hcom";
+            }
+        }
+        st_rewind(ft);
     } /* if (seekable) */
 
     if (type == 0)
     {
-	/* Use filename extension to determine audio type. */
+        /* Use filename extension to determine audio type. */
 
-	/* First, chop off any path portions of filename.  This
-	 * prevents the next search from considering that part. */
-	if ((type = strrchr(ft->filename, LASTCHAR)) == NULL)
-	    type = ft->filename;
+        /* First, chop off any path portions of filename.  This
+         * prevents the next search from considering that part. */
+        if ((type = strrchr(ft->filename, LASTCHAR)) == NULL)
+            type = ft->filename;
 
-	/* Now look for an filename extension */
-	if ((type = strrchr(type, '.')) != NULL)
-	    type++;
-	else
-	    type = NULL;
+        /* Now look for an filename extension */
+        if ((type = strrchr(type, '.')) != NULL)
+            type++;
+        else
+            type = NULL;
     }
 
     ft->filetype = type;
@@ -174,8 +174,8 @@
     rc = st_gettype(ft); /* Change ft->h to the new format */
     if(rc != ST_SUCCESS)
     {
-	st_fail_errno(ft,ST_EFMT,"Do not understand format type: %s\n",type);
-	return (rc);
+        st_fail_errno(ft,ST_EFMT,"Do not understand format type: %s\n",type);
+        return (rc);
     }
 
     st_report("Detected file format type: %s\n", type);
@@ -184,6 +184,6 @@
 
 int st_autostartwrite(ft_t ft) 
 {
-	st_fail_errno(ft,ST_EFMT,"Type AUTO can only be used for input!");
-	return(ST_EOF);
+        st_fail_errno(ft,ST_EFMT,"Type AUTO can only be used for input!");
+        return(ST_EOF);
 }
--- a/src/avr.c
+++ b/src/avr.c
@@ -36,19 +36,19 @@
   unsigned short sign; /* 0 = unsigned, 0xffff = signed */
   unsigned short loop; /* 0 = no loop, 0xffff = looping sample */
   unsigned short midi; /* 0xffff = no MIDI note assigned,
-			  0xffXX = single key note assignment
-			  0xLLHH = key split, low/hi note */
+                          0xffXX = single key note assignment
+                          0xLLHH = key split, low/hi note */
   uint32_t rate;       /* sample frequency in hertz */
   uint32_t size;       /* sample length in bytes or words (see rez) */
   uint32_t lbeg;       /* offset to start of loop in bytes or words.
-			  set to zero if unused. */
+                          set to zero if unused. */
   uint32_t lend;       /* offset to end of loop in bytes or words.
-			  set to sample length if unused. */
+                          set to sample length if unused. */
   unsigned short res1; /* Reserved, MIDI keyboard split */
   unsigned short res2; /* Reserved, sample compression */
   unsigned short res3; /* Reserved */
-  char ext[20];	       /* Additional filename space, used
-			  if (name[7] != 0) */
+  char ext[20];        /* Additional filename space, used
+                          if (name[7] != 0) */
   char user[64];       /* User defined. Typically ASCII message. */
 } *avr_t;
 
@@ -57,23 +57,22 @@
 /*
  * Do anything required before you start reading samples.
  * Read file header. 
- *	Find out sampling rate, 
- *	size and encoding of samples, 
- *	mono/stereo/quad.
+ *      Find out sampling rate, 
+ *      size and encoding of samples, 
+ *      mono/stereo/quad.
  */
 
 
-int st_avrstartread(ft) 
-ft_t ft;
+int st_avrstartread(ft_t ft) 
 {
-  avr_t	avr = (avr_t)ft->priv;
+  avr_t avr = (avr_t)ft->priv;
   int rc;
 
   /* AVR is a Big Endian format.  Swap whats read in on Little */
-  /* Endian machines.					       */
+  /* Endian machines.                                          */
   if (ST_IS_LITTLEENDIAN)
   {
-	  ft->swap = ft->swap ? 0 : 1;
+          ft->swap = ft->swap ? 0 : 1;
   }
 
   st_reads(ft, avr->magic, 4);
@@ -83,7 +82,7 @@
     return(ST_EOF);
   }
 
-  fread(avr->name, 1, sizeof(avr->name), ft->fp);
+  st_read(ft, avr->name, 1, sizeof(avr->name));
 
   st_readw (ft, &(avr->mono));
   if (avr->mono) {
@@ -138,9 +137,9 @@
 
   st_readw (ft, &(avr->res3));
 
-  fread(avr->ext, 1, sizeof(avr->ext), ft->fp);
+  st_read(ft, avr->ext, 1, sizeof(avr->ext));
 
-  fread(avr->user, 1, sizeof(avr->user), ft->fp);
+  st_read(ft, avr->user, 1, sizeof(avr->user));
 
   rc = st_rawstartread (ft);
   if (rc)
@@ -149,17 +148,16 @@
   return(ST_SUCCESS);
 }
 
-int st_avrstartwrite(ft) 
-ft_t ft;
+int st_avrstartwrite(ft_t ft) 
 {
-  avr_t	avr = (avr_t)ft->priv;
+  avr_t avr = (avr_t)ft->priv;
   int rc;
 
   /* AVR is a Big Endian format.  Swap whats read in on Little */
-  /* Endian machines.					       */
+  /* Endian machines.                                          */
   if (ST_IS_LITTLEENDIAN)
   {
-	  ft->swap = ft->swap ? 0 : 1;
+          ft->swap = ft->swap ? 0 : 1;
   }
 
   if (!ft->seekable) {
@@ -250,14 +248,14 @@
   st_writew (ft, 0);
 
   /* ext */
-  fwrite ("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 1, sizeof (avr->ext),
-          ft->fp);
+  st_write(ft, (void *)"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 1, sizeof(avr->ext));
 
   /* user */
-  fwrite ("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-          "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-          "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-          "\0\0\0\0", 1, sizeof (avr->user), ft->fp);
+  st_write(ft, 
+           (void *)"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+           "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+           "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+           "\0\0\0\0", 1, sizeof (avr->user));
 
   return(ST_SUCCESS);
 }
@@ -264,7 +262,7 @@
 
 st_ssize_t st_avrwrite(ft_t ft, st_sample_t *buf, st_ssize_t nsamp) 
 {
-  avr_t	avr = (avr_t)ft->priv;
+  avr_t avr = (avr_t)ft->priv;
 
   avr->size += nsamp;
 
@@ -273,7 +271,7 @@
 
 int st_avrstopwrite(ft_t ft) 
 {
-  avr_t	avr = (avr_t)ft->priv;
+  avr_t avr = (avr_t)ft->priv;
   int rc;
 
   int size = avr->size / ft->info.channels;
@@ -283,11 +281,11 @@
       return rc;
 
   /* Fix size */
-  fseek (ft->fp, 26L, SEEK_SET);
+  st_seek(ft, 26L, SEEK_SET);
   st_writedw (ft, size);
 
   /* Fix lend */
-  fseek (ft->fp, 34L, SEEK_SET);
+  st_seek(ft, 34L, SEEK_SET);
   st_writedw (ft, size);
 
   return(ST_SUCCESS);
--- a/src/breject.c
+++ b/src/breject.c
@@ -36,10 +36,7 @@
 #include "st_i.h"
 #include "btrworth.h"
 
-int st_bandreject_getopts (effp, n, argv)
-eff_t effp;
-int n;
-char **argv;
+int st_bandreject_getopts(eff_t effp, int n, char **argv)
 {
   butterworth_t butterworth = (butterworth_t)effp->priv;
 
@@ -62,8 +59,7 @@
   return (ST_SUCCESS);
 }
 
-int st_bandreject_start (effp)
-eff_t effp;
+int st_bandreject_start(eff_t effp)
 {
   butterworth_t butterworth = (butterworth_t) effp->priv;
   double c;
--- a/src/compand.c
+++ b/src/compand.c
@@ -101,9 +101,9 @@
       }
 
       rates = 1 + commas/2;
-      if ((l->attackRate = malloc(sizeof(double) * rates)) == NULL ||
-          (l->decayRate  = malloc(sizeof(double) * rates)) == NULL ||
-          (l->volume     = malloc(sizeof(double) * rates)) == NULL)
+      if ((l->attackRate = (double *)malloc(sizeof(double) * rates)) == NULL ||
+          (l->decayRate  = (double *)malloc(sizeof(double) * rates)) == NULL ||
+          (l->volume     = (double *)malloc(sizeof(double) * rates)) == NULL)
       {
         st_fail("Out of memory");
         return (ST_EOF);
@@ -135,8 +135,8 @@
       }
 
       tfers = 3 + commas/2; /* 0, 0 at start; 1, 1 at end */
-      if ((l->transferIns  = malloc(sizeof(double) * tfers)) == NULL ||
-          (l->transferOuts = malloc(sizeof(double) * tfers)) == NULL)
+      if ((l->transferIns  = (double *)malloc(sizeof(double) * tfers)) == NULL ||
+          (l->transferOuts = (double *)malloc(sizeof(double) * tfers)) == NULL)
       {
         st_fail("Out of memory");
         return (ST_EOF);
@@ -240,7 +240,7 @@
   /* Allocate the delay buffer */
   l->delay_buf_size = l->delay * effp->outinfo.rate * effp->outinfo.channels;
   if (l->delay_buf_size > 0
-   && (l->delay_buf = malloc(sizeof(long) * l->delay_buf_size)) == NULL) {
+   && (l->delay_buf = (st_sample_t *)malloc(sizeof(long) * l->delay_buf_size)) == NULL) {
     st_fail("Out of memory");
     return (ST_EOF);
   }
--- a/src/cvsd.c
+++ b/src/cvsd.c
@@ -463,7 +463,7 @@
 
 /* ---------------------------------------------------------------------- */
 
-static int dvms_read_header(FILE *f, struct dvms_header *hdr)
+static int dvms_read_header(ft_t ft, struct dvms_header *hdr)
 {
         unsigned char hdrbuf[DVMS_HEADER_LEN];
         unsigned char *pch = hdrbuf;
@@ -470,7 +470,7 @@
         int i;
         unsigned sum;
 
-        if (fread(hdrbuf, sizeof(hdrbuf), 1, f) != 1)
+        if (st_read(ft, hdrbuf, sizeof(hdrbuf), 1) != 1)
         {
                 return (ST_EOF);
         }
@@ -508,7 +508,7 @@
 /*
  * note! file must be seekable
  */
-static int dvms_write_header(FILE *f, struct dvms_header *hdr)
+static int dvms_write_header(ft_t ft, struct dvms_header *hdr)
 {
         unsigned char hdrbuf[DVMS_HEADER_LEN];
         unsigned char *pch = hdrbuf;
@@ -536,12 +536,12 @@
                 sum += *pchs++;
         hdr->Crc = sum;
         put16(&pch, hdr->Crc);
-        if (fseek(f, 0, SEEK_SET) < 0)
+        if (st_seek(ft, 0, SEEK_SET) < 0)
         {
                 st_report("seek failed\n: %s",strerror(errno));
                 return (ST_EOF);
         }
-        if (fwrite(hdrbuf, sizeof(hdrbuf), 1, f) != 1)
+        if (st_write(ft, hdrbuf, sizeof(hdrbuf), 1) != 1)
         {
                 st_report("%s\n",strerror(errno));
                 return (ST_EOF);
@@ -583,7 +583,7 @@
         struct dvms_header hdr;
         int rc;
 
-        rc = dvms_read_header(ft->fp, &hdr);
+        rc = dvms_read_header(ft, &hdr);
         if (rc){
             st_fail_errno(ft,ST_EHDR,"unable to read DVMS header\n");
             return rc;
@@ -627,7 +627,7 @@
             return rc;
 
         make_dvms_hdr(ft, &hdr);
-        rc = dvms_write_header(ft->fp, &hdr);
+        rc = dvms_write_header(ft, &hdr);
         if (rc){
                 st_fail_errno(ft,rc,"cannot write DVMS header\n");
             return rc;
@@ -653,13 +653,13 @@
             st_warn("File not seekable");
             return (ST_EOF);
         }
-        if (fseek(ft->fp, 0L, 0) != 0)
+        if (st_seek(ft, 0L, 0) != 0)
         {
                 st_fail_errno(ft,errno,"Can't rewind output file to rewrite DVMS header.");
                 return(ST_EOF);
         }
         make_dvms_hdr(ft, &hdr);
-        rc = dvms_write_header(ft->fp, &hdr);
+        rc = dvms_write_header(ft, &hdr);
         if(rc){
             st_fail_errno(ft,rc,"cannot write DVMS header\n");
             return rc;
--- a/src/dat.c
+++ b/src/dat.c
@@ -24,7 +24,7 @@
 
 /* Private data for dat file */
 typedef struct dat {
-	double timevalue, deltat;
+        double timevalue, deltat;
 } *dat_t;
 
 /* FIXME: Move this to misc.c */
@@ -41,13 +41,13 @@
    long rate;
 
    while (ft->info.rate == 0) {
-      fgets(inpstr, 82, ft->fp);
+      st_reads(ft, inpstr, 82);
       inpstr[81] = 0;
       sscanf(inpstr," %c",&sc);
       if (sc != ';') 
       {
-	  st_fail_errno(ft,ST_EHDR,"Cannot determine sample rate.");
-	  return (ST_EOF);
+          st_fail_errno(ft,ST_EHDR,"Cannot determine sample rate.");
+          return (ST_EOF);
       }
       /* Store in system dependent long to get around cross platform
        * problems.
@@ -75,8 +75,8 @@
    if (ft->info.channels > 1)
    {
         st_report("Can only create .dat files with one channel.");
-	st_report("Forcing output to 1 channel.");
-	ft->info.channels = 1;
+        st_report("Forcing output to 1 channel.");
+        ft->info.channels = 1;
    }
    
    ft->info.size = ST_SIZE_64BIT;
@@ -101,23 +101,23 @@
 
     while (done < nsamp) {
         do {
-          fgets(inpstr,82,ft->fp);
-          if (feof(ft->fp)) {
-		return (done);
-	  }
+          st_reads(ft, inpstr, 82);
+          if (st_eof(ft)) {
+                return (done);
+          }
           sscanf(inpstr," %c",&sc);
           }
           while(sc == ';');  /* eliminate comments */
         retc = sscanf(inpstr,"%*s %lg",&sampval);
         if (retc != 1) 
-	{
-	    st_fail_errno(ft,ST_EOF,"Unable to read sample.");
-	    return (0);
-	}
+        {
+            st_fail_errno(ft,ST_EOF,"Unable to read sample.");
+            return (0);
+        }
         *buf++ = roundoff(sampval * 2.147483648e9);
         ++done;
     }
-	return (done);
+        return (done);
 }
 
 st_ssize_t st_datwrite(ft_t ft, st_sample_t *buf, st_ssize_t nsamp)
--- a/src/fade.c
+++ b/src/fade.c
@@ -78,7 +78,7 @@
         fade->out_fadetype = 'l';
     }
 
-    fade->in_stop_str = malloc(strlen(argv[0])+1);
+    fade->in_stop_str = (char *)malloc(strlen(argv[0])+1);
     if (!fade->in_stop_str)
     {
         st_fail("Could not allocate memory");
@@ -100,7 +100,7 @@
         /* See if there is fade-in/fade-out times/curves specified. */
         if(t_argno == 1)
         {
-            fade->out_stop_str = malloc(strlen(argv[t_argno])+1);
+            fade->out_stop_str = (char *)malloc(strlen(argv[t_argno])+1);
             if (!fade->out_stop_str)
             {
                 st_fail("Could not allocate memory");
@@ -118,7 +118,7 @@
         }
         else
         {
-            fade->out_start_str = malloc(strlen(argv[t_argno])+1);
+            fade->out_start_str = (char *)malloc(strlen(argv[t_argno])+1);
             if (!fade->out_start_str)
             {
                 st_fail("Could not allocate memory");
--- a/src/g72x.c
+++ b/src/g72x.c
@@ -35,7 +35,7 @@
 #include "g72x.h"
 
 static short power2[15] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80,
-			0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000};
+                        0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000};
 
 /*
  * quan()
@@ -45,18 +45,14 @@
  *
  * Using linear search for simple coding.
  */
-static int
-quan(val,table,size)
-	int		val;
-	short		*table;
-	int		size;
+static int quan(int val, short *table, int size)
 {
-	int		i;
+        int             i;
 
-	for (i = 0; i < size; i++)
-		if (val < *table++)
-			break;
-	return (i);
+        for (i = 0; i < size; i++)
+                if (val < *table++)
+                        break;
+        return (i);
 }
 
 /*
@@ -65,26 +61,23 @@
  * returns the integer product of the 14-bit integer "an" and
  * "floating point" representation (4-bit exponent, 6-bit mantessa) "srn".
  */
-static int
-fmult(an, srn)
-	int		an;
-	int		srn;
+static int fmult(int an, int srn)
 {
-	short		anmag, anexp, anmant;
-	short		wanexp, wanmant;
-	short		retval;
+        short           anmag, anexp, anmant;
+        short           wanexp, wanmant;
+        short           retval;
 
-	anmag = (an > 0) ? an : ((-an) & 0x1FFF);
-	anexp = quan(anmag, power2, 15) - 6;
-	anmant = (anmag == 0) ? 32 :
-	    (anexp >= 0) ? anmag >> anexp : anmag << -anexp;
-	wanexp = anexp + ((srn >> 6) & 0xF) - 13;
+        anmag = (an > 0) ? an : ((-an) & 0x1FFF);
+        anexp = quan(anmag, power2, 15) - 6;
+        anmant = (anmag == 0) ? 32 :
+            (anexp >= 0) ? anmag >> anexp : anmag << -anexp;
+        wanexp = anexp + ((srn >> 6) & 0xF) - 13;
 
-	wanmant = (anmant * (srn & 077) + 0x30) >> 4;
-	retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) :
-	    (wanmant >> -wanexp);
+        wanmant = (anmant * (srn & 077) + 0x30) >> 4;
+        retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) :
+            (wanmant >> -wanexp);
 
-	return (((an ^ srn) < 0) ? -retval : retval);
+        return (((an ^ srn) < 0) ? -retval : retval);
 }
 
 /*
@@ -94,27 +87,25 @@
  * pointed to by 'state_ptr'.
  * All the initial state values are specified in the CCITT G.721 document.
  */
-void
-g72x_init_state(state_ptr)
-	struct g72x_state *state_ptr;
+void g72x_init_state(struct g72x_state *state_ptr)
 {
-	int		cnta;
+        int             cnta;
 
-	state_ptr->yl = 34816L;
-	state_ptr->yu = 544;
-	state_ptr->dms = 0;
-	state_ptr->dml = 0;
-	state_ptr->ap = 0;
-	for (cnta = 0; cnta < 2; cnta++) {
-		state_ptr->a[cnta] = 0;
-		state_ptr->pk[cnta] = 0;
-		state_ptr->sr[cnta] = 32;
-	}
-	for (cnta = 0; cnta < 6; cnta++) {
-		state_ptr->b[cnta] = 0;
-		state_ptr->dq[cnta] = 32;
-	}
-	state_ptr->td = 0;
+        state_ptr->yl = 34816L;
+        state_ptr->yu = 544;
+        state_ptr->dms = 0;
+        state_ptr->dml = 0;
+        state_ptr->ap = 0;
+        for (cnta = 0; cnta < 2; cnta++) {
+                state_ptr->a[cnta] = 0;
+                state_ptr->pk[cnta] = 0;
+                state_ptr->sr[cnta] = 32;
+        }
+        for (cnta = 0; cnta < 6; cnta++) {
+                state_ptr->b[cnta] = 0;
+                state_ptr->dq[cnta] = 32;
+        }
+        state_ptr->td = 0;
 }
 
 /*
@@ -123,17 +114,15 @@
  * computes the estimated signal from 6-zero predictor.
  *
  */
-int
-predictor_zero(state_ptr)
-	struct g72x_state *state_ptr;
+int predictor_zero(struct g72x_state *state_ptr)
 {
-	int		i;
-	int		sezi;
+        int             i;
+        int             sezi;
 
-	sezi = fmult(state_ptr->b[0] >> 2, state_ptr->dq[0]);
-	for (i = 1; i < 6; i++)			/* ACCUM */
-		sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]);
-	return (sezi);
+        sezi = fmult(state_ptr->b[0] >> 2, state_ptr->dq[0]);
+        for (i = 1; i < 6; i++)                 /* ACCUM */
+                sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]);
+        return (sezi);
 }
 /*
  * predictor_pole()
@@ -141,12 +130,10 @@
  * computes the estimated signal from 2-pole predictor.
  *
  */
-int
-predictor_pole(state_ptr)
-	struct g72x_state *state_ptr;
+int predictor_pole(struct g72x_state *state_ptr)
 {
-	return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) +
-	    fmult(state_ptr->a[0] >> 2, state_ptr->sr[0]));
+        return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) +
+            fmult(state_ptr->a[0] >> 2, state_ptr->sr[0]));
 }
 /*
  * step_size()
@@ -154,26 +141,24 @@
  * computes the quantization step size of the adaptive quantizer.
  *
  */
-int
-step_size(state_ptr)
-	struct g72x_state *state_ptr;
+int step_size(struct g72x_state *state_ptr)
 {
-	int		y;
-	int		dif;
-	int		al;
+        int             y;
+        int             dif;
+        int             al;
 
-	if (state_ptr->ap >= 256)
-		return (state_ptr->yu);
-	else {
-		y = state_ptr->yl >> 6;
-		dif = state_ptr->yu - y;
-		al = state_ptr->ap >> 2;
-		if (dif > 0)
-			y += (dif * al) >> 6;
-		else if (dif < 0)
-			y += (dif * al + 0x3F) >> 6;
-		return (y);
-	}
+        if (state_ptr->ap >= 256)
+                return (state_ptr->yu);
+        else {
+                y = state_ptr->yl >> 6;
+                dif = state_ptr->yu - y;
+                al = state_ptr->ap >> 2;
+                if (dif > 0)
+                        y += (dif * al) >> 6;
+                else if (dif < 0)
+                        y += (dif * al + 0x3F) >> 6;
+                return (y);
+        }
 }
 
 /*
@@ -185,49 +170,50 @@
  * size scale factor division operation is done in the log base 2 domain
  * as a subtraction.
  */
-int
-quantize(d, y,table,size)
-	int		d;	/* Raw difference signal sample */
-	int		y;	/* Step size multiplier */
-	short		*table;	/* quantization table */
-	int		size;	/* table size of short integers */
+int quantize(int d, int y, short *table, int size)
+#if 0
+        int             d;      /* Raw difference signal sample */
+        int             y;      /* Step size multiplier */
+        short           *table; /* quantization table */
+        int             size;   /* table size of short integers */
+#endif
 {
-	short		dqm;	/* Magnitude of 'd' */
-	short		exp;	/* Integer part of base 2 log of 'd' */
-	short		mant;	/* Fractional part of base 2 log */
-	short		dl;	/* Log of magnitude of 'd' */
-	short		dln;	/* Step size scale factor normalized log */
-	int		i;
+        short           dqm;    /* Magnitude of 'd' */
+        short           exp;    /* Integer part of base 2 log of 'd' */
+        short           mant;   /* Fractional part of base 2 log */
+        short           dl;     /* Log of magnitude of 'd' */
+        short           dln;    /* Step size scale factor normalized log */
+        int             i;
 
-	/*
-	 * LOG
-	 *
-	 * Compute base 2 log of 'd', and store in 'dl'.
-	 */
-	dqm = abs(d);
-	exp = quan(dqm >> 1, power2, 15);
-	mant = ((dqm << 7) >> exp) & 0x7F;	/* Fractional portion. */
-	dl = (exp << 7) + mant;
+        /*
+         * LOG
+         *
+         * Compute base 2 log of 'd', and store in 'dl'.
+         */
+        dqm = abs(d);
+        exp = quan(dqm >> 1, power2, 15);
+        mant = ((dqm << 7) >> exp) & 0x7F;      /* Fractional portion. */
+        dl = (exp << 7) + mant;
 
-	/*
-	 * SUBTB
-	 *
-	 * "Divide" by step size multiplier.
-	 */
-	dln = dl - (y >> 2);
+        /*
+         * SUBTB
+         *
+         * "Divide" by step size multiplier.
+         */
+        dln = dl - (y >> 2);
 
-	/*
-	 * QUAN
-	 *
-	 * Obtain codword i for 'd'.
-	 */
-	i = quan(dln, table, size);
-	if (d < 0)			/* take 1's complement of i */
-		return ((size << 1) + 1 - i);
-	else if (i == 0)		/* take 1's complement of 0 */
-		return ((size << 1) + 1); /* new in 1988 */
-	else
-		return (i);
+        /*
+         * QUAN
+         *
+         * Obtain codword i for 'd'.
+         */
+        i = quan(dln, table, size);
+        if (d < 0)                      /* take 1's complement of i */
+                return ((size << 1) + 1 - i);
+        else if (i == 0)                /* take 1's complement of 0 */
+                return ((size << 1) + 1); /* new in 1988 */
+        else
+                return (i);
 }
 /*
  * reconstruct()
@@ -236,27 +222,28 @@
  * codeword 'i' and quantization step size scale factor 'y'.
  * Multiplication is performed in log base 2 domain as addition.
  */
-int
-reconstruct(sign, dqln, y)
-	int		sign;	/* 0 for non-negative value */
-	int		dqln;	/* G.72x codeword */
-	int		y;	/* Step size multiplier */
+int reconstruct(int sign, int dqln, int y)
+#if 0
+        int             sign;   /* 0 for non-negative value */
+        int             dqln;   /* G.72x codeword */
+        int             y;      /* Step size multiplier */
+#endif
 {
-	short		dql;	/* Log of 'dq' magnitude */
-	short		dex;	/* Integer part of log */
-	short		dqt;
-	short		dq;	/* Reconstructed difference signal sample */
+        short           dql;    /* Log of 'dq' magnitude */
+        short           dex;    /* Integer part of log */
+        short           dqt;
+        short           dq;     /* Reconstructed difference signal sample */
 
-	dql = dqln + (y >> 2);	/* ADDA */
+        dql = dqln + (y >> 2);  /* ADDA */
 
-	if (dql < 0) {
-		return ((sign) ? -0x8000 : 0);
-	} else {		/* ANTILOG */
-		dex = (dql >> 7) & 15;
-		dqt = 128 + (dql & 127);
-		dq = (dqt << 7) >> (14 - dex);
-		return ((sign) ? (dq - 0x8000) : dq);
-	}
+        if (dql < 0) {
+                return ((sign) ? -0x8000 : 0);
+        } else {                /* ANTILOG */
+                dex = (dql >> 7) & 15;
+                dqt = 128 + (dql & 127);
+                dq = (dqt << 7) >> (14 - dex);
+                return ((sign) ? (dq - 0x8000) : dq);
+        }
 }
 
 
@@ -265,197 +252,199 @@
  *
  * updates the state variables for each output code
  */
-void
-update(code_size, y, wi, fi, dq, sr, dqsez, state_ptr)
-	int		code_size;	/* distinguish 723_40 with others */
-	int		y;		/* quantizer step size */
-	int		wi;		/* scale factor multiplier */
-	int		fi;		/* for long/short term energies */
-	int		dq;		/* quantized prediction difference */
-	int		sr;		/* reconstructed signal */
-	int		dqsez;		/* difference from 2-pole predictor */
-	struct g72x_state *state_ptr;	/* coder state pointer */
+void update(int code_size, int y, int wi, int fi, int dq, int sr, 
+            int dqsez, struct g72x_state *state_ptr)
+#if 0
+        int             code_size;      /* distinguish 723_40 with others */
+        int             y;              /* quantizer step size */
+        int             wi;             /* scale factor multiplier */
+        int             fi;             /* for long/short term energies */
+        int             dq;             /* quantized prediction difference */
+        int             sr;             /* reconstructed signal */
+        int             dqsez;          /* difference from 2-pole predictor */
+        struct g72x_state *state_ptr;   /* coder state pointer */
+#endif
 {
-	int		cnt;
-	short		mag, exp;	/* Adaptive predictor, FLOAT A */
-	short		a2p=0;		/* LIMC */
-	short		a1ul;		/* UPA1 */
-	short		pks1;		/* UPA2 */
-	short		fa1;
-	char		tr;		/* tone/transition detector */
-	short		ylint, thr2, dqthr;
-	short  		ylfrac, thr1;
-	short		pk0;
+        int             cnt;
+        short           mag, exp;       /* Adaptive predictor, FLOAT A */
+        short           a2p=0;          /* LIMC */
+        short           a1ul;           /* UPA1 */
+        short           pks1;           /* UPA2 */
+        short           fa1;
+        char            tr;             /* tone/transition detector */
+        short           ylint, thr2, dqthr;
+        short           ylfrac, thr1;
+        short           pk0;
 
-	pk0 = (dqsez < 0) ? 1 : 0;	/* needed in updating predictor poles */
+        pk0 = (dqsez < 0) ? 1 : 0;      /* needed in updating predictor poles */
 
-	mag = dq & 0x7FFF;		/* prediction difference magnitude */
-	/* TRANS */
-	ylint = state_ptr->yl >> 15;	/* exponent part of yl */
-	ylfrac = (state_ptr->yl >> 10) & 0x1F;	/* fractional part of yl */
-	thr1 = (32 + ylfrac) << ylint;		/* threshold */
-	thr2 = (ylint > 9) ? 31 << 10 : thr1;	/* limit thr2 to 31 << 10 */
-	dqthr = (thr2 + (thr2 >> 1)) >> 1;	/* dqthr = 0.75 * thr2 */
-	if (state_ptr->td == 0)		/* signal supposed voice */
-		tr = 0;
-	else if (mag <= dqthr)		/* supposed data, but small mag */
-		tr = 0;			/* treated as voice */
-	else				/* signal is data (modem) */
-		tr = 1;
+        mag = dq & 0x7FFF;              /* prediction difference magnitude */
+        /* TRANS */
+        ylint = state_ptr->yl >> 15;    /* exponent part of yl */
+        ylfrac = (state_ptr->yl >> 10) & 0x1F;  /* fractional part of yl */
+        thr1 = (32 + ylfrac) << ylint;          /* threshold */
+        thr2 = (ylint > 9) ? 31 << 10 : thr1;   /* limit thr2 to 31 << 10 */
+        dqthr = (thr2 + (thr2 >> 1)) >> 1;      /* dqthr = 0.75 * thr2 */
+        if (state_ptr->td == 0)         /* signal supposed voice */
+                tr = 0;
+        else if (mag <= dqthr)          /* supposed data, but small mag */
+                tr = 0;                 /* treated as voice */
+        else                            /* signal is data (modem) */
+                tr = 1;
 
-	/*
-	 * Quantizer scale factor adaptation.
-	 */
+        /*
+         * Quantizer scale factor adaptation.
+         */
 
-	/* FUNCTW & FILTD & DELAY */
-	/* update non-steady state step size multiplier */
-	state_ptr->yu = y + ((wi - y) >> 5);
+        /* FUNCTW & FILTD & DELAY */
+        /* update non-steady state step size multiplier */
+        state_ptr->yu = y + ((wi - y) >> 5);
 
-	/* LIMB */
-	if (state_ptr->yu < 544)	/* 544 <= yu <= 5120 */
-		state_ptr->yu = 544;
-	else if (state_ptr->yu > 5120)
-		state_ptr->yu = 5120;
+        /* LIMB */
+        if (state_ptr->yu < 544)        /* 544 <= yu <= 5120 */
+                state_ptr->yu = 544;
+        else if (state_ptr->yu > 5120)
+                state_ptr->yu = 5120;
 
-	/* FILTE & DELAY */
-	/* update steady state step size multiplier */
-	state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6);
+        /* FILTE & DELAY */
+        /* update steady state step size multiplier */
+        state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6);
 
-	/*
-	 * Adaptive predictor coefficients.
-	 */
-	if (tr == 1) {			/* reset a's and b's for modem signal */
-		state_ptr->a[0] = 0;
-		state_ptr->a[1] = 0;
-		state_ptr->b[0] = 0;
-		state_ptr->b[1] = 0;
-		state_ptr->b[2] = 0;
-		state_ptr->b[3] = 0;
-		state_ptr->b[4] = 0;
-		state_ptr->b[5] = 0;
-	} else {			/* update a's and b's */
-		pks1 = pk0 ^ state_ptr->pk[0];		/* UPA2 */
+        /*
+         * Adaptive predictor coefficients.
+         */
+        if (tr == 1) {                  /* reset a's and b's for modem signal */
+                state_ptr->a[0] = 0;
+                state_ptr->a[1] = 0;
+                state_ptr->b[0] = 0;
+                state_ptr->b[1] = 0;
+                state_ptr->b[2] = 0;
+                state_ptr->b[3] = 0;
+                state_ptr->b[4] = 0;
+                state_ptr->b[5] = 0;
+        } else {                        /* update a's and b's */
+                pks1 = pk0 ^ state_ptr->pk[0];          /* UPA2 */
 
-		/* update predictor pole a[1] */
-		a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7);
-		if (dqsez != 0) {
-			fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0];
-			if (fa1 < -8191)	/* a2p = function of fa1 */
-				a2p -= 0x100;
-			else if (fa1 > 8191)
-				a2p += 0xFF;
-			else
-				a2p += fa1 >> 5;
+                /* update predictor pole a[1] */
+                a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7);
+                if (dqsez != 0) {
+                        fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0];
+                        if (fa1 < -8191)        /* a2p = function of fa1 */
+                                a2p -= 0x100;
+                        else if (fa1 > 8191)
+                                a2p += 0xFF;
+                        else
+                                a2p += fa1 >> 5;
 
-			if (pk0 ^ state_ptr->pk[1])
-			{
-				/* LIMC */
-				if (a2p <= -12160)
-					a2p = -12288;
-				else if (a2p >= 12416)
-					a2p = 12288;
-				else
-					a2p -= 0x80;
-			}
-			else if (a2p <= -12416)
-				a2p = -12288;
-			else if (a2p >= 12160)
-				a2p = 12288;
-			else
-				a2p += 0x80;
-		}
+                        if (pk0 ^ state_ptr->pk[1])
+                        {
+                                /* LIMC */
+                                if (a2p <= -12160)
+                                        a2p = -12288;
+                                else if (a2p >= 12416)
+                                        a2p = 12288;
+                                else
+                                        a2p -= 0x80;
+                        }
+                        else if (a2p <= -12416)
+                                a2p = -12288;
+                        else if (a2p >= 12160)
+                                a2p = 12288;
+                        else
+                                a2p += 0x80;
+                }
 
-		/* Possible bug: a2p not initialized if dqsez == 0) */
-		/* TRIGB & DELAY */
-		state_ptr->a[1] = a2p;
+                /* Possible bug: a2p not initialized if dqsez == 0) */
+                /* TRIGB & DELAY */
+                state_ptr->a[1] = a2p;
 
-		/* UPA1 */
-		/* update predictor pole a[0] */
-		state_ptr->a[0] -= state_ptr->a[0] >> 8;
-		if (dqsez != 0)
-		{
-			if (pks1 == 0)
-				state_ptr->a[0] += 192;
-			else
-				state_ptr->a[0] -= 192;
-		}
-		/* LIMD */
-		a1ul = 15360 - a2p;
-		if (state_ptr->a[0] < -a1ul)
-			state_ptr->a[0] = -a1ul;
-		else if (state_ptr->a[0] > a1ul)
-			state_ptr->a[0] = a1ul;
+                /* UPA1 */
+                /* update predictor pole a[0] */
+                state_ptr->a[0] -= state_ptr->a[0] >> 8;
+                if (dqsez != 0)
+                {
+                        if (pks1 == 0)
+                                state_ptr->a[0] += 192;
+                        else
+                                state_ptr->a[0] -= 192;
+                }
+                /* LIMD */
+                a1ul = 15360 - a2p;
+                if (state_ptr->a[0] < -a1ul)
+                        state_ptr->a[0] = -a1ul;
+                else if (state_ptr->a[0] > a1ul)
+                        state_ptr->a[0] = a1ul;
 
-		/* UPB : update predictor zeros b[6] */
-		for (cnt = 0; cnt < 6; cnt++) {
-			if (code_size == 5)		/* for 40Kbps G.723 */
-				state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9;
-			else			/* for G.721 and 24Kbps G.723 */
-				state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8;
-			if (dq & 0x7FFF) {			/* XOR */
-				if ((dq ^ state_ptr->dq[cnt]) >= 0)
-					state_ptr->b[cnt] += 128;
-				else
-					state_ptr->b[cnt] -= 128;
-			}
-		}
-	}
+                /* UPB : update predictor zeros b[6] */
+                for (cnt = 0; cnt < 6; cnt++) {
+                        if (code_size == 5)             /* for 40Kbps G.723 */
+                                state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9;
+                        else                    /* for G.721 and 24Kbps G.723 */
+                                state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8;
+                        if (dq & 0x7FFF) {                      /* XOR */
+                                if ((dq ^ state_ptr->dq[cnt]) >= 0)
+                                        state_ptr->b[cnt] += 128;
+                                else
+                                        state_ptr->b[cnt] -= 128;
+                        }
+                }
+        }
 
-	for (cnt = 5; cnt > 0; cnt--)
-		state_ptr->dq[cnt] = state_ptr->dq[cnt-1];
-	/* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */
-	if (mag == 0) {
-		state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0xFC20;
-	} else {
-		exp = quan(mag, power2, 15);
-		state_ptr->dq[0] = (dq >= 0) ?
-		    (exp << 6) + ((mag << 6) >> exp) :
-		    (exp << 6) + ((mag << 6) >> exp) - 0x400;
-	}
+        for (cnt = 5; cnt > 0; cnt--)
+                state_ptr->dq[cnt] = state_ptr->dq[cnt-1];
+        /* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */
+        if (mag == 0) {
+                state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0xFC20;
+        } else {
+                exp = quan(mag, power2, 15);
+                state_ptr->dq[0] = (dq >= 0) ?
+                    (exp << 6) + ((mag << 6) >> exp) :
+                    (exp << 6) + ((mag << 6) >> exp) - 0x400;
+        }
 
-	state_ptr->sr[1] = state_ptr->sr[0];
-	/* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */
-	if (sr == 0) {
-		state_ptr->sr[0] = 0x20;
-	} else if (sr > 0) {
-		exp = quan(sr, power2, 15);
-		state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp);
-	} else if (sr > -32768L) {
-		mag = -sr;
-		exp = quan(mag, power2, 15);
-		state_ptr->sr[0] =  (exp << 6) + ((mag << 6) >> exp) - 0x400;
-	} else
-		state_ptr->sr[0] = 0xFC20;
+        state_ptr->sr[1] = state_ptr->sr[0];
+        /* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */
+        if (sr == 0) {
+                state_ptr->sr[0] = 0x20;
+        } else if (sr > 0) {
+                exp = quan(sr, power2, 15);
+                state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp);
+        } else if (sr > -32768L) {
+                mag = -sr;
+                exp = quan(mag, power2, 15);
+                state_ptr->sr[0] =  (exp << 6) + ((mag << 6) >> exp) - 0x400;
+        } else
+                state_ptr->sr[0] = 0xFC20;
 
-	/* DELAY A */
-	state_ptr->pk[1] = state_ptr->pk[0];
-	state_ptr->pk[0] = pk0;
+        /* DELAY A */
+        state_ptr->pk[1] = state_ptr->pk[0];
+        state_ptr->pk[0] = pk0;
 
-	/* TONE */
-	if (tr == 1)		/* this sample has been treated as data */
-		state_ptr->td = 0;	/* next one will be treated as voice */
-	else if (a2p < -11776)	/* small sample-to-sample correlation */
-		state_ptr->td = 1;	/* signal may be data */
-	else				/* signal is voice */
-		state_ptr->td = 0;
+        /* TONE */
+        if (tr == 1)            /* this sample has been treated as data */
+                state_ptr->td = 0;      /* next one will be treated as voice */
+        else if (a2p < -11776)  /* small sample-to-sample correlation */
+                state_ptr->td = 1;      /* signal may be data */
+        else                            /* signal is voice */
+                state_ptr->td = 0;
 
-	/*
-	 * Adaptation speed control.
-	 */
-	state_ptr->dms += (fi - state_ptr->dms) >> 5;		/* FILTA */
-	state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7);	/* FILTB */
+        /*
+         * Adaptation speed control.
+         */
+        state_ptr->dms += (fi - state_ptr->dms) >> 5;           /* FILTA */
+        state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7);  /* FILTB */
 
-	if (tr == 1)
-		state_ptr->ap = 256;
-	else if (y < 1536)					/* SUBTC */
-		state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
-	else if (state_ptr->td == 1)
-		state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
-	else if (abs((state_ptr->dms << 2) - state_ptr->dml) >=
-	    (state_ptr->dml >> 3))
-		state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
-	else
-		state_ptr->ap += (-state_ptr->ap) >> 4;
+        if (tr == 1)
+                state_ptr->ap = 256;
+        else if (y < 1536)                                      /* SUBTC */
+                state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
+        else if (state_ptr->td == 1)
+                state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
+        else if (abs((state_ptr->dms << 2) - state_ptr->dml) >=
+            (state_ptr->dml >> 3))
+                state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
+        else
+                state_ptr->ap += (-state_ptr->ap) >> 4;
 }
 
 /*
@@ -467,103 +456,105 @@
  * is adjusted by one level of A-law or u-law codes.
  *
  * Input:
- *	sr	decoder output linear PCM sample,
- *	se	predictor estimate sample,
- *	y	quantizer step size,
- *	i	decoder input code,
- *	sign	sign bit of code i
+ *      sr      decoder output linear PCM sample,
+ *      se      predictor estimate sample,
+ *      y       quantizer step size,
+ *      i       decoder input code,
+ *      sign    sign bit of code i
  *
  * Return:
- *	adjusted A-law or u-law compressed sample.
+ *      adjusted A-law or u-law compressed sample.
  */
-int
-tandem_adjust_alaw(sr, se, y, i, sign, qtab)
-	int		sr;	/* decoder output linear PCM sample */
-	int		se;	/* predictor estimate sample */
-	int		y;	/* quantizer step size */
-	int		i;	/* decoder input code */
-	int		sign;
-	short		*qtab;
+int tandem_adjust_alaw(int sr, int se, int y, int i, int sign, short *qtab)
+#if 0
+        int             sr;     /* decoder output linear PCM sample */
+        int             se;     /* predictor estimate sample */
+        int             y;      /* quantizer step size */
+        int             i;      /* decoder input code */
+        int             sign;
+        short           *qtab;
+#endif
 {
-	unsigned char	sp;	/* A-law compressed 8-bit code */
-	short		dx;	/* prediction error */
-	char		id;	/* quantized prediction error */
-	int		sd;	/* adjusted A-law decoded sample value */
-	int		im;	/* biased magnitude of i */
-	int		imx;	/* biased magnitude of id */
+        unsigned char   sp;     /* A-law compressed 8-bit code */
+        short           dx;     /* prediction error */
+        char            id;     /* quantized prediction error */
+        int             sd;     /* adjusted A-law decoded sample value */
+        int             im;     /* biased magnitude of i */
+        int             imx;    /* biased magnitude of id */
 
-	if (sr <= -32768L)
-		sr = -1;
-	sp = st_13linear2alaw(((sr >> 1) << 3));/* short to A-law compression */
-	dx = (st_alaw2linear16(sp) >> 2) - se;	/* 16-bit prediction error */
-	id = quantize(dx, y, qtab, sign - 1);
+        if (sr <= -32768L)
+                sr = -1;
+        sp = st_13linear2alaw(((sr >> 1) << 3));/* short to A-law compression */
+        dx = (st_alaw2linear16(sp) >> 2) - se;  /* 16-bit prediction error */
+        id = quantize(dx, y, qtab, sign - 1);
 
-	if (id == i) {			/* no adjustment on sp */
-		return (sp);
-	} else {			/* sp adjustment needed */
-		/* ADPCM codes : 8, 9, ... F, 0, 1, ... , 6, 7 */
-		im = i ^ sign;		/* 2's complement to biased unsigned */
-		imx = id ^ sign;
+        if (id == i) {                  /* no adjustment on sp */
+                return (sp);
+        } else {                        /* sp adjustment needed */
+                /* ADPCM codes : 8, 9, ... F, 0, 1, ... , 6, 7 */
+                im = i ^ sign;          /* 2's complement to biased unsigned */
+                imx = id ^ sign;
 
-		if (imx > im) {		/* sp adjusted to next lower value */
-			if (sp & 0x80) {
-				sd = (sp == 0xD5) ? 0x55 :
-				    ((sp ^ 0x55) - 1) ^ 0x55;
-			} else {
-				sd = (sp == 0x2A) ? 0x2A :
-				    ((sp ^ 0x55) + 1) ^ 0x55;
-			}
-		} else {		/* sp adjusted to next higher value */
-			if (sp & 0x80)
-				sd = (sp == 0xAA) ? 0xAA :
-				    ((sp ^ 0x55) + 1) ^ 0x55;
-			else
-				sd = (sp == 0x55) ? 0xD5 :
-				    ((sp ^ 0x55) - 1) ^ 0x55;
-		}
-		return (sd);
-	}
-}
+                if (imx > im) {         /* sp adjusted to next lower value */
+                        if (sp & 0x80) {
+                                sd = (sp == 0xD5) ? 0x55 :
+                                    ((sp ^ 0x55) - 1) ^ 0x55;
+                        } else {
+                                sd = (sp == 0x2A) ? 0x2A :
+                                    ((sp ^ 0x55) + 1) ^ 0x55;
+                        }
+                } else {                /* sp adjusted to next higher value */
+                        if (sp & 0x80)
+                                sd = (sp == 0xAA) ? 0xAA :
+                                    ((sp ^ 0x55) + 1) ^ 0x55;
+                        else
+                                sd = (sp == 0x55) ? 0xD5 :
+                                    ((sp ^ 0x55) - 1) ^ 0x55;
+                }
+                return (sd);
+        }
+}
 
-int
-tandem_adjust_ulaw(sr, se, y, i, sign, qtab)
-	int		sr;	/* decoder output linear PCM sample */
-	int		se;	/* predictor estimate sample */
-	int		y;	/* quantizer step size */
-	int		i;	/* decoder input code */
-	int		sign;
-	short		*qtab;
+int tandem_adjust_ulaw(int sr, int se, int y, int i, int sign, short *qtab)
+#if 0
+        int             sr;     /* decoder output linear PCM sample */
+        int             se;     /* predictor estimate sample */
+        int             y;      /* quantizer step size */
+        int             i;      /* decoder input code */
+        int             sign;
+        short           *qtab;
+#endif
 {
-	unsigned char	sp;	/* u-law compressed 8-bit code */
-	short		dx;	/* prediction error */
-	char		id;	/* quantized prediction error */
-	int		sd;	/* adjusted u-law decoded sample value */
-	int		im;	/* biased magnitude of i */
-	int		imx;	/* biased magnitude of id */
+        unsigned char   sp;     /* u-law compressed 8-bit code */
+        short           dx;     /* prediction error */
+        char            id;     /* quantized prediction error */
+        int             sd;     /* adjusted u-law decoded sample value */
+        int             im;     /* biased magnitude of i */
+        int             imx;    /* biased magnitude of id */
 
-	if (sr <= -32768L)
-		sr = 0;
-	sp = st_14linear2ulaw((sr << 2));/* short to u-law compression */
-	dx = (st_ulaw2linear16(sp) >> 2) - se;	/* 16-bit prediction error */
-	id = quantize(dx, y, qtab, sign - 1);
-	if (id == i) {
-		return (sp);
-	} else {
-		/* ADPCM codes : 8, 9, ... F, 0, 1, ... , 6, 7 */
-		im = i ^ sign;		/* 2's complement to biased unsigned */
-		imx = id ^ sign;
-		if (imx > im) {		/* sp adjusted to next lower value */
-			if (sp & 0x80)
-				sd = (sp == 0xFF) ? 0x7E : sp + 1;
-			else
-				sd = (sp == 0) ? 0 : sp - 1;
+        if (sr <= -32768L)
+                sr = 0;
+        sp = st_14linear2ulaw((sr << 2));/* short to u-law compression */
+        dx = (st_ulaw2linear16(sp) >> 2) - se;  /* 16-bit prediction error */
+        id = quantize(dx, y, qtab, sign - 1);
+        if (id == i) {
+                return (sp);
+        } else {
+                /* ADPCM codes : 8, 9, ... F, 0, 1, ... , 6, 7 */
+                im = i ^ sign;          /* 2's complement to biased unsigned */
+                imx = id ^ sign;
+                if (imx > im) {         /* sp adjusted to next lower value */
+                        if (sp & 0x80)
+                                sd = (sp == 0xFF) ? 0x7E : sp + 1;
+                        else
+                                sd = (sp == 0) ? 0 : sp - 1;
 
-		} else {		/* sp adjusted to next higher value */
-			if (sp & 0x80)
-				sd = (sp == 0x80) ? 0x80 : sp - 1;
-			else
-				sd = (sp == 0x7F) ? 0xFE : sp + 1;
-		}
-		return (sd);
-	}
+                } else {                /* sp adjusted to next higher value */
+                        if (sp & 0x80)
+                                sd = (sp == 0x80) ? 0x80 : sp - 1;
+                        else
+                                sd = (sp == 0x7F) ? 0xFE : sp + 1;
+                }
+                return (sd);
+        }
 }
--- a/src/gsm.c
+++ b/src/gsm.c
@@ -44,57 +44,57 @@
 
 /* Private data */
 struct gsmpriv {
-	int		channels;
-	gsm_signal	*samples;
-	gsm_signal	*samplePtr;
-	gsm_signal	*sampleTop;
-	gsm_byte *frames;
-	gsm		handle[MAXCHANS];
+        int             channels;
+        gsm_signal      *samples;
+        gsm_signal      *samplePtr;
+        gsm_signal      *sampleTop;
+        gsm_byte *frames;
+        gsm             handle[MAXCHANS];
 };
 
 static int gsmstart_rw(ft_t ft, int w) 
 {
-	struct gsmpriv *p = (struct gsmpriv *) ft->priv;
-	int ch;
-	
-	ft->info.encoding = ST_ENCODING_GSM;
-	ft->info.size = ST_SIZE_BYTE;
-	if (!ft->info.rate)
-		ft->info.rate = 8000;
+        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        int ch;
+        
+        ft->info.encoding = ST_ENCODING_GSM;
+        ft->info.size = ST_SIZE_BYTE;
+        if (!ft->info.rate)
+                ft->info.rate = 8000;
 
-	if (ft->info.channels == -1)
-	    ft->info.channels = 1;
+        if (ft->info.channels == -1)
+            ft->info.channels = 1;
 
-	p->channels = ft->info.channels;
-	if (p->channels > MAXCHANS || p->channels <= 0)
-	{
-		st_fail_errno(ft,ST_EFMT,"gsm: channels(%d) must be in 1-16", ft->info.channels);
-		return(ST_EOF);
-	}
+        p->channels = ft->info.channels;
+        if (p->channels > MAXCHANS || p->channels <= 0)
+        {
+                st_fail_errno(ft,ST_EFMT,"gsm: channels(%d) must be in 1-16", ft->info.channels);
+                return(ST_EOF);
+        }
 
-	for (ch=0; ch<p->channels; ch++) {
-		p->handle[ch] = gsm_create();
-		if (!p->handle[ch])
-		{
-			st_fail_errno(ft,errno,"unable to create GSM stream");
-			return (ST_EOF);
-		}
-	}
-	p->frames = (gsm_byte*) malloc(p->channels*FRAMESIZE);
-	p->samples = (gsm_signal*) malloc(BLOCKSIZE * (p->channels+1) * sizeof(gsm_signal));
-	p->sampleTop = p->samples + BLOCKSIZE*p->channels;
-	p->samplePtr = (w)? p->samples : p->sampleTop;
-	return (ST_SUCCESS);
-}
+        for (ch=0; ch<p->channels; ch++) {
+                p->handle[ch] = gsm_create();
+                if (!p->handle[ch])
+                {
+                        st_fail_errno(ft,errno,"unable to create GSM stream");
+                        return (ST_EOF);
+                }
+        }
+        p->frames = (gsm_byte*) malloc(p->channels*FRAMESIZE);
+        p->samples = (gsm_signal*) malloc(BLOCKSIZE * (p->channels+1) * sizeof(gsm_signal));
+        p->sampleTop = p->samples + BLOCKSIZE*p->channels;
+        p->samplePtr = (w)? p->samples : p->sampleTop;
+        return (ST_SUCCESS);
+}
 
 int st_gsmstartread(ft_t ft) 
 {
-	return gsmstart_rw(ft,0);
+        return gsmstart_rw(ft,0);
 }
 
 int st_gsmstartwrite(ft_t ft)
 {
-	return gsmstart_rw(ft,1);
+        return gsmstart_rw(ft,1);
 }
 
 /*
@@ -106,130 +106,130 @@
 
 st_ssize_t st_gsmread(ft_t ft, st_sample_t *buf, st_ssize_t samp)
 {
-	int done = 0;
-	int r, ch, chans;
-	gsm_signal *gbuff;
-	struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        int done = 0;
+        int r, ch, chans;
+        gsm_signal *gbuff;
+        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
 
-	chans = p->channels;
+        chans = p->channels;
 
-	while (done < samp)
-	{
-		while (p->samplePtr < p->sampleTop && done < samp)
-			buf[done++] = 
-			    ST_SIGNED_WORD_TO_SAMPLE(*(p->samplePtr)++);
+        while (done < samp)
+        {
+                while (p->samplePtr < p->sampleTop && done < samp)
+                        buf[done++] = 
+                            ST_SIGNED_WORD_TO_SAMPLE(*(p->samplePtr)++);
 
-		if (done>=samp) break;
+                if (done>=samp) break;
 
-		r = fread(p->frames, p->channels*FRAMESIZE, 1, ft->fp);
-		if (r != 1) break;
+                r = st_read(ft, p->frames, p->channels*FRAMESIZE, 1);
+                if (r != 1) break;
 
-		p->samplePtr = p->samples;
-		for (ch=0; ch<chans; ch++) {
-			int i;
-			gsm_signal *gsp;
+                p->samplePtr = p->samples;
+                for (ch=0; ch<chans; ch++) {
+                        int i;
+                        gsm_signal *gsp;
 
-			gbuff = p->sampleTop;
-			if (gsm_decode(p->handle[ch], p->frames + ch*FRAMESIZE, gbuff) < 0)
-			{
-				st_fail_errno(ft,errno,"error during GSM decode");
-				return (0);
-			}
-			
-			gsp = p->samples + ch;
-			for (i=0; i<BLOCKSIZE; i++) {
-				*gsp = *gbuff++;
-				gsp += chans;
-			}
-		}
-	}
+                        gbuff = p->sampleTop;
+                        if (gsm_decode(p->handle[ch], p->frames + ch*FRAMESIZE, gbuff) < 0)
+                        {
+                                st_fail_errno(ft,errno,"error during GSM decode");
+                                return (0);
+                        }
+                        
+                        gsp = p->samples + ch;
+                        for (i=0; i<BLOCKSIZE; i++) {
+                                *gsp = *gbuff++;
+                                gsp += chans;
+                        }
+                }
+        }
 
-	return done;
+        return done;
 }
 
 static int gsmflush(ft_t ft)
 {
-	int r, ch, chans;
-	gsm_signal *gbuff;
-	struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        int r, ch, chans;
+        gsm_signal *gbuff;
+        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
 
-	chans = p->channels;
+        chans = p->channels;
 
-	/* zero-fill samples as needed */
-	while (p->samplePtr < p->sampleTop)
-		*(p->samplePtr)++ = 0;
-	
-	gbuff = p->sampleTop;
-	for (ch=0; ch<chans; ch++) {
-		int i;
-		gsm_signal *gsp;
+        /* zero-fill samples as needed */
+        while (p->samplePtr < p->sampleTop)
+                *(p->samplePtr)++ = 0;
+        
+        gbuff = p->sampleTop;
+        for (ch=0; ch<chans; ch++) {
+                int i;
+                gsm_signal *gsp;
 
-		gsp = p->samples + ch;
-		for (i=0; i<BLOCKSIZE; i++) {
-			gbuff[i] = *gsp;
-			gsp += chans;
-		}
-		gsm_encode(p->handle[ch], gbuff, p->frames);
-		r = fwrite(p->frames, FRAMESIZE, 1, ft->fp);
-		if (r != 1)
-		{
-			st_fail_errno(ft,errno,"write error");
-			return(ST_EOF);
-		}
-	}
-	p->samplePtr = p->samples;
+                gsp = p->samples + ch;
+                for (i=0; i<BLOCKSIZE; i++) {
+                        gbuff[i] = *gsp;
+                        gsp += chans;
+                }
+                gsm_encode(p->handle[ch], gbuff, p->frames);
+                r = st_write(ft, p->frames, FRAMESIZE, 1);
+                if (r != 1)
+                {
+                        st_fail_errno(ft,errno,"write error");
+                        return(ST_EOF);
+                }
+        }
+        p->samplePtr = p->samples;
 
-	return (ST_SUCCESS);
+        return (ST_SUCCESS);
 }
 
 st_ssize_t st_gsmwrite(ft_t ft, st_sample_t *buf, st_ssize_t samp)
 {
-	int done = 0;
-	struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        int done = 0;
+        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
 
-	while (done < samp)
-	{
-		while ((p->samplePtr < p->sampleTop) && (done < samp))
-			*(p->samplePtr)++ = 
-			    ST_SAMPLE_TO_SIGNED_WORD(buf[done++]);
+        while (done < samp)
+        {
+                while ((p->samplePtr < p->sampleTop) && (done < samp))
+                        *(p->samplePtr)++ = 
+                            ST_SAMPLE_TO_SIGNED_WORD(buf[done++]);
 
-		if (p->samplePtr == p->sampleTop)
-		{
-			if(gsmflush(ft))
-			{
-			    return 0;
-			}
-		}
-	}
+                if (p->samplePtr == p->sampleTop)
+                {
+                        if(gsmflush(ft))
+                        {
+                            return 0;
+                        }
+                }
+        }
 
-	return done;
+        return done;
 }
 
 int st_gsmstopread(ft_t ft)
 {
-	struct gsmpriv *p = (struct gsmpriv *) ft->priv;
-	int ch;
+        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        int ch;
 
-	for (ch=0; ch<p->channels; ch++)
-		gsm_destroy(p->handle[ch]);
+        for (ch=0; ch<p->channels; ch++)
+                gsm_destroy(p->handle[ch]);
 
-	free(p->samples);
-	free(p->frames);
-	return (ST_SUCCESS);
+        free(p->samples);
+        free(p->frames);
+        return (ST_SUCCESS);
 }
 
 int st_gsmstopwrite(ft_t ft)
 {
-    	int rc;
-	struct gsmpriv *p = (struct gsmpriv *) ft->priv;
+        int rc;
+        struct gsmpriv *p = (struct gsmpriv *) ft->priv;
 
-	if (p->samplePtr > p->samples)
-	{
-		rc = gsmflush(ft);
-		if (rc)
-		    return rc;
-	}
+        if (p->samplePtr > p->samples)
+        {
+                rc = gsmflush(ft);
+                if (rc)
+                    return rc;
+        }
 
-	return st_gsmstopread(ft); /* destroy handles and free buffers */
+        return st_gsmstopread(ft); /* destroy handles and free buffers */
 }
 #endif /* ENABLE_GSM */
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -204,7 +204,7 @@
         while (p->huffcount > 0) {
                 if(p->nrbits == 0) {
                         st_readdw(ft, &(p->current));
-                        if (feof(ft->fp))
+                        if (st_eof(ft))
                         {
                                 st_fail_errno(ft,ST_EOF,"unexpected EOF in HCOM data");
                                 return (0);
@@ -531,7 +531,7 @@
         int rc;
 
         /* Compress it all at once */
-        rc = compress(&compressed_data, (uint32_t *)&compressed_len, (double) ft->info.rate);
+        rc = compress(&compressed_data, (int32_t *)&compressed_len, (double) ft->info.rate);
         free((char *) p->data);
 
         if (rc){
@@ -540,7 +540,7 @@
         }
 
         /* Write the header */
-        fwrite("\000\001A", 1, 3, ft->fp); /* Dummy file name "A" */
+        st_write(ft, (void *)"\000\001A", 1, 3); /* Dummy file name "A" */
         padbytes(ft, 65-3);
         st_writes(ft, "FSSD");
         padbytes(ft, 83-69);
@@ -547,7 +547,7 @@
         st_writedw(ft, (uint32_t) compressed_len); /* compressed_data size */
         st_writedw(ft, (uint32_t) 0); /* rsrc size */
         padbytes(ft, 128 - 91);
-        if (ferror(ft->fp))
+        if (st_error(ft))
         {
                 st_fail_errno(ft,errno,"write error in HCOM header");
                 return (ST_EOF);
@@ -554,7 +554,7 @@
         }
 
         /* Write the compressed_data fork */
-        if (fwrite((char *) compressed_data, 1, (int)compressed_len, ft->fp) != compressed_len)
+        if (st_write(ft, compressed_data, 1, (int)compressed_len) != compressed_len)
         {
                 st_fail_errno(ft,errno,"can't write compressed HCOM data");
                 rc = ST_EOF;
--- a/src/highpass.c
+++ b/src/highpass.c
@@ -37,10 +37,7 @@
 #include "btrworth.h"
 
 
-int st_highpass_getopts (effp, n, argv) 
-eff_t effp;
-int n;
-char **argv;
+int st_highpass_getopts(eff_t effp, int n, char **argv) 
 {
   butterworth_t butterworth = (butterworth_t)effp->priv;
 
@@ -60,8 +57,7 @@
 
 
 
-int st_highpass_start (effp)
-eff_t effp;
+int st_highpass_start(eff_t effp)
 {
   butterworth_t butterworth = (butterworth_t) effp->priv;
   double c;
--- a/src/lowpass.c
+++ b/src/lowpass.c
@@ -24,10 +24,7 @@
 #include "st_i.h"
 #include "btrworth.h"
 
-int st_lowpass_getopts (effp, n, argv)
-eff_t effp;
-int n;
-char **argv;
+int st_lowpass_getopts(eff_t effp, int n, char **argv)
 {
   butterworth_t butterworth = (butterworth_t)effp->priv;
 
@@ -45,8 +42,7 @@
   return (ST_SUCCESS);
 }
 
-int st_lowpass_start (effp)
-eff_t effp;
+int st_lowpass_start(eff_t effp)
 {
   butterworth_t butterworth = (butterworth_t) effp->priv;
   double c;
--- a/src/maud.c
+++ b/src/maud.c
@@ -189,8 +189,8 @@
                             st_fail_errno(ft,ST_ENOMEM,"Couldn't alloc resources");
                             return(ST_EOF);
                         }
-                        if (fread(chunk_buf,1,(int)chunksize,ft->fp) 
-                                        != chunksize)
+                        if (st_read(ft, chunk_buf, 1, (int)chunksize) 
+                            != chunksize)
                         {
                                 st_fail_errno(ft,ST_EOF,"MAUD: Unexpected EOF in ANNO header");
                                 return(ST_EOF);
@@ -206,7 +206,7 @@
                 st_readdw(ft, &chunksize);
                 if (chunksize & 1)
                         chunksize++;
-                fseek(ft->fp,chunksize,SEEK_CUR);
+                st_seek(ft, chunksize, SEEK_CUR);
                 continue;
                 
         }
@@ -304,7 +304,7 @@
 
         /* All samples are already written out. */
         
-        if (fseek(ft->fp, 0L, 0) != 0) 
+        if (st_seek(ft, 0L, 0) != 0) 
         {
             st_fail_errno(ft,errno,"can't rewind output file to rewrite MAUD header");
             return(ST_EOF);
--- a/src/mcompand.c
+++ b/src/mcompand.c
@@ -72,12 +72,14 @@
  *   there's a higher subsequent peak visible in the lookahead window)
  *   once it's reached.  */
 
-typedef struct butterworth_crossover {
-  struct xy {
+struct xy {
     double x [2];
     double y [2];
-  } *xy_low, *xy_high;
+} ;
 
+typedef struct butterworth_crossover {
+  struct xy *xy_low, *xy_high;
+
   double a_low[3], a_high[3];
   double b_low[2], b_high[3];
 
@@ -259,14 +261,14 @@
       }
 
       rates = 1 + commas/2;
-      if ((l->attackRate = malloc(sizeof(double) * rates)) == NULL ||
-          (l->decayRate  = malloc(sizeof(double) * rates)) == NULL)
+      if ((l->attackRate = (double *)malloc(sizeof(double) * rates)) == NULL ||
+          (l->decayRate  = (double *)malloc(sizeof(double) * rates)) == NULL)
       {
         st_fail("Out of memory");
         return (ST_EOF);
       }
 
-      if ((l->volume = malloc(sizeof(double) * rates)) == NULL)
+      if ((l->volume = (double *)malloc(sizeof(double) * rates)) == NULL)
       {
         st_fail("Out of memory");
         return (ST_EOF);
@@ -300,8 +302,8 @@
       }
 
       tfers = 3 + commas/2; /* 0, 0 at start; 1, 1 at end */
-      if ((l->transferIns  = malloc(sizeof(double) * tfers)) == NULL ||
-          (l->transferOuts = malloc(sizeof(double) * tfers)) == NULL)
+      if ((l->transferIns  = (double *)malloc(sizeof(double) * tfers)) == NULL ||
+          (l->transferOuts = (double *)malloc(sizeof(double) * tfers)) == NULL)
       {
         st_fail("Out of memory");
         return (ST_EOF);
@@ -469,7 +471,7 @@
 
     /* Allocate the delay buffer */
     if (c->delay_buf_size > 0) {
-      if ((l->delay_buf = malloc(sizeof(long) * c->delay_buf_size)) == NULL) {
+      if ((l->delay_buf = (st_sample_t *)malloc(sizeof(long) * c->delay_buf_size)) == NULL) {
         st_fail("Out of memory");
         return (ST_EOF);
       }
--- a/src/mp3.c
+++ b/src/mp3.c
@@ -82,13 +82,13 @@
         struct mp3priv *p = (struct mp3priv *) ft->priv;
         size_t ReadSize;
 
-        p->Stream=malloc(sizeof(struct mad_stream));
+        p->Stream=(struct mad_stream *)malloc(sizeof(struct mad_stream));
         if (p->Stream == NULL){
           st_fail_errno(ft, ST_ENOMEM, "Could not allocate memory");
           return ST_EOF;
         }
         
-        p->Frame=malloc(sizeof(struct mad_frame));
+        p->Frame=(struct mad_frame *)malloc(sizeof(struct mad_frame));
         if (p->Frame == NULL){
           st_fail_errno(ft, ST_ENOMEM, "Could not allocate memory");
           free(p->Stream);
@@ -95,7 +95,7 @@
           return ST_EOF;
         }
         
-        p->Synth=malloc(sizeof(struct mad_synth));
+        p->Synth=(struct mad_synth *)malloc(sizeof(struct mad_synth));
         if (p->Synth == NULL){
           st_fail_errno(ft, ST_ENOMEM, "Could not allocate memory");
           free(p->Stream);
@@ -103,7 +103,7 @@
           return ST_EOF;
         }
         
-        p->Timer=malloc(sizeof(mad_timer_t));
+        p->Timer=(mad_timer_t *)malloc(sizeof(mad_timer_t));
         if (p->Timer == NULL){
           st_fail_errno(ft, ST_ENOMEM, "Could not allocate memory");
           free(p->Stream);
@@ -112,7 +112,7 @@
           return ST_EOF;
         }
         
-        p->InputBuffer=malloc(INPUT_BUFFER_SIZE);
+        p->InputBuffer=(unsigned char *)malloc(INPUT_BUFFER_SIZE);
         if (p->InputBuffer == NULL){
           st_fail_errno(ft, ST_ENOMEM, "Could not allocate memory");
           free(p->Stream);
@@ -133,18 +133,18 @@
         /* We need to decode the first frame,
          * so we know the output format */
 
-        ReadSize=fread(p->InputBuffer,1,INPUT_BUFFER_SIZE,ft->fp);
+        ReadSize=st_read(ft, p->InputBuffer, 1, INPUT_BUFFER_SIZE);
         if(ReadSize<=0)
         {
-                if(ferror(ft->fp))
+                if(st_error(ft))
                         st_fail_errno(ft,ST_EOF,"read error on bitstream");
-                if(feof(ft->fp))
+                if(st_eof(ft))
                         st_fail_errno(ft,ST_EOF,"end of input stream");
                 return(ST_EOF);
         }
         
         mad_stream_buffer(p->Stream,p->InputBuffer,ReadSize);
-        p->Stream->error = 0;
+        p->Stream->error = (mad_error)0;
 
         while(mad_frame_decode(p->Frame,p->Stream)) {
             int tagsize;
@@ -256,7 +256,8 @@
         Remaining=p->Stream->bufend - p->Stream->next_frame;
         memmove(p->InputBuffer,p->Stream->next_frame,Remaining);
 
-        ReadSize=fread(p->InputBuffer+Remaining,1,INPUT_BUFFER_SIZE-Remaining,ft->fp);
+        ReadSize=st_read(ft, p->InputBuffer+Remaining, 1, 
+                         INPUT_BUFFER_SIZE-Remaining);
         if(ReadSize == 0){
           p->eof=1;
           memset(p->InputBuffer+Remaining,0,MAD_BUFFER_GUARD);
@@ -264,7 +265,7 @@
         }
 
         mad_stream_buffer(p->Stream,p->InputBuffer,ReadSize+Remaining);
-        p->Stream->error=0;
+        p->Stream->error = (mad_error)0;
       }
 
     if(mad_frame_decode(p->Frame,p->Stream)){
@@ -417,7 +418,7 @@
   }
 
   mp3buffer_size=1.25*nsamples + 7200;
-  if ( (mp3buffer=malloc(mp3buffer_size)) == NULL){
+  if ( (mp3buffer=(char *)malloc(mp3buffer_size)) == NULL){
     st_fail_errno(ft,ST_ENOMEM,"Memory allocation failed");
     goto end2;
   }
@@ -426,13 +427,13 @@
                                            buffer_l,
                                            buffer_r,
                                            nsamples,
-                                           mp3buffer,
+                                           (unsigned char *)mp3buffer,
                                            mp3buffer_size)) < 0){
     st_fail_errno(ft,ST_EOF,"Encoding failed");
     goto end;
   }
 
-  if (fwrite(mp3buffer, 1, written, ft->fp) < written){
+  if (st_write(ft, mp3buffer, 1, written) < written){
      st_fail_errno(ft,ST_EOF,"File write failed");
      goto end;
   }
@@ -456,10 +457,10 @@
   char mp3buffer[7200];
   int written;
   
-  if ( (written=lame_encode_flush(p->gfp, mp3buffer, 7200)) <0){
+  if ( (written=lame_encode_flush(p->gfp, (unsigned char *)mp3buffer, 7200)) <0){
     st_fail_errno(ft,ST_EOF,"Encoding failed");
   }
-  else if (fwrite(mp3buffer, 1, written, ft->fp) < written){
+  else if (st_write(ft, mp3buffer, 1, written) < written){
     st_fail_errno(ft,ST_EOF,"File write failed");
   }
 
--- a/src/oss.c
+++ b/src/oss.c
@@ -183,7 +183,7 @@
     ft->file.pos = 0;
     ft->file.eof = 0;
 
-    if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
+    if ((ft->file.buf = (char *)malloc(ft->file.size)) == NULL) {
         st_fail_errno(ft,ST_EOF,"Unable to allocate input/output buffer of size %d", ft->file.size);
         return (ST_EOF);
     }
--- a/src/prc.c
+++ b/src/prc.c
@@ -112,7 +112,7 @@
             st_report("PRC must only supports 1 channel.  Overriding");
         ft->info.channels = 1;
 
-        p->dataStart = ftell(ft->fp);
+        p->dataStart = st_tell(ft);
         ft->length = p->length/ft->info.size;
 
         return (ST_SUCCESS);
@@ -187,7 +187,7 @@
             return ST_SUCCESS;
         }
 
-        if (fseek(ft->fp, 0L, 0) != 0)
+        if (st_seek(ft, 0L, 0) != 0)
         {
                 st_fail_errno(ft,errno,"Can't rewind output file to rewrite Psion header.");
                 return(ST_EOF);
--- a/src/raw.c
+++ b/src/raw.c
@@ -114,7 +114,7 @@
 
 int st_rawstartread(ft_t ft)
 {
-    ft->file.buf = malloc(ST_BUFSIZ);
+    ft->file.buf = (char *)malloc(ST_BUFSIZ);
     if (!ft->file.buf)
     {
         st_fail_errno(ft,ST_ENOMEM,"Unable to alloc resources");
@@ -130,7 +130,7 @@
 
 int st_rawstartwrite(ft_t ft)
 {
-    ft->file.buf = malloc(ST_BUFSIZ);
+    ft->file.buf = (char *)malloc(ST_BUFSIZ);
     if (!ft->file.buf)
     {
         st_fail_errno(ft,ST_ENOMEM,"Unable to alloc resources");
@@ -451,7 +451,7 @@
             i = ft->file.count-ft->file.pos;
             ft->file.pos = 0;
 
-            ft->file.count = fread(ft->file.buf+i, 1, ft->file.size-i, ft->fp) ;
+            ft->file.count = st_read(ft, ft->file.buf+i, 1, ft->file.size-i);
             if (ft->file.count != ft->file.size-i)
             {
                 ft->file.eof = 1;
@@ -641,7 +641,7 @@
 
 static void writeflush(ft_t ft)
 {
-        if (fwrite(ft->file.buf, 1, ft->file.pos, ft->fp) != ft->file.pos)
+        if (st_write(ft, ft->file.buf, 1, ft->file.pos) != ft->file.pos)
         {
             ft->file.eof = ST_EOF;
         }
--- a/src/sf.c
+++ b/src/sf.c
@@ -102,7 +102,7 @@
         int rc;
         int samplesize = 0;
 
-        if (fread(&sfhead, 1, sizeof(sfhead), ft->fp) != sizeof(sfhead))
+        if (st_read(ft, &sfhead, 1, sizeof(sfhead)) != sizeof(sfhead))
         {
                 st_fail("unexpected EOF in SF header");
                 return(ST_EOF);
@@ -155,7 +155,7 @@
 /* Need length for seeking */
         if(ft->seekable){
                 ft->length = st_filelength(ft)/samplesize;
-                sf->dataStart = ftell(ft->fp);
+                sf->dataStart = st_tell(ft);
         } else {
                 ft->length = 0;
         }
@@ -216,7 +216,7 @@
         sfcharp = (char *) sfcodep + sizeof(SFCODE);
         while(sfcharp < (char *) &sfhead + SIZEOF_BSD_HEADER)
                 *sfcharp++ = '\0';
-        fwrite(&sfhead, 1, sizeof(SFHEADER), ft->fp);
+        st_write(ft, &sfhead, 1, sizeof(SFHEADER));
 
         return(ST_SUCCESS);
 }
--- a/src/sfircam.h
+++ b/src/sfircam.h
@@ -1,11 +1,11 @@
-/*				SFHEADER.H				*/
+/*                              SFHEADER.H                              */
 
 /* definitions and structures needed for manipulating soundfiles.
  */
 
 #define SIZEOF_HEADER 1024
-#define SF_BUFSIZE	(16*1024) /* used only in play */
-#define SF_MAXCHAN	4
+#define SF_BUFSIZE      (16*1024) /* used only in play */
+#define SF_MAXCHAN      4
 #define MAXCOMM 512
 #define MINCOMM 256
 
@@ -80,23 +80,25 @@
  * sf_magic is for backward compatibility; it should be SF_MAGIC as defined
  * above.
  */
+struct sfinfo {
+    union magic_union {
+        struct {
+            unsigned char sf_magic1;  /* byte 1 of magic */
+            unsigned char sf_magic2;  /* 2 */
+            unsigned char sf_machine; /* 3 */
+            unsigned char sf_param;   /* 4 */
+        } _magic_bytes;
+        uint32_t sf_magic;            /* magic as a 4-byte long */
+    } magic_union;
+    float     sf_srate;
+    uint32_t          sf_chans;
+    uint32_t          sf_packmode;
+    char      sf_codes;
+};
+
 typedef union sfheader {
-	struct sfinfo {
-		union magic_union {
-			struct {
-				unsigned char sf_magic1;  /* byte 1 of magic */
-				unsigned char sf_magic2;  /* 2 */
-				unsigned char sf_machine; /* 3 */
-				unsigned char sf_param;	  /* 4 */
-				} _magic_bytes;
-			uint32_t sf_magic;			  /* magic as a 4-byte long */
-			} magic_union;
-		float	  sf_srate;
-		uint32_t	  sf_chans;
-		uint32_t	  sf_packmode;
-		char	  sf_codes;
-	} sfinfo;
-	char	filler[SIZEOF_HEADER];
+        struct sfinfo sfinfo;
+        char    filler[SIZEOF_HEADER];
 } SFHEADER;
 
 /*
@@ -107,18 +109,18 @@
  * or to retreive such information. See man sfcodes.
  *
  * 10/90 pw
- *	These routines are now part of libcarl/sfcodes.c
+ *      These routines are now part of libcarl/sfcodes.c
  */
 
 typedef struct sfcode {
-	short	code;
-	short	bsize;
+        short   code;
+        short   bsize;
 } SFCODE;
 
 typedef struct Sfmaxamp {
-	float	value[SF_MAXCHAN];
-	uint32_t samploc[SF_MAXCHAN];
-	uint32_t timetag;
+        float   value[SF_MAXCHAN];
+        uint32_t samploc[SF_MAXCHAN];
+        uint32_t timetag;
 } SFMAXAMP;
 
 typedef struct sfcomment {
@@ -127,12 +129,12 @@
 
 typedef struct {                  /* this code written by pvanal */
         short   frameSize;
-	short   frameIncr;
+        short   frameIncr;
 } SFPVDATA;
 
 typedef struct {                  /*     ditto                    */
         short   encoding;
-	short   grouping;
+        short   grouping;
 } SFAUDIOENCOD;
 
 /*
@@ -165,21 +167,21 @@
  */
 /* True if soundfile and good arch */
 #define ismagic(x) ((sfmagic1(x) == SF_MAGIC1) && \
-	(sfmagic2(x) == SF_MAGIC2) && \
-	(sfmachine(x) == SF_MACHINE))
+        (sfmagic2(x) == SF_MAGIC2) && \
+        (sfmachine(x) == SF_MACHINE))
 
 /* True if soundfile */
 #define isforeignmagic(x) ((sfmagic1(x) == SF_MAGIC1) && \
-	(sfmagic2(x) == SF_MAGIC2))
+        (sfmagic2(x) == SF_MAGIC2))
 
 /* True if soundfile */
 #define issoundfile(x)  ((sfmagic1(x) == SF_MAGIC1) && \
-	(sfmagic2(x) == SF_MAGIC2))
+        (sfmagic2(x) == SF_MAGIC2))
 
 /* True if soundfile and foreign arch */
 #define isforeignsoundfile(x) ((sfmagic1(x) == SF_MAGIC1) && \
-	(sfmagic2(x) == SF_MAGIC2) && \
-	(sfmachine(x) != SF_MACHINE))
+        (sfmagic2(x) == SF_MAGIC2) && \
+        (sfmachine(x) != SF_MACHINE))
 
 /* True if foreign arch */
 #define isforeign(x) (sfmachine(x) != SF_MACHINE)
@@ -191,16 +193,16 @@
  */
 
 #define readopensf(name,fd,sfh,sfst,prog,result) \
-	result = (fd = openrosf(name, &sfh, &sfst, prog)) < 0 ? fd : 0;
+        result = (fd = openrosf(name, &sfh, &sfst, prog)) < 0 ? fd : 0;
 
 #define freadopensf(name,fp,sfh,sfst,prog,result) \
-	result = fopenrosf(name, &fp, &sfh, &sfst, prog);
+        result = fopenrosf(name, &fp, &sfh, &sfst, prog);
 
 #define wropensf(name,fd,sfh,prog,result) \
-	result = (fd = openwosf(name, &sfh, prog)) < 0 ? fd : 0;
+        result = (fd = openwosf(name, &sfh, prog)) < 0 ? fd : 0;
 
 #define rdwropensf(name,fd,sfh,sfst,prog,result) \
-	result = (fd = openrwsf(name, &sfh, &sfst, prog)) < 0 ? fd : 0;
+        result = (fd = openrwsf(name, &sfh, &sfst, prog)) < 0 ? fd : 0;
 
 
 /*
--- a/src/silence.c
+++ b/src/silence.c
@@ -116,7 +116,7 @@
          * parse the duration info yet.  So save argument off
          * for future processing.
          */
-        silence->start_duration_str = malloc(strlen(argv[0])+1);
+        silence->start_duration_str = (char *)malloc(strlen(argv[0])+1);
         if (!silence->start_duration_str)
         {
             st_fail("Could not allocate memory");
@@ -177,7 +177,7 @@
          * parse the duration info yet.  So save argument off
          * for future processing.
          */
-        silence->stop_duration_str = malloc(strlen(argv[0])+1);
+        silence->stop_duration_str = (char *)malloc(strlen(argv[0])+1);
         if (!silence->stop_duration_str)
         {
             st_fail("Could not allocate memory");
@@ -299,7 +299,7 @@
         else
             silence->mode = SILENCE_COPY;
 
-        silence->start_holdoff = malloc(sizeof(st_sample_t)*silence->start_duration);
+        silence->start_holdoff = (st_sample_t *)malloc(sizeof(st_sample_t)*silence->start_duration);
         if (!silence->start_holdoff)
         {
             st_fail("Could not allocate memory");
@@ -309,7 +309,7 @@
         silence->start_holdoff_end = 0;
         silence->start_found_periods = 0;
 
-        silence->stop_holdoff = malloc(sizeof(st_sample_t)*silence->stop_duration);
+        silence->stop_holdoff = (st_sample_t *)malloc(sizeof(st_sample_t)*silence->stop_duration);
         if (!silence->stop_holdoff)
         {
             st_fail("Could not allocate memory");
--- a/src/smp.c
+++ b/src/smp.c
@@ -92,7 +92,7 @@
                 ft->loops[i].count = trailer->loops[i].count;
         }
         for(i = 0; i < 8; i++) {        /* read the 8 markers */
-                if (fread(trailer->markers[i].name, 1, 10, ft->fp) != 10)
+                if (st_read(ft, trailer->markers[i].name, 1, 10) != 10)
                 {
                     st_fail_errno(ft,ST_EHDR,"EOF in SMP");
                     return(ST_EOF);
@@ -224,7 +224,7 @@
         }
 
         /* Read SampleVision header */
-        if (fread((char *) &header, 1, HEADERSIZE, ft->fp) != HEADERSIZE)
+        if (st_read(ft, (char *)&header, 1, HEADERSIZE) != HEADERSIZE)
         {
                 st_fail_errno(ft,ST_EHDR,"unexpected EOF in SMP header");
                 return(ST_EOF);
@@ -257,11 +257,11 @@
         /* Extract out the sample size (always intel format) */
         st_readdw(ft, &(smp->NoOfSamps));
         /* mark the start of the sample data */
-        samplestart = ftell(ft->fp);
+        samplestart = st_tell(ft);
 
         /* seek from the current position (the start of sample data) by */
         /* NoOfSamps * 2 */
-        if (fseek(ft->fp, smp->NoOfSamps * 2L, 1) == -1)
+        if (st_seek(ft, smp->NoOfSamps * 2L, 1) == -1)
         {
                 st_fail_errno(ft,errno,"SMP unable to seek to trailer");
                 return(ST_EOF);
@@ -273,7 +273,7 @@
         }
 
         /* seek back to the beginning of the data */
-        if (fseek(ft->fp, samplestart, 0) == -1) 
+        if (st_seek(ft, samplestart, 0) == -1) 
         {
                 st_fail_errno(ft,errno,"SMP unable to seek back to start of sample data");
                 return(ST_EOF);
@@ -384,7 +384,7 @@
         sprintf(header.name, "%-*.*s", NAMELEN, NAMELEN, ft->comment);
 
         /* Write file header */
-        if(fwrite(&header, 1, HEADERSIZE, ft->fp) != HEADERSIZE)
+        if(st_write(ft, &header, 1, HEADERSIZE) != HEADERSIZE)
         {
             st_fail_errno(ft,errno,"SMP: Can't write header completely");
             return(ST_EOF);
@@ -419,7 +419,7 @@
         /* Assign the trailer data */
         settrailer(ft, &trailer, ft->info.rate);
         writetrailer(ft, &trailer);
-        if (fseek(ft->fp, 112, 0) == -1)
+        if (st_seek(ft, 112, 0) == -1)
         {
                 st_fail_errno(ft,errno,"SMP unable to seek back to save size");
                 return(ST_EOF);
--- a/src/sndrtool.c
+++ b/src/sndrtool.c
@@ -84,7 +84,7 @@
          and second word is between 4000 & 25000 then this is sounder sound */
         /* otherwise, its probably raw, not handled here */
 
-        if (fread(buf, 1, 2, ft->fp) != 2)
+        if (st_read(ft, buf, 1, 2) != 2)
         {
                 st_fail_errno(ft,errno,"SND: unexpected EOF");
                 return(ST_EOF);
@@ -98,20 +98,20 @@
                 st_fail_errno(ft,ST_EFMT,"SND: sample rate out of range");
                 return(ST_EOF);
         }
-        fseek(ft->fp,4,SEEK_CUR);
+        st_seek(ft, 4, SEEK_CUR);
         }
         else
         {
         /* sndtool ? */
-        fread(&buf[2], 1, 6, ft->fp);
+        st_read(ft, &buf[2], 1, 6);
         if (strncmp(buf,"SOUND",5))
         {
                 st_fail_errno(ft,ST_EFMT,"SND: unrecognized SND format");
                 return(ST_EOF);
         }
-        fseek(ft->fp,12,SEEK_CUR);
+        st_seek(ft, 12, SEEK_CUR);
         st_readw(ft, &rate);
-        fseek(ft->fp,6,SEEK_CUR);
+        st_seek(ft, 6, SEEK_CUR);
         if (st_reads(ft, buf, 96) == ST_EOF)
         {
                 st_fail_errno(ft,ST_EHDR,"SND: unexpected EOF in SND header");
@@ -120,15 +120,15 @@
         st_report("%s",buf);
         }
 
-ft->info.channels = 1;
-ft->info.rate = rate;
-ft->info.encoding = ST_ENCODING_UNSIGNED;
-ft->info.size = ST_SIZE_BYTE;
+        ft->info.channels = 1;
+        ft->info.rate = rate;
+        ft->info.encoding = ST_ENCODING_UNSIGNED;
+        ft->info.size = ST_SIZE_BYTE;
 
-snd->dataStart = ftell(ft->fp);
-ft->length = st_filelength(ft) - snd->dataStart;
+        snd->dataStart = st_tell(ft);
+        ft->length = st_filelength(ft) - snd->dataStart;
 
-return (ST_SUCCESS);
+        return (ST_SUCCESS);
 }
 
 /*======================================================================*/
@@ -222,7 +222,7 @@
             return rc;
 
         /* fixup file sizes in header */
-        if (fseek(ft->fp, 0L, 0) != 0){
+        if (st_seek(ft, 0L, 0) != 0){
                 st_fail_errno(ft,errno,"can't rewind output file to rewrite SND header");
                 return ST_EOF;
         }
@@ -238,21 +238,21 @@
 /*======================================================================*/
 static void sndtwriteheader(ft_t ft, st_size_t nsamples)
 {
-char name_buf[97];
+    char name_buf[97];
 
-/* sndtool header */
-st_writes(ft, "SOUND"); /* magic */
-st_writeb(ft, 0x1a);
-st_writew (ft,0);  /* hGSound */
-st_writedw (ft,nsamples);
-st_writedw (ft,0);
-st_writedw (ft,nsamples);
-st_writew (ft,(int) ft->info.rate);
-st_writew (ft,0);
-st_writew (ft,10);
-st_writew (ft,4);
-memset (name_buf, 0, 96);
-sprintf (name_buf,"%.62s - File created by Sound Exchange",ft->filename);
-fwrite (name_buf, 1, 96, ft->fp);
+    /* sndtool header */
+    st_writes(ft, "SOUND"); /* magic */
+    st_writeb(ft, 0x1a);
+    st_writew (ft,0);  /* hGSound */
+    st_writedw (ft,nsamples);
+    st_writedw (ft,0);
+    st_writedw (ft,nsamples);
+    st_writew (ft,(int) ft->info.rate);
+    st_writew (ft,0);
+    st_writew (ft,10);
+    st_writew (ft,4);
+    memset (name_buf, 0, 96);
+    sprintf (name_buf,"%.62s - File created by Sound Exchange",ft->filename);
+    st_write(ft, name_buf, 1, 96);
 }
 
--- a/src/sox.c
+++ b/src/sox.c
@@ -178,7 +178,7 @@
         }
         else
         {
-            fo = calloc(sizeof(file_options_t), 1);
+            fo = (file_options_t *)calloc(sizeof(file_options_t), 1);
             fo->info.size = -1;
             fo->info.encoding = -1;
             fo->info.channels = -1;
@@ -969,8 +969,7 @@
     return ST_SUCCESS;
 }
 
-static int flow_effect(e)
-int e;
+static int flow_effect(int e)
 {
     st_ssize_t i, done, idone, odone, idonel, odonel, idoner, odoner;
     st_sample_t *ibuf, *obuf;
@@ -988,7 +987,8 @@
         odone = ST_BUFSIZ;
         effstatus = (* efftab[e].h->flow)(&efftab[e],
                                           &efftab[e-1].obuf[efftab[e-1].odone],
-                                          efftab[e].obuf, &idone, &odone);
+                                          efftab[e].obuf, (st_size_t *)&idone, 
+                                          (st_size_t *)&odone);
         efftab[e-1].odone += idone;
         efftab[e].odone = 0;
         efftab[e].olen = odone;
@@ -1010,7 +1010,8 @@
         idonel = (idone + 1)/2;         /* odd-length logic */
         odonel = odone/2;
         effstatus = (* efftab[e].h->flow)(&efftab[e],
-                                          ibufl, obufl, &idonel, &odonel);
+                                          ibufl, obufl, (st_size_t *)&idonel, 
+                                          (st_size_t *)&odonel);
 
         /* right */
         idoner = idone/2;               /* odd-length logic */
@@ -1017,7 +1018,8 @@
         odoner = odone/2;
         /* FIXME: effstatus of previous operation is lost. */
         effstatus = (* efftabR[e].h->flow)(&efftabR[e],
-                                           ibufr, obufr, &idoner, &odoner);
+                                           ibufr, obufr, (st_size_t *)&idoner, 
+                                           (st_size_t *)&odoner);
 
         obuf = efftab[e].obuf;
          /* This loop implies left and right effect will always output
@@ -1039,8 +1041,7 @@
     return ST_SUCCESS;
 }
 
-static int drain_effect(e)
-int e;
+static int drain_effect(int e)
 {
     st_ssize_t i, olen, olenl, olenr;
     st_sample_t *obuf;
@@ -1057,12 +1058,12 @@
         /* left */
         olenl = olen/2;
         /* FIXME: Should look at return code and abort on ST_EOF */
-        (* efftab[e].h->drain)(&efftab[e], obufl, &olenl);
+        (* efftab[e].h->drain)(&efftab[e], obufl, (st_size_t *)&olenl);
 
         /* right */
         olenr = olen/2;
         /* FIXME: Should look at return code and abort on ST_EOF */
-        (* efftab[e].h->drain)(&efftabR[e], obufr, &olenr);
+        (* efftab[e].h->drain)(&efftabR[e], obufr, (st_size_t *)&olenr);
 
         obuf = efftab[e].obuf;
         /* This loop implies left and right effect will always output
@@ -1294,8 +1295,7 @@
         return clips;
 }
 
-static int filetype(fd)
-int fd;
+static int filetype(int fd)
 {
         struct stat st;
 
@@ -1312,8 +1312,7 @@
 "[ gopts ] [ fopts ] ifile [ fopts ] ofile [ effect [ effopts ] ]";
 #endif
 
-static void usage(opt)
-char *opt;
+static void usage(char *opt)
 {
     int i;
 
--- a/src/speed.c
+++ b/src/speed.c
@@ -132,7 +132,7 @@
     }
     else if (cent != 0) /* CONST==2**(1/1200) */
     {
-        speed->factor = pow(1.00057778950655, speed->factor);
+        speed->factor = pow((double)1.00057778950655, speed->factor);
         /* fprintf(stderr, "Speed factor: %f\n", speed->factor);*/
     }
 
--- a/src/sphere.c
+++ b/src/sphere.c
@@ -18,173 +18,173 @@
 #endif
 /* Private data for SKEL file */
 typedef struct spherestuff {
-	char	  shorten_check[4];
-	st_size_t numSamples;
+        char      shorten_check[4];
+        st_size_t numSamples;
 } *sphere_t;
 
 /*
  * Do anything required before you start reading samples.
  * Read file header. 
- *	Find out sampling rate, 
- *	size and encoding of samples, 
- *	mono/stereo/quad.
+ *      Find out sampling rate, 
+ *      size and encoding of samples, 
+ *      mono/stereo/quad.
  */
 int st_spherestartread(ft_t ft) 
 {
-	sphere_t sphere = (sphere_t) ft->priv;
-	int rc;
-	char *buf;
-	char fldname[64], fldtype[16], fldsval[128];
-	int i;
-	int header_size, bytes_read;
-	long rate;
+        sphere_t sphere = (sphere_t) ft->priv;
+        int rc;
+        char *buf;
+        char fldname[64], fldtype[16], fldsval[128];
+        int i;
+        int header_size, bytes_read;
+        long rate;
 
-	/* Needed for rawread() */
-	rc = st_rawstartread(ft);
-	if (rc)
-	    return rc;
+        /* Needed for rawread() */
+        rc = st_rawstartread(ft);
+        if (rc)
+            return rc;
 
-	/* Magic header */
-	if (st_reads(ft, fldname, 8) == ST_EOF || strncmp(fldname, "NIST_1A", 7) != 0)
-	{
-	    st_fail_errno(ft,ST_EHDR,"Sphere header does not begin with magic mord 'NIST_1A'");
-	    return(ST_EOF);
-	}
+        /* Magic header */
+        if (st_reads(ft, fldname, 8) == ST_EOF || strncmp(fldname, "NIST_1A", 7) != 0)
+        {
+            st_fail_errno(ft,ST_EHDR,"Sphere header does not begin with magic mord 'NIST_1A'");
+            return(ST_EOF);
+        }
 
-	if (st_reads(ft, fldsval, 8) == ST_EOF)
-	{
-	    st_fail_errno(ft,ST_EHDR,"Error reading Sphere header");
-	    return(ST_EOF);
-	}
+        if (st_reads(ft, fldsval, 8) == ST_EOF)
+        {
+            st_fail_errno(ft,ST_EHDR,"Error reading Sphere header");
+            return(ST_EOF);
+        }
 
-	/* Determine header size, and allocate a buffer large enough to hold it. */
-	sscanf(fldsval, "%d", &header_size);
-	buf = (char *)malloc(header_size);
-	if (buf == NULL)
-	{
-	    st_fail_errno(ft,ST_ENOMEM,"Unable to allocate memory");
-	    return(ST_ENOMEM);
-	}
+        /* Determine header size, and allocate a buffer large enough to hold it. */
+        sscanf(fldsval, "%d", &header_size);
+        buf = (char *)malloc(header_size);
+        if (buf == NULL)
+        {
+            st_fail_errno(ft,ST_ENOMEM,"Unable to allocate memory");
+            return(ST_ENOMEM);
+        }
 
-	/* Skip what we have read so far */
-	header_size -= 16;
+        /* Skip what we have read so far */
+        header_size -= 16;
 
-	if (st_reads(ft, buf, header_size) == ST_EOF)
-	{
-	    st_fail_errno(ft,ST_EHDR,"Error reading Sphere header");
-	    free(buf);
-	    return(ST_EOF);
-	}
+        if (st_reads(ft, buf, header_size) == ST_EOF)
+        {
+            st_fail_errno(ft,ST_EHDR,"Error reading Sphere header");
+            free(buf);
+            return(ST_EOF);
+        }
 
-	header_size -= (strlen(buf) + 1);
+        header_size -= (strlen(buf) + 1);
 
-	while (strncmp(buf, "end_head", 8) != 0)
-	{
-	    if (strncmp(buf, "sample_n_bytes", 14) == 0 && ft->info.size == -1)
-	    {
-		sscanf(buf, "%s %s %d", fldname, fldtype, &i);
-		ft->info.size = i;
-	    }
-	    if (strncmp(buf, "channel_count", 13) == 0 && 
-		ft->info.channels == -1)
-	    {
-		sscanf(buf, "%s %s %d", fldname, fldtype, &i);
-		ft->info.channels = i;
-	    }
-	    if (strncmp(buf, "sample_coding", 13) == 0)
-	    {
-		sscanf(buf, "%s %s %s", fldname, fldtype, fldsval);
-		/* Only bother looking for ulaw flag.  All others
-		 * should be caught below by default PCM check
-		 */
-		if (ft->info.encoding == -1 && 
-		    strncmp(fldsval,"ulaw",4) == 0)
-		{
-		    ft->info.encoding = ST_ENCODING_ULAW;
-		}
-	    }
-	    if (strncmp(buf, "sample_rate ", 12) == 0 &&
-		ft->info.rate == 0)
-	    {
-		sscanf(buf, "%s %s %ld", fldname, fldtype, &rate);
-		ft->info.rate = rate;
-	    }
-	    if (strncmp(buf, "sample_byte_format", 18) == 0)
-	    {
-		sscanf(buf, "%s %s %s", fldname, fldtype, fldsval);
-		if (strncmp(fldsval,"01",2) == 0)
-		{
-		    /* Data is in little endian. */
-		    if (ST_IS_BIGENDIAN)
-		    {
-			ft->swap = ft->swap ? 0 : 1;
-		    }
-		}
-		else if (strncmp(fldsval,"10",2) == 0)
-		{
-		    /* Data is in big endian. */
-		    if (ST_IS_LITTLEENDIAN)
-		    {
-			ft->swap = ft->swap ? 0 : 1;
-		    }
-		}
-	    }
+        while (strncmp(buf, "end_head", 8) != 0)
+        {
+            if (strncmp(buf, "sample_n_bytes", 14) == 0 && ft->info.size == -1)
+            {
+                sscanf(buf, "%s %s %d", fldname, fldtype, &i);
+                ft->info.size = i;
+            }
+            if (strncmp(buf, "channel_count", 13) == 0 && 
+                ft->info.channels == -1)
+            {
+                sscanf(buf, "%s %s %d", fldname, fldtype, &i);
+                ft->info.channels = i;
+            }
+            if (strncmp(buf, "sample_coding", 13) == 0)
+            {
+                sscanf(buf, "%s %s %s", fldname, fldtype, fldsval);
+                /* Only bother looking for ulaw flag.  All others
+                 * should be caught below by default PCM check
+                 */
+                if (ft->info.encoding == -1 && 
+                    strncmp(fldsval,"ulaw",4) == 0)
+                {
+                    ft->info.encoding = ST_ENCODING_ULAW;
+                }
+            }
+            if (strncmp(buf, "sample_rate ", 12) == 0 &&
+                ft->info.rate == 0)
+            {
+                sscanf(buf, "%s %s %ld", fldname, fldtype, &rate);
+                ft->info.rate = rate;
+            }
+            if (strncmp(buf, "sample_byte_format", 18) == 0)
+            {
+                sscanf(buf, "%s %s %s", fldname, fldtype, fldsval);
+                if (strncmp(fldsval,"01",2) == 0)
+                {
+                    /* Data is in little endian. */
+                    if (ST_IS_BIGENDIAN)
+                    {
+                        ft->swap = ft->swap ? 0 : 1;
+                    }
+                }
+                else if (strncmp(fldsval,"10",2) == 0)
+                {
+                    /* Data is in big endian. */
+                    if (ST_IS_LITTLEENDIAN)
+                    {
+                        ft->swap = ft->swap ? 0 : 1;
+                    }
+                }
+            }
 
-	    if (st_reads(ft, buf, header_size) == ST_EOF)
-	    {
-	        st_fail_errno(ft,ST_EHDR,"Error reading Sphere header");
-		free(buf);
-	        return(ST_EOF);
-	    }
+            if (st_reads(ft, buf, header_size) == ST_EOF)
+            {
+                st_fail_errno(ft,ST_EHDR,"Error reading Sphere header");
+                free(buf);
+                return(ST_EOF);
+            }
 
-	    header_size -= (strlen(buf) + 1);
-	}
+            header_size -= (strlen(buf) + 1);
+        }
 
-	if (ft->info.size == -1)
-	    ft->info.size = ST_SIZE_BYTE;
+        if (ft->info.size == -1)
+            ft->info.size = ST_SIZE_BYTE;
 
-	/* sample_coding is optional and is PCM if missing.
-	 * This means encoding is signed if size = word or
-	 * unsigned if size = byte.
-	 */
-	if (ft->info.encoding == -1)
-	{
-	    if (ft->info.size == 1)
-		ft->info.encoding = ST_ENCODING_UNSIGNED;
-	    else
-		ft->info.encoding = ST_ENCODING_SIGN2;
-	}
+        /* sample_coding is optional and is PCM if missing.
+         * This means encoding is signed if size = word or
+         * unsigned if size = byte.
+         */
+        if (ft->info.encoding == -1)
+        {
+            if (ft->info.size == 1)
+                ft->info.encoding = ST_ENCODING_UNSIGNED;
+            else
+                ft->info.encoding = ST_ENCODING_SIGN2;
+        }
 
-	while (header_size)
-	{
-	    bytes_read = st_read(ft, buf, ST_SIZE_BYTE, header_size);
-	    if (bytes_read == 0)
-	    {
-		free(buf);
-		return(ST_EOF);
-	    }
-	    header_size -= bytes_read;
-	}
+        while (header_size)
+        {
+            bytes_read = st_read(ft, buf, ST_SIZE_BYTE, header_size);
+            if (bytes_read == 0)
+            {
+                free(buf);
+                return(ST_EOF);
+            }
+            header_size -= bytes_read;
+        }
 
-	sphere->shorten_check[0] = 0;
+        sphere->shorten_check[0] = 0;
 
-	/* TODO: Check first four bytes of data to see if its shorten
-	 * compressed or not.  This data will need to be written to
-	 * buffer during first st_sphereread().
-	 */
+        /* TODO: Check first four bytes of data to see if its shorten
+         * compressed or not.  This data will need to be written to
+         * buffer during first st_sphereread().
+         */
 #if 0
-	st_reads(ft, sphere->shorten_check, 4);
+        st_reads(ft, sphere->shorten_check, 4);
 
-	if (!strcmp(sphere->shorten_check,"ajkg"))
-	{
-	    st_fail_errno(ft,ST_EFMT,"File uses shorten compression, can not handle this.\n");
-	    free(buf);
-	    return(ST_EOF);
-	}
+        if (!strcmp(sphere->shorten_check,"ajkg"))
+        {
+            st_fail_errno(ft,ST_EFMT,"File uses shorten compression, can not handle this.\n");
+            free(buf);
+            return(ST_EOF);
+        }
 #endif
 
-	free(buf);
-	return (ST_SUCCESS);
+        free(buf);
+        return (ST_SUCCESS);
 }
 
 /*
@@ -200,10 +200,10 @@
 
     if (sphere->shorten_check[0])
     {
-	/* TODO: put these 4 bytes into the buffer.  Requires
-	 * knowing how to process ulaw and all version of PCM data size.
-	 */
-	sphere->shorten_check[0] = 0;
+        /* TODO: put these 4 bytes into the buffer.  Requires
+         * knowing how to process ulaw and all version of PCM data size.
+         */
+        sphere->shorten_check[0] = 0;
     }
     return st_rawread(ft, buf, len);
 }
@@ -216,19 +216,19 @@
 
     if (!ft->seekable)
     {
-	st_fail_errno(ft,ST_EOF,"File must be seekable for sphere file output");
-	return (ST_EOF);
+        st_fail_errno(ft,ST_EOF,"File must be seekable for sphere file output");
+        return (ST_EOF);
     }
 
     switch (ft->info.encoding)
     {
-	case ST_ENCODING_ULAW:
-	case ST_ENCODING_SIGN2:
-	case ST_ENCODING_UNSIGNED:
-	    break;
-	default:
-	    st_fail_errno(ft,ST_EFMT,"SPHERE format only supports ulaw and PCM data.");
-	    return(ST_EOF);
+        case ST_ENCODING_ULAW:
+        case ST_ENCODING_SIGN2:
+        case ST_ENCODING_UNSIGNED:
+            break;
+        default:
+            st_fail_errno(ft,ST_EFMT,"SPHERE format only supports ulaw and PCM data.");
+            return(ST_EOF);
     }
 
     sphere->numSamples = 0;
@@ -236,15 +236,15 @@
     /* Needed for rawwrite */
     rc = st_rawstartwrite(ft);
     if (rc)
-	return rc;
+        return rc;
 
     for (x = 0; x < 1024; x++)
     {
-	st_writeb(ft, ' ');
+        st_writeb(ft, ' ');
     }
 
     return(ST_SUCCESS);
-	
+        
 }
 
 st_ssize_t st_spherewrite(ft_t ft, st_sample_t *buf, st_ssize_t len) 
@@ -264,12 +264,12 @@
 
     rc = st_rawstopwrite(ft);
     if (rc)
-	return rc;
+        return rc;
 
-    if (fseek(ft->fp, 0L, 0) != 0)
+    if (st_seek(ft, 0L, 0) != 0)
     {
-	st_fail_errno(ft,errno,"Could not rewird output file to rewrite sphere header.\n");
-	return (ST_EOF);
+        st_fail_errno(ft,errno,"Could not rewird output file to rewrite sphere header.\n");
+        return (ST_EOF);
     }
 
     st_writes(ft, "NIST_1A\n");
@@ -287,11 +287,11 @@
 
     if (ft->swap)
     {
-	sprintf(buf, "sample_byte_format -s2 %s\n", ST_IS_BIGENDIAN ? "01" : "10");
+        sprintf(buf, "sample_byte_format -s2 %s\n", ST_IS_BIGENDIAN ? "01" : "10");
     }
     else
     {
-	sprintf(buf, "sample_byte_format -s2 %s\n", ST_IS_BIGENDIAN ? "10" : "01");
+        sprintf(buf, "sample_byte_format -s2 %s\n", ST_IS_BIGENDIAN ? "10" : "01");
     }
     st_writes(ft, buf);
 
@@ -300,9 +300,9 @@
     st_writes(ft, buf);
 
     if (ft->info.encoding == ST_ENCODING_ULAW)
-	st_writes(ft, "sample_coding -s4 ulaw\n");
+        st_writes(ft, "sample_coding -s4 ulaw\n");
     else
-	st_writes(ft, "sample_coding -s3 pcm\n");
+        st_writes(ft, "sample_coding -s3 pcm\n");
 
     st_writes(ft, "end_head\n");
 
--- a/src/stat.c
+++ b/src/stat.c
@@ -143,8 +143,8 @@
                 return(ST_EOF);
             }
 
-            stat->re = malloc(sizeof(double) * stat->fft_size);
-            stat->im = malloc(sizeof(double) * stat->fft_size);
+            stat->re = (double *)malloc(sizeof(double) * stat->fft_size);
+            stat->im = (double *)malloc(sizeof(double) * stat->fft_size);
 
             if (!stat->re || !stat->im)
             {
--- a/src/synth.c
+++ b/src/synth.c
@@ -178,7 +178,7 @@
  * calculated by freq = 440Hz * 2**(note/12)
  */
 static double calc_note_freq(double note){
-    return (440.0 * pow(2,note/12.0));
+    return (440.0 * pow(2.0,note/12.0));
 }
 
 
@@ -269,7 +269,7 @@
 
     /* read length if given ( if first par starts with digit )*/
     if( isdigit((int)argv[argn][0])) {
-        synth->length_str = malloc(strlen(argv[argn])+1);
+        synth->length_str = (char *)malloc(strlen(argv[argn])+1);
         if (!synth->length_str)
         {
             st_fail("Could not allocate memeory");
--- a/src/trim.c
+++ b/src/trim.c
@@ -46,7 +46,7 @@
      */
     switch (n) {
         case 2:
-            trim->length_str = malloc(strlen(argv[1])+1);
+            trim->length_str = (char *)malloc(strlen(argv[1])+1);
             if (!trim->length_str)
             {
                 st_fail("Could not allocate memory");
@@ -61,7 +61,7 @@
                 return(ST_EOF);
             }
         case 1:
-            trim->start_str = malloc(strlen(argv[0])+1);
+            trim->start_str = (char *)malloc(strlen(argv[0])+1);
             if (!trim->start_str)
             {
                 st_fail("Could not allocate memory");
--- a/src/tx16w.c
+++ b/src/tx16w.c
@@ -97,7 +97,7 @@
     while (st_readb(ft, (unsigned char *)&trash) != ST_EOF)
         num_samp_bytes++; 
     num_samp_bytes -= 32;         /* calculate num samples by sub header size */
-    fseek(ft->fp,0L,0);           /* rewind file */
+    st_seek(ft, 0L, 0);           /* rewind file */
     sk->rest = num_samp_bytes;    /* set how many sample bytes to read */
 
     /* first 6 bytes are file type ID LM8953 */
@@ -271,7 +271,7 @@
     /* dummy numbers, just for place holder, real header is written
        at end of processing, since byte count is needed */
 
-    fwrite(&WH,1,32,ft->fp);
+    st_write(ft, &WH, 1, 32);
     writedone = 32;
     return(ST_SUCCESS);
 }
@@ -370,8 +370,8 @@
     WH.rpt_length[2] = (0x01 & (LoopLength >> 16)) +
         magic2[WH.sample_rate];
 
-    rewind(ft->fp);
-    fwrite(&WH,1,32,ft->fp);
+    st_rewind(ft);
+    st_write(ft, &WH, 1, 32);
 
     return(ST_SUCCESS);
 }
--- a/src/voc.c
+++ b/src/voc.c
@@ -230,7 +230,7 @@
         }
 
 
-        if (fread(header, 1, 20, ft->fp) != 20)
+        if (st_read(ft, header, 1, 20) != 20)
         {
                 st_fail_errno(ft,ST_EHDR,"unexpected EOF in VOC header");
                 return(ST_EOF);
@@ -389,7 +389,7 @@
                     break;
                 case ST_SIZE_WORD:
                     st_readw(ft, (unsigned short *)&sw);
-                    if (feof(ft->fp))
+                    if (st_eof(ft))
                         {
                             st_warn("VOC input: short file");
                             v->rest = 0;
@@ -526,7 +526,7 @@
         while (v->rest == 0) {
                 /* IF EOF, return EOF
                  * ANN:  was returning SUCCESS */
-                if (feof(ft->fp))
+                if (st_eof(ft))
                         return ST_EOF;
 
                 if (st_readb(ft, &block) == ST_EOF)
@@ -538,7 +538,7 @@
 
                 /* IF EOF after reading block type, return EOF
                  * ANN:  was returning SUCCESS */
-                if (feof(ft->fp))
+                if (st_eof(ft))
                         return ST_EOF;
                 /*
                  * Size is an 24-bit value.  Currently there is no util
@@ -738,7 +738,7 @@
 {
         vs_t v = (vs_t) ft->priv;
 
-        v->blockseek = ftell(ft->fp);
+        v->blockseek = st_tell(ft);
         if (v->silent) {
                 st_writeb(ft, VOC_SILENCE);     /* Silence block code */
                 st_writeb(ft, 0);               /* Period length */
@@ -796,15 +796,15 @@
         vs_t v = (vs_t) ft->priv;
         st_sample_t datum;
 
-        st_writeb(ft, 0);                       /* End of file block code */
-        fseek(ft->fp, v->blockseek, 0);         /* seek back to block length */
-        fseek(ft->fp, 1, 1);                    /* seek forward one */
+        st_writeb(ft, 0);                     /* End of file block code */
+        st_seek(ft, v->blockseek, 0);         /* seek back to block length */
+        st_seek(ft, 1, 1);                    /* seek forward one */
         if (v->silent) {
                 st_writew(ft, v->samples);
         } else {
           if (ft->info.size == ST_SIZE_BYTE) {
             if (ft->info.channels > 1) {
-              fseek(ft->fp, 8, 1); /* forward 7 + 1 for new block header */
+              st_seek(ft, 8, 1); /* forward 7 + 1 for new block header */
             }
           }
                 v->samples += 2;                /* adjustment: SBDK pp. 3-5 */
--- a/src/vorbis.c
+++ b/src/vorbis.c
@@ -105,7 +105,7 @@
         
         
         /* Allocate space for decoding structure */
-        vb->vf = malloc(sizeof(OggVorbis_File));
+        vb->vf = (OggVorbis_File *)malloc(sizeof(OggVorbis_File));
         if (vb->vf == NULL) 
         {
             st_fail_errno(ft, ST_ENOMEM, "Could not allocate memory");
@@ -140,7 +140,7 @@
                 for (i = 0; i < vc->comments; i++)
                         comment_size += vc->comment_lengths[i] + 1;
 
-                if ( (ft->comment = calloc(comment_size, sizeof(char))) 
+                if ((ft->comment = (char *)calloc(comment_size, sizeof(char))) 
                      == NULL)
                 {
                         ov_clear(vb->vf);
@@ -168,7 +168,7 @@
 
         /* Setup buffer */
         vb->buf_len = DEF_BUF_LEN;
-        if ( (vb->buf = calloc(vb->buf_len, sizeof(char))) == NULL )
+        if ((vb->buf = (char *)calloc(vb->buf_len, sizeof(char))) == NULL )
         {
                 ov_clear(vb->vf);
                 free(vb->vf);
@@ -270,11 +270,11 @@
 
 /* Write a page of ogg data to a file.  Taken directly from encode.c in 
    oggenc.   Returns the number of bytes written. */
-int oe_write_page(ogg_page *page, FILE *fp)
+int oe_write_page(ogg_page *page, ft_t ft)
 {
         int written;
-        written = fwrite(page->header,1,page->header_len, fp);
-        written += fwrite(page->body,1,page->body_len, fp);
+        written = st_write(ft, page->header,1,page->header_len);
+        written += st_write(ft, page->body,1,page->body_len);
 
         return written;
 }
@@ -293,8 +293,8 @@
         char *comment;
 
         /* Make the comment structure */
-        vc.user_comments = calloc(1, sizeof(char *));
-        vc.comment_lengths = calloc(1, sizeof(int));
+        vc.user_comments = (char **)calloc(1, sizeof(char *));
+        vc.comment_lengths = (int *)calloc(1, sizeof(int));
         vc.comments = 1;
 
         /* We check if there is a FIELD=value pair already in the comment
@@ -301,11 +301,11 @@
          * if not, add one */
         if (strchr(ft->comment,'=') == NULL) 
         {
-            comment = calloc(1,strlen(ft->comment)+strlen("COMMENT=")+1);
+            comment = (char *)calloc(1,strlen(ft->comment)+strlen("COMMENT=")+1);
             strncpy(comment,"COMMENT=",strlen("COMMENT="));
         }
         else
-            comment = calloc(1,strlen(ft->comment)+1);
+            comment = (char *)calloc(1,strlen(ft->comment)+1);
 
         strcat(comment,ft->comment);
 
@@ -326,7 +326,7 @@
         while((result = ogg_stream_flush(&ve->os, &ve->og)))
         {
                 if(!result) break;
-                ret = oe_write_page(&ve->og, ft->fp);
+                ret = oe_write_page(&ve->og, ft);
                 if(!ret)
                 {
                     free(comment);
@@ -345,7 +345,7 @@
         long rate;
 
         /* Allocate memory for all of the structures */
-        ve = vb->vorbis_enc_data = malloc(sizeof(vorbis_enc_t));
+        ve = vb->vorbis_enc_data = (vorbis_enc_t *)malloc(sizeof(vorbis_enc_t));
         if (ve == NULL)
         {
             st_fail_errno(ft, ST_ENOMEM, "Could not allocate memory");
@@ -418,7 +418,7 @@
                         int result = ogg_stream_pageout(&ve->os,&ve->og);
                         if(!result) break;
                         
-                        ret = oe_write_page(&ve->og, ft->fp);
+                        ret = oe_write_page(&ve->og, ft);
                         if(!ret)
                             return (ST_EOF);
 
--- a/src/vox.c
+++ b/src/vox.c
@@ -110,7 +110,7 @@
 
            // ... setup file info
 
-       ft->file.buf = malloc (ST_BUFSIZ);
+       ft->file.buf = (char *)malloc(ST_BUFSIZ);
     
        if (!ft->file.buf)
           { st_fail_errno (ft,ST_ENOMEM,"Unable to allocate internal buffer memory");
@@ -227,7 +227,7 @@
 
            // ... setup file info
 
-       ft->file.buf = malloc (ST_BUFSIZ);
+       ft->file.buf = (char *)malloc(ST_BUFSIZ);
     
        if (!ft->file.buf)
           { st_fail_errno (ft,ST_ENOMEM,"Unable to allocate internal buffer memory");
--- a/src/wav.c
+++ b/src/wav.c
@@ -113,7 +113,7 @@
 #endif
 */
 
-static char *wav_format_str();
+static char *wav_format_str(unsigned wFormatTag);
 
 static int wavwritehdr(ft_t, int);
 
@@ -134,7 +134,7 @@
     int samplesThisBlock;
 
     /* Pull in the packet and check the header */
-    bytesRead = fread(wav->packet,1,wav->blockAlign,ft->fp);
+    bytesRead = st_read(ft, wav->packet, 1, wav->blockAlign);
     samplesThisBlock = wav->samplesPerBlock;
     if (bytesRead < wav->blockAlign) 
     { 
@@ -175,7 +175,7 @@
     const char *errmsg;
 
     /* Pull in the packet and check the header */
-    bytesRead = fread(wav->packet,1,wav->blockAlign,ft->fp);
+    bytesRead = st_read(ft, wav->packet, 1, wav->blockAlign);
     samplesThisBlock = wav->samplesPerBlock;
     if (bytesRead < wav->blockAlign) 
     {
@@ -221,7 +221,7 @@
             ImaBlockMashI(chans, wav->samples, wav->samplesPerBlock, wav->state, wav->packet, 9);
         }
         /* write the compressed packet */
-        if (fwrite(wav->packet, wav->blockAlign, 1, ft->fp) != 1)
+        if (st_write(ft, wav->packet, wav->blockAlign, 1) != 1)
         {
             st_fail_errno(ft,ST_EOF,"write error");
             return (ST_EOF);
@@ -260,7 +260,7 @@
         return (ST_EOF);
     }
 
-    wav->gsmsample=malloc(sizeof(gsm_signal)*160*2);
+    wav->gsmsample=(gsm_signal*)malloc(sizeof(gsm_signal)*160*2);
     if (wav->gsmsample == NULL){
         st_fail_errno(ft,ST_ENOMEM,"error allocating memory for gsm buffer");
         return (ST_EOF);
@@ -293,7 +293,7 @@
   /* read and decode loop, possibly leaving some samples in wav->gsmsample */
     while (done < len) {
         wav->gsmindex=0;
-        bytes = fread(frame,1,65,ft->fp);   
+        bytes = st_read(ft, frame, 1, 65);   
         if (bytes <=0)
             return done;
         if (bytes<65) {
@@ -334,7 +334,7 @@
     gsm_encode(wav->gsmhandle, wav->gsmsample, frame);
     /*encode the odd half long (33 byte) frame */
     gsm_encode(wav->gsmhandle, wav->gsmsample+160, frame+32);
-    if (fwrite(frame, 1, 65, ft->fp) != 65)
+    if (st_write(ft, frame, 1, 65) != 65)
     {
         st_fail_errno(ft,ST_EOF,"write error");
         return (ST_EOF);
@@ -399,6 +399,7 @@
 {
     char magic[5];
     st_ssize_t len;
+    uint32_t tmp_len;
     for (;;)
     {
         if (st_reads(ft, magic, 4) == ST_EOF)
@@ -406,7 +407,8 @@
             st_fail_errno(ft,ST_EHDR,"WAVE file has missing %s chunk", Label);
             return ST_EOF;
         }
-        st_readdw(ft, &len);
+        st_readdw(ft, &tmp_len);
+        len = tmp_len;
         st_report("Chunk %s",magic);
         if (strncmp(Label, magic, 4) == 0)
             break;              /* Found the data chunk */
@@ -828,7 +830,7 @@
     /* findChunk() only returns if chunk was found */
 
         /* Data starts here */
-        wav->dataStart = ftell(ft->fp);
+        wav->dataStart = st_tell(ft);
 
     switch (wav->formatTag)
     {
@@ -910,7 +912,7 @@
             ft->comment = (char*)malloc(256);
             /* Initialize comment to a NULL string */
             ft->comment[0] = 0;
-            while(!feof(ft->fp)){
+            while(!st_eof(ft)){
                 st_reads(ft,magic,4);
                 if(strncmp(magic,"INFO",4) == 0){
                         /*Skip*/
@@ -967,7 +969,7 @@
                 }
             }
         }
-        clearerr(ft->fp);
+        st_clearerr(ft);
         st_seek(ft,wav->dataStart,SEEK_SET);
     }   
     return ST_SUCCESS;
@@ -1575,7 +1577,7 @@
         if (!ft->seekable)
                 return ST_EOF;
 
-        if (fseek(ft->fp, 0L, SEEK_SET) != 0)
+        if (st_seek(ft, 0L, SEEK_SET) != 0)
         {
                 st_fail_errno(ft,ST_EOF,"Can't rewind output file to rewrite .wav header.");
                 return ST_EOF;
--- a/src/wve.c
+++ b/src/wve.c
@@ -123,7 +123,7 @@
             st_report("WVE must only supports 1 channel.  Overriding");
         ft->info.channels = 1;
 
-        p->dataStart = ftell(ft->fp);
+        p->dataStart = st_tell(ft);
         ft->length = p->length/ft->info.size;
 
         return (ST_SUCCESS);
@@ -198,7 +198,7 @@
             return ST_SUCCESS;
         }
 
-        if (fseek(ft->fp, 0L, 0) != 0)
+        if (st_seek(ft, 0L, 0) != 0)
         {
                 st_fail_errno(ft,errno,"Can't rewind output file to rewrite Psion header.");
                 return(ST_EOF);