ref: cda92aa17607fb38f480e87bc6e015ac0667a136
parent: 307885170d650df8918e71f50b368f76883b68cd
author: cbagwell <cbagwell>
date: Wed Dec 1 14:58:07 EST 1999
Fixed configure typeo. Fixed bug in clip24() functions and moved to misc file. Fixed array overrun bug in rate effect.
--- a/configure.in
+++ b/configure.in
@@ -155,7 +155,6 @@
ac_cv_dev_alsa_dsp=no,
ac_cv_dev_alsa_dsp=no)
)
-
if test "$ac_cv_dev_alsa_dsp" = yes
then
AC_CHECK_HEADERS(linux/asound.h, alsa_dsp=yes)
@@ -248,7 +247,7 @@
)
if test "$ac_cv_dev_sun_audio" = yes
then
- AC_CHECK_HEADER(sys/audioio.h, sun/audioio.h, sun_audio=yes)
+ AC_CHECK_HEADERS(sys/audioio.h sun/audioio.h, sun_audio=yes)
if test "$sun_audio" = auto
then
AC_WARN([No audioio.h to compile with SUN /dev/audio])
--- a/libst.h
+++ b/libst.h
@@ -51,7 +51,11 @@
extern int rand();
extern void srand(/* seed */);
#endif
-extern void initrand();
+extern void st_initrand();
+
+extern LONG st_clip24();
+extern void st_sine();
+extern void st_triangle();
#ifndef HAVE_STRERROR
char *strerror(/*errorcode*/);
--- a/src/chorus.c
+++ b/src/chorus.c
@@ -69,6 +69,7 @@
#include <math.h>
#include <string.h>
#include "st.h"
+#include "libst.h"
#define MOD_SINE 0
#define MOD_TRIANGLE 1
@@ -90,59 +91,6 @@
int maxsamples, fade_out;
} *chorus_t;
-/* Private data for SKEL file */
-
-LONG chorus_clip24(l)
-LONG l;
-{
- if (l >= ((LONG)1 << 24))
- return ((LONG)1 << 24) - 1;
- else if (l <= -((LONG)1 << 24))
- return -((LONG)1 << 24) + 1;
- else
- return l;
-}
-
-/* This was very painful. We need a sine library. */
-
-void chorus_sine(buf, len, max, depth)
-int *buf;
-long len;
-int max;
-int depth;
-{
- long i;
- int offset;
- double val;
-
- offset = max - depth;
- for (i = 0; i < len; i++) {
- val = sin((double)i/(double)len * 2.0 * M_PI);
- buf[i] = offset + (int) (val * (double)depth);
- }
-}
-
-void chorus_triangle(buf, len, max, depth)
-int *buf;
-long len;
-int max;
-int depth;
-{
- long i;
- int offset;
- double val;
-
- offset = max - 2 * depth;
- for (i = 0; i < len / 2; i++) {
- val = i * 2.0 / len;
- buf[i] = offset + (int) (val * 2.0 * (double)depth);
- }
- for (i = len / 2; i < len ; i++) {
- val = (len - i) * 2.0 / len;
- buf[i] = offset + (int) (val * 2.0 * (double)depth);
- }
-}
-
/*
* Process options
*/
@@ -226,10 +174,10 @@
fail("chorus: Cannot malloc %d bytes!\n",
sizeof(int) * chorus->length[i]);
if ( chorus->modulation[i] == MOD_SINE )
- chorus_sine(chorus->lookup_tab[i], chorus->length[i],
+ st_sine(chorus->lookup_tab[i], chorus->length[i],
chorus->samples[i] - 1, chorus->depth_samples[i]);
else
- chorus_triangle(chorus->lookup_tab[i], chorus->length[i],
+ st_triangle(chorus->lookup_tab[i], chorus->length[i],
chorus->samples[i] - 1, chorus->depth_samples[i]);
chorus->phase[i] = 0;
@@ -285,7 +233,7 @@
chorus->maxsamples] * chorus->decay[i];
/* Adjust the output volume and size to 24 bit */
d_out = d_out * chorus->out_gain;
- out = chorus_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
/* Mix decay of delay and input */
chorus->chorusbuf[chorus->counter] = d_in;
@@ -324,7 +272,7 @@
chorus->maxsamples] * chorus->decay[i];
/* Adjust the output volume and size to 24 bit */
d_out = d_out * chorus->out_gain;
- out = chorus_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
/* Mix decay of delay and input */
chorus->chorusbuf[chorus->counter] = d_in;
--- a/src/echo.c
+++ b/src/echo.c
@@ -61,6 +61,7 @@
#endif
#include <math.h>
#include "st.h"
+#include "libst.h"
#define DELAY_BUFSIZ ( 50L * MAXRATE )
#define MAX_ECHOS 7 /* 24 bit x ( 1 + MAX_ECHOS ) = */
@@ -79,20 +80,6 @@
/* Private data for SKEL file */
-/* If we are not carefull with the output volume */
-LONG echo_clip24(l)
-LONG l;
-{
- if (l >= ((LONG)1 << 24))
- return ((LONG)1 << 24) - 1;
- else if (l <= -((LONG)1 << 24))
- return -((LONG)1 << 24) + 1;
- else
- return l;
-}
-
-
-
/*
* Process options
*/
@@ -200,7 +187,7 @@
}
/* Adjust the output volume and size to 24 bit */
d_out = d_out * echo->out_gain;
- out = echo_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
/* Store input in delay buffer */
echo->delay_buf[echo->counter] = d_in;
@@ -236,7 +223,7 @@
}
/* Adjust the output volume and size to 24 bit */
d_out = d_out * echo->out_gain;
- out = echo_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
/* Store input in delay buffer */
echo->delay_buf[echo->counter] = d_in;
--- a/src/echos.c
+++ b/src/echos.c
@@ -52,6 +52,7 @@
#endif
#include <math.h>
#include "st.h"
+#include "libst.h"
#define DELAY_BUFSIZ ( 50L * MAXRATE )
#define MAX_ECHOS 7 /* 24 bit x ( 1 + MAX_ECHOS ) = */
@@ -69,21 +70,6 @@
/* Private data for SKEL file */
-
-/* If we are not carefull with the output volume */
-LONG echos_clip24(l)
-LONG l;
-{
- if (l >= ((LONG)1 << 24))
- return ((LONG)1 << 24) - 1;
- else if (l <= -((LONG)1 << 24))
- return -((LONG)1 << 24) + 1;
- else
- return l;
-}
-
-
-
/*
* Process options
*/
@@ -188,7 +174,7 @@
}
/* Adjust the output volume and size to 24 bit */
d_out = d_out * echos->out_gain;
- out = echos_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
/* Mix decay of delays and input */
for ( j = 0; j < echos->num_delays; j++ ) {
@@ -230,7 +216,7 @@
}
/* Adjust the output volume and size to 24 bit */
d_out = d_out * echos->out_gain;
- out = echos_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
/* Mix decay of delays and input */
for ( j = 0; j < echos->num_delays; j++ ) {
--- a/src/flanger.c
+++ b/src/flanger.c
@@ -59,6 +59,7 @@
#include <math.h>
#include <string.h>
#include "st.h"
+#include "libst.h"
#define MOD_SINE 0
#define MOD_TRIANGLE 1
@@ -79,51 +80,6 @@
/* Private data for SKEL file */
-LONG flanger_clip24(l)
-LONG l;
-{
- if (l >= ((LONG)1 << 24))
- return ((LONG)1 << 24) - 1;
- else if (l <= -((LONG)1 << 24))
- return -((LONG)1 << 24) + 1;
- else
- return l;
-}
-
-/* This was very painful. We need a sine library. */
-
-void flanger_sine(buf, len, depth)
-int *buf;
-long len;
-long depth;
-{
- long i;
- double val;
-
- for (i = 0; i < len; i++) {
- val = sin((double)i/(double)len * 2.0 * M_PI);
- buf[i] = (int) ((1.0 + val) * depth / 2.0);
- }
-}
-
-void flanger_triangle(buf, len, depth)
-int *buf;
-long len;
-long depth;
-{
- long i;
- double val;
-
- for (i = 0; i < len / 2; i++) {
- val = i * 2.0 / len;
- buf[i] = (int) (val * depth);
- }
- for (i = len / 2; i < len ; i++) {
- val = (len - i) * 2.0 / len;
- buf[i] = (int) (val * depth);
- }
-}
-
/*
* Process options
*/
@@ -200,10 +156,10 @@
sizeof(int) * flanger->length);
if ( flanger->modulation == MOD_SINE )
- flanger_sine(flanger->lookup_tab, flanger->length,
+ st_sine(flanger->lookup_tab, flanger->length,
flanger->maxsamples - 1);
else
- flanger_triangle(flanger->lookup_tab, flanger->length,
+ st_triangle(flanger->lookup_tab, flanger->length,
flanger->maxsamples - 1);
flanger->counter = 0;
flanger->phase = 0;
@@ -237,7 +193,7 @@
flanger->maxsamples] * flanger->decay;
/* Adjust the output volume and size to 24 bit */
d_out = d_out * flanger->out_gain;
- out = flanger_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
/* Mix decay of delay and input */
flanger->flangerbuf[flanger->counter] = d_in;
@@ -272,7 +228,7 @@
flanger->maxsamples] * flanger->decay;
/* Adjust the output volume and size to 24 bit */
d_out = d_out * flanger->out_gain;
- out = flanger_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
/* Mix decay of delay and input */
flanger->flangerbuf[flanger->counter] = d_in;
--- a/src/mask.c
+++ b/src/mask.c
@@ -38,7 +38,7 @@
fail("Mask effect takes no options.");
/* should take # of bits */
- initrand();
+ st_initrand();
}
/*
--- a/src/misc.c
+++ b/src/misc.c
@@ -11,12 +11,14 @@
* Sound Tools miscellaneous stuff.
*/
-#include "st.h"
-#include "version.h"
-#include "patchlvl.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+#include <math.h>
+#include "st.h"
+#include "libst.h"
+#include "version.h"
+#include "patchlvl.h"
char *sizes[] = {
"NONSENSE!",
@@ -256,11 +258,56 @@
#endif
/* Util to set initial seed so that we are a little less non-random */
-void initrand() {
+void st_initrand() {
time_t t;
time(&t);
srand(t);
+}
+
+LONG st_clip24(l)
+LONG l;
+{
+ if (l >= ((LONG)1 << 23))
+ return ((LONG)1 << 23) - 1;
+ else if (l <= -((LONG)1 << 23))
+ return -((LONG)1 << 23) + 1;
+ else
+ return l;
+}
+
+/* This was very painful. We need a sine library. */
+
+void st_sine(buf, len, depth)
+int *buf;
+long len;
+long depth;
+{
+ long i;
+ double val;
+
+ for (i = 0; i < len; i++) {
+ val = sin((double)i/(double)len * 2.0 * M_PI);
+ buf[i] = (int) ((1.0 + val) * depth / 2.0);
+ }
+}
+
+void st_triangle(buf, len, depth)
+int *buf;
+long len;
+long depth;
+{
+ long i;
+ double val;
+
+ for (i = 0; i < len / 2; i++) {
+ val = i * 2.0 / len;
+ buf[i] = (int) (val * depth);
+ }
+ for (i = len / 2; i < len ; i++) {
+ val = (len - i) * 2.0 / len;
+ buf[i] = (int) (val * depth);
+ }
}
char *
--- a/src/phaser.c
+++ b/src/phaser.c
@@ -62,6 +62,7 @@
#include <math.h>
#include <string.h>
#include "st.h"
+#include "libst.h"
#define MOD_SINE 0
#define MOD_TRIANGLE 1
@@ -80,53 +81,6 @@
long maxsamples, fade_out;
} *phaser_t;
-/* Private data for SKEL file */
-
-LONG phaser_clip24(l)
-LONG l;
-{
- if (l >= ((LONG)1 << 24))
- return ((LONG)1 << 24) - 1;
- else if (l <= -((LONG)1 << 24))
- return -((LONG)1 << 24) + 1;
- else
- return l;
-}
-
-/* This was very painful. We need a sine library. */
-
-void phaser_sine(buf, len, depth)
-int *buf;
-long len;
-long depth;
-{
- long i;
- double val;
-
- for (i = 0; i < len; i++) {
- val = sin((double)i/(double)len * 2.0 * M_PI);
- buf[i] = (int) ((1.0 + val) * depth / 2.0);
- }
-}
-
-void phaser_triangle(buf, len, depth)
-int *buf;
-long len;
-long depth;
-{
- long i;
- double val;
-
- for (i = 0; i < len / 2; i++) {
- val = i * 2.0 / len;
- buf[i] = (int) (val * depth);
- }
- for (i = len / 2; i < len ; i++) {
- val = (len - i) * 2.0 / len;
- buf[i] = (int) (val * depth);
- }
-}
-
/*
* Process options
*/
@@ -199,10 +153,10 @@
sizeof(int) * phaser->length);
if ( phaser->modulation == MOD_SINE )
- phaser_sine(phaser->lookup_tab, phaser->length,
+ st_sine(phaser->lookup_tab, phaser->length,
phaser->maxsamples - 1);
else
- phaser_triangle(phaser->lookup_tab, phaser->length,
+ st_triangle(phaser->lookup_tab, phaser->length,
phaser->maxsamples - 1);
phaser->counter = 0;
phaser->phase = 0;
@@ -236,7 +190,7 @@
phaser->maxsamples] * phaser->decay * -1.0;
/* Adjust the output volume and size to 24 bit */
d_out = d_in * phaser->out_gain;
- out = phaser_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
/* Mix decay of delay and input */
phaser->phaserbuf[phaser->counter] = d_in;
@@ -271,7 +225,7 @@
phaser->maxsamples] * phaser->decay * -1.0;
/* Adjust the output volume and size to 24 bit */
d_out = d_in * phaser->out_gain;
- out = phaser_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
/* Mix decay of delay and input */
phaser->phaserbuf[phaser->counter] = d_in;
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -385,7 +385,7 @@
int total, size, uprate;
int k;
- initrand();
+ st_initrand();
rate->lcmrate = st_lcm((long)effp->ininfo.rate, (long)effp->outinfo.rate);
--- a/src/rate.c
+++ b/src/rate.c
@@ -30,7 +30,7 @@
*
* Limited to 16 bit samples and sampling frequency <= 65535 Hz. If
* the input & output frequencies are equal, a delay of one sample is
- * introduced
+ * introduced. Limited to processing 32-bit count worth of samples.
*
* 1 << FRAC_BITS evaluating to zero in several places. Changed with
* an (unsigned long) cast to make it safe. MarkMLl 2/1/99
@@ -40,13 +40,13 @@
/* Private data */
typedef struct ratestuff {
- u_l opos_frac; /* fractional position of the output stream in input stream unit */
- u_l opos;
+ ULONG opos_frac; /* fractional position of the output stream in input stream unit */
+ ULONG opos;
- u_l opos_inc_frac; /* fractional position increment in the output stream */
- u_l opos_inc;
+ ULONG opos_inc_frac; /* fractional position increment in the output stream */
+ ULONG opos_inc;
- u_l ipos; /* position in the input stream (integer) */
+ ULONG ipos; /* position in the input stream (integer) */
LONG ilast; /* last sample in the input stream */
} *rate_t;
@@ -70,13 +70,18 @@
eff_t effp;
{
rate_t rate = (rate_t) effp->priv;
- u_l incr;
+ ULONG incr;
+ if (effp->ininfo.rate >= 65535 || effp->outinfo.rate >= 65535)
+ fail("rate effect can only handle rates <= 65535");
+ if (effp->ininfo.size == DWORD || effp->ininfo.size == FLOAT)
+ fail("rate effect does not work on data greater then 16 bits");
+
rate->opos_frac=0;
rate->opos=0;
/* increment */
- incr=(u_l)((double)effp->ininfo.rate / (double)effp->outinfo.rate *
+ incr=(ULONG)((double)effp->ininfo.rate / (double)effp->outinfo.rate *
(double) ((unsigned long) 1 << FRAC_BITS));
rate->opos_inc_frac = incr & (((unsigned long) 1 << FRAC_BITS)-1);
@@ -101,7 +106,7 @@
LONG *istart,*iend;
LONG *ostart,*oend;
LONG ilast,icur,out;
- u_l tmp;
+ ULONG tmp;
double t;
ilast=rate->ilast;
@@ -114,13 +119,18 @@
while (obuf < oend) {
- /* read as many input samples so that ipos > opos */
-
+ /* Safety catch to make sure we have input samples. */
+ if (ibuf >= iend) goto the_end;
+
+ /* read as many input samples so that ipos > opos */
+
while (rate->ipos <= rate->opos) {
- if (ibuf >= iend) goto the_end;
ilast = *ibuf++;
rate->ipos++;
+ /* See if we finished the input buffer yet */
+ if (ibuf >= iend) goto the_end;
}
+
icur = *ibuf;
/* interpolate */
@@ -206,10 +216,10 @@
/* Private data for Lerp via LCM file */
typedef struct ratestuff {
- u_l lcmrate; /* least common multiple of rates */
- u_l inskip, outskip; /* LCM increments for I & O rates */
- u_l total;
- u_l intot, outtot; /* total samples in LCM basis */
+ ULONG lcmrate; /* least common multiple of rates */
+ ULONG inskip, outskip; /* LCM increments for I & O rates */
+ ULONG total;
+ ULONG intot, outtot; /* total samples in LCM basis */
LONG lastsamp; /* history */
} *rate_t;
--- a/src/reverb.c
+++ b/src/reverb.c
@@ -98,6 +98,7 @@
#endif
#include <math.h>
#include "st.h"
+#include "libst.h"
#define REVERB_FADE_THRESH 10
#define DELAY_BUFSIZ ( 50L * MAXRATE )
@@ -114,23 +115,6 @@
LONG pl, ppl, pppl;
} *reverb_t;
-/* Private data for SKEL file */
-
-#ifndef abs
-#define abs(a) ((a) >= 0 ? (a) : -(a))
-#endif
-
-LONG reverb_clip24(l)
-LONG l;
-{
- if (l >= ((LONG)1 << 24))
- return ((LONG)1 << 24) - 1;
- else if (l <= -((LONG)1 << 24))
- return -((LONG)1 << 24) + 1;
- else
- return l;
-}
-
/*
* Process options
*/
@@ -232,7 +216,7 @@
d_in +=
reverb->reverbbuf[(i + reverb->maxsamples - reverb->samples[j]) % reverb->maxsamples] * reverb->decay[j];
d_out = d_in * reverb->out_gain;
- out = reverb_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
*obuf++ = out * 256;
reverb->reverbbuf[i] = d_in;
i++; /* XXX need a % maxsamples here ? */
@@ -265,10 +249,10 @@
d_in +=
reverb->reverbbuf[(i + reverb->maxsamples - reverb->samples[j]) % reverb->maxsamples] * reverb->decay[j];
d_out = d_in * reverb->out_gain;
- out = reverb_clip24((LONG) d_out);
+ out = st_clip24((LONG) d_out);
obuf[done++] = out * 256;
reverb->reverbbuf[i] = d_in;
- l = reverb_clip24((LONG) d_in);
+ l = st_clip24((LONG) d_in);
reverb->pppl = reverb->ppl;
reverb->ppl = reverb->pl;
reverb->pl = l;
--
⑨