ref: b99e78af51ae0964fdb8f0fc2795c20e2f6c237c
parent: 7cada5204526807c68f740a92d3797763bf66d4f
author: cbagwell <cbagwell>
date: Tue Aug 3 17:14:48 EDT 2004
voc 8-bit format fix. General warning cleanups.
--- a/Changelog
+++ b/Changelog
@@ -37,6 +37,8 @@
Geiger.
o J Robert Ray submitted fix for AIFF handler to ignore lowercase
chunks that are unknown.
+ o Bugfix for 8-bit voc files. Jimen Ching
+ o General warning cleanups (cbagwell)
sox-12.17.4
-----------
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -38,9 +38,8 @@
uint32_t totalsize;
uint32_t chunksize;
- uint32_t channels;
+ uint32_t channels, i;
unsigned short rate;
- int i;
long chan1_pos;
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -389,7 +389,7 @@
}
} else {
if ((ft->info.channels == -1)
- || (ft->info.rate == -1)
+ || (ft->info.rate == 0)
|| (ft->info.encoding == -1)
|| (ft->info.size == -1)) {
st_report("You must specify # channels, sample rate, signed/unsigned,\n");
@@ -583,8 +583,9 @@
aiff_t aiff = (aiff_t ) ft->priv;
st_ssize_t done;
- /* just read what's left of SSND chunk */
- if (len > aiff->nsamples)
+ if (len < 0)
+ return ST_EOF;
+ else if ((st_size_t)len > aiff->nsamples)
len = aiff->nsamples;
done = st_rawread(ft, buf, len);
if (done == 0 && aiff->nsamples != 0)
--- a/src/au.c
+++ b/src/au.c
@@ -28,37 +28,37 @@
#endif
/* Magic numbers used in Sun and NeXT audio files */
-#define SUN_MAGIC 0x2e736e64 /* Really '.snd' */
-#define SUN_INV_MAGIC 0x646e732e /* '.snd' upside-down */
-#define DEC_MAGIC 0x2e736400 /* Really '\0ds.' (for DEC) */
-#define DEC_INV_MAGIC 0x0064732e /* '\0ds.' upside-down */
-#define SUN_HDRSIZE 24 /* Size of minimal header */
-#define SUN_UNSPEC ((unsigned)(~0)) /* Unspecified data size */
-#define SUN_ULAW 1 /* u-law encoding */
-#define SUN_LIN_8 2 /* Linear 8 bits */
-#define SUN_LIN_16 3 /* Linear 16 bits */
-#define SUN_LIN_24 4 /* Linear 24 bits */
-#define SUN_LIN_32 5 /* Linear 32 bits */
-#define SUN_FLOAT 6 /* IEEE FP 32 bits */
-#define SUN_DOUBLE 7 /* IEEE FP 64 bits */
-#define SUN_G721 23 /* CCITT G.721 4-bits ADPCM */
-#define SUN_G723_3 25 /* CCITT G.723 3-bits ADPCM */
-#define SUN_G723_5 26 /* CCITT G.723 5-bits ADPCM */
-#define SUN_ALAW 27 /* a-law encoding */
+#define SUN_MAGIC 0x2e736e64 /* Really '.snd' */
+#define SUN_INV_MAGIC 0x646e732e /* '.snd' upside-down */
+#define DEC_MAGIC 0x2e736400 /* Really '\0ds.' (for DEC) */
+#define DEC_INV_MAGIC 0x0064732e /* '\0ds.' upside-down */
+#define SUN_HDRSIZE 24 /* Size of minimal header */
+#define SUN_UNSPEC ((unsigned)(~0)) /* Unspecified data size */
+#define SUN_ULAW 1 /* u-law encoding */
+#define SUN_LIN_8 2 /* Linear 8 bits */
+#define SUN_LIN_16 3 /* Linear 16 bits */
+#define SUN_LIN_24 4 /* Linear 24 bits */
+#define SUN_LIN_32 5 /* Linear 32 bits */
+#define SUN_FLOAT 6 /* IEEE FP 32 bits */
+#define SUN_DOUBLE 7 /* IEEE FP 64 bits */
+#define SUN_G721 23 /* CCITT G.721 4-bits ADPCM */
+#define SUN_G723_3 25 /* CCITT G.723 3-bits ADPCM */
+#define SUN_G723_5 26 /* CCITT G.723 5-bits ADPCM */
+#define SUN_ALAW 27 /* a-law encoding */
/* The other formats are not supported by sox at the moment */
/* Private data */
typedef struct aupriv {
- /* For writer: size in bytes */
- st_size_t data_size;
- /* For seeking */
- st_size_t dataStart;
- /* For G72x decoding: */
- struct g72x_state state;
- int (*dec_routine)();
- int dec_bits;
- unsigned int in_buffer;
- int in_bits;
+ /* For writer: size in bytes */
+ st_size_t data_size;
+ /* For seeking */
+ st_size_t dataStart;
+ /* For G72x decoding: */
+ struct g72x_state state;
+ int (*dec_routine)();
+ int dec_bits;
+ unsigned int in_buffer;
+ int in_bits;
} *au_t;
static void auwriteheader(ft_t ft, st_size_t data_size);
@@ -72,8 +72,8 @@
break;
case SUN_ALAW:
*encoding = ST_ENCODING_ALAW;
- *size = ST_SIZE_BYTE;
- break;
+ *size = ST_SIZE_BYTE;
+ break;
case SUN_LIN_8:
*encoding = ST_ENCODING_SIGN2;
*size = ST_SIZE_BYTE;
@@ -103,157 +103,157 @@
int st_auseek(ft_t ft, st_size_t offset)
{
- au_t au = (au_t ) ft->priv;
+ au_t au = (au_t ) ft->priv;
- if (au->dec_routine != NULL)
- st_fail_errno(ft,ST_ENOTSUP,"Sorry, DEC unsupported");
- else
- return st_seek(ft,offset*ft->info.size + au->dataStart,SEEK_SET);
+ if (au->dec_routine != NULL)
+ st_fail_errno(ft,ST_ENOTSUP,"Sorry, DEC unsupported");
+ else
+ return st_seek(ft,offset*ft->info.size + au->dataStart,SEEK_SET);
- return(ft->st_errno);
+ return(ft->st_errno);
}
int st_austartread(ft_t ft)
{
- /* The following 6 variables represent a Sun sound header on disk.
- The numbers are written as big-endians.
- Any extra bytes (totalling hdr_size - 24) are an
- "info" field of unspecified nature, usually a string.
- By convention the header size is a multiple of 4. */
- uint32_t magic;
- uint32_t hdr_size;
- uint32_t data_size;
- uint32_t encoding;
- uint32_t sample_rate;
- uint32_t channels;
+ /* The following 6 variables represent a Sun sound header on disk.
+ The numbers are written as big-endians.
+ Any extra bytes (totalling hdr_size - 24) are an
+ "info" field of unspecified nature, usually a string.
+ By convention the header size is a multiple of 4. */
+ uint32_t magic;
+ uint32_t hdr_size;
+ uint32_t data_size;
+ uint32_t encoding;
+ uint32_t sample_rate;
+ uint32_t channels;
- register int i;
- char *buf;
- au_t p = (au_t ) ft->priv;
+ unsigned int i;
+ char *buf;
+ au_t p = (au_t ) ft->priv;
- int rc;
+ int rc;
- /* AU is in big endian format. Swap whats read
- * in onlittle endian machines.
- */
- if (ST_IS_LITTLEENDIAN)
- {
- ft->swap = ft->swap ? 0 : 1;
- }
+ /* AU is in big endian format. Swap whats read
+ * in onlittle endian machines.
+ */
+ if (ST_IS_LITTLEENDIAN)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
- /* Check the magic word */
- st_readdw(ft, &magic);
- if (magic == DEC_INV_MAGIC) {
- /* 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;
- st_report("Found inverted DEC magic word. Swapping bytes.");
- }
- else if (magic == SUN_INV_MAGIC) {
- ft->swap = ft->swap ? 0 : 1;
- st_report("Found inverted Sun/NeXT magic word. Swapping bytes.");
- }
- else if (magic == SUN_MAGIC) {
- st_report("Found Sun/NeXT magic word");
- }
- else if (magic == DEC_MAGIC) {
- st_report("Found DEC magic word");
- }
- else
- {
- st_fail_errno(ft,ST_EHDR,"Did not detect valid Sun/NeXT/DEC magic number in header.");
- return(ST_EOF);
- }
+ /* Check the magic word */
+ st_readdw(ft, &magic);
+ if (magic == DEC_INV_MAGIC) {
+ /* 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;
+ st_report("Found inverted DEC magic word. Swapping bytes.");
+ }
+ else if (magic == SUN_INV_MAGIC) {
+ ft->swap = ft->swap ? 0 : 1;
+ st_report("Found inverted Sun/NeXT magic word. Swapping bytes.");
+ }
+ else if (magic == SUN_MAGIC) {
+ st_report("Found Sun/NeXT magic word");
+ }
+ else if (magic == DEC_MAGIC) {
+ st_report("Found DEC magic word");
+ }
+ else
+ {
+ st_fail_errno(ft,ST_EHDR,"Did not detect valid Sun/NeXT/DEC magic number in header.");
+ return(ST_EOF);
+ }
- /* Read the header size */
- st_readdw(ft, &hdr_size);
- if (hdr_size < SUN_HDRSIZE)
- {
- st_fail_errno(ft,ST_EHDR,"Sun/NeXT header size too small.");
- return(ST_EOF);
- }
+ /* Read the header size */
+ st_readdw(ft, &hdr_size);
+ if (hdr_size < SUN_HDRSIZE)
+ {
+ st_fail_errno(ft,ST_EHDR,"Sun/NeXT header size too small.");
+ return(ST_EOF);
+ }
- /* Read the data size; may be ~0 meaning unspecified */
- st_readdw(ft, &data_size);
+ /* Read the data size; may be ~0 meaning unspecified */
+ st_readdw(ft, &data_size);
- /* Read the encoding; there are some more possibilities */
- st_readdw(ft, &encoding);
+ /* Read the encoding; there are some more possibilities */
+ st_readdw(ft, &encoding);
- /* Translate the encoding into encoding and size parameters */
- /* (Or, for G.72x, set the decoding routine and parameters) */
- p->dec_routine = NULL;
- p->in_buffer = 0;
- p->in_bits = 0;
+ /* Translate the encoding into encoding and size parameters */
+ /* (Or, for G.72x, set the decoding routine and parameters) */
+ p->dec_routine = NULL;
+ p->in_buffer = 0;
+ p->in_bits = 0;
if(st_auencodingandsize(encoding, &(ft->info.encoding),
- &(ft->info.size)) == ST_EOF)
- {
+ &(ft->info.size)) == ST_EOF)
+ {
st_fail_errno(ft,ST_EFMT,"Unsupported encoding in Sun/NeXT header.\nOnly U-law, signed bytes, signed words, and ADPCM are supported.");
return(ST_EOF);
- }
- switch (encoding) {
- case SUN_G721:
- g72x_init_state(&p->state);
- p->dec_routine = g721_decoder;
- p->dec_bits = 4;
- break;
- case SUN_G723_3:
- g72x_init_state(&p->state);
- p->dec_routine = g723_24_decoder;
- p->dec_bits = 3;
- break;
- case SUN_G723_5:
- g72x_init_state(&p->state);
- p->dec_routine = g723_40_decoder;
- p->dec_bits = 5;
- break;
- }
+ }
+ switch (encoding) {
+ case SUN_G721:
+ g72x_init_state(&p->state);
+ p->dec_routine = g721_decoder;
+ p->dec_bits = 4;
+ break;
+ case SUN_G723_3:
+ g72x_init_state(&p->state);
+ p->dec_routine = g723_24_decoder;
+ p->dec_bits = 3;
+ break;
+ case SUN_G723_5:
+ g72x_init_state(&p->state);
+ p->dec_routine = g723_40_decoder;
+ p->dec_bits = 5;
+ break;
+ }
- /* Read the sampling rate */
- st_readdw(ft, &sample_rate);
- ft->info.rate = sample_rate;
+ /* Read the sampling rate */
+ st_readdw(ft, &sample_rate);
+ ft->info.rate = sample_rate;
- /* Read the number of channels */
- st_readdw(ft, &channels);
- ft->info.channels = (int) channels;
+ /* Read the number of channels */
+ st_readdw(ft, &channels);
+ ft->info.channels = (int) channels;
- /* Skip the info string in header; print it if verbose */
- hdr_size -= SUN_HDRSIZE; /* #bytes already read */
- if (hdr_size > 0) {
+ /* Skip the info string in header; print it if verbose */
+ hdr_size -= SUN_HDRSIZE; /* #bytes already read */
+ if (hdr_size > 0) {
/* Allocate comment buffer */
- buf = (char *) malloc(hdr_size+1);
- for(i = 0; i < hdr_size; i++) {
- st_readb(ft, (unsigned char *)&(buf[i]));
- if (feof(ft->fp))
- {
- st_fail_errno(ft,ST_EOF,"Unexpected EOF in Sun/NeXT header info.");
- return(ST_EOF);
- }
- }
- /* Buffer should already be null terminated but
- * just in case we malloced an extra byte and
- * force the last byte to be 0 anyways.
- * This should help work with a greater array of
- * software.
- */
- buf[hdr_size] = '\0';
+ buf = (char *) malloc(hdr_size+1);
+ for(i = 0; i < hdr_size; i++) {
+ st_readb(ft, (unsigned char *)&(buf[i]));
+ if (feof(ft->fp))
+ {
+ st_fail_errno(ft,ST_EOF,"Unexpected EOF in Sun/NeXT header info.");
+ return(ST_EOF);
+ }
+ }
+ /* Buffer should already be null terminated but
+ * just in case we malloced an extra byte and
+ * force the last byte to be 0 anyways.
+ * This should help work with a greater array of
+ * software.
+ */
+ buf[hdr_size] = '\0';
- ft->comment = buf;
- st_report("Input file %s: Sun header info: %s", ft->filename, buf);
- }
- /* Needed for seeking */
- ft->length = data_size/ft->info.size;
- if(ft->seekable)
- p->dataStart = ftell(ft->fp);
+ ft->comment = buf;
+ st_report("Input file %s: Sun header info: %s", ft->filename, buf);
+ }
+ /* Needed for seeking */
+ ft->length = data_size/ft->info.size;
+ if(ft->seekable)
+ p->dataStart = ftell(ft->fp);
- /* Needed for rawread() */
- rc = st_rawstartread(ft);
- if (rc)
- return rc;
+ /* Needed for rawread() */
+ rc = st_rawstartread(ft);
+ if (rc)
+ return rc;
- return(ST_SUCCESS);
+ return(ST_SUCCESS);
}
/* When writing, the header is supposed to contain the number of
@@ -267,25 +267,25 @@
int st_austartwrite(ft_t ft)
{
- au_t p = (au_t ) ft->priv;
- int rc;
+ au_t p = (au_t ) ft->priv;
+ int rc;
- /* Needed because of rawwrite(); */
- rc = st_rawstartwrite(ft);
- if (rc)
- return rc;
+ /* Needed because of rawwrite(); */
+ rc = st_rawstartwrite(ft);
+ if (rc)
+ return rc;
- /* AU is in big endian format. Swap whats read in
- * on little endian machines.
- */
- if (ST_IS_LITTLEENDIAN)
- {
- ft->swap = ft->swap ? 0 : 1;
- }
+ /* AU is in big endian format. Swap whats read in
+ * on little endian machines.
+ */
+ if (ST_IS_LITTLEENDIAN)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
- p->data_size = 0;
- auwriteheader(ft, SUN_UNSPEC);
- return(ST_SUCCESS);
+ p->data_size = 0;
+ auwriteheader(ft, SUN_UNSPEC);
+ return(ST_SUCCESS);
}
/*
@@ -295,146 +295,146 @@
*/
static int unpack_input(ft_t ft, unsigned char *code)
{
- au_t p = (au_t ) ft->priv;
- unsigned char in_byte;
+ au_t p = (au_t ) ft->priv;
+ unsigned char in_byte;
- if (p->in_bits < p->dec_bits) {
- if (st_readb(ft, &in_byte) == ST_EOF) {
- *code = 0;
- return (-1);
- }
- p->in_buffer |= (in_byte << p->in_bits);
- p->in_bits += 8;
- }
- *code = p->in_buffer & ((1 << p->dec_bits) - 1);
- p->in_buffer >>= p->dec_bits;
- p->in_bits -= p->dec_bits;
- return (p->in_bits > 0);
-}
+ if (p->in_bits < p->dec_bits) {
+ if (st_readb(ft, &in_byte) == ST_EOF) {
+ *code = 0;
+ return (-1);
+ }
+ p->in_buffer |= (in_byte << p->in_bits);
+ p->in_bits += 8;
+ }
+ *code = p->in_buffer & ((1 << p->dec_bits) - 1);
+ p->in_buffer >>= p->dec_bits;
+ p->in_bits -= p->dec_bits;
+ return (p->in_bits > 0);
+}
st_ssize_t st_auread(ft_t ft, st_sample_t *buf, st_ssize_t samp)
{
- au_t p = (au_t ) ft->priv;
- unsigned char code;
- int done;
- if (p->dec_routine == NULL)
- return st_rawread(ft, buf, samp);
- done = 0;
- while (samp > 0 && unpack_input(ft, &code) >= 0) {
- *buf++ = ST_SIGNED_WORD_TO_SAMPLE(
- (*p->dec_routine)(code, AUDIO_ENCODING_LINEAR,
- &p->state));
- samp--;
- done++;
- }
- return done;
+ au_t p = (au_t ) ft->priv;
+ unsigned char code;
+ int done;
+ if (p->dec_routine == NULL)
+ return st_rawread(ft, buf, samp);
+ done = 0;
+ while (samp > 0 && unpack_input(ft, &code) >= 0) {
+ *buf++ = ST_SIGNED_WORD_TO_SAMPLE(
+ (*p->dec_routine)(code, AUDIO_ENCODING_LINEAR,
+ &p->state));
+ samp--;
+ done++;
+ }
+ return done;
}
st_ssize_t st_auwrite(ft_t ft, st_sample_t *buf, st_ssize_t samp)
{
- au_t p = (au_t ) ft->priv;
- p->data_size += samp * ft->info.size;
- return(st_rawwrite(ft, buf, samp));
+ au_t p = (au_t ) ft->priv;
+ p->data_size += samp * ft->info.size;
+ return(st_rawwrite(ft, buf, samp));
}
int st_austopwrite(ft_t ft)
{
- au_t p = (au_t ) ft->priv;
- int rc;
+ au_t p = (au_t ) ft->priv;
+ int rc;
- /* Needed because of rawwrite(). Do now to flush
- * data before seeking around below.
- */
- rc = st_rawstopwrite(ft);
- if (rc)
- return rc;
+ /* Needed because of rawwrite(). Do now to flush
+ * data before seeking around below.
+ */
+ rc = st_rawstopwrite(ft);
+ if (rc)
+ return rc;
- /* Attempt to update header */
- if (ft->seekable)
- {
- if (fseek(ft->fp, 0L, 0) != 0)
- {
- st_fail_errno(ft,errno,"Can't rewind output file to rewrite Sun header.");
- return(ST_EOF);
- }
- auwriteheader(ft, p->data_size);
- }
- return(ST_SUCCESS);
+ /* Attempt to update header */
+ if (ft->seekable)
+ {
+ if (fseek(ft->fp, 0L, 0) != 0)
+ {
+ st_fail_errno(ft,errno,"Can't rewind output file to rewrite Sun header.");
+ return(ST_EOF);
+ }
+ auwriteheader(ft, p->data_size);
+ }
+ return(ST_SUCCESS);
}
static int st_ausunencoding(int size, int encoding)
{
- int sun_encoding;
+ int sun_encoding;
- if (encoding == ST_ENCODING_ULAW && size == ST_SIZE_BYTE)
- sun_encoding = SUN_ULAW;
- else if (encoding == ST_ENCODING_ALAW && size == ST_SIZE_BYTE)
- sun_encoding = SUN_ALAW;
- else if (encoding == ST_ENCODING_SIGN2 && size == ST_SIZE_BYTE)
- sun_encoding = SUN_LIN_8;
- else if (encoding == ST_ENCODING_SIGN2 && size == ST_SIZE_WORD)
- sun_encoding = SUN_LIN_16;
- else
- sun_encoding = -1;
- return sun_encoding;
+ if (encoding == ST_ENCODING_ULAW && size == ST_SIZE_BYTE)
+ sun_encoding = SUN_ULAW;
+ else if (encoding == ST_ENCODING_ALAW && size == ST_SIZE_BYTE)
+ sun_encoding = SUN_ALAW;
+ else if (encoding == ST_ENCODING_SIGN2 && size == ST_SIZE_BYTE)
+ sun_encoding = SUN_LIN_8;
+ else if (encoding == ST_ENCODING_SIGN2 && size == ST_SIZE_WORD)
+ sun_encoding = SUN_LIN_16;
+ else
+ sun_encoding = -1;
+ return sun_encoding;
}
static void auwriteheader(ft_t ft, st_size_t data_size)
{
- uint32_t magic;
- uint32_t hdr_size;
- uint32_t encoding;
- uint32_t sample_rate;
- uint32_t channels;
- int x;
- int comment_size;
+ uint32_t magic;
+ uint32_t hdr_size;
+ int encoding;
+ uint32_t sample_rate;
+ uint32_t channels;
+ int x;
+ int comment_size;
- if((encoding = st_ausunencoding(ft->info.size, ft->info.encoding)) == -1) {
- st_report("Unsupported output encoding/size for Sun/NeXT header or .AU format not specified.");
- st_report("Only U-law, A-law signed bytes, and signed words are supported.");
- st_report("Defaulting to 8khz u-law\n");
- encoding = SUN_ULAW;
- ft->info.encoding = ST_ENCODING_ULAW;
- ft->info.size = ST_SIZE_BYTE;
- ft->info.rate = 8000; /* strange but true */
- }
+ if ((encoding = st_ausunencoding(ft->info.size, ft->info.encoding)) == -1) {
+ st_report("Unsupported output encoding/size for Sun/NeXT header or .AU format not specified.");
+ st_report("Only U-law, A-law signed bytes, and signed words are supported.");
+ st_report("Defaulting to 8khz u-law\n");
+ encoding = SUN_ULAW;
+ ft->info.encoding = ST_ENCODING_ULAW;
+ ft->info.size = ST_SIZE_BYTE;
+ ft->info.rate = 8000; /* strange but true */
+ }
- magic = SUN_MAGIC;
- st_writedw(ft, magic);
+ magic = SUN_MAGIC;
+ st_writedw(ft, magic);
- /* Info field is at least 4 bytes. Here I force it to something
- * useful when there is no comments.
- */
- if (ft->comment == NULL)
- ft->comment = "SOX";
+ /* Info field is at least 4 bytes. Here I force it to something
+ * useful when there is no comments.
+ */
+ if (ft->comment == NULL)
+ ft->comment = "SOX";
- hdr_size = SUN_HDRSIZE;
+ hdr_size = SUN_HDRSIZE;
- comment_size = strlen(ft->comment) + 1; /*+1 = null-term. */
- if (comment_size < 4)
- comment_size = 4; /* minimum size */
+ comment_size = strlen(ft->comment) + 1; /*+1 = null-term. */
+ if (comment_size < 4)
+ comment_size = 4; /* minimum size */
- hdr_size += comment_size;
+ hdr_size += comment_size;
- st_writedw(ft, hdr_size);
+ st_writedw(ft, hdr_size);
- st_writedw(ft, data_size);
+ st_writedw(ft, data_size);
- st_writedw(ft, encoding);
+ st_writedw(ft, encoding);
- sample_rate = ft->info.rate;
- st_writedw(ft, sample_rate);
+ sample_rate = ft->info.rate;
+ st_writedw(ft, sample_rate);
- channels = ft->info.channels;
- st_writedw(ft, channels);
+ channels = ft->info.channels;
+ st_writedw(ft, channels);
- st_writes(ft, ft->comment);
+ st_writes(ft, ft->comment);
- /* Info must be 4 bytes at least and null terminated. */
- x = strlen(ft->comment);
- for (;x < 3; x++)
- st_writeb(ft, 0);
+ /* Info must be 4 bytes at least and null terminated. */
+ x = strlen(ft->comment);
+ for (;x < 3; x++)
+ st_writeb(ft, 0);
- st_writeb(ft, 0);
+ st_writeb(ft, 0);
}
--- a/src/avg.c
+++ b/src/avg.c
@@ -489,7 +489,7 @@
st_size_t *isamp, st_size_t *osamp)
{
avg_t avg = (avg_t) effp->priv;
- int len, done;
+ st_size_t len, done;
int ichan, ochan;
int i, j;
double samp;
--- a/src/chorus.c
+++ b/src/chorus.c
@@ -8,7 +8,7 @@
*/
/*
- * Chorus effect.
+ * Chorus effect.
*
* Flow diagram scheme for n delays ( 1 <= n <= MAX_CHORUS ):
*
@@ -67,24 +67,24 @@
#include <string.h>
#include "st_i.h"
-#define MOD_SINE 0
-#define MOD_TRIANGLE 1
-#define MAX_CHORUS 7
+#define MOD_SINE 0
+#define MOD_TRIANGLE 1
+#define MAX_CHORUS 7
/* Private data for SKEL file */
typedef struct chorusstuff {
- int num_chorus;
- int modulation[MAX_CHORUS];
- int counter;
- long phase[MAX_CHORUS];
- float *chorusbuf;
- float in_gain, out_gain;
- float delay[MAX_CHORUS], decay[MAX_CHORUS];
- float speed[MAX_CHORUS], depth[MAX_CHORUS];
- long length[MAX_CHORUS];
- int *lookup_tab[MAX_CHORUS];
- int depth_samples[MAX_CHORUS], samples[MAX_CHORUS];
- int maxsamples, fade_out;
+ int num_chorus;
+ int modulation[MAX_CHORUS];
+ int counter;
+ long phase[MAX_CHORUS];
+ float *chorusbuf;
+ float in_gain, out_gain;
+ float delay[MAX_CHORUS], decay[MAX_CHORUS];
+ float speed[MAX_CHORUS], depth[MAX_CHORUS];
+ long length[MAX_CHORUS];
+ int *lookup_tab[MAX_CHORUS];
+ int depth_samples[MAX_CHORUS], samples[MAX_CHORUS];
+ int maxsamples, fade_out;
} *chorus_t;
/*
@@ -92,44 +92,44 @@
*/
int st_chorus_getopts(eff_t effp, int n, char **argv)
{
- chorus_t chorus = (chorus_t) effp->priv;
- int i;
+ chorus_t chorus = (chorus_t) effp->priv;
+ int i;
- chorus->num_chorus = 0;
- i = 0;
+ chorus->num_chorus = 0;
+ i = 0;
- if ( ( n < 7 ) || (( n - 2 ) % 5 ) )
- {
- st_fail("Usage: chorus gain-in gain-out delay decay speed depth [ -s | -t ]");
- return (ST_EOF);
- }
+ if ( ( n < 7 ) || (( n - 2 ) % 5 ) )
+ {
+ st_fail("Usage: chorus gain-in gain-out delay decay speed depth [ -s | -t ]");
+ return (ST_EOF);
+ }
- sscanf(argv[i++], "%f", &chorus->in_gain);
- sscanf(argv[i++], "%f", &chorus->out_gain);
- while ( i < n ) {
- if ( chorus->num_chorus > MAX_CHORUS )
- {
- st_fail("chorus: to many delays, use less than %i delays", MAX_CHORUS);
- return (ST_EOF);
- }
- sscanf(argv[i++], "%f", &chorus->delay[chorus->num_chorus]);
- sscanf(argv[i++], "%f", &chorus->decay[chorus->num_chorus]);
- sscanf(argv[i++], "%f", &chorus->speed[chorus->num_chorus]);
- sscanf(argv[i++], "%f", &chorus->depth[chorus->num_chorus]);
- if ( !strcmp(argv[i], "-s"))
- chorus->modulation[chorus->num_chorus] = MOD_SINE;
- else if ( ! strcmp(argv[i], "-t"))
- chorus->modulation[chorus->num_chorus] = MOD_TRIANGLE;
- else
- {
- st_fail("Usage: chorus gain-in gain-out delay decay speed [ -s | -t ]");
- return (ST_EOF);
- }
- i++;
- chorus->num_chorus++;
- }
- return (ST_SUCCESS);
-}
+ sscanf(argv[i++], "%f", &chorus->in_gain);
+ sscanf(argv[i++], "%f", &chorus->out_gain);
+ while ( i < n ) {
+ if ( chorus->num_chorus > MAX_CHORUS )
+ {
+ st_fail("chorus: to many delays, use less than %i delays", MAX_CHORUS);
+ return (ST_EOF);
+ }
+ sscanf(argv[i++], "%f", &chorus->delay[chorus->num_chorus]);
+ sscanf(argv[i++], "%f", &chorus->decay[chorus->num_chorus]);
+ sscanf(argv[i++], "%f", &chorus->speed[chorus->num_chorus]);
+ sscanf(argv[i++], "%f", &chorus->depth[chorus->num_chorus]);
+ if ( !strcmp(argv[i], "-s"))
+ chorus->modulation[chorus->num_chorus] = MOD_SINE;
+ else if ( ! strcmp(argv[i], "-t"))
+ chorus->modulation[chorus->num_chorus] = MOD_TRIANGLE;
+ else
+ {
+ st_fail("Usage: chorus gain-in gain-out delay decay speed [ -s | -t ]");
+ return (ST_EOF);
+ }
+ i++;
+ chorus->num_chorus++;
+ }
+ return (ST_SUCCESS);
+}
/*
* Prepare for processing.
@@ -136,116 +136,116 @@
*/
int st_chorus_start(eff_t effp)
{
- chorus_t chorus = (chorus_t) effp->priv;
- int i;
- float sum_in_volume;
+ chorus_t chorus = (chorus_t) effp->priv;
+ int i;
+ float sum_in_volume;
- chorus->maxsamples = 0;
+ chorus->maxsamples = 0;
- if ( chorus->in_gain < 0.0 )
- {
- st_fail("chorus: gain-in must be positive!\n");
- return (ST_EOF);
- }
- if ( chorus->in_gain > 1.0 )
- {
- st_fail("chorus: gain-in must be less than 1.0!\n");
- return (ST_EOF);
- }
- if ( chorus->out_gain < 0.0 )
- {
- st_fail("chorus: gain-out must be positive!\n");
- return (ST_EOF);
- }
- for ( i = 0; i < chorus->num_chorus; i++ ) {
- chorus->samples[i] = (int) ( ( chorus->delay[i] +
- chorus->depth[i] ) * effp->ininfo.rate / 1000.0);
- chorus->depth_samples[i] = (int) (chorus->depth[i] *
- effp->ininfo.rate / 1000.0);
+ if ( chorus->in_gain < 0.0 )
+ {
+ st_fail("chorus: gain-in must be positive!\n");
+ return (ST_EOF);
+ }
+ if ( chorus->in_gain > 1.0 )
+ {
+ st_fail("chorus: gain-in must be less than 1.0!\n");
+ return (ST_EOF);
+ }
+ if ( chorus->out_gain < 0.0 )
+ {
+ st_fail("chorus: gain-out must be positive!\n");
+ return (ST_EOF);
+ }
+ for ( i = 0; i < chorus->num_chorus; i++ ) {
+ chorus->samples[i] = (int) ( ( chorus->delay[i] +
+ chorus->depth[i] ) * effp->ininfo.rate / 1000.0);
+ chorus->depth_samples[i] = (int) (chorus->depth[i] *
+ effp->ininfo.rate / 1000.0);
- if ( chorus->delay[i] < 20.0 )
- {
- st_fail("chorus: delay must be more than 20.0 msec!\n");
- return (ST_EOF);
- }
- if ( chorus->delay[i] > 100.0 )
- {
- st_fail("chorus: delay must be less than 100.0 msec!\n");
- return (ST_EOF);
- }
- if ( chorus->speed[i] < 0.1 )
- {
- st_fail("chorus: speed must be more than 0.1 Hz!\n");
- return (ST_EOF);
- }
- if ( chorus->speed[i] > 5.0 )
- {
- st_fail("chorus: speed must be less than 5.0 Hz!\n");
- return (ST_EOF);
- }
- if ( chorus->depth[i] < 0.0 )
- {
- st_fail("chorus: delay must be more positive!\n");
- return (ST_EOF);
- }
- if ( chorus->depth[i] > 10.0 )
- {
- st_fail("chorus: delay must be less than 10.0 msec!\n");
- return (ST_EOF);
- }
- if ( chorus->decay[i] < 0.0 )
- {
- st_fail("chorus: decay must be positive!\n" );
- return (ST_EOF);
- }
- if ( chorus->decay[i] > 1.0 )
- {
- st_fail("chorus: decay must be less that 1.0!\n" );
- return (ST_EOF);
- }
- chorus->length[i] = effp->ininfo.rate / chorus->speed[i];
- if (! (chorus->lookup_tab[i] =
- (int *) malloc(sizeof (int) * chorus->length[i])))
- {
- st_fail("chorus: Cannot malloc %d bytes!\n",
- sizeof(int) * chorus->length[i]);
- return (ST_EOF);
- }
- if ( chorus->modulation[i] == MOD_SINE )
- st_sine(chorus->lookup_tab[i], chorus->length[i],
- chorus->depth_samples[i] - 1,
- chorus->depth_samples[i]);
- else
- st_triangle(chorus->lookup_tab[i], chorus->length[i],
- chorus->samples[i] - 1,
- chorus->depth_samples[i]);
- chorus->phase[i] = 0;
+ if ( chorus->delay[i] < 20.0 )
+ {
+ st_fail("chorus: delay must be more than 20.0 msec!\n");
+ return (ST_EOF);
+ }
+ if ( chorus->delay[i] > 100.0 )
+ {
+ st_fail("chorus: delay must be less than 100.0 msec!\n");
+ return (ST_EOF);
+ }
+ if ( chorus->speed[i] < 0.1 )
+ {
+ st_fail("chorus: speed must be more than 0.1 Hz!\n");
+ return (ST_EOF);
+ }
+ if ( chorus->speed[i] > 5.0 )
+ {
+ st_fail("chorus: speed must be less than 5.0 Hz!\n");
+ return (ST_EOF);
+ }
+ if ( chorus->depth[i] < 0.0 )
+ {
+ st_fail("chorus: delay must be more positive!\n");
+ return (ST_EOF);
+ }
+ if ( chorus->depth[i] > 10.0 )
+ {
+ st_fail("chorus: delay must be less than 10.0 msec!\n");
+ return (ST_EOF);
+ }
+ if ( chorus->decay[i] < 0.0 )
+ {
+ st_fail("chorus: decay must be positive!\n" );
+ return (ST_EOF);
+ }
+ if ( chorus->decay[i] > 1.0 )
+ {
+ st_fail("chorus: decay must be less that 1.0!\n" );
+ return (ST_EOF);
+ }
+ chorus->length[i] = effp->ininfo.rate / chorus->speed[i];
+ if (! (chorus->lookup_tab[i] =
+ (int *) malloc(sizeof (int) * chorus->length[i])))
+ {
+ st_fail("chorus: Cannot malloc %d bytes!\n",
+ sizeof(int) * chorus->length[i]);
+ return (ST_EOF);
+ }
+ if ( chorus->modulation[i] == MOD_SINE )
+ st_sine(chorus->lookup_tab[i], chorus->length[i],
+ chorus->depth_samples[i] - 1,
+ chorus->depth_samples[i]);
+ else
+ st_triangle(chorus->lookup_tab[i], chorus->length[i],
+ chorus->samples[i] - 1,
+ chorus->depth_samples[i]);
+ chorus->phase[i] = 0;
- if ( chorus->samples[i] > chorus->maxsamples )
- chorus->maxsamples = chorus->samples[i];
- }
+ if ( chorus->samples[i] > chorus->maxsamples )
+ chorus->maxsamples = chorus->samples[i];
+ }
- /* Be nice and check the hint with warning, if... */
- sum_in_volume = 1.0;
- for ( i = 0; i < chorus->num_chorus; i++ )
- sum_in_volume += chorus->decay[i];
- if ( chorus->in_gain * ( sum_in_volume ) > 1.0 / chorus->out_gain )
- st_warn("chorus: warning >>> gain-out can cause saturation or clipping of output <<<");
+ /* Be nice and check the hint with warning, if... */
+ sum_in_volume = 1.0;
+ for ( i = 0; i < chorus->num_chorus; i++ )
+ sum_in_volume += chorus->decay[i];
+ if ( chorus->in_gain * ( sum_in_volume ) > 1.0 / chorus->out_gain )
+ st_warn("chorus: warning >>> gain-out can cause saturation or clipping of output <<<");
- if (! (chorus->chorusbuf =
- (float *) malloc(sizeof (float) * chorus->maxsamples)))
- {
- st_fail("chorus: Cannot malloc %d bytes!\n",
- sizeof(float) * chorus->maxsamples);
- return (ST_EOF);
- }
- for ( i = 0; i < chorus->maxsamples; i++ )
- chorus->chorusbuf[i] = 0.0;
+ if (! (chorus->chorusbuf =
+ (float *) malloc(sizeof (float) * chorus->maxsamples)))
+ {
+ st_fail("chorus: Cannot malloc %d bytes!\n",
+ sizeof(float) * chorus->maxsamples);
+ return (ST_EOF);
+ }
+ for ( i = 0; i < chorus->maxsamples; i++ )
+ chorus->chorusbuf[i] = 0.0;
- chorus->counter = 0;
- chorus->fade_out = chorus->maxsamples;
- return (ST_SUCCESS);
+ chorus->counter = 0;
+ chorus->fade_out = chorus->maxsamples;
+ return (ST_SUCCESS);
}
/*
@@ -255,37 +255,37 @@
int st_chorus_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
st_size_t *isamp, st_size_t *osamp)
{
- chorus_t chorus = (chorus_t) effp->priv;
- int len, done;
- int i;
-
- float d_in, d_out;
- st_sample_t out;
+ chorus_t chorus = (chorus_t) effp->priv;
+ int len, done;
+ int i;
+
+ float d_in, d_out;
+ st_sample_t out;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
- /* Store delays as 24-bit signed longs */
- d_in = (float) *ibuf++ / 256;
- /* Compute output first */
- d_out = d_in * chorus->in_gain;
- for ( i = 0; i < chorus->num_chorus; i++ )
- d_out += chorus->chorusbuf[(chorus->maxsamples +
- chorus->counter - chorus->lookup_tab[i][chorus->phase[i]]) %
- chorus->maxsamples] * chorus->decay[i];
- /* Adjust the output volume and size to 24 bit */
- d_out = d_out * chorus->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- /* Mix decay of delay and input */
- chorus->chorusbuf[chorus->counter] = d_in;
- chorus->counter =
- ( chorus->counter + 1 ) % chorus->maxsamples;
- for ( i = 0; i < chorus->num_chorus; i++ )
- chorus->phase[i] =
- ( chorus->phase[i] + 1 ) % chorus->length[i];
- }
- /* processed all samples */
- return (ST_SUCCESS);
+ len = ((*isamp > *osamp) ? *osamp : *isamp);
+ for(done = 0; done < len; done++) {
+ /* Store delays as 24-bit signed longs */
+ d_in = (float) *ibuf++ / 256;
+ /* Compute output first */
+ d_out = d_in * chorus->in_gain;
+ for ( i = 0; i < chorus->num_chorus; i++ )
+ d_out += chorus->chorusbuf[(chorus->maxsamples +
+ chorus->counter - chorus->lookup_tab[i][chorus->phase[i]]) %
+ chorus->maxsamples] * chorus->decay[i];
+ /* Adjust the output volume and size to 24 bit */
+ d_out = d_out * chorus->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ /* Mix decay of delay and input */
+ chorus->chorusbuf[chorus->counter] = d_in;
+ chorus->counter =
+ ( chorus->counter + 1 ) % chorus->maxsamples;
+ for ( i = 0; i < chorus->num_chorus; i++ )
+ chorus->phase[i] =
+ ( chorus->phase[i] + 1 ) % chorus->length[i];
+ }
+ /* processed all samples */
+ return (ST_SUCCESS);
}
/*
@@ -293,39 +293,39 @@
*/
int st_chorus_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
- chorus_t chorus = (chorus_t) effp->priv;
- int done;
- int i;
-
- float d_in, d_out;
- st_sample_t out;
+ chorus_t chorus = (chorus_t) effp->priv;
+ st_size_t done;
+ int i;
+
+ float d_in, d_out;
+ st_sample_t out;
- done = 0;
- while ( ( done < *osamp ) && ( done < chorus->fade_out ) ) {
- d_in = 0;
- d_out = 0;
- /* Compute output first */
- for ( i = 0; i < chorus->num_chorus; i++ )
- d_out += chorus->chorusbuf[(chorus->maxsamples +
- chorus->counter - chorus->lookup_tab[i][chorus->phase[i]]) %
- chorus->maxsamples] * chorus->decay[i];
- /* Adjust the output volume and size to 24 bit */
- d_out = d_out * chorus->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- /* Mix decay of delay and input */
- chorus->chorusbuf[chorus->counter] = d_in;
- chorus->counter =
- ( chorus->counter + 1 ) % chorus->maxsamples;
- for ( i = 0; i < chorus->num_chorus; i++ )
- chorus->phase[i] =
- ( chorus->phase[i] + 1 ) % chorus->length[i];
- done++;
- chorus->fade_out--;
- }
- /* samples played, it remains */
- *osamp = done;
- return (ST_SUCCESS);
+ done = 0;
+ while ( ( done < *osamp ) && ( done < chorus->fade_out ) ) {
+ d_in = 0;
+ d_out = 0;
+ /* Compute output first */
+ for ( i = 0; i < chorus->num_chorus; i++ )
+ d_out += chorus->chorusbuf[(chorus->maxsamples +
+ chorus->counter - chorus->lookup_tab[i][chorus->phase[i]]) %
+ chorus->maxsamples] * chorus->decay[i];
+ /* Adjust the output volume and size to 24 bit */
+ d_out = d_out * chorus->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ /* Mix decay of delay and input */
+ chorus->chorusbuf[chorus->counter] = d_in;
+ chorus->counter =
+ ( chorus->counter + 1 ) % chorus->maxsamples;
+ for ( i = 0; i < chorus->num_chorus; i++ )
+ chorus->phase[i] =
+ ( chorus->phase[i] + 1 ) % chorus->length[i];
+ done++;
+ chorus->fade_out--;
+ }
+ /* samples played, it remains */
+ *osamp = done;
+ return (ST_SUCCESS);
}
/*
@@ -333,14 +333,14 @@
*/
int st_chorus_stop(eff_t effp)
{
- chorus_t chorus = (chorus_t) effp->priv;
- int i;
+ chorus_t chorus = (chorus_t) effp->priv;
+ int i;
- free((char *) chorus->chorusbuf);
- chorus->chorusbuf = (float *) -1; /* guaranteed core dump */
- for ( i = 0; i < chorus->num_chorus; i++ ) {
- free((char *) chorus->lookup_tab[i]);
- chorus->lookup_tab[i] = (int *) -1; /* guaranteed core dump */
- }
- return (ST_SUCCESS);
+ free((char *) chorus->chorusbuf);
+ chorus->chorusbuf = (float *) -1; /* guaranteed core dump */
+ for ( i = 0; i < chorus->num_chorus; i++ ) {
+ free((char *) chorus->lookup_tab[i]);
+ chorus->lookup_tab[i] = (int *) -1; /* guaranteed core dump */
+ }
+ return (ST_SUCCESS);
}
--- a/src/compand.c
+++ b/src/compand.c
@@ -21,17 +21,17 @@
*
* Flow diagram for one channel:
*
- * ------------ ---------------
- * | | | | ---
+ * ------------ ---------------
+ * | | | | ---
* ibuff ---+---| integrator |--->| transfer func |--->| |
- * | | | | | | |
- * | ------------ --------------- | | * gain
- * | | * |----------->obuff
- * | ------- | |
- * | | | | |
- * +----->| delay |-------------------------->| |
- * | | ---
- * -------
+ * | | | | | | |
+ * | ------------ --------------- | | * gain
+ * | | * |----------->obuff
+ * | ------- | |
+ * | | | | |
+ * +----->| delay |-------------------------->| |
+ * | | ---
+ * -------
*
* Usage:
* compand attack1,decay1[,attack2,decay2...]
@@ -46,9 +46,9 @@
/* Private data for SKEL file */
typedef struct {
int expectedChannels; /* Also flags that channels aren't to be treated
- individually when = 1 and input not mono */
+ individually when = 1 and input not mono */
int transferPoints; /* Number of points specified on the transfer
- function */
+ function */
double *attackRate; /* An array of attack rates */
double *decayRate; /* ... and of decay rates */
double *transferIns; /* ... and points on the transfer function */
@@ -55,7 +55,7 @@
double *transferOuts;
double *volume; /* Current "volume" of each channel */
double outgain; /* Post processor gain */
- double delay; /* Delay to apply before companding */
+ double delay; /* Delay to apply before companding */
st_sample_t *delay_buf; /* Old samples, used for delay processing */
st_ssize_t delay_buf_size;/* Size of delay_buf in samples */
st_ssize_t delay_buf_ptr; /* Index into delay_buf */
@@ -76,12 +76,12 @@
if (n < 2 || n > 5)
{
st_fail("Wrong number of arguments for the compander effect\n"
- "Use: {<attack_time>,<decay_time>}+ {<dB_in>,<db_out>}+ "
- "[<dB_postamp> [<initial-volume> [<delay_time]]]\n"
- "where {}+ means `one or more in a comma-separated, "
- "white-space-free list'\n"
- "and [] indications possible omission. dB values are floating\n"
- "point or `-inf'; times are in seconds.");
+ "Use: {<attack_time>,<decay_time>}+ {<dB_in>,<db_out>}+ "
+ "[<dB_postamp> [<initial-volume> [<delay_time]]]\n"
+ "where {}+ means `one or more in a comma-separated, "
+ "white-space-free list'\n"
+ "and [] indications possible omission. dB values are floating\n"
+ "point or `-inf'; times are in seconds.");
return (ST_EOF);
}
else { /* Right no. of args, but are they well formed? */
@@ -91,55 +91,55 @@
/* Start by checking the attack and decay rates */
for (s = argv[0], commas = 0; *s; ++s)
- if (*s == ',') ++commas;
+ if (*s == ',') ++commas;
if (commas % 2 == 0) /* There must be an even number of
- attack/decay parameters */
+ attack/decay parameters */
{
- st_fail("compander: Odd number of attack & decay rate parameters");
- return (ST_EOF);
+ st_fail("compander: Odd number of attack & decay rate parameters");
+ return (ST_EOF);
}
rates = 1 + commas/2;
if ((l->attackRate = malloc(sizeof(double) * rates)) == NULL ||
- (l->decayRate = malloc(sizeof(double) * rates)) == NULL ||
- (l->volume = malloc(sizeof(double) * rates)) == NULL)
+ (l->decayRate = malloc(sizeof(double) * rates)) == NULL ||
+ (l->volume = malloc(sizeof(double) * rates)) == NULL)
{
- st_fail("Out of memory");
- return (ST_EOF);
+ st_fail("Out of memory");
+ return (ST_EOF);
}
l->expectedChannels = rates;
l->delay_buf = NULL;
/* Now tokenise the rates string and set up these arrays. Keep
- them in seconds at the moment: we don't know the sample rate yet. */
+ them in seconds at the moment: we don't know the sample rate yet. */
s = strtok(argv[0], ","); i = 0;
do {
- l->attackRate[i] = atof(s); s = strtok(NULL, ",");
- l->decayRate[i] = atof(s); s = strtok(NULL, ",");
- ++i;
+ l->attackRate[i] = atof(s); s = strtok(NULL, ",");
+ l->decayRate[i] = atof(s); s = strtok(NULL, ",");
+ ++i;
} while (s != NULL);
/* Same business, but this time for the transfer function */
for (s = argv[1], commas = 0; *s; ++s)
- if (*s == ',') ++commas;
+ if (*s == ',') ++commas;
if (commas % 2 == 0) /* There must be an even number of
- transfer parameters */
+ transfer parameters */
{
- st_fail("compander: Odd number of transfer function parameters\n"
- "Each input value in dB must have a corresponding output value");
- return (ST_EOF);
+ st_fail("compander: Odd number of transfer function parameters\n"
+ "Each input value in dB must have a corresponding output value");
+ return (ST_EOF);
}
tfers = 3 + commas/2; /* 0, 0 at start; 1, 1 at end */
if ((l->transferIns = malloc(sizeof(double) * tfers)) == NULL ||
- (l->transferOuts = malloc(sizeof(double) * tfers)) == NULL)
+ (l->transferOuts = malloc(sizeof(double) * tfers)) == NULL)
{
- st_fail("Out of memory");
- return (ST_EOF);
+ st_fail("Out of memory");
+ return (ST_EOF);
}
l->transferPoints = tfers;
l->transferIns[0] = 0.0; l->transferOuts[0] = 0.0;
@@ -146,31 +146,31 @@
l->transferIns[tfers-1] = 1.0; l->transferOuts[tfers-1] = 1.0;
s = strtok(argv[1], ","); i = 1;
do {
- if (!strcmp(s, "-inf"))
- {
- st_fail("Input signals of zero level must always generate zero output");
- return (ST_EOF);
- }
- l->transferIns[i] = pow(10.0, atof(s)/20.0);
- if (l->transferIns[i] > 1.0)
- {
- st_fail("dB values are relative to maximum input, and, ipso facto, "
- "cannot exceed 0");
- return (ST_EOF);
- }
- if (l->transferIns[i] == 1.0) /* Final point was explicit */
- --(l->transferPoints);
- if (i > 0 && l->transferIns[i] <= l->transferIns[i-1])
- {
- st_fail("Transfer function points don't have strictly ascending "
- "input amplitude");
- return (ST_EOF);
- }
- s = strtok(NULL, ",");
- l->transferOuts[i] = strcmp(s, "-inf") ?
- pow(10.0, atof(s)/20.0) : 0;
- s = strtok(NULL, ",");
- ++i;
+ if (!strcmp(s, "-inf"))
+ {
+ st_fail("Input signals of zero level must always generate zero output");
+ return (ST_EOF);
+ }
+ l->transferIns[i] = pow(10.0, atof(s)/20.0);
+ if (l->transferIns[i] > 1.0)
+ {
+ st_fail("dB values are relative to maximum input, and, ipso facto, "
+ "cannot exceed 0");
+ return (ST_EOF);
+ }
+ if (l->transferIns[i] == 1.0) /* Final point was explicit */
+ --(l->transferPoints);
+ if (i > 0 && l->transferIns[i] <= l->transferIns[i-1])
+ {
+ st_fail("Transfer function points don't have strictly ascending "
+ "input amplitude");
+ return (ST_EOF);
+ }
+ s = strtok(NULL, ",");
+ l->transferOuts[i] = strcmp(s, "-inf") ?
+ pow(10.0, atof(s)/20.0) : 0;
+ s = strtok(NULL, ",");
+ ++i;
} while (s != NULL);
/* If there is a postprocessor gain, store it */
@@ -178,11 +178,11 @@
else l->outgain = 1.0;
/* Set the initial "volume" to be attibuted to the input channels.
- Unless specified, choose 1.0 (maximum) otherwise clipping will
- result if the user has seleced a long attack time */
+ Unless specified, choose 1.0 (maximum) otherwise clipping will
+ result if the user has seleced a long attack time */
for (i = 0; i < l->expectedChannels; ++i) {
- double v = n>=4 ? pow(10.0, atof(argv[3])/20) : 1.0;
- l->volume[i] = v;
+ double v = n>=4 ? pow(10.0, atof(argv[3])/20) : 1.0;
+ l->volume[i] = v;
/* If there is a delay, store it. */
if (n >= 5) l->delay = atof(argv[4]);
@@ -205,20 +205,20 @@
{
fprintf(stderr, "Starting compand effect\n");
fprintf(stderr, "\nRate %ld, size %d, encoding %d, output gain %g.\n",
- effp->outinfo.rate, effp->outinfo.size, effp->outinfo.encoding,
- l->outgain);
+ effp->outinfo.rate, effp->outinfo.size, effp->outinfo.encoding,
+ l->outgain);
fprintf(stderr, "%d input channel(s) expected: actually %d\n",
- l->expectedChannels, effp->outinfo.channels);
+ l->expectedChannels, effp->outinfo.channels);
fprintf(stderr, "\nAttack and decay rates\n"
- "======================\n");
+ "======================\n");
for (i = 0; i < l->expectedChannels; ++i)
fprintf(stderr, "Channel %d: attack = %-12g decay = %-12g\n",
- i, l->attackRate[i], l->decayRate[i]);
+ i, l->attackRate[i], l->decayRate[i]);
fprintf(stderr, "\nTransfer function (linear values)\n"
- "================= =============\n");
+ "================= =============\n");
for (i = 0; i < l->transferPoints; ++i)
fprintf(stderr, "%12g -> %-12g\n",
- l->transferIns[i], l->transferOuts[i]);
+ l->transferIns[i], l->transferOuts[i]);
}
# endif
@@ -227,12 +227,12 @@
for (i = 0; i < l->expectedChannels; ++i) {
if (l->attackRate[i] > 1.0/effp->outinfo.rate)
l->attackRate[i] = 1.0 -
- exp(-1.0/(effp->outinfo.rate * l->attackRate[i]));
+ exp(-1.0/(effp->outinfo.rate * l->attackRate[i]));
else
l->attackRate[i] = 1.0;
if (l->decayRate[i] > 1.0/effp->outinfo.rate)
l->decayRate[i] = 1.0 -
- exp(-1.0/(effp->outinfo.rate * l->decayRate[i]));
+ exp(-1.0/(effp->outinfo.rate * l->decayRate[i]));
else
l->decayRate[i] = 1.0;
}
@@ -289,17 +289,17 @@
for (chan = 0; chan < filechans; ++chan) {
if (l->expectedChannels == 1 && filechans > 1) {
- /* User is expecting same compander for all channels */
- int i;
- double maxsamp = 0.0;
- for (i = 0; i < filechans; ++i) {
- double rect = fabs(ibuf[i]);
- if (rect > maxsamp) maxsamp = rect;
- }
- doVolume(&l->volume[0], maxsamp, l, 0);
- break;
+ /* User is expecting same compander for all channels */
+ int i;
+ double maxsamp = 0.0;
+ for (i = 0; i < filechans; ++i) {
+ double rect = fabs(ibuf[i]);
+ if (rect > maxsamp) maxsamp = rect;
+ }
+ doVolume(&l->volume[0], maxsamp, l, 0);
+ break;
} else
- doVolume(&l->volume[chan], fabs(ibuf[chan]), l, chan);
+ doVolume(&l->volume[chan], fabs(ibuf[chan]), l, chan);
}
/* Volume memory is updated: perform compand */
@@ -306,21 +306,21 @@
for (chan = 0; chan < filechans; ++chan) {
double v = l->expectedChannels > 1 ?
- l->volume[chan] : l->volume[0];
+ l->volume[chan] : l->volume[0];
double outv;
int piece;
for (piece = 1 /* yes, 1 */;
- piece < l->transferPoints;
- ++piece)
- if (v >= l->transferIns[piece - 1] &&
- v < l->transferIns[piece])
- break;
+ piece < l->transferPoints;
+ ++piece)
+ if (v >= l->transferIns[piece - 1] &&
+ v < l->transferIns[piece])
+ break;
outv = l->transferOuts[piece-1] +
- (l->transferOuts[piece] - l->transferOuts[piece-1]) *
- (v - l->transferIns[piece-1]) /
- (l->transferIns[piece] - l->transferIns[piece-1]);
+ (l->transferOuts[piece] - l->transferOuts[piece-1]) *
+ (v - l->transferIns[piece-1]) /
+ (l->transferIns[piece] - l->transferIns[piece-1]);
if (l->delay_buf_size <= 0)
{
@@ -337,10 +337,10 @@
}
else
{
- if (l->delay_buf_cnt >= l->delay_buf_size)
+ if (l->delay_buf_cnt >= l->delay_buf_size)
{
l->delay_buf_full=1; //delay buffer is now definetly full
- checkbuf = l->delay_buf[l->delay_buf_ptr]*(outv/v)*l->outgain;
+ checkbuf = l->delay_buf[l->delay_buf_ptr]*(outv/v)*l->outgain;
if(checkbuf > ST_SAMPLE_MAX)
obuf[odone] = ST_SAMPLE_MAX;
else if(checkbuf < ST_SAMPLE_MIN)
@@ -351,9 +351,9 @@
odone++;
idone++;
}
- else
+ else
{
- l->delay_buf_cnt++;
+ l->delay_buf_cnt++;
idone++; //no "odone++" because we did not fill obuf[...]
}
l->delay_buf[l->delay_buf_ptr++] = ibuf[chan];
@@ -372,7 +372,7 @@
int st_compand_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
compand_t l = (compand_t) effp->priv;
- int done;
+ st_size_t done;
/*
* Drain out delay samples. Note that this loop does all channels.
--- a/src/cvsd.c
+++ b/src/cvsd.c
@@ -5,7 +5,7 @@
* The CVSD format is described in the MIL Std 188 113, which is
* available from http://bbs.itsi.disa.mil:5580/T3564
*
- * Copyright (C) 1996
+ * Copyright (C) 1996
* Thomas Sailer (sailer@ife.ee.ethz.ch) (HB9JNX/AE4WA)
* Swiss Federal Institute of Technology, Electronics Lab
*
@@ -44,7 +44,7 @@
#include <errno.h>
#endif
#ifdef HAVE_UNISTD_H
-#include <unistd.h> /* For SEEK_* defines if not found in stdio */
+#include <unistd.h> /* For SEEK_* defines if not found in stdio */
#endif
#include "cvsdfilt.h"
@@ -61,38 +61,38 @@
*/
struct cvsd_common_state {
- unsigned overload;
- float mla_int;
- float mla_tc0;
- float mla_tc1;
- unsigned phase;
- unsigned phase_inc;
- float v_min, v_max;
+ unsigned overload;
+ float mla_int;
+ float mla_tc0;
+ float mla_tc1;
+ unsigned phase;
+ unsigned phase_inc;
+ float v_min, v_max;
};
struct cvsd_decode_state {
- float output_filter[DEC_FILTERLEN];
+ float output_filter[DEC_FILTERLEN];
};
struct cvsd_encode_state {
- float recon_int;
- float input_filter[ENC_FILTERLEN];
+ float recon_int;
+ float input_filter[ENC_FILTERLEN];
};
struct cvsdpriv {
- struct cvsd_common_state com;
- union {
- struct cvsd_decode_state dec;
- struct cvsd_encode_state enc;
- } c;
- struct {
- unsigned char shreg;
- unsigned mask;
- unsigned cnt;
- } bit;
- unsigned bytes_written;
- unsigned cvsd_rate;
- char swapbits;
+ struct cvsd_common_state com;
+ union {
+ struct cvsd_decode_state dec;
+ struct cvsd_encode_state enc;
+ } c;
+ struct {
+ unsigned char shreg;
+ unsigned mask;
+ unsigned cnt;
+ } bit;
+ unsigned bytes_written;
+ unsigned cvsd_rate;
+ char swapbits;
};
/* ---------------------------------------------------------------------- */
@@ -99,10 +99,10 @@
static float float_conv(float *fp1, float *fp2,int n)
{
- float res = 0;
- for(; n > 0; n--)
- res += (*fp1++) * (*fp2++);
- return res;
+ float res = 0;
+ for(; n > 0; n--)
+ res += (*fp1++) * (*fp2++);
+ return res;
}
/* ---------------------------------------------------------------------- */
@@ -119,42 +119,42 @@
static void cvsdstartcommon(ft_t ft)
{
- struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
-
- p->cvsd_rate = (ft->info.rate <= 24000) ? 16000 : 32000;
- ft->info.rate = 8000;
- ft->info.channels = 1;
- ft->info.size = ST_SIZE_WORD; /* make output format default to words */
- ft->info.encoding = ST_ENCODING_SIGN2;
- p->swapbits = ft->swap;
- ft->swap = 0;
- /*
- * initialize the decoder
- */
- p->com.overload = 0x5;
- p->com.mla_int = 0;
- /*
- * timeconst = (1/e)^(200 / SR) = exp(-200/SR)
- * SR is the sampling rate
- */
- p->com.mla_tc0 = exp((-200.0)/((float)(p->cvsd_rate)));
- /*
- * phase_inc = 32000 / SR
- */
- p->com.phase_inc = 32000 / p->cvsd_rate;
- /*
- * initialize bit shift register
- */
- p->bit.shreg = p->bit.cnt = 0;
- p->bit.mask = p->swapbits ? 0x80 : 1;
- /*
- * count the bytes written
- */
- p->bytes_written = 0;
- p->com.v_min = 1;
- p->com.v_max = -1;
- st_report("cvsd: bit rate %dbit/s, bits from %s\n", p->cvsd_rate,
- p->swapbits ? "msb to lsb" : "lsb to msb");
+ struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+
+ p->cvsd_rate = (ft->info.rate <= 24000) ? 16000 : 32000;
+ ft->info.rate = 8000;
+ ft->info.channels = 1;
+ ft->info.size = ST_SIZE_WORD; /* make output format default to words */
+ ft->info.encoding = ST_ENCODING_SIGN2;
+ p->swapbits = ft->swap;
+ ft->swap = 0;
+ /*
+ * initialize the decoder
+ */
+ p->com.overload = 0x5;
+ p->com.mla_int = 0;
+ /*
+ * timeconst = (1/e)^(200 / SR) = exp(-200/SR)
+ * SR is the sampling rate
+ */
+ p->com.mla_tc0 = exp((-200.0)/((float)(p->cvsd_rate)));
+ /*
+ * phase_inc = 32000 / SR
+ */
+ p->com.phase_inc = 32000 / p->cvsd_rate;
+ /*
+ * initialize bit shift register
+ */
+ p->bit.shreg = p->bit.cnt = 0;
+ p->bit.mask = p->swapbits ? 0x80 : 1;
+ /*
+ * count the bytes written
+ */
+ p->bytes_written = 0;
+ p->com.v_min = 1;
+ p->com.v_max = -1;
+ st_report("cvsd: bit rate %dbit/s, bits from %s\n", p->cvsd_rate,
+ p->swapbits ? "msb to lsb" : "lsb to msb");
}
/* ---------------------------------------------------------------------- */
@@ -161,26 +161,26 @@
int st_cvsdstartread(ft_t ft)
{
- struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
- float *fp1;
- int i;
+ struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+ float *fp1;
+ int i;
- cvsdstartcommon(ft);
+ cvsdstartcommon(ft);
- p->com.mla_tc1 = 0.1 * (1 - p->com.mla_tc0);
- p->com.phase = 0;
- /*
- * initialize the output filter coeffs (i.e. multiply
- * the coeffs with (1/(1-1/z)) to achieve integration
- * this is now done in the filter parameter generation utility
- */
- /*
- * zero the filter
- */
- for(fp1 = p->c.dec.output_filter, i = DEC_FILTERLEN; i > 0; i--)
- *fp1++ = 0;
+ p->com.mla_tc1 = 0.1 * (1 - p->com.mla_tc0);
+ p->com.phase = 0;
+ /*
+ * initialize the output filter coeffs (i.e. multiply
+ * the coeffs with (1/(1-1/z)) to achieve integration
+ * this is now done in the filter parameter generation utility
+ */
+ /*
+ * zero the filter
+ */
+ for(fp1 = p->c.dec.output_filter, i = DEC_FILTERLEN; i > 0; i--)
+ *fp1++ = 0;
- return (ST_SUCCESS);
+ return (ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -187,22 +187,22 @@
int st_cvsdstartwrite(ft_t ft)
{
- struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
- float *fp1;
- int i;
+ struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+ float *fp1;
+ int i;
- cvsdstartcommon(ft);
+ cvsdstartcommon(ft);
- p->com.mla_tc1 = 0.1 * (1 - p->com.mla_tc0);
- p->com.phase = 4;
- /*
- * zero the filter
- */
- for(fp1 = p->c.enc.input_filter, i = ENC_FILTERLEN; i > 0; i--)
- *fp1++ = 0;
- p->c.enc.recon_int = 0;
+ p->com.mla_tc1 = 0.1 * (1 - p->com.mla_tc0);
+ p->com.phase = 4;
+ /*
+ * zero the filter
+ */
+ for(fp1 = p->c.enc.input_filter, i = ENC_FILTERLEN; i > 0; i--)
+ *fp1++ = 0;
+ p->c.enc.recon_int = 0;
- return(ST_SUCCESS);
+ return(ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -209,16 +209,16 @@
int st_cvsdstopwrite(ft_t ft)
{
- struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+ struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
- if (p->bit.cnt) {
- st_writeb(ft, p->bit.shreg);
- p->bytes_written++;
- }
- st_report("cvsd: min slope %f, max slope %f\n",
- p->com.v_min, p->com.v_max);
+ if (p->bit.cnt) {
+ st_writeb(ft, p->bit.shreg);
+ p->bytes_written++;
+ }
+ st_report("cvsd: min slope %f, max slope %f\n",
+ p->com.v_min, p->com.v_max);
- return (ST_SUCCESS);
+ return (ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -225,12 +225,12 @@
int st_cvsdstopread(ft_t ft)
{
- struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+ struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
- st_report("cvsd: min value %f, max value %f\n",
- p->com.v_min, p->com.v_max);
+ st_report("cvsd: min value %f, max value %f\n",
+ p->com.v_min, p->com.v_max);
- return(ST_SUCCESS);
+ return(ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -239,172 +239,172 @@
#ifdef DEBUG
static struct {
- FILE *f1;
- FILE *f2;
- int cnt
+ FILE *f1;
+ FILE *f2;
+ int cnt
} dbg = { NULL, NULL, 0 };
#endif
st_ssize_t st_cvsdread(ft_t ft, st_sample_t *buf, st_ssize_t nsamp)
{
- struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
- int done = 0;
- float oval;
-
+ struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+ int done = 0;
+ float oval;
+
#ifdef DEBUG
- if (!dbg.f1) {
- if (!(dbg.f1 = fopen("dbg1", "w")))
- {
- st_fail_errno(ft,errno,"debugging");
- return (0);
- }
- fprintf(dbg.f1, "\"input\"\n");
- }
- if (!dbg.f2) {
- if (!(dbg.f2 = fopen("dbg2", "w")))
- {
- st_fail_errno(ft,errno,"debugging");
- return (0);
- }
- fprintf(dbg.f2, "\"recon\"\n");
- }
+ if (!dbg.f1) {
+ if (!(dbg.f1 = fopen("dbg1", "w")))
+ {
+ st_fail_errno(ft,errno,"debugging");
+ return (0);
+ }
+ fprintf(dbg.f1, "\"input\"\n");
+ }
+ if (!dbg.f2) {
+ if (!(dbg.f2 = fopen("dbg2", "w")))
+ {
+ st_fail_errno(ft,errno,"debugging");
+ return (0);
+ }
+ fprintf(dbg.f2, "\"recon\"\n");
+ }
#endif
- while (done < nsamp) {
- if (!p->bit.cnt) {
- if (st_readb(ft, &(p->bit.shreg)) == ST_EOF)
- return done;
- p->bit.cnt = 8;
- p->bit.mask = p->swapbits ? 0x80 : 1;
- }
- /*
- * handle one bit
- */
- p->bit.cnt--;
- p->com.overload = ((p->com.overload << 1) |
- (!!(p->bit.shreg & p->bit.mask))) & 7;
- if (p->swapbits)
- p->bit.mask >>= 1;
- else
- p->bit.mask <<= 1;
- p->com.mla_int *= p->com.mla_tc0;
- if ((p->com.overload == 0) || (p->com.overload == 7))
- p->com.mla_int += p->com.mla_tc1;
- memmove(p->c.dec.output_filter+1, p->c.dec.output_filter,
- sizeof(p->c.dec.output_filter)-sizeof(float));
- if (p->com.overload & 1)
- p->c.dec.output_filter[0] = p->com.mla_int;
- else
- p->c.dec.output_filter[0] = -p->com.mla_int;
- /*
- * check if the next output is due
- */
- p->com.phase += p->com.phase_inc;
- if (p->com.phase >= 4) {
- oval = float_conv(p->c.dec.output_filter,
- (p->cvsd_rate < 24000) ?
- dec_filter_16 : dec_filter_32,
- DEC_FILTERLEN);
+ while (done < nsamp) {
+ if (!p->bit.cnt) {
+ if (st_readb(ft, &(p->bit.shreg)) == ST_EOF)
+ return done;
+ p->bit.cnt = 8;
+ p->bit.mask = p->swapbits ? 0x80 : 1;
+ }
+ /*
+ * handle one bit
+ */
+ p->bit.cnt--;
+ p->com.overload = ((p->com.overload << 1) |
+ (!!(p->bit.shreg & p->bit.mask))) & 7;
+ if (p->swapbits)
+ p->bit.mask >>= 1;
+ else
+ p->bit.mask <<= 1;
+ p->com.mla_int *= p->com.mla_tc0;
+ if ((p->com.overload == 0) || (p->com.overload == 7))
+ p->com.mla_int += p->com.mla_tc1;
+ memmove(p->c.dec.output_filter+1, p->c.dec.output_filter,
+ sizeof(p->c.dec.output_filter)-sizeof(float));
+ if (p->com.overload & 1)
+ p->c.dec.output_filter[0] = p->com.mla_int;
+ else
+ p->c.dec.output_filter[0] = -p->com.mla_int;
+ /*
+ * check if the next output is due
+ */
+ p->com.phase += p->com.phase_inc;
+ if (p->com.phase >= 4) {
+ oval = float_conv(p->c.dec.output_filter,
+ (p->cvsd_rate < 24000) ?
+ dec_filter_16 : dec_filter_32,
+ DEC_FILTERLEN);
#ifdef DEBUG
- fprintf(dbg.f1, "%f %f\n", (double)dbg.cnt,
- (double)p->com.mla_int);
- fprintf(dbg.f2, "%f %f\n", (double)dbg.cnt,
- (double)oval);
- dbg.cnt++;
-#endif
- if (oval > p->com.v_max)
- p->com.v_max = oval;
- if (oval < p->com.v_min)
- p->com.v_min = oval;
- *buf++ = (oval * ((float)ST_SAMPLE_MAX));
- done++;
- }
- p->com.phase &= 3;
- }
- return done;
-}
+ fprintf(dbg.f1, "%f %f\n", (double)dbg.cnt,
+ (double)p->com.mla_int);
+ fprintf(dbg.f2, "%f %f\n", (double)dbg.cnt,
+ (double)oval);
+ dbg.cnt++;
+#endif
+ if (oval > p->com.v_max)
+ p->com.v_max = oval;
+ if (oval < p->com.v_min)
+ p->com.v_min = oval;
+ *buf++ = (oval * ((float)ST_SAMPLE_MAX));
+ done++;
+ }
+ p->com.phase &= 3;
+ }
+ return done;
+}
/* ---------------------------------------------------------------------- */
st_ssize_t st_cvsdwrite(ft_t ft, st_sample_t *buf, st_ssize_t nsamp)
{
- struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
- int done = 0;
- float inval;
+ struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+ int done = 0;
+ float inval;
#ifdef DEBUG
- if (!dbg.f1) {
- if (!(dbg.f1 = fopen("dbg1", "w")))
- {
- st_fail_errno(ft,errno,"debugging");
- return (0);
- }
- fprintf(dbg.f1, "\"input\"\n");
- }
- if (!dbg.f2) {
- if (!(dbg.f2 = fopen("dbg2", "w")))
- {
- st_fail_errno(ft,errno,"debugging");
- return (0);
- }
- fprintf(dbg.f2, "\"recon\"\n");
- }
+ if (!dbg.f1) {
+ if (!(dbg.f1 = fopen("dbg1", "w")))
+ {
+ st_fail_errno(ft,errno,"debugging");
+ return (0);
+ }
+ fprintf(dbg.f1, "\"input\"\n");
+ }
+ if (!dbg.f2) {
+ if (!(dbg.f2 = fopen("dbg2", "w")))
+ {
+ st_fail_errno(ft,errno,"debugging");
+ return (0);
+ }
+ fprintf(dbg.f2, "\"recon\"\n");
+ }
#endif
- for(;;) {
- /*
- * check if the next input is due
- */
- if (p->com.phase >= 4) {
- if (done >= nsamp)
- 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++) /
- ((float)ST_SAMPLE_MAX);
- done++;
- }
- p->com.phase &= 3;
- /* insert input filter here! */
- inval = float_conv(p->c.enc.input_filter,
- (p->cvsd_rate < 24000) ?
- (enc_filter_16[(p->com.phase >= 2)]) :
- (enc_filter_32[p->com.phase]),
- ENC_FILTERLEN);
- /*
- * encode one bit
- */
- p->com.overload = (((p->com.overload << 1) |
- (inval > p->c.enc.recon_int)) & 7);
- p->com.mla_int *= p->com.mla_tc0;
- if ((p->com.overload == 0) || (p->com.overload == 7))
- p->com.mla_int += p->com.mla_tc1;
- if (p->com.mla_int > p->com.v_max)
- p->com.v_max = p->com.mla_int;
- if (p->com.mla_int < p->com.v_min)
- p->com.v_min = p->com.mla_int;
- if (p->com.overload & 1) {
- p->c.enc.recon_int += p->com.mla_int;
- p->bit.shreg |= p->bit.mask;
- } else
- p->c.enc.recon_int -= p->com.mla_int;
- if ((++(p->bit.cnt)) >= 8) {
- st_writeb(ft, p->bit.shreg);
- p->bytes_written++;
- p->bit.shreg = p->bit.cnt = 0;
- p->bit.mask = p->swapbits ? 0x80 : 1;
- } else {
- if (p->swapbits)
- p->bit.mask >>= 1;
- else
- p->bit.mask <<= 1;
- }
- p->com.phase += p->com.phase_inc;
+ for(;;) {
+ /*
+ * check if the next input is due
+ */
+ if (p->com.phase >= 4) {
+ if (done >= nsamp)
+ 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++) /
+ ((float)ST_SAMPLE_MAX);
+ done++;
+ }
+ p->com.phase &= 3;
+ /* insert input filter here! */
+ inval = float_conv(p->c.enc.input_filter,
+ (p->cvsd_rate < 24000) ?
+ (enc_filter_16[(p->com.phase >= 2)]) :
+ (enc_filter_32[p->com.phase]),
+ ENC_FILTERLEN);
+ /*
+ * encode one bit
+ */
+ p->com.overload = (((p->com.overload << 1) |
+ (inval > p->c.enc.recon_int)) & 7);
+ p->com.mla_int *= p->com.mla_tc0;
+ if ((p->com.overload == 0) || (p->com.overload == 7))
+ p->com.mla_int += p->com.mla_tc1;
+ if (p->com.mla_int > p->com.v_max)
+ p->com.v_max = p->com.mla_int;
+ if (p->com.mla_int < p->com.v_min)
+ p->com.v_min = p->com.mla_int;
+ if (p->com.overload & 1) {
+ p->c.enc.recon_int += p->com.mla_int;
+ p->bit.shreg |= p->bit.mask;
+ } else
+ p->c.enc.recon_int -= p->com.mla_int;
+ if ((++(p->bit.cnt)) >= 8) {
+ st_writeb(ft, p->bit.shreg);
+ p->bytes_written++;
+ p->bit.shreg = p->bit.cnt = 0;
+ p->bit.mask = p->swapbits ? 0x80 : 1;
+ } else {
+ if (p->swapbits)
+ p->bit.mask >>= 1;
+ else
+ p->bit.mask <<= 1;
+ }
+ p->com.phase += p->com.phase_inc;
#ifdef DEBUG
- fprintf(dbg.f1, "%f %f\n", (double)dbg.cnt, (double)inval);
- fprintf(dbg.f2, "%f %f\n", (double)dbg.cnt,
- (double)p->c.enc.recon_int);
- dbg.cnt++;
-#endif
- }
+ fprintf(dbg.f1, "%f %f\n", (double)dbg.cnt, (double)inval);
+ fprintf(dbg.f2, "%f %f\n", (double)dbg.cnt,
+ (double)p->c.enc.recon_int);
+ dbg.cnt++;
+#endif
+ }
}
/* ---------------------------------------------------------------------- */
@@ -412,20 +412,20 @@
* DVMS file header
*/
struct dvms_header {
- char Filename[14];
- unsigned Id;
- unsigned State;
- time_t Unixtime;
- unsigned Usender;
- unsigned Ureceiver;
- st_size_t Length;
- unsigned Srate;
- unsigned Days;
- unsigned Custom1;
- unsigned Custom2;
- char Info[16];
- char extend[64];
- unsigned Crc;
+ char Filename[14];
+ unsigned Id;
+ unsigned State;
+ time_t Unixtime;
+ unsigned Usender;
+ unsigned Ureceiver;
+ st_size_t Length;
+ unsigned Srate;
+ unsigned Days;
+ unsigned Custom1;
+ unsigned Custom2;
+ char Info[16];
+ char extend[64];
+ unsigned Crc;
};
#define DVMS_HEADER_LEN 120
@@ -434,31 +434,31 @@
/* FIXME: Move these to misc.c */
static uint32_t get32(unsigned char **p)
{
- uint32_t val = (((*p)[3]) << 24) | (((*p)[2]) << 16) |
- (((*p)[1]) << 8) | (**p);
- (*p) += 4;
- return val;
+ uint32_t val = (((*p)[3]) << 24) | (((*p)[2]) << 16) |
+ (((*p)[1]) << 8) | (**p);
+ (*p) += 4;
+ return val;
}
static uint16_t get16(unsigned char **p)
{
- unsigned val = (((*p)[1]) << 8) | (**p);
- (*p) += 2;
- return val;
+ unsigned val = (((*p)[1]) << 8) | (**p);
+ (*p) += 2;
+ return val;
}
static void put32(unsigned char **p, uint32_t val)
{
- *(*p)++ = val & 0xff;
- *(*p)++ = (val >> 8) & 0xff;
- *(*p)++ = (val >> 16) & 0xff;
- *(*p)++ = (val >> 24) & 0xff;
+ *(*p)++ = val & 0xff;
+ *(*p)++ = (val >> 8) & 0xff;
+ *(*p)++ = (val >> 16) & 0xff;
+ *(*p)++ = (val >> 24) & 0xff;
}
static void put16(unsigned char **p, int16_t val)
{
- *(*p)++ = val & 0xff;
- *(*p)++ = (val >> 8) & 0xff;
+ *(*p)++ = val & 0xff;
+ *(*p)++ = (val >> 8) & 0xff;
}
/* ---------------------------------------------------------------------- */
@@ -465,42 +465,42 @@
static int dvms_read_header(FILE *f, struct dvms_header *hdr)
{
- unsigned char hdrbuf[DVMS_HEADER_LEN];
- unsigned char *pch = hdrbuf;
- int i;
- unsigned sum;
+ unsigned char hdrbuf[DVMS_HEADER_LEN];
+ unsigned char *pch = hdrbuf;
+ int i;
+ unsigned sum;
- if (fread(hdrbuf, sizeof(hdrbuf), 1, f) != 1)
- {
- return (ST_EOF);
- }
- for(i = sizeof(hdrbuf), sum = 0; i > /*2*/3; i--) /* Deti bug */
- sum += *pch++;
- pch = hdrbuf;
- memcpy(hdr->Filename, pch, sizeof(hdr->Filename));
- pch += sizeof(hdr->Filename);
- hdr->Id = get16(&pch);
- hdr->State = get16(&pch);
- hdr->Unixtime = get32(&pch);
- hdr->Usender = get16(&pch);
- hdr->Ureceiver = get16(&pch);
- hdr->Length = get32(&pch);
- hdr->Srate = get16(&pch);
- hdr->Days = get16(&pch);
- hdr->Custom1 = get16(&pch);
- hdr->Custom2 = get16(&pch);
- memcpy(hdr->Info, pch, sizeof(hdr->Info));
- pch += sizeof(hdr->Info);
- memcpy(hdr->extend, pch, sizeof(hdr->extend));
- pch += sizeof(hdr->extend);
- hdr->Crc = get16(&pch);
- if (sum != hdr->Crc)
- {
- st_report("DVMS header checksum error, read %u, calculated %u\n",
- hdr->Crc, sum);
- return (ST_EOF);
- }
- return (ST_SUCCESS);
+ if (fread(hdrbuf, sizeof(hdrbuf), 1, f) != 1)
+ {
+ return (ST_EOF);
+ }
+ for(i = sizeof(hdrbuf), sum = 0; i > /*2*/3; i--) /* Deti bug */
+ sum += *pch++;
+ pch = hdrbuf;
+ memcpy(hdr->Filename, pch, sizeof(hdr->Filename));
+ pch += sizeof(hdr->Filename);
+ hdr->Id = get16(&pch);
+ hdr->State = get16(&pch);
+ hdr->Unixtime = get32(&pch);
+ hdr->Usender = get16(&pch);
+ hdr->Ureceiver = get16(&pch);
+ hdr->Length = get32(&pch);
+ hdr->Srate = get16(&pch);
+ hdr->Days = get16(&pch);
+ hdr->Custom1 = get16(&pch);
+ hdr->Custom2 = get16(&pch);
+ memcpy(hdr->Info, pch, sizeof(hdr->Info));
+ pch += sizeof(hdr->Info);
+ memcpy(hdr->extend, pch, sizeof(hdr->extend));
+ pch += sizeof(hdr->extend);
+ hdr->Crc = get16(&pch);
+ if (sum != hdr->Crc)
+ {
+ st_report("DVMS header checksum error, read %u, calculated %u\n",
+ hdr->Crc, sum);
+ return (ST_EOF);
+ }
+ return (ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -510,43 +510,43 @@
*/
static int dvms_write_header(FILE *f, struct dvms_header *hdr)
{
- unsigned char hdrbuf[DVMS_HEADER_LEN];
- unsigned char *pch = hdrbuf;
- unsigned char *pchs = hdrbuf;
- int i;
- unsigned sum;
+ unsigned char hdrbuf[DVMS_HEADER_LEN];
+ unsigned char *pch = hdrbuf;
+ unsigned char *pchs = hdrbuf;
+ int i;
+ unsigned sum;
- memcpy(pch, hdr->Filename, sizeof(hdr->Filename));
- pch += sizeof(hdr->Filename);
- put16(&pch, hdr->Id);
- put16(&pch, hdr->State);
- put32(&pch, hdr->Unixtime);
- put16(&pch, hdr->Usender);
- put16(&pch, hdr->Ureceiver);
- put32(&pch, hdr->Length);
- put16(&pch, hdr->Srate);
- put16(&pch, hdr->Days);
- put16(&pch, hdr->Custom1);
- put16(&pch, hdr->Custom2);
- memcpy(pch, hdr->Info, sizeof(hdr->Info));
- pch += sizeof(hdr->Info);
- memcpy(pch, hdr->extend, sizeof(hdr->extend));
- pch += sizeof(hdr->extend);
- for(i = sizeof(hdrbuf), sum = 0; i > /*2*/3; i--) /* Deti bug */
- sum += *pchs++;
- hdr->Crc = sum;
- put16(&pch, hdr->Crc);
- if (fseek(f, 0, SEEK_SET) < 0)
- {
- st_report("seek failed\n: %s",strerror(errno));
- return (ST_EOF);
- }
- if (fwrite(hdrbuf, sizeof(hdrbuf), 1, f) != 1)
- {
- st_report("%s\n",strerror(errno));
- return (ST_EOF);
- }
- return (ST_SUCCESS);
+ memcpy(pch, hdr->Filename, sizeof(hdr->Filename));
+ pch += sizeof(hdr->Filename);
+ put16(&pch, hdr->Id);
+ put16(&pch, hdr->State);
+ put32(&pch, hdr->Unixtime);
+ put16(&pch, hdr->Usender);
+ put16(&pch, hdr->Ureceiver);
+ put32(&pch, hdr->Length);
+ put16(&pch, hdr->Srate);
+ put16(&pch, hdr->Days);
+ put16(&pch, hdr->Custom1);
+ put16(&pch, hdr->Custom2);
+ memcpy(pch, hdr->Info, sizeof(hdr->Info));
+ pch += sizeof(hdr->Info);
+ memcpy(pch, hdr->extend, sizeof(hdr->extend));
+ pch += sizeof(hdr->extend);
+ for(i = sizeof(hdrbuf), sum = 0; i > /*2*/3; i--) /* Deti bug */
+ sum += *pchs++;
+ hdr->Crc = sum;
+ put16(&pch, hdr->Crc);
+ if (fseek(f, 0, SEEK_SET) < 0)
+ {
+ st_report("seek failed\n: %s",strerror(errno));
+ return (ST_EOF);
+ }
+ if (fwrite(hdrbuf, sizeof(hdrbuf), 1, f) != 1)
+ {
+ st_report("%s\n",strerror(errno));
+ return (ST_EOF);
+ }
+ return (ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -553,26 +553,26 @@
static void make_dvms_hdr(ft_t ft, struct dvms_header *hdr)
{
- struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
- int len;
+ struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+ size_t len;
- memset(hdr->Filename, 0, sizeof(hdr->Filename));
- len = strlen(ft->filename);
- if (len >= sizeof(hdr->Filename))
- len = sizeof(hdr->Filename)-1;
- memcpy(hdr->Filename, ft->filename, len);
- hdr->Id = hdr->State = 0;
- hdr->Unixtime = time(NULL);
- hdr->Usender = hdr->Ureceiver = 0;
- hdr->Length = p->bytes_written;
- hdr->Srate = p->cvsd_rate/100;
- hdr->Days = hdr->Custom1 = hdr->Custom2 = 0;
- memset(hdr->Info, 0, sizeof(hdr->Info));
- len = strlen(ft->comment);
- if (len >= sizeof(hdr->Info))
- len = sizeof(hdr->Info)-1;
- memcpy(hdr->Info, ft->comment, len);
- memset(hdr->extend, 0, sizeof(hdr->extend));
+ memset(hdr->Filename, 0, sizeof(hdr->Filename));
+ len = strlen(ft->filename);
+ if (len >= sizeof(hdr->Filename))
+ len = sizeof(hdr->Filename)-1;
+ memcpy(hdr->Filename, ft->filename, len);
+ hdr->Id = hdr->State = 0;
+ hdr->Unixtime = time(NULL);
+ hdr->Usender = hdr->Ureceiver = 0;
+ hdr->Length = p->bytes_written;
+ hdr->Srate = p->cvsd_rate/100;
+ hdr->Days = hdr->Custom1 = hdr->Custom2 = 0;
+ memset(hdr->Info, 0, sizeof(hdr->Info));
+ len = strlen(ft->comment);
+ if (len >= sizeof(hdr->Info))
+ len = sizeof(hdr->Info)-1;
+ memcpy(hdr->Info, ft->comment, len);
+ memset(hdr->extend, 0, sizeof(hdr->extend));
}
/* ---------------------------------------------------------------------- */
@@ -579,39 +579,39 @@
int st_dvmsstartread(ft_t ft)
{
- struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
- struct dvms_header hdr;
- int rc;
+ struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+ struct dvms_header hdr;
+ int rc;
- rc = dvms_read_header(ft->fp, &hdr);
- if (rc){
- st_fail_errno(ft,ST_EHDR,"unable to read DVMS header\n");
- return rc;
- }
+ rc = dvms_read_header(ft->fp, &hdr);
+ if (rc){
+ st_fail_errno(ft,ST_EHDR,"unable to read DVMS header\n");
+ return rc;
+ }
- st_report("DVMS header of source file \"%s\":");
- st_report(" filename \"%.14s\"",ft->filename);
+ st_report("DVMS header of source file \"%s\":");
+ st_report(" filename \"%.14s\"",ft->filename);
st_report(" id 0x%x", hdr.Filename);
- st_report(" state 0x%x", hdr.Id, hdr.State);
- st_report(" time %s",ctime(&hdr.Unixtime)); /* ctime generates lf */
- st_report(" usender %u", hdr.Usender);
- st_report(" ureceiver %u", hdr.Ureceiver);
- st_report(" length %u", hdr.Length);
- st_report(" srate %u", hdr.Srate);
- st_report(" days %u", hdr.Days);
- st_report(" custom1 %u", hdr.Custom1);
- st_report(" custom2 %u", hdr.Custom2);
- st_report(" info \"%.16s\"\n", hdr.Info);
- ft->info.rate = (hdr.Srate < 240) ? 16000 : 32000;
- st_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);
- rc = st_cvsdstartread(ft);
- if (rc)
- return rc;
+ st_report(" state 0x%x", hdr.Id, hdr.State);
+ st_report(" time %s",ctime(&hdr.Unixtime)); /* ctime generates lf */
+ st_report(" usender %u", hdr.Usender);
+ st_report(" ureceiver %u", hdr.Ureceiver);
+ st_report(" length %u", hdr.Length);
+ st_report(" srate %u", hdr.Srate);
+ st_report(" days %u", hdr.Days);
+ st_report(" custom1 %u", hdr.Custom1);
+ st_report(" custom2 %u", hdr.Custom2);
+ st_report(" info \"%.16s\"\n", hdr.Info);
+ ft->info.rate = (hdr.Srate < 240) ? 16000 : 32000;
+ st_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);
+ rc = st_cvsdstartread(ft);
+ if (rc)
+ return rc;
- p->swapbits = 0;
- return(ST_SUCCESS);
+ p->swapbits = 0;
+ return(ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -618,26 +618,26 @@
int st_dvmsstartwrite(ft_t ft)
{
- struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
- struct dvms_header hdr;
- int rc;
-
- rc = st_cvsdstartwrite(ft);
- if (rc)
- return rc;
+ struct cvsdpriv *p = (struct cvsdpriv *) ft->priv;
+ struct dvms_header hdr;
+ int rc;
+
+ rc = st_cvsdstartwrite(ft);
+ if (rc)
+ return rc;
- make_dvms_hdr(ft, &hdr);
- rc = dvms_write_header(ft->fp, &hdr);
- if (rc){
- st_fail_errno(ft,rc,"cannot write DVMS header\n");
- return rc;
- }
+ make_dvms_hdr(ft, &hdr);
+ rc = dvms_write_header(ft->fp, &hdr);
+ if (rc){
+ st_fail_errno(ft,rc,"cannot write DVMS header\n");
+ return rc;
+ }
- if (!ft->seekable)
- st_warn("Length in output .DVMS header will wrong since can't seek to fix it");
+ if (!ft->seekable)
+ st_warn("Length in output .DVMS header will wrong since can't seek to fix it");
- p->swapbits = 0;
- return(ST_SUCCESS);
+ p->swapbits = 0;
+ return(ST_SUCCESS);
}
/* ---------------------------------------------------------------------- */
@@ -644,27 +644,27 @@
int st_dvmsstopwrite(ft_t ft)
{
- struct dvms_header hdr;
- int rc;
-
- st_cvsdstopwrite(ft);
- if (!ft->seekable)
- {
- st_warn("File not seekable");
- return (ST_EOF);
- }
- if (fseek(ft->fp, 0L, 0) != 0)
- {
- st_fail_errno(ft,errno,"Can't rewind output file to rewrite DVMS header.");
- return(ST_EOF);
- }
- make_dvms_hdr(ft, &hdr);
- rc = dvms_write_header(ft->fp, &hdr);
- if(rc){
- st_fail_errno(ft,rc,"cannot write DVMS header\n");
- return rc;
- }
- return rc;
+ struct dvms_header hdr;
+ int rc;
+
+ st_cvsdstopwrite(ft);
+ if (!ft->seekable)
+ {
+ st_warn("File not seekable");
+ return (ST_EOF);
+ }
+ if (fseek(ft->fp, 0L, 0) != 0)
+ {
+ st_fail_errno(ft,errno,"Can't rewind output file to rewrite DVMS header.");
+ return(ST_EOF);
+ }
+ make_dvms_hdr(ft, &hdr);
+ rc = dvms_write_header(ft->fp, &hdr);
+ if(rc){
+ st_fail_errno(ft,rc,"cannot write DVMS header\n");
+ return rc;
+ }
+ return rc;
}
/* ---------------------------------------------------------------------- */
--- a/src/echo.c
+++ b/src/echo.c
@@ -60,17 +60,17 @@
#include "st_i.h"
#define DELAY_BUFSIZ ( 50L * ST_MAXRATE )
-#define MAX_ECHOS 7 /* 24 bit x ( 1 + MAX_ECHOS ) = */
- /* 24 bit x 8 = 32 bit !!! */
+#define MAX_ECHOS 7 /* 24 bit x ( 1 + MAX_ECHOS ) = */
+ /* 24 bit x 8 = 32 bit !!! */
/* Private data for SKEL file */
typedef struct echostuff {
- int counter;
- int num_delays;
- double *delay_buf;
- float in_gain, out_gain;
- float delay[MAX_ECHOS], decay[MAX_ECHOS];
- st_ssize_t samples[MAX_ECHOS], maxsamples, fade_out;
+ int counter;
+ int num_delays;
+ double *delay_buf;
+ float in_gain, out_gain;
+ float delay[MAX_ECHOS], decay[MAX_ECHOS];
+ st_ssize_t samples[MAX_ECHOS], maxsamples, fade_out;
} *echo_t;
/* Private data for SKEL file */
@@ -81,30 +81,30 @@
*/
int st_echo_getopts(eff_t effp, int n, char **argv)
{
- echo_t echo = (echo_t) effp->priv;
- int i;
+ echo_t echo = (echo_t) effp->priv;
+ int i;
- echo->num_delays = 0;
+ echo->num_delays = 0;
- if ((n < 4) || (n % 2))
- {
- st_fail("Usage: echo gain-in gain-out delay decay [ delay decay ... ]");
- return (ST_EOF);
- }
+ if ((n < 4) || (n % 2))
+ {
+ st_fail("Usage: echo gain-in gain-out delay decay [ delay decay ... ]");
+ return (ST_EOF);
+ }
- i = 0;
- sscanf(argv[i++], "%f", &echo->in_gain);
- sscanf(argv[i++], "%f", &echo->out_gain);
- while (i < n) {
- if ( echo->num_delays >= MAX_ECHOS )
- st_fail("echo: to many delays, use less than %i delays",
- MAX_ECHOS);
- /* Linux bug and it's cleaner. */
- sscanf(argv[i++], "%f", &echo->delay[echo->num_delays]);
- sscanf(argv[i++], "%f", &echo->decay[echo->num_delays]);
- echo->num_delays++;
- }
- return (ST_SUCCESS);
+ i = 0;
+ sscanf(argv[i++], "%f", &echo->in_gain);
+ sscanf(argv[i++], "%f", &echo->out_gain);
+ while (i < n) {
+ if ( echo->num_delays >= MAX_ECHOS )
+ st_fail("echo: to many delays, use less than %i delays",
+ MAX_ECHOS);
+ /* Linux bug and it's cleaner. */
+ sscanf(argv[i++], "%f", &echo->delay[echo->num_delays]);
+ sscanf(argv[i++], "%f", &echo->decay[echo->num_delays]);
+ echo->num_delays++;
+ }
+ return (ST_SUCCESS);
}
/*
@@ -112,71 +112,71 @@
*/
int st_echo_start(eff_t effp)
{
- echo_t echo = (echo_t) effp->priv;
- int i;
- float sum_in_volume;
- long j;
+ echo_t echo = (echo_t) effp->priv;
+ int i;
+ float sum_in_volume;
+ long j;
- echo->maxsamples = 0L;
- if ( echo->in_gain < 0.0 )
- {
- st_fail("echo: gain-in must be positive!\n");
- return (ST_EOF);
- }
- if ( echo->in_gain > 1.0 )
- {
- st_fail("echo: gain-in must be less than 1.0!\n");
- return (ST_EOF);
- }
- if ( echo->out_gain < 0.0 )
- {
- st_fail("echo: gain-in must be positive!\n");
- return (ST_EOF);
- }
- for ( i = 0; i < echo->num_delays; i++ ) {
- echo->samples[i] = echo->delay[i] * effp->ininfo.rate / 1000.0;
- if ( echo->samples[i] < 1 )
- {
- st_fail("echo: delay must be positive!\n");
- return (ST_EOF);
- }
- if ( echo->samples[i] > DELAY_BUFSIZ )
- {
- st_fail("echo: delay must be less than %g seconds!\n",
- DELAY_BUFSIZ / (float) effp->ininfo.rate );
- return (ST_EOF);
- }
- if ( echo->decay[i] < 0.0 )
- {
- st_fail("echo: decay must be positive!\n" );
- return (ST_EOF);
- }
- if ( echo->decay[i] > 1.0 )
- {
- st_fail("echo: decay must be less than 1.0!\n" );
- return (ST_EOF);
- }
- if ( echo->samples[i] > echo->maxsamples )
- echo->maxsamples = echo->samples[i];
- }
- if (! (echo->delay_buf = (double *) malloc(sizeof (double) * echo->maxsamples)))
- {
- st_fail("echo: Cannot malloc %d bytes!\n",
- sizeof(long) * echo->maxsamples);
- return (ST_EOF);
- }
- for ( j = 0; j < echo->maxsamples; ++j )
- echo->delay_buf[j] = 0.0;
- /* Be nice and check the hint with warning, if... */
- sum_in_volume = 1.0;
- for ( i = 0; i < echo->num_delays; i++ )
- sum_in_volume += echo->decay[i];
- if ( sum_in_volume * echo->in_gain > 1.0 / echo->out_gain )
- st_warn("echo: warning >>> gain-out can cause saturation of output <<<");
- echo->counter = 0;
- echo->fade_out = echo->maxsamples;
- return (ST_SUCCESS);
-}
+ echo->maxsamples = 0L;
+ if ( echo->in_gain < 0.0 )
+ {
+ st_fail("echo: gain-in must be positive!\n");
+ return (ST_EOF);
+ }
+ if ( echo->in_gain > 1.0 )
+ {
+ st_fail("echo: gain-in must be less than 1.0!\n");
+ return (ST_EOF);
+ }
+ if ( echo->out_gain < 0.0 )
+ {
+ st_fail("echo: gain-in must be positive!\n");
+ return (ST_EOF);
+ }
+ for ( i = 0; i < echo->num_delays; i++ ) {
+ echo->samples[i] = echo->delay[i] * effp->ininfo.rate / 1000.0;
+ if ( echo->samples[i] < 1 )
+ {
+ st_fail("echo: delay must be positive!\n");
+ return (ST_EOF);
+ }
+ if ( echo->samples[i] > DELAY_BUFSIZ )
+ {
+ st_fail("echo: delay must be less than %g seconds!\n",
+ DELAY_BUFSIZ / (float) effp->ininfo.rate );
+ return (ST_EOF);
+ }
+ if ( echo->decay[i] < 0.0 )
+ {
+ st_fail("echo: decay must be positive!\n" );
+ return (ST_EOF);
+ }
+ if ( echo->decay[i] > 1.0 )
+ {
+ st_fail("echo: decay must be less than 1.0!\n" );
+ return (ST_EOF);
+ }
+ if ( echo->samples[i] > echo->maxsamples )
+ echo->maxsamples = echo->samples[i];
+ }
+ if (! (echo->delay_buf = (double *) malloc(sizeof (double) * echo->maxsamples)))
+ {
+ st_fail("echo: Cannot malloc %d bytes!\n",
+ sizeof(long) * echo->maxsamples);
+ return (ST_EOF);
+ }
+ for ( j = 0; j < echo->maxsamples; ++j )
+ echo->delay_buf[j] = 0.0;
+ /* Be nice and check the hint with warning, if... */
+ sum_in_volume = 1.0;
+ for ( i = 0; i < echo->num_delays; i++ )
+ sum_in_volume += echo->decay[i];
+ if ( sum_in_volume * echo->in_gain > 1.0 / echo->out_gain )
+ st_warn("echo: warning >>> gain-out can cause saturation of output <<<");
+ echo->counter = 0;
+ echo->fade_out = echo->maxsamples;
+ return (ST_SUCCESS);
+}
/*
* Processed signed long samples from ibuf to obuf.
@@ -185,36 +185,36 @@
int st_echo_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
st_size_t *isamp, st_size_t *osamp)
{
- echo_t echo = (echo_t) effp->priv;
- int len, done;
- int j;
-
- double d_in, d_out;
- st_sample_t out;
+ echo_t echo = (echo_t) effp->priv;
+ int len, done;
+ int j;
+
+ double d_in, d_out;
+ st_sample_t out;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
- /* Store delays as 24-bit signed longs */
- d_in = (double) *ibuf++ / 256;
- /* Compute output first */
- d_out = d_in * echo->in_gain;
- for ( j = 0; j < echo->num_delays; j++ ) {
- d_out += echo->delay_buf[
+ len = ((*isamp > *osamp) ? *osamp : *isamp);
+ for(done = 0; done < len; done++) {
+ /* Store delays as 24-bit signed longs */
+ d_in = (double) *ibuf++ / 256;
+ /* Compute output first */
+ d_out = d_in * echo->in_gain;
+ for ( j = 0; j < echo->num_delays; j++ ) {
+ d_out += echo->delay_buf[
(echo->counter + echo->maxsamples - echo->samples[j]) % echo->maxsamples]
- * echo->decay[j];
- }
- /* Adjust the output volume and size to 24 bit */
- d_out = d_out * echo->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- /* Store input in delay buffer */
- echo->delay_buf[echo->counter] = d_in;
- /* Adjust the counter */
- echo->counter = ( echo->counter + 1 ) % echo->maxsamples;
- }
- /* processed all samples */
- return (ST_SUCCESS);
-}
+ * echo->decay[j];
+ }
+ /* Adjust the output volume and size to 24 bit */
+ d_out = d_out * echo->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ /* Store input in delay buffer */
+ echo->delay_buf[echo->counter] = d_in;
+ /* Adjust the counter */
+ echo->counter = ( echo->counter + 1 ) % echo->maxsamples;
+ }
+ /* processed all samples */
+ return (ST_SUCCESS);
+}
/*
* Drain out reverb lines.
@@ -221,37 +221,37 @@
*/
int st_echo_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
- echo_t echo = (echo_t) effp->priv;
- double d_in, d_out;
- st_sample_t out;
- int j;
- long done;
+ echo_t echo = (echo_t) effp->priv;
+ double d_in, d_out;
+ st_sample_t out;
+ int j;
+ st_size_t done;
- done = 0;
- /* drain out delay samples */
- while ( ( done < *osamp ) && ( done < echo->fade_out ) ) {
- d_in = 0;
- d_out = 0;
- for ( j = 0; j < echo->num_delays; j++ ) {
- d_out += echo->delay_buf[
+ done = 0;
+ /* drain out delay samples */
+ while ( ( done < *osamp ) && ( done < echo->fade_out ) ) {
+ d_in = 0;
+ d_out = 0;
+ for ( j = 0; j < echo->num_delays; j++ ) {
+ d_out += echo->delay_buf[
(echo->counter + echo->maxsamples - echo->samples[j]) % echo->maxsamples]
- * echo->decay[j];
- }
- /* Adjust the output volume and size to 24 bit */
- d_out = d_out * echo->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- /* Store input in delay buffer */
- echo->delay_buf[echo->counter] = d_in;
- /* Adjust the counters */
- echo->counter = ( echo->counter + 1 ) % echo->maxsamples;
- done++;
- echo->fade_out--;
- };
- /* samples played, it remains */
- *osamp = done;
- return (ST_SUCCESS);
-}
+ * echo->decay[j];
+ }
+ /* Adjust the output volume and size to 24 bit */
+ d_out = d_out * echo->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ /* Store input in delay buffer */
+ echo->delay_buf[echo->counter] = d_in;
+ /* Adjust the counters */
+ echo->counter = ( echo->counter + 1 ) % echo->maxsamples;
+ done++;
+ echo->fade_out--;
+ };
+ /* samples played, it remains */
+ *osamp = done;
+ return (ST_SUCCESS);
+}
/*
* Clean up reverb effect.
@@ -258,9 +258,9 @@
*/
int st_echo_stop(eff_t effp)
{
- echo_t echo = (echo_t) effp->priv;
+ echo_t echo = (echo_t) effp->priv;
- free((char *) echo->delay_buf);
- echo->delay_buf = (double *) -1; /* guaranteed core dump */
- return (ST_SUCCESS);
+ free((char *) echo->delay_buf);
+ echo->delay_buf = (double *) -1; /* guaranteed core dump */
+ return (ST_SUCCESS);
}
--- a/src/echos.c
+++ b/src/echos.c
@@ -51,17 +51,17 @@
#include "st_i.h"
#define DELAY_BUFSIZ ( 50L * ST_MAXRATE )
-#define MAX_ECHOS 7 /* 24 bit x ( 1 + MAX_ECHOS ) = */
- /* 24 bit x 8 = 32 bit !!! */
+#define MAX_ECHOS 7 /* 24 bit x ( 1 + MAX_ECHOS ) = */
+ /* 24 bit x 8 = 32 bit !!! */
/* Private data for SKEL file */
typedef struct echosstuff {
- int counter[MAX_ECHOS];
- int num_delays;
- double *delay_buf;
- float in_gain, out_gain;
- float delay[MAX_ECHOS], decay[MAX_ECHOS];
- st_ssize_t samples[MAX_ECHOS], pointer[MAX_ECHOS], sumsamples;
+ int counter[MAX_ECHOS];
+ int num_delays;
+ double *delay_buf;
+ float in_gain, out_gain;
+ float delay[MAX_ECHOS], decay[MAX_ECHOS];
+ st_ssize_t samples[MAX_ECHOS], pointer[MAX_ECHOS], sumsamples;
} *echos_t;
/* Private data for SKEL file */
@@ -71,35 +71,35 @@
*/
int st_echos_getopts(eff_t effp, int n, char **argv)
{
- echos_t echos = (echos_t) effp->priv;
- int i;
+ echos_t echos = (echos_t) effp->priv;
+ int i;
- echos->num_delays = 0;
+ echos->num_delays = 0;
- if ((n < 4) || (n % 2))
- {
- st_fail("Usage: echos gain-in gain-out delay decay [ delay decay ... ]");
- return (ST_EOF);
- }
+ if ((n < 4) || (n % 2))
+ {
+ st_fail("Usage: echos gain-in gain-out delay decay [ delay decay ... ]");
+ return (ST_EOF);
+ }
- i = 0;
- sscanf(argv[i++], "%f", &echos->in_gain);
- sscanf(argv[i++], "%f", &echos->out_gain);
- while (i < n) {
- /* Linux bug and it's cleaner. */
- sscanf(argv[i++], "%f", &echos->delay[echos->num_delays]);
- sscanf(argv[i++], "%f", &echos->decay[echos->num_delays]);
- echos->num_delays++;
- if ( echos->num_delays > MAX_ECHOS )
- {
- st_fail("echos: to many delays, use less than %i delays",
- MAX_ECHOS);
- return (ST_EOF);
- }
- }
- echos->sumsamples = 0;
- return (ST_SUCCESS);
-}
+ i = 0;
+ sscanf(argv[i++], "%f", &echos->in_gain);
+ sscanf(argv[i++], "%f", &echos->out_gain);
+ while (i < n) {
+ /* Linux bug and it's cleaner. */
+ sscanf(argv[i++], "%f", &echos->delay[echos->num_delays]);
+ sscanf(argv[i++], "%f", &echos->decay[echos->num_delays]);
+ echos->num_delays++;
+ if ( echos->num_delays > MAX_ECHOS )
+ {
+ st_fail("echos: to many delays, use less than %i delays",
+ MAX_ECHOS);
+ return (ST_EOF);
+ }
+ }
+ echos->sumsamples = 0;
+ return (ST_SUCCESS);
+}
/*
* Prepare for processing.
@@ -106,69 +106,69 @@
*/
int st_echos_start(eff_t effp)
{
- echos_t echos = (echos_t) effp->priv;
- int i;
- float sum_in_volume;
- long j;
+ echos_t echos = (echos_t) effp->priv;
+ int i;
+ float sum_in_volume;
+ long j;
- if ( echos->in_gain < 0.0 )
- {
- st_fail("echos: gain-in must be positive!\n");
- return (ST_EOF);
- }
- if ( echos->in_gain > 1.0 )
- {
- st_fail("echos: gain-in must be less than 1.0!\n");
- return (ST_EOF);
- }
- if ( echos->out_gain < 0.0 )
- {
- st_fail("echos: gain-in must be positive!\n");
- return (ST_EOF);
- }
- for ( i = 0; i < echos->num_delays; i++ ) {
- echos->samples[i] = echos->delay[i] * effp->ininfo.rate / 1000.0;
- if ( echos->samples[i] < 1 )
- {
- st_fail("echos: delay must be positive!\n");
- return (ST_EOF);
- }
- if ( echos->samples[i] > DELAY_BUFSIZ )
- {
- st_fail("echos: delay must be less than %g seconds!\n",
- DELAY_BUFSIZ / (float) effp->ininfo.rate );
- return (ST_EOF);
- }
- if ( echos->decay[i] < 0.0 )
- {
- st_fail("echos: decay must be positive!\n" );
- return (ST_EOF);
- }
- if ( echos->decay[i] > 1.0 )
- {
- st_fail("echos: decay must be less than 1.0!\n" );
- return (ST_EOF);
- }
- echos->counter[i] = 0;
- echos->pointer[i] = echos->sumsamples;
- echos->sumsamples += echos->samples[i];
- }
- if (! (echos->delay_buf = (double *) malloc(sizeof (double) * echos->sumsamples)))
- {
- st_fail("echos: Cannot malloc %d bytes!\n",
- sizeof(double) * echos->sumsamples);
- return(ST_EOF);
- }
- for ( j = 0; j < echos->sumsamples; ++j )
- echos->delay_buf[j] = 0.0;
- /* Be nice and check the hint with warning, if... */
- sum_in_volume = 1.0;
- for ( i = 0; i < echos->num_delays; i++ )
- sum_in_volume += echos->decay[i];
- if ( sum_in_volume * echos->in_gain > 1.0 / echos->out_gain )
- st_warn("echos: warning >>> gain-out can cause saturation of output <<<");
- return (ST_SUCCESS);
-}
+ if ( echos->in_gain < 0.0 )
+ {
+ st_fail("echos: gain-in must be positive!\n");
+ return (ST_EOF);
+ }
+ if ( echos->in_gain > 1.0 )
+ {
+ st_fail("echos: gain-in must be less than 1.0!\n");
+ return (ST_EOF);
+ }
+ if ( echos->out_gain < 0.0 )
+ {
+ st_fail("echos: gain-in must be positive!\n");
+ return (ST_EOF);
+ }
+ for ( i = 0; i < echos->num_delays; i++ ) {
+ echos->samples[i] = echos->delay[i] * effp->ininfo.rate / 1000.0;
+ if ( echos->samples[i] < 1 )
+ {
+ st_fail("echos: delay must be positive!\n");
+ return (ST_EOF);
+ }
+ if ( echos->samples[i] > DELAY_BUFSIZ )
+ {
+ st_fail("echos: delay must be less than %g seconds!\n",
+ DELAY_BUFSIZ / (float) effp->ininfo.rate );
+ return (ST_EOF);
+ }
+ if ( echos->decay[i] < 0.0 )
+ {
+ st_fail("echos: decay must be positive!\n" );
+ return (ST_EOF);
+ }
+ if ( echos->decay[i] > 1.0 )
+ {
+ st_fail("echos: decay must be less than 1.0!\n" );
+ return (ST_EOF);
+ }
+ echos->counter[i] = 0;
+ echos->pointer[i] = echos->sumsamples;
+ echos->sumsamples += echos->samples[i];
+ }
+ if (! (echos->delay_buf = (double *) malloc(sizeof (double) * echos->sumsamples)))
+ {
+ st_fail("echos: Cannot malloc %d bytes!\n",
+ sizeof(double) * echos->sumsamples);
+ return(ST_EOF);
+ }
+ for ( j = 0; j < echos->sumsamples; ++j )
+ echos->delay_buf[j] = 0.0;
+ /* Be nice and check the hint with warning, if... */
+ sum_in_volume = 1.0;
+ for ( i = 0; i < echos->num_delays; i++ )
+ sum_in_volume += echos->decay[i];
+ if ( sum_in_volume * echos->in_gain > 1.0 / echos->out_gain )
+ st_warn("echos: warning >>> gain-out can cause saturation of output <<<");
+ return (ST_SUCCESS);
+}
/*
* Processed signed long samples from ibuf to obuf.
@@ -177,42 +177,42 @@
int st_echos_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
st_size_t *isamp, st_size_t *osamp)
{
- echos_t echos = (echos_t) effp->priv;
- int len, done;
- int j;
-
- double d_in, d_out;
- st_sample_t out;
+ echos_t echos = (echos_t) effp->priv;
+ int len, done;
+ int j;
+
+ double d_in, d_out;
+ st_sample_t out;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
- /* Store delays as 24-bit signed longs */
- d_in = (double) *ibuf++ / 256;
- /* Compute output first */
- d_out = d_in * echos->in_gain;
- for ( j = 0; j < echos->num_delays; j++ ) {
- d_out += echos->delay_buf[echos->counter[j] + echos->pointer[j]] * echos->decay[j];
- }
- /* Adjust the output volume and size to 24 bit */
- d_out = d_out * echos->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- /* Mix decay of delays and input */
- for ( j = 0; j < echos->num_delays; j++ ) {
- if ( j == 0 )
- echos->delay_buf[echos->counter[j] + echos->pointer[j]] = d_in;
- else
- echos->delay_buf[echos->counter[j] + echos->pointer[j]] =
- echos->delay_buf[echos->counter[j-1] + echos->pointer[j-1]] + d_in;
- }
- /* Adjust the counters */
- for ( j = 0; j < echos->num_delays; j++ )
- echos->counter[j] =
- ( echos->counter[j] + 1 ) % echos->samples[j];
- }
- /* processed all samples */
- return (ST_SUCCESS);
-}
+ len = ((*isamp > *osamp) ? *osamp : *isamp);
+ for(done = 0; done < len; done++) {
+ /* Store delays as 24-bit signed longs */
+ d_in = (double) *ibuf++ / 256;
+ /* Compute output first */
+ d_out = d_in * echos->in_gain;
+ for ( j = 0; j < echos->num_delays; j++ ) {
+ d_out += echos->delay_buf[echos->counter[j] + echos->pointer[j]] * echos->decay[j];
+ }
+ /* Adjust the output volume and size to 24 bit */
+ d_out = d_out * echos->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ /* Mix decay of delays and input */
+ for ( j = 0; j < echos->num_delays; j++ ) {
+ if ( j == 0 )
+ echos->delay_buf[echos->counter[j] + echos->pointer[j]] = d_in;
+ else
+ echos->delay_buf[echos->counter[j] + echos->pointer[j]] =
+ echos->delay_buf[echos->counter[j-1] + echos->pointer[j-1]] + d_in;
+ }
+ /* Adjust the counters */
+ for ( j = 0; j < echos->num_delays; j++ )
+ echos->counter[j] =
+ ( echos->counter[j] + 1 ) % echos->samples[j];
+ }
+ /* processed all samples */
+ return (ST_SUCCESS);
+}
/*
* Drain out reverb lines.
@@ -219,43 +219,43 @@
*/
int st_echos_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
- echos_t echos = (echos_t) effp->priv;
- double d_in, d_out;
- st_sample_t out;
- int j;
- long done;
+ echos_t echos = (echos_t) effp->priv;
+ double d_in, d_out;
+ st_sample_t out;
+ int j;
+ st_size_t done;
- done = 0;
- /* drain out delay samples */
- while ( ( done < *osamp ) && ( done < echos->sumsamples ) ) {
- d_in = 0;
- d_out = 0;
- for ( j = 0; j < echos->num_delays; j++ ) {
- d_out += echos->delay_buf[echos->counter[j] + echos->pointer[j]] * echos->decay[j];
- }
- /* Adjust the output volume and size to 24 bit */
- d_out = d_out * echos->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- /* Mix decay of delays and input */
- for ( j = 0; j < echos->num_delays; j++ ) {
- if ( j == 0 )
- echos->delay_buf[echos->counter[j] + echos->pointer[j]] = d_in;
- else
- echos->delay_buf[echos->counter[j] + echos->pointer[j]] =
- echos->delay_buf[echos->counter[j-1] + echos->pointer[j-1]];
- }
- /* Adjust the counters */
- for ( j = 0; j < echos->num_delays; j++ )
- echos->counter[j] =
- ( echos->counter[j] + 1 ) % echos->samples[j];
- done++;
- echos->sumsamples--;
- };
- /* samples played, it remains */
- *osamp = done;
- return (ST_SUCCESS);
-}
+ done = 0;
+ /* drain out delay samples */
+ while ( ( done < *osamp ) && ( done < echos->sumsamples ) ) {
+ d_in = 0;
+ d_out = 0;
+ for ( j = 0; j < echos->num_delays; j++ ) {
+ d_out += echos->delay_buf[echos->counter[j] + echos->pointer[j]] * echos->decay[j];
+ }
+ /* Adjust the output volume and size to 24 bit */
+ d_out = d_out * echos->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ /* Mix decay of delays and input */
+ for ( j = 0; j < echos->num_delays; j++ ) {
+ if ( j == 0 )
+ echos->delay_buf[echos->counter[j] + echos->pointer[j]] = d_in;
+ else
+ echos->delay_buf[echos->counter[j] + echos->pointer[j]] =
+ echos->delay_buf[echos->counter[j-1] + echos->pointer[j-1]];
+ }
+ /* Adjust the counters */
+ for ( j = 0; j < echos->num_delays; j++ )
+ echos->counter[j] =
+ ( echos->counter[j] + 1 ) % echos->samples[j];
+ done++;
+ echos->sumsamples--;
+ };
+ /* samples played, it remains */
+ *osamp = done;
+ return (ST_SUCCESS);
+}
/*
* Clean up echos effect.
@@ -262,10 +262,10 @@
*/
int st_echos_stop(eff_t effp)
{
- echos_t echos = (echos_t) effp->priv;
+ echos_t echos = (echos_t) effp->priv;
- free((char *) echos->delay_buf);
- echos->delay_buf = (double *) -1; /* guaranteed core dump */
- return (ST_SUCCESS);
+ free((char *) echos->delay_buf);
+ echos->delay_buf = (double *) -1; /* guaranteed core dump */
+ return (ST_SUCCESS);
}
--- a/src/flanger.c
+++ b/src/flanger.c
@@ -8,7 +8,7 @@
*/
/*
- * Flanger effect.
+ * Flanger effect.
*
* Flow diagram scheme:
*
@@ -57,21 +57,21 @@
#include <string.h>
#include "st_i.h"
-#define MOD_SINE 0
-#define MOD_TRIANGLE 1
+#define MOD_SINE 0
+#define MOD_TRIANGLE 1
/* Private data for SKEL file */
typedef struct flangerstuff {
- int modulation;
- int counter;
- int phase;
- double *flangerbuf;
- float in_gain, out_gain;
- float delay, decay;
- float speed;
- st_size_t length;
- int *lookup_tab;
- st_size_t maxsamples, fade_out;
+ int modulation;
+ int counter;
+ int phase;
+ double *flangerbuf;
+ float in_gain, out_gain;
+ float delay, decay;
+ float speed;
+ st_size_t length;
+ int *lookup_tab;
+ st_size_t maxsamples, fade_out;
} *flanger_t;
/* Private data for SKEL file */
@@ -81,33 +81,33 @@
*/
int st_flanger_getopts(eff_t effp, int n, char **argv)
{
- flanger_t flanger = (flanger_t) effp->priv;
+ flanger_t flanger = (flanger_t) effp->priv;
- if (!((n == 5) || (n == 6)))
- {
- st_fail("Usage: flanger gain-in gain-out delay decay speed [ -s | -t ]");
- return (ST_EOF);
- }
+ if (!((n == 5) || (n == 6)))
+ {
+ st_fail("Usage: flanger gain-in gain-out delay decay speed [ -s | -t ]");
+ return (ST_EOF);
+ }
- sscanf(argv[0], "%f", &flanger->in_gain);
- sscanf(argv[1], "%f", &flanger->out_gain);
- sscanf(argv[2], "%f", &flanger->delay);
- sscanf(argv[3], "%f", &flanger->decay);
- sscanf(argv[4], "%f", &flanger->speed);
- flanger->modulation = MOD_SINE;
- if ( n == 6 ) {
- if ( !strcmp(argv[5], "-s"))
- flanger->modulation = MOD_SINE;
- else if ( ! strcmp(argv[5], "-t"))
- flanger->modulation = MOD_TRIANGLE;
- else
- {
- st_fail("Usage: flanger gain-in gain-out delay decay speed [ -s | -t ]");
- return (ST_EOF);
- }
- }
- return (ST_SUCCESS);
-}
+ sscanf(argv[0], "%f", &flanger->in_gain);
+ sscanf(argv[1], "%f", &flanger->out_gain);
+ sscanf(argv[2], "%f", &flanger->delay);
+ sscanf(argv[3], "%f", &flanger->decay);
+ sscanf(argv[4], "%f", &flanger->speed);
+ flanger->modulation = MOD_SINE;
+ if ( n == 6 ) {
+ if ( !strcmp(argv[5], "-s"))
+ flanger->modulation = MOD_SINE;
+ else if ( ! strcmp(argv[5], "-t"))
+ flanger->modulation = MOD_TRIANGLE;
+ else
+ {
+ st_fail("Usage: flanger gain-in gain-out delay decay speed [ -s | -t ]");
+ return (ST_EOF);
+ }
+ }
+ return (ST_SUCCESS);
+}
/*
* Prepare for processing.
@@ -114,91 +114,91 @@
*/
int st_flanger_start(eff_t effp)
{
- flanger_t flanger = (flanger_t) effp->priv;
- int i;
+ flanger_t flanger = (flanger_t) effp->priv;
+ unsigned int i;
- flanger->maxsamples = flanger->delay * effp->ininfo.rate / 1000.0;
+ flanger->maxsamples = flanger->delay * effp->ininfo.rate / 1000.0;
- if ( flanger->in_gain < 0.0 )
- {
- st_fail("flanger: gain-in must be positive!\n");
- return (ST_EOF);
- }
- if ( flanger->in_gain > 1.0 )
- {
- st_fail("flanger: gain-in must be less than 1.0!\n");
- return (ST_EOF);
- }
- if ( flanger->out_gain < 0.0 )
- {
- st_fail("flanger: gain-out must be positive!\n");
- return (ST_EOF);
- }
- if ( flanger->delay < 0.0 )
- {
- st_fail("flanger: delay must be positive!\n");
- return (ST_EOF);
- }
- if ( flanger->delay > 5.0 )
- {
- st_fail("flanger: delay must be less than 5.0 msec!\n");
- return (ST_EOF);
- }
- if ( flanger->speed < 0.1 )
- {
- st_fail("flanger: speed must be more than 0.1 Hz!\n");
- return (ST_EOF);
- }
- if ( flanger->speed > 2.0 )
- {
- st_fail("flanger: speed must be less than 2.0 Hz!\n");
- return (ST_EOF);
- }
- if ( flanger->decay < 0.0 )
- {
- st_fail("flanger: decay must be positive!\n" );
- return (ST_EOF);
- }
- if ( flanger->decay > 1.0 )
- {
- st_fail("flanger: decay must be less that 1.0!\n" );
- return (ST_EOF);
- }
- /* Be nice and check the hint with warning, if... */
- if ( flanger->in_gain * ( 1.0 + flanger->decay ) > 1.0 / flanger->out_gain )
- st_warn("flanger: warning >>> gain-out can cause saturation or clipping of output <<<");
+ if ( flanger->in_gain < 0.0 )
+ {
+ st_fail("flanger: gain-in must be positive!\n");
+ return (ST_EOF);
+ }
+ if ( flanger->in_gain > 1.0 )
+ {
+ st_fail("flanger: gain-in must be less than 1.0!\n");
+ return (ST_EOF);
+ }
+ if ( flanger->out_gain < 0.0 )
+ {
+ st_fail("flanger: gain-out must be positive!\n");
+ return (ST_EOF);
+ }
+ if ( flanger->delay < 0.0 )
+ {
+ st_fail("flanger: delay must be positive!\n");
+ return (ST_EOF);
+ }
+ if ( flanger->delay > 5.0 )
+ {
+ st_fail("flanger: delay must be less than 5.0 msec!\n");
+ return (ST_EOF);
+ }
+ if ( flanger->speed < 0.1 )
+ {
+ st_fail("flanger: speed must be more than 0.1 Hz!\n");
+ return (ST_EOF);
+ }
+ if ( flanger->speed > 2.0 )
+ {
+ st_fail("flanger: speed must be less than 2.0 Hz!\n");
+ return (ST_EOF);
+ }
+ if ( flanger->decay < 0.0 )
+ {
+ st_fail("flanger: decay must be positive!\n" );
+ return (ST_EOF);
+ }
+ if ( flanger->decay > 1.0 )
+ {
+ st_fail("flanger: decay must be less that 1.0!\n" );
+ return (ST_EOF);
+ }
+ /* Be nice and check the hint with warning, if... */
+ if ( flanger->in_gain * ( 1.0 + flanger->decay ) > 1.0 / flanger->out_gain )
+ st_warn("flanger: warning >>> gain-out can cause saturation or clipping of output <<<");
- flanger->length = effp->ininfo.rate / flanger->speed;
+ flanger->length = effp->ininfo.rate / flanger->speed;
- if (! (flanger->flangerbuf =
- (double *) malloc(sizeof (double) * flanger->maxsamples)))
- {
- st_fail("flanger: Cannot malloc %d bytes!\n",
- sizeof(double) * flanger->maxsamples);
- return (ST_EOF);
- }
- for ( i = 0; i < flanger->maxsamples; i++ )
- flanger->flangerbuf[i] = 0.0;
- if (! (flanger->lookup_tab =
- (int *) malloc(sizeof (int) * flanger->length)))
- {
- st_fail("flanger: Cannot malloc %d bytes!\n",
- sizeof(int) * flanger->length);
- return(ST_EOF);
- }
+ if (! (flanger->flangerbuf =
+ (double *) malloc(sizeof (double) * flanger->maxsamples)))
+ {
+ st_fail("flanger: Cannot malloc %d bytes!\n",
+ sizeof(double) * flanger->maxsamples);
+ return (ST_EOF);
+ }
+ for ( i = 0; i < flanger->maxsamples; i++ )
+ flanger->flangerbuf[i] = 0.0;
+ if (! (flanger->lookup_tab =
+ (int *) malloc(sizeof (int) * flanger->length)))
+ {
+ st_fail("flanger: Cannot malloc %d bytes!\n",
+ sizeof(int) * flanger->length);
+ return(ST_EOF);
+ }
- if ( flanger->modulation == MOD_SINE )
- st_sine(flanger->lookup_tab, flanger->length,
- flanger->maxsamples - 1,
- flanger->maxsamples - 1);
- else
- st_triangle(flanger->lookup_tab, flanger->length,
- (flanger->maxsamples - 1) * 2,
- flanger->maxsamples - 1);
- flanger->counter = 0;
- flanger->phase = 0;
- flanger->fade_out = flanger->maxsamples;
- return (ST_SUCCESS);
+ if ( flanger->modulation == MOD_SINE )
+ st_sine(flanger->lookup_tab, flanger->length,
+ flanger->maxsamples - 1,
+ flanger->maxsamples - 1);
+ else
+ st_triangle(flanger->lookup_tab, flanger->length,
+ (flanger->maxsamples - 1) * 2,
+ flanger->maxsamples - 1);
+ flanger->counter = 0;
+ flanger->phase = 0;
+ flanger->fade_out = flanger->maxsamples;
+ return (ST_SUCCESS);
}
/*
@@ -208,33 +208,33 @@
int st_flanger_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
st_size_t *isamp, st_size_t *osamp)
{
- flanger_t flanger = (flanger_t) effp->priv;
- int len, done;
-
- double d_in, d_out;
- st_sample_t out;
+ flanger_t flanger = (flanger_t) effp->priv;
+ int len, done;
+
+ double d_in, d_out;
+ st_sample_t out;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
- /* Store delays as 24-bit signed longs */
- d_in = (double) *ibuf++ / 256;
- /* Compute output first */
- d_out = d_in * flanger->in_gain;
- d_out += flanger->flangerbuf[(flanger->maxsamples +
- flanger->counter - flanger->lookup_tab[flanger->phase]) %
- flanger->maxsamples] * flanger->decay;
- /* Adjust the output volume and size to 24 bit */
- d_out = d_out * flanger->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- /* Mix decay of delay and input */
- flanger->flangerbuf[flanger->counter] = d_in;
- flanger->counter =
- ( flanger->counter + 1 ) % flanger->maxsamples;
- flanger->phase = ( flanger->phase + 1 ) % flanger->length;
- }
- /* processed all samples */
- return (ST_SUCCESS);
+ len = ((*isamp > *osamp) ? *osamp : *isamp);
+ for(done = 0; done < len; done++) {
+ /* Store delays as 24-bit signed longs */
+ d_in = (double) *ibuf++ / 256;
+ /* Compute output first */
+ d_out = d_in * flanger->in_gain;
+ d_out += flanger->flangerbuf[(flanger->maxsamples +
+ flanger->counter - flanger->lookup_tab[flanger->phase]) %
+ flanger->maxsamples] * flanger->decay;
+ /* Adjust the output volume and size to 24 bit */
+ d_out = d_out * flanger->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ /* Mix decay of delay and input */
+ flanger->flangerbuf[flanger->counter] = d_in;
+ flanger->counter =
+ ( flanger->counter + 1 ) % flanger->maxsamples;
+ flanger->phase = ( flanger->phase + 1 ) % flanger->length;
+ }
+ /* processed all samples */
+ return (ST_SUCCESS);
}
/*
@@ -242,35 +242,35 @@
*/
int st_flanger_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
- flanger_t flanger = (flanger_t) effp->priv;
- int done;
-
- double d_in, d_out;
- st_sample_t out;
+ flanger_t flanger = (flanger_t) effp->priv;
+ st_size_t done;
+
+ double d_in, d_out;
+ st_sample_t out;
- done = 0;
- while ( ( done < *osamp ) && ( done < flanger->fade_out ) ) {
- d_in = 0;
- d_out = 0;
- /* Compute output first */
- d_out += flanger->flangerbuf[(flanger->maxsamples +
- flanger->counter - flanger->lookup_tab[flanger->phase]) %
- flanger->maxsamples] * flanger->decay;
- /* Adjust the output volume and size to 24 bit */
- d_out = d_out * flanger->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- /* Mix decay of delay and input */
- flanger->flangerbuf[flanger->counter] = d_in;
- flanger->counter =
- ( flanger->counter + 1 ) % flanger->maxsamples;
- flanger->phase = ( flanger->phase + 1 ) % flanger->length;
- done++;
- flanger->fade_out--;
- }
- /* samples playd, it remains */
- *osamp = done;
- return (ST_SUCCESS);
+ done = 0;
+ while ( ( done < *osamp ) && ( done < flanger->fade_out ) ) {
+ d_in = 0;
+ d_out = 0;
+ /* Compute output first */
+ d_out += flanger->flangerbuf[(flanger->maxsamples +
+ flanger->counter - flanger->lookup_tab[flanger->phase]) %
+ flanger->maxsamples] * flanger->decay;
+ /* Adjust the output volume and size to 24 bit */
+ d_out = d_out * flanger->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ /* Mix decay of delay and input */
+ flanger->flangerbuf[flanger->counter] = d_in;
+ flanger->counter =
+ ( flanger->counter + 1 ) % flanger->maxsamples;
+ flanger->phase = ( flanger->phase + 1 ) % flanger->length;
+ done++;
+ flanger->fade_out--;
+ }
+ /* samples playd, it remains */
+ *osamp = done;
+ return (ST_SUCCESS);
}
/*
@@ -278,11 +278,11 @@
*/
int st_flanger_stop(eff_t effp)
{
- flanger_t flanger = (flanger_t) effp->priv;
+ flanger_t flanger = (flanger_t) effp->priv;
- free((char *) flanger->flangerbuf);
- flanger->flangerbuf = (double *) -1; /* guaranteed core dump */
- free((char *) flanger->lookup_tab);
- flanger->lookup_tab = (int *) -1; /* guaranteed core dump */
- return (ST_SUCCESS);
+ free((char *) flanger->flangerbuf);
+ flanger->flangerbuf = (double *) -1; /* guaranteed core dump */
+ free((char *) flanger->lookup_tab);
+ flanger->lookup_tab = (int *) -1; /* guaranteed core dump */
+ return (ST_SUCCESS);
}
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -392,7 +392,7 @@
st_wvestartread, st_wveread, st_rawstopread,
st_wvestartwrite, st_wvewrite, st_wvestopwrite, st_wveseek},
{0, 0,
- 0, 0, 0, 0, 0, 0}
+ 0, 0, 0, 0, 0, 0, 0}
};
/* Effects handlers. */
--- a/src/ima_rw.c
+++ b/src/ima_rw.c
@@ -1,7 +1,7 @@
/*
- ima_rw.c -- codex utilities for WAV_FORMAT_IMA_ADPCM
-
- Copyright (C) 1999 Stanley J. Brooks <stabro@megsinet.net>
+ ima_rw.c -- codex utilities for WAV_FORMAT_IMA_ADPCM
+
+ Copyright (C) 1999 Stanley J. Brooks <stabro@megsinet.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -33,14 +33,14 @@
#define ISSTMAX 88
static const int imaStepSizeTable[ISSTMAX + 1] = {
- 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34,
- 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143,
- 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494,
- 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552,
- 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, 3660, 4026,
- 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442,
- 11487, 12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623,
- 27086, 29794, 32767
+ 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34,
+ 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143,
+ 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494,
+ 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552,
+ 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, 3660, 4026,
+ 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442,
+ 11487, 12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623,
+ 27086, 29794, 32767
};
#define imaStateAdjust(c) (((c)<4)? -1:(2*(c)-6))
@@ -53,205 +53,205 @@
void initImaTable(void)
{
- int i,j,k;
- for (i=0; i<=ISSTMAX; i++) {
- for (j=0; j<8; j++) {
- k = i + imaStateAdjust(j);
- if (k<0) k=0;
- else if (k>ISSTMAX) k=ISSTMAX;
- imaStateAdjustTable[i][j] = k;
- }
- }
-}
+ int i,j,k;
+ for (i=0; i<=ISSTMAX; i++) {
+ for (j=0; j<8; j++) {
+ k = i + imaStateAdjust(j);
+ if (k<0) k=0;
+ else if (k>ISSTMAX) k=ISSTMAX;
+ imaStateAdjustTable[i][j] = k;
+ }
+ }
+}
static void ImaExpandS(
- int ch, /* channel number to decode, REQUIRE 0 <= ch < chans */
- int chans, /* total channels */
- const unsigned char *ibuff,/* input buffer[blockAlign] */
- SAMPL *obuff, /* obuff[n] will be output samples */
- int n, /* samples to decode PER channel, REQUIRE n % 8 == 1 */
- int o_inc /* index difference between successive output samples */
+ int ch, /* channel number to decode, REQUIRE 0 <= ch < chans */
+ int chans, /* total channels */
+ const unsigned char *ibuff,/* input buffer[blockAlign] */
+ SAMPL *obuff, /* obuff[n] will be output samples */
+ int n, /* samples to decode PER channel, REQUIRE n % 8 == 1 */
+ int o_inc /* index difference between successive output samples */
)
{
- const unsigned char *ip;
- int i_inc;
- SAMPL *op;
- int i, val, state;
+ const unsigned char *ip;
+ int i_inc;
+ SAMPL *op;
+ int i, val, state;
- ip = ibuff + 4*ch; /* input pointer to 4-byte block state-initializer */
- i_inc = 4*(chans-1); /* amount by which to incr ip after each 4-byte read */
- val = (short)(ip[0] + (ip[1]<<8)); /* need cast for sign-extend */
- state = ip[2];
- if (state > ISSTMAX) {
- st_warn("IMA_ADPCM block ch%d initial-state (%d) out of range\n", ch, state);
- fflush(stderr);
- state = 0;
- }
- /* specs say to ignore ip[3] , but write it as 0 */
- ip += 4+i_inc;
+ ip = ibuff + 4*ch; /* input pointer to 4-byte block state-initializer */
+ i_inc = 4*(chans-1); /* amount by which to incr ip after each 4-byte read */
+ val = (short)(ip[0] + (ip[1]<<8)); /* need cast for sign-extend */
+ state = ip[2];
+ if (state > ISSTMAX) {
+ st_warn("IMA_ADPCM block ch%d initial-state (%d) out of range\n", ch, state);
+ fflush(stderr);
+ state = 0;
+ }
+ /* specs say to ignore ip[3] , but write it as 0 */
+ ip += 4+i_inc;
- op = obuff;
- *op = val; /* 1st output sample for this channel */
- op += o_inc;
+ op = obuff;
+ *op = val; /* 1st output sample for this channel */
+ op += o_inc;
- for (i = 1; i < n; i++) {
- int step,dp,c,cm;
+ for (i = 1; i < n; i++) {
+ int step,dp,c,cm;
- if (i&1) { /* 1st of pair */
- cm = *ip & 0x0f;
- } else {
- cm = (*ip++)>>4;
- if ((i&7) == 0) /* ends the 8-sample input block for this channel */
- ip += i_inc; /* skip ip for next group */
- }
+ if (i&1) { /* 1st of pair */
+ cm = *ip & 0x0f;
+ } else {
+ cm = (*ip++)>>4;
+ if ((i&7) == 0) /* ends the 8-sample input block for this channel */
+ ip += i_inc; /* skip ip for next group */
+ }
- step = imaStepSizeTable[state];
- /* Update the state for the next sample */
- c = cm & 0x07;
- state = imaStateAdjustTable[state][c];
+ step = imaStepSizeTable[state];
+ /* Update the state for the next sample */
+ c = cm & 0x07;
+ state = imaStateAdjustTable[state][c];
-# ifdef STRICT_IMA
- dp = 0;
- if (c & 4) dp += step;
- step = step >> 1;
- if (c & 2) dp += step;
- step = step >> 1;
- if (c & 1) dp += step;
- step = step >> 1;
- dp += step;
-# else
- dp = ((c+c+1) * step) >> 3; /* faster than bit-test & add on my cpu */
-# endif
- if (c != cm) {
- val -= dp;
- if (val<-0x8000) val = -0x8000;
- } else {
- val += dp;
- if (val>0x7fff) val = 0x7fff;
- }
- *op = val;
- op += o_inc;
- }
- return;
-}
+# ifdef STRICT_IMA
+ dp = 0;
+ if (c & 4) dp += step;
+ step = step >> 1;
+ if (c & 2) dp += step;
+ step = step >> 1;
+ if (c & 1) dp += step;
+ step = step >> 1;
+ dp += step;
+# else
+ dp = ((c+c+1) * step) >> 3; /* faster than bit-test & add on my cpu */
+# endif
+ if (c != cm) {
+ val -= dp;
+ if (val<-0x8000) val = -0x8000;
+ } else {
+ val += dp;
+ if (val>0x7fff) val = 0x7fff;
+ }
+ *op = val;
+ op += o_inc;
+ }
+ return;
+}
/* ImaBlockExpandI() outputs interleaved samples into one output buffer */
void ImaBlockExpandI(
- int chans, /* total channels */
- const unsigned char *ibuff,/* input buffer[blockAlign] */
- SAMPL *obuff, /* output samples, n*chans */
- int n /* samples to decode PER channel, REQUIRE n % 8 == 1 */
+ int chans, /* total channels */
+ const unsigned char *ibuff,/* input buffer[blockAlign] */
+ SAMPL *obuff, /* output samples, n*chans */
+ int n /* samples to decode PER channel, REQUIRE n % 8 == 1 */
)
{
- int ch;
- for (ch=0; ch<chans; ch++)
- ImaExpandS(ch, chans, ibuff, obuff+ch, n, chans);
+ int ch;
+ for (ch=0; ch<chans; ch++)
+ ImaExpandS(ch, chans, ibuff, obuff+ch, n, chans);
}
/* ImaBlockExpandM() outputs non-interleaved samples into chan separate output buffers */
void ImaBlockExpandM(
- int chans, /* total channels */
- const unsigned char *ibuff,/* input buffer[blockAlign] */
- SAMPL **obuffs, /* chan output sample buffers, each takes n samples */
- int n /* samples to decode PER channel, REQUIRE n % 8 == 1 */
+ int chans, /* total channels */
+ const unsigned char *ibuff,/* input buffer[blockAlign] */
+ SAMPL **obuffs, /* chan output sample buffers, each takes n samples */
+ int n /* samples to decode PER channel, REQUIRE n % 8 == 1 */
)
{
- int ch;
- for (ch=0; ch<chans; ch++)
- ImaExpandS(ch, chans, ibuff, obuffs[ch], n, 1);
+ int ch;
+ for (ch=0; ch<chans; ch++)
+ ImaExpandS(ch, chans, ibuff, obuffs[ch], n, 1);
}
static int ImaMashS(
- int ch, /* channel number to encode, REQUIRE 0 <= ch < chans */
- int chans, /* total channels */
- SAMPL v0, /* value to use as starting prediction0 */
- const SAMPL *ibuff, /* ibuff[] is interleaved input samples */
- int n, /* samples to encode PER channel, REQUIRE n % 8 == 1 */
- int *st, /* input/output state, REQUIRE 0 <= *st <= ISSTMAX */
- unsigned char *obuff, /* output buffer[blockAlign], or NULL for no output */
- int sho /* nonzero for debug printout */
+ int ch, /* channel number to encode, REQUIRE 0 <= ch < chans */
+ int chans, /* total channels */
+ SAMPL v0, /* value to use as starting prediction0 */
+ const SAMPL *ibuff, /* ibuff[] is interleaved input samples */
+ int n, /* samples to encode PER channel, REQUIRE n % 8 == 1 */
+ int *st, /* input/output state, REQUIRE 0 <= *st <= ISSTMAX */
+ unsigned char *obuff, /* output buffer[blockAlign], or NULL for no output */
+ int sho /* nonzero for debug printout */
)
{
- const SAMPL *ip, *itop;
- unsigned char *op;
- int o_inc = 0; /* set 0 only to shut up gcc's 'might be uninitialized' */
- int i, val;
- int state;
- double d2; /* long long is okay also, speed abt the same */
+ const SAMPL *ip, *itop;
+ unsigned char *op;
+ int o_inc = 0; /* set 0 only to shut up gcc's 'might be uninitialized' */
+ int i, val;
+ int state;
+ double d2; /* long long is okay also, speed abt the same */
- ip = ibuff + ch; /* point ip to 1st input sample for this channel */
- itop = ibuff + n*chans;
- val = *ip - v0; ip += chans;/* 1st input sample for this channel */
- d2 = val*val;/* d2 will be sum of squares of errors, given input v0 and *st */
- val = v0;
+ ip = ibuff + ch; /* point ip to 1st input sample for this channel */
+ itop = ibuff + n*chans;
+ val = *ip - v0; ip += chans;/* 1st input sample for this channel */
+ d2 = val*val;/* d2 will be sum of squares of errors, given input v0 and *st */
+ val = v0;
- op = obuff; /* output pointer (or NULL) */
- if (op) { /* NULL means don't output, just compute the rms error */
- op += 4*ch; /* where to put this channel's 4-byte block state-initializer */
- o_inc = 4*(chans-1); /* amount by which to incr op after each 4-byte written */
- *op++ = val; *op++ = val>>8;
- *op++ = *st; *op++ = 0; /* they could have put a mid-block state-correction here */
- op += o_inc; /* _sigh_ NEVER waste a byte. It's a rule! */
- }
+ op = obuff; /* output pointer (or NULL) */
+ if (op) { /* NULL means don't output, just compute the rms error */
+ op += 4*ch; /* where to put this channel's 4-byte block state-initializer */
+ o_inc = 4*(chans-1); /* amount by which to incr op after each 4-byte written */
+ *op++ = val; *op++ = val>>8;
+ *op++ = *st; *op++ = 0; /* they could have put a mid-block state-correction here */
+ op += o_inc; /* _sigh_ NEVER waste a byte. It's a rule! */
+ }
- state = *st;
+ state = *st;
- for (i = 0; ip < itop; ip+=chans) {
- int step,d,dp,c;
+ for (i = 0; ip < itop; ip+=chans) {
+ int step,d,dp,c;
- d = *ip - val; /* difference between last prediction and current sample */
+ d = *ip - val; /* difference between last prediction and current sample */
- step = imaStepSizeTable[state];
- c = (abs(d)<<2)/step;
- if (c > 7) c = 7;
- /* Update the state for the next sample */
- state = imaStateAdjustTable[state][c];
+ step = imaStepSizeTable[state];
+ c = (abs(d)<<2)/step;
+ if (c > 7) c = 7;
+ /* Update the state for the next sample */
+ state = imaStateAdjustTable[state][c];
- if (op) { /* if we want output, put it in proper place */
- int cm = c;
- if (d<0) cm |= 8;
- if (i&1) { /* odd numbered output */
- *op++ |= (cm<<4);
- if (i == 7) /* ends the 8-sample output block for this channel */
- op += o_inc; /* skip op for next group */
- } else {
- *op = cm;
- }
- i = (i+1) & 0x07;
- }
+ if (op) { /* if we want output, put it in proper place */
+ int cm = c;
+ if (d<0) cm |= 8;
+ if (i&1) { /* odd numbered output */
+ *op++ |= (cm<<4);
+ if (i == 7) /* ends the 8-sample output block for this channel */
+ op += o_inc; /* skip op for next group */
+ } else {
+ *op = cm;
+ }
+ i = (i+1) & 0x07;
+ }
-# ifdef STRICT_IMA
- dp = 0;
- if (c & 4) dp += step;
- step = step >> 1;
- if (c & 2) dp += step;
- step = step >> 1;
- if (c & 1) dp += step;
- step = step >> 1;
- dp += step;
-# else
- dp = ((c+c+1) * step) >> 3; /* faster than bit-test & add on my cpu */
-# endif
- if (d<0) {
- val -= dp;
- if (val<-0x8000) val = -0x8000;
- } else {
- val += dp;
- if (val>0x7fff) val = 0x7fff;
- }
+# ifdef STRICT_IMA
+ dp = 0;
+ if (c & 4) dp += step;
+ step = step >> 1;
+ if (c & 2) dp += step;
+ step = step >> 1;
+ if (c & 1) dp += step;
+ step = step >> 1;
+ dp += step;
+# else
+ dp = ((c+c+1) * step) >> 3; /* faster than bit-test & add on my cpu */
+# endif
+ if (d<0) {
+ val -= dp;
+ if (val<-0x8000) val = -0x8000;
+ } else {
+ val += dp;
+ if (val>0x7fff) val = 0x7fff;
+ }
- {
- int x = *ip - val;
- d2 += x*x;
- }
+ {
+ int x = *ip - val;
+ d2 += x*x;
+ }
- }
- d2 /= n; /* be sure it's non-negative */
- if (sho) {
- fflush(stderr);
- }
- *st = state;
- return (int) sqrt(d2);
+ }
+ d2 /= n; /* be sure it's non-negative */
+ if (sho) {
+ fflush(stderr);
+ }
+ *st = state;
+ return (int) sqrt(d2);
}
/* mash one channel... if you want to use opt>0, 9 is a reasonable value */
@@ -259,72 +259,72 @@
inline
#endif
static void ImaMashChannel(
- int ch, /* channel number to encode, REQUIRE 0 <= ch < chans */
- int chans, /* total channels */
- const SAMPL *ip, /* ip[] is interleaved input samples */
- int n, /* samples to encode PER channel, REQUIRE n % 8 == 1 */
- int *st, /* input/output state, REQUIRE 0 <= *st <= ISSTMAX */
- unsigned char *obuff, /* output buffer[blockAlign] */
- int opt /* non-zero allows some cpu-intensive code to improve output */
+ int ch, /* channel number to encode, REQUIRE 0 <= ch < chans */
+ int chans, /* total channels */
+ const SAMPL *ip, /* ip[] is interleaved input samples */
+ int n, /* samples to encode PER channel, REQUIRE n % 8 == 1 */
+ int *st, /* input/output state, REQUIRE 0 <= *st <= ISSTMAX */
+ unsigned char *obuff, /* output buffer[blockAlign] */
+ int opt /* non-zero allows some cpu-intensive code to improve output */
)
{
- int snext,d;
- int s0,d0;
- int s32,d32;
- int sho = 0;
+ int snext,d;
+ int s0,d0;
+ int s32,d32;
+ int sho = 0;
- s32 = s0 = *st;
- if (opt>0) {
- int low,hi,w;
- int low0,hi0;
- snext = s0;
- d32 = d0 = ImaMashS(ch, chans, ip[0], ip,n,&snext, NULL, sho);
+ s32 = s0 = *st;
+ if (opt>0) {
+ int low,hi,w;
+ int low0,hi0;
+ snext = s0;
+ d32 = d0 = ImaMashS(ch, chans, ip[0], ip,n,&snext, NULL, sho);
- w = 0;
- low=hi=s0;
- low0 = low-opt; if (low0<0) low0=0;
- hi0 = hi+opt; if (hi0>ISSTMAX) hi0=ISSTMAX;
- while (low>low0 || hi<hi0) {
- if (!w && low>low0) {
- int d;
- snext = --low;
- d = ImaMashS(ch, chans, ip[0], ip,n,&snext, NULL, sho);
- if (d<d0) {
- d0=d; s0=low;
- low0 = low-opt; if (low0<0) low0=0;
- hi0 = low+opt; if (hi0>ISSTMAX) hi0=ISSTMAX;
- }
- }
- if (w && hi<hi0) {
- int d;
- snext = ++hi;
- d = ImaMashS(ch, chans, ip[0], ip,n,&snext, NULL, sho);
- if (d<d0) {
- d0=d; s0=hi;
- low0 = hi-opt; if (low0<0) low0=0;
- hi0 = hi+opt; if (hi0>ISSTMAX) hi0=ISSTMAX;
- }
- }
- w=1-w;
- }
- *st = s0;
- }
- d = ImaMashS(ch, chans, ip[0], ip,n,st, obuff, 0);
-}
+ w = 0;
+ low=hi=s0;
+ low0 = low-opt; if (low0<0) low0=0;
+ hi0 = hi+opt; if (hi0>ISSTMAX) hi0=ISSTMAX;
+ while (low>low0 || hi<hi0) {
+ if (!w && low>low0) {
+ int d;
+ snext = --low;
+ d = ImaMashS(ch, chans, ip[0], ip,n,&snext, NULL, sho);
+ if (d<d0) {
+ d0=d; s0=low;
+ low0 = low-opt; if (low0<0) low0=0;
+ hi0 = low+opt; if (hi0>ISSTMAX) hi0=ISSTMAX;
+ }
+ }
+ if (w && hi<hi0) {
+ int d;
+ snext = ++hi;
+ d = ImaMashS(ch, chans, ip[0], ip,n,&snext, NULL, sho);
+ if (d<d0) {
+ d0=d; s0=hi;
+ low0 = hi-opt; if (low0<0) low0=0;
+ hi0 = hi+opt; if (hi0>ISSTMAX) hi0=ISSTMAX;
+ }
+ }
+ w=1-w;
+ }
+ *st = s0;
+ }
+ d = ImaMashS(ch, chans, ip[0], ip,n,st, obuff, 0);
+}
/* mash one block. if you want to use opt>0, 9 is a reasonable value */
void ImaBlockMashI(
- int chans, /* total channels */
- const SAMPL *ip, /* ip[] is interleaved input samples */
- int n, /* samples to encode PER channel, REQUIRE n % 8 == 1 */
- int *st, /* input/output state, REQUIRE 0 <= *st <= ISSTMAX */
- unsigned char *obuff, /* output buffer[blockAlign] */
- int opt /* non-zero allows some cpu-intensive code to improve output */
+ int chans, /* total channels */
+ const SAMPL *ip, /* ip[] is interleaved input samples */
+ int n, /* samples to encode PER channel, REQUIRE n % 8 == 1 */
+ int *st, /* input/output state, REQUIRE 0 <= *st <= ISSTMAX */
+ unsigned char *obuff, /* output buffer[blockAlign] */
+ int opt /* non-zero allows some cpu-intensive code to improve output */
)
{
- int ch;
- for (ch=0; ch<chans; ch++)
- ImaMashChannel(ch, chans, ip, n, st+ch, obuff, opt);
+ int ch;
+ for (ch=0; ch<chans; ch++)
+ ImaMashChannel(ch, chans, ip, n, st+ch, obuff, opt);
}
/*
@@ -351,7 +351,7 @@
n = 0;
m = blockAlign;
}
- if (m >= 4*chans) {
+ if (m >= (st_size_t)4*chans) {
m -= 4*chans; /* number of bytes beyond block-header */
m /= 4*chans; /* number of 4-byte blocks/channel beyond header */
m = 8*m + 1; /* samples/chan beyond header + 1 in header */
@@ -385,63 +385,63 @@
#if 0
static void ImaMashChannel(int ch, const SAMPL *ip, int n, int *st)
{
- int s,snext,d;
- int s0,d0;
- int s32,d32;
- int sho = 0;
- int mx[ISSTMAX+1];
+ int s,snext,d;
+ int s0,d0;
+ int s32,d32;
+ int sho = 0;
+ int mx[ISSTMAX+1];
#if 0
- s32=-1; d32=0x10000;
- for (s=3; s<=ISSTMAX; s += 9) {
- snext = s;
- d = ImaMashS(ch, O.chans, ip[0], ip,n,&snext, NULL, sho);
- if (d<d32) {
- d32=d; s32=s;
- }
- }
+ s32=-1; d32=0x10000;
+ for (s=3; s<=ISSTMAX; s += 9) {
+ snext = s;
+ d = ImaMashS(ch, O.chans, ip[0], ip,n,&snext, NULL, sho);
+ if (d<d32) {
+ d32=d; s32=s;
+ }
+ }
#endif
- s0=-1; d0=0x10000;
- for (s=0; s<=ISSTMAX;s++) {
- snext = s;
- mx[s] = d = ImaMashS(ch, O.chans, ip[0], ip,n,&snext, NULL, sho);
- /* if (s==s32) d32 = d; */
- if (d<d0) {
- d0=d; s0=s;
- }
- }
- s32 = *st;
- d32 = mx[s32];
+ s0=-1; d0=0x10000;
+ for (s=0; s<=ISSTMAX;s++) {
+ snext = s;
+ mx[s] = d = ImaMashS(ch, O.chans, ip[0], ip,n,&snext, NULL, sho);
+ /* if (s==s32) d32 = d; */
+ if (d<d0) {
+ d0=d; s0=s;
+ }
+ }
+ s32 = *st;
+ d32 = mx[s32];
#if 1
- {
- int low,hi,w;
- int low0,hi0;
- w = 0;
- low=hi=s32;
- d32 = mx[s32];
- low0 = low-9; if (low0<0) low0=0;
- hi0 = hi+9; if (hi0>ISSTMAX) hi0=ISSTMAX;
- while (low>low0 || hi<hi0) {
- if (!w && low>low0) {
- if (mx[--low]<d32) {
- d32=mx[low]; s32=low;
- low0 = low-9; if (low0<0) low0=0;
- hi0 = low+9; if (hi0>ISSTMAX) hi0=ISSTMAX;
- }
- }
- if (w && hi<hi0) {
- if (mx[++hi]<d32) {
- d32=mx[hi]; s32=hi;
- low0 = hi-9; if (low0<0) low0=0;
- hi0 = hi+9; if (hi0>ISSTMAX) hi0=ISSTMAX;
- }
- }
- w=1-w;
- }
- }
+ {
+ int low,hi,w;
+ int low0,hi0;
+ w = 0;
+ low=hi=s32;
+ d32 = mx[s32];
+ low0 = low-9; if (low0<0) low0=0;
+ hi0 = hi+9; if (hi0>ISSTMAX) hi0=ISSTMAX;
+ while (low>low0 || hi<hi0) {
+ if (!w && low>low0) {
+ if (mx[--low]<d32) {
+ d32=mx[low]; s32=low;
+ low0 = low-9; if (low0<0) low0=0;
+ hi0 = low+9; if (hi0>ISSTMAX) hi0=ISSTMAX;
+ }
+ }
+ if (w && hi<hi0) {
+ if (mx[++hi]<d32) {
+ d32=mx[hi]; s32=hi;
+ low0 = hi-9; if (low0<0) low0=0;
+ hi0 = hi+9; if (hi0>ISSTMAX) hi0=ISSTMAX;
+ }
+ }
+ w=1-w;
+ }
+ }
#endif
- *st = s0;
- d = ImaMashS(ch, O.chans, ip[0], ip,n,st, O.packet, 0);
+ *st = s0;
+ d = ImaMashS(ch, O.chans, ip[0], ip,n,st, O.packet, 0);
}
#endif
--- a/src/misc.c
+++ b/src/misc.c
@@ -49,13 +49,13 @@
"signed (2's complement)",
"u-law",
"a-law",
- "floating point",
+ "floating point",
"adpcm",
"ima_adpcm",
"gsm",
- "inversed u-law",
- "inversed A-law",
- "MPEG audio (layer I, III or III)"
+ "inversed u-law",
+ "inversed A-law",
+ "MPEG audio (layer I, III or III)"
};
static const char readerr[] = "Premature EOF while reading sample file.";
@@ -333,8 +333,8 @@
{
for (; toupper(*s1) == toupper(*s2); ++s1, ++s2)
{
- if (*s1 == '\0')
- return(0);
+ if (*s1 == '\0')
+ return(0);
}
return ((*(unsigned char *)s1 < *(unsigned char *)s2) ? -1 : +1);
}
@@ -450,6 +450,10 @@
* EPERM "Operation not permitted"
*/
if(whence == SEEK_CUR ){
+ /* FIXME: This isn't possible with current
+ * prototype anyways. Should st_seek support negative
+ * offsets?
+ */
if( offset < 0 ){
st_fail_errno(ft,ST_EINVAL,"Can't seek backwards in pipe");
} else {
--- a/src/oss.c
+++ b/src/oss.c
@@ -153,7 +153,7 @@
tmp = ft->info.rate;
if (ioctl (fileno(ft->fp), SNDCTL_DSP_SPEED, &tmp) < 0 ||
- ft->info.rate != tmp) {
+ (int)ft->info.rate != tmp) {
/* If the rate the sound card is using is not within 1% of what
* the user specified then override the user setting.
* The only reason not to always override this is because of
--- a/src/pan.c
+++ b/src/pan.c
@@ -65,10 +65,10 @@
pan->clipped = 0;
if (n && (!sscanf(argv[0], PAN_FLOAT_SCAN, &pan->dir) ||
- pan->dir < MONE || pan->dir > ONE))
+ pan->dir < MONE || pan->dir > ONE))
{
- st_fail(PAN_USAGE);
- return ST_EOF;
+ st_fail(PAN_USAGE);
+ return ST_EOF;
}
return ST_SUCCESS;
@@ -80,13 +80,13 @@
int st_pan_start(eff_t effp)
{
if (effp->outinfo.channels==1)
- st_warn("PAN onto a mono channel...");
+ st_warn("PAN onto a mono channel...");
if (effp->outinfo.rate != effp->ininfo.rate)
{
- st_fail("PAN cannot handle different rates (in=%ld, out=%ld)"
- " use resample or rate", effp->ininfo.rate, effp->outinfo.rate);
- return ST_EOF;
+ st_fail("PAN cannot handle different rates (in=%ld, out=%ld)"
+ " use resample or rate", effp->ininfo.rate, effp->outinfo.rate);
+ return ST_EOF;
}
return ST_SUCCESS;
@@ -101,13 +101,13 @@
{
if (value < -ST_SAMPLE_MAX)
{
- pan->clipped++;
- return -ST_SAMPLE_MAX;
+ pan->clipped++;
+ return -ST_SAMPLE_MAX;
}
else if (value > ST_SAMPLE_MAX)
{
- pan->clipped++;
- return ST_SAMPLE_MAX;
+ pan->clipped++;
+ return ST_SAMPLE_MAX;
} /* else */
return (st_sample_t) value;
@@ -129,7 +129,8 @@
{
pan_t pan = (pan_t) effp->priv;
register st_size_t len;
- register int done, ich, och;
+ st_size_t done;
+ char ich, och;
register PAN_FLOAT left, right, dir, hdir;
dir = pan->dir; /* -1 <= dir <= 1 */
@@ -149,237 +150,237 @@
/* 9 different cases to handle: (1,2,4) X (1,2,4) */
switch (och) {
case 1: /* pan on mono channel... not much sense. just avg. */
- switch (ich) {
- case 1: /* simple copy */
- for (done=0; done<len; done++)
- *obuf++ = *ibuf++;
- break;
- case 2: /* average 2 */
- for (done=0; done<len; done++)
- *obuf++ = clip(pan, HALF*ibuf[0] + HALF*ibuf[1]),
- ibuf += 2;
- break;
- case 4: /* average 4 */
- for (done=0; done<len; done++)
- *obuf++ = clip(pan,
- QUARTER*ibuf[0] + QUARTER*ibuf[1] +
- QUARTER*ibuf[2] + QUARTER*ibuf[3]),
- ibuf += 4;
- break;
- default:
- UNEXPECTED_CHANNELS;
- break;
- } /* end first switch in channel */
- break;
+ switch (ich) {
+ case 1: /* simple copy */
+ for (done=0; done<len; done++)
+ *obuf++ = *ibuf++;
+ break;
+ case 2: /* average 2 */
+ for (done=0; done<len; done++)
+ *obuf++ = clip(pan, HALF*ibuf[0] + HALF*ibuf[1]),
+ ibuf += 2;
+ break;
+ case 4: /* average 4 */
+ for (done=0; done<len; done++)
+ *obuf++ = clip(pan,
+ QUARTER*ibuf[0] + QUARTER*ibuf[1] +
+ QUARTER*ibuf[2] + QUARTER*ibuf[3]),
+ ibuf += 4;
+ break;
+ default:
+ UNEXPECTED_CHANNELS;
+ break;
+ } /* end first switch in channel */
+ break;
case 2:
- switch (ich) {
- case 1: /* linear */
- for (done=0; done<len; done++)
- {
- obuf[0] = clip(pan, left * ibuf[0]);
- obuf[1] = clip(pan, right * ibuf[0]);
- obuf += 2;
- ibuf++;
- }
- break;
- case 2: /* linear panorama.
- * I'm not sure this is the right way to do it.
- */
- if (dir <= ZERO) /* to the left */
- {
- register PAN_FLOAT volume, cll, clr, cr;
+ switch (ich) {
+ case 1: /* linear */
+ for (done=0; done<len; done++)
+ {
+ obuf[0] = clip(pan, left * ibuf[0]);
+ obuf[1] = clip(pan, right * ibuf[0]);
+ obuf += 2;
+ ibuf++;
+ }
+ break;
+ case 2: /* linear panorama.
+ * I'm not sure this is the right way to do it.
+ */
+ if (dir <= ZERO) /* to the left */
+ {
+ register PAN_FLOAT volume, cll, clr, cr;
- volume = ONE - HALF*dir;
- cll = volume*(ONEHALF-left);
- clr = volume*(left-HALF);
- cr = volume*(ONE+dir);
+ volume = ONE - HALF*dir;
+ cll = volume*(ONEHALF-left);
+ clr = volume*(left-HALF);
+ cr = volume*(ONE+dir);
- for (done=0; done<len; done++)
- {
- obuf[0] = clip(pan, cll * ibuf[0] + clr * ibuf[1]);
- obuf[1] = clip(pan, cr * ibuf[1]);
- obuf += 2;
- ibuf += 2;
- }
- }
- else /* to the right */
- {
- register PAN_FLOAT volume, cl, crl, crr;
+ for (done=0; done<len; done++)
+ {
+ obuf[0] = clip(pan, cll * ibuf[0] + clr * ibuf[1]);
+ obuf[1] = clip(pan, cr * ibuf[1]);
+ obuf += 2;
+ ibuf += 2;
+ }
+ }
+ else /* to the right */
+ {
+ register PAN_FLOAT volume, cl, crl, crr;
- volume = ONE + HALF*dir;
- cl = volume*(ONE-dir);
- crl = volume*(right-HALF);
- crr = volume*(ONEHALF-right);
+ volume = ONE + HALF*dir;
+ cl = volume*(ONE-dir);
+ crl = volume*(right-HALF);
+ crr = volume*(ONEHALF-right);
- for (done=0; done<len; done++)
- {
- obuf[0] = clip(pan, cl * ibuf[0]);
- obuf[1] = clip(pan, crl * ibuf[0] + crr * ibuf[1]);
- obuf += 2;
- ibuf += 2;
- }
- }
- break;
- case 4:
- if (dir <= ZERO) /* to the left */
- {
- register PAN_FLOAT volume, cll, clr, cr;
+ for (done=0; done<len; done++)
+ {
+ obuf[0] = clip(pan, cl * ibuf[0]);
+ obuf[1] = clip(pan, crl * ibuf[0] + crr * ibuf[1]);
+ obuf += 2;
+ ibuf += 2;
+ }
+ }
+ break;
+ case 4:
+ if (dir <= ZERO) /* to the left */
+ {
+ register PAN_FLOAT volume, cll, clr, cr;
- volume = ONE - HALF*dir;
- cll = volume*(ONEHALF-left);
- clr = volume*(left-HALF);
- cr = volume*(ONE+dir);
+ volume = ONE - HALF*dir;
+ cll = volume*(ONEHALF-left);
+ clr = volume*(left-HALF);
+ cr = volume*(ONE+dir);
- for (done=0; done<len; done++)
- {
- register PAN_FLOAT ibuf0, ibuf1;
+ for (done=0; done<len; done++)
+ {
+ register PAN_FLOAT ibuf0, ibuf1;
- /* build stereo signal */
- ibuf0 = HALF*ibuf[0] + HALF*ibuf[2];
- ibuf1 = HALF*ibuf[1] + HALF*ibuf[3];
+ /* build stereo signal */
+ ibuf0 = HALF*ibuf[0] + HALF*ibuf[2];
+ ibuf1 = HALF*ibuf[1] + HALF*ibuf[3];
- /* pan it */
- obuf[0] = clip(pan, cll * ibuf0 + clr * ibuf1);
- obuf[1] = clip(pan, cr * ibuf1);
- obuf += 2;
- ibuf += 4;
- }
- }
- else /* to the right */
- {
- register PAN_FLOAT volume, cl, crl, crr;
+ /* pan it */
+ obuf[0] = clip(pan, cll * ibuf0 + clr * ibuf1);
+ obuf[1] = clip(pan, cr * ibuf1);
+ obuf += 2;
+ ibuf += 4;
+ }
+ }
+ else /* to the right */
+ {
+ register PAN_FLOAT volume, cl, crl, crr;
- volume = ONE + HALF*dir;
- cl = volume*(ONE-dir);
- crl = volume*(right-HALF);
- crr = volume*(ONEHALF-right);
+ volume = ONE + HALF*dir;
+ cl = volume*(ONE-dir);
+ crl = volume*(right-HALF);
+ crr = volume*(ONEHALF-right);
- for (done=0; done<len; done++)
- {
- register PAN_FLOAT ibuf0, ibuf1;
+ for (done=0; done<len; done++)
+ {
+ register PAN_FLOAT ibuf0, ibuf1;
- ibuf0 = HALF*ibuf[0] + HALF*ibuf[2];
- ibuf1 = HALF*ibuf[1] + HALF*ibuf[3];
+ ibuf0 = HALF*ibuf[0] + HALF*ibuf[2];
+ ibuf1 = HALF*ibuf[1] + HALF*ibuf[3];
- obuf[0] = clip(pan, cl * ibuf0);
- obuf[1] = clip(pan, crl * ibuf0 + crr * ibuf1);
- obuf += 2;
- ibuf += 4;
- }
- }
- break;
- default:
- UNEXPECTED_CHANNELS;
- break;
- } /* end second switch in channel */
- break;
+ obuf[0] = clip(pan, cl * ibuf0);
+ obuf[1] = clip(pan, crl * ibuf0 + crr * ibuf1);
+ obuf += 2;
+ ibuf += 4;
+ }
+ }
+ break;
+ default:
+ UNEXPECTED_CHANNELS;
+ break;
+ } /* end second switch in channel */
+ break;
case 4:
- switch (ich) {
- case 1: /* linear */
- {
- register PAN_FLOAT cr, cl;
+ switch (ich) {
+ case 1: /* linear */
+ {
+ register PAN_FLOAT cr, cl;
- cl = HALF*left;
- cr = HALF*right;
+ cl = HALF*left;
+ cr = HALF*right;
- for (done=0; done<len; done++)
- {
- obuf[0] = clip(pan, cl * ibuf[0]);
- obuf[2] = obuf[0];
- obuf[1] = clip(pan, cr * ibuf[0]);
- ibuf[3] = obuf[1];
- obuf += 4;
- ibuf++;
- }
- }
- break;
- case 2: /* simple linear panorama */
- if (dir <= ZERO) /* to the left */
- {
- register PAN_FLOAT volume, cll, clr, cr;
+ for (done=0; done<len; done++)
+ {
+ obuf[0] = clip(pan, cl * ibuf[0]);
+ obuf[2] = obuf[0];
+ obuf[1] = clip(pan, cr * ibuf[0]);
+ ibuf[3] = obuf[1];
+ obuf += 4;
+ ibuf++;
+ }
+ }
+ break;
+ case 2: /* simple linear panorama */
+ if (dir <= ZERO) /* to the left */
+ {
+ register PAN_FLOAT volume, cll, clr, cr;
- volume = HALF - QUARTER*dir;
- cll = volume * (ONEHALF-left);
- clr = volume * (left-HALF);
- cr = volume * (ONE+dir);
+ volume = HALF - QUARTER*dir;
+ cll = volume * (ONEHALF-left);
+ clr = volume * (left-HALF);
+ cr = volume * (ONE+dir);
- for (done=0; done<len; done++)
- {
- obuf[0] = clip(pan, cll * ibuf[0] + clr * ibuf[1]);
- obuf[2] = obuf[0];
- obuf[1] = clip(pan, cr * ibuf[1]);
- ibuf[3] = obuf[1];
- obuf += 4;
- ibuf += 2;
- }
- }
- else /* to the right */
- {
- register PAN_FLOAT volume, cl, crl, crr;
+ for (done=0; done<len; done++)
+ {
+ obuf[0] = clip(pan, cll * ibuf[0] + clr * ibuf[1]);
+ obuf[2] = obuf[0];
+ obuf[1] = clip(pan, cr * ibuf[1]);
+ ibuf[3] = obuf[1];
+ obuf += 4;
+ ibuf += 2;
+ }
+ }
+ else /* to the right */
+ {
+ register PAN_FLOAT volume, cl, crl, crr;
- volume = HALF + QUARTER*dir;
- cl = volume * (ONE-dir);
- crl = volume * (right-HALF);
- crr = volume * (ONEHALF-right);
+ volume = HALF + QUARTER*dir;
+ cl = volume * (ONE-dir);
+ crl = volume * (right-HALF);
+ crr = volume * (ONEHALF-right);
- for (done=0; done<len; done++)
- {
- obuf[0] = clip(pan, cl * ibuf[0]);
- obuf[2] = obuf[0];
- obuf[1] = clip(pan, crl * ibuf[0] + crr * ibuf[1]);
- ibuf[3] = obuf[1];
- obuf += 4;
- ibuf += 2;
- }
- }
- break;
- case 4:
- /* maybe I could improve the formula to reverse...
- also, turn only by quarters.
- */
- if (dir <= ZERO) /* to the left */
- {
- register PAN_FLOAT cown, cright;
+ for (done=0; done<len; done++)
+ {
+ obuf[0] = clip(pan, cl * ibuf[0]);
+ obuf[2] = obuf[0];
+ obuf[1] = clip(pan, crl * ibuf[0] + crr * ibuf[1]);
+ ibuf[3] = obuf[1];
+ obuf += 4;
+ ibuf += 2;
+ }
+ }
+ break;
+ case 4:
+ /* maybe I could improve the formula to reverse...
+ also, turn only by quarters.
+ */
+ if (dir <= ZERO) /* to the left */
+ {
+ register PAN_FLOAT cown, cright;
- cright = -dir;
- cown = ONE + dir;
+ cright = -dir;
+ cown = ONE + dir;
- for (done=0; done<len; done++)
- {
- obuf[0] = clip(pan, cown*ibuf[0] + cright*ibuf[1]);
- obuf[1] = clip(pan, cown*ibuf[1] + cright*ibuf[3]);
- obuf[2] = clip(pan, cown*ibuf[2] + cright*ibuf[0]);
- obuf[3] = clip(pan, cown*ibuf[3] + cright*ibuf[2]);
- obuf += 4;
- ibuf += 4;
- }
- }
- else /* to the right */
- {
- register PAN_FLOAT cleft, cown;
+ for (done=0; done<len; done++)
+ {
+ obuf[0] = clip(pan, cown*ibuf[0] + cright*ibuf[1]);
+ obuf[1] = clip(pan, cown*ibuf[1] + cright*ibuf[3]);
+ obuf[2] = clip(pan, cown*ibuf[2] + cright*ibuf[0]);
+ obuf[3] = clip(pan, cown*ibuf[3] + cright*ibuf[2]);
+ obuf += 4;
+ ibuf += 4;
+ }
+ }
+ else /* to the right */
+ {
+ register PAN_FLOAT cleft, cown;
- cleft = dir;
- cown = ONE - dir;
+ cleft = dir;
+ cown = ONE - dir;
- for (done=0; done<len; done++)
- {
- obuf[0] = clip(pan, cleft*ibuf[2] + cown*ibuf[0]);
- obuf[1] = clip(pan, cleft*ibuf[0] + cown*ibuf[1]);
- obuf[2] = clip(pan, cleft*ibuf[3] + cown*ibuf[2]);
- obuf[3] = clip(pan, cleft*ibuf[1] + cown*ibuf[3]);
- obuf += 4;
- ibuf += 4;
- }
- }
- break;
- default:
- UNEXPECTED_CHANNELS;
- break;
- } /* end third switch in channel */
- break;
+ for (done=0; done<len; done++)
+ {
+ obuf[0] = clip(pan, cleft*ibuf[2] + cown*ibuf[0]);
+ obuf[1] = clip(pan, cleft*ibuf[0] + cown*ibuf[1]);
+ obuf[2] = clip(pan, cleft*ibuf[3] + cown*ibuf[2]);
+ obuf[3] = clip(pan, cleft*ibuf[1] + cown*ibuf[3]);
+ obuf += 4;
+ ibuf += 4;
+ }
+ }
+ break;
+ default:
+ UNEXPECTED_CHANNELS;
+ break;
+ } /* end third switch in channel */
+ break;
default:
- UNEXPECTED_CHANNELS;
- break;
+ UNEXPECTED_CHANNELS;
+ break;
} /* end switch out channel */
return ST_SUCCESS;
@@ -395,8 +396,8 @@
{
pan_t pan = (pan_t) effp->priv;
if (pan->clipped) {
- st_warn("PAN clipped %d values, maybe adjust volume?",
- pan->clipped);
+ st_warn("PAN clipped %d values, maybe adjust volume?",
+ pan->clipped);
}
return ST_SUCCESS;
}
--- a/src/phaser.c
+++ b/src/phaser.c
@@ -8,7 +8,7 @@
*/
/*
- * Phaser effect.
+ * Phaser effect.
*
* Flow diagram scheme:
*
@@ -59,21 +59,21 @@
#include <string.h>
#include "st_i.h"
-#define MOD_SINE 0
-#define MOD_TRIANGLE 1
+#define MOD_SINE 0
+#define MOD_TRIANGLE 1
/* Private data for SKEL file */
typedef struct phaserstuff {
- int modulation;
- int counter;
- int phase;
- double *phaserbuf;
- float in_gain, out_gain;
- float delay, decay;
- float speed;
- st_size_t length;
- int *lookup_tab;
- st_size_t maxsamples, fade_out;
+ int modulation;
+ int counter;
+ int phase;
+ double *phaserbuf;
+ float in_gain, out_gain;
+ float delay, decay;
+ float speed;
+ st_size_t length;
+ int *lookup_tab;
+ st_size_t maxsamples, fade_out;
} *phaser_t;
/*
@@ -81,33 +81,33 @@
*/
int st_phaser_getopts(eff_t effp, int n, char **argv)
{
- phaser_t phaser = (phaser_t) effp->priv;
+ phaser_t phaser = (phaser_t) effp->priv;
- if (!((n == 5) || (n == 6)))
- {
- st_fail("Usage: phaser gain-in gain-out delay decay speed [ -s | -t ]");
- return (ST_EOF);
- }
+ if (!((n == 5) || (n == 6)))
+ {
+ st_fail("Usage: phaser gain-in gain-out delay decay speed [ -s | -t ]");
+ return (ST_EOF);
+ }
- sscanf(argv[0], "%f", &phaser->in_gain);
- sscanf(argv[1], "%f", &phaser->out_gain);
- sscanf(argv[2], "%f", &phaser->delay);
- sscanf(argv[3], "%f", &phaser->decay);
- sscanf(argv[4], "%f", &phaser->speed);
- phaser->modulation = MOD_SINE;
- if ( n == 6 ) {
- if ( !strcmp(argv[5], "-s"))
- phaser->modulation = MOD_SINE;
- else if ( ! strcmp(argv[5], "-t"))
- phaser->modulation = MOD_TRIANGLE;
- else
- {
- st_fail("Usage: phaser gain-in gain-out delay decay speed [ -s | -t ]");
- return (ST_EOF);
- }
- }
- return (ST_SUCCESS);
-}
+ sscanf(argv[0], "%f", &phaser->in_gain);
+ sscanf(argv[1], "%f", &phaser->out_gain);
+ sscanf(argv[2], "%f", &phaser->delay);
+ sscanf(argv[3], "%f", &phaser->decay);
+ sscanf(argv[4], "%f", &phaser->speed);
+ phaser->modulation = MOD_SINE;
+ if ( n == 6 ) {
+ if ( !strcmp(argv[5], "-s"))
+ phaser->modulation = MOD_SINE;
+ else if ( ! strcmp(argv[5], "-t"))
+ phaser->modulation = MOD_TRIANGLE;
+ else
+ {
+ st_fail("Usage: phaser gain-in gain-out delay decay speed [ -s | -t ]");
+ return (ST_EOF);
+ }
+ }
+ return (ST_SUCCESS);
+}
/*
* Prepare for processing.
@@ -114,78 +114,78 @@
*/
int st_phaser_start(eff_t effp)
{
- phaser_t phaser = (phaser_t) effp->priv;
- int i;
+ phaser_t phaser = (phaser_t) effp->priv;
+ int i;
- phaser->maxsamples = phaser->delay * effp->ininfo.rate / 1000.0;
+ phaser->maxsamples = phaser->delay * effp->ininfo.rate / 1000.0;
- if ( phaser->delay < 0.0 )
- {
- st_fail("phaser: delay must be positive!\n");
- return (ST_EOF);
- }
- if ( phaser->delay > 5.0 )
- {
- st_fail("phaser: delay must be less than 5.0 msec!\n");
- return (ST_EOF);
- }
- if ( phaser->speed < 0.1 )
- {
- st_fail("phaser: speed must be more than 0.1 Hz!\n");
- return (ST_EOF);
- }
- if ( phaser->speed > 2.0 )
- {
- st_fail("phaser: speed must be less than 2.0 Hz!\n");
- return (ST_EOF);
- }
- if ( phaser->decay < 0.0 )
- {
- st_fail("phaser: decay must be positive!\n" );
- return (ST_EOF);
- }
- if ( phaser->decay >= 1.0 )
- {
- st_fail("phaser: decay must be less that 1.0!\n" );
- return (ST_EOF);
- }
- /* Be nice and check the hint with warning, if... */
- if ( phaser->in_gain > ( 1.0 - phaser->decay * phaser->decay ) )
- st_warn("phaser: warning >>> gain-in can cause saturation or clipping of output <<<");
- if ( phaser->in_gain / ( 1.0 - phaser->decay ) > 1.0 / phaser->out_gain )
- st_warn("phaser: warning >>> gain-out can cause saturation or clipping of output <<<");
+ if ( phaser->delay < 0.0 )
+ {
+ st_fail("phaser: delay must be positive!\n");
+ return (ST_EOF);
+ }
+ if ( phaser->delay > 5.0 )
+ {
+ st_fail("phaser: delay must be less than 5.0 msec!\n");
+ return (ST_EOF);
+ }
+ if ( phaser->speed < 0.1 )
+ {
+ st_fail("phaser: speed must be more than 0.1 Hz!\n");
+ return (ST_EOF);
+ }
+ if ( phaser->speed > 2.0 )
+ {
+ st_fail("phaser: speed must be less than 2.0 Hz!\n");
+ return (ST_EOF);
+ }
+ if ( phaser->decay < 0.0 )
+ {
+ st_fail("phaser: decay must be positive!\n" );
+ return (ST_EOF);
+ }
+ if ( phaser->decay >= 1.0 )
+ {
+ st_fail("phaser: decay must be less that 1.0!\n" );
+ return (ST_EOF);
+ }
+ /* Be nice and check the hint with warning, if... */
+ if ( phaser->in_gain > ( 1.0 - phaser->decay * phaser->decay ) )
+ st_warn("phaser: warning >>> gain-in can cause saturation or clipping of output <<<");
+ if ( phaser->in_gain / ( 1.0 - phaser->decay ) > 1.0 / phaser->out_gain )
+ st_warn("phaser: warning >>> gain-out can cause saturation or clipping of output <<<");
- phaser->length = effp->ininfo.rate / phaser->speed;
+ phaser->length = effp->ininfo.rate / phaser->speed;
- if (! (phaser->phaserbuf =
- (double *) malloc(sizeof (double) * phaser->maxsamples)))
- {
- st_fail("phaser: Cannot malloc %d bytes!\n",
- sizeof(double) * phaser->maxsamples);
- return (ST_EOF);
- }
- for ( i = 0; i < phaser->maxsamples; i++ )
- phaser->phaserbuf[i] = 0.0;
- if (! (phaser->lookup_tab =
- (int *) malloc(sizeof (int) * phaser->length)))
- {
- st_fail("phaser: Cannot malloc %d bytes!\n",
- sizeof(int) * phaser->length);
- return (ST_EOF);
- }
+ if (! (phaser->phaserbuf =
+ (double *) malloc(sizeof (double) * phaser->maxsamples)))
+ {
+ st_fail("phaser: Cannot malloc %d bytes!\n",
+ sizeof(double) * phaser->maxsamples);
+ return (ST_EOF);
+ }
+ for ( i = 0; i < phaser->maxsamples; i++ )
+ phaser->phaserbuf[i] = 0.0;
+ if (! (phaser->lookup_tab =
+ (int *) malloc(sizeof (int) * phaser->length)))
+ {
+ st_fail("phaser: Cannot malloc %d bytes!\n",
+ sizeof(int) * phaser->length);
+ return (ST_EOF);
+ }
- if ( phaser->modulation == MOD_SINE )
- st_sine(phaser->lookup_tab, phaser->length,
- phaser->maxsamples - 1,
- phaser->maxsamples - 1);
- else
- st_triangle(phaser->lookup_tab, phaser->length,
- (phaser->maxsamples - 1) * 2,
- phaser->maxsamples - 1);
- phaser->counter = 0;
- phaser->phase = 0;
- phaser->fade_out = phaser->maxsamples;
- return (ST_SUCCESS);
+ if ( phaser->modulation == MOD_SINE )
+ st_sine(phaser->lookup_tab, phaser->length,
+ phaser->maxsamples - 1,
+ phaser->maxsamples - 1);
+ else
+ st_triangle(phaser->lookup_tab, phaser->length,
+ (phaser->maxsamples - 1) * 2,
+ phaser->maxsamples - 1);
+ phaser->counter = 0;
+ phaser->phase = 0;
+ phaser->fade_out = phaser->maxsamples;
+ return (ST_SUCCESS);
}
/*
@@ -195,33 +195,33 @@
int st_phaser_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
st_size_t *isamp, st_size_t *osamp)
{
- phaser_t phaser = (phaser_t) effp->priv;
- int len, done;
-
- double d_in, d_out;
- st_sample_t out;
+ phaser_t phaser = (phaser_t) effp->priv;
+ int len, done;
+
+ double d_in, d_out;
+ st_sample_t out;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
- /* Store delays as 24-bit signed longs */
- d_in = (double) *ibuf++ / 256;
- /* Compute output first */
- d_in = d_in * phaser->in_gain;
- d_in += phaser->phaserbuf[(phaser->maxsamples +
- phaser->counter - phaser->lookup_tab[phaser->phase]) %
- phaser->maxsamples] * phaser->decay * -1.0;
- /* Adjust the output volume and size to 24 bit */
- d_out = d_in * phaser->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- /* Mix decay of delay and input */
- phaser->phaserbuf[phaser->counter] = d_in;
- phaser->counter =
- ( phaser->counter + 1 ) % phaser->maxsamples;
- phaser->phase = ( phaser->phase + 1 ) % phaser->length;
- }
- /* processed all samples */
- return (ST_SUCCESS);
+ len = ((*isamp > *osamp) ? *osamp : *isamp);
+ for(done = 0; done < len; done++) {
+ /* Store delays as 24-bit signed longs */
+ d_in = (double) *ibuf++ / 256;
+ /* Compute output first */
+ d_in = d_in * phaser->in_gain;
+ d_in += phaser->phaserbuf[(phaser->maxsamples +
+ phaser->counter - phaser->lookup_tab[phaser->phase]) %
+ phaser->maxsamples] * phaser->decay * -1.0;
+ /* Adjust the output volume and size to 24 bit */
+ d_out = d_in * phaser->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ /* Mix decay of delay and input */
+ phaser->phaserbuf[phaser->counter] = d_in;
+ phaser->counter =
+ ( phaser->counter + 1 ) % phaser->maxsamples;
+ phaser->phase = ( phaser->phase + 1 ) % phaser->length;
+ }
+ /* processed all samples */
+ return (ST_SUCCESS);
}
/*
@@ -229,35 +229,35 @@
*/
int st_phaser_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
- phaser_t phaser = (phaser_t) effp->priv;
- int done;
-
- double d_in, d_out;
- st_sample_t out;
+ phaser_t phaser = (phaser_t) effp->priv;
+ st_size_t done;
+
+ double d_in, d_out;
+ st_sample_t out;
- done = 0;
- while ( ( done < *osamp ) && ( done < phaser->fade_out ) ) {
- d_in = 0;
- d_out = 0;
- /* Compute output first */
- d_in += phaser->phaserbuf[(phaser->maxsamples +
- phaser->counter - phaser->lookup_tab[phaser->phase]) %
- phaser->maxsamples] * phaser->decay * -1.0;
- /* Adjust the output volume and size to 24 bit */
- d_out = d_in * phaser->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- /* Mix decay of delay and input */
- phaser->phaserbuf[phaser->counter] = d_in;
- phaser->counter =
- ( phaser->counter + 1 ) % phaser->maxsamples;
- phaser->phase = ( phaser->phase + 1 ) % phaser->length;
- done++;
- phaser->fade_out--;
- }
- /* samples playd, it remains */
- *osamp = done;
- return (ST_SUCCESS);
+ done = 0;
+ while ( ( done < *osamp ) && ( done < phaser->fade_out ) ) {
+ d_in = 0;
+ d_out = 0;
+ /* Compute output first */
+ d_in += phaser->phaserbuf[(phaser->maxsamples +
+ phaser->counter - phaser->lookup_tab[phaser->phase]) %
+ phaser->maxsamples] * phaser->decay * -1.0;
+ /* Adjust the output volume and size to 24 bit */
+ d_out = d_in * phaser->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ /* Mix decay of delay and input */
+ phaser->phaserbuf[phaser->counter] = d_in;
+ phaser->counter =
+ ( phaser->counter + 1 ) % phaser->maxsamples;
+ phaser->phase = ( phaser->phase + 1 ) % phaser->length;
+ done++;
+ phaser->fade_out--;
+ }
+ /* samples playd, it remains */
+ *osamp = done;
+ return (ST_SUCCESS);
}
/*
@@ -265,12 +265,12 @@
*/
int st_phaser_stop(eff_t effp)
{
- phaser_t phaser = (phaser_t) effp->priv;
+ phaser_t phaser = (phaser_t) effp->priv;
- free((char *) phaser->phaserbuf);
- phaser->phaserbuf = (double *) -1; /* guaranteed core dump */
- free((char *) phaser->lookup_tab);
- phaser->lookup_tab = (int *) -1; /* guaranteed core dump */
- return (ST_SUCCESS);
+ free((char *) phaser->phaserbuf);
+ phaser->phaserbuf = (double *) -1; /* guaranteed core dump */
+ free((char *) phaser->lookup_tab);
+ phaser->lookup_tab = (int *) -1; /* guaranteed core dump */
+ return (ST_SUCCESS);
}
--- a/src/pitch.c
+++ b/src/pitch.c
@@ -96,8 +96,8 @@
/* linear factors for the Hamming window
0<=i<=n: HAM_n(i) = HAM0 + HAM1*cos(i*PI/n)
*/
-#define HAM1 ((PITCH_FLOAT)(0.46e0))
-#define HAM0 ((PITCH_FLOAT)(0.54e0))
+#define HAM1 ((PITCH_FLOAT)(0.46e0))
+#define HAM0 ((PITCH_FLOAT)(0.54e0))
/* state of buffer management... */
typedef enum { pi_input, pi_compute, pi_output } pitch_state_t;
@@ -212,41 +212,41 @@
if (rate>0) /* sweep forwards */
{
- for (index=ZERO, i=0; i<olen; i++, index+=rate)
- {
- register int ifl = (int) index; /* FLOOR */
- register PITCH_FLOAT frac = index - ifl;
+ for (index=ZERO, i=0; i<olen; i++, index+=rate)
+ {
+ register int ifl = (int) index; /* FLOOR */
+ register PITCH_FLOAT frac = index - ifl;
- if (pitch->interopt==PITCH_INTERPOLE_LIN)
- out[i] = lin((PITCH_FLOAT) ibuf[ifl],
- (PITCH_FLOAT) ibuf[ifl+1],
- frac);
- else
- out[i] = cub((PITCH_FLOAT) ibuf[ifl-1],
- (PITCH_FLOAT) ibuf[ifl],
- (PITCH_FLOAT) ibuf[ifl+1],
- (PITCH_FLOAT) ibuf[ifl+2],
- frac);
- }
+ if (pitch->interopt==PITCH_INTERPOLE_LIN)
+ out[i] = lin((PITCH_FLOAT) ibuf[ifl],
+ (PITCH_FLOAT) ibuf[ifl+1],
+ frac);
+ else
+ out[i] = cub((PITCH_FLOAT) ibuf[ifl-1],
+ (PITCH_FLOAT) ibuf[ifl],
+ (PITCH_FLOAT) ibuf[ifl+1],
+ (PITCH_FLOAT) ibuf[ifl+2],
+ frac);
+ }
}
else /* rate < 0, sweep backwards */
{
- for (index=ilen-1, i=olen-1; i>=0; i--, index+=rate)
- {
- register int ifl = (int) index; /* FLOOR */
- register PITCH_FLOAT frac = index - ifl;
+ for (index=ilen-1, i=olen-1; i>=0; i--, index+=rate)
+ {
+ register int ifl = (int) index; /* FLOOR */
+ register PITCH_FLOAT frac = index - ifl;
- if (pitch->interopt==PITCH_INTERPOLE_LIN)
- out[i] = lin((PITCH_FLOAT) ibuf[ifl],
- (PITCH_FLOAT) ibuf[ifl+1],
- frac);
- else
- out[i] = cub((PITCH_FLOAT) ibuf[ifl-1],
- (PITCH_FLOAT) ibuf[ifl],
- (PITCH_FLOAT) ibuf[ifl+1],
- (PITCH_FLOAT) ibuf[ifl+2],
- frac);
- }
+ if (pitch->interopt==PITCH_INTERPOLE_LIN)
+ out[i] = lin((PITCH_FLOAT) ibuf[ifl],
+ (PITCH_FLOAT) ibuf[ifl+1],
+ frac);
+ else
+ out[i] = cub((PITCH_FLOAT) ibuf[ifl-1],
+ (PITCH_FLOAT) ibuf[ifl],
+ (PITCH_FLOAT) ibuf[ifl+1],
+ (PITCH_FLOAT) ibuf[ifl+2],
+ frac);
+ }
}
}
@@ -258,21 +258,21 @@
/* forwards sweep */
interpolation(pitch,
- pitch->buf+pitch->overlap, pitch->step+pitch->overlap,
- pitch->tmp, pitch->step,
- pitch->rate);
+ pitch->buf+pitch->overlap, pitch->step+pitch->overlap,
+ pitch->tmp, pitch->step,
+ pitch->rate);
for (i=0; i<len; i++)
- pitch->acc[i] = pitch->fade[i]*pitch->tmp[i];
+ pitch->acc[i] = pitch->fade[i]*pitch->tmp[i];
/* backwards sweep */
interpolation(pitch,
- pitch->buf, pitch->step+pitch->overlap,
- pitch->tmp, pitch->step,
- -pitch->rate);
+ pitch->buf, pitch->step+pitch->overlap,
+ pitch->tmp, pitch->step,
+ -pitch->rate);
for (i=0; i<len; i++)
- pitch->acc[i] += pitch->fade[pitch->step-i-1]*pitch->tmp[i];
+ pitch->acc[i] += pitch->fade[pitch->step-i-1]*pitch->tmp[i];
}
static st_sample_t clip(pitch_t pitch, PITCH_FLOAT v)
@@ -279,16 +279,16 @@
{
if (v < -ST_SAMPLE_MAX)
{
- pitch->clipped++;
- return -ST_SAMPLE_MAX;
+ pitch->clipped++;
+ return -ST_SAMPLE_MAX;
}
else if (v > ST_SAMPLE_MAX)
{
- pitch->clipped++;
- return ST_SAMPLE_MAX;
+ pitch->clipped++;
+ return ST_SAMPLE_MAX;
}
else
- return (st_sample_t) v;
+ return (st_sample_t) v;
}
/*
@@ -303,8 +303,8 @@
if (n && !sscanf(argv[0], PITCH_FLOAT_SCAN, &pitch->shift))
{
- st_fail(PITCH_USAGE);
- return ST_EOF;
+ st_fail(PITCH_USAGE);
+ return ST_EOF;
}
/* sweep size in ms */
@@ -311,8 +311,8 @@
pitch->width = PITCH_DEFAULT_WIDTH;
if (n>1 && !sscanf(argv[1], PITCH_FLOAT_SCAN, &pitch->width))
{
- st_fail(PITCH_USAGE);
- return ST_EOF;
+ st_fail(PITCH_USAGE);
+ return ST_EOF;
}
/* interpole option */
@@ -319,20 +319,20 @@
pitch->interopt = PITCH_INTERPOLE_DEFAULT;
if (n>2)
{
- switch(argv[2][0])
- {
- case 'l':
- case 'L':
- pitch->interopt = PITCH_INTERPOLE_LIN;
- break;
- case 'c':
- case 'C':
- pitch->interopt = PITCH_INTERPOLE_CUB;
- break;
- default:
- st_fail(PITCH_USAGE);
- return ST_EOF;
- }
+ switch(argv[2][0])
+ {
+ case 'l':
+ case 'L':
+ pitch->interopt = PITCH_INTERPOLE_LIN;
+ break;
+ case 'c':
+ case 'C':
+ pitch->interopt = PITCH_INTERPOLE_CUB;
+ break;
+ default:
+ st_fail(PITCH_USAGE);
+ return ST_EOF;
+ }
}
/* fade option */
@@ -339,36 +339,36 @@
pitch->fadeopt = PITCH_FADE_DEFAULT; /* default */
if (n>3)
{
- switch (argv[3][0]) /* what a parser;-) */
- {
- case 'l':
- case 'L':
- pitch->fadeopt = PITCH_FADE_LIN;
- break;
- case 't':
- case 'T':
- pitch->fadeopt = PITCH_FADE_TRA;
- break;
- case 'h':
- case 'H':
- pitch->fadeopt = PITCH_FADE_HAM;
- break;
- case 'c':
- case 'C':
- pitch->fadeopt = PITCH_FADE_COS;
- break;
- default:
- st_fail(PITCH_USAGE);
- return ST_EOF;
- }
+ switch (argv[3][0]) /* what a parser;-) */
+ {
+ case 'l':
+ case 'L':
+ pitch->fadeopt = PITCH_FADE_LIN;
+ break;
+ case 't':
+ case 'T':
+ pitch->fadeopt = PITCH_FADE_TRA;
+ break;
+ case 'h':
+ case 'H':
+ pitch->fadeopt = PITCH_FADE_HAM;
+ break;
+ case 'c':
+ case 'C':
+ pitch->fadeopt = PITCH_FADE_COS;
+ break;
+ default:
+ st_fail(PITCH_USAGE);
+ return ST_EOF;
+ }
}
pitch->coef = QUARTER;
if (n>4 && (!sscanf(argv[4], PITCH_FLOAT_SCAN, &pitch->coef) ||
- pitch->coef<ZERO || pitch->coef>HALF))
+ pitch->coef<ZERO || pitch->coef>HALF))
{
- st_fail(PITCH_USAGE);
- return ST_EOF;
+ st_fail(PITCH_USAGE);
+ return ST_EOF;
}
pitch->clipped = 0;
@@ -388,16 +388,16 @@
*/
if (effp->outinfo.rate != effp->ininfo.rate)
{
- st_fail("PITCH cannot handle different rates (in=%ld, out=%ld)"
- " use resample or rate", effp->ininfo.rate, effp->outinfo.rate);
- return ST_EOF;
+ st_fail("PITCH cannot handle different rates (in=%ld, out=%ld)"
+ " use resample or rate", effp->ininfo.rate, effp->outinfo.rate);
+ return ST_EOF;
}
if (effp->outinfo.channels != effp->ininfo.channels)
{
- st_fail("PITCH cannot handle different channels (in=%ld, out=%ld)"
- " use avg or pan", effp->ininfo.channels, effp->outinfo.channels);
- return ST_EOF;
+ st_fail("PITCH cannot handle different channels (in=%ld, out=%ld)"
+ " use avg or pan", effp->ininfo.channels, effp->outinfo.channels);
+ return ST_EOF;
}
/* computer inner stuff... */
@@ -417,9 +417,9 @@
/* security for safe cubic interpolation */
if (pitch->rate > ONE)
- pitch->overlap = (int) ((pitch->rate-ONE)*pitch->step) + 2;
+ pitch->overlap = (int) ((pitch->rate-ONE)*pitch->step) + 2;
else
- pitch->overlap = 2;
+ pitch->overlap = 2;
pitch->size = pitch->step + 2*pitch->overlap;
@@ -430,8 +430,8 @@
if (!pitch->fade || !pitch->tmp || !pitch->acc || !pitch->buf)
{
- st_fail("malloc failed in st_pitch_start");
- return ST_EOF;
+ st_fail("malloc failed in st_pitch_start");
+ return ST_EOF;
}
pitch->index = pitch->overlap;
@@ -438,53 +438,53 @@
/* default initial signal */
for (i=0; i<pitch->size; i++)
- pitch->buf[i] = 0;
+ pitch->buf[i] = 0;
if (pitch->fadeopt == PITCH_FADE_HAM)
{
- /* does it make sense to have such an option? */
- register PITCH_FLOAT pi_step = M_PI / (pitch->step-1);
-
- for (i=0; i<pitch->step; i++)
- pitch->fade[i] = (PITCH_FLOAT) (HAM0 + HAM1*cos(pi_step*i));
+ /* does it make sense to have such an option? */
+ register PITCH_FLOAT pi_step = M_PI / (pitch->step-1);
+
+ for (i=0; i<pitch->step; i++)
+ pitch->fade[i] = (PITCH_FLOAT) (HAM0 + HAM1*cos(pi_step*i));
}
else if (pitch->fadeopt == PITCH_FADE_COS)
{
- register PITCH_FLOAT pi_2_step = M_PI_2 / (pitch->step-1);
+ register PITCH_FLOAT pi_2_step = M_PI_2 / (pitch->step-1);
- pitch->fade[0] = ONE; /* cos(0) == 1.0 */
- for (i=1; i<pitch->step-1; i++)
- pitch->fade[i] = (PITCH_FLOAT) cos(pi_2_step*i);
- pitch->fade[pitch->step-1] = ZERO; /* cos(PI/2) == 0.0 */
+ pitch->fade[0] = ONE; /* cos(0) == 1.0 */
+ for (i=1; i<pitch->step-1; i++)
+ pitch->fade[i] = (PITCH_FLOAT) cos(pi_2_step*i);
+ pitch->fade[pitch->step-1] = ZERO; /* cos(PI/2) == 0.0 */
}
else if (pitch->fadeopt == PITCH_FADE_LIN)
{
- register PITCH_FLOAT stepth = ONE / (pitch->step-1);
+ register PITCH_FLOAT stepth = ONE / (pitch->step-1);
- pitch->fade[0] = ONE;
- for (i=1; i<pitch->step-1; i++)
- pitch->fade[i] = (pitch->step-i-1) * stepth;
- pitch->fade[pitch->step-1] = ZERO;
+ pitch->fade[0] = ONE;
+ for (i=1; i<pitch->step-1; i++)
+ pitch->fade[i] = (pitch->step-i-1) * stepth;
+ pitch->fade[pitch->step-1] = ZERO;
}
else if (pitch->fadeopt == PITCH_FADE_TRA)
{
- /* 0 <= coef <= 0.5 */
- register int plat = (int) (pitch->step*pitch->coef);
- register PITCH_FLOAT slope = ONE / (pitch->step - 2*plat);
+ /* 0 <= coef <= 0.5 */
+ register int plat = (int) (pitch->step*pitch->coef);
+ register PITCH_FLOAT slope = ONE / (pitch->step - 2*plat);
- for (i=0; i<plat; i++)
- pitch->fade[i] = ONE;
+ for (i=0; i<plat; i++)
+ pitch->fade[i] = ONE;
- for (; i<pitch->step-plat; i++)
- pitch->fade[i] = slope * (pitch->step-plat-i-1);
+ for (; i<pitch->step-plat; i++)
+ pitch->fade[i] = slope * (pitch->step-plat-i-1);
- for (; i<pitch->step; i++)
- pitch->fade[i] = ZERO;
+ for (; i<pitch->step; i++)
+ pitch->fade[i] = ZERO;
}
else
{
- st_fail("unexpected PITCH_FADE parameter %d", pitch->fadeopt);
- return ST_EOF;
+ st_fail("unexpected PITCH_FADE parameter %d", pitch->fadeopt);
+ return ST_EOF;
}
pitch->clipped = 0;
@@ -498,7 +498,8 @@
st_size_t *isamp, st_size_t *osamp)
{
pitch_t pitch = (pitch_t) effp->priv;
- register int i, len, size, iindex, oindex;
+ int i, size;
+ st_size_t len, iindex, oindex;
size = pitch->size;
/* size to process */
@@ -514,45 +515,45 @@
*/
while (len>0 && iindex<*isamp && oindex<*osamp)
{
- if (pitch->state == pi_input)
- {
- register int tocopy = MIN(pitch->size-pitch->index, len);
+ if (pitch->state == pi_input)
+ {
+ register int tocopy = MIN(pitch->size-pitch->index, len);
- memcpy(pitch->buf+pitch->index, ibuf+iindex, tocopy*sizeof(st_sample_t));
+ memcpy(pitch->buf+pitch->index, ibuf+iindex, tocopy*sizeof(st_sample_t));
- len -= tocopy;
- pitch->index += tocopy;
- iindex += tocopy;
+ len -= tocopy;
+ pitch->index += tocopy;
+ iindex += tocopy;
- if (pitch->index==pitch->size)
- pitch->state = pi_compute;
- }
+ if (pitch->index==pitch->size)
+ pitch->state = pi_compute;
+ }
- if (pitch->state == pi_compute)
- {
- process_intput_buffer(pitch);
- pitch->state = pi_output;
- pitch->iacc = 0;
- }
+ if (pitch->state == pi_compute)
+ {
+ process_intput_buffer(pitch);
+ pitch->state = pi_output;
+ pitch->iacc = 0;
+ }
- if (pitch->state == pi_output)
- {
- register int toout = MIN(*osamp-oindex, pitch->step-pitch->iacc);
+ if (pitch->state == pi_output)
+ {
+ int toout = MIN(*osamp-oindex, pitch->step-pitch->iacc);
- for (i=0; i<toout; i++)
- obuf[oindex++] = clip(pitch, pitch->acc[pitch->iacc++]);
+ for (i=0; i<toout; i++)
+ obuf[oindex++] = clip(pitch, pitch->acc[pitch->iacc++]);
- if (pitch->iacc == pitch->step)
- {
- pitch->state = pi_input;
+ if (pitch->iacc == pitch->step)
+ {
+ pitch->state = pi_input;
- /* shift input buffer. memmove? */
- for (i=0; i<2*pitch->overlap; i++)
- pitch->buf[i] = pitch->buf[i+pitch->step];
-
- pitch->index = 2*pitch->overlap;
- }
- }
+ /* shift input buffer. memmove? */
+ for (i=0; i<2*pitch->overlap; i++)
+ pitch->buf[i] = pitch->buf[i+pitch->step];
+
+ pitch->index = 2*pitch->overlap;
+ }
+ }
}
/* report consumption. */
@@ -567,27 +568,27 @@
int st_pitch_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
pitch_t pitch = (pitch_t) effp->priv;
- register int i;
+ st_size_t i;
if (pitch->state == pi_input)
{
- /* complete input buffer content with 0. */
- for (i=pitch->index; i<pitch->size; i++)
- pitch->buf[i] = 0;
+ /* complete input buffer content with 0. */
+ for (i=pitch->index; i<pitch->size; i++)
+ pitch->buf[i] = 0;
- pitch->state = pi_compute;
+ pitch->state = pi_compute;
}
if (pitch->state == pi_compute)
{
- process_intput_buffer(pitch);
- pitch->state = pi_output;
- pitch->iacc = 0;
+ process_intput_buffer(pitch);
+ pitch->state = pi_output;
+ pitch->iacc = 0;
}
/* (pitch->state == pi_output) */
for (i=0; i<*osamp && i<pitch->index-pitch->overlap;)
- obuf[i++] = clip(pitch, pitch->acc[pitch->iacc++]);
+ obuf[i++] = clip(pitch, pitch->acc[pitch->iacc++]);
/* report... */
*osamp = i;
@@ -609,8 +610,8 @@
free(pitch->buf);
if (pitch->clipped)
- st_warn("PITCH clipped %d values... adjust volume with -v option maybe?",
- pitch->clipped);
+ st_warn("PITCH clipped %d values... adjust volume with -v option maybe?",
+ pitch->clipped);
return ST_SUCCESS;
}
--- a/src/raw.c
+++ b/src/raw.c
@@ -163,13 +163,13 @@
{
while (len)
{
- uint8_t datum;
+ uint8_t datum;
- datum = *((uint8_t *)buf2);
- buf2++;
+ datum = *((uint8_t *)buf2);
+ buf2++;
- *buf1++ = ST_ULAW_BYTE_TO_SAMPLE(datum);
- len--;
+ *buf1++ = ST_ULAW_BYTE_TO_SAMPLE(datum);
+ len--;
}
}
@@ -178,13 +178,13 @@
{
while (len)
{
- uint8_t datum;
+ uint8_t datum;
- datum = *((uint8_t *)buf2);
- buf2++;
+ datum = *((uint8_t *)buf2);
+ buf2++;
- *buf1++ = ST_ALAW_BYTE_TO_SAMPLE(datum);
- len--;
+ *buf1++ = ST_ALAW_BYTE_TO_SAMPLE(datum);
+ len--;
}
}
@@ -193,13 +193,13 @@
{
while (len)
{
- uint8_t datum;
+ uint8_t datum;
- datum = *((uint8_t *)buf2);
- buf2++;
+ datum = *((uint8_t *)buf2);
+ buf2++;
- *buf1++ = ST_INVERT_ULAW_BYTE_TO_SAMPLE(datum);
- len--;
+ *buf1++ = ST_INVERT_ULAW_BYTE_TO_SAMPLE(datum);
+ len--;
}
}
@@ -208,13 +208,13 @@
{
while (len)
{
- uint8_t datum;
+ uint8_t datum;
- datum = *((uint8_t *)buf2);
- buf2++;
+ datum = *((uint8_t *)buf2);
+ buf2++;
- *buf1++ = ST_INVERT_ALAW_BYTE_TO_SAMPLE(datum);
- len--;
+ *buf1++ = ST_INVERT_ALAW_BYTE_TO_SAMPLE(datum);
+ len--;
}
}
@@ -328,8 +328,14 @@
{
st_ssize_t len, done = 0;
void (*read_buf)(st_sample_t *, char *, st_ssize_t, char) = 0;
- int i;
+ size_t i;
+ if (nsamp < 0)
+ {
+ st_fail_errno(ft,ST_EINVAL,"st_rawread requires positive sizes");
+ return ST_EOF;
+ }
+
switch(ft->info.size) {
case ST_SIZE_BYTE:
switch(ft->info.encoding)
@@ -408,7 +414,7 @@
}
- len = MIN(nsamp,(ft->file.count-ft->file.pos)/ft->info.size);
+ len = MIN((st_size_t)nsamp,(ft->file.count-ft->file.pos)/ft->info.size);
if (len)
{
read_buf(buf + done, ft->file.buf + ft->file.pos, len, ft->swap);
@@ -440,7 +446,7 @@
ft->file.count += i;
}
- len = MIN(nsamp - done,(ft->file.count-ft->file.pos)/ft->info.size);
+ len = MIN((st_size_t)nsamp - done,(ft->file.count-ft->file.pos)/ft->info.size);
if (len)
{
read_buf(buf + done, ft->file.buf + ft->file.pos, len, ft->swap);
@@ -483,8 +489,8 @@
{
while (len)
{
- *(uint8_t *)buf1++ = ST_SAMPLE_TO_ULAW_BYTE(*buf2++);
- len--;
+ *(uint8_t *)buf1++ = ST_SAMPLE_TO_ULAW_BYTE(*buf2++);
+ len--;
}
}
@@ -493,8 +499,8 @@
{
while (len)
{
- *(uint8_t *)buf1++ = ST_SAMPLE_TO_ALAW_BYTE(*buf2++);
- len--;
+ *(uint8_t *)buf1++ = ST_SAMPLE_TO_ALAW_BYTE(*buf2++);
+ len--;
}
}
@@ -503,8 +509,8 @@
{
while (len)
{
- *(uint8_t *)buf1++ = ST_SAMPLE_TO_INVERT_ULAW_BYTE(*buf2++);
- len--;
+ *(uint8_t *)buf1++ = ST_SAMPLE_TO_INVERT_ULAW_BYTE(*buf2++);
+ len--;
}
}
@@ -513,8 +519,8 @@
{
while (len)
{
- *(uint8_t *)buf1++ = ST_SAMPLE_TO_INVERT_ALAW_BYTE(*buf2++);
- len--;
+ *(uint8_t *)buf1++ = ST_SAMPLE_TO_INVERT_ALAW_BYTE(*buf2++);
+ len--;
}
}
@@ -707,7 +713,7 @@
break;
default:
st_fail_errno(ft,ST_EFMT,"Do not support this encoding for this data size");
- return(0);
+ return(0);
}
break;
--- a/src/repeat.c
+++ b/src/repeat.c
@@ -121,12 +121,6 @@
repeat->remaining = repeat->total;
}
}
-
- if (repeat->remaining < 0) {
- st_fail("repeat: unknown error");
- return (ST_EOF);
- }
-
if (*osamp > repeat->remaining) {
buf = obuf;
samp = repeat->remaining;
--- a/src/reverb.c
+++ b/src/reverb.c
@@ -8,7 +8,7 @@
*/
/*
-** Echo effect. based on:
+** Echo effect. based on:
**
** echoplex.c - echo generator
**
@@ -101,13 +101,13 @@
/* Private data for SKEL file */
typedef struct reverbstuff {
- int counter;
- int numdelays;
- float *reverbbuf;
- float in_gain, out_gain, time;
- float delay[MAXREVERBS], decay[MAXREVERBS];
- long samples[MAXREVERBS], maxsamples;
- st_sample_t pl, ppl, pppl;
+ int counter;
+ int numdelays;
+ float *reverbbuf;
+ float in_gain, out_gain, time;
+ float delay[MAXREVERBS], decay[MAXREVERBS];
+ long samples[MAXREVERBS], maxsamples;
+ st_sample_t pl, ppl, pppl;
} *reverb_t;
/*
@@ -115,34 +115,34 @@
*/
int st_reverb_getopts(eff_t effp, int n, char **argv)
{
- reverb_t reverb = (reverb_t) effp->priv;
- int i;
+ reverb_t reverb = (reverb_t) effp->priv;
+ int i;
- reverb->numdelays = 0;
- reverb->maxsamples = 0;
+ reverb->numdelays = 0;
+ reverb->maxsamples = 0;
- if ( n < 3 )
- {
- st_fail("Usage: reverb gain-out reverb-time delay [ delay ... ]");
- return (ST_EOF);
- }
+ if ( n < 3 )
+ {
+ st_fail("Usage: reverb gain-out reverb-time delay [ delay ... ]");
+ return (ST_EOF);
+ }
- if ( n - 2 > MAXREVERBS )
- {
- st_fail("reverb: to many dalays, use less than %i delays",
- MAXREVERBS);
- return (ST_EOF);
- }
+ if ( n - 2 > MAXREVERBS )
+ {
+ st_fail("reverb: to many dalays, use less than %i delays",
+ MAXREVERBS);
+ return (ST_EOF);
+ }
- i = 0;
- sscanf(argv[i++], "%f", &reverb->out_gain);
- sscanf(argv[i++], "%f", &reverb->time);
- while (i < n) {
- /* Linux bug and it's cleaner. */
- sscanf(argv[i++], "%f", &reverb->delay[reverb->numdelays]);
- reverb->numdelays++;
- }
- return (ST_SUCCESS);
+ i = 0;
+ sscanf(argv[i++], "%f", &reverb->out_gain);
+ sscanf(argv[i++], "%f", &reverb->time);
+ while (i < n) {
+ /* Linux bug and it's cleaner. */
+ sscanf(argv[i++], "%f", &reverb->delay[reverb->numdelays]);
+ reverb->numdelays++;
+ }
+ return (ST_SUCCESS);
}
/*
@@ -150,57 +150,57 @@
*/
int st_reverb_start(eff_t effp)
{
- reverb_t reverb = (reverb_t) effp->priv;
- int i;
+ reverb_t reverb = (reverb_t) effp->priv;
+ int i;
- reverb->in_gain = 1.0;
+ reverb->in_gain = 1.0;
- if ( reverb->out_gain < 0.0 )
- {
- st_fail("reverb: gain-out must be positive");
- return (ST_EOF);
- }
- if ( reverb->out_gain > 1.0 )
- st_warn("reverb: warnig >>> gain-out can cause saturation of output <<<");
- if ( reverb->time < 0.0 )
- {
- st_fail("reverb: reverb-time must be positive");
- return (ST_EOF);
- }
- for(i = 0; i < reverb->numdelays; i++) {
- reverb->samples[i] = reverb->delay[i] * effp->ininfo.rate / 1000.0;
- if ( reverb->samples[i] < 1 )
- {
- st_fail("reverb: delay must be positive!\n");
- return (ST_EOF);
- }
- if ( reverb->samples[i] > DELAY_BUFSIZ )
- {
- st_fail("reverb: delay must be less than %g seconds!\n",
- DELAY_BUFSIZ / (float) effp->ininfo.rate );
- return(ST_EOF);
- }
- /* Compute a realistic decay */
- reverb->decay[i] = (float) pow(10.0,(-3.0 * reverb->delay[i] / reverb->time));
- if ( reverb->samples[i] > reverb->maxsamples )
- reverb->maxsamples = reverb->samples[i];
- }
- if (! (reverb->reverbbuf = (float *) malloc(sizeof (float) * reverb->maxsamples)))
- {
- st_fail("reverb: Cannot malloc %d bytes!\n",
- sizeof(float) * reverb->maxsamples);
- return(ST_EOF);
- }
- for ( i = 0; i < reverb->maxsamples; ++i )
- reverb->reverbbuf[i] = 0.0;
- reverb->pppl = reverb->ppl = reverb->pl = 0x7fffff; /* fade-outs */
- reverb->counter = 0;
- /* Compute the input volume carefully */
- for ( i = 0; i < reverb->numdelays; i++ )
- reverb->in_gain *=
- ( 1.0 - ( reverb->decay[i] * reverb->decay[i] ));
- return (ST_SUCCESS);
-}
+ if ( reverb->out_gain < 0.0 )
+ {
+ st_fail("reverb: gain-out must be positive");
+ return (ST_EOF);
+ }
+ if ( reverb->out_gain > 1.0 )
+ st_warn("reverb: warnig >>> gain-out can cause saturation of output <<<");
+ if ( reverb->time < 0.0 )
+ {
+ st_fail("reverb: reverb-time must be positive");
+ return (ST_EOF);
+ }
+ for(i = 0; i < reverb->numdelays; i++) {
+ reverb->samples[i] = reverb->delay[i] * effp->ininfo.rate / 1000.0;
+ if ( reverb->samples[i] < 1 )
+ {
+ st_fail("reverb: delay must be positive!\n");
+ return (ST_EOF);
+ }
+ if ( reverb->samples[i] > DELAY_BUFSIZ )
+ {
+ st_fail("reverb: delay must be less than %g seconds!\n",
+ DELAY_BUFSIZ / (float) effp->ininfo.rate );
+ return(ST_EOF);
+ }
+ /* Compute a realistic decay */
+ reverb->decay[i] = (float) pow(10.0,(-3.0 * reverb->delay[i] / reverb->time));
+ if ( reverb->samples[i] > reverb->maxsamples )
+ reverb->maxsamples = reverb->samples[i];
+ }
+ if (! (reverb->reverbbuf = (float *) malloc(sizeof (float) * reverb->maxsamples)))
+ {
+ st_fail("reverb: Cannot malloc %d bytes!\n",
+ sizeof(float) * reverb->maxsamples);
+ return(ST_EOF);
+ }
+ for ( i = 0; i < reverb->maxsamples; ++i )
+ reverb->reverbbuf[i] = 0.0;
+ reverb->pppl = reverb->ppl = reverb->pl = 0x7fffff; /* fade-outs */
+ reverb->counter = 0;
+ /* Compute the input volume carefully */
+ for ( i = 0; i < reverb->numdelays; i++ )
+ reverb->in_gain *=
+ ( 1.0 - ( reverb->decay[i] * reverb->decay[i] ));
+ return (ST_SUCCESS);
+}
/*
* Processed signed long samples from ibuf to obuf.
@@ -209,33 +209,33 @@
int st_reverb_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
st_size_t *isamp, st_size_t *osamp)
{
- reverb_t reverb = (reverb_t) effp->priv;
- int len, done;
- int i, j;
-
- float d_in, d_out;
- st_sample_t out;
+ reverb_t reverb = (reverb_t) effp->priv;
+ int len, done;
+ int i, j;
+
+ float d_in, d_out;
+ st_sample_t out;
- i = reverb->counter;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
- /* Store delays as 24-bit signed longs */
- d_in = (float) *ibuf++ / 256;
- d_in = d_in * reverb->in_gain;
- /* Mix decay of delay and input as output */
- for ( j = 0; j < reverb->numdelays; j++ )
- d_in +=
+ i = reverb->counter;
+ len = ((*isamp > *osamp) ? *osamp : *isamp);
+ for(done = 0; done < len; done++) {
+ /* Store delays as 24-bit signed longs */
+ d_in = (float) *ibuf++ / 256;
+ d_in = d_in * reverb->in_gain;
+ /* Mix decay of delay and input as output */
+ for ( j = 0; j < reverb->numdelays; j++ )
+ d_in +=
reverb->reverbbuf[(i + reverb->maxsamples - reverb->samples[j]) % reverb->maxsamples] * reverb->decay[j];
- d_out = d_in * reverb->out_gain;
- out = st_clip24((st_sample_t) d_out);
- *obuf++ = out * 256;
- reverb->reverbbuf[i] = d_in;
- i++; /* XXX need a % maxsamples here ? */
- i %= reverb->maxsamples;
- }
- reverb->counter = i;
- /* processed all samples */
- return (ST_SUCCESS);
+ d_out = d_in * reverb->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ *obuf++ = out * 256;
+ reverb->reverbbuf[i] = d_in;
+ i++; /* XXX need a % maxsamples here ? */
+ i %= reverb->maxsamples;
+ }
+ reverb->counter = i;
+ /* processed all samples */
+ return (ST_SUCCESS);
}
/*
@@ -243,35 +243,36 @@
*/
int st_reverb_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
- reverb_t reverb = (reverb_t) effp->priv;
- float d_in, d_out;
- st_sample_t out, l;
- int i, j, done;
+ reverb_t reverb = (reverb_t) effp->priv;
+ float d_in, d_out;
+ st_sample_t out, l;
+ int i, j;
+ st_size_t done;
- i = reverb->counter;
- done = 0;
- /* drain out delay samples */
- do {
- d_in = 0;
- d_out = 0;
- for ( j = 0; j < reverb->numdelays; ++j )
- d_in +=
+ i = reverb->counter;
+ done = 0;
+ /* drain out delay samples */
+ do {
+ d_in = 0;
+ d_out = 0;
+ for ( j = 0; j < reverb->numdelays; ++j )
+ d_in +=
reverb->reverbbuf[(i + reverb->maxsamples - reverb->samples[j]) % reverb->maxsamples] * reverb->decay[j];
- d_out = d_in * reverb->out_gain;
- out = st_clip24((st_sample_t) d_out);
- obuf[done++] = out * 256;
- reverb->reverbbuf[i] = d_in;
- l = st_clip24((st_sample_t) d_in);
- reverb->pppl = reverb->ppl;
- reverb->ppl = reverb->pl;
- reverb->pl = l;
- i++; /* need a % maxsamples here ? */
- i %= reverb->maxsamples;
- } while((done < *osamp) &&
- ((abs(reverb->pl) + abs(reverb->ppl) + abs(reverb->pppl)) > REVERB_FADE_THRESH));
- reverb->counter = i;
- *osamp = done;
- return (ST_SUCCESS);
+ d_out = d_in * reverb->out_gain;
+ out = st_clip24((st_sample_t) d_out);
+ obuf[done++] = out * 256;
+ reverb->reverbbuf[i] = d_in;
+ l = st_clip24((st_sample_t) d_in);
+ reverb->pppl = reverb->ppl;
+ reverb->ppl = reverb->pl;
+ reverb->pl = l;
+ i++; /* need a % maxsamples here ? */
+ i %= reverb->maxsamples;
+ } while((done < *osamp) &&
+ ((abs(reverb->pl) + abs(reverb->ppl) + abs(reverb->pppl)) > REVERB_FADE_THRESH));
+ reverb->counter = i;
+ *osamp = done;
+ return (ST_SUCCESS);
}
/*
@@ -279,9 +280,9 @@
*/
int st_reverb_stop(eff_t effp)
{
- reverb_t reverb = (reverb_t) effp->priv;
+ reverb_t reverb = (reverb_t) effp->priv;
- free((char *) reverb->reverbbuf);
- reverb->reverbbuf = (float *) -1; /* guaranteed core dump */
- return (ST_SUCCESS);
+ free((char *) reverb->reverbbuf);
+ reverb->reverbbuf = (float *) -1; /* guaranteed core dump */
+ return (ST_SUCCESS);
}
--- a/src/silence.c
+++ b/src/silence.c
@@ -38,29 +38,29 @@
typedef struct silencestuff
{
- char start;
- int start_periods;
- char *start_duration_str;
- st_size_t start_duration;
- double start_threshold;
- char start_unit; /* "d" for decibels or "%" for percent. */
+ char start;
+ int start_periods;
+ char *start_duration_str;
+ st_size_t start_duration;
+ double start_threshold;
+ char start_unit; /* "d" for decibels or "%" for percent. */
- st_sample_t *start_holdoff;
- st_size_t start_holdoff_offset;
- st_size_t start_holdoff_end;
- int start_found_periods;
+ st_sample_t *start_holdoff;
+ st_size_t start_holdoff_offset;
+ st_size_t start_holdoff_end;
+ int start_found_periods;
- char stop;
- int stop_periods;
- char *stop_duration_str;
- st_size_t stop_duration;
- double stop_threshold;
- char stop_unit;
+ char stop;
+ int stop_periods;
+ char *stop_duration_str;
+ st_size_t stop_duration;
+ double stop_threshold;
+ char stop_unit;
- st_sample_t *stop_holdoff;
- st_size_t stop_holdoff_offset;
- st_size_t stop_holdoff_end;
- int stop_found_periods;
+ st_sample_t *stop_holdoff;
+ st_size_t stop_holdoff_offset;
+ st_size_t stop_holdoff_end;
+ int stop_found_periods;
double *window;
double *window_current;
@@ -69,7 +69,7 @@
double rms_sum;
/* State Machine */
- char mode;
+ char mode;
} *silence_t;
#define SILENCE_USAGE "Usage: silence above_periods [ duration thershold[d | %% ] ] [ below_periods duration threshold[ d | %% ]]"
@@ -76,13 +76,13 @@
int st_silence_getopts(eff_t effp, int n, char **argv)
{
- silence_t silence = (silence_t) effp->priv;
+ silence_t silence = (silence_t) effp->priv;
int parse_count;
if (n < 1)
{
- st_fail(SILENCE_USAGE);
- return (ST_EOF);
+ st_fail(SILENCE_USAGE);
+ return (ST_EOF);
}
/* Parse data related to trimming front side */
@@ -89,13 +89,13 @@
silence->start = FALSE;
if (sscanf(argv[0], "%d", &silence->start_periods) != 1)
{
- st_fail(SILENCE_USAGE);
- return(ST_EOF);
+ st_fail(SILENCE_USAGE);
+ return(ST_EOF);
}
if (silence->start_periods < 0)
{
- st_fail("Periods must not be negative");
- return(ST_EOF);
+ st_fail("Periods must not be negative");
+ return(ST_EOF);
}
argv++;
n--;
@@ -102,45 +102,45 @@
if (silence->start_periods > 0)
{
- silence->start = TRUE;
- if (n < 2)
- {
- st_fail(SILENCE_USAGE);
- return ST_EOF;
- }
+ silence->start = TRUE;
+ if (n < 2)
+ {
+ st_fail(SILENCE_USAGE);
+ return ST_EOF;
+ }
- /* We do not know the sample rate so we can not fully
- * parse the duration info yet. So save argument off
- * for future processing.
- */
- silence->start_duration_str = malloc(strlen(argv[0])+1);
- if (!silence->start_duration_str)
- {
- st_fail("Could not allocate memory");
- return(ST_EOF);
- }
- strcpy(silence->start_duration_str,argv[0]);
- /* Perform a fake parse to do error checking */
- if (st_parsesamples(0,silence->start_duration_str,
- &silence->start_duration,'s') !=
- ST_SUCCESS)
- {
- st_fail(SILENCE_USAGE);
- return(ST_EOF);
- }
+ /* We do not know the sample rate so we can not fully
+ * parse the duration info yet. So save argument off
+ * for future processing.
+ */
+ silence->start_duration_str = malloc(strlen(argv[0])+1);
+ if (!silence->start_duration_str)
+ {
+ st_fail("Could not allocate memory");
+ return(ST_EOF);
+ }
+ strcpy(silence->start_duration_str,argv[0]);
+ /* Perform a fake parse to do error checking */
+ if (st_parsesamples(0,silence->start_duration_str,
+ &silence->start_duration,'s') !=
+ ST_SUCCESS)
+ {
+ st_fail(SILENCE_USAGE);
+ return(ST_EOF);
+ }
- parse_count = sscanf(argv[1], "%lf%c", &silence->start_threshold,
- &silence->start_unit);
- if (parse_count < 1)
- {
- st_fail(SILENCE_USAGE);
- return ST_EOF;
- }
- else if (parse_count < 2)
- silence->start_unit = '%';
+ parse_count = sscanf(argv[1], "%lf%c", &silence->start_threshold,
+ &silence->start_unit);
+ if (parse_count < 1)
+ {
+ st_fail(SILENCE_USAGE);
+ return ST_EOF;
+ }
+ else if (parse_count < 2)
+ silence->start_unit = '%';
- argv++; argv++;
- n--; n--;
+ argv++; argv++;
+ n--; n--;
}
silence->stop = FALSE;
@@ -147,99 +147,99 @@
/* Parse data needed for trimming of backside */
if (n > 0)
{
- if (n < 3)
- {
- st_fail(SILENCE_USAGE);
- return ST_EOF;
- }
- if (sscanf(argv[0], "%d", &silence->stop_periods) != 1)
- {
- st_fail(SILENCE_USAGE);
- return ST_EOF;
- }
- if (silence->stop_periods < 0)
- {
- st_fail("Periods must not be greater then zero");
- return(ST_EOF);
- }
- silence->stop = TRUE;
- argv++;
- n--;
+ if (n < 3)
+ {
+ st_fail(SILENCE_USAGE);
+ return ST_EOF;
+ }
+ if (sscanf(argv[0], "%d", &silence->stop_periods) != 1)
+ {
+ st_fail(SILENCE_USAGE);
+ return ST_EOF;
+ }
+ if (silence->stop_periods < 0)
+ {
+ st_fail("Periods must not be greater then zero");
+ return(ST_EOF);
+ }
+ silence->stop = TRUE;
+ argv++;
+ n--;
- /* We do not know the sample rate so we can not fully
- * parse the duration info yet. So save argument off
- * for future processing.
- */
- silence->stop_duration_str = malloc(strlen(argv[0])+1);
- if (!silence->stop_duration_str)
- {
- st_fail("Could not allocate memory");
- return(ST_EOF);
- }
- strcpy(silence->stop_duration_str,argv[0]);
- /* Perform a fake parse to do error checking */
- if (st_parsesamples(0,silence->stop_duration_str,
- &silence->stop_duration,'s') !=
- ST_SUCCESS)
- {
- st_fail(SILENCE_USAGE);
- return(ST_EOF);
- }
+ /* We do not know the sample rate so we can not fully
+ * parse the duration info yet. So save argument off
+ * for future processing.
+ */
+ silence->stop_duration_str = malloc(strlen(argv[0])+1);
+ if (!silence->stop_duration_str)
+ {
+ st_fail("Could not allocate memory");
+ return(ST_EOF);
+ }
+ strcpy(silence->stop_duration_str,argv[0]);
+ /* Perform a fake parse to do error checking */
+ if (st_parsesamples(0,silence->stop_duration_str,
+ &silence->stop_duration,'s') !=
+ ST_SUCCESS)
+ {
+ st_fail(SILENCE_USAGE);
+ return(ST_EOF);
+ }
- parse_count = sscanf(argv[1], "%lf%c", &silence->stop_threshold,
- &silence->stop_unit);
- if (parse_count < 1)
- {
- st_fail(SILENCE_USAGE);
- return ST_EOF;
- }
- else if (parse_count < 2)
- silence->stop_unit = '%';
+ parse_count = sscanf(argv[1], "%lf%c", &silence->stop_threshold,
+ &silence->stop_unit);
+ if (parse_count < 1)
+ {
+ st_fail(SILENCE_USAGE);
+ return ST_EOF;
+ }
+ else if (parse_count < 2)
+ silence->stop_unit = '%';
- argv++; argv++;
- n--; n--;
+ argv++; argv++;
+ n--; n--;
}
/* Error checking */
if (silence->start)
{
- if ((silence->start_unit != '%') && (silence->start_unit != 'd'))
- {
- st_fail("Invalid unit specified");
- st_fail(SILENCE_USAGE);
- return(ST_EOF);
- }
- if ((silence->start_unit == '%') && ((silence->start_threshold < 0.0)
- || (silence->start_threshold > 100.0)))
- {
- st_fail("silence threshold should be between 0.0 and 100.0 %%");
- return (ST_EOF);
- }
- if ((silence->start_unit == 'd') && (silence->start_threshold >= 0.0))
- {
- st_fail("silence threshold should be less than 0.0 dB");
- return(ST_EOF);
- }
+ if ((silence->start_unit != '%') && (silence->start_unit != 'd'))
+ {
+ st_fail("Invalid unit specified");
+ st_fail(SILENCE_USAGE);
+ return(ST_EOF);
+ }
+ if ((silence->start_unit == '%') && ((silence->start_threshold < 0.0)
+ || (silence->start_threshold > 100.0)))
+ {
+ st_fail("silence threshold should be between 0.0 and 100.0 %%");
+ return (ST_EOF);
+ }
+ if ((silence->start_unit == 'd') && (silence->start_threshold >= 0.0))
+ {
+ st_fail("silence threshold should be less than 0.0 dB");
+ return(ST_EOF);
+ }
}
if (silence->stop)
{
- if ((silence->stop_unit != '%') && (silence->stop_unit != 'd'))
- {
- st_fail("Invalid unit specified");
- return(ST_EOF);
- }
- if ((silence->stop_unit == '%') && ((silence->stop_threshold < 0.0) ||
- (silence->stop_threshold > 100.0)))
- {
- st_fail("silence threshold should be between 0.0 and 100.0 %%");
- return (ST_EOF);
- }
- if ((silence->stop_unit == 'd') && (silence->stop_threshold >= 0.0))
- {
- st_fail("silence threshold should be less than 0.0 dB");
- return(ST_EOF);
- }
+ if ((silence->stop_unit != '%') && (silence->stop_unit != 'd'))
+ {
+ st_fail("Invalid unit specified");
+ return(ST_EOF);
+ }
+ if ((silence->stop_unit == '%') && ((silence->stop_threshold < 0.0) ||
+ (silence->stop_threshold > 100.0)))
+ {
+ st_fail("silence threshold should be between 0.0 and 100.0 %%");
+ return (ST_EOF);
+ }
+ if ((silence->stop_unit == 'd') && (silence->stop_threshold >= 0.0))
+ {
+ st_fail("silence threshold should be less than 0.0 dB");
+ return(ST_EOF);
+ }
}
return(ST_SUCCESS);
}
@@ -246,73 +246,73 @@
int st_silence_start(eff_t effp)
{
- silence_t silence = (silence_t) effp->priv;
+ silence_t silence = (silence_t) effp->priv;
- silence->window_size = (effp->ininfo.rate / 10) * effp->ininfo.channels;
- silence->window = (double *)malloc(silence->window_size *
- sizeof(double));
+ silence->window_size = (effp->ininfo.rate / 10) * effp->ininfo.channels;
+ silence->window = (double *)malloc(silence->window_size *
+ sizeof(double));
- if (!silence->window)
- {
- st_fail("Unable to allocate memory");
- return(ST_EOF);
- }
+ if (!silence->window)
+ {
+ st_fail("Unable to allocate memory");
+ return(ST_EOF);
+ }
- memset(silence->window, 0,
- silence->window_size * sizeof(double));
+ memset(silence->window, 0,
+ silence->window_size * sizeof(double));
- silence->window_current = silence->window;
- silence->window_end = silence->window + silence->window_size;
- silence->rms_sum = 0;
+ silence->window_current = silence->window;
+ silence->window_end = silence->window + silence->window_size;
+ silence->rms_sum = 0;
- /* Now that we now sample rate, reparse duration. */
- if (silence->start)
- {
- if (st_parsesamples(effp->ininfo.rate, silence->start_duration_str,
- &silence->start_duration, 's') !=
- ST_SUCCESS)
- {
- st_fail(SILENCE_USAGE);
- return(ST_EOF);
- }
- }
- if (silence->stop)
- {
- if (st_parsesamples(effp->ininfo.rate,silence->stop_duration_str,
- &silence->stop_duration,'s') !=
- ST_SUCCESS)
- {
- st_fail(SILENCE_USAGE);
- return(ST_EOF);
- }
- }
+ /* Now that we now sample rate, reparse duration. */
+ if (silence->start)
+ {
+ if (st_parsesamples(effp->ininfo.rate, silence->start_duration_str,
+ &silence->start_duration, 's') !=
+ ST_SUCCESS)
+ {
+ st_fail(SILENCE_USAGE);
+ return(ST_EOF);
+ }
+ }
+ if (silence->stop)
+ {
+ if (st_parsesamples(effp->ininfo.rate,silence->stop_duration_str,
+ &silence->stop_duration,'s') !=
+ ST_SUCCESS)
+ {
+ st_fail(SILENCE_USAGE);
+ return(ST_EOF);
+ }
+ }
- if (silence->start)
- silence->mode = SILENCE_TRIM;
- else
- silence->mode = SILENCE_COPY;
+ if (silence->start)
+ silence->mode = SILENCE_TRIM;
+ else
+ silence->mode = SILENCE_COPY;
- silence->start_holdoff = malloc(sizeof(st_sample_t)*silence->start_duration);
- if (!silence->start_holdoff)
- {
- st_fail("Could not allocate memory");
- return(ST_EOF);
- }
- silence->start_holdoff_offset = 0;
- silence->start_holdoff_end = 0;
- silence->start_found_periods = 0;
+ silence->start_holdoff = malloc(sizeof(st_sample_t)*silence->start_duration);
+ if (!silence->start_holdoff)
+ {
+ st_fail("Could not allocate memory");
+ return(ST_EOF);
+ }
+ silence->start_holdoff_offset = 0;
+ silence->start_holdoff_end = 0;
+ silence->start_found_periods = 0;
- silence->stop_holdoff = malloc(sizeof(st_sample_t)*silence->stop_duration);
- if (!silence->stop_holdoff)
- {
- st_fail("Could not allocate memory");
- return(ST_EOF);
- }
- silence->stop_holdoff_offset = 0;
- silence->stop_holdoff_end = 0;
- silence->stop_found_periods = 0;
+ silence->stop_holdoff = malloc(sizeof(st_sample_t)*silence->stop_duration);
+ if (!silence->stop_holdoff)
+ {
+ st_fail("Could not allocate memory");
+ return(ST_EOF);
+ }
+ silence->stop_holdoff_offset = 0;
+ silence->stop_holdoff_end = 0;
+ silence->stop_found_periods = 0;
- return(ST_SUCCESS);
+ return(ST_SUCCESS);
}
int aboveThreshold(eff_t effp, st_sample_t value, double threshold, char unit)
@@ -324,26 +324,26 @@
/* Only consider the original bits when looking for silence */
switch(effp->ininfo.size)
{
- case ST_SIZE_BYTE:
- value = ST_SAMPLE_TO_SIGNED_BYTE(value);
- ratio = (double)abs(value) / (double)ST_INT8_MAX;
- break;
- case ST_SIZE_WORD:
- value = ST_SAMPLE_TO_SIGNED_WORD(value);
- ratio = (double)abs(value) / (double)ST_INT16_MAX;
- break;
- case ST_SIZE_DWORD:
- value = ST_SAMPLE_TO_SIGNED_DWORD(value);
- ratio = (double)labs(value) / (double)ST_INT32_MAX;
- break;
- default:
- ratio = 0;
+ case ST_SIZE_BYTE:
+ value = ST_SAMPLE_TO_SIGNED_BYTE(value);
+ ratio = (double)abs(value) / (double)ST_INT8_MAX;
+ break;
+ case ST_SIZE_WORD:
+ value = ST_SAMPLE_TO_SIGNED_WORD(value);
+ ratio = (double)abs(value) / (double)ST_INT16_MAX;
+ break;
+ case ST_SIZE_DWORD:
+ value = ST_SAMPLE_TO_SIGNED_DWORD(value);
+ ratio = (double)labs(value) / (double)ST_INT32_MAX;
+ break;
+ default:
+ ratio = 0;
}
if (unit == '%')
- ratio *= 100.0;
+ ratio *= 100.0;
else if (unit == 'd')
- ratio = log10(ratio) * 20.0;
+ ratio = log10(ratio) * 20.0;
rc = (ratio >= threshold);
return rc;
@@ -374,7 +374,7 @@
silence->window_current++;
if (silence->window_current >= silence->window_end)
- silence->window_current = silence->window;
+ silence->window_current = silence->window;
}
/* Process signed long samples from ibuf to obuf. */
@@ -383,7 +383,8 @@
st_size_t *isamp, st_size_t *osamp)
{
silence_t silence = (silence_t) effp->priv;
- int threshold, i, j;
+ int threshold, j;
+ st_size_t i;
st_size_t nrOfTicks, nrOfInSamplesRead, nrOfOutSamplesWritten;
nrOfInSamplesRead = 0;
@@ -391,230 +392,230 @@
switch (silence->mode)
{
- case SILENCE_TRIM:
- /* Reads and discards all input data until it detects a
- * sample that is above the specified threshold. Turns on
- * copy mode when detected.
- * Need to make sure and copy input in groups of "channels" to
- * prevent getting buffers out of sync.
- */
- nrOfTicks = min((*isamp), (*osamp)) / effp->ininfo.channels;
- for(i = 0; i < nrOfTicks; i++)
- {
- threshold = 0;
- for (j = 0; j < effp->ininfo.channels; j++)
- {
- threshold |= aboveThreshold(effp,
- compute_rms(effp, ibuf[j]),
- silence->start_threshold,
- silence->start_unit);
- }
+ case SILENCE_TRIM:
+ /* Reads and discards all input data until it detects a
+ * sample that is above the specified threshold. Turns on
+ * copy mode when detected.
+ * Need to make sure and copy input in groups of "channels" to
+ * prevent getting buffers out of sync.
+ */
+ nrOfTicks = min((*isamp), (*osamp)) / effp->ininfo.channels;
+ for(i = 0; i < nrOfTicks; i++)
+ {
+ threshold = 0;
+ for (j = 0; j < effp->ininfo.channels; j++)
+ {
+ threshold |= aboveThreshold(effp,
+ compute_rms(effp, ibuf[j]),
+ silence->start_threshold,
+ silence->start_unit);
+ }
- if (threshold)
- {
- /* Add to holdoff buffer */
- for (j = 0; j < effp->ininfo.channels; j++)
- {
- update_rms(effp, *ibuf);
- silence->start_holdoff[
- silence->start_holdoff_end++] = *ibuf++;
- nrOfInSamplesRead++;
- }
+ if (threshold)
+ {
+ /* Add to holdoff buffer */
+ for (j = 0; j < effp->ininfo.channels; j++)
+ {
+ update_rms(effp, *ibuf);
+ silence->start_holdoff[
+ silence->start_holdoff_end++] = *ibuf++;
+ nrOfInSamplesRead++;
+ }
- if (silence->start_holdoff_end >=
- silence->start_duration)
- {
- if (++silence->start_found_periods >=
- silence->start_periods)
- {
- silence->mode = SILENCE_TRIM_FLUSH;
- goto silence_trim_flush;
- }
- /* Trash holdoff buffer since its not
- * needed. Start looking again.
- */
- silence->start_holdoff_offset = 0;
- silence->start_holdoff_end = 0;
- }
- }
- else /* !above Threshold */
- {
- silence->start_holdoff_end = 0;
- for (j = 0; j < effp->ininfo.channels; j++)
- {
- update_rms(effp, ibuf[j]);
- }
- ibuf += effp->ininfo.channels;
- nrOfInSamplesRead += effp->ininfo.channels;
- }
- } /* for nrOfTicks */
- break;
+ if (silence->start_holdoff_end >=
+ silence->start_duration)
+ {
+ if (++silence->start_found_periods >=
+ silence->start_periods)
+ {
+ silence->mode = SILENCE_TRIM_FLUSH;
+ goto silence_trim_flush;
+ }
+ /* Trash holdoff buffer since its not
+ * needed. Start looking again.
+ */
+ silence->start_holdoff_offset = 0;
+ silence->start_holdoff_end = 0;
+ }
+ }
+ else /* !above Threshold */
+ {
+ silence->start_holdoff_end = 0;
+ for (j = 0; j < effp->ininfo.channels; j++)
+ {
+ update_rms(effp, ibuf[j]);
+ }
+ ibuf += effp->ininfo.channels;
+ nrOfInSamplesRead += effp->ininfo.channels;
+ }
+ } /* for nrOfTicks */
+ break;
- case SILENCE_TRIM_FLUSH:
+ case SILENCE_TRIM_FLUSH:
silence_trim_flush:
- nrOfTicks = min((silence->start_holdoff_end -
- silence->start_holdoff_offset),
- (*osamp-nrOfOutSamplesWritten));
- for(i = 0; i < nrOfTicks; i++)
- {
- *obuf++ = silence->start_holdoff[silence->start_holdoff_offset++];
- nrOfOutSamplesWritten++;
- }
+ nrOfTicks = min((silence->start_holdoff_end -
+ silence->start_holdoff_offset),
+ (*osamp-nrOfOutSamplesWritten));
+ for(i = 0; i < nrOfTicks; i++)
+ {
+ *obuf++ = silence->start_holdoff[silence->start_holdoff_offset++];
+ nrOfOutSamplesWritten++;
+ }
- /* If fully drained holdoff then switch to copy mode */
- if (silence->start_holdoff_offset == silence->start_holdoff_end)
- {
- silence->start_holdoff_offset = 0;
- silence->start_holdoff_end = 0;
- silence->mode = SILENCE_COPY;
- goto silence_copy;
- }
- break;
+ /* If fully drained holdoff then switch to copy mode */
+ if (silence->start_holdoff_offset == silence->start_holdoff_end)
+ {
+ silence->start_holdoff_offset = 0;
+ silence->start_holdoff_end = 0;
+ silence->mode = SILENCE_COPY;
+ goto silence_copy;
+ }
+ break;
- case SILENCE_COPY:
- /* Attempts to copy samples into output buffer. If not
- * looking for silence to terminate copy then blindly
- * copy data into output buffer.
- *
- * If looking for silence, then see if input sample is above
- * threshold. If found then flush out hold off buffer
- * and copy over to output buffer. Tell user about
- * input and output processing.
- *
- * If not above threshold then store in hold off buffer
- * and do not write to output buffer. Tell user input
- * was processed.
- *
- * If hold off buffer is full then stop copying data and
- * discard data in hold off buffer.
- */
+ case SILENCE_COPY:
+ /* Attempts to copy samples into output buffer. If not
+ * looking for silence to terminate copy then blindly
+ * copy data into output buffer.
+ *
+ * If looking for silence, then see if input sample is above
+ * threshold. If found then flush out hold off buffer
+ * and copy over to output buffer. Tell user about
+ * input and output processing.
+ *
+ * If not above threshold then store in hold off buffer
+ * and do not write to output buffer. Tell user input
+ * was processed.
+ *
+ * If hold off buffer is full then stop copying data and
+ * discard data in hold off buffer.
+ */
silence_copy:
- nrOfTicks = min((*isamp-nrOfInSamplesRead),
- (*osamp-nrOfOutSamplesWritten)) /
- effp->ininfo.channels;
- if (silence->stop)
- {
- for(i = 0; i < nrOfTicks; i++)
- {
- threshold = 1;
- for (j = 0; j < effp->ininfo.channels; j++)
- {
- threshold &= aboveThreshold(effp,
- compute_rms(effp, ibuf[j]),
- silence->stop_threshold,
- silence->stop_unit);
- }
+ nrOfTicks = min((*isamp-nrOfInSamplesRead),
+ (*osamp-nrOfOutSamplesWritten)) /
+ effp->ininfo.channels;
+ if (silence->stop)
+ {
+ for(i = 0; i < nrOfTicks; i++)
+ {
+ threshold = 1;
+ for (j = 0; j < effp->ininfo.channels; j++)
+ {
+ threshold &= aboveThreshold(effp,
+ compute_rms(effp, ibuf[j]),
+ silence->stop_threshold,
+ silence->stop_unit);
+ }
- /* If above threshold, check to see if we where holding
- * off previously. If so then flush this buffer.
- * We haven't incremented any pointers yet so nothing
- * is lost.
- */
- if (threshold && silence->stop_holdoff_end)
- {
- silence->mode = SILENCE_COPY_FLUSH;
- goto silence_copy_flush;
- }
- else if (threshold)
- {
- /* Not holding off so copy into output buffer */
- for (j = 0; j < effp->ininfo.channels; j++)
- {
- update_rms(effp, *ibuf);
- *obuf++ = *ibuf++;
- nrOfInSamplesRead++;
- nrOfOutSamplesWritten++;
- }
- }
- else if (!threshold)
- {
- /* Add to holdoff buffer */
- for (j = 0; j < effp->ininfo.channels; j++)
- {
- update_rms(effp, *ibuf);
- silence->stop_holdoff[
- silence->stop_holdoff_end++] = *ibuf++;
- nrOfInSamplesRead++;
- }
+ /* If above threshold, check to see if we where holding
+ * off previously. If so then flush this buffer.
+ * We haven't incremented any pointers yet so nothing
+ * is lost.
+ */
+ if (threshold && silence->stop_holdoff_end)
+ {
+ silence->mode = SILENCE_COPY_FLUSH;
+ goto silence_copy_flush;
+ }
+ else if (threshold)
+ {
+ /* Not holding off so copy into output buffer */
+ for (j = 0; j < effp->ininfo.channels; j++)
+ {
+ update_rms(effp, *ibuf);
+ *obuf++ = *ibuf++;
+ nrOfInSamplesRead++;
+ nrOfOutSamplesWritten++;
+ }
+ }
+ else if (!threshold)
+ {
+ /* Add to holdoff buffer */
+ for (j = 0; j < effp->ininfo.channels; j++)
+ {
+ update_rms(effp, *ibuf);
+ silence->stop_holdoff[
+ silence->stop_holdoff_end++] = *ibuf++;
+ nrOfInSamplesRead++;
+ }
+
+ /* Check if holdoff buffer is greater than duration
+ */
+ if (silence->stop_holdoff_end >=
+ silence->stop_duration)
+ {
+ /* Increment found counter and see if this
+ * is the last period. If so then exit.
+ */
+ if (++silence->stop_found_periods >=
+ silence->stop_periods)
+ {
+ silence->mode = SILENCE_STOP;
+ silence->stop_holdoff_offset = 0;
+ silence->stop_holdoff_end = 0;
+ *isamp = nrOfInSamplesRead;
+ *osamp = nrOfOutSamplesWritten;
+ /* Return ST_EOF since no more processing */
+ return (ST_EOF);
+ }
+ else
+ {
+ /* Flush this buffer and start
+ * looking again.
+ */
+ silence->mode = SILENCE_COPY_FLUSH;
+ goto silence_copy_flush;
+ }
+ break;
+ } /* Filled holdoff buffer */
+ } /* Detected silence */
+ } /* For # of samples */
+ } /* Trimming off backend */
+ else /* !(silence->stop) */
+ {
+ memcpy(obuf, ibuf, sizeof(st_sample_t)*nrOfTicks*
+ effp->ininfo.channels);
+ nrOfInSamplesRead += (nrOfTicks*effp->ininfo.channels);
+ nrOfOutSamplesWritten += (nrOfTicks*effp->ininfo.channels);
+ }
+ break;
- /* Check if holdoff buffer is greater than duration
- */
- if (silence->stop_holdoff_end >=
- silence->stop_duration)
- {
- /* Increment found counter and see if this
- * is the last period. If so then exit.
- */
- if (++silence->stop_found_periods >=
- silence->stop_periods)
- {
- silence->mode = SILENCE_STOP;
- silence->stop_holdoff_offset = 0;
- silence->stop_holdoff_end = 0;
- *isamp = nrOfInSamplesRead;
- *osamp = nrOfOutSamplesWritten;
- /* Return ST_EOF since no more processing */
- return (ST_EOF);
- }
- else
- {
- /* Flush this buffer and start
- * looking again.
- */
- silence->mode = SILENCE_COPY_FLUSH;
- goto silence_copy_flush;
- }
- break;
- } /* Filled holdoff buffer */
- } /* Detected silence */
- } /* For # of samples */
- } /* Trimming off backend */
- else /* !(silence->stop) */
- {
- memcpy(obuf, ibuf, sizeof(st_sample_t)*nrOfTicks*
- effp->ininfo.channels);
- nrOfInSamplesRead += (nrOfTicks*effp->ininfo.channels);
- nrOfOutSamplesWritten += (nrOfTicks*effp->ininfo.channels);
- }
- break;
-
- case SILENCE_COPY_FLUSH:
+ case SILENCE_COPY_FLUSH:
silence_copy_flush:
- nrOfTicks = min((silence->stop_holdoff_end -
- silence->stop_holdoff_offset),
- (*osamp-nrOfOutSamplesWritten));
+ nrOfTicks = min((silence->stop_holdoff_end -
+ silence->stop_holdoff_offset),
+ (*osamp-nrOfOutSamplesWritten));
- for(i = 0; i < nrOfTicks; i++)
- {
- *obuf++ = silence->stop_holdoff[silence->stop_holdoff_offset++];
- nrOfOutSamplesWritten++;
- }
+ for(i = 0; i < nrOfTicks; i++)
+ {
+ *obuf++ = silence->stop_holdoff[silence->stop_holdoff_offset++];
+ nrOfOutSamplesWritten++;
+ }
- /* If fully drained holdoff then return to copy mode */
- if (silence->stop_holdoff_offset == silence->stop_holdoff_end)
- {
- silence->stop_holdoff_offset = 0;
- silence->stop_holdoff_end = 0;
- silence->mode = SILENCE_COPY;
- goto silence_copy;
- }
- break;
+ /* If fully drained holdoff then return to copy mode */
+ if (silence->stop_holdoff_offset == silence->stop_holdoff_end)
+ {
+ silence->stop_holdoff_offset = 0;
+ silence->stop_holdoff_end = 0;
+ silence->mode = SILENCE_COPY;
+ goto silence_copy;
+ }
+ break;
- case SILENCE_STOP:
- nrOfInSamplesRead = *isamp;
- break;
- }
+ case SILENCE_STOP:
+ nrOfInSamplesRead = *isamp;
+ break;
+ }
- *isamp = nrOfInSamplesRead;
- *osamp = nrOfOutSamplesWritten;
+ *isamp = nrOfInSamplesRead;
+ *osamp = nrOfOutSamplesWritten;
- return (ST_SUCCESS);
+ return (ST_SUCCESS);
}
int st_silence_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
silence_t silence = (silence_t) effp->priv;
- int i;
+ st_size_t i;
st_size_t nrOfTicks, nrOfOutSamplesWritten = 0;
/* Only if in flush mode will there be possible samples to write
@@ -621,23 +622,23 @@
* out during drain() call.
*/
if (silence->mode == SILENCE_COPY_FLUSH ||
- silence->mode == SILENCE_COPY)
+ silence->mode == SILENCE_COPY)
{
nrOfTicks = min((silence->stop_holdoff_end -
- silence->stop_holdoff_offset), *osamp);
- for(i = 0; i < nrOfTicks; i++)
- {
- *obuf++ = silence->stop_holdoff[silence->stop_holdoff_offset++];
- nrOfOutSamplesWritten++;
+ silence->stop_holdoff_offset), *osamp);
+ for(i = 0; i < nrOfTicks; i++)
+ {
+ *obuf++ = silence->stop_holdoff[silence->stop_holdoff_offset++];
+ nrOfOutSamplesWritten++;
}
- /* If fully drained holdoff then stop */
- if (silence->stop_holdoff_offset == silence->stop_holdoff_end)
- {
- silence->stop_holdoff_offset = 0;
- silence->stop_holdoff_end = 0;
- silence->mode = SILENCE_STOP;
- }
+ /* If fully drained holdoff then stop */
+ if (silence->stop_holdoff_offset == silence->stop_holdoff_end)
+ {
+ silence->stop_holdoff_offset = 0;
+ silence->stop_holdoff_end = 0;
+ silence->mode = SILENCE_STOP;
+ }
}
*osamp = nrOfOutSamplesWritten;
@@ -649,10 +650,10 @@
silence_t silence = (silence_t) effp->priv;
if (silence->window)
- free(silence->window);
+ free(silence->window);
if (silence->start_holdoff)
- free(silence->start_holdoff);
+ free(silence->start_holdoff);
if (silence->stop_holdoff)
- free(silence->stop_holdoff);
+ free(silence->stop_holdoff);
return(ST_SUCCESS);
}
--- a/src/sox.c
+++ b/src/sox.c
@@ -133,7 +133,7 @@
int argc_effect;
ft_t ft;
int parsing_output = 0;
- int i;
+ int i;
myname = argv[0];
@@ -290,13 +290,13 @@
process();
statistics();
- for (i = 0; i < input_count; i++)
- {
- if (informat[i])
- free(informat[i]);
- }
- if (outformat)
- free(outformat);
+ for (i = 0; i < input_count; i++)
+ {
+ if (informat[i])
+ free(informat[i]);
+ }
+ if (outformat)
+ free(outformat);
return(0);
}
@@ -310,7 +310,7 @@
if ( st_gettype(ft) )
st_fail("Unknown input file format for '%s': %s",
- ft->filename, ft->st_errstr);
+ ft->filename, ft->st_errstr);
/* Default the input comment to the filename if not set from
* command line.
@@ -370,7 +370,7 @@
{
if ( st_gettype(ft) )
st_fail("Unknown output file format for '%s': %s",
- ft->filename, ft->st_errstr);
+ ft->filename, ft->st_errstr);
}
@@ -469,13 +469,13 @@
str = optarg;
if (!sscanf(str, "%d", &i))
st_fail("-c must be given a number");
- /* Since we use -1 as a special internal value,
- * we must do some extra logic so user doesn't
- * get confused when we translate -1 to mean
- * something valid.
- */
- if (i < 1)
- st_fail("-c must be given a positive number");
+ /* Since we use -1 as a special internal value,
+ * we must do some extra logic so user doesn't
+ * get confused when we translate -1 to mean
+ * something valid.
+ */
+ if (i < 1)
+ st_fail("-c must be given a positive number");
ft->info.channels = i;
break;
case 'b':
@@ -567,7 +567,7 @@
static void process(void) {
int e, f, flowstatus;
#ifdef SOXMIX
- int s;
+ st_size_t s;
st_ssize_t ilen[MAX_INPUT_FILES];
st_sample_t *ibuf[MAX_INPUT_FILES];
#endif
@@ -655,7 +655,7 @@
for(e = 0; e < neffects; e++)
{
efftab[e].obuf = (st_sample_t *) malloc(ST_BUFSIZ *
- sizeof(st_sample_t));
+ sizeof(st_sample_t));
if (efftab[e].obuf == NULL)
{
st_fail("could not allocate memory");
@@ -663,7 +663,7 @@
if (efftabR[e].name)
{
efftabR[e].obuf = (st_sample_t *) malloc(ST_BUFSIZ *
- sizeof(st_sample_t));
+ sizeof(st_sample_t));
if (efftabR[e].obuf == NULL)
{
st_fail("could not allocate memory");
@@ -696,18 +696,23 @@
#ifndef SOXMIX
efftab[0].olen = (*informat[0]->h->read)(informat[0],
efftab[0].obuf,
- (st_ssize_t)ST_BUFSIZ);
+ (st_ssize_t)ST_BUFSIZ);
#else
for (f = 0; f < input_count; f++)
{
ilen[f] = (*informat[f]->h->read)(informat[f],
ibuf[f],
- (st_ssize_t)ST_BUFSIZ);
+ (st_ssize_t)ST_BUFSIZ);
}
+ /* FIXME: Should check for ST_EOF from read and
+ * abort!
+ * FIXME: Should warn if the size of the reads are not
+ * the same!
+ */
efftab[0].olen = 0;
for (f = 0; f < input_count; f++)
- if (ilen[f] > efftab[0].olen)
+ if ((st_size_t)ilen[f] > efftab[0].olen)
efftab[0].olen = ilen[f];
for (s = 0; s < efftab[0].olen; s++)
@@ -720,9 +725,9 @@
{
if (f == 0)
efftab[0].obuf[s] =
- (s<ilen[f]) ? (ibuf[f][s]/input_count) : 0;
+ (s<(st_size_t)ilen[f]) ? (ibuf[f][s]/input_count) : 0;
else
- if (s < ilen[f])
+ if (s < (st_size_t)ilen[f])
efftab[0].obuf[s] += ibuf[f][s]/input_count;
}
}
@@ -730,12 +735,12 @@
efftab[0].odone = 0;
- /* If not writing and no effects are occuring then not much
- * reason to continue reading. This allows this case. Mainly
- * useful to print out info about input file header and quite.
- */
- if (!writing && neffects == 1)
- efftab[0].olen = 0;
+ /* If not writing and no effects are occuring then not much
+ * reason to continue reading. This allows this case. Mainly
+ * useful to print out info about input file header and quite.
+ */
+ if (!writing && neffects == 1)
+ efftab[0].olen = 0;
if (efftab[0].olen == 0)
break;
@@ -790,7 +795,7 @@
{
free(efftab[e].obuf);
if (efftabR[e].obuf)
- free(efftabR[e].obuf);
+ free(efftabR[e].obuf);
}
/* Very Important:
@@ -1155,7 +1160,7 @@
}
static st_sample_t volumechange(st_sample_t *buf, st_ssize_t ct,
- double vol)
+ double vol)
{
double y;
st_sample_t *p,*top;
@@ -1235,16 +1240,16 @@
{
if (informat[i] && informat[i]->fp)
fclose(informat[i]->fp);
- if (informat[i])
- free(informat[i]);
+ if (informat[i])
+ free(informat[i]);
}
if (outformat && outformat->fp) {
- fclose(outformat->fp);
- /* remove the output file because we failed, if it's ours. */
- /* Don't if its not a regular file. */
- if (filetype(fileno(outformat->fp)) == S_IFREG)
- unlink(outformat->filename);
+ fclose(outformat->fp);
+ /* remove the output file because we failed, if it's ours. */
+ /* Don't if its not a regular file. */
+ if (filetype(fileno(outformat->fp)) == S_IFREG)
+ unlink(outformat->filename);
}
if (outformat)
- free(outformat);
+ free(outformat);
}
--- a/src/speed.c
+++ b/src/speed.c
@@ -67,8 +67,8 @@
static void debug(char * where, speed_t s)
{
fprintf(stderr, "%s: f=%f r=%f comp=%d i=%d ic=%d frac=%f state=%d v=%f\n",
- where, s->factor, s->rate, s->compression, s->index,
- s->icbuf, s->frac, s->state, s->cbuf[0]);
+ where, s->factor, s->rate, s->compression, s->index,
+ s->icbuf, s->frac, s->state, s->cbuf[0]);
}
*/
@@ -97,16 +97,16 @@
{
if (v < -ST_SAMPLE_MAX)
{
- speed->clipped++;
- return -ST_SAMPLE_MAX;
+ speed->clipped++;
+ return -ST_SAMPLE_MAX;
}
else if (v > ST_SAMPLE_MAX)
{
- speed->clipped++;
- return ST_SAMPLE_MAX;
+ speed->clipped++;
+ return ST_SAMPLE_MAX;
}
else
- return (st_sample_t) v;
+ return (st_sample_t) v;
}
/* get options. */
@@ -119,21 +119,21 @@
if (n>0 && !strcmp(argv[0], "-c"))
{
- cent = 1;
- argv++; n--;
+ cent = 1;
+ argv++; n--;
}
if (n && (!sscanf(argv[0], SPEED_FLOAT_SCAN, &speed->factor) ||
- (cent==0 && speed->factor<=ZERO)))
+ (cent==0 && speed->factor<=ZERO)))
{
- printf("n = %d cent = %d speed = %f\n",n,cent,speed->factor);
- st_fail(SPEED_USAGE);
- return ST_EOF;
+ printf("n = %d cent = %d speed = %f\n",n,cent,speed->factor);
+ st_fail(SPEED_USAGE);
+ return ST_EOF;
}
else if (cent != 0) /* CONST==2**(1/1200) */
{
- speed->factor = pow(1.00057778950655, speed->factor);
- /* fprintf(stderr, "Speed factor: %f\n", speed->factor);*/
+ speed->factor = pow(1.00057778950655, speed->factor);
+ /* fprintf(stderr, "Speed factor: %f\n", speed->factor);*/
}
return ST_SUCCESS;
@@ -147,17 +147,17 @@
if (speed->factor >= ONE)
{
- speed->compression = (int) speed->factor; /* floor */
- speed->rate = speed->factor / speed->compression;
+ speed->compression = (int) speed->factor; /* floor */
+ speed->rate = speed->factor / speed->compression;
}
else
{
- speed->compression = 1;
- speed->rate = speed->factor;
+ speed->compression = 1;
+ speed->rate = speed->factor;
}
speed->ibuf = (st_sample_t *) malloc(speed->compression*
- sizeof(st_sample_t));
+ sizeof(st_sample_t));
speed->index = 0;
speed->state = sp_input;
@@ -166,8 +166,8 @@
speed->frac = ZERO;
if (!speed->ibuf) {
- st_fail("malloc failed");
- return ST_EOF;
+ st_fail("malloc failed");
+ return ST_EOF;
}
return ST_SUCCESS;
@@ -185,14 +185,14 @@
register SPEED_FLOAT s = ZERO;
for (i=0; i<speed->index; i++)
- s += (SPEED_FLOAT) speed->ibuf[i];
+ s += (SPEED_FLOAT) speed->ibuf[i];
speed->cbuf[speed->icbuf++] = s / ((SPEED_FLOAT) speed->index);
if (speed->icbuf == 4)
- speed->state = sp_compute;
+ speed->state = sp_compute;
else
- speed->state = sp_input;
+ speed->state = sp_input;
speed->index = 0;
}
@@ -201,24 +201,24 @@
*/
static st_size_t compute(speed_t speed, st_sample_t *obuf, st_size_t olen)
{
- register int i;
+ st_size_t i;
for(i = 0;
- i<olen && speed->frac < ONE;
- i++, speed->frac += speed->rate)
- obuf[i] = clip(speed,
- cub(speed->cbuf[0], speed->cbuf[1],
- speed->cbuf[2], speed->cbuf[3],
- speed->frac));
+ i<olen && speed->frac < ONE;
+ i++, speed->frac += speed->rate)
+ obuf[i] = clip(speed,
+ cub(speed->cbuf[0], speed->cbuf[1],
+ speed->cbuf[2], speed->cbuf[3],
+ speed->frac));
if (speed->frac >= ONE)
{
- speed->frac -= ONE;
- speed->cbuf[0] = speed->cbuf[1];
- speed->cbuf[1] = speed->cbuf[2];
- speed->cbuf[2] = speed->cbuf[3];
- speed->icbuf = 3;
- speed->state = sp_input;
+ speed->frac -= ONE;
+ speed->cbuf[0] = speed->cbuf[1];
+ speed->cbuf[1] = speed->cbuf[2];
+ speed->cbuf[2] = speed->cbuf[3];
+ speed->icbuf = 3;
+ speed->state = sp_input;
}
return i; /* number of data out */
@@ -227,7 +227,7 @@
/* handle a flow.
*/
int st_speed_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
- st_size_t *isamp, st_size_t *osamp)
+ st_size_t *isamp, st_size_t *osamp)
{
speed_t speed;
register st_size_t len, iindex, oindex;
@@ -240,21 +240,21 @@
while (iindex<len && oindex<len)
{
- /* store to input buffer. */
- if (speed->state==sp_input)
- {
- speed->ibuf[speed->index++] = ibuf[iindex++];
- if (speed->index==speed->compression)
- speed->state = sp_transfer;
- }
+ /* store to input buffer. */
+ if (speed->state==sp_input)
+ {
+ speed->ibuf[speed->index++] = ibuf[iindex++];
+ if (speed->index==speed->compression)
+ speed->state = sp_transfer;
+ }
- /* transfer to compute buffer. */
- if (speed->state==sp_transfer)
- transfer(speed);
+ /* transfer to compute buffer. */
+ if (speed->state==sp_transfer)
+ transfer(speed);
- /* compute interpolation. */
- if (speed->state==sp_compute)
- oindex += compute(speed, obuf+oindex, len-oindex);
+ /* compute interpolation. */
+ if (speed->state==sp_compute)
+ oindex += compute(speed, obuf+oindex, len-oindex);
}
*isamp = iindex;
@@ -268,7 +268,7 @@
int st_speed_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
speed_t speed = (speed_t) effp->priv;
- register int i, oindex;
+ st_size_t i, oindex;
transfer(speed);
@@ -275,8 +275,8 @@
/* fix up trail by emptying cbuf */
for (oindex=0, i=0; i<2 && oindex<*osamp;)
{
- if (speed->state==sp_input)
- {
+ if (speed->state==sp_input)
+ {
speed->ibuf[speed->index++] = ZERO;
i++;
if (speed->index==speed->compression)
@@ -304,7 +304,7 @@
speed_t speed = (speed_t) effp->priv;
if (speed->clipped)
- st_warn("SPEED: %d values clipped...", speed->clipped);
+ st_warn("SPEED: %d values clipped...", speed->clipped);
free(speed->ibuf);
--- a/src/stretch.c
+++ b/src/stretch.c
@@ -41,16 +41,16 @@
/* ok, it looks stupid to have such constant.
this is because of the cast, if floats are switched to doubles.
*/
-#define ZERO ((STRETCH_FLOAT)(0.0e0))
-#define HALF ((STRETCH_FLOAT)(0.5e0))
-#define ONE ((STRETCH_FLOAT)(1.0e0))
-#define MONE ((STRETCH_FLOAT)(-1.0e0))
-#define ONETHOUSANDS ((STRETCH_FLOAT)(0.001e0))
+#define ZERO ((STRETCH_FLOAT)(0.0e0))
+#define HALF ((STRETCH_FLOAT)(0.5e0))
+#define ONE ((STRETCH_FLOAT)(1.0e0))
+#define MONE ((STRETCH_FLOAT)(-1.0e0))
+#define ONETHOUSANDS ((STRETCH_FLOAT)(0.001e0))
-#define DEFAULT_SLOW_SHIFT_RATIO ((STRETCH_FLOAT)(0.8e0))
-#define DEFAULT_FAST_SHIFT_RATIO ONE
+#define DEFAULT_SLOW_SHIFT_RATIO ((STRETCH_FLOAT)(0.8e0))
+#define DEFAULT_FAST_SHIFT_RATIO ONE
-#define DEFAULT_STRETCH_WINDOW ((STRETCH_FLOAT)(20.0e0)) /* ms */
+#define DEFAULT_STRETCH_WINDOW ((STRETCH_FLOAT)(20.0e0)) /* ms */
/* I'm planing to put some common fading stuff outside.
It's also used in pitch.c
@@ -95,11 +95,11 @@
static void debug(stretch_t s, char * where)
{
fprintf(stderr,
- "%s: (f=%.2f w=%.2f r=%.2f f=%.2f)"
- " st=%d s=%d ii=%d is=%d oi=%d os=%d fs=%d\n",
- where, s->factor, s->window, s->shift, s->fading,
- s->state, s->size, s->index, s->ishift,
- s->oindex, s->oshift, s->fsize);
+ "%s: (f=%.2f w=%.2f r=%.2f f=%.2f)"
+ " st=%d s=%d ii=%d is=%d oi=%d os=%d fs=%d\n",
+ where, s->factor, s->window, s->shift, s->fading,
+ s->state, s->size, s->index, s->ishift,
+ s->oindex, s->oshift, s->fsize);
}
*/
@@ -109,17 +109,17 @@
{
if (v < -ST_SAMPLE_MAX)
{
- stretch->clipped++;
- return -ST_SAMPLE_MAX;
+ stretch->clipped++;
+ return -ST_SAMPLE_MAX;
}
else if (v > ST_SAMPLE_MAX)
{
- stretch->clipped++;
- return ST_SAMPLE_MAX;
+ stretch->clipped++;
+ return ST_SAMPLE_MAX;
}
else
{
- return (st_sample_t) v;
+ return (st_sample_t) v;
}
}
@@ -137,44 +137,44 @@
if (n>0 && !sscanf(argv[0], STRETCH_FLOAT_SCAN, &stretch->factor))
{
- st_fail(STRETCH_USAGE "\n\terror while parsing factor");
- return ST_EOF;
+ st_fail(STRETCH_USAGE "\n\terror while parsing factor");
+ return ST_EOF;
}
if (n>1 && !sscanf(argv[1], STRETCH_FLOAT_SCAN, &stretch->window))
{
- st_fail(STRETCH_USAGE "\n\terror while parsing window size");
- return ST_EOF;
+ st_fail(STRETCH_USAGE "\n\terror while parsing window size");
+ return ST_EOF;
}
if (n>2)
{
- switch (argv[2][0])
- {
- case 'l':
- case 'L':
- stretch->fade = st_linear_fading;
- break;
- default:
- st_fail(STRETCH_USAGE "\n\terror while parsing fade type");
- return ST_EOF;
- }
+ switch (argv[2][0])
+ {
+ case 'l':
+ case 'L':
+ stretch->fade = st_linear_fading;
+ break;
+ default:
+ st_fail(STRETCH_USAGE "\n\terror while parsing fade type");
+ return ST_EOF;
+ }
}
/* default shift depends whether we go slower or faster */
stretch->shift = (stretch->factor <= ONE) ?
- DEFAULT_FAST_SHIFT_RATIO: DEFAULT_SLOW_SHIFT_RATIO;
+ DEFAULT_FAST_SHIFT_RATIO: DEFAULT_SLOW_SHIFT_RATIO;
if (n>3 && !sscanf(argv[3], STRETCH_FLOAT_SCAN, &stretch->shift))
{
- st_fail(STRETCH_USAGE "\n\terror while parsing shift ratio");
- return ST_EOF;
+ st_fail(STRETCH_USAGE "\n\terror while parsing shift ratio");
+ return ST_EOF;
}
if (stretch->shift > ONE || stretch->shift <= ZERO)
{
- st_fail(STRETCH_USAGE "\n\terror with shift ratio value");
- return ST_EOF;
+ st_fail(STRETCH_USAGE "\n\terror with shift ratio value");
+ return ST_EOF;
}
/* default fading stuff...
@@ -181,21 +181,21 @@
it makes sense for factor >= 0.5
*/
if (stretch->factor<ONE)
- stretch->fading = ONE - (stretch->factor*stretch->shift);
+ stretch->fading = ONE - (stretch->factor*stretch->shift);
else
- stretch->fading = ONE - stretch->shift;
+ stretch->fading = ONE - stretch->shift;
if (stretch->fading > HALF) stretch->fading = HALF;
if (n>4 && !sscanf(argv[4], STRETCH_FLOAT_SCAN, &stretch->fading))
{
- st_fail(STRETCH_USAGE "\n\terror while parsing fading ratio");
- return ST_EOF;
+ st_fail(STRETCH_USAGE "\n\terror while parsing fading ratio");
+ return ST_EOF;
}
if (stretch->fading > HALF || stretch->fading < ZERO)
{
- st_fail(STRETCH_USAGE "\n\terror with fading ratio value");
- return ST_EOF;
+ st_fail(STRETCH_USAGE "\n\terror with fading ratio value");
+ return ST_EOF;
}
return ST_SUCCESS;
@@ -212,16 +212,16 @@
/* not necessary. taken care by effect processing? */
if (effp->outinfo.channels != effp->ininfo.channels)
{
- st_fail("STRETCH cannot handle different channels (in=%d, out=%d)"
- " use avg or pan", effp->ininfo.channels, effp->outinfo.channels);
- return ST_EOF;
+ st_fail("STRETCH cannot handle different channels (in=%d, out=%d)"
+ " use avg or pan", effp->ininfo.channels, effp->outinfo.channels);
+ return ST_EOF;
}
if (effp->outinfo.rate != effp->ininfo.rate)
{
- st_fail("STRETCH cannot handle different rates (in=%ld, out=%ld)"
- " use resample or rate", effp->ininfo.rate, effp->outinfo.rate);
- return ST_EOF;
+ st_fail("STRETCH cannot handle different rates (in=%ld, out=%ld)"
+ " use resample or rate", effp->ininfo.rate, effp->outinfo.rate);
+ return ST_EOF;
}
stretch->state = input_state;
@@ -231,7 +231,7 @@
/* start in the middle of an input to avoid initial fading... */
stretch->index = stretch->size/2;
stretch->ibuf = (st_sample_t *) malloc(stretch->size *
- sizeof(st_sample_t));
+ sizeof(st_sample_t));
/* the shift ratio deal with the longest of ishift/oshift
hence ishift<=size and oshift<=size. should be asserted.
@@ -238,48 +238,48 @@
*/
if (stretch->factor < ONE)
{
- stretch->ishift = (int) (stretch->shift * stretch->size);
- stretch->oshift = (int) (stretch->factor * stretch->ishift);
+ stretch->ishift = (int) (stretch->shift * stretch->size);
+ stretch->oshift = (int) (stretch->factor * stretch->ishift);
}
else
{
- stretch->oshift = (int) (stretch->shift * stretch->size);
- stretch->ishift = (int) (stretch->oshift / stretch->factor);
+ stretch->oshift = (int) (stretch->shift * stretch->size);
+ stretch->ishift = (int) (stretch->oshift / stretch->factor);
}
stretch->oindex = stretch->index; /* start as synchronized */
stretch->obuf = (STRETCH_FLOAT *)
- malloc(stretch->size * sizeof(STRETCH_FLOAT));
+ malloc(stretch->size * sizeof(STRETCH_FLOAT));
stretch->fsize = (int) (stretch->fading * stretch->size);
stretch->fbuf = (STRETCH_FLOAT *)
- malloc(stretch->fsize * sizeof(STRETCH_FLOAT));
-
+ malloc(stretch->fsize * sizeof(STRETCH_FLOAT));
+
if (!stretch->ibuf || !stretch->obuf || !stretch->fbuf)
{
- st_fail("some malloc failed");
- return ST_EOF;
+ st_fail("some malloc failed");
+ return ST_EOF;
}
/* initialize buffers
*/
for (i=0; i<stretch->size; i++)
- stretch->ibuf[i] = 0;
+ stretch->ibuf[i] = 0;
for (i=0; i<stretch->size; i++)
- stretch->obuf[i] = ZERO;
+ stretch->obuf[i] = ZERO;
if (stretch->fsize>1)
{
- register STRETCH_FLOAT slope = ONE / (stretch->fsize - 1);
-
- stretch->fbuf[0] = ONE;
- for (i=1; i<stretch->fsize-1; i++)
- stretch->fbuf[i] = slope * (stretch->fsize-i-1);
- stretch->fbuf[stretch->fsize-1] = ZERO;
+ register STRETCH_FLOAT slope = ONE / (stretch->fsize - 1);
+
+ stretch->fbuf[0] = ONE;
+ for (i=1; i<stretch->fsize-1; i++)
+ stretch->fbuf[i] = slope * (stretch->fsize-i-1);
+ stretch->fbuf[stretch->fsize-1] = ZERO;
} else if (stretch->fsize==1)
- stretch->fbuf[0] = ONE;
+ stretch->fbuf[0] = ONE;
/* debug(stretch, "start"); */
@@ -297,15 +297,15 @@
/* fade in */
for (i=0; i<fsize; i++)
- stretch->obuf[i] += stretch->fbuf[fsize-i-1]*stretch->ibuf[i];
+ stretch->obuf[i] += stretch->fbuf[fsize-i-1]*stretch->ibuf[i];
/* steady state */
for (; i<size-fsize; i++)
- stretch->obuf[i] += stretch->ibuf[i];
+ stretch->obuf[i] += stretch->ibuf[i];
/* fade out */
for (; i<size; i++)
- stretch->obuf[i] += stretch->fbuf[i-size+fsize]*stretch->ibuf[i];
+ stretch->obuf[i] += stretch->fbuf[i-size+fsize]*stretch->ibuf[i];
}
/*
@@ -315,7 +315,8 @@
st_size_t *isamp, st_size_t *osamp)
{
stretch_t stretch = (stretch_t) effp->priv;
- register int iindex, oindex, i;
+ st_size_t iindex, oindex;
+ int i;
iindex = 0;
oindex = 0;
@@ -322,54 +323,54 @@
while (iindex<*isamp && oindex<*osamp)
{
- if (stretch->state == input_state)
- {
- register int tocopy = MIN(*isamp-iindex,
- stretch->size-stretch->index);
+ if (stretch->state == input_state)
+ {
+ st_size_t tocopy = MIN(*isamp-iindex,
+ stretch->size-stretch->index);
- memcpy(stretch->ibuf+stretch->index,
- ibuf+iindex, tocopy*sizeof(st_sample_t));
+ memcpy(stretch->ibuf+stretch->index,
+ ibuf+iindex, tocopy*sizeof(st_sample_t));
- iindex += tocopy;
- stretch->index += tocopy;
+ iindex += tocopy;
+ stretch->index += tocopy;
- if (stretch->index == stretch->size)
- {
- /* compute */
- combine(stretch);
+ if (stretch->index == stretch->size)
+ {
+ /* compute */
+ combine(stretch);
- /* shift input */
- for (i=0; i+stretch->ishift<stretch->size; i++)
- stretch->ibuf[i] = stretch->ibuf[i+stretch->ishift];
+ /* shift input */
+ for (i=0; i+stretch->ishift<stretch->size; i++)
+ stretch->ibuf[i] = stretch->ibuf[i+stretch->ishift];
- stretch->index -= stretch->ishift;
+ stretch->index -= stretch->ishift;
- /* switch to output state */
- stretch->state = output_state;
- }
- }
+ /* switch to output state */
+ stretch->state = output_state;
+ }
+ }
- if (stretch->state == output_state)
- {
- while (stretch->oindex<stretch->oshift && oindex<*osamp)
- obuf[oindex++] =
- clip(stretch, stretch->obuf[stretch->oindex++]);
+ if (stretch->state == output_state)
+ {
+ while (stretch->oindex<stretch->oshift && oindex<*osamp)
+ obuf[oindex++] =
+ clip(stretch, stretch->obuf[stretch->oindex++]);
- if (stretch->oindex >= stretch->oshift && oindex<*osamp)
- {
- stretch->oindex -= stretch->oshift;
+ if (stretch->oindex >= stretch->oshift && oindex<*osamp)
+ {
+ stretch->oindex -= stretch->oshift;
- /* shift internal output buffer */
- for (i=0; i+stretch->oshift<stretch->size; i++)
- stretch->obuf[i] = stretch->obuf[i+stretch->oshift];
+ /* shift internal output buffer */
+ for (i=0; i+stretch->oshift<stretch->size; i++)
+ stretch->obuf[i] = stretch->obuf[i+stretch->oshift];
- /* pad with 0 */
- for (; i<stretch->size; i++)
- stretch->obuf[i] = ZERO;
-
- stretch->state = input_state;
- }
- }
+ /* pad with 0 */
+ for (; i<stretch->size; i++)
+ stretch->obuf[i] = ZERO;
+
+ stretch->state = input_state;
+ }
+ }
}
*isamp = iindex;
@@ -386,24 +387,25 @@
int st_stretch_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
{
stretch_t stretch = (stretch_t) effp->priv;
- register int i, oindex;
+ register int i;
+ st_size_t oindex;
oindex = 0;
if (stretch->state == input_state)
{
- for (i=stretch->index; i<stretch->size; i++)
- stretch->ibuf[i] = 0;
+ for (i=stretch->index; i<stretch->size; i++)
+ stretch->ibuf[i] = 0;
- combine(stretch);
-
- stretch->state = output_state;
+ combine(stretch);
+
+ stretch->state = output_state;
}
if (stretch->state == output_state)
{
- for (; oindex<*osamp && stretch->oindex<stretch->index;)
- obuf[oindex++] = clip(stretch, stretch->obuf[stretch->oindex++]);
+ for (; oindex<*osamp && stretch->oindex<stretch->index;)
+ obuf[oindex++] = clip(stretch, stretch->obuf[stretch->oindex++]);
}
*osamp = oindex;
@@ -425,7 +427,7 @@
free(stretch->fbuf);
if (stretch->clipped)
- st_warn("STRETCH clipped %d values...", stretch->clipped);
+ st_warn("STRETCH clipped %d values...", stretch->clipped);
return ST_SUCCESS;
}
--- a/src/voc.c
+++ b/src/voc.c
@@ -254,6 +254,7 @@
v->rest = 0;
v->total_size = 0; /* ANN added */
v->extended = 0;
+ v->format = VOC_FMT_LIN8U;
/* read until we get the format information.... */
rc = getblock(ft);
@@ -517,7 +518,7 @@
uint32_t sblen;
uint16_t new_rate_16;
uint32_t new_rate_32;
- int i;
+ uint32_t i;
uint32_t trash;
v->silent = 0;
@@ -595,7 +596,7 @@
"File %s: Sample rate is zero?",ft->filename);
return(ST_EOF);
}
- if ((v->rate != -1) && (new_rate_32 != v->rate))
+ if ((v->rate != -1) && ((long)new_rate_32 != v->rate))
{
st_fail_errno(ft,ST_EFMT,
"File %s: sample rate codes differ: %d != %d",
@@ -656,7 +657,7 @@
/* Falling! Falling! */
case VOC_TEXT:
{
- int i;
+ uint32_t i;
/* Could add to comment in SF? */
for(i = 0; i < sblen; i++) {
st_readb(ft, (unsigned char *)&trash);
--- a/src/wav.c
+++ b/src/wav.c
@@ -103,7 +103,7 @@
gsm gsmhandle;
gsm_signal *gsmsample;
int gsmindex;
- int gsmbytecount; /* counts bytes written to data block */
+ st_size_t gsmbytecount; /* counts bytes written to data block */
#endif
} *wav_t;
@@ -391,14 +391,14 @@
wavgsmdestroy(ft);
}
#endif /*ifdef out gsm code */
+
/****************************************************************************/
/* General Sox WAV file code */
/****************************************************************************/
-
-static uint32_t findChunk(ft_t ft, const char *Label)
+static st_ssize_t findChunk(ft_t ft, const char *Label)
{
char magic[5];
- uint32_t len;
+ st_ssize_t len;
for (;;)
{
if (st_reads(ft, magic, 4) == ST_EOF)