ref: 59288c4cb8d7776baad29295dbe1866559626ebd
parent: 77be88f63835eddc47b948d708d6bbd684e96f3b
author: robs <robs>
date: Mon May 21 15:07:07 EDT 2007
Fix flow bugs in various effects
--- a/src/chorus.c
+++ b/src/chorus.c
@@ -247,14 +247,13 @@
sox_size_t *isamp, sox_size_t *osamp)
{
chorus_t chorus = (chorus_t) effp->priv;
- int len, done;
int i;
-
float d_in, d_out;
sox_ssample_t out;
+ sox_size_t len = min(*isamp, *osamp);
+ *isamp = *osamp = len;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
+ while (len--) {
/* Store delays as 24-bit signed longs */
d_in = (float) *ibuf++ / 256;
/* Compute output first */
--- a/src/echo.c
+++ b/src/echo.c
@@ -184,14 +184,13 @@
sox_size_t *isamp, sox_size_t *osamp)
{
echo_t echo = (echo_t) effp->priv;
- int len, done;
int j;
-
double d_in, d_out;
sox_ssample_t out;
+ sox_size_t len = min(*isamp, *osamp);
+ *isamp = *osamp = len;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
+ while (len--) {
/* Store delays as 24-bit signed longs */
d_in = (double) *ibuf++ / 256;
/* Compute output first */
--- a/src/echos.c
+++ b/src/echos.c
@@ -176,14 +176,13 @@
sox_size_t *isamp, sox_size_t *osamp)
{
echos_t echos = (echos_t) effp->priv;
- int len, done;
int j;
-
double d_in, d_out;
sox_ssample_t out;
+ sox_size_t len = min(*isamp, *osamp);
+ *isamp = *osamp = len;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
+ while (len--) {
/* Store delays as 24-bit signed longs */
d_in = (double) *ibuf++ / 256;
/* Compute output first */
--- a/src/phaser.c
+++ b/src/phaser.c
@@ -183,13 +183,12 @@
sox_size_t *isamp, sox_size_t *osamp)
{
phaser_t phaser = (phaser_t) effp->priv;
- int len, done;
-
double d_in, d_out;
sox_ssample_t out;
+ sox_size_t len = min(*isamp, *osamp);
+ *isamp = *osamp = len;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
+ while (len--) {
/* Store delays as 24-bit signed longs */
d_in = (double) *ibuf++ / 256;
/* Compute output first */
--- a/src/reverb.c
+++ b/src/reverb.c
@@ -207,15 +207,13 @@
sox_size_t *isamp, sox_size_t *osamp)
{
reverb_t reverb = (reverb_t) effp->priv;
- size_t len, done;
- size_t i, j;
-
+ size_t i = reverb->counter, j;
float d_in, d_out;
sox_ssample_t out;
+ sox_size_t len = min(*isamp, *osamp);
+ *isamp = *osamp = len;
- i = reverb->counter;
- len = ((*isamp > *osamp) ? *osamp : *isamp);
- for(done = 0; done < len; done++) {
+ while (len--) {
/* Store delays as 24-bit signed longs */
d_in = (float) *ibuf++ / 256;
d_in = d_in * reverb->in_gain;
@@ -227,7 +225,7 @@
out = SOX_24BIT_CLIP_COUNT((sox_ssample_t) d_out, effp->clips);
*obuf++ = out * 256;
reverb->reverbbuf[i] = d_in;
- i++; /* XXX need a % maxsamples here ? */
+ i++; /* FIXME need a % maxsamples here ? */
i %= reverb->maxsamples;
}
reverb->counter = i;
--- a/src/stat.c
+++ b/src/stat.c
@@ -136,62 +136,62 @@
int done, x, len = min(*isamp, *osamp);
short count = 0;
- if (len == 0)
- return SOX_SUCCESS;
+ if (len) {
+ if (stat->read == 0) /* 1st sample */
+ stat->min = stat->max = stat->mid = stat->last = (*ibuf)/stat->scale;
- if (stat->read == 0) /* 1st sample */
- stat->min = stat->max = stat->mid = stat->last = (*ibuf)/stat->scale;
+ if (stat->fft) {
+ for (x = 0; x < len; x++) {
+ stat->re_in[stat->fft_offset++] = SOX_SAMPLE_TO_FLOAT_32BIT(ibuf[x], effp->clips);
- if (stat->fft) {
- for (x = 0; x < len; x++) {
- stat->re_in[stat->fft_offset++] = SOX_SAMPLE_TO_FLOAT_32BIT(ibuf[x], effp->clips);
+ if (stat->fft_offset >= stat->fft_size) {
+ stat->fft_offset = 0;
+ print_power_spectrum(stat->fft_size, (double)effp->ininfo.rate, stat->re_in, stat->re_out);
+ }
- if (stat->fft_offset >= stat->fft_size) {
- stat->fft_offset = 0;
- print_power_spectrum(stat->fft_size, (double)effp->ininfo.rate, stat->re_in, stat->re_out);
}
-
}
- }
- for (done = 0; done < len; done++) {
- long lsamp = *ibuf++;
- double delta, samp = (double)lsamp / stat->scale;
- /* work in scaled levels for both sample and delta */
- stat->bin[(lsamp >> 30) + 2]++;
- *obuf++ = lsamp;
+ for (done = 0; done < len; done++) {
+ long lsamp = *ibuf++;
+ double delta, samp = (double)lsamp / stat->scale;
+ /* work in scaled levels for both sample and delta */
+ stat->bin[(lsamp >> 30) + 2]++;
+ *obuf++ = lsamp;
- if (stat->volume == 2) {
- fprintf(stderr,"%08lx ",lsamp);
- if (count++ == 5) {
- fprintf(stderr,"\n");
- count = 0;
- }
- }
+ if (stat->volume == 2) {
+ fprintf(stderr,"%08lx ",lsamp);
+ if (count++ == 5) {
+ fprintf(stderr,"\n");
+ count = 0;
+ }
+ }
- /* update min/max */
- if (stat->min > samp)
- stat->min = samp;
- else if (stat->max < samp)
- stat->max = samp;
- stat->mid = stat->min / 2 + stat->max / 2;
+ /* update min/max */
+ if (stat->min > samp)
+ stat->min = samp;
+ else if (stat->max < samp)
+ stat->max = samp;
+ stat->mid = stat->min / 2 + stat->max / 2;
- stat->sum1 += samp;
- stat->sum2 += samp*samp;
- stat->asum += fabs(samp);
+ stat->sum1 += samp;
+ stat->sum2 += samp*samp;
+ stat->asum += fabs(samp);
- delta = fabs(samp - stat->last);
- if (delta < stat->dmin)
- stat->dmin = delta;
- else if (delta > stat->dmax)
- stat->dmax = delta;
+ delta = fabs(samp - stat->last);
+ if (delta < stat->dmin)
+ stat->dmin = delta;
+ else if (delta > stat->dmax)
+ stat->dmax = delta;
- stat->dsum1 += delta;
- stat->dsum2 += delta*delta;
+ stat->dsum1 += delta;
+ stat->dsum2 += delta*delta;
- stat->last = samp;
+ stat->last = samp;
+ }
+ stat->read += len;
}
- stat->read += len;
+
*isamp = *osamp = len;
/* Process all samples */
--- a/src/trim.c
+++ b/src/trim.c
@@ -119,7 +119,7 @@
static int sox_trim_flow(eff_t effp, const sox_ssample_t *ibuf, sox_ssample_t *obuf,
sox_size_t *isamp, sox_size_t *osamp)
{
- int finished = 0;
+ int result = SOX_SUCCESS;
int start_trim = 0;
int offset = 0;
int done;
@@ -158,25 +158,17 @@
* to the desired length less the amount already read.
*/
done = trim->length - trim->trimmed;
- finished = 1;
+ result = SOX_EOF;
}
trim->trimmed += done;
}
-
- memcpy(obuf, ibuf+offset, done * sizeof(sox_ssample_t));
-
+ memcpy(obuf, ibuf+offset, done * sizeof(*obuf));
*osamp = done;
*isamp = offset + done;
trim->index += done;
- /* return SOX_EOF when nothing consumed and we detect
- * we are finished.
- */
- if (finished && !done)
- return (SOX_EOF);
- else
- return (SOX_SUCCESS);
+ return result;
}
static int kill(eff_t effp)