ref: e2e7cef191606fc6f69a88d8da4e675a3b30c347
parent: 00c3c905ce9a2768595fdda8be7a493c8fd7475e
author: cbagwell <cbagwell>
date: Mon Sep 26 20:46:18 EDT 2005
Rename internal st_seek to st_seeki so that st_seek can be used for new user interface. Updates to libst.3 to define new user interfaces.
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -81,9 +81,9 @@
st_fail_errno(ft, ST_EHDR, "VHDR chunk has bad size");
return(ST_EOF);
}
- st_seek(ft,12,SEEK_CUR);
+ st_seeki(ft,12,SEEK_CUR);
st_readw(ft, &rate);
- st_seek(ft,1,SEEK_CUR);
+ st_seeki(ft,1,SEEK_CUR);
st_readbuf(ft, buf,1,1);
if (buf[0] != 0)
{
@@ -90,7 +90,7 @@
st_fail_errno(ft, ST_EFMT, "Unsupported data compression");
return(ST_EOF);
}
- st_seek(ft,4,SEEK_CUR);
+ st_seeki(ft,4,SEEK_CUR);
continue;
}
@@ -160,7 +160,7 @@
st_readdw(ft, &chunksize);
if (chunksize & 1)
chunksize++;
- st_seek(ft,chunksize,SEEK_CUR);
+ st_seeki(ft,chunksize,SEEK_CUR);
continue;
}
@@ -343,7 +343,7 @@
st_writeb(ft, '\0');
/* fixup file sizes in header */
- if (st_seek(ft, 0L, 0) != 0)
+ if (st_seeki(ft, 0L, 0) != 0)
{
st_fail_errno(ft,errno,"can't rewind output file to rewrite 8SVX header");
return(ST_EOF);
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -88,7 +88,7 @@
new_offset += (channel_block - alignment);
new_offset += aiff->dataStart;
- ft->st_errno = st_seek(ft, new_offset, SEEK_SET);
+ ft->st_errno = st_seeki(ft, new_offset, SEEK_SET);
if (ft->st_errno == ST_SUCCESS)
aiff->nsamples = ft->length -
@@ -213,7 +213,7 @@
break;
/* else, seek to end of sound and hunt for more */
seekto = st_tell(ft);
- st_seek(ft, chunksize, SEEK_CUR);
+ st_seeki(ft, chunksize, SEEK_CUR);
}
else if (strncmp(buf, "MARK", 4) == 0) {
/* MARK chunk */
@@ -363,7 +363,7 @@
if (ft->seekable)
{
if (seekto > 0)
- st_seek(ft, seekto, SEEK_SET);
+ st_seeki(ft, seekto, SEEK_SET);
else
{
st_fail_errno(ft,ST_EOF,"AIFF: no sound data on input file");
@@ -735,7 +735,7 @@
st_fail_errno(ft,ST_EOF,"Non-seekable file.");
return(ST_EOF);
}
- if (st_seek(ft, 0L, SEEK_SET) != 0)
+ if (st_seeki(ft, 0L, SEEK_SET) != 0)
{
st_fail_errno(ft,errno,"can't rewind output file to rewrite AIFF header");
return(ST_EOF);
--- a/src/au.c
+++ b/src/au.c
@@ -129,7 +129,7 @@
new_offset += (channel_block - alignment);
new_offset += au->dataStart;
- ft->st_errno = st_seek(ft, new_offset, SEEK_SET);
+ ft->st_errno = st_seeki(ft, new_offset, SEEK_SET);
}
return(ft->st_errno);
@@ -374,7 +374,7 @@
/* Attempt to update header */
if (ft->seekable)
{
- if (st_seek(ft, 0L, 0) != 0)
+ if (st_seeki(ft, 0L, 0) != 0)
{
st_fail_errno(ft,errno,"Can't rewind output file to rewrite Sun header.");
return(ST_EOF);
--- a/src/avr.c
+++ b/src/avr.c
@@ -281,11 +281,11 @@
return rc;
/* Fix size */
- st_seek(ft, 26L, SEEK_SET);
+ st_seeki(ft, 26L, SEEK_SET);
st_writedw (ft, size);
/* Fix lend */
- st_seek(ft, 34L, SEEK_SET);
+ st_seeki(ft, 34L, SEEK_SET);
st_writedw (ft, size);
return(ST_SUCCESS);
--- a/src/cvsd.c
+++ b/src/cvsd.c
@@ -536,7 +536,7 @@
sum += *pchs++;
hdr->Crc = sum;
put16(&pch, hdr->Crc);
- if (st_seek(ft, 0, SEEK_SET) < 0)
+ if (st_seeki(ft, 0, SEEK_SET) < 0)
{
st_report("seek failed\n: %s",strerror(errno));
return (ST_EOF);
@@ -653,7 +653,7 @@
st_warn("File not seekable");
return (ST_EOF);
}
- if (st_seek(ft, 0L, 0) != 0)
+ if (st_seeki(ft, 0L, 0) != 0)
{
st_fail_errno(ft,errno,"Can't rewind output file to rewrite DVMS header.");
return(ST_EOF);
--- a/src/maud.c
+++ b/src/maud.c
@@ -206,7 +206,7 @@
st_readdw(ft, &chunksize);
if (chunksize & 1)
chunksize++;
- st_seek(ft, chunksize, SEEK_CUR);
+ st_seeki(ft, chunksize, SEEK_CUR);
continue;
}
@@ -304,7 +304,7 @@
/* All samples are already written out. */
- if (st_seek(ft, 0L, 0) != 0)
+ if (st_seeki(ft, 0L, 0) != 0)
{
st_fail_errno(ft,errno,"can't rewind output file to rewrite MAUD header");
return(ST_EOF);
--- a/src/misc.c
+++ b/src/misc.c
@@ -511,10 +511,12 @@
}
#endif
-/* Sets file offset
- * offset in bytes
+/* Implements traditional fseek() behavior. Meant to abstract out
+ * file operations so that they could one day also work on memory
+ * buffers.
+ * Offset is in bytes as apposed to st_seek() which is in samples.
*/
-int st_seek(ft_t ft, st_size_t offset, int whence)
+int st_seeki(ft_t ft, st_size_t offset, int whence)
{
if( ft->seekable == 0 ){
/*
--- a/src/prc.c
+++ b/src/prc.c
@@ -59,7 +59,7 @@
new_offset += (channel_block - alignment);
new_offset += prc->dataStart;
- return st_seek(ft, new_offset, SEEK_SET);
+ return st_seeki(ft, new_offset, SEEK_SET);
}
int st_prcstartread(ft_t ft)
@@ -187,7 +187,7 @@
return ST_SUCCESS;
}
- if (st_seek(ft, 0L, 0) != 0)
+ if (st_seeki(ft, 0L, 0) != 0)
{
st_fail_errno(ft,errno,"Can't rewind output file to rewrite Psion header.");
return(ST_EOF);
--- a/src/raw.c
+++ b/src/raw.c
@@ -107,7 +107,7 @@
if (alignment != 0)
new_offset += (channel_block - alignment);
- ft->st_errno = st_seek(ft, new_offset, SEEK_SET);
+ ft->st_errno = st_seeki(ft, new_offset, SEEK_SET);
return ft->st_errno;
}
--- a/src/sf.c
+++ b/src/sf.c
@@ -85,7 +85,7 @@
new_offset += (channel_block - alignment);
new_offset += sf->dataStart;
- return st_seek(ft, new_offset, SEEK_SET);
+ return st_seeki(ft, new_offset, SEEK_SET);
}
/*
--- a/src/smp.c
+++ b/src/smp.c
@@ -188,7 +188,7 @@
new_offset += (channel_block - alignment);
new_offset += smp->dataStart;
- ft->st_errno = st_seek(ft, new_offset, SEEK_SET);
+ ft->st_errno = st_seeki(ft, new_offset, SEEK_SET);
if( ft->st_errno == ST_SUCCESS )
smp->NoOfSamps = (ft->length*ft->info.channels) -
@@ -264,7 +264,7 @@
/* seek from the current position (the start of sample data) by */
/* NoOfSamps * 2 */
- if (st_seek(ft, smp->NoOfSamps * 2L, 1) == -1)
+ if (st_seeki(ft, smp->NoOfSamps * 2L, 1) == -1)
{
st_fail_errno(ft,errno,"SMP unable to seek to trailer");
return(ST_EOF);
@@ -276,7 +276,7 @@
}
/* seek back to the beginning of the data */
- if (st_seek(ft, samplestart, 0) == -1)
+ if (st_seeki(ft, samplestart, 0) == -1)
{
st_fail_errno(ft,errno,"SMP unable to seek back to start of sample data");
return(ST_EOF);
@@ -422,7 +422,7 @@
/* Assign the trailer data */
settrailer(ft, &trailer, ft->info.rate);
writetrailer(ft, &trailer);
- if (st_seek(ft, 112, 0) == -1)
+ if (st_seeki(ft, 112, 0) == -1)
{
st_fail_errno(ft,errno,"SMP unable to seek back to save size");
return(ST_EOF);
--- a/src/sndrtool.c
+++ b/src/sndrtool.c
@@ -48,7 +48,7 @@
new_offset += (channel_block - alignment);
new_offset += snd->dataStart;
- return st_seek(ft, new_offset, SEEK_SET);
+ return st_seeki(ft, new_offset, SEEK_SET);
}
/*======================================================================*/
/* SNDSTARTREAD */
@@ -98,7 +98,7 @@
st_fail_errno(ft,ST_EFMT,"SND: sample rate out of range");
return(ST_EOF);
}
- st_seek(ft, 4, SEEK_CUR);
+ st_seeki(ft, 4, SEEK_CUR);
}
else
{
@@ -109,9 +109,9 @@
st_fail_errno(ft,ST_EFMT,"SND: unrecognized SND format");
return(ST_EOF);
}
- st_seek(ft, 12, SEEK_CUR);
+ st_seeki(ft, 12, SEEK_CUR);
st_readw(ft, &rate);
- st_seek(ft, 6, SEEK_CUR);
+ st_seeki(ft, 6, SEEK_CUR);
if (st_reads(ft, buf, 96) == ST_EOF)
{
st_fail_errno(ft,ST_EHDR,"SND: unexpected EOF in SND header");
@@ -222,7 +222,7 @@
return rc;
/* fixup file sizes in header */
- if (st_seek(ft, 0L, 0) != 0){
+ if (st_seeki(ft, 0L, 0) != 0){
st_fail_errno(ft,errno,"can't rewind output file to rewrite SND header");
return ST_EOF;
}
--- a/src/sox.c
+++ b/src/sox.c
@@ -426,12 +426,12 @@
{
if ((file_desc[0]->h->flags & ST_FILE_SEEK) && file_desc[0]->seekable)
{
- if (file_desc[0]->h->seek(file_desc[0],
- st_trim_get_start(&efftab[1])) != ST_EOF)
+ if (st_seek(file_desc[0], st_trim_get_start(&efftab[1]),
+ ST_SEEK_SET) != ST_EOF)
{
/* Assuming a failed seek stayed where it was. If the
* seek worked then reset the start location of
- * trim so that it skips that part.
+ * trim so that it thinks user didn't request a skip.
*/
st_trim_clear_start(&efftab[1]);
}
--- a/src/sphere.c
+++ b/src/sphere.c
@@ -266,7 +266,7 @@
if (rc)
return rc;
- if (st_seek(ft, 0L, 0) != 0)
+ if (st_seeki(ft, 0L, 0) != 0)
{
st_fail_errno(ft,errno,"Could not rewird output file to rewrite sphere header.\n");
return (ST_EOF);
--- a/src/st.h
+++ b/src/st.h
@@ -254,16 +254,19 @@
extern st_effect_t st_effects[]; /* declared in handlers.c */
-extern ft_t st_open_input(const char *path, const st_signalinfo_t *si,
- const char *filetype, const char swap);
+extern ft_t st_open_input(const char *path, const st_signalinfo_t *info,
+ const char *filetype, char swap);
extern ft_t st_open_output(const char *path, const st_signalinfo_t *info,
const st_signalinfo_t *input_info,
const char *comment, const st_loopinfo_t *loops,
const st_instrinfo_t *instr,
- const char *filetype, const char swap);
+ const char *filetype, char swap);
extern st_ssize_t st_read(ft_t ft, st_sample_t *buf, st_ssize_t len);
extern st_ssize_t st_write(ft_t ft, st_sample_t *buf, st_ssize_t len);
extern int st_close(ft_t ft);
+
+#define ST_SEEK_SET 0
+extern int st_seek(ft_t ft, st_size_t offset, int whence);
int st_geteffect_opt(eff_t, int, char **);
int st_geteffect(eff_t, char *);
--- a/src/st_i.h
+++ b/src/st_i.h
@@ -81,7 +81,7 @@
int st_writef(ft_t ft, float f);
int st_readdf(ft_t ft, double *d);
int st_writedf(ft_t ft, double d);
-int st_seek(ft_t ft, st_size_t offset, int whence);
+int st_seeki(ft_t ft, st_size_t offset, int whence);
st_size_t st_filelength(ft_t ft);
int st_flush(ft_t ft);
st_size_t st_tell(ft_t ft);
--- a/src/stio.c
+++ b/src/stio.c
@@ -71,8 +71,8 @@
return ST_SUCCESS;
}
-ft_t st_open_input(const char *path, const st_signalinfo_t *si,
- const char *filetype, const char swap)
+ft_t st_open_input(const char *path, const st_signalinfo_t *info,
+ const char *filetype, char swap)
{
ft_t ft;
@@ -103,7 +103,7 @@
ft->info.size = -1;
ft->info.encoding = -1;
ft->info.channels = -1;
- ft->info = *si;
+ ft->info = *info;
ft->swap = swap;
ft->mode = 'r';
@@ -204,7 +204,7 @@
const st_signalinfo_t *input_info,
const char *comment, const st_loopinfo_t *loops,
const st_instrinfo_t *instr,
- const char *filetype, const char swap)
+ const char *filetype, char swap)
{
ft_t ft;
ft = (ft_t)calloc(sizeof(struct st_soundstream), 1);
@@ -349,4 +349,23 @@
free(ft->comment);
return rc;
+}
+
+int st_seek(ft_t ft, st_size_t offset, int whence)
+{
+ /* One day, ST_SEEK_CUR and ST_SEEK_END should be impelemented */
+ if (whence != ST_SEEK_SET)
+ return ST_EOF;
+ /* FIXME: Should return this */
+/* return ST_EINVAL; */
+
+ /* If file is a seekable file and this handler supports seeking,
+ * the invoke handlers function.
+ */
+ if (ft->seekable && (ft->h->flags & ST_FILE_SEEK))
+ return (*ft->h->seek)(ft, offset);
+ else
+ return ST_EOF;
+ /* FIXME: Should return this */
+/* return ST_EBADF; */
}
--- a/src/tx16w.c
+++ b/src/tx16w.c
@@ -97,7 +97,7 @@
while (st_readb(ft, (unsigned char *)&trash) != ST_EOF)
num_samp_bytes++;
num_samp_bytes -= 32; /* calculate num samples by sub header size */
- st_seek(ft, 0L, 0); /* rewind file */
+ st_seeki(ft, 0L, 0); /* rewind file */
sk->rest = num_samp_bytes; /* set how many sample bytes to read */
/* first 6 bytes are file type ID LM8953 */
--- a/src/voc.c
+++ b/src/voc.c
@@ -797,14 +797,14 @@
st_sample_t datum;
st_writeb(ft, 0); /* End of file block code */
- st_seek(ft, v->blockseek, 0); /* seek back to block length */
- st_seek(ft, 1, 1); /* seek forward one */
+ st_seeki(ft, v->blockseek, 0); /* seek back to block length */
+ st_seeki(ft, 1, 1); /* seek forward one */
if (v->silent) {
st_writew(ft, v->samples);
} else {
if (ft->info.size == ST_SIZE_BYTE) {
if (ft->info.channels > 1) {
- st_seek(ft, 8, 1); /* forward 7 + 1 for new block header */
+ st_seeki(ft, 8, 1); /* forward 7 + 1 for new block header */
}
}
v->samples += 2; /* adjustment: SBDK pp. 3-5 */
--- a/src/wav.c
+++ b/src/wav.c
@@ -417,7 +417,7 @@
break; /* Found the data chunk */
/* skip to next chunk */
- if (st_seek(ft, *len, SEEK_CUR) != ST_SUCCESS)
+ if (st_seeki(ft, *len, SEEK_CUR) != ST_SUCCESS)
{
st_fail_errno(ft,ST_EHDR,
"WAV chunk appears to have invalid size %d.", *len);
@@ -853,7 +853,7 @@
}
/* Skip anything left over from fmt chunk */
- st_seek(ft, len, SEEK_CUR);
+ st_seeki(ft, len, SEEK_CUR);
/* for non-PCM formats, there's a 'fact' chunk before
* the upcoming 'data' chunk */
@@ -946,7 +946,7 @@
* doubt any machine writing Cool Edit Chunks writes them at an odd
* offset */
len = (len + 1) & ~1;
- if (st_seek(ft, len, SEEK_CUR) == ST_SUCCESS &&
+ if (st_seeki(ft, len, SEEK_CUR) == ST_SUCCESS &&
findChunk(ft, "LIST", &len) != ST_EOF)
{
wav->found_cooledit = 1;
@@ -994,7 +994,7 @@
strcat(ft->comment,text);
}
if (strlen(text) < len)
- st_seek(ft, len - strlen(text), SEEK_CUR);
+ st_seeki(ft, len - strlen(text), SEEK_CUR);
}
else if (strncmp(magic,"ISFT",4) == 0)
{
@@ -1013,12 +1013,12 @@
strcat(ft->comment,text);
}
if (strlen(text) < len)
- st_seek(ft, len - strlen(text), SEEK_CUR);
+ st_seeki(ft, len - strlen(text), SEEK_CUR);
}
else if (strncmp(magic,"cue ",4) == 0)
{
st_report("Chunk cue ");
- st_seek(ft,len-4,SEEK_CUR);
+ st_seeki(ft,len-4,SEEK_CUR);
st_readdw(ft,&dwLoopPos);
ft->loops[0].start = dwLoopPos;
}
@@ -1028,19 +1028,19 @@
st_readdw(ft,&dwLoopPos);
ft->loops[0].length = dwLoopPos - ft->loops[0].start;
if (len > 4)
- st_seek(ft, len - 4, SEEK_CUR);
+ st_seeki(ft, len - 4, SEEK_CUR);
}
else
{
st_report("Attempting to seek beyond unsupported chunk '%c%c%c%c' of length %d bytes\n", magic[0], magic[1], magic[2], magic[3], len);
len = (len + 1) & ~1;
- st_seek(ft, len, SEEK_CUR);
+ st_seeki(ft, len, SEEK_CUR);
}
}
}
}
st_clearerr(ft);
- st_seek(ft,wav->dataStart,SEEK_SET);
+ st_seeki(ft,wav->dataStart,SEEK_SET);
}
return ST_SUCCESS;
}
@@ -1675,7 +1675,7 @@
if (!ft->seekable)
return ST_EOF;
- if (st_seek(ft, 0L, SEEK_SET) != 0)
+ if (st_seeki(ft, 0L, SEEK_SET) != 0)
{
st_fail_errno(ft,ST_EOF,"Can't rewind output file to rewrite .wav header.");
return ST_EOF;
@@ -1763,7 +1763,7 @@
new_offset += (channel_block - alignment);
new_offset += wav->dataStart;
- ft->st_errno = st_seek(ft, new_offset, SEEK_SET);
+ ft->st_errno = st_seeki(ft, new_offset, SEEK_SET);
if( ft->st_errno == ST_SUCCESS )
wav->numSamples = ft->length - (new_offset / ft->info.size /
--- a/src/wve.c
+++ b/src/wve.c
@@ -44,7 +44,7 @@
new_offset += (channel_block - alignment);
new_offset += wve->dataStart;
- return st_seek(ft, offset, SEEK_SET);
+ return st_seeki(ft, offset, SEEK_SET);
}
int st_wvestartread(ft_t ft)
@@ -198,7 +198,7 @@
return ST_SUCCESS;
}
- if (st_seek(ft, 0L, 0) != 0)
+ if (st_seeki(ft, 0L, 0) != 0)
{
st_fail_errno(ft,errno,"Can't rewind output file to rewrite Psion header.");
return(ST_EOF);