ref: 72507ca85456260a1373255d83c8b1bdcf5b6db0
parent: 40da70e5f545fa977c0c20da9dfabc86b2934bd5
author: cbagwell <cbagwell>
date: Sun Sep 19 16:28:37 EDT 2004
Fixing some more overflow cases by switching to ST_SAMPLE_MIN.
--- a/TODO
+++ b/TODO
@@ -1,22 +1,20 @@
People are encouraged to pick some of these and implement it. Send
all patches to cbagwell@users.sourceforge.net.
+ o Effects engine should not have a global "flow" period
+ followed by a global "drain" period. Each effect should
+ track which it needs to invoke. Until thats done you
+ won't be able to stack two effects that both make use
+ of drain (ie. can't run the "reverse" effect twice
+ on the same command line and have a good output file).
+
o Document how to play to audio device in man pages.
- o Fix comment memory leaks and other issues.
-
- o Use valgrind and fix reported errors.
-
o Have sox.c auto remove an resample effects when rates are the same
(allows scripts to be dumper).
o Add MP3 support to WAV handler. Can copy most work from mp3.c.
- o Allow to trim beginning of audio file using file handler's
- seek() function to speed up operation. Not sure if
- it should be done with command line option or intercepting
- the "trim" effect.
-
o Document how the synth effect is meant to be used (with nul file
handler).
@@ -64,9 +62,6 @@
of detecting uint64_t... Use that when possible to speed up
math (won't have to convert back and forth from int to float).
- o Several files are using hard-coded #'s instead of ST_SAMPLE_MIN/MAX.
- Change these.
-
o Make a global version of MIN/MAX instead of sprinkled min/max/MIN/MAX
o Make a global version of clip() instead of sprinked in all files.
@@ -73,9 +68,6 @@
o Add support to all file handlers to handle 32-bit and float
data types since raw functions can handle them.
-
- o All comment code has a memory leak. They must malloc memory to
- store comment but its never free()'d.
o Comment strings. Some file formats have space for embedded comments.
These are currently thrown away. Printing them out, carrying them
--- a/src/btrworth.c
+++ b/src/btrworth.c
@@ -48,7 +48,7 @@
}
int st_butterworth_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)
{
butterworth_t butterworth = (butterworth_t) effp->priv;
@@ -81,11 +81,11 @@
butterworth->y [1] = butterworth->y [0];
butterworth->y [0] = out;
- if (out < -2147483647.0) {
- out = -2147483647.0;
+ if (out < ST_SAMPLE_MIN) {
+ out = ST_SAMPLE_MIN;
}
- else if (out > 2147483647.0) {
- out = 2147483647.0;
+ else if (out > ST_SAMPLE_MAX) {
+ out = ST_SAMPLE_MAX;
}
*obuf++ = out;
--- a/src/highp.c
+++ b/src/highp.c
@@ -8,7 +8,7 @@
*
* Reference: The Scientist and Engineer's Guide to Digital Processing
*
- * output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1]
+ * output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1]
*
* X = exp(-2.0 * pi * Fc)
* A0 = (1 + X) / 2
@@ -34,9 +34,9 @@
/* Private data for Highpass effect */
typedef struct highpstuff {
- float cutoff;
- double A0, A1, B1;
- double inm1, outm1;
+ float cutoff;
+ double A0, A1, B1;
+ double inm1, outm1;
} *highp_t;
/*
@@ -44,14 +44,14 @@
*/
int st_highp_getopts(eff_t effp, int n, char **argv)
{
- highp_t highp = (highp_t) effp->priv;
+ highp_t highp = (highp_t) effp->priv;
- if ((n < 1) || !sscanf(argv[0], "%f", &highp->cutoff))
- {
- st_fail("Usage: highp cutoff");
- return (ST_EOF);
- }
- return (ST_SUCCESS);
+ if ((n < 1) || !sscanf(argv[0], "%f", &highp->cutoff))
+ {
+ st_fail("Usage: highp cutoff");
+ return (ST_EOF);
+ }
+ return (ST_SUCCESS);
}
/*
@@ -59,19 +59,19 @@
*/
int st_highp_start(eff_t effp)
{
- highp_t highp = (highp_t) effp->priv;
- if (highp->cutoff > effp->ininfo.rate/2)
- {
- st_fail("Highpass: cutoff must be < sample rate / 2 (Nyquest rate)\n");
- return (ST_EOF);
- }
+ highp_t highp = (highp_t) effp->priv;
+ if (highp->cutoff > effp->ininfo.rate/2)
+ {
+ st_fail("Highpass: cutoff must be < sample rate / 2 (Nyquest rate)\n");
+ return (ST_EOF);
+ }
- highp->B1 = exp((-2.0 * M_PI * (highp->cutoff / effp->ininfo.rate)));
- highp->A0 = (1 + highp->B1) / 2;
- highp->A1 = (-1 * (1 + highp->B1)) / 2;
- highp->inm1 = 0.0;
- highp->outm1 = 0.0;
- return (ST_SUCCESS);
+ highp->B1 = exp((-2.0 * M_PI * (highp->cutoff / effp->ininfo.rate)));
+ highp->A0 = (1 + highp->B1) / 2;
+ highp->A1 = (-1 * (1 + highp->B1)) / 2;
+ highp->inm1 = 0.0;
+ highp->outm1 = 0.0;
+ return (ST_SUCCESS);
}
/*
@@ -81,29 +81,29 @@
int st_highp_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
st_size_t *isamp, st_size_t *osamp)
{
- highp_t highp = (highp_t) effp->priv;
- int len, done;
- double d;
- st_sample_t l;
+ highp_t highp = (highp_t) effp->priv;
+ int len, done;
+ double d;
+ st_sample_t l;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
+ len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
- l = *ibuf++;
- d = highp->A0 * l +
- highp->A1 * highp->inm1 +
- highp->B1 * highp->outm1;
- if (d < -2147483647L)
- d = -2147483647L;
- else if (d > 2147483647L)
- d = 2147483647L;
- highp->inm1 = l;
- highp->outm1 = d;
- *obuf++ = d;
- }
- *isamp = len;
- *osamp = len;
- return (ST_SUCCESS);
+ for(done = 0; done < len; done++) {
+ l = *ibuf++;
+ d = highp->A0 * l +
+ highp->A1 * highp->inm1 +
+ highp->B1 * highp->outm1;
+ if (d < ST_SAMPLE_MIN)
+ d = ST_SAMPLE_MIN;
+ else if (d > ST_SAMPLE_MAX)
+ d = ST_SAMPLE_MAX;
+ highp->inm1 = l;
+ highp->outm1 = d;
+ *obuf++ = d;
+ }
+ *isamp = len;
+ *osamp = len;
+ return (ST_SUCCESS);
}
/*
@@ -112,7 +112,7 @@
*/
int st_highp_stop(eff_t effp)
{
- /* nothing to do */
+ /* nothing to do */
return (ST_SUCCESS);
}
--- a/src/lowp.c
+++ b/src/lowp.c
@@ -8,12 +8,12 @@
*
* Reference: The Scientist and Engineer's Guide to Digital Signal Processing
*
- * output[N] = input[N] * A + output[N-1] * B
+ * output[N] = input[N] * A + output[N-1] * B
*
- * X = exp(-2.0 * pi * Fc)
- * A = 1 - X
- * B = X
- * Fc = cutoff freq / sample rate
+ * X = exp(-2.0 * pi * Fc)
+ * A = 1 - X
+ * B = X
+ * Fc = cutoff freq / sample rate
*
* Mimics an RC low-pass filter:
*
@@ -32,9 +32,9 @@
/* Private data for Lowpass effect */
typedef struct lowpstuff {
- float cutoff;
- double A, B;
- double outm1;
+ float cutoff;
+ double A, B;
+ double outm1;
} *lowp_t;
/*
@@ -42,14 +42,14 @@
*/
int st_lowp_getopts(eff_t effp, int n, char **argv)
{
- lowp_t lowp = (lowp_t) effp->priv;
+ lowp_t lowp = (lowp_t) effp->priv;
- if ((n < 1) || !sscanf(argv[0], "%f", &lowp->cutoff))
- {
- st_fail("Usage: lowp cutoff");
- return (ST_EOF);
- }
- return (ST_SUCCESS);
+ if ((n < 1) || !sscanf(argv[0], "%f", &lowp->cutoff))
+ {
+ st_fail("Usage: lowp cutoff");
+ return (ST_EOF);
+ }
+ return (ST_SUCCESS);
}
/*
@@ -57,17 +57,17 @@
*/
int st_lowp_start(eff_t effp)
{
- lowp_t lowp = (lowp_t) effp->priv;
- if (lowp->cutoff > effp->ininfo.rate / 2)
- {
- st_fail("Lowpass: cutoff must be < sample rate / 2 (Nyquest rate)\n");
- return (ST_EOF);
- }
+ lowp_t lowp = (lowp_t) effp->priv;
+ if (lowp->cutoff > effp->ininfo.rate / 2)
+ {
+ st_fail("Lowpass: cutoff must be < sample rate / 2 (Nyquest rate)\n");
+ return (ST_EOF);
+ }
- lowp->B = exp((-2.0 * M_PI * (lowp->cutoff / effp->ininfo.rate)));
- lowp->A = 1 - lowp->B;
- lowp->outm1 = 0.0;
- return (ST_SUCCESS);
+ lowp->B = exp((-2.0 * M_PI * (lowp->cutoff / effp->ininfo.rate)));
+ lowp->A = 1 - lowp->B;
+ lowp->outm1 = 0.0;
+ return (ST_SUCCESS);
}
/*
@@ -77,26 +77,26 @@
int st_lowp_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
st_size_t *isamp, st_size_t *osamp)
{
- lowp_t lowp = (lowp_t) effp->priv;
- int len, done;
- double d;
- st_sample_t l;
+ lowp_t lowp = (lowp_t) effp->priv;
+ int len, done;
+ double d;
+ st_sample_t l;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
+ len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
- l = *ibuf++;
- d = lowp->A * l + lowp->B * lowp->outm1;
- if (d < -2147483647L)
- d = -2147483647L;
- else if (d > 2147483647L)
- d = 2147483647L;
- lowp->outm1 = d;
- *obuf++ = d;
- }
- *isamp = len;
- *osamp = len;
- return (ST_SUCCESS);
+ for(done = 0; done < len; done++) {
+ l = *ibuf++;
+ d = lowp->A * l + lowp->B * lowp->outm1;
+ if (d < ST_SAMPLE_MIN)
+ d = ST_SAMPLE_MIN;
+ else if (d > ST_SAMPLE_MAX)
+ d = ST_SAMPLE_MAX;
+ lowp->outm1 = d;
+ *obuf++ = d;
+ }
+ *isamp = len;
+ *osamp = len;
+ return (ST_SUCCESS);
}
/*
@@ -105,7 +105,7 @@
*/
int st_lowp_stop(eff_t effp)
{
- /* nothing to do */
+ /* nothing to do */
return (ST_SUCCESS);
}
--- a/src/vorbis.c
+++ b/src/vorbis.c
@@ -394,7 +394,7 @@
for (i = 0; i < samples; i++)
for (j = 0; j < ft->info.channels; j++)
buffer[j][i] = buf[i*ft->info.channels + j]
- / 2147483648.0f;
+ / ((float)ST_SAMPLE_MAX);
vorbis_analysis_wrote(&ve->vd, samples);