summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/phasor~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/phasor~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/phasor~.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/phasor~.c b/apps/plugins/pdbox/PDa/intern/phasor~.c
new file mode 100644
index 0000000000..b823286b89
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/phasor~.c
@@ -0,0 +1,138 @@
1
2#include <m_pd.h>
3#include <m_fixed.h>
4
5/* -------------------------- phasor~ ------------------------------ */
6static t_class *phasor_class;
7
8typedef struct _phasor
9{
10 t_object x_obj;
11 unsigned int x_phase;
12 t_sample x_conv;
13 t_sample x_f; /* scalar frequency */
14} t_phasor;
15
16static void *phasor_new(t_floatarg f)
17{
18 t_phasor *x = (t_phasor *)pd_new(phasor_class);
19 x->x_f = ftofix(f);
20 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
21 x->x_phase = 0;
22 x->x_conv = 0;
23 outlet_new(&x->x_obj, gensym("signal"));
24 return (x);
25}
26
27static t_int *phasor_perform(t_int *w)
28{
29 t_phasor *x = (t_phasor *)(w[1]);
30 t_sample *in = (t_sample *)(w[2]);
31 t_sample *out = (t_sample *)(w[3]);
32 int n = (int)(w[4]);
33 unsigned int phase = x->x_phase;
34 int conv = x->x_conv;
35
36 while (n--) {
37 phase+= mult(conv , (*in++));
38 phase &= (itofix(1) - 1);
39 *out++ = phase;
40 }
41 x->x_phase = phase;
42
43 return (w+5);
44}
45
46static void phasor_dsp(t_phasor *x, t_signal **sp)
47{
48 x->x_conv = ftofix(1000.)/sp[0]->s_sr;
49 x->x_conv = mult(x->x_conv + 500,ftofix(0.001));
50 dsp_add(phasor_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
51}
52
53
54static void phasor_ft1(t_phasor *x, t_float f)
55{
56 x->x_phase = ftofix(f);
57}
58
59void phasor_tilde_setup(void)
60{
61 phasor_class = class_new(gensym("phasor~"), (t_newmethod)phasor_new, 0,
62 sizeof(t_phasor), 0, A_DEFFLOAT, 0);
63 CLASS_MAINSIGNALIN(phasor_class, t_phasor, x_f);
64 class_addmethod(phasor_class, (t_method)phasor_dsp, gensym("dsp"), 0);
65 class_addmethod(phasor_class, (t_method)phasor_ft1,
66 gensym("ft1"), A_FLOAT, 0);
67 class_sethelpsymbol(phasor_class, gensym("osc~-help.pd"));
68}
69
70
71#include <m_pd.h>
72#include <m_fixed.h>
73
74/* -------------------------- phasor~ ------------------------------ */
75static t_class *phasor_class;
76
77typedef struct _phasor
78{
79 t_object x_obj;
80 unsigned int x_phase;
81 t_sample x_conv;
82 t_sample x_f; /* scalar frequency */
83} t_phasor;
84
85static void *phasor_new(t_floatarg f)
86{
87 t_phasor *x = (t_phasor *)pd_new(phasor_class);
88 x->x_f = ftofix(f);
89 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
90 x->x_phase = 0;
91 x->x_conv = 0;
92 outlet_new(&x->x_obj, gensym("signal"));
93 return (x);
94}
95
96static t_int *phasor_perform(t_int *w)
97{
98 t_phasor *x = (t_phasor *)(w[1]);
99 t_sample *in = (t_sample *)(w[2]);
100 t_sample *out = (t_sample *)(w[3]);
101 int n = (int)(w[4]);
102 unsigned int phase = x->x_phase;
103 int conv = x->x_conv;
104
105 while (n--) {
106 phase+= mult(conv , (*in++));
107 phase &= (itofix(1) - 1);
108 *out++ = phase;
109 }
110 x->x_phase = phase;
111
112 return (w+5);
113}
114
115static void phasor_dsp(t_phasor *x, t_signal **sp)
116{
117 x->x_conv = ftofix(1000.)/sp[0]->s_sr;
118 x->x_conv = mult(x->x_conv + 500,ftofix(0.001));
119 dsp_add(phasor_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
120}
121
122
123static void phasor_ft1(t_phasor *x, t_float f)
124{
125 x->x_phase = ftofix(f);
126}
127
128void phasor_tilde_setup(void)
129{
130 phasor_class = class_new(gensym("phasor~"), (t_newmethod)phasor_new, 0,
131 sizeof(t_phasor), 0, A_DEFFLOAT, 0);
132 CLASS_MAINSIGNALIN(phasor_class, t_phasor, x_f);
133 class_addmethod(phasor_class, (t_method)phasor_dsp, gensym("dsp"), 0);
134 class_addmethod(phasor_class, (t_method)phasor_ft1,
135 gensym("ft1"), A_FLOAT, 0);
136 class_sethelpsymbol(phasor_class, gensym("osc~-help.pd"));
137}
138