aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamie Bullock <postlude@users.sourceforge.net>2006-01-20 12:58:38 +0000
committerJamie Bullock <postlude@users.sourceforge.net>2006-01-20 12:58:38 +0000
commit6119a3a90526ab88bf7ce239aae45f8e876bcbbe (patch)
tree42dd008ba97a995c429ecf51556c9b7b33270a0a
parent217786860c5c1105df6ece257a939daaa7111245 (diff)
Added features to bang right output when dirty values found, and set replacement value via first argument
svn path=/trunk/externals/postlude/; revision=4454
-rw-r--r--flib/src/clean~.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/flib/src/clean~.c b/flib/src/clean~.c
index 1261357..0133e18 100644
--- a/flib/src/clean~.c
+++ b/flib/src/clean~.c
@@ -18,15 +18,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-/* cleans 'nan' 'inf' '-inf' from an audio vector */
+/* cleans 'nan' 'inf' '-inf' from an audio vector or control value
+ * If no argument is given 'dirty' values will be replaced by 0, otherwise values are replaced by the argument value. If an audio vector is given as input, a bang is sent to the right output if 'dirty' values are found */
#include "flib.h"
+
+#define CLEAN (x->outval == x->inf ? 0 : x->outval)
+
static t_class *clean_class;
typedef struct _clean {
t_object x_obj;
t_float f;
t_outlet *out_r;
+ t_float outval, inf;
} t_clean;
static t_int *clean_perform(t_int *w)
@@ -35,14 +40,20 @@ static t_int *clean_perform(t_int *w)
t_sample *out = (t_sample *)(w[2]);
t_int N = (t_int)(w[3]);
t_clean *x = (t_clean *)(w[4]);
-
+ t_int dirty = 0;
while(N--){
- if(finite(*in))
- *out++ = *in++;
+ if(!finite(*in)){
+ dirty = 1;
+ *out++ = CLEAN;
+
+ }
else
- *out++ = 0;
+ *out++ = *in++;
}
+ if(dirty)
+ outlet_bang(x->out_r);
+
return (w+5);
}
@@ -55,8 +66,8 @@ static void clean_dsp(t_clean *x, t_signal **sp)
static void clean_float(t_clean *x, t_float f)
{
x->f = f;
- if(!x->f || !finite(x->f))
- outlet_float(x->out_r, 0);
+ if(!finite(x->f))
+ outlet_float(x->out_r, CLEAN);
else
outlet_float(x->out_r, x->f);
@@ -64,11 +75,19 @@ static void clean_float(t_clean *x, t_float f)
-static void *clean_new(void)
+static void *clean_new(t_symbol *s, t_int argc, t_atom *argv)
{
t_clean *x = (t_clean *)pd_new(clean_class);
outlet_new(&x->x_obj, &s_signal);
x->out_r = outlet_new(&x->x_obj, &s_float);
+ x->inf = (t_float)HUGE_VAL;
+
+ if(argc)
+ x->outval = atom_getfloatarg(0, argc, argv);
+ else
+ x->outval = x->inf;
+
+ post("%.2f", x->outval);
return (void *)x;
}
@@ -77,7 +96,7 @@ void clean_tilde_setup(void) {
clean_class = class_new(gensym("clean~"),
(t_newmethod)clean_new,
0, sizeof(t_clean),
- CLASS_DEFAULT, 0);
+ CLASS_DEFAULT, A_GIMME, 0);
CLASS_MAINSIGNALIN(clean_class, t_clean,f);
class_addfloat(clean_class, clean_float);