ref: 2010240ce3c22f65d1379ec785f754253e9759b9
parent: f58321658de6c9a7c69a130b0c99eb1c350b49d2
author: cbagwell <cbagwell>
date: Sun Aug 26 20:40:17 EDT 2001
Fixed bug in reading to small data in st_readbuf.
--- a/Makefile.dos
+++ b/Makefile.dos
@@ -66,13 +66,13 @@
# $(CC) $(CFLAGS) $*.c
# $(LDD) libst -+$*,,
-all: sox.exe mix.exe
+all: sox.exe soxmix.exe
sox.exe: sox.obj libst.lib
$(CC) $(LFLAGS) -L$(LIBDIR) sox.obj libst.lib
-mix.exe: mix.obj libst.lib
- $(CC) $(LFLAGS) -L$(LIBDIR) mix.obj libst.lib
+soxmix.exe: soxmix.obj libst.lib
+ $(CC) $(LFLAGS) -L$(LIBDIR) soxmix.obj libst.lib
libst.lib: $(LIBOBJS)
@@ -79,10 +79,11 @@
sox.obj: sox.c st.h
$(CC) $(CFLAGS) -I$(INCDIR) -L$(LIBDIR) $*.c
-mix.obj: mix.c st.h
- $(CC) $(CFLAGS) -I$(INCDIR) -L$(LIBDIR) $*.c
+soxmix.obj: sox.c st.h
+ $(CC) $(CFLAGS) -DSOXMIX -I$(INCDIR) -L$(LIBDIR) sox.c
clean:
del *.obj
del sox.exe
+ del soxmix.exe
del libst.lib
--- a/Makefile.gcc
+++ b/Makefile.gcc
@@ -192,13 +192,16 @@
CFLAGS = $O $(SOX_DEFINES) $(SOX_INCLUDES)
-all: sox mix
+all: sox soxmix
sox: sox.o $(SOUNDLIB)
$(CC) $(CFLAGS) -o sox sox.o $(SOUNDLIB) $(SOX_PRE_LIBS) $(SOX_POST_LIBS)
-mix: mix.o $(SOUNDLIB)
- $(CC) $(CFLAGS) -o mix mix.o $(SOUNDLIB) $(SOX_PRE_LIBS) $(SOX_POST_LIBS)
+soxmix.o: sox.c
+ $(CC) $(CLAGS) -DSOXMIX -c -o soxmix.o sox.c
+
+soxmix: soxmix.o $(SOUNDLIB)
+ $(CC) $(CFLAGS) -o soxmix soxmix.o $(SOUNDLIB) $(SOX_PRE_LIBS) $(SOX_POST_LIBS)
$(SOUNDLIB): $(LIBOBJS)
$(RM) $(SOUNDLIB)
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -74,7 +74,7 @@
sox: libst.a sox.o
$(CC) $(LDFLAGS) -o sox sox.o $(LIBS)
-soxmix.o:
+soxmix.o: sox.c
$(CC) $(CFLAGS) -DSOXMIX -c -o soxmix.o sox.c
soxmix: libst.a soxmix.o
--- a/src/auto.c
+++ b/src/auto.c
@@ -102,25 +102,17 @@
type = NULL;
}
- if (type == 0)
+ ft->filetype = type;
+ rc = st_gettype(ft); /* Change ft->h to the new format */
+ if(rc != ST_SUCCESS)
{
- st_warn("Could not detect type. Assuming signed 16-bit data using rate of 44100.\n");
- type = "raw";
- ft->info.rate = 44100;
- ft->info.size = ST_SIZE_WORD;
- ft->info.encoding = ST_ENCODING_SIGN2;
+ st_fail_errno(ft,ST_EFMT,"Do not understand format type: %s\n",type);
+ return (rc);
}
- ft->filetype = type;
- rc = st_gettype(ft); /* Change ft->h to the new format */
- if(rc != ST_SUCCESS)
- {
- st_fail_errno(ft,ST_EFMT,"Do not understand format type: %s\n",type);
- return (rc);
- }
- st_report("Detected file format type: %s\n", type);
- return ((* ft->h->startread)(ft));
- }
+ st_report("Detected file format type: %s\n", type);
+ return ((* ft->h->startread)(ft));
+}
int st_autostartwrite(ft)
ft_t ft;
--- a/src/raw.c
+++ b/src/raw.c
@@ -286,6 +286,7 @@
{
ULONG len, done = 0;
void (*copy_buf)(LONG *, char *, ULONG, char) = 0;
+ int i;
switch(size) {
case ST_SIZE_BYTE:
@@ -341,11 +342,13 @@
case ST_SIZE_FLOAT:
copy_buf = st_f32_copy_buf;
+ /* Hack hack... Encoding should be FLOAT, not the size */
size = 4;
break;
case ST_SIZE_DOUBLE:
copy_buf = st_f64_copy_buf;
+ /* Hack hack... Encoding should be FLOAT, not the size */
size = 8;
break;
@@ -365,14 +368,24 @@
while (done < n)
{
- if (!ft->file.eof && ft->file.pos == ft->file.count)
+ /* See if there is not enough data in buffer for any more reads.
+ * If not then shift any remaining data down to the beginning
+ * and attempt to fill up the rest of the buffer.
+ */
+ if (!ft->file.eof && ft->file.pos >= (ft->file.count-size+1))
{
- ft->file.count = fread(ft->file.buf, 1, ft->file.size, ft->fp);
+ for (i = 0; i < (ft->file.count-ft->file.pos); i++)
+ ft->file.buf[i] = ft->file.buf[ft->file.pos+i];
+
+ i = ft->file.count-ft->file.pos;
ft->file.pos = 0;
+
+ ft->file.count = fread(ft->file.buf+i, 1, ft->file.size-i, ft->fp) ;
if (ft->file.count == 0)
{
ft->file.eof = 1;
}
+ ft->file.count += i;
}
len = MIN(n - done,(ft->file.count-ft->file.pos)/size);
--- a/src/sox.c
+++ b/src/sox.c
@@ -351,8 +351,12 @@
ft->filetype = NULL;
}
- if ( st_gettype(ft) )
- st_fail("Unknown output file format for '%s'. Use -t option to override",ft->filename);
+ if (writing)
+ {
+ if ( st_gettype(ft) )
+ st_fail("Unknown output file format for '%s'. Use -t option to override",ft->filename);
+
+ }
}
static void open_output(ft_t ft)
--- a/src/wav.c
+++ b/src/wav.c
@@ -1568,9 +1568,13 @@
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 (ft->st_errno)
- return ST_EOF;
+ /* Flush any remaining data */
+ if (wav->formatTag != WAVE_FORMAT_IMA_ADPCM &&
+ wav->formatTag != WAVE_FORMAT_ADPCM &&
+ wav->formatTag != WAVE_FORMAT_GSM610)
+ {
+ st_rawstopwrite(ft);
+ }
/* All samples are already written out. */
/* If file header needs fixing up, for example it needs the */
@@ -1580,19 +1584,11 @@
if (fseek(ft->fp, 0L, SEEK_SET) != 0)
{
- st_fail_errno(ft,ST_EOF,"Sorry, can't rewind output file to rewrite .wav header.");
+ st_fail_errno(ft,ST_EOF,"Can't rewind output file to rewrite .wav header.");
return ST_EOF;
}
- wavwritehdr(ft, 1);
- if (wav->formatTag != WAVE_FORMAT_IMA_ADPCM &&
- wav->formatTag != WAVE_FORMAT_ADPCM &&
- wav->formatTag != WAVE_FORMAT_GSM610)
- {
- st_rawstopwrite(ft);
- }
-
- return (ST_SUCCESS);
+ return (wavwritehdr(ft, 1));
}
/*