summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/extra/zerox~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/zerox~.c')
-rw-r--r--apps/plugins/pdbox/PDa/extra/zerox~.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/zerox~.c b/apps/plugins/pdbox/PDa/extra/zerox~.c
new file mode 100644
index 0000000000..f97f412308
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/zerox~.c
@@ -0,0 +1,114 @@
1#include "m_pd.h"
2
3static t_class *zerox_class;
4
5typedef struct _zerox
6{
7 t_object x_obj;
8 t_sample x_f;
9 t_int x_zeros;
10} t_zerox;
11
12
13static t_int *zerox_perform(t_int *w)
14{
15 t_zerox* x = (t_zerox*)w[1];
16 t_sample *in = (t_sample *)(w[2]);
17 int n = (int)(w[3]) ;
18
19 if (*in * x->x_f < 0) x->x_zeros++;
20 n--;
21 while (n--)
22 {
23 float f = *(in++);
24 x->x_zeros += f * *in < 0;
25 }
26 return (w+4);
27}
28
29static void zerox_dsp(t_zerox *x, t_signal **sp)
30{
31 dsp_add(zerox_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
32}
33
34
35static void zerox_bang(t_zerox* x)
36{
37 outlet_float(x->x_obj.ob_outlet,x->x_zeros);
38 x->x_zeros=0;
39}
40
41static void *zerox_new(void)
42{
43 t_zerox *x = (t_zerox *)pd_new(zerox_class);
44 outlet_new(&x->x_obj, gensym("float"));
45 x->x_f = 0;
46 x->x_zeros=0;
47 return (x);
48}
49
50void zerox_tilde_setup(void)
51{
52 zerox_class = class_new(gensym("zerox~"), (t_newmethod)zerox_new, 0,
53 sizeof(t_zerox), 0, A_DEFFLOAT, 0);
54 CLASS_MAINSIGNALIN(zerox_class, t_zerox, x_f);
55 class_addmethod(zerox_class, (t_method)zerox_dsp, gensym("dsp"), 0);
56 class_addbang(zerox_class, (t_method)zerox_bang);
57}
58#include "m_pd.h"
59
60static t_class *zerox_class;
61
62typedef struct _zerox
63{
64 t_object x_obj;
65 t_sample x_f;
66 t_int x_zeros;
67} t_zerox;
68
69
70static t_int *zerox_perform(t_int *w)
71{
72 t_zerox* x = (t_zerox*)w[1];
73 t_sample *in = (t_sample *)(w[2]);
74 int n = (int)(w[3]) ;
75
76 if (*in * x->x_f < 0) x->x_zeros++;
77 n--;
78 while (n--)
79 {
80 float f = *(in++);
81 x->x_zeros += f * *in < 0;
82 }
83 return (w+4);
84}
85
86static void zerox_dsp(t_zerox *x, t_signal **sp)
87{
88 dsp_add(zerox_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
89}
90
91
92static void zerox_bang(t_zerox* x)
93{
94 outlet_float(x->x_obj.ob_outlet,x->x_zeros);
95 x->x_zeros=0;
96}
97
98static void *zerox_new(void)
99{
100 t_zerox *x = (t_zerox *)pd_new(zerox_class);
101 outlet_new(&x->x_obj, gensym("float"));
102 x->x_f = 0;
103 x->x_zeros=0;
104 return (x);
105}
106
107void zerox_tilde_setup(void)
108{
109 zerox_class = class_new(gensym("zerox~"), (t_newmethod)zerox_new, 0,
110 sizeof(t_zerox), 0, A_DEFFLOAT, 0);
111 CLASS_MAINSIGNALIN(zerox_class, t_zerox, x_f);
112 class_addmethod(zerox_class, (t_method)zerox_dsp, gensym("dsp"), 0);
113 class_addbang(zerox_class, (t_method)zerox_bang);
114}