aboutsummaryrefslogtreecommitdiff
path: root/decimator.c
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2010-02-10 00:34:05 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2010-02-10 00:34:05 +0000
commit086e6b358ad45bda0e6a948cfb7ea2d33ab7da5a (patch)
treeb87b0adfbfd8f9b9439d8bf528b63b64f23dce03 /decimator.c
parent98e3e1214cf71a62b2de938c9c7e07f6bdd0090c (diff)
re-arranged into libdir and setup with the template Makefile+debian stuff. renabled vv+ and vv- as vvplus and vvminus
svn path=/trunk/externals/smlib/; revision=13158
Diffstat (limited to 'decimator.c')
-rw-r--r--decimator.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/decimator.c b/decimator.c
new file mode 100644
index 0000000..d7f93f3
--- /dev/null
+++ b/decimator.c
@@ -0,0 +1,66 @@
+#include "defines.h"
+
+/*--------------- decimator ---------------*/
+
+static t_class *decimator_class;
+
+typedef struct _decimator
+{
+ t_object x_obj;
+ int m_state;
+ int m_factor;
+} t_decimator;
+
+static void decimator_perform(t_decimator *x, t_float in)
+{
+ if (!x->m_state)
+ {
+ outlet_float(x->x_obj.ob_outlet, in);
+ x->m_state=x->m_factor;
+ }
+ else
+ {
+ x->m_state--;
+ }
+
+}
+
+static void decimator_setFactor(t_decimator *x, t_float factor)
+{
+ x->m_factor=(int)factor - 1;
+}
+
+static void decimator_clear(t_decimator *x)
+{
+ x->m_state=0;
+}
+
+
+static void *decimator_new(t_float factor)
+{
+
+ t_decimator *x=(t_decimator *)pd_new(decimator_class);
+ outlet_new(&x->x_obj, gensym("float"));
+
+ if (factor<1) factor=2;
+
+ decimator_setFactor(x, factor);
+ decimator_clear(x);
+ return (void *)x;
+}
+
+
+void decimator_setup(void)
+{
+ decimator_class = class_new(gensym("decimator"),
+ (t_newmethod)decimator_new, 0,
+ sizeof(t_decimator),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addfloat(decimator_class, (t_method)decimator_perform);
+ class_addmethod(decimator_class, (t_method)decimator_clear,
+ gensym("clear"), A_GIMME, NULL);
+ class_addmethod(decimator_class, (t_method)decimator_setFactor,
+ gensym("factor"), A_DEFFLOAT, NULL);
+}
+