From 086e6b358ad45bda0e6a948cfb7ea2d33ab7da5a Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 Feb 2010 00:34:05 +0000 Subject: 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 --- hip.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 hip.c (limited to 'hip.c') diff --git a/hip.c b/hip.c new file mode 100644 index 0000000..b1425c1 --- /dev/null +++ b/hip.c @@ -0,0 +1,77 @@ +#include "defines.h" + +/*--------------- hip ---------------*/ + +typedef struct hipctl +{ + float c_x; + float c_coef; +} t_hipctl; + +typedef struct hip +{ + t_object x_obj; + float x_sr; + float x_hz; + t_hipctl x_cspace; + t_hipctl *x_ctl; + float x_f; +} t_hip; + +t_class *hip_class; + +static void hip_ft1(t_hip *x, t_floatarg f); + +static void *hip_new(t_floatarg f) +{ + t_hip *x = (t_hip *)pd_new(hip_class); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1")); + outlet_new(&x->x_obj, gensym("float")); + x->x_ctl = &x->x_cspace; + x->x_cspace.c_x = 0; + hip_ft1(x, f); + x->x_f = 0; + return (x); +} + +static void hip_ft1(t_hip *x, t_floatarg f) +{ + if (f < 0.001) f = 10; + x->x_hz = f; + x->x_ctl->c_coef = 1 - f * (2 * 3.14159f); + if (x->x_ctl->c_coef < 0) x->x_ctl->c_coef = 0; +} + +static void hip_perform(t_hip *x, t_float in) +{ + t_hipctl *c = x->x_ctl; + float last = c->c_x; + float coef = c->c_coef; + float out; + + float new = in + coef * last; + out = new - last; + last = new; + + /* NAN protect */ + if (!((last <= 0) || (last >= 0))) + last = 0; + c->c_x = last; + + outlet_float(x->x_obj.ob_outlet, out); +} + +static void hip_clear(t_hip *x, t_floatarg q) +{ + x->x_cspace.c_x = 0; +} + +void hip_setup(void) +{ + hip_class = class_new(gensym("hip"), (t_newmethod)hip_new, 0, + sizeof(t_hip), 0, A_DEFFLOAT, 0); + class_addfloat(hip_class, (t_method)hip_perform); + class_addmethod(hip_class, (t_method)hip_ft1, + gensym("ft1"), A_FLOAT, 0); + class_addmethod(hip_class, (t_method)hip_clear, gensym("clear"), 0); +} \ No newline at end of file -- cgit v1.2.1