aboutsummaryrefslogtreecommitdiff
path: root/source/lavg.c
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2005-11-28 16:53:25 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2005-11-28 16:53:25 +0000
commitda1f0065d07250b86b9a761b012987e4825f491f (patch)
tree6e048a70f8d60e2fdf9d374ec536cab9df10e24a /source/lavg.c
This commit was generated by cvs2svn to compensate for changes in r4068,svn2git-root
which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/smlib/; revision=4069
Diffstat (limited to 'source/lavg.c')
-rw-r--r--source/lavg.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/source/lavg.c b/source/lavg.c
new file mode 100644
index 0000000..fce0015
--- /dev/null
+++ b/source/lavg.c
@@ -0,0 +1,55 @@
+#include "defines.h"
+
+/*--------------- lavg ---------------*/
+
+static t_class *lavg_class;
+
+typedef struct _lavg
+{
+ t_object x_obj;
+ float m_avg;
+ float m_c_leak;
+ float m_leak;
+} t_lavg;
+
+
+static void lavg_perform(t_lavg *x, t_float in)
+{
+ x->m_avg= x->m_avg * x->m_c_leak + in * x->m_leak;
+ outlet_float(x->x_obj.ob_outlet, x->m_avg);
+}
+
+static void lavg_clear(t_lavg *x)
+{
+ x->m_avg=0.0f;
+}
+
+static void lavg_setHalfDecay(t_lavg *x, t_float halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void *lavg_new( t_float halfDecayTime)
+{
+ t_lavg *x=(t_lavg *)pd_new(lavg_class);
+ outlet_new(&x->x_obj, gensym("float"));
+
+ lavg_setHalfDecay(x, halfDecayTime);
+ return (void *)x;
+}
+
+void lavg_setup(void)
+{
+ lavg_class = class_new(gensym("lavg"),
+ (t_newmethod)lavg_new, 0,
+ sizeof(t_lavg),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addfloat(lavg_class, (t_method)lavg_perform);
+ class_addmethod(lavg_class, (t_method)lavg_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+ class_addmethod(lavg_class, (t_method)lavg_clear,
+ gensym("clear"), 0);
+}
+