ref: 1fe09e346267ad32591320888caa63ac23391e22
parent: 5e32cee2c962d96421fd047c63f9f7d01753d707
author: cbagwell <cbagwell>
date: Wed Feb 24 21:39:26 EST 1999
Changed raw drivers to be block oriented. Did some endianess cleanups as well.
--- a/Changelog
+++ b/Changelog
@@ -6,7 +6,11 @@
sox-12.16
---------
-
+
+ o Changed raw data functions to perform I/O operations using block reads.
+ Should improve speeds greatly, especially when filesize is in megs.
+ Got code ready to tweak speed more which also forced me to clean up
+ Endian test code.
o Fixed a bug in .au's handling of G.723. It wasn't using the correct
number of bits.
o Quoted $filename in play/rec scripts so that files with spaces in
--- a/TODO
+++ b/TODO
@@ -19,9 +19,6 @@
the number of makefiles by having all systems compile using one
makefile.
- o Change all code that sets up auto-swapping of bytes (-x option) to match
- that of cdr.c driver. Current method fails on certain endian machines.
-
o Fix for how include files are found when fseek() is used. In most
configs it has to hardcode the values for things like SEEK_SET. *BAD*
Include files are a mess, i.e. fseek problem. Need to resort to
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -36,19 +36,28 @@
struct svxpriv *p = (struct svxpriv *) ft->priv;
char buf[12];
- char *endptr;
char *chunk_buf;
-
+
ULONG totalsize;
ULONG chunksize;
int channels;
LONG rate;
- int littlendian = 0;
int i;
+ int littlendian = 1;
+ char *endptr;
ULONG chan1_pos;
+ endptr = (char*) &littlendian;
+ /* 8svx is in big endian format. Swap whats
+ * read in on little endian machines.
+ */
+ if (*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
rate = 0;
channels = 1;
@@ -55,7 +64,7 @@
/* 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'");
- totalsize = rblong(ft);
+ 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");
@@ -62,11 +71,11 @@
/* read chunks until 'BODY' (or end) */
while (fread(buf,1,4,ft->fp) == 4 && strncmp(buf,"BODY",4) != 0) {
if (strncmp(buf,"VHDR",4) == 0) {
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (chunksize != 20)
fail ("8SVX: VHDR chunk has bad size");
fseek(ft->fp,12,SEEK_CUR);
- rate = rbshort(ft);
+ rate = rshort(ft);
fseek(ft->fp,1,SEEK_CUR);
fread(buf,1,1,ft->fp);
if (buf[0] != 0)
@@ -76,7 +85,7 @@
}
if (strncmp(buf,"ANNO",4) == 0) {
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (chunksize & 1)
chunksize++;
chunk_buf = (char *) malloc(chunksize + 1);
@@ -91,7 +100,7 @@
}
if (strncmp(buf,"NAME",4) == 0) {
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (chunksize & 1)
chunksize++;
chunk_buf = (char *) malloc(chunksize + 1);
@@ -106,10 +115,10 @@
}
if (strncmp(buf,"CHAN",4) == 0) {
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (chunksize != 4)
fail("8SVX: Short channel chunk");
- channels = rblong(ft);
+ channels = rlong(ft);
channels = (channels & 0x01) +
((channels & 0x02) >> 1) +
((channels & 0x04) >> 2) +
@@ -119,7 +128,7 @@
}
/* some other kind of chunk */
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (chunksize & 1)
chunksize++;
fseek(ft->fp,chunksize,SEEK_CUR);
@@ -131,7 +140,7 @@
fail ("8SVX: invalid rate");
if (strncmp(buf,"BODY",4) != 0)
fail ("8SVX: BODY chunk not found");
- p->nsamples = rblong(ft);
+ p->nsamples = rlong(ft);
ft->info.channels = channels;
ft->info.rate = rate;
@@ -153,12 +162,6 @@
if (fseek(p->ch[i],p->nsamples/channels*i,SEEK_CUR))
fail ("Can't seek channel %d: %s",i,strerror(errno));
}
-
-
- endptr = (char *) &littlendian;
- *endptr = 1;
- if (littlendian == 1)
- ft->swap = 1;
}
/*======================================================================*/
@@ -210,10 +213,20 @@
ft_t ft;
{
struct svxpriv *p = (struct svxpriv *) ft->priv;
- int littlendian = 0;
int i;
+
+ int littlendian = 1;
char *endptr;
+ endptr = (char *) &littlendian;
+ /* 8svx is in big endian format. Swaps wahst
+ * read in on little endian machines.
+ */
+ if (*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
/* open channel output files */
p->ch[0] = ft->fp;
for (i = 1; i < ft->info.channels; i++) {
@@ -228,11 +241,6 @@
p->nsamples = 0;
svxwriteheader(ft, p->nsamples);
-
- endptr = (char *) &littlendian;
- *endptr = 1;
- if (littlendian == 1)
- ft->swap = 1;
}
/*======================================================================*/
@@ -309,28 +317,28 @@
if(formsize % 2 != 0) formsize++;
fputs ("FORM", ft->fp);
- wblong(ft, formsize); /* size of file */
+ wlong(ft, formsize); /* size of file */
fputs("8SVX", ft->fp); /* File type */
fputs ("VHDR", ft->fp);
- wblong(ft, (LONG) 20); /* number of bytes to follow */
- wblong(ft, nsamples); /* samples, 1-shot */
- wblong(ft, (LONG) 0); /* samples, repeat */
- wblong(ft, (LONG) 0); /* samples per repeat cycle */
- wbshort(ft, (int) ft->info.rate); /* samples per second */
+ wlong(ft, (LONG) 20); /* number of bytes to follow */
+ wlong(ft, nsamples); /* samples, 1-shot */
+ wlong(ft, (LONG) 0); /* samples, repeat */
+ wlong(ft, (LONG) 0); /* samples per repeat cycle */
+ wshort(ft, (int) ft->info.rate); /* samples per second */
fputc(1,ft->fp); /* number of octaves */
fputc(0,ft->fp); /* data compression (none) */
- wbshort(ft,1); wbshort(ft,0); /* volume */
+ wshort(ft,1); wshort(ft,0); /* volume */
fputs ("ANNO", ft->fp);
- wblong(ft, (LONG) 32); /* length of block */
+ wlong(ft, (LONG) 32); /* length of block */
fputs ("File created by Sound Exchange ", ft->fp);
fputs ("CHAN", ft->fp);
- wblong(ft, (LONG) 4);
- wblong(ft, (ft->info.channels == 2) ? (LONG) 6 :
+ wlong(ft, (LONG) 4);
+ wlong(ft, (ft->info.channels == 2) ? (LONG) 6 :
(ft->info.channels == 4) ? (LONG) 15 : (LONG) 2);
fputs ("BODY", ft->fp);
- wblong(ft, nsamples); /* samples in file */
+ wlong(ft, nsamples); /* samples in file */
}
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -74,7 +74,7 @@
double rate = 0.0;
ULONG offset = 0;
ULONG blocksize = 0;
- int littlendian;
+ int littlendian = 1;
char *endptr;
int foundcomm = 0, foundmark = 0, foundinstr = 0;
struct mark {
@@ -93,7 +93,6 @@
/* AIFF is in Big Endian format. Swap whats read in on Little */
/* Endian machines. */
- littlendian = 1;
endptr = (char *) &littlendian;
if (*endptr)
{
@@ -103,7 +102,7 @@
/* 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'");
- totalsize = rblong(ft);
+ 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");
@@ -112,27 +111,28 @@
/* The SSND chunk must be the last in the file */
while (1) {
if (fread(buf, 1, 4, ft->fp) != 4)
+ {
if (ssndsize > 0)
break;
else
fail("Missing SSND chunk in AIFF file");
-
+ }
if (strncmp(buf, "COMM", 4) == 0) {
/* COMM chunk */
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (chunksize != 18)
fail("AIFF COMM chunk has bad size");
- channels = rbshort(ft);
- frames = rblong(ft);
- bits = rbshort(ft);
+ channels = rshort(ft);
+ frames = rlong(ft);
+ bits = rshort(ft);
rate = read_ieee_extended(ft);
foundcomm = 1;
}
else if (strncmp(buf, "SSND", 4) == 0) {
/* SSND chunk */
- chunksize = rblong(ft);
- offset = rblong(ft);
- blocksize = rblong(ft);
+ chunksize = rlong(ft);
+ offset = rlong(ft);
+ blocksize = rlong(ft);
chunksize -= 8;
ssndsize = chunksize;
/* if can't seek, just do sound now */
@@ -144,14 +144,14 @@
}
else if (strncmp(buf, "MARK", 4) == 0) {
/* MARK chunk */
- chunksize = rblong(ft);
- nmarks = rbshort(ft);
+ chunksize = rlong(ft);
+ nmarks = rshort(ft);
chunksize -= 2;
for(i = 0; i < nmarks; i++) {
int len;
- marks[i].id = rbshort(ft);
- marks[i].position = rblong(ft);
+ marks[i].id = rshort(ft);
+ marks[i].position = rlong(ft);
chunksize -= 6;
len = getc(ft->fp);
chunksize -= len + 1;
@@ -172,7 +172,7 @@
}
else if (strncmp(buf, "INST", 4) == 0) {
/* INST chunk */
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
ft->instr.MIDInote = getc(ft->fp);
getc(ft->fp); /* detune */
ft->instr.MIDIlow = getc(ft->fp);
@@ -179,13 +179,13 @@
ft->instr.MIDIhi = getc(ft->fp);
getc(ft->fp); /* low velocity */
getc(ft->fp); /* hi velocity */
- rbshort(ft); /* gain */
- ft->loops[0].type = rbshort(ft); /* sustain loop */
- sustainLoopBegin = rbshort(ft); /* begin marker */
- sustainLoopEnd = rbshort(ft); /* end marker */
- ft->loops[1].type = rbshort(ft); /* release loop */
- releaseLoopBegin = rbshort(ft); /* begin marker */
- releaseLoopEnd = rbshort(ft); /* end marker */
+ rshort(ft); /* gain */
+ ft->loops[0].type = rshort(ft); /* sustain loop */
+ sustainLoopBegin = rshort(ft); /* begin marker */
+ sustainLoopEnd = rshort(ft); /* end marker */
+ ft->loops[1].type = rshort(ft); /* release loop */
+ releaseLoopBegin = rshort(ft); /* begin marker */
+ releaseLoopEnd = rshort(ft); /* end marker */
/* At least one known program generates an INST */
/* block with everything zeroed out (meaning */
@@ -197,7 +197,7 @@
foundinstr = 1;
}
else if (strncmp(buf, "APPL", 4) == 0) {
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
while(chunksize-- > 0)
getc(ft->fp);
}
@@ -204,14 +204,14 @@
else if (strncmp(buf, "ALCH", 4) == 0) {
/* I think this is bogus and gets grabbed by APPL */
/* INST chunk */
- rblong(ft); /* ENVS - jeez! */
- chunksize = rblong(ft);
+ rlong(ft); /* ENVS - jeez! */
+ chunksize = rlong(ft);
while(chunksize-- > 0)
getc(ft->fp);
}
else if (strncmp(buf, "ANNO", 4) == 0) {
/* Old form of comment chunk */
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
/* allocate enough memory to hold the comment */
ft->comment = (char *) malloc((size_t) chunksize);
if (ft->comment == NULL)
@@ -245,7 +245,7 @@
if (feof(ft->fp))
break;
report("AIFFstartread: ignoring '%s' chunk\n", buf);
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (feof(ft->fp))
break;
/* Skip the chunk using getc() so we may read
@@ -264,11 +264,12 @@
* Like, say, instrument loops.
*/
if (ft->seekable)
+ {
if (seekto > 0)
fseek(ft->fp, seekto, SEEK_SET);
else
fail("AIFF: no sound data on input file");
-
+ }
/* SSND chunk just read */
if (blocksize != 0)
fail("AIFF header specifies nonzero blocksize?!?!");
@@ -384,7 +385,7 @@
char *chunkDescription;
ft_t ft;
{
- LONG chunksize = rblong(ft);
+ LONG chunksize = rlong(ft);
/* allocate enough memory to hold the text including a terminating \0 */
*text = (char *) malloc((size_t) chunksize + 1);
if (*text == NULL)
@@ -422,7 +423,7 @@
if (fread(buf, 1, 4, ft->fp) != 4)
return;
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (feof(ft->fp))
return;
buf[4] = '\0';
@@ -520,7 +521,7 @@
fail("unsupported output style/size for AIFF header");
fputs("FORM", ft->fp); /* IFF header */
- wblong(ft, hsize + nframes * ft->info.size * ft->info.channels); /* file size */
+ wlong(ft, hsize + nframes * ft->info.size * ft->info.channels); /* file size */
fputs("AIFF", ft->fp); /* File type */
/* ANNO chunk -- holds comments text, however this is */
@@ -527,15 +528,15 @@
/* discouraged by Apple in preference to a COMT comments */
/* chunk, which holds a timestamp and marker id */
fputs("ANNO", ft->fp);
- wblong(ft, (LONG) strlen(ft->comment)); /* ANNO chunk size, the No of chars */
+ wlong(ft, (LONG) strlen(ft->comment)); /* ANNO chunk size, the No of chars */
fputs(ft->comment, ft->fp);
/* COMM chunk -- describes encoding (and #frames) */
fputs("COMM", ft->fp);
- wblong(ft, (LONG) 18); /* COMM chunk size */
- wbshort(ft, ft->info.channels); /* nchannels */
- wblong(ft, nframes); /* number of frames */
- wbshort(ft, bits); /* sample width, in bits */
+ wlong(ft, (LONG) 18); /* COMM chunk size */
+ wshort(ft, ft->info.channels); /* nchannels */
+ wlong(ft, nframes); /* number of frames */
+ wshort(ft, bits); /* sample width, in bits */
write_ieee_extended(ft, (double)ft->info.rate);
/* MARK chunk -- set markers */
@@ -543,22 +544,22 @@
fputs("MARK", ft->fp);
if (ft->instr.nloops > 2)
ft->instr.nloops = 2;
- wblong(ft, 2 + 16*ft->instr.nloops);
- wbshort(ft, ft->instr.nloops);
+ wlong(ft, 2 + 16*ft->instr.nloops);
+ wshort(ft, ft->instr.nloops);
for(i = 0; i < ft->instr.nloops; i++) {
- wbshort(ft, i + 1);
- wblong(ft, ft->loops[i].start);
+ wshort(ft, i + 1);
+ wlong(ft, ft->loops[i].start);
fputc(0, ft->fp);
fputc(0, ft->fp);
- wbshort(ft, i*2 + 1);
- wblong(ft, ft->loops[i].start + ft->loops[i].length);
+ wshort(ft, i*2 + 1);
+ wlong(ft, ft->loops[i].start + ft->loops[i].length);
fputc(0, ft->fp);
fputc(0, ft->fp);
}
fputs("INST", ft->fp);
- wblong(ft, 20);
+ wlong(ft, 20);
/* random MIDI shit that we default on */
fputc(ft->instr.MIDInote, ft->fp);
fputc(0, ft->fp); /* detune */
@@ -566,21 +567,21 @@
fputc(ft->instr.MIDIhi, ft->fp);
fputc(1, ft->fp); /* low velocity */
fputc(127, ft->fp); /* hi velocity */
- wbshort(ft, 0); /* gain */
+ wshort(ft, 0); /* gain */
/* sustain loop */
- wbshort(ft, ft->loops[0].type);
- wbshort(ft, 1); /* marker 1 */
- wbshort(ft, 3); /* marker 3 */
+ wshort(ft, ft->loops[0].type);
+ wshort(ft, 1); /* marker 1 */
+ wshort(ft, 3); /* marker 3 */
/* release loop, if there */
if (ft->instr.nloops == 2) {
- wbshort(ft, ft->loops[1].type);
- wbshort(ft, 2); /* marker 2 */
- wbshort(ft, 4); /* marker 4 */
+ wshort(ft, ft->loops[1].type);
+ wshort(ft, 2); /* marker 2 */
+ wshort(ft, 4); /* marker 4 */
} else {
- wbshort(ft, 0); /* no release loop */
- wbshort(ft, 0);
- wbshort(ft, 0);
+ wshort(ft, 0); /* no release loop */
+ wshort(ft, 0);
+ wshort(ft, 0);
}
}
@@ -587,9 +588,9 @@
/* SSND chunk -- describes data */
fputs("SSND", ft->fp);
/* chunk size */
- wblong(ft, 8 + nframes * ft->info.channels * ft->info.size);
- wblong(ft, (LONG) 0); /* offset */
- wblong(ft, (LONG) 0); /* block size */
+ wlong(ft, 8 + nframes * ft->info.channels * ft->info.size);
+ wlong(ft, (LONG) 0); /* offset */
+ wlong(ft, (LONG) 0); /* block size */
}
double read_ieee_extended(ft)
--- a/src/au.c
+++ b/src/au.c
@@ -77,6 +77,18 @@
char *buf;
struct aupriv *p = (struct aupriv *) ft->priv;
+ int littlendian = 1;
+ char *endptr;
+
+ endptr = (char *) &littlendian;
+ /* AU is in big endian format. Swap whats read
+ * in onlittle endian machines.
+ */
+ if (*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
/* Sanity check */
if (sizeof(struct aupriv) > PRIVSIZE)
fail(
@@ -86,19 +98,21 @@
/* Check the magic word */
magic = rlong(ft);
if (magic == DEC_INV_MAGIC) {
- ft->swap = 1;
- report("Found inverted DEC magic word");
+ /* Inverted headers are not standard. Code was probably
+ * left over from pre-standardize period of testing for
+ * endianess. Its not hurting though.
+ */
+ ft->swap = ft->swap ? 0 : 1;
+ report("Found inverted DEC magic word. Swapping bytes.");
}
else if (magic == SUN_INV_MAGIC) {
- ft->swap = 1;
- report("Found inverted Sun/NeXT magic word");
+ ft->swap = ft->swap ? 0 : 1;
+ report("Found inverted Sun/NeXT magic word. Swapping bytes.");
}
else if (magic == SUN_MAGIC) {
- ft->swap = 0;
report("Found Sun/NeXT magic word");
}
else if (magic == DEC_MAGIC) {
- ft->swap = 0;
report("Found DEC magic word");
}
else
@@ -197,15 +211,20 @@
ft_t ft;
{
struct aupriv *p = (struct aupriv *) ft->priv;
- int littlendian = 0;
+ int littlendian = 1;
char *endptr;
p->data_size = 0;
auwriteheader(ft, SUN_UNSPEC);
+
endptr = (char *) &littlendian;
- *endptr = 1;
- if (littlendian == 1)
- ft->swap = 1;
+ /* AU is in big endian format. Swap whats read in
+ * on little endian machines.
+ */
+ if (*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
}
/*
@@ -302,22 +321,22 @@
}
magic = SUN_MAGIC;
- wblong(ft, magic);
+ wlong(ft, magic);
if (ft->comment == NULL)
ft->comment = "";
hdr_size = SUN_HDRSIZE + strlen(ft->comment);
- wblong(ft, hdr_size);
+ wlong(ft, hdr_size);
- wblong(ft, data_size);
+ wlong(ft, data_size);
- wblong(ft, encoding);
+ wlong(ft, encoding);
sample_rate = ft->info.rate;
- wblong(ft, sample_rate);
+ wlong(ft, sample_rate);
channels = ft->info.channels;
- wblong(ft, channels);
+ wlong(ft, channels);
fputs(ft->comment, ft->fp);
}
--- a/src/g72x.c
+++ b/src/g72x.c
@@ -371,11 +371,12 @@
/* update predictor pole a[0] */
state_ptr->a[0] -= state_ptr->a[0] >> 8;
if (dqsez != 0)
+ {
if (pks1 == 0)
state_ptr->a[0] += 192;
else
state_ptr->a[0] -= 192;
-
+ }
/* LIMD */
a1ul = 15360 - a2p;
if (state_ptr->a[0] < -a1ul)
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -151,6 +151,7 @@
};
extern void rawstartread();
extern LONG rawread();
+extern void rawstopread();
extern void rawstartwrite();
extern void rawwrite();
extern void rawstopwrite();
@@ -318,8 +319,8 @@
aiffstartread, aiffread, aiffstopread, /* SGI/Apple AIFF */
aiffstartwrite, aiffwrite, aiffstopwrite},
{alnames, FILE_STEREO,
- alstartread, rawread, nothing, /* a-law byte raw */
- alstartwrite, rawwrite, nothing},
+ alstartread, rawread, rawstopread, /* a-law byte raw */
+ alstartwrite, rawwrite, rawstopwrite},
{aunames, FILE_STEREO,
austartread, auread, nothing, /* SPARC .AU w/header */
austartwrite, auwrite, austopwrite},
@@ -356,8 +357,8 @@
ossdspstartwrite, ossdspwrite, ossdspstopwrite},
#endif
{rawnames, FILE_STEREO,
- rawstartread, rawread, nothing, /* Raw format */
- rawstartwrite, rawwrite, nothing},
+ rawstartread, rawread, rawstopread, /* Raw format */
+ rawstartwrite, rawwrite, rawstopwrite},
#if defined(BLASTER) || defined(SBLAST)
/* 386 Unix sound blaster player. */
{sbdspnames, FILE_STEREO,
@@ -365,8 +366,8 @@
sbdspstartwrite, sbdspwrite, sbdspstopwrite},
#endif
{sbnames, FILE_STEREO,
- sbstartread, rawread, nothing, /* signed byte raw */
- sbstartwrite, rawwrite, nothing},
+ sbstartread, rawread, rawstopread, /* signed byte raw */
+ sbstartwrite, rawwrite, rawstopwrite},
{sfnames, FILE_STEREO,
sfstartread, rawread, nothing, /* IRCAM Sound File */
sfstartwrite, rawwrite, nothing}, /* Relies on raw */
@@ -389,20 +390,20 @@
svxstartread, svxread, svxstopread, /* Amiga 8SVX */
svxstartwrite, svxwrite, svxstopwrite},
{swnames, FILE_STEREO,
- swstartread, rawread, nothing, /* signed word raw */
- swstartwrite, rawwrite, nothing},
+ 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, nothing, /* unsigned byte raw */
- ubstartwrite, rawwrite, nothing},
+ ubstartread, rawread, rawstopread, /* unsigned byte raw */
+ ubstartwrite, rawwrite, rawstopwrite},
{ulnames, FILE_STEREO,
- ulstartread, rawread, nothing, /* u-law byte raw */
- ulstartwrite, rawwrite, nothing},
+ ulstartread, rawread, rawstopread, /* u-law byte raw */
+ ulstartwrite, rawwrite, rawstopwrite},
{uwnames, FILE_STEREO,
- uwstartread, rawread, nothing, /* unsigned word raw */
- uwstartwrite, rawwrite, nothing},
+ uwstartread, rawread, rawstopread, /* unsigned word raw */
+ uwstartwrite, rawwrite, rawstopwrite},
{vocnames, FILE_STEREO,
vocstartread, vocread, vocstopread, /* Sound Blaster .VOC */
vocstartwrite, vocwrite, vocstopwrite},
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -64,6 +64,19 @@
ULONG huffcount, checksum, compresstype, divisor;
unsigned short dictsize;
+ int littlendian = 1;
+ char *endptr;
+
+
+ endptr = (char *) &littlendian;
+ /* hcom is in big endian format. Swap whats
+ * read in on little machine
+ */
+ if (*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
/* Skip first 65 bytes of header */
skipbytes(ft, 65);
@@ -75,8 +88,8 @@
skipbytes(ft, 83-69);
/* Get essential numbers from the header */
- datasize = rblong(ft); /* bytes 83-86 */
- rsrcsize = rblong(ft); /* bytes 87-90 */
+ datasize = rlong(ft); /* bytes 83-86 */
+ rsrcsize = rlong(ft); /* bytes 87-90 */
/* Skip the rest of the header (total 128 bytes) */
skipbytes(ft, 128-91);
@@ -86,15 +99,15 @@
fail("Mac data fork is not HCOM");
/* Then follow various parameters */
- huffcount = rblong(ft);
- checksum = rblong(ft);
- compresstype = rblong(ft);
+ huffcount = rlong(ft);
+ checksum = rlong(ft);
+ compresstype = rlong(ft);
if (compresstype > 1)
fail("Bad compression type in HCOM header");
- divisor = rblong(ft);
+ divisor = rlong(ft);
if (divisor == 0 || divisor > 4)
fail("Bad sampling rate divisor in HCOM header");
- dictsize = rbshort(ft);
+ dictsize = rshort(ft);
/* Translate to sox parameters */
ft->info.style = UNSIGNED;
@@ -109,8 +122,8 @@
/* Read dictionary */
for(i = 0; i < dictsize; i++) {
- p->dictionary[i].dict_leftson = rbshort(ft);
- p->dictionary[i].dict_rightson = rbshort(ft);
+ p->dictionary[i].dict_leftson = rshort(ft);
+ p->dictionary[i].dict_rightson = rshort(ft);
/*
report("%d %d",
p->dictionary[i].dict_leftson,
@@ -165,7 +178,7 @@
while (p->huffcount > 0) {
if(p->nrbits == 0) {
- p->current = rblong(ft);
+ p->current = rlong(ft);
if (feof(ft->fp))
fail("unexpected EOF in HCOM data");
p->cksum += p->current;
@@ -228,6 +241,18 @@
{
register struct writepriv *p = (struct writepriv *) ft->priv;
+ int littlendian = 1;
+ char *endptr;
+
+ endptr = (char *) &littlendian;
+ /* hcom is inbigendian format. Swap whats
+ * read in on little endian machines.
+ */
+ if (*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
switch (ft->info.rate) {
case 22050:
case 22050/2:
@@ -475,8 +500,8 @@
padbytes(ft, 65-3);
(void) fwrite("FSSD", 1, 4, ft->fp);
padbytes(ft, 83-69);
- wblong(ft, (ULONG) compressed_len); /* compressed_data size */
- wblong(ft, (ULONG) 0); /* rsrc size */
+ wlong(ft, (ULONG) compressed_len); /* compressed_data size */
+ wlong(ft, (ULONG) 0); /* rsrc size */
padbytes(ft, 128 - 91);
if (ferror(ft->fp))
fail("write error in HCOM header");
--- a/src/maud.c
+++ b/src/maud.c
@@ -10,7 +10,7 @@
/*
* Sound Tools MAUD file format driver, by Lutz Vieweg 1993
*
- * supports: mono and stereo, linear, a-lawa and u-law reading and writing
+ * supports: mono and stereo, linear, a-law and u-law reading and writing
*
*/
@@ -42,7 +42,6 @@
struct maudstuff * p = (struct maudstuff *) ft->priv;
char buf[12];
- char *endptr;
char *chunk_buf;
unsigned short bitpersam;
@@ -52,13 +51,23 @@
ULONG chunksize;
- int littlendian = 0;
+ int littlendian = 1;
+ char *endptr;
+
+ endptr = (char *) &littlendian;
+ /* maud is in big endian format. Swap whats read in
+ * on little endian machines.
+ */
+ if (*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
/* 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'");
- rblong(ft); /* totalsize */
+ 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");
@@ -74,21 +83,21 @@
if (strncmp(buf,"MHDR",4) == 0) {
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (chunksize != 8*4) fail ("MAUD: MHDR chunk has bad size");
/* fseek(ft->fp,12,SEEK_CUR); */
- p->nsamples = rblong(ft); /* number of samples stored in MDAT */
- bitpersam = rbshort(ft); /* number of bits per sample as stored in MDAT */
- rbshort(ft); /* number of bits per sample after decompression */
- nom = rblong(ft); /* clock source frequency */
- denom = rbshort(ft); /* clock devide */
+ p->nsamples = rlong(ft); /* number of samples stored in MDAT */
+ bitpersam = rshort(ft); /* number of bits per sample as stored in MDAT */
+ 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");
ft->info.rate = nom / denom;
- chaninf = rbshort(ft); /* channel information */
+ chaninf = rshort(ft); /* channel information */
switch (chaninf) {
case 0:
ft->info.channels = 1;
@@ -101,14 +110,14 @@
break;
}
- chaninf = rbshort(ft); /* number of channels (mono: 1, stereo: 2, ...) */
+ chaninf = rshort(ft); /* number of channels (mono: 1, stereo: 2, ...) */
if (chaninf != ft->info.channels) fail("MAUD: unsupported number of channels in file");
- chaninf = rbshort(ft); /* compression type */
+ chaninf = rshort(ft); /* compression type */
- rblong(ft); /* rest of chunk, unused yet */
- rblong(ft);
- rblong(ft);
+ rlong(ft); /* rest of chunk, unused yet */
+ rlong(ft);
+ rlong(ft);
if (bitpersam == 8 && chaninf == 0) {
ft->info.size = BYTE;
@@ -134,7 +143,7 @@
}
if (strncmp(buf,"ANNO",4) == 0) {
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (chunksize & 1)
chunksize++;
chunk_buf = (char *) malloc(chunksize + 1);
@@ -149,7 +158,7 @@
}
/* some other kind of chunk */
- chunksize = rblong(ft);
+ chunksize = rlong(ft);
if (chunksize & 1)
chunksize++;
fseek(ft->fp,chunksize,SEEK_CUR);
@@ -158,11 +167,7 @@
}
if (strncmp(buf,"MDAT",4) != 0) fail("MAUD: MDAT chunk not found");
- p->nsamples = rblong(ft);
-
- endptr = (char *) &littlendian;
- *endptr = 1;
- if (littlendian == 1) ft->swap = 1;
+ p->nsamples = rlong(ft);
}
/*
@@ -217,7 +222,7 @@
}
else {
while(done < len) {
- datum = rbshort(ft);
+ datum = rshort(ft);
if (feof(ft->fp)) return done;
/* scale signed up to long's range */
*buf++ = LEFT(datum, 16);
@@ -281,12 +286,12 @@
}
else {
while(done < len) {
- datum = rbshort(ft);
+ datum = rshort(ft);
if (feof(ft->fp)) return done;
/* scale signed up to long's range */
*buf++ = LEFT(datum, 16);
- datum = rbshort(ft);
+ datum = rshort(ft);
if (feof(ft->fp)) return done;
/* scale signed up to long's range */
*buf++ = LEFT(datum, 16);
@@ -310,8 +315,18 @@
ft_t ft;
{
struct maudstuff * p = (struct maudstuff *) ft->priv;
- int littlendian = 0;
+
+ int littlendian = 1;
char *endptr;
+
+ endptr = (char *) &littlendian;
+ /* maud is in big endian format. Swap whats read in
+ * on little endian machines.
+ */
+ if (*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
/* If you have to seek around the output file */
if (! ft->seekable) fail("Output .maud file must be a file, not a pipe");
@@ -326,10 +341,6 @@
p->nsamples = 0x7f000000L;
maudwriteheader(ft);
p->nsamples = 0;
-
- endptr = (char *) &littlendian;
- *endptr = 1;
- if (littlendian == 1) ft->swap = 1;
}
void maudwrite(ft, buf, len)
@@ -360,43 +371,43 @@
struct maudstuff * p = (struct maudstuff *) ft->priv;
fputs ("FORM", ft->fp);
- wblong(ft, (p->nsamples*ft->info.size) + MAUDHEADERSIZE); /* size of file */
+ wlong(ft, (p->nsamples*ft->info.size) + MAUDHEADERSIZE); /* size of file */
fputs("MAUD", ft->fp); /* File type */
fputs ("MHDR", ft->fp);
- wblong(ft, (LONG) 8*4); /* number of bytes to follow */
- wblong(ft, (LONG) (p->nsamples )); /* number of samples stored in MDAT */
+ wlong(ft, (LONG) 8*4); /* number of bytes to follow */
+ wlong(ft, (LONG) (p->nsamples )); /* number of samples stored in MDAT */
switch (ft->info.style) {
case UNSIGNED:
- wbshort(ft, (int) 8); /* number of bits per sample as stored in MDAT */
- wbshort(ft, (int) 8); /* number of bits per sample after decompression */
+ 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:
- wbshort(ft, (int) 16); /* number of bits per sample as stored in MDAT */
- wbshort(ft, (int) 16); /* number of bits per sample after decompression */
+ 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:
- wbshort(ft, (int) 8); /* number of bits per sample as stored in MDAT */
- wbshort(ft, (int) 16); /* number of bits per sample after decompression */
+ 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;
}
- wblong(ft, (LONG) ft->info.rate); /* clock source frequency */
- wbshort(ft, (int) 1); /* clock devide */
+ wlong(ft, (LONG) ft->info.rate); /* clock source frequency */
+ wshort(ft, (int) 1); /* clock devide */
if (ft->info.channels == 1) {
- wbshort(ft, (int) 0); /* channel information */
- wbshort(ft, (int) 1); /* number of channels (mono: 1, stereo: 2, ...) */
+ wshort(ft, (int) 0); /* channel information */
+ wshort(ft, (int) 1); /* number of channels (mono: 1, stereo: 2, ...) */
}
else {
- wbshort(ft, (int) 1);
- wbshort(ft, (int) 2);
+ wshort(ft, (int) 1);
+ wshort(ft, (int) 2);
}
switch (ft->info.style) {
@@ -403,28 +414,28 @@
case UNSIGNED:
case SIGN2:
- wbshort(ft, (int) 0); /* no compression */
+ wshort(ft, (int) 0); /* no compression */
break;
case ULAW:
- wbshort(ft, (int) 3);
+ wshort(ft, (int) 3);
break;
case ALAW:
- wbshort(ft, (int) 2);
+ wshort(ft, (int) 2);
break;
}
- wblong(ft, (LONG) 0); /* reserved */
- wblong(ft, (LONG) 0); /* reserved */
- wblong(ft, (LONG) 0); /* reserved */
+ wlong(ft, (LONG) 0); /* reserved */
+ wlong(ft, (LONG) 0); /* reserved */
+ wlong(ft, (LONG) 0); /* reserved */
fputs ("ANNO", ft->fp);
- wblong(ft, (LONG) 32); /* length of block */
+ wlong(ft, (LONG) 32); /* length of block */
fputs ("file written by SOX MAUD-export ", ft->fp);
fputs ("MDAT", ft->fp);
- wblong(ft, p->nsamples * ft->info.size ); /* samples in file */
+ wlong(ft, p->nsamples * ft->info.size ); /* samples in file */
}
--- a/src/misc.c
+++ b/src/misc.c
@@ -43,134 +43,6 @@
/* Utilities */
-/* Read short, little-endian: little end first. VAX/386 style. */
-unsigned short
-rlshort(ft)
-ft_t ft;
-{
- unsigned char uc, uc2;
- uc = getc(ft->fp);
- uc2 = getc(ft->fp);
- return (uc2 << 8) | uc;
-}
-
-/* Read short, bigendian: big first. 68000/SPARC style. */
-unsigned short
-rbshort(ft)
-ft_t ft;
-{
- unsigned char uc, uc2;
- uc2 = getc(ft->fp);
- uc = getc(ft->fp);
- return (uc2 << 8) | uc;
-}
-
-/* Write short, little-endian: little end first. VAX/386 style. */
-unsigned short
-#if defined(__STDC__)
-wlshort(ft_t ft, unsigned short us)
-#else
-wlshort(ft, us)
-ft_t ft;
-unsigned short us;
-#endif
-{
- putc(us, ft->fp);
- putc(us >> 8, ft->fp);
- if (ferror(ft->fp))
- fail(writerr);
- return(0);
-}
-
-/* Write short, big-endian: big end first. 68000/SPARC style. */
-unsigned short
-#if defined(__STDC__)
-wbshort(ft_t ft, unsigned short us)
-#else
-wbshort(ft, us)
-ft_t ft;
-unsigned short us;
-#endif
-{
- putc(us >> 8, ft->fp);
- putc(us, ft->fp);
- if (ferror(ft->fp))
- fail(writerr);
- return(0);
-}
-
-/* Read long, little-endian: little end first. VAX/386 style. */
-ULONG
-rllong(ft)
-ft_t ft;
-{
- unsigned char uc, uc2, uc3, uc4;
-/* if (feof(ft->fp))
- fail(readerr); */ /* No worky! */
- uc = getc(ft->fp);
- uc2 = getc(ft->fp);
- uc3 = getc(ft->fp);
- uc4 = getc(ft->fp);
- return ((LONG)uc4 << 24) | ((LONG)uc3 << 16) | ((LONG)uc2 << 8) | (LONG)uc;
-}
-
-/* Read long, bigendian: big first. 68000/SPARC style. */
-ULONG
-rblong(ft)
-ft_t ft;
-{
- unsigned char uc, uc2, uc3, uc4;
-/* if (feof(ft->fp))
- fail(readerr); */ /* No worky! */
- uc = getc(ft->fp);
- uc2 = getc(ft->fp);
- uc3 = getc(ft->fp);
- uc4 = getc(ft->fp);
- return ((LONG)uc << 24) | ((LONG)uc2 << 16) | ((LONG)uc3 << 8) | (LONG)uc4;
-}
-
-/* Write long, little-endian: little end first. VAX/386 style. */
-ULONG
-wllong(ft, ul)
-ft_t ft;
-ULONG ul;
-{
-char datum;
-
- datum = (char) (ul) & 0xff;
- putc(datum, ft->fp);
- datum = (char) (ul >> 8) & 0xff;
- putc(datum, ft->fp);
- datum = (char) (ul >> 16) & 0xff;
- putc(datum, ft->fp);
- datum = (char) (ul >> 24) & 0xff;
- putc(datum, ft->fp);
- if (ferror(ft->fp))
- fail(writerr);
- return(0);
-}
-
-/* Write long, big-endian: big end first. 68000/SPARC style. */
-ULONG
-wblong(ft, ul)
-ft_t ft;
-ULONG ul;
-{
-char datum;
-
- datum = (char) (ul >> 24) & 0xff;
- putc(datum, ft->fp);
- datum = (char) (ul >> 16) & 0xff;
- putc(datum, ft->fp);
- datum = (char) (ul >> 8) & 0xff;
- putc(datum, ft->fp);
- datum = (char) (ul) & 0xff;
- putc(datum, ft->fp);
- if (ferror(ft->fp))
- fail(writerr);
- return(0);
-}
-
/* Read and write words and longs in "machine format". Swap if indicated. */
/* Read short. */
@@ -180,8 +52,6 @@
{
unsigned short us;
-/* if (feof(ft->fp))
- fail(readerr); */ /* No worky! */
fread(&us, 2, 1, ft->fp);
if (ft->swap)
us = swapw(us);
@@ -212,8 +82,6 @@
{
ULONG ul;
-/* if (feof(ft->fp))
- fail(readerr); */ /* No worky! */
fread(&ul, 4, 1, ft->fp);
if (ft->swap)
ul = swapl(ul);
@@ -240,8 +108,6 @@
{
float f;
-/* if (feof(ft->fp))
- fail(readerr); */ /* No worky! */
fread(&f, sizeof(float), 1, ft->fp);
if (ft->swap)
f = swapf(f);
@@ -268,8 +134,6 @@
{
double d;
-/* if (feof(ft->fp))
- fail(readerr); */ /* No worky! */
fread(&d, sizeof(double), 1, ft->fp);
if (ft->swap)
d = swapd(d);
--- a/src/raw.c
+++ b/src/raw.c
@@ -22,19 +22,88 @@
#include "st.h"
#include "libst.h"
+#include <malloc.h>
+
void rawstartread(ft)
ft_t ft;
{
+ ft->file.buf = malloc(BUFSIZ);
+ ft->file.size = BUFSIZ;
+ ft->file.count = 0;
+ ft->file.eof = 0;
}
void rawstartwrite(ft)
ft_t ft;
{
+ ft->file.buf = malloc(BUFSIZ);
+ ft->file.size = BUFSIZ;
+ ft->file.count = 0;
+ ft->file.eof = 0;
}
/* Read raw file data, and convert it to */
/* the sox internal signed long format. */
+unsigned char blockgetc(ft)
+ft_t ft;
+{
+ char rval;
+
+ if (ft->file.count < 1)
+ {
+ ft->file.count = read(fileno(ft->fp), (char *)ft->file.buf,
+ ft->file.size);
+ if (ft->file.count == 0)
+ {
+ ft->file.eof = 1;
+ return(0);
+ }
+ }
+ rval = *(ft->file.buf + (ft->file.size - ft->file.count--));
+ return (rval);
+}
+
+unsigned short blockrshort(ft)
+ft_t ft;
+{
+ unsigned short rval;
+ if (ft->file.count < 2)
+ {
+ ft->file.count = read(fileno(ft->fp), (char *)ft->file.buf,
+ ft->file.size);
+ if (ft->file.count == 0)
+ {
+ ft->file.eof = 1;
+ return(0);
+ }
+ }
+ rval = *((unsigned short *)(ft->file.buf + (ft->file.size - ft->file.count)));
+ ft->file.count -= 2;
+ return(rval);
+}
+
+float blockrfloat(ft)
+ft_t ft;
+{
+ float rval;
+
+ if (ft->file.count < sizeof(float))
+ {
+ ft->file.count = read(fileno(ft->fp), (char *)ft->file.buf,
+ ft->file.size);
+ if (ft->file.count == 0)
+ {
+ ft->file.eof = 1;
+ return(0);
+ }
+ }
+ rval = *((float *)(ft->file.buf + (ft->file.size - ft->file.count)));
+ ft->file.count -= sizeof(float);
+ return(rval);
+}
+
+
LONG rawread(ft, buf, nsamp)
ft_t ft;
LONG *buf, nsamp;
@@ -48,8 +117,8 @@
{
case SIGN2:
while(done < nsamp) {
- datum = getc(ft->fp);
- if (feof(ft->fp))
+ datum = blockgetc(ft);
+ if (ft->file.eof)
return done;
/* scale signed up to long's range */
*buf++ = LEFT(datum, 24);
@@ -58,8 +127,8 @@
return done;
case UNSIGNED:
while(done < nsamp) {
- datum = getc(ft->fp);
- if (feof(ft->fp))
+ datum = blockgetc(ft);
+ if (ft->file.eof)
return done;
/* Convert to signed */
datum ^= 128;
@@ -70,8 +139,8 @@
return done;
case ULAW:
while(done < nsamp) {
- datum = getc(ft->fp);
- if (feof(ft->fp))
+ datum = blockgetc(ft);
+ if (ft->file.eof)
return done;
datum = st_ulaw_to_linear(datum);
/* scale signed up to long's range */
@@ -81,8 +150,8 @@
return done;
case ALAW:
while(done < nsamp) {
- datum = getc(ft->fp);
- if (feof(ft->fp))
+ datum = blockgetc(ft);
+ if (ft->file.eof)
return done;
datum = st_Alaw_to_linear(datum);
/* scale signed up to long's range */
@@ -98,8 +167,8 @@
{
case SIGN2:
while(done < nsamp) {
- datum = rshort(ft);
- if (feof(ft->fp))
+ datum = blockrshort(ft);
+ if (ft->file.eof)
return done;
/* scale signed up to long's range */
*buf++ = LEFT(datum, 16);
@@ -108,8 +177,8 @@
return done;
case UNSIGNED:
while(done < nsamp) {
- datum = rshort(ft);
- if (feof(ft->fp))
+ datum = blockrshort(ft);
+ if (ft->file.eof)
return done;
/* Convert to signed */
datum ^= 0x8000;
@@ -128,9 +197,8 @@
break;
case FLOAT:
while(done < nsamp) {
- datum = dovolume? volume * rfloat(ft)
- : rfloat(ft);
- if (feof(ft->fp))
+ datum = blockrfloat(ft);
+ if (ft->file.eof)
return done;
*buf++ = LEFT(datum, 16);
done++;
@@ -144,6 +212,49 @@
return(0);
}
+void rawstopread(ft)
+ft_t ft;
+{
+ free(ft->file.buf);
+}
+
+void blockflush(ft)
+ft_t ft;
+{
+ if (write(fileno(ft->fp), ft->file.buf, ft->file.count) != ft->file.count)
+ {
+ fail("Error writing data to file");
+ }
+ ft->file.count = 0;
+}
+
+void blockputc(ft,c)
+ft_t ft;
+int c;
+{
+ if (ft->file.count > ft->file.size-1) blockflush(ft);
+ *(ft->file.buf + ft->file.count) = c;
+ ft->file.count++;
+}
+
+void blockwshort(ft,ui)
+ft_t ft;
+unsigned short ui;
+{
+ if (ft->file.count > ft->file.size-2) blockflush(ft);
+ *((unsigned short *)(ft->file.buf + ft->file.count)) = ui;
+ ft->file.count += 2;
+}
+
+void blockwfloat(ft,f)
+ft_t ft;
+float f;
+{
+ if (ft->file.count > ft->file.size - sizeof(float)) blockflush(ft);
+ *((float *)(ft->file.buf + ft->file.count)) = f;
+ ft->file.count += sizeof(float);
+}
+
/* Convert the sox internal signed long format */
/* to the raw file data, and write it. */
@@ -163,7 +274,7 @@
while(done < nsamp) {
/* scale signed up to long's range */
datum = (int) RIGHT(*buf++, 24);
- putc(datum, ft->fp);
+ blockputc(ft, datum);
done++;
}
return;
@@ -173,7 +284,7 @@
datum = (int) RIGHT(*buf++, 24);
/* Convert to unsigned */
datum ^= 128;
- putc(datum, ft->fp);
+ blockputc(ft, datum);
done++;
}
return;
@@ -184,7 +295,7 @@
/* round up to 12 bits of data */
datum += 0x8; /* + 0b1000 */
datum = st_linear_to_ulaw(datum);
- putc(datum, ft->fp);
+ blockputc(ft, datum);
done++;
}
return;
@@ -195,7 +306,7 @@
/* round up to 12 bits of data */
datum += 0x8; /* + 0b1000 */
datum = st_linear_to_Alaw(datum);
- putc(datum, ft->fp);
+ blockputc(ft, datum);
done++;
}
return;
@@ -208,7 +319,7 @@
while(done < nsamp) {
/* scale signed up to long's range */
datum = (int) RIGHT(*buf++, 16);
- wshort(ft, datum);
+ blockwshort(ft, datum);
done++;
}
return;
@@ -218,7 +329,7 @@
datum = (int) RIGHT(*buf++, 16);
/* Convert to unsigned */
datum ^= 0x8000;
- wshort(ft, datum);
+ blockwshort(ft, datum);
done++;
}
return;
@@ -234,7 +345,7 @@
while(done < nsamp) {
/* scale signed up to long's range */
datum = (int) RIGHT(*buf++, 16);
- wfloat(ft, (double) datum);
+ blockwfloat(ft, (double) datum);
done++;
}
return;
@@ -245,6 +356,13 @@
styles[ft->info.style], sizes[ft->info.size]);
}
+void rawstopwrite(ft)
+ft_t ft;
+{
+ blockflush(ft);
+ free(ft->file.buf);
+}
+
/*
* Set parameters to the fixed parameters known for this format,
* and change format to raw format.
@@ -258,6 +376,7 @@
{
ft->info.size = BYTE;
ft->info.style = SIGN2;
+ rawstartread(ft);
rawdefaults(ft);
}
@@ -266,6 +385,7 @@
{
ft->info.size = BYTE;
ft->info.style = SIGN2;
+ rawstartwrite(ft);
rawdefaults(ft);
}
@@ -274,6 +394,7 @@
{
ft->info.size = BYTE;
ft->info.style = UNSIGNED;
+ rawstartread(ft);
rawdefaults(ft);
}
@@ -282,6 +403,7 @@
{
ft->info.size = BYTE;
ft->info.style = UNSIGNED;
+ rawstartwrite(ft);
rawdefaults(ft);
}
@@ -290,6 +412,7 @@
{
ft->info.size = WORD;
ft->info.style = UNSIGNED;
+ rawstartread(ft);
rawdefaults(ft);
}
@@ -298,6 +421,7 @@
{
ft->info.size = WORD;
ft->info.style = UNSIGNED;
+ rawstartwrite(ft);
rawdefaults(ft);
}
@@ -306,6 +430,7 @@
{
ft->info.size = WORD;
ft->info.style = SIGN2;
+ rawstartread(ft);
rawdefaults(ft);
}
@@ -314,6 +439,7 @@
{
ft->info.size = WORD;
ft->info.style = SIGN2;
+ rawstartwrite(ft);
rawdefaults(ft);
}
@@ -322,6 +448,7 @@
{
ft->info.size = BYTE;
ft->info.style = ULAW;
+ rawstartread(ft);
rawdefaults(ft);
}
@@ -330,6 +457,7 @@
{
ft->info.size = BYTE;
ft->info.style = ULAW;
+ rawstartwrite(ft);
rawdefaults(ft);
}
@@ -338,6 +466,7 @@
{
ft->info.size = BYTE;
ft->info.style = ALAW;
+ rawstartread(ft);
rawdefaults(ft);
}
@@ -346,6 +475,7 @@
{
ft->info.size = BYTE;
ft->info.style = ALAW;
+ rawstartwrite(ft);
rawdefaults(ft);
}
--- a/src/sf.c
+++ b/src/sf.c
@@ -143,7 +143,7 @@
SFHEADER sfhead;
SFCODE *sfcodep;
char *sfcharp;
- int littlendian = 0;
+ int littlendian = 1;
char *endptr;
#ifdef IRCAM
--- a/src/smp.c
+++ b/src/smp.c
@@ -76,27 +76,27 @@
{
int i;
- rlshort(ft); /* read reserved word */
+ rshort(ft); /* read reserved word */
for(i = 0; i < 8; i++) { /* read the 8 loops */
- trailer->loops[i].start = rllong(ft);
+ trailer->loops[i].start = rlong(ft);
ft->loops[i].start = trailer->loops[i].start;
- trailer->loops[i].end = rllong(ft);
+ trailer->loops[i].end = rlong(ft);
ft->loops[i].length =
trailer->loops[i].end - trailer->loops[i].start;
trailer->loops[i].type = getc(ft->fp);
ft->loops[i].type = trailer->loops[8].type;
- trailer->loops[i].count = rlshort(ft);
+ trailer->loops[i].count = rshort(ft);
ft->loops[8].count = trailer->loops[8].count;
}
for(i = 0; i < 8; i++) { /* read the 8 markers */
if (fread(trailer->markers[i].name, 1, 10, ft->fp) != 10)
return(0);
- trailer->markers[i].position = rllong(ft);
+ trailer->markers[i].position = rlong(ft);
}
trailer->MIDInote = getc(ft->fp);
- trailer->rate = rllong(ft);
- trailer->SMPTEoffset = rllong(ft);
- trailer->CycleSize = rllong(ft);
+ trailer->rate = rlong(ft);
+ trailer->SMPTEoffset = rlong(ft);
+ trailer->CycleSize = rlong(ft);
return(1);
}
@@ -146,22 +146,22 @@
{
int i;
- wlshort(ft, 0); /* write the reserved word */
+ wshort(ft, 0); /* write the reserved word */
for(i = 0; i < 8; i++) { /* write the 8 loops */
- wllong(ft, trailer->loops[i].start);
- wllong(ft, trailer->loops[i].end);
+ wlong(ft, trailer->loops[i].start);
+ wlong(ft, trailer->loops[i].end);
putc(trailer->loops[i].type, ft->fp);
- wlshort(ft, trailer->loops[i].count);
+ wshort(ft, trailer->loops[i].count);
}
for(i = 0; i < 8; i++) { /* write the 8 markers */
if (fwrite(trailer->markers[i].name, 1, 10, ft->fp) != 10)
return(0);
- wllong(ft, trailer->markers[i].position);
+ wlong(ft, trailer->markers[i].position);
}
putc(trailer->MIDInote, ft->fp);
- wllong(ft, trailer->rate);
- wllong(ft, trailer->SMPTEoffset);
- wllong(ft, trailer->CycleSize);
+ wlong(ft, trailer->rate);
+ wlong(ft, trailer->SMPTEoffset);
+ wlong(ft, trailer->CycleSize);
return(1);
}
@@ -176,13 +176,22 @@
ft_t ft;
{
smp_t smp = (smp_t) ft->priv;
- int littlendian = 0, i;
+ int littlendian = 1;
+ char *endptr;
+ int i;
int namelen, commentlen;
LONG samplestart;
- char *endptr;
struct smpheader header;
struct smptrailer trailer;
+ endptr = (char *) &littlendian;
+ /* SMP is in Little Endian format. Swap whats read in on */
+ /* Big Endian machines. */
+ if (!*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
/* If you need to seek around the input file. */
if (! ft->seekable)
fail("SMP input file must be a file, not a pipe");
@@ -210,7 +219,7 @@
report("SampleVision file name and comments: %s", ft->comment);
/* Extract out the sample size (always intel format) */
- smp->NoOfSamps = rllong(ft);
+ smp->NoOfSamps = rlong(ft);
/* mark the start of the sample data */
samplestart = ftell(ft->fp);
@@ -230,11 +239,6 @@
ft->info.style = SIGN2;
ft->info.channels = 1;
- endptr = (char *) &littlendian;
- *endptr = 1;
- if (littlendian != 1)
- ft->swap = 1;
-
if (verbose) {
fprintf(stderr, "SampleVision trailer:\n");
for(i = 0; i < 8; i++) if (1 || trailer.loops[i].count) {
@@ -308,9 +312,20 @@
void smpstartwrite(ft)
ft_t ft;
{
+ int littlendian = 1;
+ char *endptr;
+
smp_t smp = (smp_t) ft->priv;
struct smpheader header;
+ endptr = (char *) &littlendian;
+ /* SMP is in Little Endian format. Swap whats read in on */
+ /* Big Endian machines. */
+ if (!*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
/* If you have to seek around the output file */
if (! ft->seekable)
fail("Output .smp file must be a file, not a pipe");
@@ -328,7 +343,7 @@
/* Write file header */
if(fwrite(&header, 1, HEADERSIZE, ft->fp) != HEADERSIZE)
fail("SMP: Can't write header completely");
- wllong(ft, 0); /* write as zero length for now, update later */
+ wlong(ft, 0); /* write as zero length for now, update later */
smp->NoOfSamps = 0;
}
@@ -341,7 +356,7 @@
while(len--) {
datum = (int) RIGHT(*buf++, 16);
- wlshort(ft, datum);
+ wshort(ft, datum);
smp->NoOfSamps++;
}
/* If you cannot write out all of the supplied samples, */
@@ -359,5 +374,5 @@
writetrailer(ft, &trailer);
if (fseek(ft->fp, 112, 0) == -1)
fail("SMP unable to seek back to save size");
- wllong(ft, smp->NoOfSamps);
+ wlong(ft, smp->NoOfSamps);
}
--- a/src/sndrtool.c
+++ b/src/sndrtool.c
@@ -31,8 +31,20 @@
LONG rate;
-rate = 0;
+ int littlendian = 1;
+ char *endptr;
+ endptr = (char *) &littlendian;
+ /* sndt is in little endian format so
+ * swap bytes on big endian machines.
+ */
+ if (!*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
+ rate = 0;
+
/* determine file type */
/* if first 5 bytes == SOUND then this is probably a sndtool sound */
/* if first word (16 bits) == 0
@@ -44,7 +56,7 @@
if (strncmp(buf,"\0\0",2) == 0)
{
/* sounder */
- rate = rlshort(ft);
+ rate = rshort(ft);
if (rate < 4000 || rate > 25000 )
fail ("SND: sample rate out of range");
fseek(ft->fp,4,SEEK_CUR);
@@ -56,7 +68,7 @@
if (strncmp(buf,"SOUND",5))
fail ("SND: unrecognized SND format");
fseek(ft->fp,12,SEEK_CUR);
- rate = rlshort(ft);
+ rate = rshort(ft);
fseek(ft->fp,6,SEEK_CUR);
if (fread(buf,1,96,ft->fp) != 96)
fail ("SND: unexpected EOF in SND header");
@@ -78,6 +90,18 @@
{
struct sndpriv *p = (struct sndpriv *) ft->priv;
+ int littlendian = 1;
+ char *endptr;
+
+ endptr = (char *) &littlendian;
+ /* sndt is in little endian format so
+ * swap bytes on big endian machines
+ */
+ if (!*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
/* write header */
ft->info.channels = 1;
ft->info.style = UNSIGNED;
@@ -98,10 +122,10 @@
ft->info.size = BYTE;
/* sounder header */
-wlshort (ft,0); /* sample size code */
-wlshort (ft,(int) ft->info.rate); /* sample rate */
-wlshort (ft,10); /* volume */
-wlshort (ft,4); /* shift */
+wshort (ft,0); /* sample size code */
+wshort (ft,(int) ft->info.rate); /* sample rate */
+wshort (ft,10); /* volume */
+wshort (ft,4); /* shift */
}
/*======================================================================*/
@@ -144,14 +168,14 @@
/* sndtool header */
fputs ("SOUND",ft->fp); /* magic */
fputc (0x1a,ft->fp);
-wlshort (ft,(LONG)0); /* hGSound */
-wllong (ft,nsamples);
-wllong (ft,(LONG)0);
-wllong (ft,nsamples);
-wlshort (ft,(int) ft->info.rate);
-wlshort (ft,0);
-wlshort (ft,10);
-wlshort (ft,4);
+wshort (ft,(LONG)0); /* hGSound */
+wlong (ft,nsamples);
+wlong (ft,(LONG)0);
+wlong (ft,nsamples);
+wshort (ft,(int) ft->info.rate);
+wshort (ft,0);
+wshort (ft,10);
+wshort (ft,4);
sprintf (name_buf,"%s - File created by Sound Exchange",ft->filename);
fwrite (name_buf, 1, 96, ft->fp);
}
--- a/src/st.h
+++ b/src/st.h
@@ -104,6 +104,18 @@
#define LOOP_SUSTAIN_DECAY 64 /* AIFF style: one sustain & one decay loop */
/*
+ * File buffer info. Holds info so that data can be read in blocks.
+ */
+
+struct fileinfo {
+ char *buf; /* Pointer to data buffer */
+ int size; /* Size of buffer */
+ int count; /* Count read in to buffer */
+ int eof; /* Marker that EOF has been reached */
+};
+
+
+/*
* Format information for input and output files.
*/
@@ -121,6 +133,7 @@
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 */
double priv[PRIVSIZE/8]; /* format's private data area */
};
--- a/src/voc.c
+++ b/src/voc.c
@@ -177,7 +177,17 @@
char header[20];
vs_t v = (vs_t) ft->priv;
int sbseek;
+ int littlendian = 1;
+ char *endptr;
+ endptr = (char *) &littlendian;
+ /* VOC is in Little Endian format. Swap bytes read in on */
+ /* Big Endian mahcines. */
+ if (!*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
if (! ft->seekable)
fail("VOC input file must be a file, not a pipe");
if (fread(header, 1, 20, ft->fp) != 20)
@@ -185,7 +195,7 @@
if (strncmp(header, "Creative Voice File\032", 19))
fail("VOC file header incorrect");
- sbseek = rlshort(ft);
+ sbseek = rshort(ft);
fseek(ft->fp, sbseek, 0);
v->rate = -1;
@@ -221,30 +231,28 @@
*buf++ = 0x80000000L;
} else {
for(;v->rest && (done < len); v->rest--, done++) {
- LONG l1, l2;
+ LONG datum;
switch(v->size)
{
case BYTE:
- if ((l1 = getc(ft->fp)) == EOF) {
- fail("VOC input: short file"); /* */
+ if ((datum = getc(ft->fp)) == EOF) {
+ warn("VOC input: short file");
v->rest = 0;
- return 0;
+ return done;
}
- l1 ^= 0x80; /* convert to signed */
- *buf++ = LEFT(l1, 24);
+ datum ^= 0x80; /* convert to signed */
+ *buf++ = LEFT(datum, 24);
break;
case WORD:
- l1 = getc(ft->fp);
- l2 = getc(ft->fp);
- if (l1 == EOF || l2 == EOF)
+ datum = rshort(ft);
+ if (feof(ft->fp))
{
- fail("VOC input: short file");
+ warn("VOC input: short file");
v->rest = 0;
- return 0;
+ return done;
}
- l1 = (l2 << 8) | l1; /* already sign2 */
- *buf++ = LEFT(l1, 16);
- v->rest--;
+ *buf++ = LEFT(datum, 16);
+ v->rest--; /* Processed 2 bytes so update */
break;
}
}
@@ -273,7 +281,17 @@
ft_t ft;
{
vs_t v = (vs_t) ft->priv;
+ int littlendian = 1;
+ char *endptr;
+ endptr = (char *) &littlendian;
+ /* VOC is in Little Endian format. Swap whats read */
+ /* in on Big Endian machines. */
+ if (!*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
if (! ft->seekable)
fail("Output .voc file must be a file, not a pipe");
@@ -281,9 +299,9 @@
/* File format name and a ^Z (aborts printing under DOS) */
(void) fwrite("Creative Voice File\032\032", 1, 20, ft->fp);
- wlshort(ft, 26); /* size of header */
- wlshort(ft, 0x10a); /* major/minor version number */
- wlshort(ft, 0x1129); /* checksum of version number */
+ wshort(ft, 26); /* size of header */
+ wshort(ft, 0x10a); /* major/minor version number */
+ wshort(ft, 0x1129); /* checksum of version number */
if (ft->info.size == BYTE)
ft->info.style = UNSIGNED;
@@ -314,7 +332,7 @@
putc(uc, ft->fp);
} else {
sw = (int) RIGHT(*buf++, 16);
- wlshort(ft,sw);
+ wshort(ft,sw);
}
}
}
@@ -347,6 +365,11 @@
return;
if (feof(ft->fp))
return;
+ /*
+ * Size is an 24-bit value. Currently there is no util
+ * func to read this so do it this cross-platform way
+ *
+ */
uc = getc(ft->fp);
sblen = uc;
uc = getc(ft->fp);
@@ -377,7 +400,7 @@
v->size = BYTE;
return;
case VOC_DATA_16:
- new_rate = rllong(ft);
+ new_rate = rlong(ft);
if (new_rate == 0)
fail("File %s: Sample rate is zero?",ft->filename);
if ((v->rate != -1) && (new_rate != v->rate))
@@ -393,7 +416,7 @@
default: fail("Don't understand size %d", uc);
}
v->channels = getc(ft->fp);
- getc(ft->fp); /* unknown1 */
+ getc(ft->fp); /* unknown */
getc(ft->fp); /* notused */
getc(ft->fp); /* notused */
getc(ft->fp); /* notused */
@@ -408,7 +431,7 @@
{
unsigned short period;
- period = rlshort(ft);
+ period = rshort(ft);
uc = getc(ft->fp);
if (uc == 0)
fail("File %s: Silence sample rate is zero");
@@ -449,7 +472,7 @@
/* value from the extended block and not the */
/* data block. */
v->extended = 1;
- new_rate = rlshort(ft);
+ new_rate = rshort(ft);
if (new_rate == 0)
fail("File %s: Sample rate is zero?");
if ((v->rate != -1) && (new_rate != v->rate))
@@ -505,7 +528,7 @@
putc(0, ft->fp); /* block length = 4 */
putc(0, ft->fp); /* block length = 4 */
v->rate = 65536L - (256000000.0/(2*(float)ft->info.rate));
- wlshort(ft,v->rate); /* Rate code */
+ wshort(ft,v->rate); /* Rate code */
putc(0, ft->fp); /* File is not packed */
putc(1, ft->fp); /* samples are in stereo */
}
@@ -522,7 +545,7 @@
putc(0, ft->fp); /* block length (for now) */
putc(0, ft->fp); /* block length (for now) */
v->rate = ft->info.rate;
- wllong(ft, v->rate); /* Rate code */
+ wlong(ft, v->rate); /* Rate code */
putc(16, ft->fp); /* Sample Size */
putc(ft->info.channels, ft->fp); /* Sample Size */
putc(0, ft->fp); /* Unknown */
@@ -546,10 +569,7 @@
fseek(ft->fp, v->blockseek, 0); /* seek back to block length */
fseek(ft->fp, 1, 1); /* seek forward one */
if (v->silent) {
- datum = (v->samples) & 0xff;
- putc((int)datum, ft->fp); /* low byte of length */
- datum = (v->samples >> 8) & 0xff;
- putc((int)datum, ft->fp); /* high byte of length */
+ wshort(ft, v->samples);
} else {
if (ft->info.size == BYTE) {
if (ft->info.channels > 1) {
--- a/src/wav.c
+++ b/src/wav.c
@@ -453,7 +453,7 @@
ULONG bytespersample; /* bytes per sample (per channel */
endptr = (char *) &littlendian;
- if (!*endptr) ft->swap = 1;
+ if (!*endptr) ft->swap = ft->swap ? 0 : 1;
/* If you need to seek around the input file. */
if (0 && ! ft->seekable)
@@ -462,7 +462,7 @@
if ( fread(magic, 1, 4, ft->fp) != 4 || strncmp("RIFF", magic, 4))
fail("WAVE: RIFF header not found");
- len = rllong(ft);
+ len = rlong(ft);
if ( fread(magic, 1, 4, ft->fp) != 4 || strncmp("WAVE", magic, 4))
fail("WAVE header not found");
@@ -472,7 +472,7 @@
{
if ( fread(magic, 1, 4, ft->fp) != 4 )
fail("WAVE file missing fmt spec");
- len = rllong(ft);
+ len = rlong(ft);
if (strncmp("fmt ", magic, 4) == 0)
break; /* Found the format chunk */
@@ -487,7 +487,7 @@
if ( len < 16 )
fail("WAVE file fmt chunk is too short");
- wav->formatTag = rlshort(ft);
+ wav->formatTag = rshort(ft);
len -= 2;
switch (wav->formatTag)
{
@@ -538,7 +538,7 @@
default: fail("WAV file has unknown format type");
}
- wChannels = rlshort(ft);
+ wChannels = rshort(ft);
len -= 2;
/* User options take precedence */
if (ft->info.channels == -1 || ft->info.channels == wChannels)
@@ -546,7 +546,7 @@
else
warn("User options overriding channels read in .wav header");
- wSamplesPerSecond = rllong(ft);
+ wSamplesPerSecond = rlong(ft);
len -= 4;
if (ft->info.rate == 0 || ft->info.rate == wSamplesPerSecond)
ft->info.rate = wSamplesPerSecond;
@@ -553,12 +553,12 @@
else
warn("User options overriding rate read in .wav header");
- wAvgBytesPerSec = rllong(ft); /* Average bytes/second */
- wav->blockAlign = rlshort(ft); /* Block align */
+ wAvgBytesPerSec = rlong(ft); /* Average bytes/second */
+ wav->blockAlign = rshort(ft); /* Block align */
len -= 6;
/* bits per sample per channel */
- wBitsPerSample = rlshort(ft);
+ wBitsPerSample = rshort(ft);
len -= 2;
/* ADPCM formats have extended fmt chunk. Check for those cases. */
@@ -567,10 +567,10 @@
if (wBitsPerSample != 4)
fail("Can only handle 4-bit MS ADPCM in wav files");
- wExtSize = rlshort(ft);
- wav->samplesPerBlock = rlshort(ft);
+ wExtSize = rshort(ft);
+ wav->samplesPerBlock = rshort(ft);
wav->bytesPerBlock = (wav->samplesPerBlock + 7)/2 * ft->info.channels;
- wNumCoefs = rlshort(ft);
+ wNumCoefs = rshort(ft);
wav->packet = (unsigned char *)malloc(wav->blockAlign);
len -= 6;
@@ -586,8 +586,8 @@
if (wBitsPerSample != 4)
fail("Can only handle 4-bit IMA ADPCM in wav files");
- wExtSize = rlshort(ft);
- wav->samplesPerBlock = rlshort(ft);
+ wExtSize = rshort(ft);
+ wav->samplesPerBlock = rshort(ft);
wav->bytesPerBlock = (wav->samplesPerBlock + 7)/2 * ft->info.channels;
wav->packet = (unsigned char *)malloc(wav->blockAlign);
len -= 4;
@@ -657,7 +657,7 @@
{
if ( fread(magic, 1, 4, ft->fp) != 4 )
fail("WAVE file has missing data chunk");
- len = rllong(ft);
+ len = rlong(ft);
if (strncmp("data", magic, 4) == 0)
break; /* Found the data chunk */
@@ -806,7 +806,7 @@
char *endptr;
endptr = (char *) &littlendian;
- if (!*endptr) ft->swap = 1;
+ if (!*endptr) ft->swap = ft->swap ? 0 : 1;
wav->numSamples = 0;
wav->second_header = 0;
@@ -898,19 +898,19 @@
/* figured out header info, so write it */
fputs("RIFF", ft->fp);
- wllong(ft, data_length + 8+16+12); /* Waveform chunk size: FIXUP(4) */
+ wlong(ft, data_length + 8+16+12); /* Waveform chunk size: FIXUP(4) */
fputs("WAVE", ft->fp);
fputs("fmt ", ft->fp);
- wllong(ft, (LONG)16); /* fmt chunk size */
- wlshort(ft, wFormatTag);
- wlshort(ft, wChannels);
- wllong(ft, wSamplesPerSecond);
- wllong(ft, wAvgBytesPerSec);
- wlshort(ft, wBlockAlign);
- wlshort(ft, wBitsPerSample);
+ wlong(ft, (LONG)16); /* fmt chunk size */
+ wshort(ft, wFormatTag);
+ wshort(ft, wChannels);
+ wlong(ft, wSamplesPerSecond);
+ wlong(ft, wAvgBytesPerSec);
+ wshort(ft, wBlockAlign);
+ wshort(ft, wBitsPerSample);
fputs("data", ft->fp);
- wllong(ft, data_length); /* data chunk size: FIXUP(40) */
+ wlong(ft, data_length); /* data chunk size: FIXUP(40) */
if (!wav->second_header) {
report("Writing Wave file: %s format, %d channel%s, %d samp/sec",
--- a/src/wve.c
+++ b/src/wve.c
@@ -30,8 +30,19 @@
char magic[16];
short version;
+ int littlendian = 1;
+ char *endptr;
- /* Sanity check */
+ endptr = (char *) &littlendian;
+ /* WVE is in big endian format. Swap whats read in
+ * on little endian machines.
+ */
+ if (*endptr)
+ {
+ 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",
@@ -50,12 +61,15 @@
/* Check for what type endian machine its read on */
if (version == PSION_INV_VERSION)
{
- ft->swap = 1;
- report("Found inverted PSION magic word");
+ /* This is probably left over from a time before
+ * testing for endianess was standardized. Leaving since
+ * it doesn't hurt.
+ */
+ ft->swap = ft->swap ? 0 : 1;
+ report("Found inverted PSION magic word. Swapping bytes.");
}
else if (version == PSION_VERSION)
{
- ft->swap = 0;
report("Found PSION magic word");
}
else
@@ -93,6 +107,18 @@
{
struct wvepriv *p = (struct wvepriv *) ft->priv;
+ int littlendian = 1;
+ char *endptr;
+
+ endptr = (char *) &littlendian;
+ /* wve is in big endian format. Swap whats read in
+ * on little endian machines.
+ */
+ if (*endptr)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
+
p->length = 0;
if (p->repeats == 0)
p->repeats = 1;
@@ -147,7 +173,7 @@
fwrite(magic, sizeof(magic), 1, ft->fp);
wshort(ft, version);
- wblong(ft, p->length);
+ wlong(ft, p->length);
wshort(ft, p->padding);
wshort(ft, p->repeats);