shithub: sox

Download patch

ref: 3ee5ec9286a35a3cfb726662d905067dbb8c8bad
parent: 0b2ba364d7c36ade7b829a485516815f6e2a2180
author: cbagwell <cbagwell>
date: Tue May 25 21:13:59 EDT 2004

stereo fix for 8svx... Compile warnings for others.

--- a/Changelog
+++ b/Changelog
@@ -14,6 +14,7 @@
   o Modified play.1 man page to not use multiple name lines.  This
     appears to confuse some conversion programs.  Updated sox.1
     man page for typo in reverb option.
+  o Andrew Church fixed problem with header of stereo 8SVX files.
 
 sox-12.17.4
 -----------
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -13,13 +13,13 @@
 #include <stdio.h>
 
 #ifdef HAVE_UNISTD_H
-#include <unistd.h>	/* For SEEK_* defines if not found in stdio */
+#include <unistd.h>     /* For SEEK_* defines if not found in stdio */
 #endif
 
 /* Private data used by writer */
 typedef struct svxpriv {
-	uint32_t nsamples;
-	FILE *ch[4];
+        uint32_t nsamples;
+        FILE *ch[4];
 }*svx_t;
 
 static void svxwriteheader(ft_t, st_ssize_t);
@@ -30,186 +30,186 @@
 
 int st_svxstartread(ft_t ft)
 {
-	svx_t p = (svx_t ) ft->priv;
+        svx_t p = (svx_t ) ft->priv;
 
-	char buf[12];
-	char *chunk_buf;
+        char buf[12];
+        char *chunk_buf;
  
-	uint32_t totalsize;
-	uint32_t chunksize;
+        uint32_t totalsize;
+        uint32_t chunksize;
 
-	uint32_t channels;
-	unsigned short rate;
-	int i;
+        uint32_t channels;
+        unsigned short rate;
+        int i;
 
-	long chan1_pos;
+        long chan1_pos;
 
-	if (! ft->seekable)
-	{
-		st_fail_errno(ft,ST_EINVAL,"8svx input file must be a file, not a pipe");
-		return (ST_EOF);
-	}
-	/* 8svx is in big endian format. Swap whats
-	 * read in on little endian machines.
-	 */
-	if (ST_IS_LITTLEENDIAN)
-	{
-		ft->swap = ft->swap ? 0 : 1;
-	}
+        if (! ft->seekable)
+        {
+                st_fail_errno(ft,ST_EINVAL,"8svx input file must be a file, not a pipe");
+                return (ST_EOF);
+        }
+        /* 8svx is in big endian format. Swap whats
+         * read in on little endian machines.
+         */
+        if (ST_IS_LITTLEENDIAN)
+        {
+                ft->swap = ft->swap ? 0 : 1;
+        }
 
-	rate = 0;
-	channels = 1;
+        rate = 0;
+        channels = 1;
 
-	/* read FORM chunk */
-	if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "FORM", 4) != 0)
-	{
-		st_fail_errno(ft, ST_EHDR, "Header did not begin with magic word 'FORM'");
-		return(ST_EOF);
-	}
-	st_readdw(ft, &totalsize);
-	if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "8SVX", 4) != 0)
-	{
-		st_fail_errno(ft, ST_EHDR, "'FORM' chunk does not specify '8SVX' as type");
-		return(ST_EOF);
-	}
+        /* read FORM chunk */
+        if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "FORM", 4) != 0)
+        {
+                st_fail_errno(ft, ST_EHDR, "Header did not begin with magic word 'FORM'");
+                return(ST_EOF);
+        }
+        st_readdw(ft, &totalsize);
+        if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "8SVX", 4) != 0)
+        {
+                st_fail_errno(ft, ST_EHDR, "'FORM' chunk does not specify '8SVX' as type");
+                return(ST_EOF);
+        }
 
-	/* read chunks until 'BODY' (or end) */
-	while (st_reads(ft, buf, 4) == ST_SUCCESS && strncmp(buf,"BODY",4) != 0) {
-		if (strncmp(buf,"VHDR",4) == 0) {
-			st_readdw(ft, &chunksize);
-			if (chunksize != 20)
-			{
-				st_fail_errno(ft, ST_EHDR, "VHDR chunk has bad size");
-				return(ST_EOF);
-			}
-			fseek(ft->fp,12,SEEK_CUR);
-			st_readw(ft, &rate);
-			fseek(ft->fp,1,SEEK_CUR);
-			fread(buf,1,1,ft->fp);
-			if (buf[0] != 0)
-			{
-				st_fail_errno(ft, ST_EFMT, "Unsupported data compression");
-				return(ST_EOF);
-			}
-			fseek(ft->fp,4,SEEK_CUR);
-			continue;
-		}
+        /* read chunks until 'BODY' (or end) */
+        while (st_reads(ft, buf, 4) == ST_SUCCESS && strncmp(buf,"BODY",4) != 0) {
+                if (strncmp(buf,"VHDR",4) == 0) {
+                        st_readdw(ft, &chunksize);
+                        if (chunksize != 20)
+                        {
+                                st_fail_errno(ft, ST_EHDR, "VHDR chunk has bad size");
+                                return(ST_EOF);
+                        }
+                        fseek(ft->fp,12,SEEK_CUR);
+                        st_readw(ft, &rate);
+                        fseek(ft->fp,1,SEEK_CUR);
+                        fread(buf,1,1,ft->fp);
+                        if (buf[0] != 0)
+                        {
+                                st_fail_errno(ft, ST_EFMT, "Unsupported data compression");
+                                return(ST_EOF);
+                        }
+                        fseek(ft->fp,4,SEEK_CUR);
+                        continue;
+                }
 
-		if (strncmp(buf,"ANNO",4) == 0) {
-			st_readdw(ft, &chunksize);
-			if (chunksize & 1)
-				chunksize++;
-			chunk_buf = (char *) malloc(chunksize + 2);
-			if (chunk_buf == 0)
-			{
-			    st_fail_errno(ft, ST_ENOMEM, "Unable to alloc memory");
-			    return(ST_EOF);
-			}
-			if (fread(chunk_buf,1,(size_t)chunksize,ft->fp) 
-					!= chunksize)
-			{
-				st_fail_errno(ft, ST_EHDR, "Couldn't read all of header");
-				return(ST_EOF);
-			}
-			chunk_buf[chunksize] = '\0';
-			st_report("%s",chunk_buf);
-			free(chunk_buf);
+                if (strncmp(buf,"ANNO",4) == 0) {
+                        st_readdw(ft, &chunksize);
+                        if (chunksize & 1)
+                                chunksize++;
+                        chunk_buf = (char *) malloc(chunksize + 2);
+                        if (chunk_buf == 0)
+                        {
+                            st_fail_errno(ft, ST_ENOMEM, "Unable to alloc memory");
+                            return(ST_EOF);
+                        }
+                        if (fread(chunk_buf,1,(size_t)chunksize,ft->fp) 
+                                        != chunksize)
+                        {
+                                st_fail_errno(ft, ST_EHDR, "Couldn't read all of header");
+                                return(ST_EOF);
+                        }
+                        chunk_buf[chunksize] = '\0';
+                        st_report("%s",chunk_buf);
+                        free(chunk_buf);
 
-			continue;
-		}
+                        continue;
+                }
 
-		if (strncmp(buf,"NAME",4) == 0) {
-			st_readdw(ft, &chunksize);
-			if (chunksize & 1)
-				chunksize++;
-			chunk_buf = (char *) malloc(chunksize + 1);
-			if (chunk_buf == 0)
-			{
-			    st_fail_errno(ft, ST_ENOMEM, "Unable to alloc memory");
-			    return(ST_EOF);
-			}
-			if (fread (chunk_buf,1,(size_t)chunksize,ft->fp) 
-					!= chunksize)
-			{
-				st_fail_errno(ft, ST_EHDR, "Couldn't read all of header");
-				return(ST_EOF);
-			}
-			chunk_buf[chunksize] = '\0';
-			st_report("%s",chunk_buf);
-			free(chunk_buf);
+                if (strncmp(buf,"NAME",4) == 0) {
+                        st_readdw(ft, &chunksize);
+                        if (chunksize & 1)
+                                chunksize++;
+                        chunk_buf = (char *) malloc(chunksize + 1);
+                        if (chunk_buf == 0)
+                        {
+                            st_fail_errno(ft, ST_ENOMEM, "Unable to alloc memory");
+                            return(ST_EOF);
+                        }
+                        if (fread (chunk_buf,1,(size_t)chunksize,ft->fp) 
+                                        != chunksize)
+                        {
+                                st_fail_errno(ft, ST_EHDR, "Couldn't read all of header");
+                                return(ST_EOF);
+                        }
+                        chunk_buf[chunksize] = '\0';
+                        st_report("%s",chunk_buf);
+                        free(chunk_buf);
 
-			continue;
-		}
+                        continue;
+                }
 
-		if (strncmp(buf,"CHAN",4) == 0) {
-			st_readdw(ft, &chunksize);
-			if (chunksize != 4) 
-			{
-				st_fail_errno(ft, ST_EHDR, "Couldn't read all of header");
-				return(ST_EOF);
-			}
-			st_readdw(ft, &channels);
-			channels = (channels & 0x01) + 
-					((channels & 0x02) >> 1) +
-				   	((channels & 0x04) >> 2) + 
-					((channels & 0x08) >> 3);
+                if (strncmp(buf,"CHAN",4) == 0) {
+                        st_readdw(ft, &chunksize);
+                        if (chunksize != 4) 
+                        {
+                                st_fail_errno(ft, ST_EHDR, "Couldn't read all of header");
+                                return(ST_EOF);
+                        }
+                        st_readdw(ft, &channels);
+                        channels = (channels & 0x01) + 
+                                        ((channels & 0x02) >> 1) +
+                                        ((channels & 0x04) >> 2) + 
+                                        ((channels & 0x08) >> 3);
 
-			continue;
-		}
+                        continue;
+                }
 
-		/* some other kind of chunk */
-		st_readdw(ft, &chunksize);
-		if (chunksize & 1)
-			chunksize++;
-		fseek(ft->fp,chunksize,SEEK_CUR);
-		continue;
+                /* some other kind of chunk */
+                st_readdw(ft, &chunksize);
+                if (chunksize & 1)
+                        chunksize++;
+                fseek(ft->fp,chunksize,SEEK_CUR);
+                continue;
 
-	}
+        }
 
-	if (rate == 0)
-	{
-		st_fail_errno(ft, ST_ERATE, "Invalid sample rate");
-		return(ST_EOF);
-	}
-	if (strncmp(buf,"BODY",4) != 0)
-	{
-		st_fail_errno(ft, ST_EHDR, "BODY chunk not found");
-		return(ST_EOF);
-	}
-	st_readdw(ft, &(p->nsamples));
+        if (rate == 0)
+        {
+                st_fail_errno(ft, ST_ERATE, "Invalid sample rate");
+                return(ST_EOF);
+        }
+        if (strncmp(buf,"BODY",4) != 0)
+        {
+                st_fail_errno(ft, ST_EHDR, "BODY chunk not found");
+                return(ST_EOF);
+        }
+        st_readdw(ft, &(p->nsamples));
 
-	ft->length = p->nsamples;
-	ft->info.channels = channels;
-	ft->info.rate = rate;
-	ft->info.encoding = ST_ENCODING_SIGN2;
-	ft->info.size = ST_SIZE_BYTE;
+        ft->length = p->nsamples;
+        ft->info.channels = channels;
+        ft->info.rate = rate;
+        ft->info.encoding = ST_ENCODING_SIGN2;
+        ft->info.size = ST_SIZE_BYTE;
 
-	/* open files to channels */
-	p->ch[0] = ft->fp;
-	chan1_pos = ftell(p->ch[0]);
+        /* open files to channels */
+        p->ch[0] = ft->fp;
+        chan1_pos = ftell(p->ch[0]);
 
-	for (i = 1; i < channels; i++) {
-		if ((p->ch[i] = fopen(ft->filename, "rb")) == NULL)
-		{
-			st_fail_errno(ft,errno,"Can't open channel file '%s'",
-				ft->filename);
-			return(ST_EOF);
-		}
+        for (i = 1; i < channels; i++) {
+                if ((p->ch[i] = fopen(ft->filename, "rb")) == NULL)
+                {
+                        st_fail_errno(ft,errno,"Can't open channel file '%s'",
+                                ft->filename);
+                        return(ST_EOF);
+                }
 
-		/* position channel files */
-		if (fseek(p->ch[i],chan1_pos,SEEK_SET))
-		{
-		    st_fail_errno (ft,errno,"Can't position channel %d",i);
-		    return(ST_EOF);
-		}
-		if (fseek(p->ch[i],p->nsamples/channels*i,SEEK_CUR))
-		{
-		    st_fail_errno (ft,errno,"Can't seek channel %d",i);
-		    return(ST_EOF);
-		}
-	}
-	return(ST_SUCCESS);
-}
+                /* position channel files */
+                if (fseek(p->ch[i],chan1_pos,SEEK_SET))
+                {
+                    st_fail_errno (ft,errno,"Can't position channel %d",i);
+                    return(ST_EOF);
+                }
+                if (fseek(p->ch[i],p->nsamples/channels*i,SEEK_CUR))
+                {
+                    st_fail_errno (ft,errno,"Can't seek channel %d",i);
+                    return(ST_EOF);
+                }
+        }
+        return(ST_SUCCESS);
+}
 
 /*======================================================================*/
 /*                         8SVXREAD                                     */
@@ -216,25 +216,25 @@
 /*======================================================================*/
 st_ssize_t st_svxread(ft_t ft, st_sample_t *buf, st_ssize_t nsamp) 
 {
-	unsigned char datum;
-	int done = 0;
-	int i;
+        unsigned char datum;
+        int done = 0;
+        int i;
 
-	svx_t p = (svx_t ) ft->priv;
+        svx_t p = (svx_t ) ft->priv;
 
-	while (done < nsamp) {
-		for (i = 0; i < ft->info.channels; i++) {
-		    	/* FIXME: don't pass FILE pointers! */
-		    	datum = getc(p->ch[i]);
-			if (feof(p->ch[i]))
-				return done;
-			/* scale signed up to long's range */
-			*buf++ = ST_SIGNED_BYTE_TO_SAMPLE(datum);
-		}
-		done += ft->info.channels;
-	}
-	return done;
-}
+        while (done < nsamp) {
+                for (i = 0; i < ft->info.channels; i++) {
+                        /* FIXME: don't pass FILE pointers! */
+                        datum = getc(p->ch[i]);
+                        if (feof(p->ch[i]))
+                                return done;
+                        /* scale signed up to long's range */
+                        *buf++ = ST_SIGNED_BYTE_TO_SAMPLE(datum);
+                }
+                done += ft->info.channels;
+        }
+        return done;
+}
 
 /*======================================================================*/
 /*                         8SVXSTOPREAD                                 */
@@ -241,15 +241,15 @@
 /*======================================================================*/
 int st_svxstopread(ft_t ft)
 {
-	int i;
+        int i;
 
-	svx_t p = (svx_t ) ft->priv;
+        svx_t p = (svx_t ) ft->priv;
 
-	/* close channel files */
-	for (i = 1; i < ft->info.channels; i++) {
-		fclose (p->ch[i]);
-	}
-	return(ST_SUCCESS);
+        /* close channel files */
+        for (i = 1; i < ft->info.channels; i++) {
+                fclose (p->ch[i]);
+        }
+        return(ST_SUCCESS);
 }
 
 /*======================================================================*/
@@ -257,34 +257,34 @@
 /*======================================================================*/
 int st_svxstartwrite(ft_t ft)
 {
-	svx_t p = (svx_t ) ft->priv;
-	int i;
+        svx_t p = (svx_t ) ft->priv;
+        int i;
 
-	/* 8svx is in big endian format.  Swaps wahst
-	 * read in on little endian machines.
-	 */
-	if (ST_IS_LITTLEENDIAN)
-	{
-		ft->swap = ft->swap ? 0 : 1;
-	}
+        /* 8svx is in big endian format.  Swaps wahst
+         * read in on little endian machines.
+         */
+        if (ST_IS_LITTLEENDIAN)
+        {
+                ft->swap = ft->swap ? 0 : 1;
+        }
 
-	/* open channel output files */
-	p->ch[0] = ft->fp;
-	for (i = 1; i < ft->info.channels; i++) {
-		if ((p->ch[i] = tmpfile()) == NULL)
-		{
-			st_fail_errno(ft,errno,"Can't open channel output file");
-			return(ST_EOF);
-		}
-	}
+        /* open channel output files */
+        p->ch[0] = ft->fp;
+        for (i = 1; i < ft->info.channels; i++) {
+                if ((p->ch[i] = tmpfile()) == NULL)
+                {
+                        st_fail_errno(ft,errno,"Can't open channel output file");
+                        return(ST_EOF);
+                }
+        }
 
-	/* write header (channel 0) */
-	ft->info.encoding = ST_ENCODING_SIGN2;
-	ft->info.size = ST_SIZE_BYTE;
+        /* write header (channel 0) */
+        ft->info.encoding = ST_ENCODING_SIGN2;
+        ft->info.size = ST_SIZE_BYTE;
 
-	p->nsamples = 0;
-	svxwriteheader(ft, p->nsamples);
-	return(ST_SUCCESS);
+        p->nsamples = 0;
+        svxwriteheader(ft, p->nsamples);
+        return(ST_SUCCESS);
 }
 
 /*======================================================================*/
@@ -293,24 +293,24 @@
 
 st_ssize_t st_svxwrite(ft_t ft, st_sample_t *buf, st_ssize_t len)
 {
-	svx_t p = (svx_t ) ft->priv;
+        svx_t p = (svx_t ) ft->priv;
 
-	unsigned char datum;
-	int done = 0;
-	int i;
+        unsigned char datum;
+        int done = 0;
+        int i;
 
-	p->nsamples += len;
+        p->nsamples += len;
 
-	while(done < len) {
-		for (i = 0; i < ft->info.channels; i++) {
-			datum = ST_SAMPLE_TO_SIGNED_BYTE(*buf++);
-			/* FIXME: Needs to pass ft struct and not FILE */
-			putc(datum, p->ch[i]);
-		}
-		done += ft->info.channels;
-	}
-	return (done);
-}
+        while(done < len) {
+                for (i = 0; i < ft->info.channels; i++) {
+                        datum = ST_SAMPLE_TO_SIGNED_BYTE(*buf++);
+                        /* FIXME: Needs to pass ft struct and not FILE */
+                        putc(datum, p->ch[i]);
+                }
+                done += ft->info.channels;
+        }
+        return (done);
+}
 
 /*======================================================================*/
 /*                         8SVXSTOPWRITE                                */
@@ -318,39 +318,39 @@
 
 int st_svxstopwrite(ft_t ft)
 {
-	svx_t p = (svx_t ) ft->priv;
+        svx_t p = (svx_t ) ft->priv;
 
-	int i;
-	int len;
-	char svxbuf[512];
+        int i;
+        int len;
+        char svxbuf[512];
 
-	/* append all channel pieces to channel 0 */
-	/* close temp files */
-	for (i = 1; i < ft->info.channels; i++) {
-		if (fseek (p->ch[i], 0L, 0))
-		{
-			st_fail_errno (ft,errno,"Can't rewind channel output file %d",i);
-			return(ST_EOF);
-		}
-		while (!feof(p->ch[i])) {
-			len = fread (svxbuf, 1, 512, p->ch[i]);
-			fwrite (svxbuf, 1, len, p->ch[0]);
-		}
-		fclose (p->ch[i]);
-	}
+        /* append all channel pieces to channel 0 */
+        /* close temp files */
+        for (i = 1; i < ft->info.channels; i++) {
+                if (fseek (p->ch[i], 0L, 0))
+                {
+                        st_fail_errno (ft,errno,"Can't rewind channel output file %d",i);
+                        return(ST_EOF);
+                }
+                while (!feof(p->ch[i])) {
+                        len = fread (svxbuf, 1, 512, p->ch[i]);
+                        fwrite (svxbuf, 1, len, p->ch[0]);
+                }
+                fclose (p->ch[i]);
+        }
 
-	/* add a pad byte if BODY size is odd */
-	if(p->nsamples % 2 != 0)
-	    st_writeb(ft, '\0');
+        /* add a pad byte if BODY size is odd */
+        if(p->nsamples % 2 != 0)
+            st_writeb(ft, '\0');
 
-	/* fixup file sizes in header */
-	if (fseek(ft->fp, 0L, 0) != 0)
-	{
-		st_fail_errno(ft,errno,"can't rewind output file to rewrite 8SVX header");
-		return(ST_EOF);
-	}
-	svxwriteheader(ft, p->nsamples);
-	return(ST_SUCCESS);
+        /* fixup file sizes in header */
+        if (fseek(ft->fp, 0L, 0) != 0)
+        {
+                st_fail_errno(ft,errno,"can't rewind output file to rewrite 8SVX header");
+                return(ST_EOF);
+        }
+        svxwriteheader(ft, p->nsamples);
+        return(ST_SUCCESS);
 }
 
 /*======================================================================*/
@@ -359,34 +359,34 @@
 #define SVXHEADERSIZE 100
 static void svxwriteheader(ft_t ft, st_ssize_t nsamples)
 {
-	int32_t formsize =  nsamples + SVXHEADERSIZE - 8;
+        int32_t formsize =  nsamples + SVXHEADERSIZE - 8;
 
-	/* FORM size must be even */
-	if(formsize % 2 != 0) formsize++;
+        /* FORM size must be even */
+        if(formsize % 2 != 0) formsize++;
 
-	st_writes(ft, "FORM");
-	st_writedw(ft, formsize);  /* size of file */
-	st_writes(ft, "8SVX"); /* File type */
+        st_writes(ft, "FORM");
+        st_writedw(ft, formsize);  /* size of file */
+        st_writes(ft, "8SVX"); /* File type */
 
-	st_writes(ft, "VHDR");
-	st_writedw(ft, 20); /* number of bytes to follow */
-	st_writedw(ft, nsamples);  /* samples, 1-shot */
-	st_writedw(ft, 0);  /* samples, repeat */
-	st_writedw(ft, 0);  /* samples per repeat cycle */
-	st_writew(ft, (int) ft->info.rate); /* samples per second */
-	st_writeb(ft,1); /* number of octabes */
-	st_writeb(ft,0); /* data compression (none) */
-	st_writew(ft,1); st_writew(ft,0); /* volume */
+        st_writes(ft, "VHDR");
+        st_writedw(ft, 20); /* number of bytes to follow */
+        st_writedw(ft, nsamples/ft->info.channels);  /* samples, 1-shot */
+        st_writedw(ft, 0);  /* samples, repeat */
+        st_writedw(ft, 0);  /* samples per repeat cycle */
+        st_writew(ft, (int) ft->info.rate); /* samples per second */
+        st_writeb(ft,1); /* number of octabes */
+        st_writeb(ft,0); /* data compression (none) */
+        st_writew(ft,1); st_writew(ft,0); /* volume */
 
-	st_writes(ft, "ANNO");
-	st_writedw(ft, 32); /* length of block */
-	st_writes(ft, "File created by Sound Exchange  ");
+        st_writes(ft, "ANNO");
+        st_writedw(ft, 32); /* length of block */
+        st_writes(ft, "File created by Sound Exchange  ");
 
-	st_writes(ft, "CHAN");
-	st_writedw(ft, 4);
-	st_writedw(ft, (ft->info.channels == 2) ? 6 :
-		   (ft->info.channels == 4) ? 15 : 2);
+        st_writes(ft, "CHAN");
+        st_writedw(ft, 4);
+        st_writedw(ft, (ft->info.channels == 2) ? 6 :
+                   (ft->info.channels == 4) ? 15 : 2);
 
-	st_writes(ft, "BODY");
-	st_writedw(ft, nsamples); /* samples in file */
+        st_writes(ft, "BODY");
+        st_writedw(ft, nsamples); /* samples in file */
 }
--- a/src/maud.c
+++ b/src/maud.c
@@ -25,12 +25,12 @@
 #include <errno.h>
 #endif
 #ifdef HAVE_UNISTD_H
-#include <unistd.h>	/* For SEEK_* defines if not found in stdio */
+#include <unistd.h>     /* For SEEK_* defines if not found in stdio */
 #endif
 
 /* Private data for MAUD file */
 struct maudstuff { /* max. 100 bytes!!!! */
-	uint32_t nsamples;
+        uint32_t nsamples;
 };
 
 static void maudwriteheader(ft_t);
@@ -38,187 +38,188 @@
 /*
  * 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_maudstartread(ft_t ft) 
 {
-	struct maudstuff * p = (struct maudstuff *) ft->priv;
-	
-	char buf[12];
-	char *chunk_buf;
-	
-	unsigned short bitpersam;
-	uint32_t nom;
-	unsigned short denom;
-	unsigned short chaninf;
-	
-	uint32_t chunksize;
-	uint32_t trash32;
-	int rc;
+        struct maudstuff * p = (struct maudstuff *) ft->priv;
+        
+        char buf[12];
+        char *chunk_buf;
+        
+        unsigned short bitpersam;
+        uint32_t nom;
+        unsigned short denom;
+        unsigned short chaninf;
+        
+        uint32_t chunksize;
+        uint32_t trash32;
+        uint16_t trash16;
+        int rc;
 
-	/* Needed for rawread() */
-	rc = st_rawstartread(ft);
-	if (rc)
-	    return rc;
+        /* Needed for rawread() */
+        rc = st_rawstartread(ft);
+        if (rc)
+            return rc;
 
-	/* maud is in big endian format.  Swap whats read in
-	 * on little endian machines.
-	 */
-	if (ST_IS_LITTLEENDIAN)
-	{
-		ft->swap = ft->swap ? 0 : 1;
-	}
-	
-	/* read FORM chunk */
-	if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "FORM", 4) != 0)
-	{
-		st_fail_errno(ft,ST_EHDR,"MAUD: header does not begin with magic word 'FORM'");
-		return (ST_EOF);
-	}
-	
-	st_readdw(ft, &trash32); /* totalsize */
-	
-	if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "MAUD", 4) != 0)
-	{
-		st_fail_errno(ft,ST_EHDR,"MAUD: 'FORM' chunk does not specify 'MAUD' as type");
-		return(ST_EOF);
-	}
-	
-	/* read chunks until 'BODY' (or end) */
-	
-	while (st_reads(ft, buf, 4) == ST_SUCCESS && strncmp(buf,"MDAT",4) != 0) {
-		
-		/*
-		buf[4] = 0;
-		st_report("chunk %s",buf);
-		*/
-		
-		if (strncmp(buf,"MHDR",4) == 0) {
-			
-			st_readdw(ft, &chunksize);
-			if (chunksize != 8*4) 
-			{
-			    st_fail_errno(ft,ST_EHDR,"MAUD: MHDR chunk has bad size");
-			    return(ST_EOF);
-			}
-			
-			/* fseek(ft->fp,12,SEEK_CUR); */
-
-			/* number of samples stored in MDAT */
-			st_readdw(ft, &(p->nsamples));
-
-			/* number of bits per sample as stored in MDAT */
-			st_readw(ft, &bitpersam);
+        /* maud is in big endian format.  Swap whats read in
+         * on little endian machines.
+         */
+        if (ST_IS_LITTLEENDIAN)
+        {
+                ft->swap = ft->swap ? 0 : 1;
+        }
+        
+        /* read FORM chunk */
+        if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "FORM", 4) != 0)
+        {
+                st_fail_errno(ft,ST_EHDR,"MAUD: header does not begin with magic word 'FORM'");
+                return (ST_EOF);
+        }
+        
+        st_readdw(ft, &trash32); /* totalsize */
+        
+        if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "MAUD", 4) != 0)
+        {
+                st_fail_errno(ft,ST_EHDR,"MAUD: 'FORM' chunk does not specify 'MAUD' as type");
+                return(ST_EOF);
+        }
+        
+        /* read chunks until 'BODY' (or end) */
+        
+        while (st_reads(ft, buf, 4) == ST_SUCCESS && strncmp(buf,"MDAT",4) != 0) {
+                
+                /*
+                buf[4] = 0;
+                st_report("chunk %s",buf);
+                */
+                
+                if (strncmp(buf,"MHDR",4) == 0) {
+                        
+                        st_readdw(ft, &chunksize);
+                        if (chunksize != 8*4) 
+                        {
+                            st_fail_errno(ft,ST_EHDR,"MAUD: MHDR chunk has bad size");
+                            return(ST_EOF);
+                        }
+                        
+                        /* fseek(ft->fp,12,SEEK_CUR); */
 
-			/* number of bits per sample after decompression */
-			st_readw(ft, (unsigned short *)&trash32);
+                        /* number of samples stored in MDAT */
+                        st_readdw(ft, &(p->nsamples));
 
-			st_readdw(ft, &nom);         /* clock source frequency */
-			st_readw(ft, &denom);       /* clock devide           */
-			if (denom == 0) 
-			{
-			    st_fail_errno(ft,ST_EHDR,"MAUD: frequency denominator == 0, failed");
-			    return (ST_EOF);
-			}
-			
-			ft->info.rate = nom / denom;
-			
-			st_readw(ft, &chaninf); /* channel information */
-			switch (chaninf) {
-			case 0:
-				ft->info.channels = 1;
-				break;
-			case 1:
-				ft->info.channels = 2;
-				break;
-			default:
-				st_fail_errno(ft,ST_EFMT,"MAUD: unsupported number of channels in file");
-				return (ST_EOF);
-			}
-			
-			st_readw(ft, &chaninf); /* number of channels (mono: 1, stereo: 2, ...) */
-			if (chaninf != ft->info.channels) 
-			{
-				st_fail_errno(ft,ST_EFMT,"MAUD: unsupported number of channels in file");
-			    return(ST_EOF);
-			}
-			
-			st_readw(ft, &chaninf); /* compression type */
-			
-			st_readdw(ft, &trash32); /* rest of chunk, unused yet */
-			st_readdw(ft, &trash32);
-			st_readdw(ft, &trash32);
-			
-			if (bitpersam == 8 && chaninf == 0) {
-				ft->info.size = ST_SIZE_BYTE;
-				ft->info.encoding = ST_ENCODING_UNSIGNED;
-			}
-			else if (bitpersam == 8 && chaninf == 2) {
-				ft->info.size = ST_SIZE_BYTE;
-				ft->info.encoding = ST_ENCODING_ALAW;
-			}
-			else if (bitpersam == 8 && chaninf == 3) {
-				ft->info.size = ST_SIZE_BYTE;
-				ft->info.encoding = ST_ENCODING_ULAW;
-			}
-			else if (bitpersam == 16 && chaninf == 0) {
-				ft->info.size = ST_SIZE_WORD;
-				ft->info.encoding = ST_ENCODING_SIGN2;
-			}
-			else 
-			{
-				st_fail_errno(ft,ST_EFMT,"MAUD: unsupported compression type detected");
-				return(ST_EOF);
-			}
-			
-			ft->comment = 0;
-			
-			continue;
-		}
-		
-		if (strncmp(buf,"ANNO",4) == 0) {
-			st_readdw(ft, &chunksize);
-			if (chunksize & 1)
-				chunksize++;
-			chunk_buf = (char *) malloc(chunksize + 1);
-			if (!chunk_buf)
-			{
-			    st_fail_errno(ft,ST_ENOMEM,"Couldn't alloc resources");
-			    return(ST_EOF);
-			}
-			if (fread(chunk_buf,1,(int)chunksize,ft->fp) 
-					!= chunksize)
-			{
-				st_fail_errno(ft,ST_EOF,"MAUD: Unexpected EOF in ANNO header");
-				return(ST_EOF);
-			}
-			chunk_buf[chunksize] = '\0';
-			st_report("%s",chunk_buf);
-			free(chunk_buf);
-			
-			continue;
-		}
-		
-		/* some other kind of chunk */
-		st_readdw(ft, &chunksize);
-		if (chunksize & 1)
-			chunksize++;
-		fseek(ft->fp,chunksize,SEEK_CUR);
-		continue;
-		
-	}
-	
-	if (strncmp(buf,"MDAT",4) != 0) 
-	{
-	    st_fail_errno(ft,ST_EFMT,"MAUD: MDAT chunk not found");
-	    return(ST_EOF);
-	}
-	st_readdw(ft, &(p->nsamples));
-	return(ST_SUCCESS);
-}
-
+                        /* number of bits per sample as stored in MDAT */
+                        st_readw(ft, &bitpersam);
+
+                        /* number of bits per sample after decompression */
+                        st_readw(ft, (unsigned short *)&trash16);
+
+                        st_readdw(ft, &nom);         /* clock source frequency */
+                        st_readw(ft, &denom);       /* clock devide           */
+                        if (denom == 0) 
+                        {
+                            st_fail_errno(ft,ST_EHDR,"MAUD: frequency denominator == 0, failed");
+                            return (ST_EOF);
+                        }
+                        
+                        ft->info.rate = nom / denom;
+                        
+                        st_readw(ft, &chaninf); /* channel information */
+                        switch (chaninf) {
+                        case 0:
+                                ft->info.channels = 1;
+                                break;
+                        case 1:
+                                ft->info.channels = 2;
+                                break;
+                        default:
+                                st_fail_errno(ft,ST_EFMT,"MAUD: unsupported number of channels in file");
+                                return (ST_EOF);
+                        }
+                        
+                        st_readw(ft, &chaninf); /* number of channels (mono: 1, stereo: 2, ...) */
+                        if (chaninf != ft->info.channels) 
+                        {
+                                st_fail_errno(ft,ST_EFMT,"MAUD: unsupported number of channels in file");
+                            return(ST_EOF);
+                        }
+                        
+                        st_readw(ft, &chaninf); /* compression type */
+                        
+                        st_readdw(ft, &trash32); /* rest of chunk, unused yet */
+                        st_readdw(ft, &trash32);
+                        st_readdw(ft, &trash32);
+                        
+                        if (bitpersam == 8 && chaninf == 0) {
+                                ft->info.size = ST_SIZE_BYTE;
+                                ft->info.encoding = ST_ENCODING_UNSIGNED;
+                        }
+                        else if (bitpersam == 8 && chaninf == 2) {
+                                ft->info.size = ST_SIZE_BYTE;
+                                ft->info.encoding = ST_ENCODING_ALAW;
+                        }
+                        else if (bitpersam == 8 && chaninf == 3) {
+                                ft->info.size = ST_SIZE_BYTE;
+                                ft->info.encoding = ST_ENCODING_ULAW;
+                        }
+                        else if (bitpersam == 16 && chaninf == 0) {
+                                ft->info.size = ST_SIZE_WORD;
+                                ft->info.encoding = ST_ENCODING_SIGN2;
+                        }
+                        else 
+                        {
+                                st_fail_errno(ft,ST_EFMT,"MAUD: unsupported compression type detected");
+                                return(ST_EOF);
+                        }
+                        
+                        ft->comment = 0;
+                        
+                        continue;
+                }
+                
+                if (strncmp(buf,"ANNO",4) == 0) {
+                        st_readdw(ft, &chunksize);
+                        if (chunksize & 1)
+                                chunksize++;
+                        chunk_buf = (char *) malloc(chunksize + 1);
+                        if (!chunk_buf)
+                        {
+                            st_fail_errno(ft,ST_ENOMEM,"Couldn't alloc resources");
+                            return(ST_EOF);
+                        }
+                        if (fread(chunk_buf,1,(int)chunksize,ft->fp) 
+                                        != chunksize)
+                        {
+                                st_fail_errno(ft,ST_EOF,"MAUD: Unexpected EOF in ANNO header");
+                                return(ST_EOF);
+                        }
+                        chunk_buf[chunksize] = '\0';
+                        st_report("%s",chunk_buf);
+                        free(chunk_buf);
+                        
+                        continue;
+                }
+                
+                /* some other kind of chunk */
+                st_readdw(ft, &chunksize);
+                if (chunksize & 1)
+                        chunksize++;
+                fseek(ft->fp,chunksize,SEEK_CUR);
+                continue;
+                
+        }
+        
+        if (strncmp(buf,"MDAT",4) != 0) 
+        {
+            st_fail_errno(ft,ST_EFMT,"MAUD: MDAT chunk not found");
+            return(ST_EOF);
+        }
+        st_readdw(ft, &(p->nsamples));
+        return(ST_SUCCESS);
+}
+
 /*
  * Read up to len samples from file.
  * Convert to signed longs.
@@ -228,7 +229,7 @@
 
 st_ssize_t st_maudread(ft_t ft, st_sample_t *buf, st_ssize_t len) 
 {
-	return (st_rawread(ft, buf, len));
+        return (st_rawread(ft, buf, len));
 }
 
 /*
@@ -237,59 +238,59 @@
  */
 int st_maudstopread(ft_t ft) 
 {
-	/* Needed because of rawread() */
-	return st_rawstopread(ft);
+        /* Needed because of rawread() */
+        return st_rawstopread(ft);
 }
 
 int st_maudstartwrite(ft_t ft) 
 {
-	struct maudstuff * p = (struct maudstuff *) ft->priv;
-	int rc;
+        struct maudstuff * p = (struct maudstuff *) ft->priv;
+        int rc;
 
-	/* Needed for rawwrite() */
-	rc = st_rawstartwrite(ft);
-	if (rc)
-	    return rc;
+        /* Needed for rawwrite() */
+        rc = st_rawstartwrite(ft);
+        if (rc)
+            return rc;
 
-	/* maud is in big endian format.  Swap whats read in
-	 * on little endian machines.
-	 */
-	if (ST_IS_LITTLEENDIAN)
-	{
-		ft->swap = ft->swap ? 0 : 1;
-	}
-	
-	/* If you have to seek around the output file */
-	if (! ft->seekable) 
-	{
-	    st_fail_errno(ft,ST_EOF,"Output .maud file must be a file, not a pipe");
-	    return (ST_EOF);
-	}
-	
-	if (ft->info.channels != 1 && ft->info.channels != 2) {
-		st_fail_errno(ft,ST_EFMT,"MAUD: unsupported number of channels, unable to store");
-		return(ST_EOF);
-	}
-	if (ft->info.size == ST_SIZE_WORD) ft->info.encoding = ST_ENCODING_SIGN2;
-	if (ft->info.encoding == ST_ENCODING_ULAW || 
-	    ft->info.encoding == ST_ENCODING_ALAW) ft->info.size = ST_SIZE_BYTE;
-	if (ft->info.size == ST_SIZE_BYTE && 
-	    ft->info.encoding == ST_ENCODING_SIGN2) 
-	    ft->info.encoding = ST_ENCODING_UNSIGNED;
-	
-	p->nsamples = 0x7f000000L;
-	maudwriteheader(ft);
-	p->nsamples = 0;
-	return (ST_SUCCESS);
+        /* maud is in big endian format.  Swap whats read in
+         * on little endian machines.
+         */
+        if (ST_IS_LITTLEENDIAN)
+        {
+                ft->swap = ft->swap ? 0 : 1;
+        }
+        
+        /* If you have to seek around the output file */
+        if (! ft->seekable) 
+        {
+            st_fail_errno(ft,ST_EOF,"Output .maud file must be a file, not a pipe");
+            return (ST_EOF);
+        }
+        
+        if (ft->info.channels != 1 && ft->info.channels != 2) {
+                st_fail_errno(ft,ST_EFMT,"MAUD: unsupported number of channels, unable to store");
+                return(ST_EOF);
+        }
+        if (ft->info.size == ST_SIZE_WORD) ft->info.encoding = ST_ENCODING_SIGN2;
+        if (ft->info.encoding == ST_ENCODING_ULAW || 
+            ft->info.encoding == ST_ENCODING_ALAW) ft->info.size = ST_SIZE_BYTE;
+        if (ft->info.size == ST_SIZE_BYTE && 
+            ft->info.encoding == ST_ENCODING_SIGN2) 
+            ft->info.encoding = ST_ENCODING_UNSIGNED;
+        
+        p->nsamples = 0x7f000000L;
+        maudwriteheader(ft);
+        p->nsamples = 0;
+        return (ST_SUCCESS);
 }
 
 st_ssize_t st_maudwrite(ft_t ft, st_sample_t *buf, st_ssize_t len) 
 {
-	struct maudstuff * p = (struct maudstuff *) ft->priv;
-	
-	p->nsamples += len;
-	
-	return st_rawwrite(ft, buf, len);
+        struct maudstuff * p = (struct maudstuff *) ft->priv;
+        
+        p->nsamples += len;
+        
+        return st_rawwrite(ft, buf, len);
 }
 
 int st_maudstopwrite(ft_t ft) 
@@ -296,93 +297,93 @@
 {
         int rc;
 
-	/* Flush out remaining samples*/
-	rc = st_rawstopwrite(ft);
-	if (rc)
-	    return rc;
+        /* Flush out remaining samples*/
+        rc = st_rawstopwrite(ft);
+        if (rc)
+            return rc;
 
-	/* All samples are already written out. */
-	
-	if (fseek(ft->fp, 0L, 0) != 0) 
-	{
-	    st_fail_errno(ft,errno,"can't rewind output file to rewrite MAUD header");
-	    return(ST_EOF);
-	}
-	
-	maudwriteheader(ft);
-	return(ST_SUCCESS);
+        /* All samples are already written out. */
+        
+        if (fseek(ft->fp, 0L, 0) != 0) 
+        {
+            st_fail_errno(ft,errno,"can't rewind output file to rewrite MAUD header");
+            return(ST_EOF);
+        }
+        
+        maudwriteheader(ft);
+        return(ST_SUCCESS);
 }
 
 #define MAUDHEADERSIZE (4+(4+4+32)+(4+4+32)+(4+4))
 static void maudwriteheader(ft_t ft)
 {
-	struct maudstuff * p = (struct maudstuff *) ft->priv;
-	
-	st_writes(ft, "FORM");
-	st_writedw(ft, (p->nsamples*ft->info.size) + MAUDHEADERSIZE);  /* size of file */
-	st_writes(ft, "MAUD"); /* File type */
-	
-	st_writes(ft, "MHDR");
-	st_writedw(ft,  8*4); /* number of bytes to follow */
-	st_writedw(ft, p->nsamples);  /* number of samples stored in MDAT */
-	
-	switch (ft->info.encoding) {
-		
-	case ST_ENCODING_UNSIGNED:
-		st_writew(ft, (int) 8); /* number of bits per sample as stored in MDAT */
-		st_writew(ft, (int) 8); /* number of bits per sample after decompression */
-		break;
-		
-	case ST_ENCODING_SIGN2:
-		st_writew(ft, (int) 16); /* number of bits per sample as stored in MDAT */
-		st_writew(ft, (int) 16); /* number of bits per sample after decompression */
-		break;
-		
-	case ST_ENCODING_ALAW:
-	case ST_ENCODING_ULAW:
-		st_writew(ft, (int) 8); /* number of bits per sample as stored in MDAT */
-		st_writew(ft, (int) 16); /* number of bits per sample after decompression */
-		break;
-		
-	}
-	
-	st_writedw(ft, ft->info.rate); /* clock source frequency */
-	st_writew(ft, (int) 1); /* clock devide */
-	
-	if (ft->info.channels == 1) {
-		st_writew(ft, (int) 0); /* channel information */
-		st_writew(ft, (int) 1); /* number of channels (mono: 1, stereo: 2, ...) */
-	}
-	else {
-		st_writew(ft, (int) 1);
-		st_writew(ft, (int) 2);
-	}
-	
-	switch (ft->info.encoding) {
-		
-	case ST_ENCODING_UNSIGNED:
-	case ST_ENCODING_SIGN2:
-		st_writew(ft, (int) 0); /* no compression */
-		break;
-		
-	case ST_ENCODING_ULAW:
-		st_writew(ft, (int) 3);
-		break;
-		
-	case ST_ENCODING_ALAW:
-		st_writew(ft, (int) 2);
-		break;
-		
-	}
-	
-	st_writedw(ft, 0); /* reserved */
-	st_writedw(ft, 0); /* reserved */
-	st_writedw(ft, 0); /* reserved */
-	
-	st_writes(ft, "ANNO");
-	st_writedw(ft, 30); /* length of block */
-	st_writes(ft, "file create by Sound eXchange ");
-	
-	st_writes(ft, "MDAT");
-	st_writedw(ft, p->nsamples * ft->info.size ); /* samples in file */
+        struct maudstuff * p = (struct maudstuff *) ft->priv;
+        
+        st_writes(ft, "FORM");
+        st_writedw(ft, (p->nsamples*ft->info.size) + MAUDHEADERSIZE);  /* size of file */
+        st_writes(ft, "MAUD"); /* File type */
+        
+        st_writes(ft, "MHDR");
+        st_writedw(ft,  8*4); /* number of bytes to follow */
+        st_writedw(ft, p->nsamples);  /* number of samples stored in MDAT */
+        
+        switch (ft->info.encoding) {
+                
+        case ST_ENCODING_UNSIGNED:
+                st_writew(ft, (int) 8); /* number of bits per sample as stored in MDAT */
+                st_writew(ft, (int) 8); /* number of bits per sample after decompression */
+                break;
+                
+        case ST_ENCODING_SIGN2:
+                st_writew(ft, (int) 16); /* number of bits per sample as stored in MDAT */
+                st_writew(ft, (int) 16); /* number of bits per sample after decompression */
+                break;
+                
+        case ST_ENCODING_ALAW:
+        case ST_ENCODING_ULAW:
+                st_writew(ft, (int) 8); /* number of bits per sample as stored in MDAT */
+                st_writew(ft, (int) 16); /* number of bits per sample after decompression */
+                break;
+                
+        }
+        
+        st_writedw(ft, ft->info.rate); /* clock source frequency */
+        st_writew(ft, (int) 1); /* clock devide */
+        
+        if (ft->info.channels == 1) {
+                st_writew(ft, (int) 0); /* channel information */
+                st_writew(ft, (int) 1); /* number of channels (mono: 1, stereo: 2, ...) */
+        }
+        else {
+                st_writew(ft, (int) 1);
+                st_writew(ft, (int) 2);
+        }
+        
+        switch (ft->info.encoding) {
+                
+        case ST_ENCODING_UNSIGNED:
+        case ST_ENCODING_SIGN2:
+                st_writew(ft, (int) 0); /* no compression */
+                break;
+                
+        case ST_ENCODING_ULAW:
+                st_writew(ft, (int) 3);
+                break;
+                
+        case ST_ENCODING_ALAW:
+                st_writew(ft, (int) 2);
+                break;
+                
+        }
+        
+        st_writedw(ft, 0); /* reserved */
+        st_writedw(ft, 0); /* reserved */
+        st_writedw(ft, 0); /* reserved */
+        
+        st_writes(ft, "ANNO");
+        st_writedw(ft, 30); /* length of block */
+        st_writes(ft, "file create by Sound eXchange ");
+        
+        st_writes(ft, "MDAT");
+        st_writedw(ft, p->nsamples * ft->info.size ); /* samples in file */
 }
--- a/src/smp.c
+++ b/src/smp.c
@@ -22,47 +22,47 @@
 #include <errno.h>
 #endif
 
-#define NAMELEN    30		/* Size of Samplevision name */
-#define COMMENTLEN 60		/* Size of Samplevision comment, not shared */
-#define MIDI_UNITY 60		/* MIDI note number to play sample at unity */
+#define NAMELEN    30           /* Size of Samplevision name */
+#define COMMENTLEN 60           /* Size of Samplevision comment, not shared */
+#define MIDI_UNITY 60           /* MIDI note number to play sample at unity */
 
 /* The header preceeding the sample data */
 struct smpheader {
-	char Id[18];		/* File identifier */
-	char version[4];	/* File version */
-	char comments[COMMENTLEN];	/* User comments */
-	char name[NAMELEN + 1];	/* Sample Name, left justified */
+        char Id[18];            /* File identifier */
+        char version[4];        /* File version */
+        char comments[COMMENTLEN];      /* User comments */
+        char name[NAMELEN + 1]; /* Sample Name, left justified */
 };
-#define HEADERSIZE (sizeof(struct smpheader) - 1)	/* -1 for name's \0 */
+#define HEADERSIZE (sizeof(struct smpheader) - 1)       /* -1 for name's \0 */
 
 /* Samplevision loop definition structure */
 struct loop {
-	uint32_t start; /* Sample count into sample data, not byte count */
-	uint32_t end;   /* end point */
-	char type;   /* 0 = loop off, 1 = forward, 2 = forw/back */
-	short count;	     /* No of times to loop */
+        uint32_t start; /* Sample count into sample data, not byte count */
+        uint32_t end;   /* end point */
+        char type;   /* 0 = loop off, 1 = forward, 2 = forw/back */
+        short count;         /* No of times to loop */
 };
 
 /* Samplevision marker definition structure */
 struct marker {
-	char name[10];		/* Ascii Marker name */
-	uint32_t position;	/* Sample Number, not byte number */
+        char name[10];          /* Ascii Marker name */
+        uint32_t position;      /* Sample Number, not byte number */
 };
 
 /* The trailer following the sample data */
 struct smptrailer {
-	struct loop loops[8];		/* loops */
-	struct marker markers[8];	/* markers */
-	char MIDInote;			/* for unity pitch playback */
-	uint32_t rate;			/* in hertz */
-	uint32_t SMPTEoffset;		/* in subframes - huh? */
-	uint32_t CycleSize;		/* sample count in one cycle of the */
-					/* sampled sound -1 if unknown */
+        struct loop loops[8];           /* loops */
+        struct marker markers[8];       /* markers */
+        char MIDInote;                  /* for unity pitch playback */
+        uint32_t rate;                  /* in hertz */
+        uint32_t SMPTEoffset;           /* in subframes - huh? */
+        uint32_t CycleSize;             /* sample count in one cycle of the */
+                                        /* sampled sound -1 if unknown */
 };
 
 /* Private data for SMP file */
 typedef struct smpstuff {
-  uint32_t NoOfSamps;		/* Sample data count in words */
+  uint32_t NoOfSamps;           /* Sample data count in words */
   st_size_t dataStart;
   /* comment memory resides in private data because it's small */
   char comment[COMMENTLEN + NAMELEN + 3];
@@ -76,35 +76,35 @@
  */
 static int readtrailer(ft_t ft, struct smptrailer *trailer)
 {
-	int i;
-	int32_t trash;
+        int i;
+        int16_t trash16;
 
-	st_readw(ft, (unsigned short *)&trash);	/* read reserved word */
-	for(i = 0; i < 8; i++) {	/* read the 8 loops */
-		st_readdw(ft, &(trailer->loops[i].start));
-		ft->loops[i].start = trailer->loops[i].start;
-		st_readdw(ft, &(trailer->loops[i].end));
-		ft->loops[i].length = 
-			trailer->loops[i].end - trailer->loops[i].start;
-		st_readb(ft, (unsigned char *)&(trailer->loops[i].type));
-		ft->loops[i].type = trailer->loops[i].type;
-		st_readw(ft, (unsigned short *)&(trailer->loops[i].count));
-		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)
-		{
-		    st_fail_errno(ft,ST_EHDR,"EOF in SMP");
-		    return(ST_EOF);
-		}
-		st_readdw(ft, &(trailer->markers[i].position));
-	}
-	st_readb(ft, (unsigned char *)&(trailer->MIDInote));
-	st_readdw(ft, &(trailer->rate));
-	st_readdw(ft, &(trailer->SMPTEoffset));
-	st_readdw(ft, &(trailer->CycleSize));
-	return(ST_SUCCESS);
-}
+        st_readw(ft, (unsigned short *)&trash16); /* read reserved word */
+        for(i = 0; i < 8; i++) {        /* read the 8 loops */
+                st_readdw(ft, &(trailer->loops[i].start));
+                ft->loops[i].start = trailer->loops[i].start;
+                st_readdw(ft, &(trailer->loops[i].end));
+                ft->loops[i].length = 
+                        trailer->loops[i].end - trailer->loops[i].start;
+                st_readb(ft, (unsigned char *)&(trailer->loops[i].type));
+                ft->loops[i].type = trailer->loops[i].type;
+                st_readw(ft, (unsigned short *)&(trailer->loops[i].count));
+                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)
+                {
+                    st_fail_errno(ft,ST_EHDR,"EOF in SMP");
+                    return(ST_EOF);
+                }
+                st_readdw(ft, &(trailer->markers[i].position));
+        }
+        st_readb(ft, (unsigned char *)&(trailer->MIDInote));
+        st_readdw(ft, &(trailer->rate));
+        st_readdw(ft, &(trailer->SMPTEoffset));
+        st_readdw(ft, &(trailer->CycleSize));
+        return(ST_SUCCESS);
+}
 
 /*
  * set the trailer data - loops and markers, to reasonably benign values
@@ -111,32 +111,32 @@
  */
 static void settrailer(ft_t ft, struct smptrailer *trailer, st_rate_t rate)
 {
-	int i;
+        int i;
 
-	for(i = 0; i < 8; i++) {	/* copy the 8 loops */
-	    if (ft->loops[i].type != 0) {
-		trailer->loops[i].start = ft->loops[i].start;
-		/* to mark it as not set */
-		trailer->loops[i].end = ft->loops[i].start + ft->loops[i].length;
-		trailer->loops[i].type = ft->loops[i].type;
-		trailer->loops[i].count = ft->loops[i].count;	
-	    } else {
-		/* set first loop start as FFFFFFFF */
-		trailer->loops[i].start = ~0;	
-		/* to mark it as not set */
-		trailer->loops[i].end = 0;	
-		trailer->loops[i].type = 0;
-		trailer->loops[i].count = 0;
-	    }
-	}
-	for(i = 0; i < 8; i++) {	/* write the 8 markers */
-		strcpy(trailer->markers[i].name, "          ");
-		trailer->markers[i].position = ~0;
-	}
-	trailer->MIDInote = MIDI_UNITY;		/* Unity play back */
-	trailer->rate = rate;
-	trailer->SMPTEoffset = 0;
-	trailer->CycleSize = -1;
+        for(i = 0; i < 8; i++) {        /* copy the 8 loops */
+            if (ft->loops[i].type != 0) {
+                trailer->loops[i].start = ft->loops[i].start;
+                /* to mark it as not set */
+                trailer->loops[i].end = ft->loops[i].start + ft->loops[i].length;
+                trailer->loops[i].type = ft->loops[i].type;
+                trailer->loops[i].count = ft->loops[i].count;   
+            } else {
+                /* set first loop start as FFFFFFFF */
+                trailer->loops[i].start = ~0;   
+                /* to mark it as not set */
+                trailer->loops[i].end = 0;      
+                trailer->loops[i].type = 0;
+                trailer->loops[i].count = 0;
+            }
+        }
+        for(i = 0; i < 8; i++) {        /* write the 8 markers */
+                strcpy(trailer->markers[i].name, "          ");
+                trailer->markers[i].position = ~0;
+        }
+        trailer->MIDInote = MIDI_UNITY;         /* Unity play back */
+        trailer->rate = rate;
+        trailer->SMPTEoffset = 0;
+        trailer->CycleSize = -1;
 }
 
 /*
@@ -145,171 +145,171 @@
  */
 static int writetrailer(ft_t ft, struct smptrailer *trailer)
 {
-	int i;
+        int i;
 
-	st_writew(ft, 0);			/* write the reserved word */
-	for(i = 0; i < 8; i++) {	/* write the 8 loops */
-		st_writedw(ft, trailer->loops[i].start);
-		st_writedw(ft, trailer->loops[i].end);
-		st_writeb(ft, trailer->loops[i].type);
-		st_writew(ft, trailer->loops[i].count);
-	}
-	for(i = 0; i < 8; i++) {	/* write the 8 markers */
-		if (st_writes(ft, trailer->markers[i].name) == ST_EOF)
-		{
-		    st_fail_errno(ft,ST_EHDR,"EOF in SMP");
-	 	    return(ST_EOF);
-		}
-		st_writedw(ft, trailer->markers[i].position);
-	}
-	st_writeb(ft, trailer->MIDInote);
-	st_writedw(ft, trailer->rate);
-	st_writedw(ft, trailer->SMPTEoffset);
-	st_writedw(ft, trailer->CycleSize);
-	return(ST_SUCCESS);
-}
+        st_writew(ft, 0);                       /* write the reserved word */
+        for(i = 0; i < 8; i++) {        /* write the 8 loops */
+                st_writedw(ft, trailer->loops[i].start);
+                st_writedw(ft, trailer->loops[i].end);
+                st_writeb(ft, trailer->loops[i].type);
+                st_writew(ft, trailer->loops[i].count);
+        }
+        for(i = 0; i < 8; i++) {        /* write the 8 markers */
+                if (st_writes(ft, trailer->markers[i].name) == ST_EOF)
+                {
+                    st_fail_errno(ft,ST_EHDR,"EOF in SMP");
+                    return(ST_EOF);
+                }
+                st_writedw(ft, trailer->markers[i].position);
+        }
+        st_writeb(ft, trailer->MIDInote);
+        st_writedw(ft, trailer->rate);
+        st_writedw(ft, trailer->SMPTEoffset);
+        st_writedw(ft, trailer->CycleSize);
+        return(ST_SUCCESS);
+}
 
 int st_smpseek(ft_t ft, st_size_t offset) 
 {
-	smp_t smp = (smp_t) ft->priv;
+        smp_t smp = (smp_t) ft->priv;
 
-	ft->st_errno = st_seek(ft,offset*ft->info.size + smp->dataStart,SEEK_SET);
+        ft->st_errno = st_seek(ft,offset*ft->info.size + smp->dataStart,SEEK_SET);
 
-	if( ft->st_errno == ST_SUCCESS )
-		smp->NoOfSamps = ft->length - offset;
+        if( ft->st_errno == ST_SUCCESS )
+                smp->NoOfSamps = ft->length - offset;
 
-	return(ft->st_errno);
+        return(ft->st_errno);
 }
 /*
  * 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_smpstartread(ft_t ft) 
 {
-	smp_t smp = (smp_t) ft->priv;
-	int i;
-	int namelen, commentlen;
-	long samplestart;
-	struct smpheader header;
-	struct smptrailer trailer;
+        smp_t smp = (smp_t) ft->priv;
+        int i;
+        int namelen, commentlen;
+        long samplestart;
+        struct smpheader header;
+        struct smptrailer trailer;
 
-	/* SMP is in Little Endian format.  Swap whats read in on */
-	/* Big Endian machines.			                  */
-	if (ST_IS_BIGENDIAN)
-	{
-		ft->swap = ft->swap ? 0 : 1;
-	}
+        /* SMP is in Little Endian format.  Swap whats read in on */
+        /* Big Endian machines.                                   */
+        if (ST_IS_BIGENDIAN)
+        {
+                ft->swap = ft->swap ? 0 : 1;
+        }
 
-	/* If you need to seek around the input file. */
-	if (! ft->seekable)
-	{
-		st_fail_errno(ft,ST_EOF,"SMP input file must be a file, not a pipe");
-		return(ST_EOF);
-	}
+        /* If you need to seek around the input file. */
+        if (! ft->seekable)
+        {
+                st_fail_errno(ft,ST_EOF,"SMP input file must be a file, not a pipe");
+                return(ST_EOF);
+        }
 
-	/* Read SampleVision header */
-	if (fread((char *) &header, 1, HEADERSIZE, ft->fp) != HEADERSIZE)
-	{
-		st_fail_errno(ft,ST_EHDR,"unexpected EOF in SMP header");
-		return(ST_EOF);
-	}
-	if (strncmp(header.Id, SVmagic, 17) != 0)
-	{
-		st_fail_errno(ft,ST_EHDR,"SMP header does not begin with magic word %s\n", SVmagic);
-		return(ST_EOF);
-	}
-	if (strncmp(header.version, SVvers, 4) != 0)
-	{
-		st_fail_errno(ft,ST_EHDR,"SMP header is not version %s\n", SVvers);
-		return(ST_EOF);
-	}
+        /* Read SampleVision header */
+        if (fread((char *) &header, 1, HEADERSIZE, ft->fp) != HEADERSIZE)
+        {
+                st_fail_errno(ft,ST_EHDR,"unexpected EOF in SMP header");
+                return(ST_EOF);
+        }
+        if (strncmp(header.Id, SVmagic, 17) != 0)
+        {
+                st_fail_errno(ft,ST_EHDR,"SMP header does not begin with magic word %s\n", SVmagic);
+                return(ST_EOF);
+        }
+        if (strncmp(header.version, SVvers, 4) != 0)
+        {
+                st_fail_errno(ft,ST_EHDR,"SMP header is not version %s\n", SVvers);
+                return(ST_EOF);
+        }
 
-	/* Format the sample name and comments to a single comment */
-	/* string. We decrement the counters till we encounter non */
+        /* Format the sample name and comments to a single comment */
+        /* string. We decrement the counters till we encounter non */
         /* padding space chars, so the *lengths* are low by one */
         for (namelen = NAMELEN-1;
             namelen >= 0 && header.name[namelen] == ' '; namelen--)
-	  ;
+          ;
         for (commentlen = COMMENTLEN-1;
             commentlen >= 0 && header.comments[commentlen] == ' '; commentlen--)
-	  ;
-	sprintf(smp->comment, "%.*s: %.*s", namelen+1, header.name,
-		commentlen+1, header.comments);
-	ft->comment = smp->comment;
+          ;
+        sprintf(smp->comment, "%.*s: %.*s", namelen+1, header.name,
+                commentlen+1, header.comments);
+        ft->comment = smp->comment;
 
-	st_report("SampleVision file name and comments: %s", ft->comment);
-	/* Extract out the sample size (always intel format) */
-	st_readdw(ft, &(smp->NoOfSamps));
-	/* mark the start of the sample data */
-	samplestart = ftell(ft->fp);
+        st_report("SampleVision file name and comments: %s", ft->comment);
+        /* Extract out the sample size (always intel format) */
+        st_readdw(ft, &(smp->NoOfSamps));
+        /* mark the start of the sample data */
+        samplestart = ftell(ft->fp);
 
-	/* seek from the current position (the start of sample data) by */
-	/* NoOfSamps * 2 */
-	if (fseek(ft->fp, smp->NoOfSamps * 2L, 1) == -1)
-	{
-		st_fail_errno(ft,errno,"SMP unable to seek to trailer");
-		return(ST_EOF);
-	}
-	if (readtrailer(ft, &trailer))
-	{
-		st_fail_errno(ft,ST_EHDR,"unexpected EOF in SMP trailer");
-		return(ST_EOF);
-	}
+        /* seek from the current position (the start of sample data) by */
+        /* NoOfSamps * 2 */
+        if (fseek(ft->fp, smp->NoOfSamps * 2L, 1) == -1)
+        {
+                st_fail_errno(ft,errno,"SMP unable to seek to trailer");
+                return(ST_EOF);
+        }
+        if (readtrailer(ft, &trailer))
+        {
+                st_fail_errno(ft,ST_EHDR,"unexpected EOF in SMP trailer");
+                return(ST_EOF);
+        }
 
-	/* seek back to the beginning of the data */
-	if (fseek(ft->fp, samplestart, 0) == -1) 
-	{
-		st_fail_errno(ft,errno,"SMP unable to seek back to start of sample data");
-		return(ST_EOF);
-	}
+        /* seek back to the beginning of the data */
+        if (fseek(ft->fp, samplestart, 0) == -1) 
+        {
+                st_fail_errno(ft,errno,"SMP unable to seek back to start of sample data");
+                return(ST_EOF);
+        }
 
-	ft->info.rate = (int) trailer.rate;
-	ft->info.size = ST_SIZE_WORD;
-	ft->info.encoding = ST_ENCODING_SIGN2;
-	ft->info.channels = 1;
-	smp->dataStart = samplestart;
-	ft->length = smp->NoOfSamps;
+        ft->info.rate = (int) trailer.rate;
+        ft->info.size = ST_SIZE_WORD;
+        ft->info.encoding = ST_ENCODING_SIGN2;
+        ft->info.channels = 1;
+        smp->dataStart = samplestart;
+        ft->length = smp->NoOfSamps;
 
-	st_report("SampleVision trailer:\n");
-	for(i = 0; i < 8; i++) if (1 || trailer.loops[i].count) {
+        st_report("SampleVision trailer:\n");
+        for(i = 0; i < 8; i++) if (1 || trailer.loops[i].count) {
 #ifdef __alpha__
-		st_report("Loop %d: start: %6d", i, trailer.loops[i].start);
-		st_report(" end:   %6d", trailer.loops[i].end);
+                st_report("Loop %d: start: %6d", i, trailer.loops[i].start);
+                st_report(" end:   %6d", trailer.loops[i].end);
 #else
-		st_report("Loop %d: start: %6ld", i, trailer.loops[i].start);
-		st_report(" end:   %6ld", trailer.loops[i].end);
+                st_report("Loop %d: start: %6ld", i, trailer.loops[i].start);
+                st_report(" end:   %6ld", trailer.loops[i].end);
 #endif
-		st_report(" count: %6d", trailer.loops[i].count);
-		switch(trailer.loops[i].type) {
-		    case 0: st_report("type:  off\n"); break;
-		    case 1: st_report("type:  forward\n"); break;
-		    case 2: st_report("type:  forward/backward\n"); break;
-		}
-	}
-	st_report("MIDI Note number: %d\n\n", trailer.MIDInote);
+                st_report(" count: %6d", trailer.loops[i].count);
+                switch(trailer.loops[i].type) {
+                    case 0: st_report("type:  off\n"); break;
+                    case 1: st_report("type:  forward\n"); break;
+                    case 2: st_report("type:  forward/backward\n"); break;
+                }
+        }
+        st_report("MIDI Note number: %d\n\n", trailer.MIDInote);
 
-	ft->instr.nloops = 0;
-	for(i = 0; i < 8; i++) 
-		if (trailer.loops[i].type) 
-			ft->instr.nloops++;
-	for(i = 0; i < ft->instr.nloops; i++) {
-		ft->loops[i].type = trailer.loops[i].type;
-		ft->loops[i].count = trailer.loops[i].count;
-		ft->loops[i].start = trailer.loops[i].start;
-		ft->loops[i].length = trailer.loops[i].end 
-			- trailer.loops[i].start;
-	}
-	ft->instr.MIDIlow = ft->instr.MIDIhi =
-		ft->instr.MIDInote = trailer.MIDInote;
-	if (ft->instr.nloops > 0)
-		ft->instr.loopmode = ST_LOOP_8;
-	else
-		ft->instr.loopmode = ST_LOOP_NONE;
+        ft->instr.nloops = 0;
+        for(i = 0; i < 8; i++) 
+                if (trailer.loops[i].type) 
+                        ft->instr.nloops++;
+        for(i = 0; i < ft->instr.nloops; i++) {
+                ft->loops[i].type = trailer.loops[i].type;
+                ft->loops[i].count = trailer.loops[i].count;
+                ft->loops[i].start = trailer.loops[i].start;
+                ft->loops[i].length = trailer.loops[i].end 
+                        - trailer.loops[i].start;
+        }
+        ft->instr.MIDIlow = ft->instr.MIDIhi =
+                ft->instr.MIDInote = trailer.MIDInote;
+        if (ft->instr.nloops > 0)
+                ft->instr.loopmode = ST_LOOP_8;
+        else
+                ft->instr.loopmode = ST_LOOP_NONE;
 
-	return(ST_SUCCESS);
+        return(ST_SUCCESS);
 }
 
 /*
@@ -320,16 +320,16 @@
  */
 st_ssize_t st_smpread(ft_t ft, st_sample_t *buf, st_ssize_t len) 
 {
-	smp_t smp = (smp_t) ft->priv;
-	unsigned short datum;
-	int done = 0;
-	
-	for(; done < len && smp->NoOfSamps; done++, smp->NoOfSamps--) {
-		st_readw(ft, &datum);
-		/* scale signed up to long's range */
-		*buf++ = ST_SIGNED_WORD_TO_SAMPLE(datum);
-	}
-	return done;
+        smp_t smp = (smp_t) ft->priv;
+        unsigned short datum;
+        int done = 0;
+        
+        for(; done < len && smp->NoOfSamps; done++, smp->NoOfSamps--) {
+                st_readw(ft, &datum);
+                /* scale signed up to long's range */
+                *buf++ = ST_SIGNED_WORD_TO_SAMPLE(datum);
+        }
+        return done;
 }
 
 /*
@@ -343,75 +343,75 @@
 
 int st_smpstartwrite(ft_t ft) 
 {
-	smp_t smp = (smp_t) ft->priv;
-	struct smpheader header;
+        smp_t smp = (smp_t) ft->priv;
+        struct smpheader header;
 
-	/* SMP is in Little Endian format.  Swap whats read in on */
-	/* Big Endian machines.			                  */
-	if (ST_IS_BIGENDIAN)
-	{
-		ft->swap = ft->swap ? 0 : 1;
-	}
+        /* SMP is in Little Endian format.  Swap whats read in on */
+        /* Big Endian machines.                                   */
+        if (ST_IS_BIGENDIAN)
+        {
+                ft->swap = ft->swap ? 0 : 1;
+        }
 
-	/* If you have to seek around the output file */
-	if (! ft->seekable)
-	{
-		st_fail_errno(ft,ST_EOF,"Output .smp file must be a file, not a pipe");
-		return(ST_EOF);
-	}
+        /* If you have to seek around the output file */
+        if (! ft->seekable)
+        {
+                st_fail_errno(ft,ST_EOF,"Output .smp file must be a file, not a pipe");
+                return(ST_EOF);
+        }
 
-	/* If your format specifies any of the following info. */
-	ft->info.size = ST_SIZE_WORD;
-	ft->info.encoding = ST_ENCODING_SIGN2;
-	ft->info.channels = 1;
+        /* If your format specifies any of the following info. */
+        ft->info.size = ST_SIZE_WORD;
+        ft->info.encoding = ST_ENCODING_SIGN2;
+        ft->info.channels = 1;
 
-	strcpy(header.Id, SVmagic);
-	strcpy(header.version, SVvers);
-	sprintf(header.comments, "%-*s", COMMENTLEN, "Converted using Sox.");
-	sprintf(header.name, "%-*.*s", NAMELEN, NAMELEN, ft->comment);
+        strcpy(header.Id, SVmagic);
+        strcpy(header.version, SVvers);
+        sprintf(header.comments, "%-*s", COMMENTLEN, "Converted using Sox.");
+        sprintf(header.name, "%-*.*s", NAMELEN, NAMELEN, ft->comment);
 
-	/* Write file header */
-	if(fwrite(&header, 1, HEADERSIZE, ft->fp) != HEADERSIZE)
-	{
-	    st_fail_errno(ft,errno,"SMP: Can't write header completely");
-	    return(ST_EOF);
-	}
-	st_writedw(ft, 0);	/* write as zero length for now, update later */
-	smp->NoOfSamps = 0;
+        /* Write file header */
+        if(fwrite(&header, 1, HEADERSIZE, ft->fp) != HEADERSIZE)
+        {
+            st_fail_errno(ft,errno,"SMP: Can't write header completely");
+            return(ST_EOF);
+        }
+        st_writedw(ft, 0);      /* write as zero length for now, update later */
+        smp->NoOfSamps = 0;
 
-	return(ST_SUCCESS);
+        return(ST_SUCCESS);
 }
 
 st_ssize_t st_smpwrite(ft_t ft, st_sample_t *buf, st_ssize_t len) 
 {
-	smp_t smp = (smp_t) ft->priv;
-	register int datum;
-	st_ssize_t done = 0;
+        smp_t smp = (smp_t) ft->priv;
+        register int datum;
+        st_ssize_t done = 0;
 
-	while(done < len) {
-		datum = (int) ST_SAMPLE_TO_SIGNED_WORD(*buf++);
-		st_writew(ft, datum);
-		smp->NoOfSamps++;
-		done++;
-	}
+        while(done < len) {
+                datum = (int) ST_SAMPLE_TO_SIGNED_WORD(*buf++);
+                st_writew(ft, datum);
+                smp->NoOfSamps++;
+                done++;
+        }
 
-	return(done);
+        return(done);
 }
 
 int st_smpstopwrite(ft_t ft) 
 {
-	smp_t smp = (smp_t) ft->priv;
-	struct smptrailer trailer;
+        smp_t smp = (smp_t) ft->priv;
+        struct smptrailer trailer;
 
-	/* Assign the trailer data */
-	settrailer(ft, &trailer, ft->info.rate);
-	writetrailer(ft, &trailer);
-	if (fseek(ft->fp, 112, 0) == -1)
-	{
-		st_fail_errno(ft,errno,"SMP unable to seek back to save size");
-		return(ST_EOF);
-	}
-	st_writedw(ft, smp->NoOfSamps);
+        /* Assign the trailer data */
+        settrailer(ft, &trailer, ft->info.rate);
+        writetrailer(ft, &trailer);
+        if (fseek(ft->fp, 112, 0) == -1)
+        {
+                st_fail_errno(ft,errno,"SMP unable to seek back to save size");
+                return(ST_EOF);
+        }
+        st_writedw(ft, smp->NoOfSamps);
 
-	return(ST_SUCCESS);
+        return(ST_SUCCESS);
 }
--- a/src/wve.c
+++ b/src/wve.c
@@ -41,7 +41,7 @@
         short version;
         int rc;
 
-        uint32_t trash;
+        uint16_t trash16;
 
         /* Needed for rawread() */
         rc = st_rawstartread(ft);
@@ -95,9 +95,9 @@
 
         st_readw(ft, (unsigned short *)&(p->repeats));
 
-        (void)st_readw(ft, (unsigned short *)&trash);
-        (void)st_readw(ft, (unsigned short *)&trash);
-        (void)st_readw(ft, (unsigned short *)&trash);
+        (void)st_readw(ft, (unsigned short *)&trash16);
+        (void)st_readw(ft, (unsigned short *)&trash16);
+        (void)st_readw(ft, (unsigned short *)&trash16);
 
         ft->info.encoding = ST_ENCODING_ALAW;
         ft->info.size = ST_SIZE_BYTE;