diff options
author | Jamie Bullock <postlude@users.sourceforge.net> | 2006-01-10 11:49:01 +0000 |
---|---|---|
committer | Jamie Bullock <postlude@users.sourceforge.net> | 2006-01-10 11:49:01 +0000 |
commit | 01314ebc83191b68a8b4b31b7b9efbf531f3b1d9 (patch) | |
tree | 026a8e32c31f280b2613e2b41b58fcdf86ff5c37 /flib/src/clean~.c |
This commit was generated by cvs2svn to compensate for changes in r4382,svn2git-root
which included commits to RCS files with non-trunk default branches.
svn path=/trunk/externals/postlude/; revision=4383
Diffstat (limited to 'flib/src/clean~.c')
-rw-r--r-- | flib/src/clean~.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/flib/src/clean~.c b/flib/src/clean~.c new file mode 100644 index 0000000..1261357 --- /dev/null +++ b/flib/src/clean~.c @@ -0,0 +1,87 @@ +/* flib - PD library for feature extraction +Copyright (C) 2005 Jamie Bullock + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + + + +/* cleans 'nan' 'inf' '-inf' from an audio vector */ + +#include "flib.h" +static t_class *clean_class; + +typedef struct _clean { + t_object x_obj; + t_float f; + t_outlet *out_r; +} t_clean; + +static t_int *clean_perform(t_int *w) +{ + t_sample *in = (t_sample *)(w[1]); + t_sample *out = (t_sample *)(w[2]); + t_int N = (t_int)(w[3]); + t_clean *x = (t_clean *)(w[4]); + + + while(N--){ + if(finite(*in)) + *out++ = *in++; + else + *out++ = 0; + } + return (w+5); +} + +static void clean_dsp(t_clean *x, t_signal **sp) +{ + dsp_add(clean_perform, 4, + sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n, x); +} + +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); + else + outlet_float(x->out_r, x->f); + +} + + + +static void *clean_new(void) +{ + 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); + return (void *)x; +} + + +void clean_tilde_setup(void) { + clean_class = class_new(gensym("clean~"), + (t_newmethod)clean_new, + 0, sizeof(t_clean), + CLASS_DEFAULT, 0); + + CLASS_MAINSIGNALIN(clean_class, t_clean,f); + class_addfloat(clean_class, clean_float); + class_addmethod(clean_class, + (t_method)clean_dsp, gensym("dsp"), 0); + class_sethelpsymbol(clean_class, gensym("help-flib")); +} |