Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / intern / hip~.c
blobab398264e331a5fc93f6300658821ddfab530d87
1 #include "../src/m_pd.h"
2 #include <../src/m_fixed.h>
4 typedef struct hipctl
6 t_sample c_x;
7 t_sample c_coef;
8 } t_hipctl;
10 typedef struct sighip
12 t_object x_obj;
13 float x_sr;
14 float x_hz;
15 t_hipctl x_cspace;
16 t_hipctl *x_ctl;
17 float x_f;
18 } t_sighip;
20 t_class *sighip_class;
21 static void sighip_ft1(t_sighip *x, t_floatarg f);
23 static void *sighip_new(t_floatarg f)
25 t_sighip *x = (t_sighip *)pd_new(sighip_class);
26 inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
27 outlet_new(&x->x_obj, gensym("signal"));
28 x->x_sr = 44100;
29 x->x_ctl = &x->x_cspace;
30 x->x_cspace.c_x = 0;
31 sighip_ft1(x, f);
32 x->x_f = 0;
33 return (x);
36 static void sighip_ft1(t_sighip *x, t_floatarg f)
38 t_float coeff;
39 if (f < 0.001) f = 10;
40 x->x_hz = f;
41 coeff = 1 - f * (2 * 3.14159) / x->x_sr;
42 if (coeff < 0) coeff = 0;
43 x->x_ctl->c_coef = ftofix(coeff);
46 static t_int *sighip_perform(t_int *w)
48 t_sample *in = (t_sample *)(w[1]);
49 t_sample *out = (t_sample *)(w[2]);
50 t_hipctl *c = (t_hipctl *)(w[3]);
51 int n = (t_int)(w[4]);
52 int i;
53 t_sample last = c->c_x;
54 t_sample coef = c->c_coef;
55 for (i = 0; i < n; i++)
57 t_sample new = *in++ + mult(coef,last);
58 *out++ = new - last;
59 last = new;
61 if (PD_BADFLOAT(last))
62 last = 0;
63 c->c_x = last;
64 return (w+5);
67 static void sighip_dsp(t_sighip *x, t_signal **sp)
69 x->x_sr = sp[0]->s_sr;
70 sighip_ft1(x, x->x_hz);
71 dsp_add(sighip_perform, 4,
72 sp[0]->s_vec, sp[1]->s_vec,
73 x->x_ctl, sp[0]->s_n);
77 static void sighip_clear(t_sighip *x, t_floatarg q)
79 #ifdef ROCKBOX
80 (void) q;
81 #endif
82 x->x_cspace.c_x = 0;
85 void hip_tilde_setup(void)
87 sighip_class = class_new(gensym("hip~"), (t_newmethod)sighip_new, 0,
88 sizeof(t_sighip), 0, A_DEFFLOAT, 0);
89 CLASS_MAINSIGNALIN(sighip_class, t_sighip, x_f);
90 class_addmethod(sighip_class, (t_method)sighip_dsp, gensym("dsp"), 0);
91 class_addmethod(sighip_class, (t_method)sighip_ft1,
92 gensym("ft1"), A_FLOAT, 0);
93 class_addmethod(sighip_class, (t_method)sighip_clear, gensym("clear"), 0);
94 class_sethelpsymbol(sighip_class, gensym("lop~-help.pd"));