ref: 0f74930593ba0568b1f13918d61d90b58cddb3ba
parent: 1e0a2088ecdc01ff006315e43f87ca3a6097d2e5
author: cbagwell <cbagwell>
date: Tue Feb 21 20:45:40 EST 2006
Changing CLIP macros prototypes.
--- a/TODO
+++ b/TODO
@@ -1,6 +1,9 @@
People are encouraged to pick some of these and implement it. Send
all patches to cbagwell@users.sourceforge.net.
+ o Change all calls to ST_SAMPLE_CLIP to use counters and
+ report clipping to user.
+
o Update all read routines to be like WAV handler and only
return data in multiples of sample_size*channels. This
will prevent corrupt files from causing sox to go into
--- a/src/avg.c
+++ b/src/avg.c
@@ -527,7 +527,7 @@
samp = 0.0;
for (i = 0; i < ichan; i++)
samp += ibuf[i] * avg->sources[i][j];
- ST_SAMPLE_CLIP(samp, NULL);
+ ST_SAMPLE_CLIP(samp);
obuf[j] = samp;
}
}
--- a/src/btrworth.c
+++ b/src/btrworth.c
@@ -81,7 +81,7 @@
butterworth->y [1] = butterworth->y [0];
butterworth->y [0] = out;
- ST_SAMPLE_CLIP(out, NULL);
+ ST_SAMPLE_CLIP(out);
*obuf++ = out;
}
--- a/src/compand.c
+++ b/src/compand.c
@@ -325,7 +325,7 @@
if (l->delay_buf_size <= 0)
{
checkbuf = ibuf[chan]*(outv/v)*l->outgain;
- ST_SAMPLE_CLIP(checkbuf, NULL);
+ ST_SAMPLE_CLIP(checkbuf);
obuf[odone] = checkbuf;
idone++;
@@ -337,7 +337,7 @@
{
l->delay_buf_full=1; //delay buffer is now definetly full
checkbuf = l->delay_buf[l->delay_buf_ptr]*(outv/v)*l->outgain;
- ST_SAMPLE_CLIP(checkbuf, NULL);
+ ST_SAMPLE_CLIP(checkbuf);
obuf[odone] = checkbuf;
odone++;
--- a/src/dcshift.c
+++ b/src/dcshift.c
@@ -165,7 +165,7 @@
sample = dcshift * ST_SAMPLE_MAX + sample;
}
- ST_SAMPLE_CLIP(sample, &dcs->clipped);
+ ST_SAMPLE_CLIP_COUNT(sample, dcs->clipped);
*obuf++ = sample;
}
}
@@ -177,7 +177,7 @@
float f;
f = dcshift * ST_SAMPLE_MAX + *ibuf++;
- ST_SAMPLE_CLIP(f, &dcs->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, dcs->clipped);
*obuf++ = f;
}
}
--- a/src/highp.c
+++ b/src/highp.c
@@ -93,7 +93,7 @@
d = highp->A0 * l +
highp->A1 * highp->inm1 +
highp->B1 * highp->outm1;
- ST_SAMPLE_CLIP(d, NULL);
+ ST_SAMPLE_CLIP(d);
highp->inm1 = l;
highp->outm1 = d;
*obuf++ = d;
--- a/src/lowp.c
+++ b/src/lowp.c
@@ -87,7 +87,7 @@
for(done = 0; done < len; done++) {
l = *ibuf++;
d = lowp->A * l + lowp->B * lowp->outm1;
- ST_SAMPLE_CLIP(d, NULL);
+ ST_SAMPLE_CLIP(d);
lowp->outm1 = d;
*obuf++ = d;
}
--- a/src/mcompand.c
+++ b/src/mcompand.c
@@ -168,7 +168,7 @@
butterworth->xy_low[chan].y [1] = butterworth->xy_low[chan].y [0];
butterworth->xy_low[chan].y [0] = out;
- ST_SAMPLE_CLIP(out, NULL);
+ ST_SAMPLE_CLIP(out);
*lowbufptr = out;
@@ -185,7 +185,7 @@
butterworth->xy_high[chan].y [1] = butterworth->xy_high[chan].y [0];
butterworth->xy_high[chan].y [0] = out;
- ST_SAMPLE_CLIP(out, NULL);
+ ST_SAMPLE_CLIP(out);
/* don't forget polarity reversal of high pass! */
@@ -611,7 +611,7 @@
for (i=0;i<len;++i)
{
out = obuf[i] + abuf[i];
- ST_SAMPLE_CLIP(out, NULL);
+ ST_SAMPLE_CLIP(out);
obuf[i] = out;
}
oldabuf = abuf;
@@ -634,7 +634,7 @@
*/
for (done = 0; done < maxdrain && l->delay_buf_cnt > 0; done++) {
out = obuf[done] + l->delay_buf[l->delay_buf_ptr++];
- ST_SAMPLE_CLIP(out, NULL);
+ ST_SAMPLE_CLIP(out);
obuf[done] = out;
l->delay_buf_ptr %= c->delay_buf_size;
l->delay_buf_cnt--;
--- a/src/noisered.c
+++ b/src/noisered.c
@@ -224,7 +224,7 @@
if (!first) {
for (j = 0; j < use; j ++) {
float s = chan->window[j] + chan->lastwindow[WINDOWSIZE/2 + j];
- ST_NORMALIZED_CLIP(s, &clipped);
+ ST_NORMALIZED_CLIP_COUNT(s, clipped);
if (clipped)
{
/* Reset for future tests. */
--- a/src/pan.c
+++ b/src/pan.c
@@ -140,7 +140,7 @@
{
float f;
f = HALF*ibuf[0] + HALF*ibuf[1];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
*obuf++ = f;
ibuf += 2;
}
@@ -151,7 +151,7 @@
float f;
f = QUARTER*ibuf[0] + QUARTER*ibuf[1] +
QUARTER*ibuf[2] + QUARTER*ibuf[3];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
*obuf++ = f;
ibuf += 4;
}
@@ -169,10 +169,10 @@
float f;
f = left * ibuf[0];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[0] = f;
f = right * ibuf[0];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[1] = f;
obuf += 2;
ibuf++;
@@ -195,10 +195,10 @@
float f;
f = cll * ibuf[0] + clr * ibuf[1];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[0] = f;
f = cr * ibuf[1];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[1] = f;
obuf += 2;
ibuf += 2;
@@ -218,10 +218,10 @@
float f;
f = cl * ibuf[0];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[0] = f;
f = crl * ibuf[0] + crr * ibuf[1];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[1] = f;
obuf += 2;
ibuf += 2;
@@ -248,10 +248,10 @@
/* pan it */
f = cll * ibuf0 + clr * ibuf1;
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[0] = f;
f = cr * ibuf1;
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[1] = f;
obuf += 2;
ibuf += 4;
@@ -274,10 +274,10 @@
ibuf1 = HALF*ibuf[1] + HALF*ibuf[3];
f = cl * ibuf0;
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[0] = f;
f = crl * ibuf0 + crr * ibuf1;
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[1] = f;
obuf += 2;
ibuf += 4;
@@ -303,10 +303,10 @@
float f;
f = cl * ibuf[0];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[2] = obuf[0] = f;
f = cr * ibuf[0];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
ibuf[3] = obuf[1] = f;
obuf += 4;
ibuf++;
@@ -328,10 +328,10 @@
float f;
f = cll * ibuf[0] + clr * ibuf[1];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[2] = obuf[0] = f;
f = cr * ibuf[1];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
ibuf[3] = obuf[1] = f;
obuf += 4;
ibuf += 2;
@@ -351,10 +351,10 @@
float f;
f = cl * ibuf[0];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[2] = obuf[0] =f ;
f = crl * ibuf[0] + crr * ibuf[1];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
ibuf[3] = obuf[1] = f;
obuf += 4;
ibuf += 2;
@@ -377,16 +377,16 @@
float f;
f = cown*ibuf[0] + cright*ibuf[1];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[0] = f;
f = cown*ibuf[1] + cright*ibuf[3];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[1] = f;
f = cown*ibuf[2] + cright*ibuf[0];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[2] = f;
f = cown*ibuf[3] + cright*ibuf[2];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[3] = f;
obuf += 4;
ibuf += 4;
@@ -404,16 +404,16 @@
float f;
f = cleft*ibuf[2] + cown*ibuf[0];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[0] = f;
f = cleft*ibuf[0] + cown*ibuf[1];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[1] = f;
f = cleft*ibuf[3] + cown*ibuf[2];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[2] = f;
f = cleft*ibuf[1] + cown*ibuf[3];
- ST_SAMPLE_CLIP(f, &pan->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pan->clipped);
obuf[3] = f;
obuf += 4;
ibuf += 4;
--- a/src/pitch.c
+++ b/src/pitch.c
@@ -530,7 +530,7 @@
float f;
f = pitch->acc[pitch->iacc++];
- ST_SAMPLE_CLIP(f, &pitch->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pitch->clipped);
obuf[oindex++] = f;
}
@@ -583,7 +583,7 @@
float f;
f = pitch->acc[pitch->iacc++];
- ST_SAMPLE_CLIP(f, &pitch->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, pitch->clipped);
obuf[i++] = f;
}
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -615,7 +615,7 @@
{
float f;
f = out_buf[k] * ISCALE; /* should clip-limit */
- ST_SAMPLE_CLIP(f, NULL);
+ ST_SAMPLE_CLIP(f);
*q++ = f;
}
--- a/src/resample.c
+++ b/src/resample.c
@@ -357,7 +357,7 @@
// orig: *obuf++ = r->Y[i] * ISCALE;
Float ftemp = r->Y[i] * ISCALE;
- ST_SAMPLE_CLIP(ftemp, NULL);
+ ST_SAMPLE_CLIP(ftemp);
*obuf++ = ftemp;
}
--- a/src/sox.c
+++ b/src/sox.c
@@ -703,7 +703,7 @@
{
double sample;
sample = efftab[0].obuf[s] + ibuf[f][s];
- ST_SAMPLE_CLIP(sample, &clipped);
+ ST_SAMPLE_CLIP_COUNT(sample, clipped);
efftab[0].obuf[s] = sample;
}
}
@@ -1499,7 +1499,7 @@
top = buf+ct;
while (p < top) {
y = vol * *p;
- ST_SAMPLE_CLIP(y, &clips);
+ ST_SAMPLE_CLIP_COUNT(y, clips);
*p++ = y;
}
return clips;
--- a/src/speed.c
+++ b/src/speed.c
@@ -195,7 +195,7 @@
f = cub(speed->cbuf[0], speed->cbuf[1],
speed->cbuf[2], speed->cbuf[3],
speed->frac);
- ST_SAMPLE_CLIP(f, &speed->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, speed->clipped);
obuf[i] = f;
}
--- a/src/st.h
+++ b/src/st.h
@@ -57,27 +57,36 @@
#define ST_SAMPLE_TO_FLOAT_DDWORD(d) ((double)((double)d/(ST_SAMPLE_FLOAT_SCALE)))
/* MACRO to clip a data type that is greater then st_sample_t to
- * st_sample_t's limits; optionally incrementing clips if its a
- * non-NULL pointer of type st_size_t.
+ * st_sample_t's limits.
*/
-#define ST_SAMPLE_CLIP(samp, clips) \
+#define ST_SAMPLE_CLIP(samp) \
do { \
if (samp > ST_SAMPLE_MAX) \
- { samp = ST_SAMPLE_MAX; if (clips) (*(st_size_t *)clips)++; } \
+ { samp = ST_SAMPLE_MAX; } \
else if (samp < ST_SAMPLE_MIN) \
- { samp = ST_SAMPLE_MIN; if (clips) (*(st_size_t *)clips)++; } \
+ { samp = ST_SAMPLE_MIN; } \
} while (0)
+/* MACRO to clip a data type that is greater then st_sample_t to
+ * st_sample_t's limits and increment a counter if clipping occurs..
+ */
+#define ST_SAMPLE_CLIP_COUNT(samp, clips) \
+ do { \
+ if (samp > ST_SAMPLE_MAX) \
+ { samp = ST_SAMPLE_MAX; clips++; } \
+ else if (samp < ST_SAMPLE_MIN) \
+ { samp = ST_SAMPLE_MIN; clips++; } \
+ } while (0)
+
/* MACRO to clip a normalized floating point data between 1.0 and -1.0
- * to those limits.; optionally incrementing clips if its a
- * non-NULL pointer of type st_size_t.
+ * to those limits and increment a counter when clipping occurs.
*/
-#define ST_NORMALIZED_CLIP(samp, clips) \
+#define ST_NORMALIZED_CLIP_COUNT(samp, clips) \
do { \
if (samp > 1) \
- { samp = 1; if (clips) (*(st_size_t *)clips)++; } \
+ { samp = 1; clips++; } \
else if (samp < -1) \
- { samp = -1; if (clips) (*(st_size_t *)clips)++; } \
+ { samp = -1; clips++; } \
} while (0)
/* Maximum value size type can hold. (Minimum is 0). */
--- a/src/stretch.c
+++ b/src/stretch.c
@@ -336,7 +336,7 @@
{
float f;
f = stretch->obuf[stretch->oindex++];
- ST_SAMPLE_CLIP(f, &stretch->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, stretch->clipped);
obuf[oindex++] = f;
}
@@ -393,7 +393,7 @@
float f;
f = stretch->obuf[stretch->oindex++];
- ST_SAMPLE_CLIP(f, &stretch->clipped);
+ ST_SAMPLE_CLIP_COUNT(f, stretch->clipped);
obuf[oindex++] = f;
}
}
--- a/src/vol.c
+++ b/src/vol.c
@@ -183,7 +183,7 @@
sample = gain * sample;
}
- ST_SAMPLE_CLIP(sample, vol->clipped);
+ ST_SAMPLE_CLIP_COUNT(sample, vol->clipped);
*obuf++ = sample;
}
}
@@ -193,7 +193,7 @@
for (;len>0; len--)
{
sample = gain * *ibuf++;
- ST_SAMPLE_CLIP(sample, vol->clipped);
+ ST_SAMPLE_CLIP_COUNT(sample, vol->clipped);
*obuf++ = sample;
}
}