From da1f0065d07250b86b9a761b012987e4825f491f Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 28 Nov 2005 16:53:25 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r4068, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/smlib/; revision=4069 --- source/lmax.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 source/lmax.c (limited to 'source/lmax.c') diff --git a/source/lmax.c b/source/lmax.c new file mode 100644 index 0000000..911304f --- /dev/null +++ b/source/lmax.c @@ -0,0 +1,57 @@ +#include "defines.h" + +/*--------------- lmax ---------------*/ + +static t_class *lmax_class; + +typedef struct _lmax +{ + t_object x_obj; + float m_max; + float m_leak; + float m_c_leak; +} t_lmax; + + +static void lmax_perform(t_lmax *x, t_float in) +{ + x->m_max=(in > x->m_max) ? in : x->m_max * x->m_c_leak + in * x->m_leak; + outlet_float(x->x_obj.ob_outlet, x->m_max); +} + +static void lmax_setHalfDecay(t_lmax *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 lmax_clear(t_lmax *x) +{ + x->m_max= - MAXFLOAT; +} + +static void *lmax_new( t_float halfDecayTime) +{ + t_lmax *x=(t_lmax *)pd_new(lmax_class); + outlet_new(&x->x_obj, gensym("float")); + + lmax_setHalfDecay(x, halfDecayTime); + lmax_clear(x); + return (void *)x; +} + + +void lmax_setup(void) +{ + lmax_class = class_new(gensym("lmax"), + (t_newmethod)lmax_new, 0, + sizeof(t_lmax), + CLASS_DEFAULT, + A_DEFFLOAT, 0); + class_addfloat(lmax_class, (t_method)lmax_perform); + class_addmethod(lmax_class, (t_method)lmax_clear, + gensym("clear"), A_GIMME, NULL); + class_addmethod(lmax_class, (t_method)lmax_setHalfDecay, + gensym("decay"), A_DEFFLOAT, NULL); +} + -- cgit v1.2.1