ref: d8c8e7b910b05f6e13d4ffb5baa634b13d06afaa
parent: f81d531edaf51e7013ba7753ab3fcea5860fbe86
author: cbagwell <cbagwell>
date: Tue Dec 28 13:35:33 EST 1999
First round at converting file handlers to use return codes instead of fail().
--- a/TODO
+++ b/TODO
@@ -3,6 +3,9 @@
o SJB: The old highp.c filter is IMHO broken, need to review that code.
+ o All comment code has a memory leak. They must malloc memory to
+ store comment but its never free()'d.
+
o Create a version of OSS and Sun driver that can play and record from the
same device in duplex.
--- a/sfheader.h
+++ /dev/null
@@ -1,120 +1,0 @@
-# define SIZEOF_BSD_HEADER 1024
-# define SF_MAGIC 107364
-# define SF_LINK 107414
-# define SF_SHORT sizeof(short)
-# define SF_FLOAT sizeof(float)
-# define SF_BUFSIZE (16*1024)
-# define SF_MAXCHAN 4
-# define MAXCOMM 512
-# define MINCOMM 256
-
-/* Codes for sfcode */
-# define SF_END 0
-# define SF_MAXAMP 1
-# define SF_COMMENT 2
-# define SF_LINKCODE 3
-
-typedef struct sfcode {
- short code;
- short bsize;
-} SFCODE;
-
-typedef struct sfmaxamp {
- float value[SF_MAXCHAN];
- LONG samploc[SF_MAXCHAN];
- LONG timetag;
-} SFMAXAMP;
-
-typedef struct sfcomment {
- char comment[MAXCOMM];
-} SFCOMMENT;
-
-typedef struct sflink {
- char reality[50];
- LONG startsamp;
- LONG endsamp;
-} SFLINK;
-
-struct sfinfo {
- LONG sf_magic;
- float sf_srate;
- LONG sf_chans;
- LONG sf_packmode;
-/* char sf_codes; /* BOGUS! */
- SFCODE sf_codes;
-} ;
-
-typedef union sfheader {
- struct sfinfo sfinfo;
- char filler[SIZEOF_BSD_HEADER];
-} SFHEADER;
-
-static SFCODE ampcode = {
-SF_MAXAMP,
-sizeof(SFMAXAMP) + sizeof(SFCODE)
-};
-
-# define sfchans(x) (x)->sfinfo.sf_chans
-# define sfmagic(x) (x)->sfinfo.sf_magic
-# define sfsrate(x) (x)->sfinfo.sf_srate
-# define sfclass(x) (x)->sfinfo.sf_packmode
-# define sfbsize(x) ((x)->st_size - sizeof(SFHEADER))
-# define sfcodes(x) (x)->sfinfo.sf_codes
-
-# define ismagic(x) ((x)->sfinfo.sf_magic == SF_MAGIC)
-# define islink(x) ((x)->sfinfo.sf_magic == SF_LINK)
-
-# define sfmaxamp(mptr,chan) (mptr)->value[chan]
-# define sfmaxamploc(mptr,chan) (mptr)->samploc[chan]
-# define sfmaxamptime(x) (x)->timetag
-# define ismaxampgood(x,s) (sfmaxamptime(x) + 2 >= (s)->st_mtime)
-
-# define sfcomm(x,n) (x)->comment[n]
-
-# define realname(x) (x)->reality
-# define startsmp(x) (x)->startsamp
-# define endsmp(x) (x)->endsamp
-# define sfoffset(x,h) ((x)->startsamp * sfchans(h) * sfclass(h))
-# define sfendset(x,h) ((x)->endsamp * sfchans(h) * sfclass(h))
-
-# define sflseek(x,y,z) lseek(x,(z != 0) ? y : ((y) + sizeof(SFHEADER)),z)
-# define rheader(x,y) read(x,(char *) y,sizeof(SFHEADER)) != sizeof(SFHEADER)
-
-#define readopensf(name,fd,sfh,sfst,prog,result) \
-if ((fd = open(name, 0)) < 0) { \
- fprintf(stderr,"%s: cannot access file %s\n",prog,name); \
- result = -1; \
-} \
-else if (stat(name,&sfst)){ \
- fprintf(stderr,"%s: cannot get status on %s\n",prog,name); \
- result = -1; \
-} \
-else if (rheader(fd,&sfh)){ \
- fprintf(stderr,"%s: cannot read header from %s\n",prog,name); \
- result = -1; \
-} \
-else if (!ismagic(&sfh)){ \
- fprintf(stderr,"%s: %s not a bsd soundfile\n",prog,name); \
- result = -1; \
-} \
-else result = 0;
-
-#define rwopensf(name,fd,sfh,sfst,prog,result,code) \
-if ((fd = open(name, code)) < 0) { \
- fprintf(stderr,"%s: cannot access file %s\n",prog,name); \
- result = -1; \
-} \
-else if (rheader(fd,&sfh)){ \
- fprintf(stderr,"%s: cannot read header from %s\n",prog,name); \
- result = -1; \
-} \
-else if (!ismagic(&sfh)){ \
- fprintf(stderr,"%s: %s not a bsd soundfile\n",prog,name); \
- result = -1; \
-} \
-else if (stat(name,&sfst)){ \
- fprintf(stderr,"%s: cannot get status on %s\n",prog,name); \
- result = -1; \
-} \
-else result = 0;
-
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -26,7 +26,7 @@
/* 8SVXSTARTREAD */
/*======================================================================*/
-void svxstartread(ft)
+int st_svxstartread(ft)
ft_t ft;
{
struct svxpriv *p = (struct svxpriv *) ft->priv;
@@ -59,10 +59,16 @@
/* read FORM chunk */
if (fread(buf, 1, 4, ft->fp) != 4 || strncmp(buf, "FORM", 4) != 0)
+ {
fail("8SVX: header does not begin with magic word 'FORM'");
+ return(ST_EOF);
+ }
totalsize = rlong(ft);
if (fread(buf, 1, 4, ft->fp) != 4 || strncmp(buf, "8SVX", 4) != 0)
+ {
fail("8SVX: 'FORM' chunk does not specify '8SVX' as type");
+ return(ST_EOF);
+ }
/* read chunks until 'BODY' (or end) */
while (fread(buf,1,4,ft->fp) == 4 && strncmp(buf,"BODY",4) != 0) {
@@ -69,13 +75,19 @@
if (strncmp(buf,"VHDR",4) == 0) {
chunksize = rlong(ft);
if (chunksize != 20)
+ {
fail ("8SVX: VHDR chunk has bad size");
+ return(ST_EOF);
+ }
fseek(ft->fp,12,SEEK_CUR);
rate = rshort(ft);
fseek(ft->fp,1,SEEK_CUR);
fread(buf,1,1,ft->fp);
if (buf[0] != 0)
+ {
fail ("8SVX: unsupported data compression");
+ return(ST_EOF);
+ }
fseek(ft->fp,4,SEEK_CUR);
continue;
}
@@ -84,10 +96,18 @@
chunksize = rlong(ft);
if (chunksize & 1)
chunksize++;
- chunk_buf = (char *) malloc(chunksize + 1);
+ chunk_buf = (char *) malloc(chunksize + 2);
+ if (chunk_buf == 0)
+ {
+ fail("Couldn't alloc resources");
+ return(ST_EOF);
+ }
if (fread(chunk_buf,1,(size_t)chunksize,ft->fp)
!= chunksize)
+ {
fail("8SVX: Unexpected EOF in ANNO header");
+ return(ST_EOF);
+ }
chunk_buf[chunksize] = '\0';
report ("%s",chunk_buf);
free(chunk_buf);
@@ -100,9 +120,17 @@
if (chunksize & 1)
chunksize++;
chunk_buf = (char *) malloc(chunksize + 1);
+ if (chunk_buf == 0)
+ {
+ fail("Couldn't alloc resources");
+ return(ST_EOF);
+ }
if (fread (chunk_buf,1,(size_t)chunksize,ft->fp)
!= chunksize)
+ {
fail("8SVX: Unexpected EOF in NAME header");
+ return(ST_EOF);
+ }
chunk_buf[chunksize] = '\0';
report ("%s",chunk_buf);
free(chunk_buf);
@@ -113,7 +141,10 @@
if (strncmp(buf,"CHAN",4) == 0) {
chunksize = rlong(ft);
if (chunksize != 4)
+ {
fail("8SVX: Short channel chunk");
+ return(ST_EOF);
+ }
channels = rlong(ft);
channels = (channels & 0x01) +
((channels & 0x02) >> 1) +
@@ -133,15 +164,21 @@
}
if (rate == 0)
+ {
fail ("8SVX: invalid rate");
+ return(ST_EOF);
+ }
if (strncmp(buf,"BODY",4) != 0)
+ {
fail ("8SVX: BODY chunk not found");
+ return(ST_EOF);
+ }
p->nsamples = rlong(ft);
ft->info.channels = channels;
ft->info.rate = rate;
- ft->info.style = SIGN2;
- ft->info.size = BYTE;
+ ft->info.style = ST_ENCODING_SIGN2;
+ ft->info.size = ST_SIZE_BYTE;
/* open files to channels */
p->ch[0] = ft->fp;
@@ -149,21 +186,31 @@
for (i = 1; i < channels; i++) {
if ((p->ch[i] = fopen(ft->filename, READBINARY)) == NULL)
+ {
fail("Can't open channel file '%s': %s",
ft->filename, strerror(errno));
+ return(ST_EOF);
+ }
/* position channel files */
if (fseek(p->ch[i],chan1_pos,SEEK_SET))
+ {
fail ("Can't position channel %d: %s",i,strerror(errno));
+ return(ST_EOF);
+ }
if (fseek(p->ch[i],p->nsamples/channels*i,SEEK_CUR))
+ {
fail ("Can't seek channel %d: %s",i,strerror(errno));
+ return(ST_EOF);
+ }
}
+ return(ST_SUCCESS);
}
/*======================================================================*/
/* 8SVXREAD */
/*======================================================================*/
-LONG svxread(ft, buf, nsamp)
+LONG st_svxread(ft, buf, nsamp)
ft_t ft;
LONG *buf, nsamp;
{
@@ -189,7 +236,7 @@
/*======================================================================*/
/* 8SVXSTOPREAD */
/*======================================================================*/
-void svxstopread(ft)
+int st_svxstopread(ft)
ft_t ft;
{
int i;
@@ -200,12 +247,13 @@
for (i = 1; i < ft->info.channels; i++) {
fclose (p->ch[i]);
}
+ return(ST_SUCCESS);
}
/*======================================================================*/
/* 8SVXSTARTWRITE */
/*======================================================================*/
-void svxstartwrite(ft)
+int st_svxstartwrite(ft)
ft_t ft;
{
struct svxpriv *p = (struct svxpriv *) ft->priv;
@@ -227,16 +275,20 @@
p->ch[0] = ft->fp;
for (i = 1; i < ft->info.channels; i++) {
if ((p->ch[i] = tmpfile()) == NULL)
+ {
fail("Can't open channel output file: %s",
strerror(errno));
+ return(ST_EOF);
+ }
}
/* write header (channel 0) */
- ft->info.style = SIGN2;
- ft->info.size = BYTE;
+ ft->info.style = ST_ENCODING_SIGN2;
+ ft->info.size = ST_SIZE_BYTE;
p->nsamples = 0;
svxwriteheader(ft, p->nsamples);
+ return(ST_SUCCESS);
}
/*======================================================================*/
@@ -243,7 +295,7 @@
/* 8SVXWRITE */
/*======================================================================*/
-void svxwrite(ft, buf, len)
+LONG st_svxwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
@@ -262,6 +314,7 @@
}
done += ft->info.channels;
}
+ return (done);
}
/*======================================================================*/
@@ -268,7 +321,7 @@
/* 8SVXSTOPWRITE */
/*======================================================================*/
-void svxstopwrite(ft)
+int st_svxstopwrite(ft)
ft_t ft;
{
struct svxpriv *p = (struct svxpriv *) ft->priv;
@@ -281,7 +334,10 @@
/* close temp files */
for (i = 1; i < ft->info.channels; i++) {
if (fseek (p->ch[i], 0L, 0))
+ {
fail ("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]);
@@ -295,8 +351,12 @@
/* fixup file sizes in header */
if (fseek(ft->fp, 0L, 0) != 0)
+ {
fail("can't rewind output file to rewrite 8SVX header");
+ return(ST_EOF);
+ }
svxwriteheader(ft, p->nsamples);
+ return(ST_SUCCESS);
}
/*======================================================================*/
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -55,14 +55,14 @@
/* forward declarations */
static double read_ieee_extended(P1(ft_t));
-static void aiffwriteheader(P2(ft_t, LONG));
+static int aiffwriteheader(P2(ft_t, LONG));
static void write_ieee_extended(P2(ft_t, double));
static double ConvertFromIeeeExtended(P1(unsigned char*));
static void ConvertToIeeeExtended(P2(double, char *));
-static void textChunk(P3(char **text, char *chunkDescription, ft_t ft));
+static int textChunk(P3(char **text, char *chunkDescription, ft_t ft));
static void reportInstrument(P1(ft_t ft));
-void aiffstartread(ft)
+int st_aiffstartread(ft)
ft_t ft;
{
struct aiffpriv *p = (struct aiffpriv *) ft->priv;
@@ -91,9 +91,13 @@
char *copyright;
char *nametext;
- /* Needed because of rawread() */
- rawstartread(ft);
+ int rc;
+ /* Needed because of st_rawread() */
+ rc = st_rawstartread(ft);
+ if (rc)
+ return rc;
+
/* AIFF is in Big Endian format. Swap whats read in on Little */
/* Endian machines. */
endptr = (char *) &littlendian;
@@ -104,10 +108,16 @@
/* FORM chunk */
if (fread(buf, 1, 4, ft->fp) != 4 || strncmp(buf, "FORM", 4) != 0)
+ {
fail("AIFF header does not begin with magic word 'FORM'");
+ return(ST_EOF);
+ }
totalsize = rlong(ft);
if (fread(buf, 1, 4, ft->fp) != 4 || strncmp(buf, "AIFF", 4) != 0)
+ {
fail("AIFF 'FORM' chunk does not specify 'AIFF' as type");
+ return(ST_EOF);
+ }
/* Skip everything but the COMM chunk and the SSND chunk */
@@ -118,13 +128,19 @@
if (ssndsize > 0)
break;
else
+ {
fail("Missing SSND chunk in AIFF file");
+ return(ST_EOF);
+ }
}
if (strncmp(buf, "COMM", 4) == 0) {
/* COMM chunk */
chunksize = rlong(ft);
if (chunksize != 18)
+ {
fail("AIFF COMM chunk has bad size");
+ return(ST_EOF);
+ }
channels = rshort(ft);
frames = rlong(ft);
bits = rshort(ft);
@@ -227,23 +243,44 @@
/* allocate enough memory to hold the comment */
ft->comment = (char *) malloc((size_t) chunksize);
if (ft->comment == NULL)
+ {
fail("AIFF: Couldn't allocate ANNO header");
+ return(ST_EOF);
+ }
if (fread(ft->comment, 1, chunksize, ft->fp) != chunksize)
+ {
fail("AIFF: Unexpected EOF in ANNO header");
+ return(ST_EOF);
+ }
}
else if (strncmp(buf, "AUTH", 4) == 0) {
/* Author chunk */
- textChunk(&author, "Author:", ft);
+ rc = textChunk(&author, "Author:", ft);
+ if (rc)
+ {
+ /* Fail already called in function */
+ return(ST_EOF);
+ }
free(author);
}
else if (strncmp(buf, "NAME", 4) == 0) {
/* Name chunk */
- textChunk(&nametext, "Name:", ft);
+ rc = textChunk(&nametext, "Name:", ft);
+ if (rc)
+ {
+ /* Fail already called in function */
+ return(ST_EOF);
+ }
free(nametext);
}
else if (strncmp(buf, "(c) ", 4) == 0) {
/* Copyright chunk */
- textChunk(©right, "Copyright:", ft);
+ rc = textChunk(©right, "Copyright:", ft);
+ if (rc)
+ {
+ /* Fail already called in function */
+ return(ST_EOF);
+ }
free(copyright);
}
else {
@@ -280,29 +317,39 @@
if (seekto > 0)
fseek(ft->fp, seekto, SEEK_SET);
else
+ {
fail("AIFF: no sound data on input file");
+ return(ST_EOF);
+ }
}
/* SSND chunk just read */
if (blocksize != 0)
+ {
fail("AIFF header specifies nonzero blocksize?!?!");
+ return(ST_EOF);
+ }
while ((LONG) (--offset) >= 0) {
if (getc(ft->fp) == EOF)
+ {
fail("unexpected EOF while skipping AIFF offset");
+ return(ST_EOF);
+ }
}
if (foundcomm) {
ft->info.channels = channels;
ft->info.rate = rate;
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
switch (bits) {
case 8:
- ft->info.size = BYTE;
+ ft->info.size = ST_SIZE_BYTE;
break;
case 16:
- ft->info.size = WORD;
+ ft->info.size = ST_SIZE_WORD;
break;
default:
fail("unsupported sample size in AIFF header: %d", bits);
+ return(ST_EOF);
/*NOTREACHED*/
}
} else {
@@ -313,6 +360,7 @@
report("You must specify # channels, sample rate, signed/unsigned,\n");
report("and 8/16 on the command line.");
fail("Bogus AIFF file: no COMM section.");
+ return(ST_EOF);
}
}
@@ -320,9 +368,15 @@
p->nsamples = ssndsize / ft->info.size; /* leave out channels */
if (foundmark && !foundinstr)
+ {
fail("Bogus AIFF file: MARKers but no INSTrument.");
+ return(ST_EOF);
+ }
if (!foundmark && foundinstr)
+ {
fail("Bogus AIFF file: INSTrument but no MARKers.");
+ return(ST_EOF);
+ }
if (foundmark && foundinstr) {
int i;
int slbIndex = 0, sleIndex = 0;
@@ -347,7 +401,7 @@
marks[sleIndex].position - marks[slbIndex].position;
/* really the loop count should be infinite */
ft->loops[0].count = 1;
- ft->instr.loopmode = LOOP_SUSTAIN_DECAY | ft->loops[0].type;
+ ft->instr.loopmode = ST_LOOP_SUSTAIN_DECAY | ft->loops[0].type;
ft->instr.nloops++;
}
if (ft->loops[1].type != 0) {
@@ -356,12 +410,14 @@
marks[rleIndex].position - marks[rlbIndex].position;
/* really the loop count should be infinite */
ft->loops[1].count = 1;
- ft->instr.loopmode = LOOP_SUSTAIN_DECAY | ft->loops[1].type;
+ ft->instr.loopmode = ST_LOOP_SUSTAIN_DECAY | ft->loops[1].type;
ft->instr.nloops++;
}
}
if (verbose)
reportInstrument(ft);
+
+ return(ST_SUCCESS);
}
/* print out the MIDI key allocations, loop points, directions etc */
@@ -379,7 +435,7 @@
ft->loops[loopNum].start + ft->loops[loopNum].length);
fprintf(stderr, " count: %6d", ft->loops[loopNum].count);
fprintf(stderr, " type: ");
- switch(ft->loops[loopNum].type & ~LOOP_SUSTAIN_DECAY) {
+ switch(ft->loops[loopNum].type & ~ST_LOOP_SUSTAIN_DECAY) {
case 0: fprintf(stderr, "off\n"); break;
case 1: fprintf(stderr, "forward\n"); break;
case 2: fprintf(stderr, "forward/backward\n"); break;
@@ -392,7 +448,7 @@
}
/* Process a text chunk, allocate memory, display it if verbose and return */
-static void textChunk(text, chunkDescription, ft)
+static int textChunk(text, chunkDescription, ft)
char **text;
char *chunkDescription;
ft_t ft;
@@ -401,16 +457,23 @@
/* allocate enough memory to hold the text including a terminating \0 */
*text = (char *) malloc((size_t) chunksize + 1);
if (*text == NULL)
+ {
fail("AIFF: Couldn't allocate %s header", chunkDescription);
+ return(ST_EOF);
+ }
if (fread(*text, 1, chunksize, ft->fp) != chunksize)
+ {
fail("AIFF: Unexpected EOF in %s header", chunkDescription);
+ return(ST_EOF);
+ }
*(*text + chunksize) = '\0';
if(verbose) {
printf("%-10s \"%s\"\n", chunkDescription, *text);
}
+ return(ST_SUCCESS);
}
-LONG aiffread(ft, buf, len)
+LONG st_aiffread(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
@@ -419,12 +482,12 @@
/* just read what's left of SSND chunk */
if (len > p->nsamples)
len = p->nsamples;
- rawread(ft, buf, len);
+ st_rawread(ft, buf, len);
p->nsamples -= len;
return len;
}
-void aiffstopread(ft)
+int st_aiffstopread(ft)
ft_t ft;
{
char buf[5];
@@ -453,10 +516,8 @@
}
}
- /* Needed because of rawwrite() */
- rawstopread(ft);
-
- return;
+ /* Needed because of st_rawwrite() */
+ return st_rawstopread(ft);
}
/* When writing, the header is supposed to contain the number of
@@ -469,15 +530,18 @@
Strictly spoken this is not legal, but the playaiff utility
will still be able to play the resulting file. */
-void aiffstartwrite(ft)
+int st_aiffstartwrite(ft)
ft_t ft;
{
struct aiffpriv *p = (struct aiffpriv *) ft->priv;
int littlendian;
char *endptr;
+ int rc;
- /* Needed because rawwrite() */
- rawstartwrite(ft);
+ /* Needed because st_rawwrite() */
+ rc = st_rawstartwrite(ft);
+ if (rc)
+ return rc;
/* AIFF is in Big Endian format. Swap whats read in on Little */
/* Endian machines. */
@@ -489,11 +553,13 @@
}
p->nsamples = 0;
- if (ft->info.style == ULAW && ft->info.size == BYTE) {
+ if ((ft->info.style == ST_ENCODING_ULAW ||
+ ft->info.style == ST_ENCODING_ALAW) &&
+ ft->info.size == ST_SIZE_BYTE) {
report("expanding 8-bit u-law to 16 bits");
- ft->info.size = WORD;
+ ft->info.size = ST_SIZE_WORD;
}
- ft->info.style = SIGN2; /* We have a fixed style */
+ ft->info.style = ST_ENCODING_SIGN2; /* We have a fixed style */
/* Compute the "very large number" so that a maximum number
of samples can be transmitted through a pipe without the
@@ -501,37 +567,46 @@
At 48 kHz, 16 bits stereo, this gives ~3 hours of music.
Sorry, the AIFF format does not provide for an "infinite"
number of samples. */
- aiffwriteheader(ft, 0x7f000000L / (ft->info.size*ft->info.channels));
+ return(aiffwriteheader(ft, 0x7f000000L / (ft->info.size*ft->info.channels)));
}
-void aiffwrite(ft, buf, len)
+LONG st_aiffwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
struct aiffpriv *p = (struct aiffpriv *) ft->priv;
p->nsamples += len;
- rawwrite(ft, buf, len);
+ st_rawwrite(ft, buf, len);
+ return(len);
}
-void
-aiffstopwrite(ft)
+int st_aiffstopwrite(ft)
ft_t ft;
{
struct aiffpriv *p = (struct aiffpriv *) ft->priv;
+ int rc;
- /* Needed because of rawwrite(). Call now to flush
+ /* Needed because of st_rawwrite(). Call now to flush
* buffer now before seeking around below.
*/
- rawstopwrite(ft);
+ rc = st_rawstopwrite(ft);
+ if (rc)
+ return rc;
if (!ft->seekable)
- return;
+ {
+ fail("Non-seekable file.");
+ return(ST_EOF);
+ }
if (fseek(ft->fp, 0L, SEEK_SET) != 0)
+ {
fail("can't rewind output file to rewrite AIFF header");
- aiffwriteheader(ft, p->nsamples / ft->info.channels);
+ return(ST_EOF);
+ }
+ return(aiffwriteheader(ft, p->nsamples / ft->info.channels));
}
-static void aiffwriteheader(ft, nframes)
+static int aiffwriteheader(ft, nframes)
ft_t ft;
LONG nframes;
{
@@ -545,12 +620,17 @@
hsize += 8 + 2 + 16*ft->instr.nloops; /* MARK chunk */
hsize += 20; /* INST chunk */
- if (ft->info.style == SIGN2 && ft->info.size == BYTE)
+ if (ft->info.style == ST_ENCODING_SIGN2 &&
+ ft->info.size == ST_SIZE_BYTE)
bits = 8;
- else if (ft->info.style == SIGN2 && ft->info.size == WORD)
+ else if (ft->info.style == ST_ENCODING_SIGN2 &&
+ ft->info.size == ST_SIZE_WORD)
bits = 16;
else
+ {
fail("unsupported output style/size for AIFF header");
+ return(ST_EOF);
+ }
fputs("FORM", ft->fp); /* IFF header */
wlong(ft, hsize + nframes * ft->info.size * ft->info.channels); /* file size */
@@ -632,6 +712,7 @@
wlong(ft, 8 + nframes * ft->info.channels * ft->info.size);
wlong(ft, (LONG) 0); /* offset */
wlong(ft, (LONG) 0); /* block size */
+ return(ST_SUCCESS);
}
static double read_ieee_extended(ft)
@@ -639,7 +720,10 @@
{
char buf[10];
if (fread(buf, 1, 10, ft->fp) != 10)
+ {
fail("EOF while reading IEEE extended number");
+ return(ST_EOF);
+ }
return ConvertFromIeeeExtended(buf);
}
--- a/src/alsa.c
+++ b/src/alsa.c
@@ -29,7 +29,7 @@
* size and style of samples,
* mono/stereo/quad.
*/
-void alsastartread(ft)
+int st_alsastartread(ft)
ft_t ft;
{
int bps, fmt, size;
@@ -45,6 +45,7 @@
ft->file.size = c_info.buffer_size;
if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
fail("unable to allocate output buffer of size %d", ft->file.size);
+ return (ST_EOF)
}
if (ft->info.rate < c_info.min_rate) ft->info.rate = 2 * c_info.min_rate;
else if (ft->info.rate > c_info.max_rate) ft->info.rate = c_info.max_rate;
@@ -52,25 +53,25 @@
else if (ft->info.channels > c_info.max_channels) ft->info.channels = c_info.max_channels;
if (ft->info.size == -1) {
if ((c_info.hw_formats & SND_PCM_FMT_U8) || (c_info.hw_formats & SND_PCM_FMT_S8))
- ft->info.size = BYTE;
+ ft->info.size = ST_SIZE_BYTE;
else
- ft->info.size = WORD;
+ ft->info.size = ST_SIZE_WORD;
}
if (ft->info.style == -1) {
if ((c_info.hw_formats & SND_PCM_FMT_S16_LE) || (c_info.hw_formats & SND_PCM_FMT_S8))
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
else
- ft->info.style = UNSIGNED;
+ ft->info.style = ST_ENCODING_UNSIGNED;
}
- if (ft->info.size == BYTE) {
+ if (ft->info.size == ST_SIZE_BYTE) {
switch (ft->info.style)
{
- case SIGN2:
+ case ST_ENCODING_SIGN2:
if (!(c_info.hw_formats & SND_PCM_FMT_S8))
fail("ALSA driver does not support signed byte samples");
fmt = SND_PCM_SFMT_S8;
break;
- case UNSIGNED:
+ case ST_ENCODING_UNSIGNED:
if (!(c_info.hw_formats & SND_PCM_FMT_U8))
fail("ALSA driver does not support unsigned byte samples");
fmt = SND_PCM_SFMT_U8;
@@ -77,6 +78,7 @@
break;
default:
fail("Hardware does not support %s output", styles[ft->info.style]);
+ return(ST_EOF);
break;
}
}
@@ -83,12 +85,12 @@
else {
switch (ft->info.style)
{
- case SIGN2:
+ case ST_ENCODING_SIGN2:
if (!(c_info.hw_formats & SND_PCM_FMT_S16_LE))
fail("ALSA driver does not support signed word samples");
fmt = SND_PCM_SFMT_S16_LE;
break;
- case UNSIGNED:
+ case ST_ENCODING_UNSIGNED:
if (!(c_info.hw_formats & SND_PCM_FMT_U16_LE))
fail("ALSA driver does not support unsigned word samples");
fmt = SND_PCM_SFMT_U16_LE;
@@ -95,6 +97,7 @@
break;
default:
fail("Hardware does not support %s output", styles[ft->info.style]);
+ return(ST_EOF);
break;
}
}
@@ -120,9 +123,11 @@
setvbuf(ft->fp, NULL, _IONBF, sizeof(char) * ft->file.size);
sigintreg(ft); /* Prepare to catch SIGINT */
+
+ return (ST_SUCCESS);
}
-void alsastartwrite(ft)
+int st_alsastartwrite(ft)
ft_t ft;
{
int bps, fmt, size;
@@ -137,6 +142,7 @@
ft->file.size = p_info.buffer_size;
if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
fail("unable to allocate output buffer of size %d", ft->file.size);
+ return(ST_EOF);
}
if (ft->info.rate < p_info.min_rate) ft->info.rate = 2 * p_info.min_rate;
else if (ft->info.rate > p_info.max_rate) ft->info.rate = p_info.max_rate;
@@ -144,25 +150,25 @@
else if (ft->info.channels > p_info.max_channels) ft->info.channels = p_info.max_channels;
if (ft->info.size == -1) {
if ((p_info.hw_formats & SND_PCM_FMT_U8) || (p_info.hw_formats & SND_PCM_FMT_S8))
- ft->info.size = BYTE;
+ ft->info.size = ST_SIZE_BYTE;
else
- ft->info.size = WORD;
+ ft->info.size = ST_SIZE_WORD;
}
if (ft->info.style == -1) {
if ((p_info.hw_formats & SND_PCM_FMT_S16_LE) || (p_info.hw_formats & SND_PCM_FMT_S8))
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
else
- ft->info.style = UNSIGNED;
+ ft->info.style = ST_ENCODING_UNSIGNED;
}
- if (ft->info.size == BYTE) {
+ if (ft->info.size == ST_SIZE_BYTE) {
switch (ft->info.style)
{
- case SIGN2:
+ case ST_ENCODING_SIGN2:
if (!(p_info.hw_formats & SND_PCM_FMT_S8))
fail("ALSA driver does not support signed byte samples");
fmt = SND_PCM_SFMT_S8;
break;
- case UNSIGNED:
+ case ST_ENCODING_UNSIGNED:
if (!(p_info.hw_formats & SND_PCM_FMT_U8))
fail("ALSA driver does not support unsigned byte samples");
fmt = SND_PCM_SFMT_U8;
@@ -169,6 +175,7 @@
break;
default:
fail("Hardware does not support %s output", styles[ft->info.style]);
+ return(ST_EOF);
break;
}
}
@@ -175,12 +182,12 @@
else {
switch (ft->info.style)
{
- case SIGN2:
+ case ST_ENCODING_SIGN2:
if (!(p_info.hw_formats & SND_PCM_FMT_S16_LE))
fail("ALSA driver does not support signed word samples");
fmt = SND_PCM_SFMT_S16_LE;
break;
- case UNSIGNED:
+ case ST_ENCODING_UNSIGNED:
if (!(p_info.hw_formats & SND_PCM_FMT_U16_LE))
fail("ALSA driver does not support unsigned word samples");
fmt = SND_PCM_SFMT_U16_LE;
@@ -187,6 +194,7 @@
break;
default:
fail("Hardware does not support %s output", styles[ft->info.style]);
+ return(ST_EOF);
break;
}
}
--- a/src/au.c
+++ b/src/au.c
@@ -57,7 +57,7 @@
static void auwriteheader(P2(ft_t ft, ULONG data_size));
-void austartread(ft)
+int st_austartread(ft)
ft_t ft;
{
/* The following 6 variables represent a Sun sound header on disk.
@@ -78,9 +78,12 @@
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed for rawread() */
- rawstartread(ft);
+ rc = st_rawstartread(ft);
+ if (rc)
+ return rc;
endptr = (char *) &littlendian;
/* AU is in big endian format. Swap whats read
@@ -91,12 +94,6 @@
ft->swap = ft->swap ? 0 : 1;
}
- /* Sanity check */
- if (sizeof(struct aupriv) > PRIVSIZE)
- fail(
-"struct aupriv is too big (%d); change PRIVSIZE in st.h and recompile sox",
- sizeof(struct aupriv));
-
/* Check the magic word */
magic = rlong(ft);
if (magic == DEC_INV_MAGIC) {
@@ -118,12 +115,18 @@
report("Found DEC magic word");
}
else
+ {
fail("Sun/NeXT/DEC header doesn't start with magic word\nTry the '.ul' file type with '-t ul -r 8000 filename'");
+ return(ST_EOF);
+ }
/* Read the header size */
hdr_size = rlong(ft);
if (hdr_size < SUN_HDRSIZE)
+ {
fail("Sun/NeXT header size too small.");
+ return(0);
+ }
/* Read the data size; may be ~0 meaning unspecified */
data_size = rlong(ft);
@@ -139,37 +142,37 @@
p->in_bits = 0;
switch (encoding) {
case SUN_ULAW:
- ft->info.style = ULAW;
- ft->info.size = BYTE;
+ ft->info.style = ST_ENCODING_ULAW;
+ ft->info.size = ST_SIZE_BYTE;
break;
case SUN_ALAW:
- ft->info.style = ALAW;
- ft->info.size = BYTE;
+ ft->info.style = ST_ENCODING_ALAW;
+ ft->info.size = ST_SIZE_BYTE;
case SUN_LIN_8:
- ft->info.style = SIGN2;
- ft->info.size = BYTE;
+ ft->info.style = ST_ENCODING_SIGN2;
+ ft->info.size = ST_SIZE_BYTE;
break;
case SUN_LIN_16:
- ft->info.style = SIGN2;
- ft->info.size = WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
+ ft->info.size = ST_SIZE_WORD;
break;
case SUN_G721:
- ft->info.style = SIGN2;
- ft->info.size = WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
+ ft->info.size = ST_SIZE_WORD;
g72x_init_state(&p->state);
p->dec_routine = g721_decoder;
p->dec_bits = 4;
break;
case SUN_G723_3:
- ft->info.style = SIGN2;
- ft->info.size = WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
+ ft->info.size = ST_SIZE_WORD;
g72x_init_state(&p->state);
p->dec_routine = g723_24_decoder;
p->dec_bits = 3;
break;
case SUN_G723_5:
- ft->info.style = SIGN2;
- ft->info.size = WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
+ ft->info.size = ST_SIZE_WORD;
g72x_init_state(&p->state);
p->dec_routine = g723_40_decoder;
p->dec_bits = 5;
@@ -177,7 +180,7 @@
default:
report("encoding: 0x%lx", encoding);
fail("Unsupported encoding in Sun/NeXT header.\nOnly U-law, signed bytes, signed words, and ADPCM are supported.");
- /*NOTREACHED*/
+ return(ST_EOF);
}
/* Read the sampling rate */
@@ -195,12 +198,16 @@
for(i = 0; i < hdr_size; i++) {
buf[i] = (char) getc(ft->fp);
if (feof(ft->fp))
+ {
fail("Unexpected EOF in Sun/NeXT header info.");
+ return(ST_EOF);
+ }
}
buf[i] = '\0';
ft->comment = buf;
report("Input file %s: Sun header info: %s", ft->filename, buf);
}
+ return(ST_SUCCESS);
}
/* When writing, the header is supposed to contain the number of
@@ -212,15 +219,18 @@
if it is not, the unspecified size remains in the header
(this is legal). */
-void austartwrite(ft)
+int st_austartwrite(ft)
ft_t ft;
{
struct aupriv *p = (struct aupriv *) ft->priv;
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed because of rawwrite(); */
- rawstartread(ft);
+ rc = st_rawstartwrite(ft);
+ if (rc)
+ return rc;
endptr = (char *) &littlendian;
/* AU is in big endian format. Swap whats read in
@@ -233,6 +243,7 @@
p->data_size = 0;
auwriteheader(ft, SUN_UNSPEC);
+ return(ST_SUCCESS);
}
/*
@@ -262,7 +273,7 @@
return (p->in_bits > 0);
}
-LONG auread(ft, buf, samp)
+LONG st_auread(ft, buf, samp)
ft_t ft;
LONG *buf, samp;
{
@@ -270,7 +281,7 @@
unsigned char code;
int done;
if (p->dec_routine == NULL)
- return rawread(ft, buf, samp);
+ return st_rawread(ft, buf, samp);
done = 0;
while (samp > 0 && unpack_input(ft, &code) >= 0) {
*buf++ = LEFT((*p->dec_routine)(code, AUDIO_ENCODING_LINEAR,
@@ -282,30 +293,39 @@
return done;
}
-void auwrite(ft, buf, samp)
+LONG st_auwrite(ft, buf, samp)
ft_t ft;
LONG *buf, samp;
{
struct aupriv *p = (struct aupriv *) ft->priv;
p->data_size += samp * ft->info.size;
- rawwrite(ft, buf, samp);
+ return(st_rawwrite(ft, buf, samp));
}
-void austopwrite(ft)
+int st_austopwrite(ft)
ft_t ft;
{
struct aupriv *p = (struct aupriv *) ft->priv;
+ int rc;
/* Needed because of rawwrite(). Do now to flush
* data before seeking around below.
*/
- rawstopwrite(ft);
+ rc = st_rawstopwrite(ft);
+ if (rc)
+ return rc;
+ /* Attempt to update header */
if (!ft->seekable)
- return;
- if (fseek(ft->fp, 0L, 0) != 0)
+ {
+ if (fseek(ft->fp, 0L, 0) != 0)
+ {
fail("Can't rewind output file to rewrite Sun header.");
- auwriteheader(ft, p->data_size);
+ return(ST_EOF);
+ }
+ auwriteheader(ft, p->data_size);
+ }
+ return(ST_SUCCESS);
}
static void auwriteheader(ft, data_size)
@@ -318,13 +338,17 @@
ULONG sample_rate;
ULONG channels;
- if (ft->info.style == ULAW && ft->info.size == BYTE)
+ if (ft->info.style == ST_ENCODING_ULAW &&
+ ft->info.size == ST_SIZE_BYTE)
encoding = SUN_ULAW;
- else if (ft->info.style == ALAW && ft->info.size == BYTE)
+ else if (ft->info.style == ST_ENCODING_ALAW &&
+ ft->info.size == ST_SIZE_BYTE)
encoding = SUN_ALAW;
- else if (ft->info.style == SIGN2 && ft->info.size == BYTE)
+ else if (ft->info.style == ST_ENCODING_SIGN2 &&
+ ft->info.size == ST_SIZE_BYTE)
encoding = SUN_LIN_8;
- else if (ft->info.style == SIGN2 && ft->info.size == WORD)
+ else if (ft->info.style == ST_ENCODING_SIGN2 &&
+ ft->info.size == ST_SIZE_WORD)
encoding = SUN_LIN_16;
else {
report("Unsupported output style/size for Sun/NeXT header or .AU format not specified.");
@@ -331,8 +355,8 @@
report("Only U-law, A-law signed bytes, and signed words are supported.");
report("Defaulting to 8khz u-law\n");
encoding = SUN_ULAW;
- ft->info.style = ULAW;
- ft->info.size = BYTE;
+ ft->info.style = ST_ENCODING_ULAW;
+ ft->info.size = ST_SIZE_BYTE;
ft->info.rate = 8000; /* strange but true */
}
--- a/src/auto.c
+++ b/src/auto.c
@@ -17,15 +17,21 @@
#include "st.h"
#include <string.h>
-void autostartread(ft)
+int st_autostartread(ft)
ft_t ft;
{
char *type;
char header[132];
if (!ft->seekable)
+ {
fail("Type AUTO input must be a file, not a pipe");
+ return(ST_EOF);
+ }
if (fread(header, 1, sizeof header, ft->fp) != sizeof header)
+ {
fail("Type AUTO detects short file");
+ return(ST_EOF);
+ }
fseek(ft->fp, 0L - sizeof header, 1); /* Seek back */
type = 0;
if ((strncmp(header, ".snd", 4) == 0) ||
@@ -68,17 +74,19 @@
printf("Trying: -t raw -r 11000 -b -u\n\n");
type = "raw";
ft->info.rate = 11000;
- ft->info.size = BYTE;
- ft->info.style = UNSIGNED;
+ ft->info.size = ST_SIZE_BYTE;
+ ft->info.style = ST_ENCODING_UNSIGNED;
}
report("Type AUTO changed to %s", type);
ft->filetype = type;
st_gettype(ft); /* Change ft->h to the new format */
(* ft->h->startread)(ft);
+ return(ST_SUCCESS);
}
-void autostartwrite(ft)
+int st_autostartwrite(ft)
ft_t ft;
{
fail("Type AUTO can only be used for input!");
+ return(ST_EOF);
}
--- a/src/avr.c
+++ b/src/avr.c
@@ -62,13 +62,14 @@
* mono/stereo/quad.
*/
-void
-avrstartread(ft)
+
+int st_avrstartread(ft)
ft_t ft;
{
avr_t avr = (avr_t)ft->priv;
int littlendian = 1;
char *endptr;
+ int rc;
/* AVR is a Big Endian format. Swap whats read in on Little */
/* Endian machines. */
@@ -78,12 +79,15 @@
ft->swap = ft->swap ? 0 : 1;
}
- rawstartread (ft);
+ rc = st_rawstartread (ft);
+ if (rc)
+ return rc;
fread (avr->magic, 1, sizeof (avr->magic), ft->fp);
if (strncmp (avr->magic, AVR_MAGIC, 4)) {
fail ("AVR: unknown header");
+ return(ST_EOF);
}
fread (avr->name, 1, sizeof (avr->name), ft->fp);
@@ -98,21 +102,22 @@
avr->rez = rshort (ft);
if (avr->rez == 8) {
- ft->info.size = BYTE;
+ ft->info.size = ST_SIZE_BYTE;
}
else if (avr->rez == 16) {
- ft->info.size = WORD;
+ ft->info.size = ST_SIZE_WORD;
}
else {
fail ("AVR: unsupported sample resolution");
+ return(0);
}
avr->sign = rshort (ft);
if (avr->sign) {
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
}
else {
- ft->info.style = UNSIGNED;
+ ft->info.style = ST_ENCODING_UNSIGNED;
}
avr->loop = rshort (ft);
@@ -143,17 +148,17 @@
fread (avr->ext, 1, sizeof (avr->ext), ft->fp);
fread (avr->user, 1, sizeof (avr->user), ft->fp);
+
+ return(ST_SUCCESS);
}
-
-
-void
-avrstartwrite(ft)
+int st_avrstartwrite(ft)
ft_t ft;
{
avr_t avr = (avr_t)ft->priv;
int littlendian = 1;
char *endptr;
+ int rc;
/* AVR is a Big Endian format. Swap whats read in on Little */
/* Endian machines. */
@@ -165,9 +170,12 @@
if (!ft->seekable) {
fail ("AVR: file is not seekable");
+ return(ST_EOF);
}
- rawstartwrite (ft);
+ rc = st_rawstartwrite (ft);
+ if (rc)
+ return rc;
/* magic */
fwrite (AVR_MAGIC, 1, sizeof (avr->magic), ft->fp);
@@ -184,28 +192,31 @@
}
else {
fail ("AVR: number of channels not supported");
+ return(0);
}
/* rez */
- if (ft->info.size == BYTE) {
+ if (ft->info.size == ST_SIZE_BYTE) {
wshort (ft, 8);
}
- else if (ft->info.size == WORD) {
+ else if (ft->info.size == ST_SIZE_WORD) {
wshort (ft, 16);
}
else {
fail ("AVR: unsupported sample resolution");
+ return(ST_EOF);
}
/* sign */
- if (ft->info.style == SIGN2) {
+ if (ft->info.style == ST_ENCODING_SIGN2) {
wshort (ft, 0xffff);
}
- else if (ft->info.style == UNSIGNED) {
+ else if (ft->info.style == ST_ENCODING_UNSIGNED) {
wshort (ft, 0);
}
else {
fail ("AVR: unsupported style");
+ return(ST_EOF);
}
/* loop */
@@ -246,12 +257,11 @@
"\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);
+
+ return(ST_SUCCESS);
}
-
-
-void
-avrwrite(ft, buf, nsamp)
+LONG st_avrwrite(ft, buf, nsamp)
ft_t ft;
LONG *buf, nsamp;
{
@@ -259,20 +269,22 @@
avr->size += nsamp;
- rawwrite (ft, buf, nsamp);
+ return (st_rawwrite (ft, buf, nsamp));
}
-void
-avrstopwrite(ft)
+int st_avrstopwrite(ft)
ft_t ft;
{
avr_t avr = (avr_t)ft->priv;
+ int rc;
int size = avr->size / ft->info.channels;
- rawstopwrite(ft);
+ rc = st_rawstopwrite(ft);
+ if (rc)
+ return rc;
/* Fix size */
fseek (ft->fp, 26L, SEEK_SET);
@@ -281,4 +293,6 @@
/* Fix lend */
fseek (ft->fp, 34L, SEEK_SET);
wlong (ft, size);
+
+ return(ST_SUCCESS);
}
--- a/src/cdr.c
+++ b/src/cdr.c
@@ -39,15 +39,18 @@
* mono/stereo/quad.
*/
-void cdrstartread(ft)
+int st_cdrstartread(ft)
ft_t ft;
{
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed because of rawread() */
- rawstartread(ft);
+ rc = st_rawstartread(ft);
+ if (rc)
+ return rc;
endptr = (char *) &littlendian;
/* CDR is in Big Endian format. Swap whats read in on */
@@ -58,10 +61,12 @@
}
ft->info.rate = 44100L;
- ft->info.size = WORD;
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
ft->info.channels = 2;
ft->comment = NULL;
+
+ return(ST_SUCCESS);
}
/*
@@ -71,12 +76,12 @@
* Return number of samples read.
*/
-LONG cdrread(ft, buf, len)
+LONG st_cdrread(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
- return rawread(ft, buf, len);
+ return st_rawread(ft, buf, len);
}
/*
@@ -83,14 +88,14 @@
* Do anything required when you stop reading samples.
* Don't close input file!
*/
-void cdrstopread(ft)
+int st_cdrstopread(ft)
ft_t ft;
{
/* Needed because of rawread() */
- rawstopread(ft);
+ return st_rawstopread(ft);
}
-void cdrstartwrite(ft)
+int st_cdrstartwrite(ft)
ft_t ft;
{
cdr_t cdr = (cdr_t) ft->priv;
@@ -97,6 +102,7 @@
int littlendian = 1;
char *endptr;
+ int rc;
endptr = (char *) &littlendian;
/* CDR is in Big Endian format. Swap whats written out on */
@@ -107,17 +113,21 @@
}
/* Needed because of rawwrite() */
- rawstartwrite(ft);
+ rc = st_rawstartwrite(ft);
+ if (rc)
+ return rc;
cdr->samples = 0;
ft->info.rate = 44100L;
- ft->info.size = WORD;
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
ft->info.channels = 2;
+
+ return(ST_SUCCESS);
}
-void cdrwrite(ft, buf, len)
+LONG st_cdrwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
@@ -125,7 +135,7 @@
cdr->samples += len;
- rawwrite(ft, buf, len);
+ return st_rawwrite(ft, buf, len);
}
/*
@@ -133,16 +143,20 @@
* samples. We write -32768 for each sample to pad it out.
*/
-void cdrstopwrite(ft)
+int st_cdrstopwrite(ft)
ft_t ft;
{
cdr_t cdr = (cdr_t) ft->priv;
int padsamps = SECTORSIZE - (cdr->samples % SECTORSIZE);
short zero;
+ int rc;
/* Flush buffer before writing anything else */
- rawstopwrite(ft);
+ rc = st_rawstopwrite(ft);
+ if (rc)
+ return rc;
+
zero = 0;
if (padsamps != SECTORSIZE)
@@ -152,5 +166,6 @@
padsamps--;
}
}
+ return(ST_SUCCESS);
}
--- a/src/cvsd.c
+++ b/src/cvsd.c
@@ -123,14 +123,11 @@
{
struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
- /* sanity check */
- if (sizeof(struct cvsdpriv) > PRIVSIZE)
- fail("struct cvsdpriv is too big (%d); change PRIVSIZE in st.h and recompile sox", sizeof(struct cvsdpriv));
p->cvsd_rate = (ft->info.rate <= 24000) ? 16000 : 32000;
ft->info.rate = 8000;
ft->info.channels = 1;
- ft->info.size = WORD; /* make output format default to words */
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_WORD; /* make output format default to words */
+ ft->info.style = ST_ENCODING_SIGN2;
p->swapbits = ft->swap;
ft->swap = 0;
/*
@@ -164,14 +161,15 @@
/* ---------------------------------------------------------------------- */
-void cvsdstartread(ft)
+int st_cvsdstartread(ft)
ft_t ft;
{
struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
float *fp1;
int i;
-
+
cvsdstartcommon(ft);
+
p->com.mla_tc1 = 0.1 * (1 - p->com.mla_tc0);
p->com.phase = 0;
/*
@@ -184,11 +182,13 @@
*/
for(fp1 = p->c.dec.output_filter, i = DEC_FILTERLEN; i > 0; i--)
*fp1++ = 0;
+
+ return (ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
-void cvsdstartwrite(ft)
+int st_cvsdstartwrite(ft)
ft_t ft;
{
struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
@@ -196,6 +196,7 @@
int i;
cvsdstartcommon(ft);
+
p->com.mla_tc1 = 0.1 * (1 - p->com.mla_tc0);
p->com.phase = 4;
/*
@@ -204,12 +205,13 @@
for(fp1 = p->c.enc.input_filter, i = ENC_FILTERLEN; i > 0; i--)
*fp1++ = 0;
p->c.enc.recon_int = 0;
+
+ return(ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
-void
-cvsdstopwrite(ft)
+int st_cvsdstopwrite(ft)
ft_t ft;
{
struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
@@ -220,12 +222,13 @@
}
report("cvsd: min slope %f, max slope %f\n",
p->com.v_min, p->com.v_max);
+
+ return (ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
-void
-cvsdstopread(ft)
+int st_cvsdstopread(ft)
ft_t ft;
{
struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
@@ -232,6 +235,8 @@
report("cvsd: min value %f, max value %f\n",
p->com.v_min, p->com.v_max);
+
+ return(ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -246,7 +251,7 @@
} dbg = { NULL, NULL, 0 };
#endif
-LONG cvsdread(ft, buf, nsamp)
+LONG st_cvsdread(ft, buf, nsamp)
ft_t ft;
LONG *buf, nsamp;
{
@@ -257,12 +262,18 @@
#ifdef DEBUG
if (!dbg.f1) {
if (!(dbg.f1 = fopen("dbg1", "w")))
+ {
fail("debugging");
+ return (0);
+ }
fprintf(dbg.f1, "\"input\"\n");
}
if (!dbg.f2) {
if (!(dbg.f2 = fopen("dbg2", "w")))
+ {
fail("debugging");
+ return (0);
+ }
fprintf(dbg.f2, "\"recon\"\n");
}
#endif
@@ -323,8 +334,7 @@
/* ---------------------------------------------------------------------- */
-void
-cvsdwrite(ft, buf, nsamp)
+LONG st_cvsdwrite(ft, buf, nsamp)
ft_t ft;
LONG *buf, nsamp;
{
@@ -335,12 +345,18 @@
#ifdef DEBUG
if (!dbg.f1) {
if (!(dbg.f1 = fopen("dbg1", "w")))
+ {
fail("debugging");
+ return (0);
+ }
fprintf(dbg.f1, "\"input\"\n");
}
if (!dbg.f2) {
if (!(dbg.f2 = fopen("dbg2", "w")))
+ {
fail("debugging");
+ return (0);
+ }
fprintf(dbg.f2, "\"recon\"\n");
}
#endif
@@ -350,7 +366,7 @@
*/
if (p->com.phase >= 4) {
if (done >= nsamp)
- return;
+ return done;
memmove(p->c.enc.input_filter+1, p->c.enc.input_filter,
sizeof(p->c.enc.input_filter)-sizeof(float));
p->c.enc.input_filter[0] = (*buf++) /
@@ -426,7 +442,7 @@
#define DVMS_HEADER_LEN 120
/* ---------------------------------------------------------------------- */
-/* SJB: should these be in misc.c instead? */
+/* FIXME: Move these to misc.c */
static ULONG get32(p)
unsigned char **p;
{
@@ -464,7 +480,7 @@
/* ---------------------------------------------------------------------- */
-static void dvms_read_header(f, hdr)
+static int dvms_read_header(f, hdr)
FILE *f;
struct dvms_header *hdr;
{
@@ -474,7 +490,10 @@
unsigned sum;
if (fread(hdrbuf, sizeof(hdrbuf), 1, f) != 1)
+ {
fail("unable to read DVMS header\n");
+ return (ST_EOF);
+ }
for(i = sizeof(hdrbuf), sum = 0; i > /*2*/3; i--) /* Deti bug */
sum += *pch++;
pch = hdrbuf;
@@ -496,8 +515,12 @@
pch += sizeof(hdr->extend);
hdr->Crc = get16(&pch);
if (sum != hdr->Crc)
+ {
fail("DVMS header checksum error, read %u, calculated %u\n",
hdr->Crc, sum);
+ return (ST_EOF);
+ }
+ return (ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -505,7 +528,7 @@
/*
* note! file must be seekable
*/
-static void dvms_write_header(f, hdr)
+static int dvms_write_header(f, hdr)
FILE *f;
struct dvms_header *hdr;
{
@@ -536,9 +559,16 @@
hdr->Crc = sum;
put16(&pch, hdr->Crc);
if (fseek(f, 0, SEEK_SET) < 0)
+ {
fail("cannot write DVMS header, seek failed\n");
+ return (ST_EOF);
+ }
if (fwrite(hdrbuf, sizeof(hdrbuf), 1, f) != 1)
+ {
fail("cannot write DVMS header\n");
+ return (ST_EOF);
+ }
+ return (ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -571,13 +601,17 @@
/* ---------------------------------------------------------------------- */
-void dvmsstartread(ft)
+int st_dvmsstartread(ft)
ft_t ft;
{
struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
struct dvms_header hdr;
+ int rc;
- dvms_read_header(ft->fp, &hdr);
+ rc = dvms_read_header(ft->fp, &hdr);
+ if (rc)
+ return rc;
+
report("DVMS header of source file \"%s\":");
report(" filename \"%.14s\"",ft->filename);
report(" id 0x%x", hdr.Filename);
@@ -595,41 +629,61 @@
report("DVMS rate %dbit/s using %dbit/s deviation %d%%\n",
hdr.Srate*100, ft->info.rate,
((ft->info.rate - hdr.Srate*100) * 100) / ft->info.rate);
- cvsdstartread(ft);
+ rc = st_cvsdstartread(ft);
+ if (rc)
+ return rc;
+
p->swapbits = 0;
+ return(ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
-void dvmsstartwrite(ft)
+int st_dvmsstartwrite(ft)
ft_t ft;
{
struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
struct dvms_header hdr;
+ int rc;
- cvsdstartwrite(ft);
+ rc = st_cvsdstartwrite(ft);
+ if (rc)
+ return rc;
+
make_dvms_hdr(ft, &hdr);
- dvms_write_header(ft->fp, &hdr);
+ rc = dvms_write_header(ft->fp, &hdr);
+ if (rc)
+ return rc;
+
if (!ft->seekable)
warn("Length in output .DVMS header will wrong since can't seek to fix it");
+
p->swapbits = 0;
+ return(ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
-void
-dvmsstopwrite(ft)
+int st_dvmsstopwrite(ft)
ft_t ft;
{
struct dvms_header hdr;
+ int rc;
- cvsdstopwrite(ft);
+ st_cvsdstopwrite(ft);
if (!ft->seekable)
- return;
+ {
+ warn("File not seekable");
+ return (ST_EOF);
+ }
if (fseek(ft->fp, 0L, 0) != 0)
+ {
fail("Can't rewind output file to rewrite DVMS header.");
+ return(ST_EOF);
+ }
make_dvms_hdr(ft, &hdr);
- dvms_write_header(ft->fp, &hdr);
+ rc = dvms_write_header(ft->fp, &hdr);
+ return rc;
}
/* ---------------------------------------------------------------------- */
--- a/src/dat.c
+++ b/src/dat.c
@@ -27,7 +27,7 @@
double timevalue, deltat;
} *dat_t;
-/* SJB: should this be moved to misc.c ? */
+/* FIXME: Move this to misc.c */
static LONG roundoff(x)
double x;
{
@@ -35,8 +35,7 @@
else return(x + 0.5);
}
-void
-datstartread(ft)
+int st_datstartread(ft)
ft_t ft;
{
char inpstr[82];
@@ -45,7 +44,11 @@
while (ft->info.rate == 0) {
fgets(inpstr,82,ft->fp);
sscanf(inpstr," %c",&sc);
- if (sc != ';') fail("Cannot determine sample rate.");
+ if (sc != ';')
+ {
+ fail("Cannot determine sample rate.");
+ return (ST_EOF);
+ }
#ifdef __alpha__
sscanf(inpstr," ; Sample Rate %d", &ft->info.rate);
#else
@@ -55,12 +58,13 @@
/* size and style are really not necessary except to satisfy caller. */
- ft->info.size = DOUBLE;
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_DOUBLE;
+ ft->info.style = ST_ENCODING_SIGN2;
+
+ return (ST_SUCCESS);
}
-void
-datstartwrite(ft)
+int st_datstartwrite(ft)
ft_t ft;
{
dat_t dat = (dat_t) ft->priv;
@@ -73,8 +77,8 @@
ft->info.channels = 1;
}
- ft->info.size = DOUBLE;
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_DOUBLE;
+ ft->info.style = ST_ENCODING_SIGN2;
dat->timevalue = 0.0;
srate = ft->info.rate;
dat->deltat = 1.0 / srate;
@@ -83,9 +87,11 @@
#else
fprintf(ft->fp,"; Sample Rate %ld\015\n",ft->info.rate);
#endif
+
+ return (ST_SUCCESS);
}
-LONG datread(ft, buf, nsamp)
+LONG st_datread(ft, buf, nsamp)
ft_t ft;
LONG *buf, nsamp;
{
@@ -105,7 +111,11 @@
}
while(sc == ';'); /* eliminate comments */
retc = sscanf(inpstr,"%*s %lg",&sampval);
- if (retc != 1) fail("Unable to read sample.");
+ if (retc != 1)
+ {
+ fail("Unable to read sample.");
+ return (0);
+ }
*buf++ = roundoff(sampval * 2.147483648e9);
++done;
}
@@ -112,8 +122,7 @@
return (done);
}
-void
-datwrite(ft, buf, nsamp)
+LONG st_datwrite(ft, buf, nsamp)
ft_t ft;
LONG *buf, nsamp;
{
@@ -128,6 +137,6 @@
dat->timevalue += dat->deltat;
done++;
}
- return;
+ return done;
}
--- a/src/deemphas.c
+++ b/src/deemphas.c
@@ -120,7 +120,7 @@
{
if (n)
fail("Deemphasis filtering effect takes no options.\n");
- if (sizeof(double)*PRIVSIZE < sizeof(struct deemphstuff))
+ if (sizeof(double)*ST_MAX_PRIVSIZE < sizeof(struct deemphstuff))
fail("Internal error: PRIVSIZE too small.\n");
}
@@ -132,12 +132,12 @@
eff_t effp;
{
/* check the input format */
- if (effp->ininfo.style != SIGN2
+ if (effp->ininfo.style != ST_ENCODING_SIGN2
|| effp->ininfo.rate != 44100
- || effp->ininfo.size != WORD)
+ || effp->ininfo.size != ST_SIZE_WORD)
fail("The deemphasis effect works only with audio cd like samples.\nThe input format however has %d Hz sample rate and %d-byte%s signed linearly coded samples.",
effp->ininfo.rate, effp->ininfo.size,
- effp->ininfo.style != SIGN2 ? ", but not" : "");
+ effp->ininfo.style != ST_ENCODING_SIGN2 ? ", but not" : "");
{
deemph_t deemph = (deemph_t) effp->priv;
--- a/src/echo.c
+++ b/src/echo.c
@@ -59,7 +59,7 @@
#include <math.h>
#include "st.h"
-#define DELAY_BUFSIZ ( 50L * MAXRATE )
+#define DELAY_BUFSIZ ( 50L * ST_MAXRATE )
#define MAX_ECHOS 7 /* 24 bit x ( 1 + MAX_ECHOS ) = */
/* 24 bit x 8 = 32 bit !!! */
--- a/src/echos.c
+++ b/src/echos.c
@@ -50,7 +50,7 @@
#include <math.h>
#include "st.h"
-#define DELAY_BUFSIZ ( 50L * MAXRATE )
+#define DELAY_BUFSIZ ( 50L * ST_MAXRATE )
#define MAX_ECHOS 7 /* 24 bit x ( 1 + MAX_ECHOS ) = */
/* 24 bit x 8 = 32 bit !!! */
--- a/src/gsm.c
+++ b/src/gsm.c
@@ -47,7 +47,7 @@
gsm handle[MAXCHANS];
};
-static void
+static int
gsmstart_rw(ft,w)
ft_t ft;
int w; /* w != 0 is write */
@@ -55,42 +55,43 @@
struct gsmpriv *p = (struct gsmpriv *) ft->priv;
int ch;
- /* Sanity check */
- if (sizeof(struct gsmpriv) > PRIVSIZE)
- fail(
-"struct gsmpriv is too big (%d); change PRIVSIZE in st.h and recompile sox",
- sizeof(struct gsmpriv));
-
- ft->info.style = GSM;
- ft->info.size = BYTE;
+ ft->info.style = ST_ENCODING_GSM;
+ ft->info.size = ST_SIZE_BYTE;
if (!ft->info.rate)
ft->info.rate = 8000;
p->channels = ft->info.channels;
if (p->channels > MAXCHANS || p->channels <= 0)
+ {
fail("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])
+ {
fail("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);
}
-void gsmstartread(ft)
+int st_gsmstartread(ft)
ft_t ft;
{
- gsmstart_rw(ft,0);
+ return st_gsmstart_rw(ft,0);
}
-void gsmstartwrite(ft)
+int st_gsmstartwrite(ft)
ft_t ft;
{
- gsmstart_rw(ft,1);
+ return gsmstart_rw(ft,1);
}
/*
@@ -100,7 +101,7 @@
* Return number of samples read.
*/
-LONG gsmread(ft, buf, samp)
+LONG st_gsmread(ft, buf, samp)
ft_t ft;
long *buf, samp;
{
@@ -128,7 +129,10 @@
gbuff = p->sampleTop;
if (gsm_decode(p->handle[ch], p->frames + ch*FRAMESIZE, gbuff) < 0)
+ {
fail("error during GSM decode");
+ return (0);
+ }
gsp = p->samples + ch;
for (i=0; i<BLOCKSIZE; i++) {
@@ -141,7 +145,7 @@
return done;
}
-static void gsmflush(ft)
+static int gsmflush(ft)
ft_t ft;
{
int r, ch, chans;
@@ -167,18 +171,22 @@
gsm_encode(p->handle[ch], gbuff, p->frames);
r = fwrite(p->frames, FRAMESIZE, 1, ft->fp);
if (r != 1)
+ {
fail("write error");
+ return(ST_EOF);
+ }
}
p->samplePtr = p->samples;
- return;
+ return (ST_SUCCESS);
}
-int gsmwrite(ft, buf, samp)
+LONG st_gsmwrite(ft, buf, samp)
ft_t ft;
long *buf, samp;
{
int done = 0;
+ int rc;
struct gsmpriv *p = (struct gsmpriv *) ft->priv;
while (done < samp)
@@ -187,14 +195,18 @@
*(p->samplePtr)++ = RIGHT(buf[done++], 16);
if (p->samplePtr == p->sampleTop)
- gsmflush(ft);
+ {
+ if(gsmflush(ft))
+ {
+ return 0;
+ }
+ }
}
return done;
}
-void
-gsmstopread(ft)
+int st_gsmstopread(ft)
ft_t ft;
{
struct gsmpriv *p = (struct gsmpriv *) ft->priv;
@@ -205,17 +217,22 @@
free(p->samples);
free(p->frames);
+ return (ST_SUCCESS);
}
-void
-gsmstopwrite(ft)
+int st_gsmstopwrite(ft)
ft_t ft;
{
+ int rc;
struct gsmpriv *p = (struct gsmpriv *) ft->priv;
if (p->samplePtr > p->samples)
- gsmflush(ft);
+ {
+ rc = gsmflush(ft);
+ if (rc)
+ return rc;
+ }
- gsmstopread(ft); /* destroy handles and free buffers */
+ return gsmstopread(ft); /* destroy handles and free buffers */
}
#endif /* HAVE_LIBGSM */
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -16,35 +16,35 @@
/* File format handlers. */
-char *aiffnames[] = {
+static char *aiffnames[] = {
"aiff",
"aif",
(char *) 0
};
-extern void aiffstartread();
-extern LONG aiffread();
-extern void aiffstopread();
-extern void aiffstartwrite();
-extern void aiffwrite();
-extern void aiffstopwrite();
+extern int st_aiffstartread();
+extern LONG st_aiffread();
+extern int st_aiffstopread();
+extern int st_aiffstartwrite();
+extern LONG st_aiffwrite();
+extern int st_aiffstopwrite();
-char *alnames[] = {
+static char *alnames[] = {
"al",
(char *) 0
};
-extern void alstartread();
-extern void alstartwrite();
+extern int st_alstartread();
+extern int st_alstartwrite();
#if defined(ALSA_PLAYER)
-char *alsanames[] = {
+static char *alsanames[] = {
"alsa",
(char *) 0
};
-extern void alsastartread();
-extern void alsastartwrite();
+extern int st_alsastartread();
+extern int st_alsastartwrite();
#endif
-char *aunames[] = {
+static char *aunames[] = {
"au",
#ifdef NeXT
"snd",
@@ -51,117 +51,125 @@
#endif
(char *) 0
};
-extern void austartread();
-extern LONG auread();
-extern void austartwrite();
-extern void auwrite();
-extern void austopwrite();
-char *autonames[] = {
+extern int st_austartread();
+extern LONG st_auread();
+extern int st_austartwrite();
+extern LONG st_auwrite();
+extern int st_austopwrite();
+
+static char *autonames[] = {
"auto",
(char *) 0
};
-extern void autostartread();
-extern void autostartwrite();
+extern int st_autostartread();
+extern int st_autostartwrite();
-char *avrnames[] = {
+static char *avrnames[] = {
"avr",
(char *) 0
};
-extern void avrstartread();
-extern void avrstartwrite();
-extern void avrwrite();
-extern void avrstopwrite();
+extern int st_avrstartread();
+extern int st_avrstartwrite();
+extern LONG st_avrwrite();
+extern int st_avrstopwrite();
-char *cdrnames[] = {
+static char *cdrnames[] = {
"cdr",
(char *) 0
};
-extern void cdrstartread();
-extern LONG cdrread();
-extern void cdrstopread();
-extern void cdrstartwrite();
-extern void cdrwrite();
-extern void cdrstopwrite();
-char *cvsdnames[] = {
+extern int st_cdrstartread();
+extern LONG st_cdrread();
+extern int st_cdrstopread();
+extern int st_cdrstartwrite();
+extern LONG st_cdrwrite();
+extern int st_cdrstopwrite();
+
+static char *cvsdnames[] = {
"cvs",
"cvsd",
(char *)0
};
-extern void cvsdstartread();
-extern LONG cvsdread();
-extern void cvsdstopread();
-extern void cvsdstartwrite();
-extern void cvsdwrite();
-extern void cvsdstopwrite();
-char *datnames[] = {
+extern int st_cvsdstartread();
+extern LONG st_cvsdread();
+extern int st_cvsdstopread();
+extern int st_cvsdstartwrite();
+extern LONG st_cvsdwrite();
+extern int st_cvsdstopwrite();
+
+static char *datnames[] = {
"dat",
(char *) 0
};
-extern void datstartread();
-extern LONG datread();
-extern void datstartwrite();
-extern void datwrite();
-char *dvmsnames[] = {
+extern int st_datstartread();
+extern LONG st_datread();
+extern int st_datstartwrite();
+extern LONG st_datwrite();
+
+static char *dvmsnames[] = {
"vms",
"dvms",
(char *)0
};
-extern void dvmsstartread();
-extern void dvmsstartwrite();
-extern void dvmsstopwrite();
+extern int st_dvmsstartread();
+extern int st_dvmsstartwrite();
+extern int st_dvmsstopwrite();
+
#ifdef HAVE_LIBGSM
-char *gsmnames[] = {
+static char *gsmnames[] = {
"gsm",
(char *) 0
};
-extern void gsmstartread();
-extern LONG gsmread();
-extern void gsmstopread();
-extern void gsmstartwrite();
-extern void gsmwrite();
-extern void gsmstopwrite();
+extern int st_gsmstartread();
+extern LONG st_gsmread();
+extern int st_gsmstopread();
+extern int st_gsmstartwrite();
+extern LONG st_gsmwrite();
+extern int st_gsmstopwrite();
#endif
-char *hcomnames[] = {
+static char *hcomnames[] = {
"hcom",
(char *) 0
};
-extern void hcomstartread();
-extern LONG hcomread();
-extern void hcomstopread();
-extern void hcomstartwrite();
-extern void hcomwrite();
-extern void hcomstopwrite();
-char *maudnames[] = {
+extern int st_hcomstartread();
+extern LONG st_hcomread();
+extern int st_hcomstopread();
+extern int st_hcomstartwrite();
+extern LONG st_hcomwrite();
+extern int st_hcomstopwrite();
+
+static char *maudnames[] = {
"maud",
(char *) 0,
};
-extern void maudstartread();
-extern LONG maudread();
-extern void maudstopread();
-extern void maudwrite();
-extern void maudstartwrite();
-extern void maudstopwrite();
+extern int st_maudstartread();
+extern LONG st_maudread();
+extern int st_maudstopread();
+extern LONG st_maudwrite();
+extern int st_maudstartwrite();
+extern int st_maudstopwrite();
+
#if defined(OSS_PLAYER)
-char *ossdspnames[] = {
+static char *ossdspnames[] = {
"ossdsp",
(char *) 0
};
-extern void ossdspstartread();
-extern void ossdspstartwrite();
+
+extern int st_ossdspstartread();
+extern int st_ossdspstartwrite();
#endif
-char *rawnames[] = {
+static char *rawnames[] = {
"raw",
(char *) 0
};
@@ -168,46 +176,49 @@
/* raw prototypes are defined in st.h since they are used globally. */
-char *sbnames[] = {
+static char *sbnames[] = {
"sb",
(char *) 0
};
-extern void sbstartread();
-extern void sbstartwrite();
-char *sfnames[] = {
+extern int st_sbstartread();
+extern int st_sbstartwrite();
+
+static char *sfnames[] = {
"sf",
(char *) 0
};
-extern void sfstartread();
-extern void sfstartwrite();
-char *smpnames[] = {
- "smp",
- (char *) 0,
-};
+extern int st_sfstartread();
+extern int st_sfstartwrite();
-char *slnames[] = {
+static char *slnames[] = {
"sl",
(char *) 0,
};
-extern void slstartread();
-extern void slstartwrite();
+extern int st_slstartread();
+extern int st_slstartwrite();
-extern void smpstartread();
-extern LONG smpread();
-extern void smpwrite();
-extern void smpstartwrite();
-extern void smpstopwrite();
+static char *smpnames[] = {
+ "smp",
+ (char *) 0,
+};
-char *sndrnames[] = {
+extern int st_smpstartread();
+extern LONG st_smpread();
+extern LONG st_smpwrite();
+extern int st_smpstartwrite();
+extern int st_smpstopwrite();
+
+static char *sndrnames[] = {
"sndr",
(char *) 0
};
-extern void sndrstartwrite();
-char *sndtnames[] = {
+extern int st_sndrstartwrite();
+
+static char *sndtnames[] = {
"sndt",
#ifdef DOS
"snd",
@@ -214,50 +225,55 @@
#endif
(char *) 0
};
-extern void sndtstartread();
-extern void sndtstartwrite();
-extern void sndtwrite();
-extern void sndtstopwrite();
+extern int st_sndtstartread();
+extern int st_sndtstartwrite();
+extern LONG st_sndtwrite();
+extern int st_sndtstopwrite();
+
#if defined(SUNAUDIO_PLAYER)
-char *sunnames[] = {
+static char *sunnames[] = {
"sunau",
(char *) 0
};
-extern void sunstartread();
-extern void sunstartwrite();
+
+extern int st_sunstartread();
+extern int st_sunstartwrite();
#endif
-char *svxnames[] = {
+static char *svxnames[] = {
"8svx",
(char *) 0
};
-extern void svxstartread();
-extern LONG svxread();
-extern void svxstopread();
-extern void svxstartwrite();
-extern void svxwrite();
-extern void svxstopwrite();
-char *swnames[] = {
+extern int st_svxstartread();
+extern LONG st_svxread();
+extern int st_svxstopread();
+extern int st_svxstartwrite();
+extern LONG st_svxwrite();
+extern int st_svxstopwrite();
+
+static char *swnames[] = {
"sw",
(char *) 0
};
-extern void swstartread();
-extern void swstartwrite();
-char *txwnames[] = {
+extern int st_swstartread();
+extern int st_swstartwrite();
+
+static char *txwnames[] = {
"txw",
(char *)0
};
-extern void txwstartread();
-extern LONG txwread();
-extern void txwstopread();
-extern void txwstartwrite();
-extern void txwwrite();
-extern void txwstopwrite();
-char *ubnames[] = {
+extern int st_txwstartread();
+extern LONG st_txwread();
+extern int st_txwstopread();
+extern int st_txwstartwrite();
+extern LONG st_txwwrite();
+extern int st_txwstopwrite();
+
+static char *ubnames[] = {
"ub",
"sou",
"fssd",
@@ -266,161 +282,165 @@
#endif
(char *) 0
};
-extern void ubstartread();
-extern void ubstartwrite();
-char *ulnames[] = {
+extern int st_ubstartread();
+extern int st_ubstartwrite();
+
+static char *ulnames[] = {
"ul",
(char *) 0
};
-extern void ulstartread();
-extern void ulstartwrite();
-char *uwnames[] = {
+extern int st_ulstartread();
+extern int st_ulstartwrite();
+
+static char *uwnames[] = {
"uw",
(char *) 0
};
-extern void uwstartread();
-extern void uwstartwrite();
-char *vocnames[] = {
+extern int st_uwstartread();
+extern int st_uwstartwrite();
+
+static char *vocnames[] = {
"voc",
(char *) 0
};
-extern void vocstartread();
-extern LONG vocread();
-extern void vocstopread();
-extern void vocstartwrite();
-extern void vocwrite();
-extern void vocstopwrite();
-char *wavnames[] = {
+extern int st_vocstartread();
+extern LONG st_vocread();
+extern int st_vocstopread();
+extern int st_vocstartwrite();
+extern LONG st_vocwrite();
+extern int st_vocstopwrite();
+
+static char *wavnames[] = {
"wav",
(char *) 0
};
-extern void wavstartread();
-extern LONG wavread();
-extern void wavstartwrite();
-extern void wavwrite();
-extern void wavstopwrite();
-char *wvenames[] = {
+extern int st_wavstartread();
+extern LONG st_wavread();
+extern int st_wavstartwrite();
+extern LONG st_wavwrite();
+extern int st_wavstopwrite();
+
+static char *wvenames[] = {
"wve",
(char *) 0
};
-extern void wvestartread();
-extern LONG wveread();
-extern void wvestartwrite();
-extern void wvewrite();
-extern void wvestopwrite();
-extern void nothing();
-extern LONG nothing_success();
+extern int st_wvestartread();
+extern LONG st_wveread();
+extern int st_wvestartwrite();
+extern LONG st_wvewrite();
+extern int st_wvestopwrite();
-format_t formats[] = {
- {aiffnames, FILE_STEREO,
- aiffstartread, aiffread, aiffstopread, /* SGI/Apple AIFF */
- aiffstartwrite, aiffwrite, aiffstopwrite},
- {alnames, FILE_STEREO,
- alstartread, rawread, rawstopread, /* a-law byte raw */
- alstartwrite, rawwrite, rawstopwrite},
+extern int st_nothing();
+extern LONG st_nothing_success();
+
+st_format_t st_formats[] = {
+ {aiffnames, ST_FILE_STEREO, /* SGI/Apple AIFF */
+ st_aiffstartread, st_aiffread, st_aiffstopread,
+ st_aiffstartwrite, st_aiffwrite, st_aiffstopwrite},
+ {alnames, ST_FILE_STEREO, /* a-law byte raw */
+ st_alstartread, st_rawread, st_rawstopread,
+ st_alstartwrite, st_rawwrite, st_rawstopwrite},
#if defined(ALSA_PLAYER)
- {alsanames, FILE_STEREO,
- alsastartread, rawread, rawstopread, /* /dev/snd/pcmXX */
- alsastartwrite, rawwrite, rawstopwrite},
+ {alsanames, ST_FILE_STEREO, /* /dev/snd/pcmXX */
+ st_alsastartread, st_rawread, st_rawstopread,
+ st_alsastartwrite, st_rawwrite, st_rawstopwrite},
#endif
- {aunames, FILE_STEREO,
- austartread, auread, rawstopread, /* SPARC .AU w/header */
- austartwrite, auwrite, austopwrite},
- {autonames, FILE_STEREO,
- autostartread, nothing_success, nothing,/* Guess from header */
- autostartwrite, nothing, nothing}, /* patched run time */
- {avrnames, FILE_STEREO,
- avrstartread, rawread, nothing, /* AVR format */
- avrstartwrite, avrwrite, avrstopwrite}, /* relies on raw */
- {cdrnames, FILE_STEREO,
- cdrstartread, cdrread, cdrstopread, /* CD-R format */
- cdrstartwrite, cdrwrite, cdrstopwrite},
- {cvsdnames, 0,
- cvsdstartread, cvsdread, cvsdstopread, /* Cont. Variable */
- cvsdstartwrite, cvsdwrite, cvsdstopwrite}, /* Slope Delta */
- {datnames, 0,
- datstartread, datread, nothing, /* Text data samples */
- datstartwrite, datwrite, nothing},
- {dvmsnames, 0,
- dvmsstartread, cvsdread, cvsdstopread, /* Cont. Variable */
- dvmsstartwrite, cvsdwrite, dvmsstopwrite}, /* Slope Delta */
+ {aunames, ST_FILE_STEREO, /* SPARC .au w/header */
+ st_austartread, st_auread, st_rawstopread,
+ st_austartwrite, st_auwrite, st_austopwrite},
+ {autonames, ST_FILE_STEREO, /* Guess from header */
+ st_autostartread, st_nothing_success, st_nothing,
+ st_autostartwrite, st_nothing_success, st_nothing},
+ {avrnames, ST_FILE_STEREO, /* AVR format */
+ st_avrstartread, st_rawread, st_nothing,
+ st_avrstartwrite, st_avrwrite, st_avrstopwrite},
+ {cdrnames, ST_FILE_STEREO, /* CD-R format */
+ st_cdrstartread, st_cdrread, st_cdrstopread,
+ st_cdrstartwrite, st_cdrwrite, st_cdrstopwrite},
+ {cvsdnames, 0, /* Cont. Variable Slope Delta */
+ st_cvsdstartread, st_cvsdread, st_cvsdstopread,
+ st_cvsdstartwrite, st_cvsdwrite, st_cvsdstopwrite},
+ {datnames, 0, /* Text data samples */
+ st_datstartread, st_datread, st_nothing,
+ st_datstartwrite, st_datwrite, st_nothing},
+ {dvmsnames, 0, /* Cont. Variable Solot Delta */
+ st_dvmsstartread, st_cvsdread, st_cvsdstopread,
+ st_dvmsstartwrite, st_cvsdwrite, st_dvmsstopwrite},
#ifdef HAVE_LIBGSM
- {gsmnames, 0,
- gsmstartread, gsmread, gsmstopread, /* GSM 06.10 */
- gsmstartwrite, gsmwrite, gsmstopwrite},
+ {gsmnames, 0, /* GSM 06.10 */
+ st_gsmstartread, st_gsmread, st_gsmstopread,
+ st_gsmstartwrite, st_gsmwrite, st_gsmstopwrite},
#endif
- {hcomnames, 0,
- hcomstartread, hcomread, hcomstopread, /* Mac FSSD/HCOM */
- hcomstartwrite, hcomwrite, hcomstopwrite},
- {maudnames, FILE_STEREO, /* Amiga MAUD */
- maudstartread, maudread, maudstopread,
- maudstartwrite, maudwrite, maudstopwrite},
+ {hcomnames, 0, /* Mac FSSD/HCOM */
+ st_hcomstartread, st_hcomread, st_hcomstopread,
+ st_hcomstartwrite, st_hcomwrite, st_hcomstopwrite},
+ {maudnames, ST_FILE_STEREO, /* Amiga MAUD */
+ st_maudstartread, st_maudread, st_maudstopread,
+ st_maudstartwrite, st_maudwrite, st_maudstopwrite},
#if defined(OSS_PLAYER)
- /* OSS player. */
- {ossdspnames, FILE_STEREO,
- ossdspstartread, rawread, rawstopread, /* /dev/dsp */
- ossdspstartwrite, rawwrite, rawstopwrite},
+ {ossdspnames, ST_FILE_STEREO, /* OSS /dev/dsp player */
+ st_ossdspstartread, st_rawread, st_rawstopread,
+ st_ossdspstartwrite, st_rawwrite, st_rawstopwrite},
#endif
- {rawnames, FILE_STEREO,
- rawstartread, rawread, rawstopread, /* Raw format */
- rawstartwrite, rawwrite, rawstopwrite},
- {sbnames, FILE_STEREO,
- sbstartread, rawread, rawstopread, /* signed byte raw */
- sbstartwrite, rawwrite, rawstopwrite},
- {sfnames, FILE_STEREO,
- sfstartread, rawread, rawstopread, /* IRCAM Sound File */
- sfstartwrite, rawwrite, rawstopwrite},
- { slnames, FILE_STEREO,
- slstartread, rawread, rawstopread, /* signed long raw */
- slstartwrite, rawwrite, rawstopwrite },
- {smpnames, FILE_STEREO | FILE_LOOPS,
- smpstartread, smpread, nothing, /* SampleVision sound */
- smpstartwrite, smpwrite, smpstopwrite}, /* Turtle Beach */
- {sndrnames, FILE_STEREO,
- sndtstartread, rawread, rawstopread, /* Sounder Sound File */
- sndrstartwrite, rawwrite, rawstopwrite},
- {sndtnames, FILE_STEREO,
- sndtstartread, rawread, rawstopread, /* Sndtool Sound File */
- sndtstartwrite, sndtwrite, sndtstopwrite},
+ {rawnames, ST_FILE_STEREO, /* Raw format */
+ st_rawstartread, st_rawread, st_rawstopread,
+ st_rawstartwrite, st_rawwrite, st_rawstopwrite},
+ {sbnames, ST_FILE_STEREO, /* signed byte raw */
+ st_sbstartread, st_rawread, st_rawstopread,
+ st_sbstartwrite, st_rawwrite, st_rawstopwrite},
+ {sfnames, ST_FILE_STEREO, /* IRCAM Sound File */
+ st_sfstartread, st_rawread, st_rawstopread,
+ st_sfstartwrite, st_rawwrite, st_rawstopwrite},
+ { slnames, ST_FILE_STEREO, /* signed long raw */
+ st_slstartread, st_rawread, st_rawstopread,
+ st_slstartwrite, st_rawwrite, st_rawstopwrite },
+ {smpnames, ST_FILE_STEREO | ST_FILE_LOOPS,/* SampleVision sound */
+ st_smpstartread, st_smpread, st_nothing,
+ st_smpstartwrite, st_smpwrite, st_smpstopwrite},
+ {sndrnames, ST_FILE_STEREO, /* Sounder Sound File */
+ st_sndtstartread, st_rawread, st_rawstopread,
+ st_sndrstartwrite, st_rawwrite, st_rawstopwrite},
+ {sndtnames, ST_FILE_STEREO, /* Sndtool Sound File */
+ st_sndtstartread, st_rawread, st_rawstopread,
+ st_sndtstartwrite, st_sndtwrite, st_sndtstopwrite},
#if defined(SUNAUDIO_PLAYER)
- /* Sun /dev/audio player. */
- {sunnames, FILE_STEREO,
- sunstartread, rawread, rawstopread, /* /dev/audio */
- sunstartwrite, rawwrite, rawstopwrite},
+ {sunnames, ST_FILE_STEREO, /* Sun /dev/audio player */
+ st_sunstartread, st_rawread, st_rawstopread,
+ st_sunstartwrite, st_rawwrite, st_rawstopwrite},
#endif
- {svxnames, FILE_STEREO,
- svxstartread, svxread, svxstopread, /* Amiga 8SVX */
- svxstartwrite, svxwrite, svxstopwrite},
- {swnames, FILE_STEREO,
- swstartread, rawread, rawstopread, /* signed word raw */
- swstartwrite, rawwrite, rawstopwrite},
- {txwnames, 0,
- txwstartread, txwread, txwstopread, /* Yamaha TX16W and */
- txwstartwrite, txwwrite, txwstopwrite}, /* SY99 waves */
- {ubnames, FILE_STEREO,
- ubstartread, rawread, rawstopread, /* unsigned byte raw */
- ubstartwrite, rawwrite, rawstopwrite},
- {ulnames, FILE_STEREO,
- ulstartread, rawread, rawstopread, /* u-law byte raw */
- ulstartwrite, rawwrite, rawstopwrite},
- {uwnames, FILE_STEREO,
- uwstartread, rawread, rawstopread, /* unsigned word raw */
- uwstartwrite, rawwrite, rawstopwrite},
- {vocnames, FILE_STEREO,
- vocstartread, vocread, vocstopread, /* Sound Blaster .VOC */
- vocstartwrite, vocwrite, vocstopwrite},
- {wavnames, FILE_STEREO,
- wavstartread, wavread, nothing, /* Microsoft .wav */
- wavstartwrite, wavwrite, wavstopwrite},
- {wvenames, 0,
- wvestartread, wveread, rawstopread, /* Psion .wve */
- wvestartwrite, wvewrite, wvestopwrite},
+ {svxnames, ST_FILE_STEREO, /* Amiga 8SVX */
+ st_svxstartread, st_svxread, st_svxstopread,
+ st_svxstartwrite, st_svxwrite, st_svxstopwrite},
+ {swnames, ST_FILE_STEREO, /* signed word raw */
+ st_swstartread, st_rawread, st_rawstopread,
+ st_swstartwrite, st_rawwrite, st_rawstopwrite},
+ {txwnames, 0, /* Yamaha TX16W and SY99 waves */
+ st_txwstartread, st_txwread, st_txwstopread,
+ st_txwstartwrite, st_txwwrite, st_txwstopwrite},
+ {ubnames, ST_FILE_STEREO, /* unsigned byte raw */
+ st_ubstartread, st_rawread, st_rawstopread,
+ st_ubstartwrite, st_rawwrite, st_rawstopwrite},
+ {ulnames, ST_FILE_STEREO, /* u-law byte raw */
+ st_ulstartread, st_rawread, st_rawstopread,
+ st_ulstartwrite, st_rawwrite, st_rawstopwrite},
+ {uwnames, ST_FILE_STEREO, /* unsigned word raw */
+ st_uwstartread, st_rawread, st_rawstopread,
+ st_uwstartwrite, st_rawwrite, st_rawstopwrite},
+ {vocnames, ST_FILE_STEREO, /* Sound Blaster .VOC */
+ st_vocstartread, st_vocread, st_vocstopread,
+ st_vocstartwrite, st_vocwrite, st_vocstopwrite},
+ {wavnames, ST_FILE_STEREO, /* Microsoftt RIFF */
+ st_wavstartread, st_wavread, st_nothing,
+ st_wavstartwrite, st_wavwrite, st_wavstopwrite},
+ {wvenames, 0, /* Psion .wve */
+ st_wvestartread, st_wveread, st_rawstopread,
+ st_wvestartwrite, st_wvewrite, st_wvestopwrite},
{0, 0,
0, 0, 0, 0, 0, 0}
};
@@ -427,7 +447,7 @@
/* Effects handlers. */
-extern void null_drain(); /* dummy drain routine */
+extern LONG st_null_drain(); /* dummy drain routine */
extern void avg_getopts();
extern void avg_start();
@@ -594,36 +614,45 @@
* EFF_MCHAN just means that the effect is coded for multiple channels.
*/
-effect_t effects[] = {
+st_effect_t st_effects[] = {
{"null", 0, /* stand-in, never gets called */
- nothing, nothing, nothing, null_drain, nothing},
- {"avg", EFF_CHAN | EFF_MCHAN,
- avg_getopts, avg_start, avg_flow, null_drain, avg_stop},
+ st_nothing, st_nothing, st_nothing,
+ st_null_drain, st_nothing},
+ {"avg", ST_EFF_CHAN | ST_EFF_MCHAN,
+ avg_getopts, avg_start, avg_flow,
+ st_null_drain, avg_stop},
{"band", 0,
- band_getopts, band_start, band_flow, null_drain, band_stop},
+ band_getopts, band_start, band_flow,
+ st_null_drain, band_stop},
{"bandpass", 0,
- bandpass_getopts, bandpass_start, butterworth_flow, null_drain, nothing},
+ bandpass_getopts, bandpass_start, butterworth_flow,
+ st_null_drain, st_nothing},
{"bandreject", 0,
- bandreject_getopts, bandreject_start, butterworth_flow, null_drain, nothing},
+ bandreject_getopts, bandreject_start, butterworth_flow,
+ st_null_drain, st_nothing},
{"chorus", 0,
chorus_getopts, chorus_start, chorus_flow,
- chorus_drain, chorus_stop},
- {"compand", EFF_MCHAN,
+ chorus_drain, chorus_stop},
+ {"compand", ST_EFF_MCHAN,
compand_getopts, compand_start, compand_flow,
- null_drain, nothing},
- {"copy", EFF_MCHAN,
- copy_getopts, copy_start, copy_flow, null_drain, nothing},
- {"cut", EFF_MCHAN,
- cut_getopts, cut_start, cut_flow, null_drain, nothing},
- {"deemph", EFF_MCHAN,
+ st_null_drain, st_nothing},
+ {"copy", ST_EFF_MCHAN,
+ copy_getopts, copy_start, copy_flow,
+ st_null_drain, st_nothing},
+ {"cut", ST_EFF_MCHAN,
+ cut_getopts, cut_start, cut_flow,
+ st_null_drain, st_nothing},
+ {"deemph", ST_EFF_MCHAN,
deemph_getopts, deemph_start, deemph_flow,
- null_drain, deemph_stop},
+ st_null_drain, deemph_stop},
#ifdef USE_DYN
{"dyn", 0,
- dyn_getopts, dyn_start, dyn_flow, null_drain, dyn_stop},
+ dyn_getopts, dyn_start, dyn_flow,
+ st_null_drain, dyn_stop},
#endif
{"echo", 0,
- echo_getopts, echo_start, echo_flow, echo_drain, echo_stop},
+ echo_getopts, echo_start, echo_flow,
+ echo_drain, echo_stop},
{"echos", 0,
echos_getopts, echos_start, echos_flow,
echos_drain, echos_stop},
@@ -634,28 +663,36 @@
flanger_getopts, flanger_start, flanger_flow,
flanger_drain, flanger_stop},
{"highp", 0,
- highp_getopts, highp_start, highp_flow, null_drain,highp_stop},
+ highp_getopts, highp_start, highp_flow,
+ st_null_drain,highp_stop},
{"highpass", 0,
- highpass_getopts, highpass_start, butterworth_flow, null_drain,nothing},
+ highpass_getopts, highpass_start, butterworth_flow,
+ st_null_drain, st_nothing},
{"lowp", 0,
- lowp_getopts, lowp_start, lowp_flow, null_drain, lowp_stop},
+ lowp_getopts, lowp_start, lowp_flow,
+ st_null_drain, lowp_stop},
{"lowpass", 0,
- lowpass_getopts, lowpass_start, butterworth_flow, null_drain, nothing},
- {"map", EFF_REPORT,
- map_getopts, map_start, map_flow, null_drain, nothing},
- {"mask", EFF_MCHAN,
- mask_getopts, nothing, mask_flow, null_drain, nothing},
+ lowpass_getopts, lowpass_start, butterworth_flow,
+ st_null_drain, st_nothing},
+ {"map", ST_EFF_REPORT,
+ map_getopts, map_start, map_flow,
+ st_null_drain, st_nothing},
+ {"mask", ST_EFF_MCHAN,
+ mask_getopts, st_nothing, mask_flow,
+ st_null_drain, st_nothing},
{"phaser", 0,
phaser_getopts, phaser_start, phaser_flow,
phaser_drain, phaser_stop},
- {"pick", EFF_CHAN | EFF_MCHAN,
- pick_getopts, pick_start, pick_flow, null_drain, pick_stop},
- {"polyphase", EFF_RATE,
+ {"pick", ST_EFF_CHAN | ST_EFF_MCHAN,
+ pick_getopts, pick_start, pick_flow,
+ st_null_drain, pick_stop},
+ {"polyphase", ST_EFF_RATE,
poly_getopts, poly_start, poly_flow,
poly_drain, poly_stop},
- {"rate", EFF_RATE,
- rate_getopts, rate_start, rate_flow, null_drain, nothing},
- {"resample", EFF_RATE,
+ {"rate", ST_EFF_RATE,
+ rate_getopts, rate_start, rate_flow,
+ st_null_drain, st_nothing},
+ {"resample", ST_EFF_RATE,
resample_getopts, resample_start, resample_flow,
resample_drain, resample_stop},
{"reverb", 0,
@@ -664,14 +701,18 @@
{"reverse", 0,
reverse_getopts, reverse_start,
reverse_flow, reverse_drain, reverse_stop},
- {"split", EFF_CHAN | EFF_MCHAN,
- split_getopts, split_start, split_flow, null_drain,split_stop},
- {"stat", EFF_MCHAN | EFF_REPORT | EFF_RATE | EFF_CHAN,
- stat_getopts, stat_start, stat_flow, null_drain, stat_stop},
- {"swap", EFF_MCHAN,
- swap_getopts, swap_start, swap_flow, swap_drain, swap_stop},
+ {"split", ST_EFF_CHAN | ST_EFF_MCHAN,
+ split_getopts, split_start, split_flow,
+ st_null_drain,split_stop},
+ {"stat", ST_EFF_MCHAN | ST_EFF_REPORT | ST_EFF_RATE | ST_EFF_CHAN,
+ stat_getopts, stat_start, stat_flow,
+ st_null_drain, stat_stop},
+ {"swap", ST_EFF_MCHAN,
+ swap_getopts, swap_start, swap_flow,
+ swap_drain, swap_stop},
{"vibro", 0,
- vibro_getopts, vibro_start, vibro_flow, null_drain, nothing},
+ vibro_getopts, vibro_start, vibro_flow,
+ st_null_drain, st_nothing},
{0, 0, 0, 0, 0, 0, 0}
};
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -47,9 +47,9 @@
short sample;
};
-static void skipbytes(P2(ft_t, int));
+static int skipbytes(P2(ft_t, int));
-void hcomstartread(ft)
+int st_hcomstartread(ft)
ft_t ft;
{
struct readpriv *p = (struct readpriv *) ft->priv;
@@ -61,6 +61,7 @@
int littlendian = 1;
char *endptr;
+ int rc;
endptr = (char *) &littlendian;
@@ -73,14 +74,21 @@
}
/* Skip first 65 bytes of header */
- skipbytes(ft, 65);
+ rc = skipbytes(ft, 65);
+ if (rc)
+ return rc;
/* Check the file type (bytes 65-68) */
if (fread(buf, 1, 4, ft->fp) != 4 || strncmp(buf, "FSSD", 4) != 0)
+ {
fail("Mac header type is not FSSD");
+ return (ST_EOF);
+ }
/* Skip to byte 83 */
- skipbytes(ft, 83-69);
+ rc = skipbytes(ft, 83-69);
+ if (rc)
+ return rc;
/* Get essential numbers from the header */
datasize = rlong(ft); /* bytes 83-86 */
@@ -87,11 +95,16 @@
rsrcsize = rlong(ft); /* bytes 87-90 */
/* Skip the rest of the header (total 128 bytes) */
- skipbytes(ft, 128-91);
+ rc = skipbytes(ft, 128-91);
+ if (rc != 0)
+ return rc;
/* The data fork must contain a "HCOM" header */
if (fread(buf, 1, 4, ft->fp) != 4 || strncmp(buf, "HCOM", 4) != 0)
+ {
fail("Mac data fork is not HCOM");
+ return (ST_EOF);
+ }
/* Then follow various parameters */
huffcount = rlong(ft);
@@ -98,15 +111,21 @@
checksum = rlong(ft);
compresstype = rlong(ft);
if (compresstype > 1)
+ {
fail("Bad compression type in HCOM header");
+ return (ST_EOF);
+ }
divisor = rlong(ft);
if (divisor == 0 || divisor > 4)
+ {
fail("Bad sampling rate divisor in HCOM header");
+ return (ST_EOF);
+ }
dictsize = rshort(ft);
/* Translate to sox parameters */
- ft->info.style = UNSIGNED;
- ft->info.size = BYTE;
+ ft->info.style = ST_ENCODING_UNSIGNED;
+ ft->info.size = ST_SIZE_BYTE;
ft->info.rate = 22050 / divisor;
ft->info.channels = 1;
@@ -113,7 +132,10 @@
/* Allocate memory for the dictionary */
p->dictionary = (dictent *) malloc(511 * sizeof(dictent));
if (p->dictionary == NULL)
+ {
fail("can't malloc memory for Huffman dictionary");
+ return (0);
+ }
/* Read dictionary */
for(i = 0; i < dictsize; i++) {
@@ -125,7 +147,9 @@
p->dictionary[i].dict_rightson);
*/
}
- skipbytes(ft, 1); /* skip pad byte */
+ rc = skipbytes(ft, 1); /* skip pad byte */
+ if (rc)
+ return rc;
/* Initialized the decompression engine */
p->checksum = checksum;
@@ -136,19 +160,26 @@
p->cksum = 0;
p->dictentry = 0;
p->nrbits = -1; /* Special case to get first byte */
+
+ return (ST_SUCCESS);
}
-static void skipbytes(ft, n)
+/* FIXME: Move to misc.c */
+static int skipbytes(ft, n)
ft_t ft;
int n;
{
while (--n >= 0) {
if (getc(ft->fp) == EOF)
+ {
fail("unexpected EOF in Mac header");
+ return(ST_EOF);
+ }
}
+ return(ST_SUCCESS);
}
-int hcomread(ft, buf, len)
+LONG st_hcomread(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
@@ -161,7 +192,10 @@
return 0; /* Don't know if this can happen... */
p->sample = getc(ft->fp);
if (p->sample == EOF)
+ {
fail("unexpected EOF at start of HCOM data");
+ return (0);
+ }
*buf++ = (p->sample - 128) * 0x1000000L;
p->huffcount--;
p->nrbits = 0;
@@ -175,7 +209,10 @@
if(p->nrbits == 0) {
p->current = rlong(ft);
if (feof(ft->fp))
+ {
fail("unexpected EOF in HCOM data");
+ return (0);
+ }
p->cksum += p->current;
p->nrbits = 32;
}
@@ -210,17 +247,24 @@
return done;
}
-void hcomstopread(ft)
+int st_hcomstopread(ft)
ft_t ft;
{
register struct readpriv *p = (struct readpriv *) ft->priv;
if (p->huffcount != 0)
+ {
fail("not all HCOM data read");
+ return (ST_EOF);
+ }
if(p->cksum != p->checksum)
+ {
fail("checksum error in HCOM data");
+ return (ST_EOF);
+ }
free((char *)p->dictionary);
p->dictionary = NULL;
+ return (ST_SUCCESS);
}
struct writepriv {
@@ -231,7 +275,7 @@
#define BUFINCR (10*BUFSIZ)
-void hcomstartwrite(ft)
+int st_hcomstartwrite(ft)
ft_t ft;
{
register struct writepriv *p = (struct writepriv *) ft->priv;
@@ -256,9 +300,10 @@
break;
default:
fail("unacceptable output rate for HCOM: try 5512, 7350, 11025 or 22050 hertz");
+ return (ST_EOF);
}
- ft->info.size = BYTE;
- ft->info.style = UNSIGNED;
+ ft->info.size = ST_SIZE_BYTE;
+ ft->info.style = ST_ENCODING_UNSIGNED;
ft->info.channels = 1;
p->size = BUFINCR;
@@ -265,21 +310,32 @@
p->pos = 0;
p->data = (unsigned char *) malloc(p->size);
if (p->data == NULL)
+ {
fail("can't malloc buffer for uncompressed HCOM data");
+ return (ST_EOF);
+ }
+ return (ST_SUCCESS);
}
-void hcomwrite(ft, buf, len)
+LONG st_hcomwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
register struct writepriv *p = (struct writepriv *) ft->priv;
LONG datum;
+ LONG save_len = len;
+ if (len == 0)
+ return (0);
+
if (p->pos + len > p->size) {
p->size = ((p->pos + len) / BUFINCR + 1) * BUFINCR;
p->data = (unsigned char *) realloc(p->data, p->size);
if (p->data == NULL)
+ {
fail("can't realloc buffer for uncompressed HCOM data");
+ return (0);
+ }
}
while (--len >= 0) {
@@ -288,6 +344,8 @@
datum ^= 128;
p->data[p->pos++] = datum;
}
+
+ return (save_len - len);
}
/* Some global compression stuff hcom uses. hcom currently has problems */
@@ -321,7 +379,7 @@
static LONG curword;
static int nbits;
-/* SJB: candidates for misc.c */
+/* FIXME: Place in misc.c */
static void putlong(c, v)
unsigned char *c;
LONG v;
@@ -364,7 +422,7 @@
}
}
-static void compress(df, dl, fr)
+static int compress(df, dl, fr)
unsigned char **df;
LONG *dl;
float fr;
@@ -442,7 +500,10 @@
report(" Original size: %6d bytes", *dl);
report("Compressed size: %6d bytes", l);
if((datafork = (unsigned char *)malloc((unsigned)l)) == NULL)
+ {
fail("can't malloc buffer for compressed HCOM data");
+ return (ST_EOF);
+ }
ddf = datafork + 22;
for(i = 0; i < dictsize; i++) {
putshort(ddf, dictionary[i].dict_leftson);
@@ -470,8 +531,11 @@
putshort(datafork + 20, dictsize);
*df = datafork; /* reassign passed pointer to new datafork */
*dl = l; /* and its compressed length */
+
+ return (ST_SUCCESS);
}
+/* FIXME: Place in misc.c */
static void padbytes(ft, n)
ft_t ft;
int n;
@@ -483,17 +547,21 @@
/* End of hcom utility routines */
-void hcomstopwrite(ft)
+int st_hcomstopwrite(ft)
ft_t ft;
{
register struct writepriv *p = (struct writepriv *) ft->priv;
unsigned char *compressed_data = p->data;
LONG compressed_len = p->pos;
+ int rc;
/* Compress it all at once */
- compress(&compressed_data, &compressed_len, (double) ft->info.rate);
+ rc = compress(&compressed_data, &compressed_len, (double) ft->info.rate);
free((char *) p->data);
+ if (rc)
+ return 0;
+
/* Write the header */
(void) fwrite("\000\001A", 1, 3, ft->fp); /* Dummy file name "A" */
padbytes(ft, 65-3);
@@ -503,14 +571,26 @@
wlong(ft, (ULONG) 0); /* rsrc size */
padbytes(ft, 128 - 91);
if (ferror(ft->fp))
+ {
fail("write error in HCOM header");
+ return (ST_EOF);
+ }
/* Write the compressed_data fork */
if (fwrite((char *) compressed_data, 1, (int)compressed_len, ft->fp) != compressed_len)
+ {
fail("can't write compressed HCOM data");
+ rc = ST_EOF;
+ }
+ else
+ rc = ST_SUCCESS;
free((char *) compressed_data);
+ if (rc)
+ return rc;
+
/* Pad the compressed_data fork to a multiple of 128 bytes */
padbytes(ft, 128 - (int) (compressed_len%128));
-}
+ return (ST_SUCCESS);
+}
--- a/src/mask.c
+++ b/src/mask.c
@@ -57,8 +57,8 @@
len = ((*isamp > *osamp) ? *osamp : *isamp);
switch (effp->outinfo.style) {
- case ULAW:
- case ALAW:
+ case ST_ENCODING_ULAW:
+ case ST_ENCODING_ALAW:
for(done = 0; done < len; done++) {
tri16 = (rand() + rand()) - 32767;
@@ -68,7 +68,7 @@
break;
default:
switch (effp->outinfo.size) {
- case BYTE:
+ case ST_SIZE_BYTE:
for(done = 0; done < len; done++) {
tri16 = (rand() + rand()) - 32767;
@@ -76,7 +76,7 @@
*obuf++ = l;
}
break;
- case WORD:
+ case ST_SIZE_WORD:
for(done = 0; done < len; done++) {
tri16 = (rand() + rand()) - 32767;
--- a/src/maud.c
+++ b/src/maud.c
@@ -40,7 +40,7 @@
* size and style of samples,
* mono/stereo/quad.
*/
-void maudstartread(ft)
+int st_maudstartread(ft)
ft_t ft;
{
struct maudstuff * p = (struct maudstuff *) ft->priv;
@@ -57,9 +57,12 @@
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed for rawread() */
- rawstartread(ft);
+ rc = st_rawstartread(ft);
+ if (rc)
+ return rc;
endptr = (char *) &littlendian;
/* maud is in big endian format. Swap whats read in
@@ -72,12 +75,18 @@
/* read FORM chunk */
if (fread(buf, 1, 4, ft->fp) != 4 || strncmp(buf, "FORM", 4) != 0)
+ {
fail("MAUD: header does not begin with magic word 'FORM'");
+ return (ST_EOF);
+ }
rlong(ft); /* totalsize */
if (fread(buf, 1, 4, ft->fp) != 4 || strncmp(buf, "MAUD", 4) != 0)
+ {
fail("MAUD: 'FORM' chunk does not specify 'MAUD' as type");
+ return(ST_EOF);
+ }
/* read chunks until 'BODY' (or end) */
@@ -91,7 +100,11 @@
if (strncmp(buf,"MHDR",4) == 0) {
chunksize = rlong(ft);
- if (chunksize != 8*4) fail ("MAUD: MHDR chunk has bad size");
+ if (chunksize != 8*4)
+ {
+ fail ("MAUD: MHDR chunk has bad size");
+ return(0);
+ }
/* fseek(ft->fp,12,SEEK_CUR); */
@@ -100,7 +113,11 @@
rshort(ft); /* number of bits per sample after decompression */
nom = rlong(ft); /* clock source frequency */
denom = rshort(ft); /* clock devide */
- if (denom == 0) fail("MAUD: frequency denominator == 0, failed");
+ if (denom == 0)
+ {
+ fail("MAUD: frequency denominator == 0, failed");
+ return (ST_EOF);
+ }
ft->info.rate = nom / denom;
@@ -114,11 +131,15 @@
break;
default:
fail("MAUD: unsupported number of channels in file");
- break;
+ return (ST_EOF);
}
chaninf = rshort(ft); /* number of channels (mono: 1, stereo: 2, ...) */
- if (chaninf != ft->info.channels) fail("MAUD: unsupported number of channels in file");
+ if (chaninf != ft->info.channels)
+ {
+ fail("MAUD: unsupported number of channels in file");
+ return(ST_EOF);
+ }
chaninf = rshort(ft); /* compression type */
@@ -127,22 +148,26 @@
rlong(ft);
if (bitpersam == 8 && chaninf == 0) {
- ft->info.size = BYTE;
- ft->info.style = UNSIGNED;
+ ft->info.size = ST_SIZE_BYTE;
+ ft->info.style = ST_ENCODING_UNSIGNED;
}
else if (bitpersam == 8 && chaninf == 2) {
- ft->info.size = BYTE;
- ft->info.style = ALAW;
+ ft->info.size = ST_SIZE_BYTE;
+ ft->info.style = ST_ENCODING_ALAW;
}
else if (bitpersam == 8 && chaninf == 3) {
- ft->info.size = BYTE;
- ft->info.style = ULAW;
+ ft->info.size = ST_SIZE_BYTE;
+ ft->info.style = ST_ENCODING_ULAW;
}
else if (bitpersam == 16 && chaninf == 0) {
- ft->info.size = WORD;
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
}
- else fail("MAUD: unsupported compression type detected");
+ else
+ {
+ fail("MAUD: unsupported compression type detected");
+ return(ST_EOF);
+ }
ft->comment = 0;
@@ -154,9 +179,17 @@
if (chunksize & 1)
chunksize++;
chunk_buf = (char *) malloc(chunksize + 1);
+ if (!chunk_buf)
+ {
+ fail("Couldn't alloc resources");
+ return(ST_EOF);
+ }
if (fread(chunk_buf,1,(int)chunksize,ft->fp)
!= chunksize)
+ {
fail("MAUD: Unexpected EOF in ANNO header");
+ return(ST_EOF);
+ }
chunk_buf[chunksize] = '\0';
report ("%s",chunk_buf);
free(chunk_buf);
@@ -173,8 +206,13 @@
}
- if (strncmp(buf,"MDAT",4) != 0) fail("MAUD: MDAT chunk not found");
+ if (strncmp(buf,"MDAT",4) != 0)
+ {
+ fail("MAUD: MDAT chunk not found");
+ return(ST_EOF);
+ }
p->nsamples = rlong(ft);
+ return(ST_SUCCESS);
}
/*
@@ -184,11 +222,11 @@
* Return number of samples read.
*/
-LONG maudread(ft, buf, len)
+LONG st_maudread(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
- return (rawread(ft, buf, len));
+ return (st_rawread(ft, buf, len));
}
/*
@@ -195,14 +233,14 @@
* Do anything required when you stop reading samples.
* Don't close input file!
*/
-void maudstopread(ft)
+int st_maudstopread(ft)
ft_t ft;
{
/* Needed because of rawread() */
- rawstopread(ft);
+ return st_rawstopread(ft);
}
-void maudstartwrite(ft)
+int st_maudstartwrite(ft)
ft_t ft;
{
struct maudstuff * p = (struct maudstuff *) ft->priv;
@@ -209,9 +247,12 @@
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed for rawwrite() */
- rawstartwrite(ft);
+ rc = st_rawstartwrite(ft);
+ if (rc)
+ return rc;
endptr = (char *) &littlendian;
/* maud is in big endian format. Swap whats read in
@@ -223,21 +264,30 @@
}
/* If you have to seek around the output file */
- if (! ft->seekable) fail("Output .maud file must be a file, not a pipe");
+ if (! ft->seekable)
+ {
+ fail("Output .maud file must be a file, not a pipe");
+ return (ST_EOF);
+ }
if (ft->info.channels != 1 && ft->info.channels != 2) {
fail("MAUD: unsupported number of channels, unable to store");
+ return(ST_EOF);
}
- if (ft->info.size == WORD) ft->info.style = SIGN2;
- if (ft->info.style == ULAW || ft->info.style == ALAW) ft->info.size = BYTE;
- if (ft->info.size == BYTE && ft->info.style == SIGN2) ft->info.style = UNSIGNED;
+ if (ft->info.size == ST_SIZE_WORD) ft->info.style = ST_ENCODING_SIGN2;
+ if (ft->info.style == ST_ENCODING_ULAW ||
+ ft->info.style == ST_ENCODING_ALAW) ft->info.size = ST_SIZE_BYTE;
+ if (ft->info.size == ST_SIZE_BYTE &&
+ ft->info.style == ST_ENCODING_SIGN2)
+ ft->info.style = ST_ENCODING_UNSIGNED;
p->nsamples = 0x7f000000L;
maudwriteheader(ft);
p->nsamples = 0;
+ return (ST_SUCCESS);
}
-void maudwrite(ft, buf, len)
+LONG st_maudwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
@@ -245,20 +295,29 @@
p->nsamples += len;
- rawwrite(ft, buf, len);
+ return st_rawwrite(ft, buf, len);
}
-void maudstopwrite(ft)
+int st_maudstopwrite(ft)
ft_t ft;
{
+ int rc;
+
/* Flush out remaining samples*/
- rawstopwrite(ft);
+ rc = st_rawstopwrite(ft);
+ if (rc)
+ return rc;
/* All samples are already written out. */
- if (fseek(ft->fp, 0L, 0) != 0) fail("can't rewind output file to rewrite MAUD header");
+ if (fseek(ft->fp, 0L, 0) != 0)
+ {
+ fail("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))
@@ -277,18 +336,18 @@
switch (ft->info.style) {
- case UNSIGNED:
+ case ST_ENCODING_UNSIGNED:
wshort(ft, (int) 8); /* number of bits per sample as stored in MDAT */
wshort(ft, (int) 8); /* number of bits per sample after decompression */
break;
- case SIGN2:
+ case ST_ENCODING_SIGN2:
wshort(ft, (int) 16); /* number of bits per sample as stored in MDAT */
wshort(ft, (int) 16); /* number of bits per sample after decompression */
break;
- case ALAW:
- case ULAW:
+ case ST_ENCODING_ALAW:
+ case ST_ENCODING_ULAW:
wshort(ft, (int) 8); /* number of bits per sample as stored in MDAT */
wshort(ft, (int) 16); /* number of bits per sample after decompression */
break;
@@ -309,16 +368,16 @@
switch (ft->info.style) {
- case UNSIGNED:
- case SIGN2:
+ case ST_ENCODING_UNSIGNED:
+ case ST_ENCODING_SIGN2:
wshort(ft, (int) 0); /* no compression */
break;
- case ULAW:
+ case ST_ENCODING_ULAW:
wshort(ft, (int) 3);
break;
- case ALAW:
+ case ST_ENCODING_ALAW:
wshort(ft, (int) 2);
break;
@@ -335,4 +394,3 @@
fputs ("MDAT", ft->fp);
wlong(ft, p->nsamples * ft->info.size ); /* samples in file */
}
-
--- a/src/misc.c
+++ b/src/misc.c
@@ -19,7 +19,7 @@
#include <stdlib.h>
#include <time.h>
-const char *sizes[] = {
+const char *st_sizes_str[] = {
"NONSENSE!",
"bytes",
"shorts",
@@ -30,7 +30,7 @@
"IEEE floats"
};
-const char *styles[] = {
+const char *st_encodings_str[] = {
"NONSENSE!",
"unsigned",
"signed (2's complement)",
@@ -57,7 +57,7 @@
fread(&us, 2, 1, ft->fp);
if (ft->swap)
- us = swapw(us);
+ us = st_swapw(us);
return us;
}
@@ -68,7 +68,7 @@
unsigned short us;
{
if (ft->swap)
- us = swapw(us);
+ us = st_swapw(us);
if (fwrite(&us, 2, 1, ft->fp) != 1)
fail(writerr);
return(0);
@@ -83,7 +83,7 @@
fread(&ul, 4, 1, ft->fp);
if (ft->swap)
- ul = swapl(ul);
+ ul = st_swapl(ul);
return ul;
}
@@ -94,7 +94,7 @@
ULONG ul;
{
if (ft->swap)
- ul = swapl(ul);
+ ul = st_swapl(ul);
if (fwrite(&ul, 4, 1, ft->fp) != 1)
fail(writerr);
return(0);
@@ -109,7 +109,7 @@
fread(&f, sizeof(float), 1, ft->fp);
if (ft->swap)
- f = swapf(f);
+ f = st_swapf(f);
return f;
}
@@ -121,7 +121,7 @@
float t = f;
if (ft->swap)
- t = swapf(t);
+ t = st_swapf(t);
if (fwrite(&t, sizeof(float), 1, ft->fp) != 1)
fail(writerr);
}
@@ -135,7 +135,7 @@
fread(&d, sizeof(double), 1, ft->fp);
if (ft->swap)
- d = swapd(d);
+ d = st_swapd(d);
return d;
}
@@ -146,7 +146,7 @@
double d;
{
if (ft->swap)
- d = swapd(d);
+ d = st_swapd(d);
if (fwrite(&d, sizeof(double), 1, ft->fp) != 1)
fail(writerr);
}
@@ -153,7 +153,7 @@
/* generic swap routine */
static void
-swapb(l, f, n)
+st_swapb(l, f, n)
char *l, *f;
int n;
{ register int i;
@@ -167,7 +167,7 @@
#ifndef HAVE_BYTESWAP_H
unsigned short
-swapw(us)
+st_swapw(us)
unsigned short us;
{
return ((us >> 8) | (us << 8)) & 0xffff;
@@ -174,7 +174,7 @@
}
ULONG
-swapl(ul)
+st_swapl(ul)
ULONG ul;
{
return (ul >> 24) | ((ul >> 8) & 0xff00) | ((ul << 8) & 0xff0000L) | (ul << 24);
@@ -182,7 +182,7 @@
/* return swapped 32-bit float */
float
-swapf(float f)
+st_swapf(float f)
{
union {
ULONG l;
@@ -197,21 +197,21 @@
#endif
double
-swapd(df)
+st_swapd(df)
double df;
{
double sdf;
- swapb(&df, &sdf, sizeof(double));
+ st_swapb(&df, &sdf, sizeof(double));
return (sdf);
}
/* dummy routines for do-nothing functions */
-void nothing(P0) {}
-LONG nothing_success(P0) {return(0);}
+void st_nothing(P0) {}
+LONG st_nothing_success(P0) {return(0);}
/* dummy drain routine for effects */
-void null_drain(effp, obuf, osamp)
+void st_null_drain(effp, obuf, osamp)
eff_t effp;
LONG *obuf;
LONG *osamp;
@@ -316,7 +316,7 @@
}
const char *
-version()
+st_version()
{
static char versionstr[20];
--- a/src/oss.c
+++ b/src/oss.c
@@ -41,7 +41,7 @@
#include "st.h"
/* common r/w initialization code */
-static void ossdspinit(ft)
+static int ossdspinit(ft)
ft_t ft;
{
int samplesize = 8, dsp_stereo;
@@ -48,30 +48,30 @@
int tmp;
if (ft->info.rate == 0.0) ft->info.rate = 8000;
- if (ft->info.size == -1) ft->info.size = BYTE;
- if (ft->info.size == BYTE) {
+ if (ft->info.size == -1) ft->info.size = ST_SIZE_BYTE;
+ if (ft->info.size == ST_SIZE_BYTE) {
samplesize = 8;
if (ft->info.style == -1)
- ft->info.style = UNSIGNED;
- if (ft->info.style != UNSIGNED) {
+ ft->info.style = ST_ENCODING_UNSIGNED;
+ if (ft->info.style != ST_ENCODING_UNSIGNED) {
report("OSS driver only supports unsigned with bytes");
report("Forcing to unsigned");
- ft->info.style = UNSIGNED;
+ ft->info.style = ST_ENCODING_UNSIGNED;
}
}
- else if (ft->info.size == WORD) {
+ else if (ft->info.size == ST_SIZE_WORD) {
samplesize = 16;
if (ft->info.style == -1)
- ft->info.style = SIGN2;
- if (ft->info.style != SIGN2) {
+ ft->info.style = ST_ENCODING_SIGN2;
+ if (ft->info.style != ST_ENCODING_SIGN2) {
report("OSS driver only supports signed with words");
report("Forcing to signed linear");
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
}
}
else {
- ft->info.size = WORD;
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
report("OSS driver only supports bytes and words");
report("Forcing to signed linear word");
}
@@ -83,6 +83,7 @@
ioctl (fileno(ft->fp), SNDCTL_DSP_GETBLKSIZE, &ft->file.size);
if (ft->file.size < 4 || ft->file.size > 65536) {
fail("Invalid audio buffer size %d", ft->file.size);
+ returen (ST_EOF);
}
ft->file.count = 0;
ft->file.pos = 0;
@@ -90,10 +91,12 @@
if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
fail("Unable to allocate input/output buffer of size %d", ft->file.size);
+ return (ST_EOF);
}
if (ioctl(fileno(ft->fp), SNDCTL_DSP_SYNC, NULL) < 0) {
fail("Unable to sync dsp");
+ return (ST_EOF);
}
tmp = samplesize;
@@ -100,6 +103,7 @@
ioctl(fileno(ft->fp), SNDCTL_DSP_SAMPLESIZE, &tmp);
if (tmp != samplesize) {
fail("Unable to set the sample size to %d", samplesize);
+ return (ST_EOF);
}
if (ft->info.channels == 2) dsp_stereo = 1;
@@ -134,6 +138,7 @@
/* Change to non-buffered I/O */
setvbuf(ft->fp, NULL, _IONBF, sizeof(char) * ft->file.size);
+ return(ST_SUCCESS);
}
/*
* Do anything required before you start reading samples.
@@ -142,16 +147,18 @@
* size and style of samples,
* mono/stereo/quad.
*/
-void ossdspstartread(ft)
+int st_ossdspstartread(ft)
ft_t ft;
{
- ossdspinit(ft);
+ int rc;
+ rc = ossdspinit(ft);
sigintreg(ft); /* Prepare to catch SIGINT */
+ return rc;
}
-void ossdspstartwrite(ft)
+int st_ossdspstartwrite(ft)
ft_t ft;
{
- ossdspinit(ft);
+ return ossdspinit(ft);
}
#endif
--- a/src/rate.c
+++ b/src/rate.c
@@ -73,7 +73,8 @@
if (effp->ininfo.rate >= 65535 || effp->outinfo.rate >= 65535)
fail("rate effect can only handle rates <= 65535");
- if (effp->ininfo.size == DWORD || effp->ininfo.size == FLOAT)
+ if (effp->ininfo.size == ST_SIZE_DWORD ||
+ effp->ininfo.size == ST_SIZE_FLOAT)
fail("rate effect does not work on data greater then 16 bits");
rate->opos_frac=0;
--- a/src/raw.c
+++ b/src/raw.c
@@ -33,23 +33,37 @@
static void rawdefaults(P1(ft_t ft));
-void rawstartread(ft)
+int st_rawstartread(ft)
ft_t ft;
{
ft->file.buf = malloc(BUFSIZ);
+ if (!ft->file.buf)
+ {
+ fail("Unable to alloc resources");
+ return(ST_EOF);
+ }
ft->file.size = BUFSIZ;
ft->file.count = 0;
ft->file.pos = 0;
ft->file.eof = 0;
+
+ return(ST_SUCCESS);
}
-void rawstartwrite(ft)
+int st_rawstartwrite(ft)
ft_t ft;
{
ft->file.buf = malloc(BUFSIZ);
+ if (!ft->file.buf)
+ {
+ fail("Unable to alloc resources");
+ return(ST_EOF);
+ }
ft->file.size = BUFSIZ;
ft->file.pos = 0;
ft->file.eof = 0;
+
+ return(ST_SUCCESS);
}
/* Read raw file data, and convert it to */
@@ -77,6 +91,7 @@
}
/* Util to reverse the n chars starting at p. */
+/* FIXME: Move to misc.c */
static void swapn(p, n)
char *p;
int n;
@@ -145,7 +160,7 @@
return done;
}
-LONG rawread(ft, buf, nsamp)
+LONG st_rawread(ft, buf, nsamp)
ft_t ft;
LONG *buf, nsamp;
{
@@ -152,10 +167,10 @@
int done = 0;
switch(ft->info.size) {
- case BYTE:
+ case ST_SIZE_BYTE:
switch(ft->info.style)
{
- case SIGN2:
+ case ST_ENCODING_SIGN2:
while(done < nsamp) {
LONG datum;
datum = blockgetc(ft);
@@ -166,7 +181,7 @@
done++;
}
return done;
- case UNSIGNED:
+ case ST_ENCODING_UNSIGNED:
while(done < nsamp) {
LONG datum;
datum = blockgetc(ft);
@@ -179,7 +194,7 @@
done++;
}
return done;
- case ULAW:
+ case ST_ENCODING_ULAW:
while(done < nsamp) {
LONG datum;
datum = blockgetc(ft);
@@ -191,7 +206,7 @@
done++;
}
return done;
- case ALAW:
+ case ST_ENCODING_ALAW:
while(done < nsamp) {
LONG datum;
datum = blockgetc(ft);
@@ -205,12 +220,12 @@
return done;
}
break;
- case WORD:
+ case ST_SIZE_WORD:
switch(ft->info.style)
{
- case SIGN2:
+ case ST_ENCODING_SIGN2:
return blockr_sw(buf, nsamp, ft);
- case UNSIGNED:
+ case ST_ENCODING_UNSIGNED:
while(done < nsamp) {
LONG x;
unsigned short s;
@@ -225,18 +240,18 @@
done++;
}
return done;
- case ULAW:
+ case ST_ENCODING_ULAW:
fail("No U-Law support for shorts");
- return done;
- case ALAW:
+ return 0;
+ case ST_ENCODING_ALAW:
fail("No A-Law support for shorts");
- return done;
+ return 0;
}
break;
- case DWORD:
+ case ST_SIZE_DWORD:
switch(ft->info.style)
{
- case SIGN2:
+ case ST_ENCODING_SIGN2:
while(done < nsamp) {
blockr(buf, sizeof(LONG), ft);
if (ft->file.eof)
@@ -248,7 +263,7 @@
return done;
}
break;
- case FLOAT:
+ case ST_SIZE_FLOAT:
while(done < nsamp) {
float f;
blockr(&f, sizeof(float), ft);
@@ -262,14 +277,16 @@
fail("Drop through in rawread!");
}
fail("Sorry, don't have code to read %s, %s",
- styles[ft->info.style], sizes[ft->info.size]);
+ st_encodings_str[ft->info.style], st_sizes_str[ft->info.size]);
return(0);
}
-void rawstopread(ft)
+int st_rawstopread(ft)
ft_t ft;
{
free(ft->file.buf);
+
+ return(ST_SUCCESS);
}
static void blockflush(ft)
@@ -307,11 +324,12 @@
ft->file.pos += n;
}
-static void blockw_sw(ft, buf, nsamp)
+static LONG blockw_sw(ft, buf, nsamp)
ft_t ft;
LONG *buf, nsamp;
{
short *top;
+ LONG save_nsamp = nsamp;
top = (short*)(ft->file.buf + ft->file.size);
while (nsamp) {
@@ -328,16 +346,16 @@
# ifdef MAXWSPEED
q -= 4;
while (p<q) {
- p[0] = swapw((buf[0] + 0x8000) >> 16); /* round for 16 bit */
- p[1] = swapw((buf[1] + 0x8000) >> 16); /* round for 16 bit */
- p[2] = swapw((buf[2] + 0x8000) >> 16); /* round for 16 bit */
- p[3] = swapw((buf[3] + 0x8000) >> 16); /* round for 16 bit */
+ p[0] = st_swapw((buf[0] + 0x8000) >> 16); /* round for 16 bit */
+ p[1] = st_swapw((buf[1] + 0x8000) >> 16); /* round for 16 bit */
+ p[2] = st_swapw((buf[2] + 0x8000) >> 16); /* round for 16 bit */
+ p[3] = st_swapw((buf[3] + 0x8000) >> 16); /* round for 16 bit */
p += 4; buf += 4;
}
q += 4;
# endif
while (p<q) {
- *p++ = swapw(((*buf++) + 0x8000) >> 16); /* round for 16 bit */
+ *p++ = st_swapw(((*buf++) + 0x8000) >> 16); /* round for 16 bit */
}
} else {
# ifdef MAXWSPEED
@@ -356,12 +374,13 @@
}
}
}
+ return(save_nsamp - nsamp);
}
/* Convert the sox internal signed long format */
/* to the raw file data, and write it. */
-void rawwrite(ft, buf, nsamp)
+LONG st_rawwrite(ft, buf, nsamp)
ft_t ft;
LONG *buf, nsamp;
{
@@ -368,10 +387,10 @@
int done = 0;
switch(ft->info.size) {
- case BYTE:
+ case ST_SIZE_BYTE:
switch(ft->info.style)
{
- case SIGN2:
+ case ST_ENCODING_SIGN2:
while(done < nsamp) {
int datum;
/* scale signed up to long's range */
@@ -379,8 +398,8 @@
blockputc(ft, datum);
done++;
}
- return;
- case UNSIGNED:
+ return done;
+ case ST_ENCODING_UNSIGNED:
while(done < nsamp) {
int datum;
/* scale signed up to long's range */
@@ -390,8 +409,8 @@
blockputc(ft, datum);
done++;
}
- return;
- case ULAW:
+ return done;
+ case ST_ENCODING_ULAW:
while(done < nsamp) {
int datum;
/* scale signed up to long's range */
@@ -402,8 +421,8 @@
blockputc(ft, datum);
done++;
}
- return;
- case ALAW:
+ return done;
+ case ST_ENCODING_ALAW:
while(done < nsamp) {
int datum;
/* scale signed up to long's range */
@@ -414,16 +433,15 @@
blockputc(ft, datum);
done++;
}
- return;
+ return done;
}
break;
- case WORD:
+ case ST_SIZE_WORD:
switch(ft->info.style)
{
- case SIGN2:
- blockw_sw(ft,buf,nsamp);
- return;
- case UNSIGNED:
+ case ST_ENCODING_SIGN2:
+ return blockw_sw(ft,buf,nsamp);
+ case ST_ENCODING_UNSIGNED:
while(done < nsamp) {
int datum;
unsigned short s;
@@ -434,19 +452,19 @@
blockw(&s, sizeof(short),ft);
done++;
}
- return;
- case ULAW:
+ return done;
+ case ST_ENCODING_ULAW:
fail("No U-Law support for shorts (try -b option ?)");
- return;
- case ALAW:
+ return 0;
+ case ST_ENCODING_ALAW:
fail("No A-Law support for shorts (try -b option ?)");
- return;
+ return 0;
}
break;
- case DWORD:
+ case ST_SIZE_DWORD:
switch(ft->info.style)
{
- case SIGN2:
+ case ST_ENCODING_SIGN2:
while(done < nsamp) {
/* scale signed up to long's range */
blockw(buf, sizeof(LONG), ft);
@@ -453,10 +471,10 @@
buf++;
done++;
}
- return;
+ return done;
}
break;
- case FLOAT:
+ case ST_SIZE_FLOAT:
while(done < nsamp) {
float f;
/* scale signed up to long's range */
@@ -464,19 +482,22 @@
blockw(&f, sizeof(float), ft);
done++;
}
- return;
+ return done;
default:
fail("Drop through in rawwrite!");
+ return 0;
}
fail("Sorry, don't have code to write %s, %s",
- styles[ft->info.style], sizes[ft->info.size]);
+ st_encodings_str[ft->info.style], st_sizes_str[ft->info.size]);
+ return 0;
}
-void rawstopwrite(ft)
+int st_rawstopwrite(ft)
ft_t ft;
{
blockflush(ft);
free(ft->file.buf);
+ return(ST_SUCCESS);
}
/*
@@ -485,45 +506,45 @@
*/
#define STARTREAD(NAME,SIZE,STYLE) \
-void NAME(ft) \
+int NAME(ft) \
ft_t ft; \
{ \
ft->info.size = SIZE; \
ft->info.style = STYLE; \
- rawstartread(ft); \
rawdefaults(ft); \
+ return st_rawstartread(ft); \
}
#define STARTWRITE(NAME,SIZE,STYLE)\
-void NAME(ft) \
+int NAME(ft) \
ft_t ft; \
{ \
ft->info.size = SIZE; \
ft->info.style = STYLE; \
- rawstartwrite(ft); \
rawdefaults(ft); \
+ return st_rawstartwrite(ft); \
}
-STARTREAD(sbstartread,BYTE,SIGN2)
-STARTWRITE(sbstartwrite,BYTE,SIGN2)
+STARTREAD(st_sbstartread,ST_SIZE_BYTE,ST_ENCODING_SIGN2)
+STARTWRITE(st_sbstartwrite,ST_SIZE_BYTE,ST_ENCODING_SIGN2)
-STARTREAD(ubstartread,BYTE,UNSIGNED)
-STARTWRITE(ubstartwrite,BYTE,UNSIGNED)
+STARTREAD(st_ubstartread,ST_SIZE_BYTE,ST_ENCODING_UNSIGNED)
+STARTWRITE(st_ubstartwrite,ST_SIZE_BYTE,ST_ENCODING_UNSIGNED)
-STARTREAD(uwstartread,WORD,UNSIGNED)
-STARTWRITE(uwstartwrite,WORD,UNSIGNED)
+STARTREAD(st_uwstartread,ST_SIZE_WORD,ST_ENCODING_UNSIGNED)
+STARTWRITE(st_uwstartwrite,ST_SIZE_WORD,ST_ENCODING_UNSIGNED)
-STARTREAD(swstartread,WORD,SIGN2)
-STARTWRITE(swstartwrite,WORD,SIGN2)
+STARTREAD(st_swstartread,ST_SIZE_WORD,ST_ENCODING_SIGN2)
+STARTWRITE(st_swstartwrite,ST_SIZE_WORD,ST_ENCODING_SIGN2)
-STARTREAD(slstartread,DWORD,SIGN2)
-STARTWRITE(slstartwrite,DWORD,SIGN2)
+STARTREAD(st_slstartread,ST_SIZE_DWORD,ST_ENCODING_SIGN2)
+STARTWRITE(st_slstartwrite,ST_SIZE_DWORD,ST_ENCODING_SIGN2)
-STARTREAD(ulstartread,BYTE,ULAW)
-STARTWRITE(ulstartwrite,BYTE,ULAW)
+STARTREAD(st_ulstartread,ST_SIZE_BYTE,ST_ENCODING_ULAW)
+STARTWRITE(st_ulstartwrite,ST_SIZE_BYTE,ST_ENCODING_ULAW)
-STARTREAD(alstartread,BYTE,ALAW)
-STARTWRITE(alstartwrite,BYTE,ALAW)
+STARTREAD(st_alstartread,ST_SIZE_BYTE,ST_ENCODING_ALAW)
+STARTWRITE(st_alstartwrite,ST_SIZE_BYTE,ST_ENCODING_ALAW)
void rawdefaults(ft)
ft_t ft;
--- a/src/reverb.c
+++ b/src/reverb.c
@@ -97,7 +97,7 @@
#include "st.h"
#define REVERB_FADE_THRESH 10
-#define DELAY_BUFSIZ ( 50L * MAXRATE )
+#define DELAY_BUFSIZ ( 50L * ST_MAXRATE )
#define MAXREVERBS 8
/* Private data for SKEL file */
--- a/src/sf.c
+++ b/src/sf.c
@@ -13,16 +13,13 @@
* Derived from: Sound Tools skeleton handler file.
*/
-#define IRCAM
#include "st.h"
-#ifdef IRCAM
#include "sfircam.h"
+
#ifndef SIZEOF_BSD_HEADER
#define SIZEOF_BSD_HEADER 1024
#endif
-#else
-#include "sfheader.h"
-#endif
+
#include <string.h>
#include <stdlib.h>
@@ -47,8 +44,8 @@
do {
sfcharp = (char *) sfcodep + sizeof(SFCODE);
if (ft->swap) {
- sfcodep->bsize = swapl(sfcodep->bsize);
- sfcodep->code = swapl(sfcodep->code);
+ sfcodep->bsize = st_swapl(sfcodep->bsize);
+ sfcodep->code = st_swapl(sfcodep->code);
}
bsize = sfcodep->bsize - sizeof(SFCODE);
switch(sfcodep->code) {
@@ -78,41 +75,34 @@
* size and style of samples,
* mono/stereo/quad.
*/
-void sfstartread(ft)
+int st_sfstartread(ft)
ft_t ft;
{
sf_t sf = (sf_t) ft->priv;
SFHEADER sfhead;
+ int rc;
/* Needed for rawread() */
- rawstartread(ft);
+ rc = st_rawstartread(ft);
+ if (rc)
+ return rc;
if (fread(&sfhead, 1, sizeof(SFHEADER), ft->fp) != sizeof(SFHEADER))
+ {
fail("unexpected EOF in SF header");
+ return(ST_EOF);
+ }
memcpy(&sf->info, &sfhead.sfinfo, sizeof(struct sfinfo));
if (ft->swap) {
-#ifdef IRCAM
- sf->info.sf_srate = swapf(sf->info.sf_srate);
-#else
- sf->info.sf_magic = swapl(sf->info.sf_magic);
- sf->info.sf_srate = swapl(sf->info.sf_srate);
-#endif
- sf->info.sf_packmode = swapl(sf->info.sf_packmode);
- sf->info.sf_chans = swapl(sf->info.sf_chans);
+ sf->info.sf_srate = st_swapf(sf->info.sf_srate);
+ sf->info.sf_packmode = st_swapl(sf->info.sf_packmode);
+ sf->info.sf_chans = st_swapl(sf->info.sf_chans);
}
-#ifdef IRCAM
if ((sfmagic1(&sfhead) != SF_MAGIC1) ||
(sfmagic2(&sfhead) != SF_MAGIC2))
fail(
"SF %s file: can't read, it is byte-swapped or it is not an IRCAM SoundFile",
ft->filename);
-#else
- if (sf->info.sf_magic != SF_MAGIC)
- if (sf->info.sf_magic == swapl(SF_MAGIC))
-fail("SF %s file: can't read, it is probably byte-swapped");
- else
-fail("SF %s file: can't read, it is not an IRCAM SoundFile");
-#endif
/*
@@ -122,24 +112,27 @@
ft->info.rate = sf->info.sf_srate;
switch(sf->info.sf_packmode) {
case SF_SHORT:
- ft->info.size = WORD;
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
break;
case SF_FLOAT:
- ft->info.size = FLOAT;
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_FLOAT;
+ ft->info.style = ST_ENCODING_SIGN2;
break;
default:
fail("Soundfile input: unknown format 0x%x\n",
sf->info.sf_packmode);
+ return(ST_EOF);
}
ft->info.channels = (int) sf->info.sf_chans;
/* Read codes and print as comments. */
readcodes(ft, &sfhead);
+
+ return(ST_SUCCESS);
}
-void sfstartwrite(ft)
+int st_sfstartwrite(ft)
ft_t ft;
{
sf_t sf = (sf_t) ft->priv;
@@ -148,11 +141,13 @@
char *sfcharp;
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed for rawwrite() */
- rawstartwrite(ft);
+ rc = st_rawstartwrite(ft);
+ if (rc)
+ return rc;
-#ifdef IRCAM
sf->info.magic_union._magic_bytes.sf_magic1 = SF_MAGIC1;
sf->info.magic_union._magic_bytes.sf_magic2 = SF_MAGIC2;
sf->info.magic_union._magic_bytes.sf_param = 0;
@@ -164,33 +159,15 @@
sf->info.magic_union._magic_bytes.sf_machine = SF_VAX;
else
sf->info.magic_union._magic_bytes.sf_machine = SF_SUN;
-#else
- sf->info.sf_magic = SF_MAGIC;
-#endif
sf->info.sf_srate = ft->info.rate;
-#ifdef LATER
- /*
- * CSound sound-files have many formats.
- * We stick with the IRCAM short-or-float scheme.
- */
- if (ft->info.size == WORD) {
- sf->info.sf_packmode = SF_SHORT;
- ft->info.style = SIGN2; /* Default to signed words */
- } else if (ft->info.size == FLOAT)
+ if (ft->info.size == ST_SIZE_FLOAT) {
sf->info.sf_packmode = SF_FLOAT;
- else
- fail("SoundFile %s: must set output as signed shorts or floats",
- ft->filename);
-#else
- if (ft->info.size == FLOAT) {
- sf->info.sf_packmode = SF_FLOAT;
- ft->info.size = FLOAT;
} else {
sf->info.sf_packmode = SF_SHORT;
- ft->info.size = WORD;
- ft->info.style = SIGN2; /* Default to signed words */
+ ft->info.size = ST_SIZE_WORD;
+ ft->info.style = ST_ENCODING_SIGN2; /* Default to signed words */
}
-#endif
+
sf->info.sf_chans = ft->info.channels;
/* Clean out structure so unused areas will remain constain */
@@ -211,6 +188,8 @@
while(sfcharp < (char *) &sfhead + SIZEOF_BSD_HEADER)
*sfcharp++ = '\0';
(void) fwrite(&sfhead, 1, sizeof(SFHEADER), ft->fp);
+
+ return(ST_SUCCESS);
}
/* Read and write are supplied by raw.c */
--- a/src/smp.c
+++ b/src/smp.c
@@ -90,7 +90,10 @@
}
for(i = 0; i < 8; i++) { /* read the 8 markers */
if (fread(trailer->markers[i].name, 1, 10, ft->fp) != 10)
- return(0);
+ {
+ fail("EOF in SMP");
+ return(ST_EOF);
+ }
trailer->markers[i].position = rlong(ft);
}
trailer->MIDInote = getc(ft->fp);
@@ -97,7 +100,7 @@
trailer->rate = rlong(ft);
trailer->SMPTEoffset = rlong(ft);
trailer->CycleSize = rlong(ft);
- return(1);
+ return(ST_SUCCESS);
}
/*
@@ -155,7 +158,10 @@
}
for(i = 0; i < 8; i++) { /* write the 8 markers */
if (fwrite(trailer->markers[i].name, 1, 10, ft->fp) != 10)
- return(0);
+ {
+ fail("EOF in SMP");
+ return(ST_EOF);
+ }
wlong(ft, trailer->markers[i].position);
}
putc(trailer->MIDInote, ft->fp);
@@ -162,7 +168,7 @@
wlong(ft, trailer->rate);
wlong(ft, trailer->SMPTEoffset);
wlong(ft, trailer->CycleSize);
- return(1);
+ return(ST_SUCCESS);
}
/*
@@ -172,7 +178,7 @@
* size and style of samples,
* mono/stereo/quad.
*/
-void smpstartread(ft)
+int st_smpstartread(ft)
ft_t ft;
{
smp_t smp = (smp_t) ft->priv;
@@ -194,15 +200,27 @@
/* If you need to seek around the input file. */
if (! ft->seekable)
+ {
fail("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)
+ {
fail("unexpected EOF in SMP header");
+ return(ST_EOF);
+ }
if (strncmp(header.Id, SVmagic, 17) != 0)
+ {
fail("SMP header does not begin with magic word %s\n", SVmagic);
+ return(ST_EOF);
+ }
if (strncmp(header.version, SVvers, 4) != 0)
+ {
fail("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 */
@@ -226,39 +244,46 @@
/* seek from the current position (the start of sample data) by */
/* NoOfSamps * 2 */
if (fseek(ft->fp, smp->NoOfSamps * 2L, 1) == -1)
+ {
fail("SMP unable to seek to trailer");
- if (!readtrailer(ft, &trailer))
+ return(ST_EOF);
+ }
+ if (readtrailer(ft, &trailer))
+ {
fail("unexpected EOF in SMP trailer");
+ return(ST_EOF);
+ }
/* seek back to the beginning of the data */
if (fseek(ft->fp, samplestart, 0) == -1)
+ {
fail("SMP unable to seek back to start of sample data");
+ return(ST_EOF);
+ }
ft->info.rate = (int) trailer.rate;
- ft->info.size = WORD;
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
ft->info.channels = 1;
- if (verbose) {
- fprintf(stderr, "SampleVision trailer:\n");
- for(i = 0; i < 8; i++) if (1 || trailer.loops[i].count) {
+ report("SampleVision trailer:\n");
+ for(i = 0; i < 8; i++) if (1 || trailer.loops[i].count) {
#ifdef __alpha__
- fprintf(stderr, "Loop %d: start: %6d", i, trailer.loops[i].start);
- fprintf(stderr, " end: %6d", trailer.loops[i].end);
+ report("Loop %d: start: %6d", i, trailer.loops[i].start);
+ report(" end: %6d", trailer.loops[i].end);
#else
- fprintf(stderr, "Loop %d: start: %6ld", i, trailer.loops[i].start);
- fprintf(stderr, " end: %6ld", trailer.loops[i].end);
+ report("Loop %d: start: %6ld", i, trailer.loops[i].start);
+ report(" end: %6ld", trailer.loops[i].end);
#endif
- fprintf(stderr, " count: %6d", trailer.loops[i].count);
- fprintf(stderr, " type: ");
- switch(trailer.loops[i].type) {
- case 0: fprintf(stderr, "off\n"); break;
- case 1: fprintf(stderr, "forward\n"); break;
- case 2: fprintf(stderr, "forward/backward\n"); break;
- }
+ report(" count: %6d", trailer.loops[i].count);
+ switch(trailer.loops[i].type) {
+ case 0: report("type: off\n"); break;
+ case 1: report("type: forward\n"); break;
+ case 2: report("type: forward/backward\n"); break;
}
- fprintf(stderr, "MIDI Note number: %d\n\n", trailer.MIDInote);
}
+ report("MIDI Note number: %d\n\n", trailer.MIDInote);
+
ft->instr.nloops = 0;
for(i = 0; i < 8; i++)
if (trailer.loops[i].type)
@@ -273,9 +298,11 @@
ft->instr.MIDIlow = ft->instr.MIDIhi =
ft->instr.MIDInote = trailer.MIDInote;
if (ft->instr.nloops > 0)
- ft->instr.loopmode = LOOP_8;
+ ft->instr.loopmode = ST_LOOP_8;
else
- ft->instr.loopmode = LOOP_NONE;
+ ft->instr.loopmode = ST_LOOP_NONE;
+
+ return(ST_SUCCESS);
}
/*
@@ -284,7 +311,7 @@
* Place in buf[].
* Return number of samples read.
*/
-LONG smpread(ft, buf, len)
+LONG st_smpread(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
@@ -304,12 +331,13 @@
* Do anything required when you stop reading samples.
* Don't close input file!
*/
-void smpstopread(ft)
+int st_smpstopread(ft)
ft_t ft;
{
+ return(ST_SUCCESS);
}
-void smpstartwrite(ft)
+int st_smpstartwrite(ft)
ft_t ft;
{
int littlendian = 1;
@@ -328,11 +356,14 @@
/* If you have to seek around the output file */
if (! ft->seekable)
+ {
fail("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 = WORD;
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_WORD;
+ ft->info.style = ST_ENCODING_SIGN2;
ft->info.channels = 1;
strcpy(header.Id, SVmagic);
@@ -342,28 +373,35 @@
/* Write file header */
if(fwrite(&header, 1, HEADERSIZE, ft->fp) != HEADERSIZE)
- fail("SMP: Can't write header completely");
+ {
+ fail("SMP: Can't write header completely");
+ return(ST_EOF);
+ }
wlong(ft, 0); /* write as zero length for now, update later */
smp->NoOfSamps = 0;
+
+ return(ST_SUCCESS);
}
-void smpwrite(ft, buf, len)
+LONG st_smpwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
smp_t smp = (smp_t) ft->priv;
register int datum;
+ LONG done = 0;
- while(len--) {
+ while(done < len) {
datum = (int) RIGHT(*buf++, 16);
wshort(ft, datum);
smp->NoOfSamps++;
+ done++;
}
- /* If you cannot write out all of the supplied samples, */
- /* fail("SMP: Can't write all samples to %s", ft->filename); */
+
+ return(done);
}
-void smpstopwrite(ft)
+int st_smpstopwrite(ft)
ft_t ft;
{
smp_t smp = (smp_t) ft->priv;
@@ -373,6 +411,11 @@
settrailer(ft, &trailer, ft->info.rate);
writetrailer(ft, &trailer);
if (fseek(ft->fp, 112, 0) == -1)
+ {
fail("SMP unable to seek back to save size");
+ return(ST_EOF);
+ }
wlong(ft, smp->NoOfSamps);
+
+ return(ST_SUCCESS);
}
--- a/src/sndrtool.c
+++ b/src/sndrtool.c
@@ -32,18 +32,21 @@
/* SNDSTARTREAD */
/*======================================================================*/
-void sndtstartread(ft)
+int st_sndtstartread(ft)
ft_t ft;
{
-char buf[97];
+ char buf[97];
-LONG rate;
+ LONG rate;
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed for rawread() */
- rawstartread(ft);
+ rc = st_rawstartread(ft);
+ if (rc)
+ return rc;
endptr = (char *) &littlendian;
/* sndt is in little endian format so
@@ -56,56 +59,72 @@
rate = 0;
-/* determine file type */
+ /* determine file type */
/* if first 5 bytes == SOUND then this is probably a sndtool sound */
/* if first word (16 bits) == 0
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)
- fail("SND: unexpected EOF");
-if (strncmp(buf,"\0\0",2) == 0)
+ if (fread(buf, 1, 2, ft->fp) != 2)
{
+ fail("SND: unexpected EOF");
+ return(ST_EOF);
+ }
+ if (strncmp(buf,"\0\0",2) == 0)
+ {
/* sounder */
rate = rshort(ft);
if (rate < 4000 || rate > 25000 )
+ {
fail ("SND: sample rate out of range");
+ return(ST_EOF);
+ }
fseek(ft->fp,4,SEEK_CUR);
}
-else
+ else
{
/* sndtool ? */
fread(&buf[2],1,6,ft->fp);
if (strncmp(buf,"SOUND",5))
+ {
fail ("SND: unrecognized SND format");
+ return(ST_EOF);
+ }
fseek(ft->fp,12,SEEK_CUR);
rate = rshort(ft);
fseek(ft->fp,6,SEEK_CUR);
if (fread(buf,1,96,ft->fp) != 96)
+ {
fail ("SND: unexpected EOF in SND header");
+ return(ST_EOF);
+ }
report ("%s",buf);
}
ft->info.channels = 1;
ft->info.rate = rate;
-ft->info.style = UNSIGNED;
-ft->info.size = BYTE;
+ft->info.style = ST_ENCODING_UNSIGNED;
+ft->info.size = ST_SIZE_BYTE;
+return (ST_SUCCESS);
}
/*======================================================================*/
/* SNDTSTARTWRITE */
/*======================================================================*/
-void sndtstartwrite(ft)
+int st_sndtstartwrite(ft)
ft_t ft;
{
-struct sndpriv *p = (struct sndpriv *) ft->priv;
+ struct sndpriv *p = (struct sndpriv *) ft->priv;
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed for rawwrite() */
- rawstartwrite(ft);
+ rc = st_rawstartwrite(ft);
+ if (rc)
+ return rc;
endptr = (char *) &littlendian;
/* sndt is in little endian format so
@@ -118,23 +137,27 @@
/* write header */
ft->info.channels = 1;
-ft->info.style = UNSIGNED;
-ft->info.size = BYTE;
+ft->info.style = ST_ENCODING_UNSIGNED;
+ft->info.size = ST_SIZE_BYTE;
p->nsamples = 0;
sndtwriteheader(ft, 0);
+return(ST_SUCCESS);
}
/*======================================================================*/
/* SNDRSTARTWRITE */
/*======================================================================*/
-void sndrstartwrite(ft)
+int st_sndrstartwrite(ft)
ft_t ft;
{
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed for rawread() */
- rawstartread(ft);
+ rc = st_rawstartread(ft);
+ if (rc)
+ return rc;
endptr = (char *) &littlendian;
/* sndr is in little endian format so
@@ -147,8 +170,8 @@
/* write header */
ft->info.channels = 1;
-ft->info.style = UNSIGNED;
-ft->info.size = BYTE;
+ft->info.style = ST_ENCODING_UNSIGNED;
+ft->info.size = ST_SIZE_BYTE;
/* sounder header */
wshort (ft,0); /* sample size code */
@@ -155,6 +178,8 @@
wshort (ft,(int) ft->info.rate); /* sample rate */
wshort (ft,10); /* volume */
wshort (ft,4); /* shift */
+
+return(ST_SUCCESS);
}
/*======================================================================*/
@@ -161,13 +186,13 @@
/* SNDTWRITE */
/*======================================================================*/
-void sndtwrite(ft, buf, len)
+LONG st_sndtwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
struct sndpriv *p = (struct sndpriv *) ft->priv;
p->nsamples += len;
- rawwrite(ft, buf, len);
+ return st_rawwrite(ft, buf, len);
}
/*======================================================================*/
@@ -174,18 +199,23 @@
/* SNDTSTOPWRITE */
/*======================================================================*/
-void sndtstopwrite(ft)
+int st_sndtstopwrite(ft)
ft_t ft;
{
struct sndpriv *p = (struct sndpriv *) ft->priv;
+ int rc;
/* Flush remaining buffer out */
- rawstopwrite(ft);
+ rc = st_rawstopwrite(ft);
+ if (rc)
+ return rc;
/* fixup file sizes in header */
if (fseek(ft->fp, 0L, 0) != 0)
fail("can't rewind output file to rewrite SND header");
sndtwriteheader(ft, p->nsamples);
+
+ return(ST_SUCCESS);
}
/*======================================================================*/
--- a/src/sox.c
+++ b/src/sox.c
@@ -95,14 +95,14 @@
static int flow_effect(P1(int));
static int drain_effect(P1(int));
-static struct soundstream informat, outformat;
+static struct st_soundstream informat, outformat;
static ft_t ft;
#define MAXEFF 4
-static struct effect eff;
-static struct effect efftab[MAXEFF]; /* table of left/mono channel effects */
-static struct effect efftabR[MAXEFF]; /* table of right channel effects */
+static struct st_effect eff;
+static struct st_effect efftab[MAXEFF]; /* table of left/mono channel effects */
+static struct st_effect efftabR[MAXEFF]; /* table of right channel effects */
/* efftab[0] is the input stream */
static int neffects; /* # of effects */
static char *ifile, *ofile;
@@ -292,56 +292,56 @@
break;
case 'b':
if (! ft) usage("-b");
- ft->info.size = BYTE;
+ ft->info.size = ST_SIZE_BYTE;
break;
case 'w':
if (! ft) usage("-w");
- ft->info.size = WORD;
+ ft->info.size = ST_SIZE_WORD;
break;
case 'l':
if (! ft) usage("-l");
- ft->info.size = DWORD;
+ ft->info.size = ST_SIZE_DWORD;
break;
case 'f':
if (! ft) usage("-f");
- ft->info.size = FLOAT;
+ ft->info.size = ST_SIZE_FLOAT;
break;
case 'd':
if (! ft) usage("-d");
- ft->info.size = DOUBLE;
+ ft->info.size = ST_SIZE_DOUBLE;
break;
case 'D':
if (! ft) usage("-D");
- ft->info.size = IEEE;
+ ft->info.size = ST_SIZE_IEEE;
break;
case 's':
if (! ft) usage("-s");
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
break;
case 'u':
if (! ft) usage("-u");
- ft->info.style = UNSIGNED;
+ ft->info.style = ST_ENCODING_UNSIGNED;
break;
case 'U':
if (! ft) usage("-U");
- ft->info.style = ULAW;
+ ft->info.style = ST_ENCODING_ULAW;
break;
case 'A':
if (! ft) usage("-A");
- ft->info.style = ALAW;
+ ft->info.style = ST_ENCODING_ALAW;
break;
case 'a':
if (! ft) usage("-a");
- ft->info.style = ADPCM;
+ ft->info.style = ST_ENCODING_ADPCM;
break;
case 'i':
if (! ft) usage("-i");
- ft->info.style = IMA_ADPCM;
+ ft->info.style = ST_ENCODING_IMA_ADPCM;
break;
case 'g':
if (! ft) usage("-g");
- ft->info.style = GSM;
+ ft->info.style = ST_ENCODING_GSM;
break;
case 'x':
@@ -414,8 +414,8 @@
report("Extract samples %lu <= x < %lu\n", informat.info.x0, informat.info.x0);
report("Input file: using sample rate %lu\n\tsize %s, style %s, %d %s",
- informat.info.rate, sizes[informat.info.size],
- styles[informat.info.style], informat.info.channels,
+ informat.info.rate, st_sizes_str[informat.info.size],
+ st_encodings_str[informat.info.style], informat.info.channels,
(informat.info.channels > 1) ? "channels" : "channel");
if (informat.comment)
report("Input file: comment \"%s\"\n", informat.comment);
@@ -465,8 +465,8 @@
st_checkformat(&outformat);
st_cmpformats(&informat, &outformat);
report("Output file: using sample rate %lu\n\tsize %s, style %s, %d %s",
- outformat.info.rate, sizes[outformat.info.size],
- styles[outformat.info.style], outformat.info.channels,
+ outformat.info.rate, st_sizes_str[outformat.info.size],
+ st_encodings_str[outformat.info.style], outformat.info.channels,
(outformat.info.channels > 1) ? "channels" : "channel");
if (outformat.comment)
report("Output file: comment \"%s\"\n", outformat.comment);
@@ -482,7 +482,7 @@
eff.ininfo = informat.info;
eff.outinfo = outformat.info;
for(i = 0; i < 8; i++) {
- memcpy(&eff.loops[i], &informat.loops[i], sizeof(struct loopinfo));
+ memcpy(&eff.loops[i], &informat.loops[i], sizeof(struct st_loopinfo));
}
eff.instr = informat.instr;
@@ -720,9 +720,9 @@
/* if given effect does these, we don't need to add them */
needrate = (informat.info.rate != outformat.info.rate) &&
- ! (effp->h->flags & EFF_RATE);
+ ! (effp->h->flags & ST_EFF_RATE);
needchan = (informat.info.channels != outformat.info.channels) &&
- ! (effp->h->flags & EFF_MCHAN);
+ ! (effp->h->flags & ST_EFF_MCHAN);
neffects = 1;
/* effect #0 is the input stream */
@@ -736,9 +736,9 @@
efftabR[i].outinfo = outformat.info;
for(j = 0; j < 8; j++) {
memcpy(&efftab[i].loops[j],
- &informat.loops[j], sizeof(struct loopinfo));
+ &informat.loops[j], sizeof(struct st_loopinfo));
memcpy(&efftabR[i].loops[j],
- &informat.loops[j], sizeof(struct loopinfo));
+ &informat.loops[j], sizeof(struct st_loopinfo));
}
efftab[i].instr = informat.instr;
efftabR[i].instr = informat.instr;
@@ -752,7 +752,7 @@
neffects = 2;
efftab[1].name = effp->name;
if ((informat.info.channels == 2) &&
- (! (effp->h->flags & EFF_MCHAN)))
+ (! (effp->h->flags & ST_EFF_MCHAN)))
efftabR[1].name = effp->name;
}
else if (soxpreview) {
@@ -797,7 +797,7 @@
efftab[1].name = effp->name;
}
if ((informat.info.channels == 2) &&
- (! (effp->h->flags & EFF_MCHAN)))
+ (! (effp->h->flags & ST_EFF_MCHAN)))
efftabR[1].name = effp->name;
}
} else { /* not preview mode */
@@ -824,7 +824,7 @@
if (needrate) {
neffects = 4;
efftab[1].name = effp->name;
- if (! (effp->h->flags & EFF_MCHAN))
+ if (! (effp->h->flags & ST_EFF_MCHAN))
efftabR[1].name = effp->name;
efftab[1].outinfo.rate = informat.info.rate;
efftab[1].outinfo.channels = informat.info.channels;
@@ -833,7 +833,7 @@
} else {
neffects = 3;
efftab[1].name = effp->name;
- if (! (effp->h->flags & EFF_MCHAN))
+ if (! (effp->h->flags & ST_EFF_MCHAN))
efftabR[1].name = effp->name;
efftab[1].outinfo.channels = informat.info.channels;
efftab[2].name = "avg";
@@ -851,7 +851,7 @@
efftab[1].name = effp->name;
}
if ((informat.info.channels == 2) &&
- (! (effp->h->flags & EFF_MCHAN)))
+ (! (effp->h->flags & ST_EFF_MCHAN)))
efftabR[1].name = effp->name;
}
}
@@ -861,9 +861,9 @@
/* shallow copy of initialized effect data */
/* XXX this assumes that effect_getopt() doesn't malloc() */
if (efftab[i].name == effp->name) {
- memcpy(&efftab[i], &eff, sizeof(struct effect));
+ memcpy(&efftab[i], &eff, sizeof(struct st_effect));
if (efftabR[i].name)
- memcpy(&efftabR[i], &eff, sizeof(struct effect));
+ memcpy(&efftabR[i], &eff, sizeof(struct st_effect));
} else {
/* set up & give default opts for added effects */
st_geteffect(&efftab[i]);
@@ -870,7 +870,7 @@
(* efftab[i].h->getopts)(&efftab[i],(int)0,(char **)0);
if (efftabR[i].name)
memcpy(&efftabR[i], &efftab[i],
- sizeof(struct effect));
+ sizeof(struct st_effect));
}
}
@@ -940,7 +940,7 @@
fprintf(stderr, "%s: ", myname);
if (verbose || !opt)
- fprintf(stderr, "%s\n\n", version());
+ fprintf(stderr, "%s\n\n", st_version());
fprintf(stderr, "Usage: %s\n\n", usagestr);
if (opt)
fprintf(stderr, "Failed at: %s\n", opt);
@@ -948,14 +948,14 @@
fprintf(stderr,"gopts: -e -h -p -v volume -V\n\n");
fprintf(stderr,"fopts: -r rate -c channels -s/-u/-U/-A/-a/-i/-g -b/-w/-l/-f/-d/-D -x\n\n");
fprintf(stderr, "effect: ");
- for (i = 1; effects[i].name != NULL; i++) {
- fprintf(stderr, "%s ", effects[i].name);
+ for (i = 1; st_effects[i].name != NULL; i++) {
+ fprintf(stderr, "%s ", st_effects[i].name);
}
fprintf(stderr, "\n\neffopts: depends on effect\n\n");
fprintf(stderr, "Supported file formats: ");
- for (i = 0; formats[i].names != NULL; i++) {
+ for (i = 0; st_formats[i].names != NULL; i++) {
/* only print the first name */
- fprintf(stderr, "%s ", formats[i].names[0]);
+ fprintf(stderr, "%s ", st_formats[i].names[0]);
}
fputc('\n', stderr);
}
--- a/src/st.h
+++ b/src/st.h
@@ -87,7 +87,7 @@
/* Signal parameters */
/* FIXME: Change to typedef */
-struct signalinfo {
+struct st_signalinfo {
LONG rate; /* sampling rate */
int size; /* word length of data */
int style; /* format of sample numbers */
@@ -103,7 +103,7 @@
/* Loop parameters */
/* FIXME: Change to typedef */
-struct loopinfo {
+struct st_loopinfo {
int start; /* first sample */
int length; /* length */
int count; /* number of repeats, 0=forever */
@@ -115,7 +115,7 @@
/* vague attempt at generic information for sampler-specific info */
/* FIXME: Change to typedef */
-struct instrinfo {
+struct st_instrinfo {
char MIDInote; /* for unity pitch playback */
char MIDIlow, MIDIhi;/* MIDI pitch-bend range */
char loopmode; /* semantics of loop data */
@@ -125,13 +125,13 @@
};
-#define MIDI_UNITY 60 /* MIDI note number to play sample at unity */
+#define ST_MIDI_UNITY 60 /* MIDI note number to play sample at unity */
/* Loop modes, upper 4 bits mask the loop blass, lower 4 bits describe */
/* the loop behaviour, ie. single shot, bidirectional etc. */
-#define LOOP_NONE 0
-#define LOOP_8 32 /* 8 loops: don't know ?? */
-#define LOOP_SUSTAIN_DECAY 64 /* AIFF style: one sustain & one decay loop */
+#define ST_LOOP_NONE 0
+#define ST_LOOP_8 32 /* 8 loops: don't know ?? */
+#define ST_LOOP_SUSTAIN_DECAY 64 /* AIFF style: one sustain & one decay loop */
/*
* File buffer info. Holds info so that data can be read in blocks.
@@ -138,7 +138,7 @@
*/
/* FIXME: Change to typedef */
-struct fileinfo {
+struct st_fileinfo {
char *buf; /* Pointer to data buffer */
int size; /* Size of buffer */
int count; /* Count read in to buffer */
@@ -151,31 +151,31 @@
* Format information for input and output files.
*/
-#define PRIVSIZE 330
+#define ST_MAX_PRIVSIZE 330
-#define NLOOPS 8
+#define ST_MAX_NLOOPS 8
/*
* Handler structure for each format.
*/
-typedef struct soundstream *ft_t;
+typedef struct st_soundstream *ft_t;
-typedef struct format {
+typedef struct st_format {
char **names; /* file type names */
int flags; /* details about file type */
- void (*startread)(P1(ft_t ft));
+ int (*startread)(P1(ft_t ft));
LONG (*read)(P3(ft_t ft, LONG *buf, LONG len));
- void (*stopread)(P1(ft_t ft));
- void (*startwrite)(P1(ft_t ft));
- void (*write)(P3(ft_t ft, LONG *buf, LONG len));
- void (*stopwrite)(P1(ft_t ft));
-} format_t;
+ int (*stopread)(P1(ft_t ft));
+ int (*startwrite)(P1(ft_t ft));
+ LONG (*write)(P3(ft_t ft, LONG *buf, LONG len));
+ int (*stopwrite)(P1(ft_t ft));
+} st_format_t;
-struct soundstream {
- struct signalinfo info; /* signal specifications */
- struct instrinfo instr; /* instrument specification */
- struct loopinfo loops[NLOOPS]; /* Looping specification */
+struct st_soundstream {
+ struct st_signalinfo info; /* signal specifications */
+ struct st_instrinfo instr; /* instrument specification */
+ struct st_loopinfo loops[ST_MAX_NLOOPS]; /* Looping specification */
char swap; /* do byte- or word-swap */
char seekable; /* can seek on this file */
char *filename; /* file name */
@@ -182,84 +182,84 @@
char *filetype; /* type of file */
char *comment; /* comment string */
FILE *fp; /* File stream pointer */
- struct fileinfo file; /* File data block */
- format_t *h; /* format struct for this file */
+ struct st_fileinfo file; /* File data block */
+ st_format_t *h; /* format struct for this file */
/* FIXME: I perfer void * or char * */
- double priv[PRIVSIZE/8]; /* format's private data area */
+ double priv[ST_MAX_PRIVSIZE/8]; /* format's private data area */
};
-/* FIXME: Does this need to be here? */
-extern format_t formats[];
+extern st_format_t st_formats[];
-/* FIXME: Prefix all #defines with ST_ */
-/* flags field */
-#define FILE_STEREO 1 /* does file format support stereo? */
-#define FILE_LOOPS 2 /* does file format support loops? */
-#define FILE_INSTR 4 /* does file format support instrument specificications? */
+/* file flags field */
+#define ST_FILE_STEREO 1 /* does file format support stereo? */
+#define ST_FILE_LOOPS 2 /* does file format support loops? */
+#define ST_FILE_INSTR 4 /* does file format support instrument specificications? */
-/* Size field */ /* SJB: note that the 1st 3 are sometimes used as sizeof(type) */
-#define BYTE 1
-#define WORD 2
-#define DWORD 4
-#define FLOAT 5
-#define DOUBLE 6
-#define IEEE 7 /* IEEE 80-bit floats. Is it necessary? */
+/* Size field */
+/* SJB: note that the 1st 3 are sometimes used as sizeof(type) */
+#define ST_SIZE_BYTE 1
+#define ST_SIZE_8BIT 1
+#define ST_SIZE_WORD 2
+#define ST_SIZE_16BIT 2
+#define ST_SIZE_DWORD 4
+#define ST_SIZE_32BIT 4
+#define ST_SIZE_FLOAT 5
+#define ST_SIZE_DOUBLE 6
+#define ST_SIZE_IEEE 7 /* IEEE 80-bit floats. */
/* Style field */
-#define UNSIGNED 1 /* unsigned linear: Sound Blaster */
-#define SIGN2 2 /* signed linear 2's comp: Mac */
-#define ULAW 3 /* U-law signed logs: US telephony, SPARC */
-#define ALAW 4 /* A-law signed logs: non-US telephony */
-#define ADPCM 5 /* Compressed PCM */
-#define IMA_ADPCM 6 /* Compressed PCM */
-#define GSM 7 /* GSM 6.10 33-byte frame lossy compression */
+#define ST_ENCODING_UNSIGNED 1 /* unsigned linear: Sound Blaster */
+#define ST_ENCODING_SIGN2 2 /* signed linear 2's comp: Mac */
+#define ST_ENCODING_ULAW 3 /* U-law signed logs: US telephony, SPARC */
+#define ST_ENCODING_ALAW 4 /* A-law signed logs: non-US telephony */
+#define ST_ENCODING_ADPCM 5 /* Compressed PCM */
+#define ST_ENCODING_IMA_ADPCM 6 /* Compressed PCM */
+#define ST_ENCODING_GSM 7 /* GSM 6.10 33-byte frame lossy compression */
-/* FIXME: This shouldn't be defined inside library. Only needed
- * by sox.c itself. Delete from raw.c and misc.c.
- */
/* declared in misc.c */
-extern const char *sizes[];
-extern const char *styles[];
+extern const char *st_sizes_str[];
+extern const char *st_encodings_str[];
-#define EFF_CHAN 1 /* Effect can mix channels up/down */
-#define EFF_RATE 2 /* Effect can alter data rate */
-#define EFF_MCHAN 4 /* Effect can handle multi-channel */
-#define EFF_REPORT 8 /* Effect does nothing */
+#define ST_EFF_CHAN 1 /* Effect can mix channels up/down */
+#define ST_EFF_RATE 2 /* Effect can alter data rate */
+#define ST_EFF_MCHAN 4 /* Effect can handle multi-channel */
+#define ST_EFF_REPORT 8 /* Effect does nothing */
/*
* Handler structure for each effect.
*/
-typedef struct effect *eff_t;
+typedef struct st_effect *eff_t;
typedef struct {
char *name; /* effect name */
int flags; /* this and that */
/* process arguments */
- void (*getopts)(P3(eff_t effp, int argc, char **argv));
+ int (*getopts)(P3(eff_t effp, int argc, char **argv));
/* start off effect */
- void (*start)(P1(eff_t effp));
+ int (*start)(P1(eff_t effp));
/* do a buffer */
- void (*flow)(P5(eff_t effp, LONG *ibuf, LONG *obuf,
+ int (*flow)(P5(eff_t effp, LONG *ibuf, LONG *obuf,
LONG *isamp, LONG *osamp));
/* drain out at end */
- void (*drain)(P3(eff_t effp, LONG *obuf, LONG *osamp));
- void (*stop)(P1(eff_t effp));/* finish up effect */
-} effect_t;
+ int (*drain)(P3(eff_t effp, LONG *obuf, LONG *osamp));
+ int (*stop)(P1(eff_t effp));/* finish up effect */
+} st_effect_t;
-struct effect {
+struct st_effect {
char *name; /* effect name */
- struct signalinfo ininfo; /* input signal specifications */
- struct loopinfo loops[8]; /* input loops specifications */
- struct instrinfo instr; /* input instrument specifications */
- struct signalinfo outinfo; /* output signal specifications */
- effect_t *h; /* effects driver */
+ struct st_signalinfo ininfo; /* input signal specifications */
+ struct st_loopinfo loops[8]; /* input loops specifications */
+ struct st_instrinfo instr; /* input instrument specifications */
+ struct st_signalinfo outinfo; /* output signal specifications */
+ st_effect_t *h; /* effects driver */
LONG *obuf; /* output buffer */
LONG odone, olen; /* consumed, total length */
- double priv[PRIVSIZE]; /* private area for effect */
+ /* FIXME: I perfer void * or char * */
+ double priv[ST_MAX_PRIVSIZE]; /* private area for effect */
};
-extern effect_t effects[]; /* declared in handlers.c */
+extern st_effect_t st_effects[]; /* declared in handlers.c */
/* declared in misc.c */
extern LONG st_clip24(P1(LONG)) REGPARM(1);
@@ -304,24 +304,24 @@
* shouldn't make use of it.
*/
/* declared in raw.c */
-void rawstartread(P1(ft_t ft));
-void rawstartwrite(P1(ft_t ft));
-void rawstopread(P1(ft_t ft));
-void rawstopwrite(P1(ft_t ft));
-LONG rawread(P3(ft_t ft, LONG *buf, LONG nsamp));
-void rawwrite(P3(ft_t ft, LONG *buf, LONG nsamp));
+int st_rawstartread(P1(ft_t ft));
+int st_rawstartwrite(P1(ft_t ft));
+int st_rawstopread(P1(ft_t ft));
+int st_rawstopwrite(P1(ft_t ft));
+LONG st_rawread(P3(ft_t ft, LONG *buf, LONG nsamp));
+LONG st_rawwrite(P3(ft_t ft, LONG *buf, LONG nsamp));
/* Utilities to byte-swap values, use libc optimized macro's if possible */
#ifdef HAVE_BYTESWAP_H
-#define swapw(x) bswap_16(x)
-#define swapl(x) bswap_32(x)
-#define swapf(x) (float)bswap_32((ULONG)(x))
+#define st_swapw(x) bswap_16(x)
+#define st_swapl(x) bswap_32(x)
+#define st_swapf(x) (float)bswap_32((ULONG)(x))
#else
-unsigned short swapw(P1(unsigned short us)); /* Swap short */
-ULONG swapl(P1(ULONG ul)); /* Swap long */
-float swapf(P1(float f)); /* Swap float */
+unsigned short st_swapw(P1(unsigned short us)); /* Swap short */
+ULONG st_swapl(P1(ULONG ul)); /* Swap long */
+float st_swapf(P1(float f)); /* Swap float */
#endif
-double swapd(P1(double d)); /* Swap double */
+double st_swapd(P1(double d)); /* Swap double */
/* util.c */
void report(P2(const char *, ...));
@@ -345,8 +345,10 @@
extern int verbose; /* be noisy on stderr */
extern char *myname;
-/* FIXME: Not externally visible currently. Its a per-effect value. */
-#define MAXRATE 50L * 1024 /* maximum sample rate */
+/* Warning, this is a MAX value used in the library. Each format and
+ * effect may have its own limitations of rate.
+ */
+#define ST_MAXRATE 50L * 1024 /* maximum sample rate in library */
/* FIXME: Move to internal st header */
#define RIGHT(datum, bits) ((datum) >> bits)
@@ -356,12 +358,15 @@
#define M_PI 3.14159265358979323846
#endif
+/* FIXME: Move to platform header file */
#define READBINARY "rb"
#define WRITEBINARY "wb"
-
#define REMOVE unlink
-const char *version(P0); /* return version number */
+#define ST_EOF (-1)
+#define ST_SUCCESS (0)
+
+const char *st_version(P0); /* return version number */
#ifdef __cplusplus
} /* end of extern "C" */
--- a/src/stat.c
+++ b/src/stat.c
@@ -248,7 +248,7 @@
if (x >= 3.0) /* use opposite style */
{
- if (effp->ininfo.style == UNSIGNED)
+ if (effp->ininfo.style == ST_ENCODING_UNSIGNED)
{
printf ("\nTry: -t raw -b -s \n");
}
@@ -264,7 +264,7 @@
}
else if (x >= 0.5 && x <= 2.0) /* use ULAW */
{
- if (effp->ininfo.style == ULAW)
+ if (effp->ininfo.style == ST_ENCODING_ULAW)
{
printf ("\nTry: -t raw -b -u \n");
}
--- a/src/sunaudio.c
+++ b/src/sunaudio.c
@@ -36,7 +36,7 @@
* size and style of samples,
* mono/stereo/quad.
*/
-void sunstartread(ft)
+int st_sunstartread(ft)
ft_t ft;
{
int samplesize, encoding;
@@ -53,16 +53,18 @@
ft->file.size = 1024;
if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
fail("unable to allocate input buffer of size %d", ft->file.size);
+ return ST_EOF;
}
if (ft->info.rate == 0.0) ft->info.rate = 8000;
- if (ft->info.size == -1) ft->info.size = BYTE;
- if (ft->info.style == -1) ft->info.style = ULAW;
+ if (ft->info.size == -1) ft->info.size = ST_SIZE_BYTE;
+ if (ft->info.style == -1) ft->info.style = ST_ENCODING_ULAW;
#ifdef __SVR4
/* Read in old values, change to what we need and then send back */
if (ioctl(fileno(ft->fp), AUDIO_GETDEV, &audio_dev) < 0) {
fail("Unable to get device information.");
+ return(ST_EOF);
}
report("Hardware detected: %s\n",audio_dev.name);
if (strcmp("SUNW,am79c30",audio_dev.name) == 0)
@@ -74,43 +76,47 @@
// If simple hardware detected in force data to ulaw.
if (simple_hw)
{
- if (ft->info.size == BYTE)
+ if (ft->info.size == ST_SIZE_BYTE)
{
- if (ft->info.style != ULAW && ft->info.style != ALAW)
+ if (ft->info.style != ST_ENCODING_ULAW &&
+ ft->info.style != ST_ENCODING_ALAW)
{
report("Warning: Detected simple hardware. Forcing output to ULAW");
- ft->info.style = ULAW;
+ ft->info.style = ST_ENCODING_ULAW;
}
}
- else if (ft->info.size == WORD)
+ else if (ft->info.size == ST_SIZE_WORD)
{
report("Warning: Detected simple hardware. Forcing output to ULAW");
- ft->info.size = BYTE;
- ft->info.style = ULAW;
+ ft->info.size = ST_SIZE_BYTE;
+ ft->info.style = ST_ENCODING_ULAW;
}
}
- if (ft->info.size == BYTE) {
+ if (ft->info.size == ST_SIZE_BYTE) {
samplesize = 8;
- if (ft->info.style != ULAW &&
- ft->info.style != ALAW &&
- ft->info.style != SIGN2) {
+ if (ft->info.style != ST_ENCODING_ULAW &&
+ ft->info.style != ST_ENCODING_ALAW &&
+ ft->info.style != ST_ENCODING_SIGN2) {
fail("Sun Audio driver only supports ULAW, ALAW, and Signed Linear for bytes.");
}
- if ((ft->info.style == ULAW || ft->info.style == ALAW) && ft->info.channels == 2)
+ if ((ft->info.style == ST_ENCODING_ULAW ||
+ ft->info.style == ST_ENCODING_ALAW) && ft->info.channels == 2)
{
report("Warning: only support mono for ULAW and ALAW data. Forcing to mono");
ft->info.channels = 2;
}
}
- else if (ft->info.size == WORD) {
+ else if (ft->info.size == ST_SIZE_WORD) {
samplesize = 16;
- if (ft->info.style != SIGN2) {
+ if (ft->info.style != ST_ENCODING_SIGN2) {
fail("Sun Audio driver only supports Signed Linear for words.");
+ return(ST_EOF);
}
}
else {
fail("Sun Audio driver only supports bytes and words");
+ return(ST_EOF);
}
if (ft->info.channels == -1) ft->info.channels = 1;
@@ -126,13 +132,14 @@
/* Read in old values, change to what we need and then send back */
if (ioctl(fileno(ft->fp), AUDIO_GETINFO, &audio_if) < 0) {
fail("Unable to initialize /dev/audio");
+ return(ST_EOF);
}
audio_if.record.precision = samplesize;
audio_if.record.channels = ft->info.channels;
audio_if.record.sample_rate = ft->info.rate;
- if (ft->info.style == ULAW)
+ if (ft->info.style == ST_ENCODING_ULAW)
encoding = AUDIO_ENCODING_ULAW;
- else if (ft->info.style == ALAW)
+ else if (ft->info.style == ST_ENCODING_ALAW)
encoding = AUDIO_ENCODING_ALAW;
else
encoding = AUDIO_ENCODING_LINEAR;
@@ -141,22 +148,28 @@
ioctl(fileno(ft->fp), AUDIO_SETINFO, &audio_if);
if (audio_if.record.precision != samplesize) {
fail("Unable to initialize sample size for /dev/audio");
+ return(ST_EOF);
}
if (audio_if.record.channels != ft->info.channels) {
fail("Unable to initialize number of channels for /dev/audio");
+ return(ST_EOF);
}
if (audio_if.record.sample_rate != ft->info.rate) {
fail("Unable to initialize rate for /dev/audio");
+ return(ST_EOF);
}
if (audio_if.record.encoding != encoding) {
fail("Unable to initialize style for /dev/audio");
+ return(ST_EOF);
}
/* Change to non-buffered I/O*/
setvbuf(ft->fp, NULL, _IONBF, sizeof(char) * ft->file.size);
sigintreg(ft); /* Prepare to catch SIGINT */
+
+ return (ST_SUCCESS);
}
-void sunstartwrite(ft)
+int st_sunstartwrite(ft)
ft_t ft;
{
int samplesize, encoding;
@@ -173,6 +186,7 @@
ft->file.size = 1024;
if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
fail("unable to allocate output buffer of size %d", ft->file.size);
+ return(ST_EOF);
}
#ifdef __SVR4
@@ -179,6 +193,7 @@
/* Read in old values, change to what we need and then send back */
if (ioctl(fileno(ft->fp), AUDIO_GETDEV, &audio_dev) < 0) {
fail("Unable to get device information.");
+ return(ST_EOF);
}
report("Hardware detected: %s\n",audio_dev.name);
if (strcmp("SUNW,am79c30",audio_dev.name) == 0)
@@ -189,36 +204,38 @@
if (simple_hw)
{
- if (ft->info.size == BYTE)
+ if (ft->info.size == ST_SIZE_BYTE)
{
- if (ft->info.style != ULAW && ft->info.style != ALAW)
+ if (ft->info.style != ST_ENCODING_ULAW &&
+ ft->info.style != ST_ENCODING_ALAW)
{
report("Warning: Detected simple hardware. Forcing output to ULAW");
- ft->info.style = ULAW;
+ ft->info.style = ST_ENCODING_ULAW;
}
}
- else if (ft->info.size == WORD)
+ else if (ft->info.size == ST_SIZE_WORD)
{
report("Warning: Detected simple hardware. Forcing output to ULAW");
- ft->info.size = BYTE;
- ft->info.style = ULAW;
+ ft->info.size = ST_SIZE_BYTE;
+ ft->info.style = ST_ENCODING_ULAW;
}
}
if (ft->info.rate == 0.0) ft->info.rate = 8000;
- if (ft->info.size == -1) ft->info.size = BYTE;
- if (ft->info.style == -1) ft->info.style = ULAW;
+ if (ft->info.size == -1) ft->info.size = ST_SIZE_BYTE;
+ if (ft->info.style == -1) ft->info.style = ST_ENCODING_ULAW;
- if (ft->info.size == BYTE) {
+ if (ft->info.size == ST_SIZE_BYTE) {
samplesize = 8;
- if (ft->info.style != ULAW &&
- ft->info.style != ALAW &&
- ft->info.style != SIGN2) {
+ if (ft->info.style != ST_ENCODING_ULAW &&
+ ft->info.style != ST_ENCODING_ALAW &&
+ ft->info.style != ST_ENCODING_SIGN2) {
report("Sun Audio driver only supports ULAW, ALAW, and Signed Linear for bytes.");
report("Forcing to ULAW");
- ft->info.style = ULAW;
+ ft->info.style = ST_ENCODING_ULAW;
}
- if ((ft->info.style == ULAW || ft->info.style == ALAW) && ft->info.channels == 2)
+ if ((ft->info.style == ST_ENCODING_ULAW ||
+ ft->info.style == ST_ENCODING_ALAW) && ft->info.channels == 2)
{
report("Warning: only support mono for ULAW and ALAW data. Forcing to mono");
ft->info.channels = 2;
@@ -225,17 +242,17 @@
}
}
- else if (ft->info.size == WORD) {
+ else if (ft->info.size == ST_SIZE_WORD) {
samplesize = 16;
- if (ft->info.style != SIGN2) {
+ if (ft->info.style != ST_ENCODING_SIGN2) {
report("Sun Audio driver only supports Signed Linear for words.");
report("Forcing to Signed Linear");
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
}
}
else {
report("Sun Audio driver only supports bytes and words");
- ft->info.size = WORD;
+ ft->info.size = ST_SIZE_WORD;
samplesize = 16;
}
@@ -245,13 +262,14 @@
/* Read in old values, change to what we need and then send back */
if (ioctl(fileno(ft->fp), AUDIO_GETINFO, &audio_if) < 0) {
fail("Unable to initialize /dev/audio");
+ return(ST_EOF);
}
audio_if.play.precision = samplesize;
audio_if.play.channels = ft->info.channels;
audio_if.play.sample_rate = ft->info.rate;
- if (ft->info.style == ULAW)
+ if (ft->info.style == ST_ENCODING_ULAW)
encoding = AUDIO_ENCODING_ULAW;
- else if (ft->info.style == ALAW)
+ else if (ft->info.style == ST_ENCODING_ALAW)
encoding = AUDIO_ENCODING_ALAW;
else
encoding = AUDIO_ENCODING_LINEAR;
@@ -260,18 +278,24 @@
ioctl(fileno(ft->fp), AUDIO_SETINFO, &audio_if);
if (audio_if.play.precision != samplesize) {
fail("Unable to initialize sample size for /dev/audio");
+ return(ST_EOF);
}
if (audio_if.play.channels != ft->info.channels) {
fail("Unable to initialize number of channels for /dev/audio");
+ return(ST_EOF);
}
if (audio_if.play.sample_rate != ft->info.rate) {
fail("Unable to initialize rate for /dev/audio");
+ return(ST_EOF);
}
if (audio_if.play.encoding != encoding) {
fail("Unable to initialize style for /dev/audio");
+ return(ST_EOF);
}
/* Change to non-buffered I/O */
setvbuf(ft->fp, NULL, _IONBF, sizeof(char) * ft->file.size);
+
+ return (ST_SUCCESS);
}
#endif
--- a/src/testall.sh
+++ b/src/testall.sh
@@ -25,5 +25,5 @@
t sndt
t txw
t voc
-t wav
-t wve
+t wav
+t wve
--- a/src/tx16w.c
+++ b/src/tx16w.c
@@ -74,7 +74,7 @@
* size and style of samples,
* mono/stereo/quad.
*/
-void txwstartread(ft)
+int st_txwstartread(ft)
ft_t ft;
{
int c;
@@ -89,7 +89,10 @@
txw_t sk = (txw_t) ft->priv;
/* If you need to seek around the input file. */
if (! ft->seekable)
+ {
fail("txw input file must be a file, not a pipe");
+ return(ST_EOF);
+ }
/* This is dumb but portable, just count the bytes til EOF */
while ( getc(ft->fp) != EOF )
@@ -123,7 +126,10 @@
/* Check to make sure we got a good filetype ID from file */
report("Found header filetype %s",filetype);
if(strcmp(filetype,"LM8953"))
+ {
fail("Invalid filetype ID in input file header, != LM8953");
+ return(ST_EOF);
+ }
/*
* Set up the sample rate as indicated by the header
*/
@@ -168,8 +174,10 @@
report("Sample rate = %ld",ft->info.rate);
ft->info.channels = 1 ; /* not sure about stereo sample data yet ??? */
- ft->info.size = WORD; /* this is close enough */
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_WORD; /* this is close enough */
+ ft->info.style = ST_ENCODING_SIGN2;
+
+ return(ST_SUCCESS);
}
/*
@@ -179,7 +187,7 @@
* Return number of samples read.
*/
-LONG txwread(ft, buf, len)
+LONG st_txwread(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
@@ -235,12 +243,13 @@
* Do anything required when you stop reading samples.
* Don't close input file!
*/
-void txwstopread(ft)
+int st_txwstopread(ft)
ft_t ft;
{
+ return(ST_SUCCESS);
}
-void txwstartwrite(ft)
+int st_txwstartwrite(ft)
ft_t ft;
{
struct WaveHeader_ WH;
@@ -250,14 +259,17 @@
if (ft->info.channels != 1)
report("tx16w is overriding output format to 1 channel.");
ft->info.channels = 1 ; /* not sure about stereo sample data yet ??? */
- if (ft->info.size != WORD || ft->info.style != SIGN2)
+ if (ft->info.size != ST_SIZE_WORD || ft->info.style != ST_ENCODING_SIGN2)
report("tx16w is overriding output format to size Signed Word format.");
- ft->info.size = WORD; /* this is close enough */
- ft->info.style = SIGN2;
+ ft->info.size = ST_SIZE_WORD; /* this is close enough */
+ ft->info.style = ST_ENCODING_SIGN2;
/* If you have to seek around the output file */
if (! ft->seekable)
+ {
fail("Output .txw file must be a file, not a pipe");
+ return(ST_EOF);
+ }
/* dummy numbers, just for place holder, real header is written
at end of processing, since byte count is needed */
@@ -264,9 +276,10 @@
fwrite(&WH,1,32,ft->fp);
writedone = 32;
+ return(ST_SUCCESS);
}
-void txwwrite(ft, buf, len)
+LONG st_txwwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
@@ -274,7 +287,7 @@
unsigned int w1,w2;
tx16w_len += len;
- if (tx16w_len > TXMAXLEN) return;
+ if (tx16w_len > TXMAXLEN) return 0;
for (i=0;i<len;i+=2) {
w1 = *buf++ >> 20;
@@ -288,9 +301,10 @@
putc((w2 >> 4) & 0xFF,ft->fp);
writedone += 3;
}
+ return(len);
}
-void txwstopwrite(ft)
+int st_txwstopwrite(ft)
ft_t ft;
{
struct WaveHeader_ WH;
@@ -300,14 +314,6 @@
/* If file header needs fixing up, for example it needs the */
/* the number of samples in a field, seek back and write them here. */
- /* If your format specifies any of the following info. */
- /*
- ft->info.rate =
- ft->info.size = BYTE or WORD ...;
- ft->info.style = UNSIGNED or SIGN2 ...;
- ft->info.channels = 1 or 2 or 4;
- */
-
report("tx16w:output finished");
strncpy(WH.filetype,"LM8953",6);
@@ -371,4 +377,6 @@
rewind(ft->fp);
fwrite(&WH,1,32,ft->fp);
+
+ return(ST_SUCCESS);
}
--- a/src/util.c
+++ b/src/util.c
@@ -102,8 +102,8 @@
if (! formp->filetype)
fail("Must give file type for %s file, either as suffix or with -t option",
formp->filename);
- for(i = 0; formats[i].names; i++) {
- for(list = formats[i].names; *list; list++) {
+ for(i = 0; st_formats[i].names; i++) {
+ for(list = st_formats[i].names; *list; list++) {
char *s1 = *list, *s2 = formp->filetype;
if (! strcmpcase(s1, s2))
break; /* not a match */
@@ -111,7 +111,7 @@
if (! *list)
continue;
/* Found it! */
- formp->h = &formats[i];
+ formp->h = &st_formats[i];
return;
}
if (! strcmpcase(formp->filetype, "snd")) {
@@ -138,20 +138,20 @@
{
int i;
- for(i = 0; effects[i].name; i++) {
- char *s1 = effects[i].name, *s2 = effp->name;
+ for(i = 0; st_effects[i].name; i++) {
+ char *s1 = st_effects[i].name, *s2 = effp->name;
while(*s1 && *s2 && (tolower(*s1) == tolower(*s2)))
s1++, s2++;
if (*s1 || *s2)
continue; /* not a match */
/* Found it! */
- effp->h = &effects[i];
+ effp->h = &st_effects[i];
return;
}
/* Guido Van Rossum fix */
fprintf(stderr, "%s: Known effects: ",myname);
- for (i = 1; effects[i].name; i++)
- fprintf(stderr, "%s ", effects[i].name);
+ for (i = 1; st_effects[i].name; i++)
+ fprintf(stderr, "%s ", st_effects[i].name);
fprintf(stderr, "\n");
fail("Effect '%s' is not known!", effp->name);
}
@@ -191,7 +191,7 @@
* it's in samples, so # channels don't matter
*/
factor = (double) ft2->info.rate / (double) ft->info.rate;
- for(i = 0; i < NLOOPS; i++) {
+ for(i = 0; i < ST_MAX_NLOOPS; i++) {
ft2->loops[i].start = ft->loops[i].start * factor;
ft2->loops[i].length = ft->loops[i].length * factor;
ft2->loops[i].count = ft->loops[i].count;
@@ -217,7 +217,7 @@
ft->info.rate, ft->filename);
if (ft->info.size == -1)
fail("Data size was not given for %s file\nUse one of -b/-w/-l/-f/-d/-D", ft->filename);
- if (ft->info.style == -1 && ft->info.size != FLOAT)
+ if (ft->info.style == -1 && ft->info.size != ST_SIZE_FLOAT)
fail("Data style was not given for %s file\nUse one of -s/-u/-U/-A", ft->filename);
/* it's so common, might as well default */
if (ft->info.channels == -1)
--- a/src/voc.c
+++ b/src/voc.c
@@ -167,11 +167,11 @@
#define min(a, b) (((a) < (b)) ? (a) : (b))
-static void getblock(P1(ft_t));
+static int getblock(P1(ft_t));
static void blockstart(P1(ft_t));
static void blockstop(P1(ft_t));
-void vocstartread(ft)
+int st_vocstartread(ft)
ft_t ft;
{
char header[20];
@@ -179,6 +179,7 @@
int sbseek;
int littlendian = 1;
char *endptr;
+ int rc;
endptr = (char *) &littlendian;
/* VOC is in Little Endian format. Swap bytes read in on */
@@ -189,11 +190,20 @@
}
if (! ft->seekable)
+ {
fail("VOC input file must be a file, not a pipe");
+ return(ST_EOF);
+ }
if (fread(header, 1, 20, ft->fp) != 20)
+ {
fail("unexpected EOF in VOC header");
+ return(ST_EOF);
+ }
if (strncmp(header, "Creative Voice File\032", 19))
+ {
fail("VOC file header incorrect");
+ return(ST_EOF);
+ }
sbseek = rshort(ft);
fseek(ft->fp, sbseek, 0);
@@ -201,27 +211,40 @@
v->rate = -1;
v->rest = 0;
v->extended = 0;
- getblock(ft);
+ rc = getblock(ft);
+ if (rc)
+ return rc;
if (v->rate == -1)
+ {
fail("Input .voc file had no sound!");
+ return(ST_EOF);
+ }
ft->info.size = v->size;
- ft->info.style = UNSIGNED;
- if (v->size == WORD)
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_UNSIGNED;
+ if (v->size == ST_SIZE_WORD)
+ ft->info.style = ST_ENCODING_SIGN2;
if (ft->info.channels == -1)
ft->info.channels = v->channels;
+
+ return(ST_SUCCESS);
}
-LONG vocread(ft, buf, len)
+LONG st_vocread(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
vs_t v = (vs_t) ft->priv;
int done = 0;
+ int rc;
if (v->rest == 0)
- getblock(ft);
+ {
+ rc = getblock(ft);
+ if (rc)
+ return 0;
+ }
+
if (v->rest == 0)
return 0;
@@ -234,7 +257,7 @@
LONG datum;
switch(v->size)
{
- case BYTE:
+ case ST_SIZE_BYTE:
if ((datum = getc(ft->fp)) == EOF) {
warn("VOC input: short file");
v->rest = 0;
@@ -243,7 +266,7 @@
datum ^= 0x80; /* convert to signed */
*buf++ = LEFT(datum, 24);
break;
- case WORD:
+ case ST_SIZE_WORD:
datum = rshort(ft);
if (feof(ft->fp))
{
@@ -261,9 +284,10 @@
}
/* nothing to do */
-void vocstopread(ft)
+int st_vocstopread(ft)
ft_t ft;
{
+ return(ST_SUCCESS);
}
/* When saving samples in VOC format the following outline is followed:
@@ -277,7 +301,7 @@
* which will work with the oldest software (eg. an 8-bit mono sample
* will be able to be played with a really old SB VOC player.)
*/
-void vocstartwrite(ft)
+int st_vocstartwrite(ft)
ft_t ft;
{
vs_t v = (vs_t) ft->priv;
@@ -293,7 +317,10 @@
}
if (! ft->seekable)
+ {
fail("Output .voc file must be a file, not a pipe");
+ return(ST_EOF);
+ }
v->samples = 0;
@@ -303,15 +330,17 @@
wshort(ft, 0x10a); /* major/minor version number */
wshort(ft, 0x1129); /* checksum of version number */
- if (ft->info.size == BYTE)
- ft->info.style = UNSIGNED;
+ if (ft->info.size == ST_SIZE_BYTE)
+ ft->info.style = ST_ENCODING_UNSIGNED;
else
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
if (ft->info.channels == -1)
ft->info.channels = 1;
+
+ return(ST_SUCCESS);
}
-void vocwrite(ft, buf, len)
+LONG st_vocwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
@@ -318,6 +347,7 @@
vs_t v = (vs_t) ft->priv;
unsigned char uc;
int sw;
+ LONG done = 0;
if (v->samples == 0) {
/* No silence packing yet. */
@@ -325,8 +355,8 @@
blockstart(ft);
}
v->samples += len;
- while(len--) {
- if (ft->info.size == BYTE) {
+ while(done < len) {
+ if (ft->info.size == ST_SIZE_BYTE) {
uc = RIGHT(*buf++, 24);
uc ^= 0x80;
putc(uc, ft->fp);
@@ -334,19 +364,22 @@
sw = (int) RIGHT(*buf++, 16);
wshort(ft,sw);
}
+ done++;
}
+ return done;
}
-void vocstopwrite(ft)
+int st_vocstopwrite(ft)
ft_t ft;
{
blockstop(ft);
+ return(ST_SUCCESS);
}
/* Voc-file handlers */
/* Read next block header, save info, leave position at start of data */
-static void
+static int
getblock(ft)
ft_t ft;
{
@@ -359,12 +392,12 @@
v->silent = 0;
while (v->rest == 0) {
if (feof(ft->fp))
- return;
+ return ST_SUCCESS;
block = getc(ft->fp);
if (block == VOC_TERM)
- return;
+ return ST_SUCCESS;
if (feof(ft->fp))
- return;
+ return ST_SUCCESS;
/*
* Size is an 24-bit value. Currently there is no util
* func to read this so do it this cross-platform way
@@ -383,10 +416,16 @@
/* block, the DATA blocks rate value is invalid */
if (!v->extended) {
if (uc == 0)
+ {
fail("File %s: Sample rate is zero?");
+ return(ST_EOF);
+ }
if ((v->rate != -1) && (uc != v->rate))
+ {
fail("File %s: sample rate codes differ: %d != %d",
ft->filename,v->rate, uc);
+ return(ST_EOF);
+ }
v->rate = uc;
ft->info.rate = 1000000.0/(256 - v->rate);
v->channels = 1;
@@ -393,27 +432,38 @@
}
uc = getc(ft->fp);
if (uc != 0)
+ {
fail("File %s: only interpret 8-bit data!",
ft->filename);
+ return(ST_EOF);
+ }
v->extended = 0;
v->rest = sblen - 2;
- v->size = BYTE;
- return;
+ v->size = ST_SIZE_BYTE;
+ return (ST_SUCCESS);
case VOC_DATA_16:
new_rate = rlong(ft);
if (new_rate == 0)
+ {
fail("File %s: Sample rate is zero?",ft->filename);
+ return(ST_EOF);
+ }
if ((v->rate != -1) && (new_rate != v->rate))
+ {
fail("File %s: sample rate codes differ: %d != %d",
ft->filename, v->rate, new_rate);
+ return(ST_EOF);
+ }
v->rate = new_rate;
ft->info.rate = new_rate;
uc = getc(ft->fp);
switch (uc)
{
- case 8: v->size = BYTE; break;
- case 16: v->size = WORD; break;
- default: fail("Don't understand size %d", uc);
+ case 8: v->size = ST_SIZE_BYTE; break;
+ case 16: v->size = ST_SIZE_WORD; break;
+ default:
+ fail("Don't understand size %d", uc);
+ return(ST_EOF);
}
v->channels = getc(ft->fp);
getc(ft->fp); /* unknown */
@@ -423,10 +473,10 @@
getc(ft->fp); /* notused */
getc(ft->fp); /* notused */
v->rest = sblen - 12;
- return;
+ return (ST_SUCCESS);
case VOC_CONT:
v->rest = sblen;
- return;
+ return (ST_SUCCESS);
case VOC_SILENCE:
{
unsigned short period;
@@ -434,7 +484,10 @@
period = rshort(ft);
uc = getc(ft->fp);
if (uc == 0)
+ {
fail("File %s: Silence sample rate is zero");
+ return(ST_EOF);
+ }
/*
* Some silence-packed files have gratuitously
* different sample rate codes in silence.
@@ -446,7 +499,7 @@
v->rate = uc;
v->rest = period;
v->silent = 1;
- return;
+ return (ST_SUCCESS);
}
case VOC_MARKER:
uc = getc(ft->fp);
@@ -474,15 +527,24 @@
v->extended = 1;
new_rate = rshort(ft);
if (new_rate == 0)
+ {
fail("File %s: Sample rate is zero?");
+ return(ST_EOF);
+ }
if ((v->rate != -1) && (new_rate != v->rate))
+ {
fail("File %s: sample rate codes differ: %d != %d",
ft->filename, v->rate, new_rate);
+ return(ST_EOF);
+ }
v->rate = new_rate;
uc = getc(ft->fp);
if (uc != 0)
+ {
fail("File %s: only interpret 8-bit data!",
ft->filename);
+ return(ST_EOF);
+ }
uc = getc(ft->fp);
if (uc)
ft->info.channels = 2; /* Stereo */
@@ -500,6 +562,7 @@
getc(ft->fp);
}
}
+ return ST_SUCCESS;
}
/* Start an output block. */
@@ -515,7 +578,7 @@
putc(0, ft->fp); /* Period length */
putc((int) v->rate, ft->fp); /* Rate code */
} else {
- if (ft->info.size == BYTE) {
+ if (ft->info.size == ST_SIZE_BYTE) {
/* 8-bit sample section. By always setting the correct */
/* rate value in the DATA block (even when its preceeded */
/* by an EXTENDED block) old software can still play stereo */
@@ -571,7 +634,7 @@
if (v->silent) {
wshort(ft, v->samples);
} else {
- if (ft->info.size == BYTE) {
+ if (ft->info.size == ST_SIZE_BYTE) {
if (ft->info.channels > 1) {
fseek(ft->fp, 8, 1); /* forward 7 + 1 for new block header */
}
--- a/src/wav.c
+++ b/src/wav.c
@@ -114,7 +114,7 @@
static char *wav_format_str();
-static void wavwritehdr(P2(ft_t, int));
+static int wavwritehdr(P2(ft_t, int));
/****************************************************************************/
@@ -203,7 +203,7 @@
/* Common ADPCM Write Function */
/****************************************************************************/
-static void xxxAdpcmWriteBlock(ft)
+static int xxxAdpcmWriteBlock(ft)
ft_t ft;
{
wav_t wav = (wav_t) ft->priv;
@@ -224,7 +224,10 @@
}
/* write the compressed packet */
if (fwrite(wav->packet, wav->blockAlign, 1, ft->fp) != 1)
+ {
fail("write error");
+ return (ST_EOF);
+ }
/* update lengths and samplePtr */
wav->dataLength += wav->blockAlign;
#ifndef PAD_NSAMPS
@@ -234,6 +237,7 @@
#endif
wav->samplePtr = wav->samples;
}
+ return (ST_SUCCESS);
}
/****************************************************************************/
@@ -241,7 +245,7 @@
/****************************************************************************/
#ifdef HAVE_LIBGSM
/* create the gsm object, malloc buffer for 160*2 samples */
-void wavgsminit(ft)
+int wavgsminit(ft)
ft_t ft;
{
int valueP=1;
@@ -249,17 +253,23 @@
wav->gsmbytecount=0;
wav->gsmhandle=gsm_create();
if (!wav->gsmhandle)
+ {
fail("cannot create GSM object");
+ return (ST_EOF);
+ }
if(gsm_option(wav->gsmhandle,GSM_OPT_WAV49,&valueP) == -1){
fail("error setting gsm_option for WAV49 format. Recompile gsm library with -DWAV49 option and relink sox");
+ return (ST_EOF);
}
wav->gsmsample=malloc(sizeof(gsm_signal)*160*2);
if (wav->gsmsample == NULL){
fail("error allocating memory for gsm buffer");
+ return (ST_EOF);
}
wav->gsmindex=0;
+ return (ST_SUCCESS);
}
/*destroy the gsm object and free the buffer */
@@ -296,10 +306,16 @@
}
/* decode the long 33 byte half */
if(gsm_decode(wav->gsmhandle,frame, wav->gsmsample)<0)
+ {
fail("error during gsm decode");
+ return 0;
+ }
/* decode the short 32 byte half */
if(gsm_decode(wav->gsmhandle,frame+33, wav->gsmsample+160)<0)
+ {
fail("error during gsm decode");
+ return 0;
+ }
while ((wav->gsmindex <160*2) && (done < len)){
buf[done++]=LEFT(wav->gsmsample[(wav->gsmindex)++],16);
@@ -309,7 +325,7 @@
return done;
}
-static void wavgsmflush(ft, pad)
+static int wavgsmflush(ft, pad)
ft_t ft;
int pad; /* normally 0, but 1 to pad last write to even datalen */
{
@@ -325,7 +341,10 @@
/*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)
+ {
fail("write error");
+ return (ST_EOF);
+ }
wav->gsmbytecount += 65;
wav->gsmindex = 0;
@@ -333,17 +352,22 @@
if (pad & wav->gsmbytecount){
/* pad output to an even number of bytes */
if(fputc(0,ft->fp))
+ {
fail("write error");
+ return (ST_EOF);
+ }
wav->gsmbytecount += 1;
}
+ return (ST_SUCCESS);
}
-void wavgsmwrite(ft, buf, len)
+LONG wavgsmwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
wav_t wav = (wav_t) ft->priv;
int done = 0;
+ int rc;
while (done < len) {
while ((wav->gsmindex < 160*2) && (done < len))
@@ -352,8 +376,11 @@
if (wav->gsmindex < 160*2)
break;
- wavgsmflush(ft, 0);
+ rc = wavgsmflush(ft, 0);
+ if (rc)
+ return 0;
}
+ return done;
}
@@ -372,8 +399,9 @@
/* General Sox WAV file code */
/****************************************************************************/
+/* FIXME: Use common misc.c skip code */
static void fSkip(FILE *fp, ULONG len)
-{ /* FIXME: this should also check ferror(fp) */
+{
while (len > 0 && !feof(fp))
{
getc(fp);
@@ -388,7 +416,10 @@
for (;;)
{
if (fread(magic, 1, 4, ft->fp) != 4)
+ {
fail("WAVE file has missing %s chunk", Label);
+ return 0;
+ }
len = rlong(ft);
if (strncmp(Label, magic, 4) == 0)
break; /* Found the data chunk */
@@ -405,7 +436,7 @@
* size and style of samples,
* mono/stereo/quad.
*/
-void wavstartread(ft)
+int st_wavstartread(ft)
ft_t ft;
{
wav_t wav = (wav_t) ft->priv;
@@ -413,6 +444,7 @@
ULONG len;
int littlendian = 1;
char *endptr;
+ int rc;
/* wave file characteristics */
ULONG wRiffLength;
@@ -427,27 +459,27 @@
ULONG bytesPerBlock = 0;
ULONG bytespersample; /* bytes per sample (per channel */
- if (sizeof(struct wavstuff)> PRIVSIZE)
- fail("struct wav_t too big (%d); increase PRIVSIZE in st.h and recompile sox",sizeof(struct wavstuff));
/* This is needed for rawread(), rshort, etc */
- rawstartread(ft);
+ rc = st_rawstartread(ft);
+ if (rc)
+ return rc;
endptr = (char *) &littlendian;
if (!*endptr) ft->swap = ft->swap ? 0 : 1;
-#if 0
- /* If you need to seek around the input file. */
- if (! ft->seekable)
- fail("WAVE input file must be a file, not a pipe");
-#endif
-
if ( fread(magic, 1, 4, ft->fp) != 4 || strncmp("RIFF", magic, 4))
+ {
fail("WAVE: RIFF header not found");
+ return ST_EOF;
+ }
wRiffLength = rlong(ft);
if ( fread(magic, 1, 4, ft->fp) != 4 || strncmp("WAVE", magic, 4))
+ {
fail("WAVE header not found");
+ return ST_EOF;
+ }
/* Now look for the format chunk */
wFmtSize = len = findChunk(ft, "fmt ");
@@ -454,7 +486,10 @@
/* findChunk() only returns if chunk was found */
if (wFmtSize < 16)
+ {
fail("WAVE file fmt chunk is too short");
+ return ST_EOF;
+ }
wav->formatTag = rshort(ft);
wChannels = rshort(ft);
@@ -468,24 +503,25 @@
{
case WAVE_FORMAT_UNKNOWN:
fail("WAVE file is in unsupported Microsoft Official Unknown format.");
+ return ST_EOF;
case WAVE_FORMAT_PCM:
/* Default (-1) depends on sample size. Set that later on. */
- if (ft->info.style != -1 && ft->info.style != UNSIGNED &&
- ft->info.style != SIGN2)
+ if (ft->info.style != -1 && ft->info.style != ST_ENCODING_UNSIGNED &&
+ ft->info.style != ST_ENCODING_SIGN2)
warn("User options overriding style read in .wav header");
break;
case WAVE_FORMAT_IMA_ADPCM:
- if (ft->info.style == -1 || ft->info.style == IMA_ADPCM)
- ft->info.style = IMA_ADPCM;
+ if (ft->info.style == -1 || ft->info.style == ST_ENCODING_IMA_ADPCM)
+ ft->info.style = ST_ENCODING_IMA_ADPCM;
else
warn("User options overriding style read in .wav header");
break;
case WAVE_FORMAT_ADPCM:
- if (ft->info.style == -1 || ft->info.style == ADPCM)
- ft->info.style = ADPCM;
+ if (ft->info.style == -1 || ft->info.style == ST_ENCODING_ADPCM)
+ ft->info.style = ST_ENCODING_ADPCM;
else
warn("User options overriding style read in .wav header");
break;
@@ -492,17 +528,18 @@
case WAVE_FORMAT_IEEE_FLOAT:
fail("Sorry, this WAV file is in IEEE Float format.");
+ return ST_EOF;
case WAVE_FORMAT_ALAW:
- if (ft->info.style == -1 || ft->info.style == ALAW)
- ft->info.style = ALAW;
+ if (ft->info.style == -1 || ft->info.style == ST_ENCODING_ALAW)
+ ft->info.style = ST_ENCODING_ALAW;
else
warn("User options overriding style read in .wav header");
break;
case WAVE_FORMAT_MULAW:
- if (ft->info.style == -1 || ft->info.style == ULAW)
- ft->info.style = ULAW;
+ if (ft->info.style == -1 || ft->info.style == ST_ENCODING_ULAW)
+ ft->info.style = ST_ENCODING_ULAW;
else
warn("User options overriding style read in .wav header");
break;
@@ -509,39 +546,53 @@
case WAVE_FORMAT_OKI_ADPCM:
fail("Sorry, this WAV file is in OKI ADPCM format.");
+ return ST_EOF;
case WAVE_FORMAT_DIGISTD:
fail("Sorry, this WAV file is in Digistd format.");
+ return ST_EOF;
case WAVE_FORMAT_DIGIFIX:
fail("Sorry, this WAV file is in Digifix format.");
+ return ST_EOF;
case WAVE_FORMAT_DOLBY_AC2:
fail("Sorry, this WAV file is in Dolby AC2 format.");
+ return ST_EOF;
case WAVE_FORMAT_GSM610:
#ifdef HAVE_LIBGSM
- if (ft->info.style == -1 || ft->info.style == GSM )
- ft->info.style = GSM;
+ if (ft->info.style == -1 || ft->info.style == ST_ENCODING_GSM )
+ ft->info.style = ST_ENCODING_GSM;
else
warn("User options overriding style read in .wav header");
break;
#else
fail("Sorry, this WAV file is in GSM6.10 format and no GSM support present, recompile sox with gsm library");
+ return ST_EOF;
#endif
case WAVE_FORMAT_ROCKWELL_ADPCM:
fail("Sorry, this WAV file is in Rockwell ADPCM format.");
+ return ST_EOF;
case WAVE_FORMAT_ROCKWELL_DIGITALK:
fail("Sorry, this WAV file is in Rockwell DIGITALK format.");
+ return ST_EOF;
case WAVE_FORMAT_G721_ADPCM:
fail("Sorry, this WAV file is in G.721 ADPCM format.");
+ return ST_EOF;
case WAVE_FORMAT_G728_CELP:
fail("Sorry, this WAV file is in G.728 CELP format.");
+ return ST_EOF;
case WAVE_FORMAT_MPEG:
fail("Sorry, this WAV file is in MPEG format.");
+ return ST_EOF;
case WAVE_FORMAT_MPEGLAYER3:
fail("Sorry, this WAV file is in MPEG Layer 3 format.");
+ return ST_EOF;
case WAVE_FORMAT_G726_ADPCM:
fail("Sorry, this WAV file is in G.726 ADPCM format.");
+ return ST_EOF;
case WAVE_FORMAT_G722_ADPCM:
fail("Sorry, this WAV file is in G.722 ADPCM format.");
+ return ST_EOF;
default: fail("WAV file has unknown format type of %x",wav->formatTag);
+ return ST_EOF;
}
/* User options take precedence */
@@ -571,7 +622,10 @@
}
if (wExtSize > len)
+ {
fail("wave header error: wExtSize inconsistent with wFmtLen");
+ return ST_EOF;
+ }
switch (wav->formatTag)
{
@@ -578,33 +632,62 @@
/* ULONG max_spb; */
case WAVE_FORMAT_ADPCM:
if (wExtSize < 4)
+ {
fail("format[%s]: expects wExtSize >= %d",
wav_format_str(wav->formatTag), 4);
+ return ST_EOF;
+ }
if (wBitsPerSample != 4)
+ {
fail("Can only handle 4-bit MS ADPCM in wav files");
+ return ST_EOF;
+ }
wav->samplesPerBlock = rshort(ft);
bytesPerBlock = AdpcmBytesPerBlock(ft->info.channels, wav->samplesPerBlock);
if (bytesPerBlock > wav->blockAlign)
+ {
fail("format[%s]: samplesPerBlock(%d) incompatible with blockAlign(%d)",
wav_format_str(wav->formatTag), wav->samplesPerBlock, wav->blockAlign);
+ return ST_EOF;
+ }
wav->nCoefs = rshort(ft);
if (wav->nCoefs < 7 || wav->nCoefs > 0x100) {
fail("ADPCM file nCoefs (%.4hx) makes no sense\n", wav->nCoefs);
+ return ST_EOF;
}
wav->packet = (unsigned char *)malloc(wav->blockAlign);
+ if (!wav->packet)
+ {
+ fail("Unable to alloc resources");
+ return ST_EOF;
+ }
+
len -= 4;
if (wExtSize < 4 + 4*wav->nCoefs)
+ {
fail("wave header error: wExtSize(%d) too small for nCoefs(%d)", wExtSize, wav->nCoefs);
+ return ST_EOF;
+ }
wav->samples = (short *)malloc(wChannels*wav->samplesPerBlock*sizeof(short));
+ if (!wav->samples)
+ {
+ fail("Unable to alloc resources");
+ return ST_EOF;
+ }
/* nCoefs, iCoefs used by adpcm.c */
wav->iCoefs = (short *)malloc(wav->nCoefs * 2 * sizeof(short));
+ if (!wav->iCoefs)
{
+ fail("Unable to alloc resources");
+ return ST_EOF;
+ }
+ {
int i, errct=0;
for (i=0; len>=2 && i < 2*wav->nCoefs; i++) {
wav->iCoefs[i] = rshort(ft);
@@ -615,29 +698,48 @@
if (errct) warn("base iCoefs differ in %d/14 positions",errct);
}
- bytespersample = WORD; /* AFTER de-compression */
+ bytespersample = ST_SIZE_WORD; /* AFTER de-compression */
break;
case WAVE_FORMAT_IMA_ADPCM:
if (wExtSize < 2)
+ {
fail("format[%s]: expects wExtSize >= %d",
wav_format_str(wav->formatTag), 2);
+ return ST_EOF;
+ }
if (wBitsPerSample != 4)
+ {
fail("Can only handle 4-bit IMA ADPCM in wav files");
+ return ST_EOF;
+ }
wav->samplesPerBlock = rshort(ft);
bytesPerBlock = ImaBytesPerBlock(ft->info.channels, wav->samplesPerBlock);
if (bytesPerBlock > wav->blockAlign || wav->samplesPerBlock%8 != 1)
+ {
fail("format[%s]: samplesPerBlock(%d) incompatible with blockAlign(%d)",
wav_format_str(wav->formatTag), wav->samplesPerBlock, wav->blockAlign);
+ return ST_EOF;
+ }
wav->packet = (unsigned char *)malloc(wav->blockAlign);
+ if (!wav->packet)
+ {
+ fail("Unable to alloc resources");
+ return ST_EOF;
+ }
len -= 2;
wav->samples = (short *)malloc(wChannels*wav->samplesPerBlock*sizeof(short));
+ if (!wav->samples)
+ {
+ fail("Unable to alloc resources");
+ return ST_EOF;
+ }
- bytespersample = WORD; /* AFTER de-compression */
+ bytespersample = ST_SIZE_WORD; /* AFTER de-compression */
break;
#ifdef HAVE_LIBGSM
@@ -644,17 +746,26 @@
/* GSM formats have extended fmt chunk. Check for those cases. */
case WAVE_FORMAT_GSM610:
if (wExtSize < 2)
+ {
fail("format[%s]: expects wExtSize >= %d",
wav_format_str(wav->formatTag), 2);
+ return ST_EOF;
+ }
wav->samplesPerBlock = rshort(ft);
bytesPerBlock = 65;
if (wav->blockAlign != 65)
+ {
fail("format[%s]: expects blockAlign(%d) = %d",
wav_format_str(wav->formatTag), wav->blockAlign, 65);
+ return ST_EOF;
+ }
if (wav->samplesPerBlock != 320)
+ {
fail("format[%s]: expects samplesPerBlock(%d) = %d",
wav_format_str(wav->formatTag), wav->samplesPerBlock, 320);
- bytespersample = WORD; /* AFTER de-compression */
+ return ST_EOF;
+ }
+ bytespersample = ST_SIZE_WORD; /* AFTER de-compression */
len -= 2;
break;
#endif
@@ -667,42 +778,43 @@
switch (bytespersample)
{
- case BYTE:
+ case ST_SIZE_BYTE:
/* User options take precedence */
- if (ft->info.size == -1 || ft->info.size == BYTE)
- ft->info.size = BYTE;
+ if (ft->info.size == -1 || ft->info.size == ST_SIZE_BYTE)
+ ft->info.size = ST_SIZE_BYTE;
else
warn("User options overriding size read in .wav header");
/* Now we have enough information to set default styles. */
if (ft->info.style == -1)
- ft->info.style = UNSIGNED;
+ ft->info.style = ST_ENCODING_UNSIGNED;
break;
- case WORD:
- if (ft->info.size == -1 || ft->info.size == WORD)
- ft->info.size = WORD;
+ case ST_SIZE_WORD:
+ if (ft->info.size == -1 || ft->info.size == ST_SIZE_WORD)
+ ft->info.size = ST_SIZE_WORD;
else
warn("User options overriding size read in .wav header");
/* Now we have enough information to set default styles. */
if (ft->info.style == -1)
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
break;
- case DWORD:
- if (ft->info.size == -1 || ft->info.size == DWORD)
- ft->info.size = DWORD;
+ case ST_SIZE_DWORD:
+ if (ft->info.size == -1 || ft->info.size == ST_SIZE_DWORD)
+ ft->info.size = ST_SIZE_DWORD;
else
warn("User options overriding size read in .wav header");
/* Now we have enough information to set default styles. */
if (ft->info.style == -1)
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
break;
default:
fail("Sorry, don't understand .wav size");
+ return ST_EOF;
}
/* Skip anything left over from fmt chunk */
@@ -775,7 +887,7 @@
default:
}
-
+ return ST_SUCCESS;
}
@@ -786,7 +898,7 @@
* Return number of samples read.
*/
-LONG wavread(ft, buf, len)
+LONG st_wavread(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
@@ -799,8 +911,8 @@
/* read as much as possible and return quickly. */
switch (ft->info.style)
{
- case IMA_ADPCM:
- case ADPCM:
+ case ST_ENCODING_IMA_ADPCM:
+ case ST_ENCODING_ADPCM:
done = 0;
while (done < len) { /* Still want data? */
/* See if need to read more from disk */
@@ -841,7 +953,7 @@
break;
#ifdef HAVE_LIBGSM
- case GSM:
+ case ST_ENCODING_GSM:
done = wavgsmread(ft, buf, len);
if (done == 0 && wav->numSamples != 0)
warn("Premature EOF on .wav input file");
@@ -848,7 +960,7 @@
break;
#endif
default: /* assume PCM style */
- done = rawread(ft, buf, len);
+ done = st_rawread(ft, buf, len);
/* If software thinks there are more samples but I/O */
/* says otherwise, let the user know about this. */
if (done == 0 && wav->numSamples != 0)
@@ -863,10 +975,11 @@
* Do anything required when you stop reading samples.
* Don't close input file!
*/
-void wavstopread(ft)
+int st_wavstopread(ft)
ft_t ft;
{
wav_t wav = (wav_t) ft->priv;
+ int rc = ST_SUCCESS;
if (wav->packet) free(wav->packet);
if (wav->samples) free(wav->samples);
@@ -875,29 +988,28 @@
switch (ft->info.style)
{
#ifdef HAVE_LIBGSM
- case GSM:
- wavgsmdestroy(ft);
+ case ST_ENCODING_GSM:
+ rc = wavgsmdestroy(ft);
break;
#endif
- case IMA_ADPCM:
- case ADPCM:
+ case ST_ENCODING_IMA_ADPCM:
+ case ST_ENCODING_ADPCM:
break;
default:
/* Needed for rawread() */
- rawstopread(ft);
+ rc = st_rawstopread(ft);
}
+ return rc;
}
-void wavstartwrite(ft)
+int st_wavstartwrite(ft)
ft_t ft;
{
wav_t wav = (wav_t) ft->priv;
int littlendian = 1;
char *endptr;
+ int rc;
- if (sizeof(struct wavstuff)> PRIVSIZE)
- fail("struct wav_t too big (%d); increase PRIVSIZE in st.h and recompile sox",sizeof(struct wavstuff));
-
endptr = (char *) &littlendian;
if (!*endptr) ft->swap = ft->swap ? 0 : 1;
@@ -905,7 +1017,9 @@
wav->dataLength = 0;
if (!ft->seekable)
warn("Length in output .wav header will be wrong since can't seek to fix it");
- wavwritehdr(ft, 0); /* also calculates various wav->* info */
+ rc = wavwritehdr(ft, 0); /* also calculates various wav->* info */
+ if (rc != 0)
+ return rc;
wav->packet = NULL;
wav->samples = NULL;
wav->iCoefs = NULL;
@@ -922,6 +1036,11 @@
sbsize = ft->info.channels * wav->samplesPerBlock;
wav->packet = (unsigned char *)malloc(wav->blockAlign);
wav->samples = (short *)malloc(sbsize*sizeof(short));
+ if (!wav->packet || !wav->samples)
+ {
+ fail("Unable to alloc resources");
+ return ST_EOF;
+ }
wav->sampleTop = wav->samples + sbsize;
wav->samplePtr = wav->samples;
break;
@@ -933,6 +1052,7 @@
#endif
default:
}
+ return ST_SUCCESS;
}
/* wavwritehdr: write .wav headers as follows:
@@ -991,7 +1111,7 @@
*/
-static void wavwritehdr(ft, second_header)
+static int wavwritehdr(ft, second_header)
ft_t ft;
int second_header;
{
@@ -1025,42 +1145,51 @@
ULONG bytespersample; /* (uncompressed) bytes per sample (per channel) */
ULONG blocksWritten = 0;
- if (ft->info.style != ADPCM &&
- ft->info.style != IMA_ADPCM &&
- ft->info.style != GSM
+ int rc;
+
+ if (ft->info.style != ST_ENCODING_ADPCM &&
+ ft->info.style != ST_ENCODING_IMA_ADPCM &&
+ ft->info.style != ST_ENCODING_GSM
)
- rawstartwrite(ft);
+ {
+ rc = st_rawstartwrite(ft);
+ if (rc)
+ return rc;
+ }
wSamplesPerSecond = ft->info.rate;
wChannels = ft->info.channels;
if (wChannels == 0 || wChannels>64) /* FIXME: arbitrary upper limit */
+ {
fail("Channels(%d) out-of-range\n",wChannels);
+ return ST_EOF;
+ }
switch (ft->info.size)
{
- case BYTE:
+ case ST_SIZE_BYTE:
wBitsPerSample = 8;
- if (ft->info.style != UNSIGNED &&
- ft->info.style != ULAW &&
- ft->info.style != ALAW)
+ if (ft->info.style != ST_ENCODING_UNSIGNED &&
+ ft->info.style != ST_ENCODING_ULAW &&
+ ft->info.style != ST_ENCODING_ALAW)
{
warn("Only support unsigned, ulaw, or alaw with 8-bit data. Forcing to unsigned");
- ft->info.style = UNSIGNED;
+ ft->info.style = ST_ENCODING_UNSIGNED;
}
break;
- case WORD:
+ case ST_SIZE_WORD:
wBitsPerSample = 16;
- if ((ft->info.style == UNSIGNED ||
- ft->info.style == ULAW ||
- ft->info.style == ALAW) &&
+ if ((ft->info.style == ST_ENCODING_UNSIGNED ||
+ ft->info.style == ST_ENCODING_ULAW ||
+ ft->info.style == ST_ENCODING_ALAW) &&
!second_header)
{
warn("Do not support Unsigned, ulaw, or alaw with 16 bit data. Forcing to Signed");
- ft->info.style = SIGN2;
+ ft->info.style = ST_ENCODING_SIGN2;
}
break;
- case DWORD:
+ case ST_SIZE_DWORD:
wBitsPerSample = 32;
break;
default:
@@ -1068,31 +1197,33 @@
break;
}
- bytespersample = WORD; /* common default */
+ bytespersample = ST_SIZE_WORD; /* common default */
wSamplesPerBlock = 1; /* common default */
switch (ft->info.style)
{
- case UNSIGNED:
- case SIGN2:
+ case ST_ENCODING_UNSIGNED:
+ case ST_ENCODING_SIGN2:
wFormatTag = WAVE_FORMAT_PCM;
bytespersample = (wBitsPerSample + 7)/8;
wBlockAlign = wChannels * bytespersample;
break;
- case ALAW:
+ case ST_ENCODING_ALAW:
wFormatTag = WAVE_FORMAT_ALAW;
- bytespersample = BYTE;
+ bytespersample = ST_SIZE_BYTE;
wBlockAlign = wChannels;
break;
- case ULAW:
+ case ST_ENCODING_ULAW:
wFormatTag = WAVE_FORMAT_MULAW;
- bytespersample = BYTE;
+ bytespersample = ST_SIZE_BYTE;
wBlockAlign = wChannels;
break;
- case IMA_ADPCM:
- /* warn("Experimental support writing IMA_ADPCM style.\n"); */
+ case ST_ENCODING_IMA_ADPCM:
if (wChannels>16)
+ {
fail("Channels(%d) must be <= 16\n",wChannels);
+ return ST_EOF;
+ }
wFormatTag = WAVE_FORMAT_IMA_ADPCM;
wBlockAlign = wChannels * 64; /* reasonable default */
wBitsPerSample = 4;
@@ -1099,10 +1230,13 @@
wExtSize = 2;
wSamplesPerBlock = ImaSamplesIn(0, wChannels, wBlockAlign, 0);
break;
- case ADPCM:
+ case ST_ENCODING_ADPCM:
/* warn("Experimental support writing ADPCM style.\n"); */
if (wChannels>16)
+ {
fail("Channels(%d) must be <= 16\n",wChannels);
+ return ST_EOF;
+ }
wFormatTag = WAVE_FORMAT_ADPCM;
wBlockAlign = wChannels * 128; /* reasonable default */
wBitsPerSample = 4;
@@ -1109,10 +1243,13 @@
wExtSize = 4+4*7; /* Ext fmt data length */
wSamplesPerBlock = AdpcmSamplesIn(0, wChannels, wBlockAlign, 0);
break;
- case GSM:
+ case ST_ENCODING_GSM:
#ifdef HAVE_LIBGSM
if (wChannels!=1)
+ {
fail("Channels(%d) must be == 1\n",wChannels);
+ return ST_EOF;
+ }
wFormatTag = WAVE_FORMAT_GSM610;
/* wAvgBytesPerSec = 1625*(wSamplesPerSecond/8000.)+0.5; */
wBlockAlign=65;
@@ -1121,6 +1258,7 @@
wSamplesPerBlock = 320;
#else
fail("sorry, no GSM6.10 support, recompile sox with gsm library");
+ return ST_EOF;
#endif
break;
}
@@ -1235,14 +1373,15 @@
}
#endif
}
+ return ST_SUCCESS;
}
-
-void wavwrite(ft, buf, len)
+LONG st_wavwrite(ft, buf, len)
ft_t ft;
LONG *buf, len;
{
wav_t wav = (wav_t) ft->priv;
+ LONG save_len = len;
switch (wav->formatTag)
{
@@ -1262,51 +1401,63 @@
xxxAdpcmWriteBlock(ft);
}
+ return save_len - len;
break;
#ifdef HAVE_LIBGSM
case WAVE_FORMAT_GSM610:
wav->numSamples += len;
- wavgsmwrite(ft, buf, len);
+ return wavgsmwrite(ft, buf, len);
break;
#endif
default:
wav->numSamples += len; /* must later be divided by wChannels */
- rawwrite(ft, buf, len);
+ return st_rawwrite(ft, buf, len);
}
}
-void wavstopwrite(ft)
+int st_wavstopwrite(ft)
ft_t ft;
{
wav_t wav = (wav_t) ft->priv;
+ int rc;
+
/* Call this to flush out any remaining data. */
switch (wav->formatTag)
{
case WAVE_FORMAT_IMA_ADPCM:
case WAVE_FORMAT_ADPCM:
- xxxAdpcmWriteBlock(ft);
+ rc = xxxAdpcmWriteBlock(ft);
break;
#ifdef HAVE_LIBGSM
case WAVE_FORMAT_GSM610:
- wavgsmstopwrite(ft);
+ rc = wavgsmstopwrite(ft);
break;
#endif
default:
- rawstopwrite(ft);
+ rc = st_rawstopwrite(ft);
}
if (wav->packet) free(wav->packet);
if (wav->samples) free(wav->samples);
if (wav->iCoefs) free(wav->iCoefs);
+ /* Now that we've free()'d memory, return with errors if needed */
+ if (rc)
+ return rc;
+
/* All samples are already written out. */
/* If file header needs fixing up, for example it needs the */
/* the number of samples in a field, seek back and write them here. */
if (!ft->seekable)
- return;
+ return ST_EOF;
+
if (fseek(ft->fp, 0L, SEEK_SET) != 0)
+ {
fail("Sorry, can't rewind output file to rewrite .wav header.");
+ return ST_EOF;
+ }
wavwritehdr(ft, 1);
+ return (ST_SUCCESS);
}
/*
--- a/src/wve.c
+++ b/src/wve.c
@@ -21,7 +21,7 @@
static void wvewriteheader(P1(ft_t ft));
-void wvestartread(ft)
+int st_wvestartread(ft)
ft_t ft;
{
struct wvepriv *p = (struct wvepriv *) ft->priv;
@@ -30,9 +30,12 @@
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed for rawread() */
- rawstartread(ft);
+ rc = st_rawstartread(ft);
+ if (rc)
+ return rc;
endptr = (char *) &littlendian;
/* WVE is in big endian format. Swap whats read in
@@ -43,12 +46,6 @@
ft->swap = ft->swap ? 0 : 1;
}
- /* Sanity check */
- if (sizeof(struct wvepriv) > PRIVSIZE)
- fail(
-"struct wvepriv is too big (%d); change PRIVSIZE in st.h and recompile sox",
- sizeof(struct wvepriv));
-
/* Check the magic word */
fread(magic, 16, 1, ft->fp);
if (strcmp(magic, PSION_MAGIC)==0) {
@@ -55,7 +52,10 @@
report("Found Psion magic word");
}
else
+ {
fail("Psion header doesn't start with magic word\nTry the '.al' file type with '-t al -r 8000 filename'");
+ return (ST_EOF);
+ }
version=rshort(ft);
@@ -74,7 +74,10 @@
report("Found PSION magic word");
}
else
+ {
fail("Wrong version in Psion header");
+ return(ST_EOF);
+ }
p->length=rlong(ft);
@@ -86,12 +89,13 @@
(void)rshort(ft);
(void)rshort(ft);
- ft->info.style = ALAW;
- ft->info.size = BYTE;
+ ft->info.style = ST_ENCODING_ALAW;
+ ft->info.size = ST_SIZE_BYTE;
ft->info.rate = 8000;
ft->info.channels = 1;
+ return (ST_SUCCESS);
}
/* When writing, the header is supposed to contain the number of
@@ -103,7 +107,7 @@
if it is not, the unspecified size remains in the header
(this is illegal). */
-void wvestartwrite(ft)
+int st_wvestartwrite(ft)
ft_t ft;
{
struct wvepriv *p = (struct wvepriv *) ft->priv;
@@ -110,9 +114,12 @@
int littlendian = 1;
char *endptr;
+ int rc;
/* Needed for rawwrite() */
- rawstartwrite(ft);
+ rc = st_rawstartwrite(ft);
+ if (rc)
+ return ST_EOF;
endptr = (char *) &littlendian;
/* wve is in big endian format. Swap whats read in
@@ -127,42 +134,48 @@
if (p->repeats == 0)
p->repeats = 1;
- ft->info.style = ALAW;
- ft->info.size = BYTE;
+ ft->info.style = ST_ENCODING_ALAW;
+ ft->info.size = ST_SIZE_BYTE;
ft->info.rate = 8000;
wvewriteheader(ft);
+ return ST_SUCCESS;
}
-LONG wveread(ft, buf, samp)
+LONG st_wveread(ft, buf, samp)
ft_t ft;
LONG *buf, samp;
{
- return rawread(ft, buf, samp);
+ return st_rawread(ft, buf, samp);
}
-void wvewrite(ft, buf, samp)
+LONG st_wvewrite(ft, buf, samp)
ft_t ft;
LONG *buf, samp;
{
struct wvepriv *p = (struct wvepriv *) ft->priv;
p->length += samp * ft->info.size;
- rawwrite(ft, buf, samp);
+ return st_rawwrite(ft, buf, samp);
}
-void
-wvestopwrite(ft)
+int st_wvestopwrite(ft)
ft_t ft;
{
if (!ft->seekable)
- return;
+ {
+ warn("Header will be have invalid file length since file is not seekable");
+ return ST_SUCCESS;
+ }
if (fseek(ft->fp, 0L, 0) != 0)
+ {
fail("Can't rewind output file to rewrite Psion header.");
+ return(ST_EOF);
+ }
wvewriteheader(ft);
/* Needed for rawwrite() */
- rawstopwrite(ft);
+ return st_rawstopwrite(ft);
}
static void wvewriteheader(ft)