summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/osc~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/osc~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/osc~.c174
1 files changed, 174 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/osc~.c b/apps/plugins/pdbox/PDa/intern/osc~.c
new file mode 100644
index 0000000000..f8e89970e9
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/osc~.c
@@ -0,0 +1,174 @@
1
2
3#include <m_pd.h>
4#include <m_fixed.h>
5#include "cos_table.h"
6
7/* ------------------------ osc~ ----------------------------- */
8
9static t_class *osc_class, *scalarosc_class;
10
11typedef struct _osc
12{
13 t_object x_obj;
14 unsigned int x_phase;
15 t_sample x_conv;
16 t_sample x_f; /* frequency if scalar */
17} t_osc;
18
19static void *osc_new(t_floatarg f)
20{
21 t_osc *x = (t_osc *)pd_new(osc_class);
22 x->x_f = ftofix(f);
23 outlet_new(&x->x_obj, gensym("signal"));
24 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
25 x->x_phase = 0;
26 x->x_conv = 0;
27 return (x);
28}
29
30
31static t_int *osc_perform(t_int *w)
32{
33 t_osc *x = (t_osc *)(w[1]);
34 t_sample *in = (t_sample *)(w[2]);
35 t_sample *out = (t_sample *)(w[3]);
36 int n = (int)(w[4]);
37 t_sample *tab = cos_table;
38 unsigned int phase = x->x_phase;
39 int conv = x->x_conv;
40 int off;
41 int frac;
42 while (n--) {
43 phase+= mult(conv ,(*in++));
44 phase &= (itofix(1) -1);
45 off = fixtoi((long long)phase<<ILOGCOSTABSIZE);
46
47#ifdef NO_INTERPOLATION
48 *out = *(tab+off);
49#else
50// frac = phase & (itofix(1)-1);
51 frac = phase & ((1<<ILOGCOSTABSIZE)-1);
52 frac <<= (fix1-ILOGCOSTABSIZE);
53 *out = mult(*(tab + off),(itofix(1) - frac)) +
54 mult(*(tab + off + 1),frac);
55#endif
56 out++;
57 }
58 x->x_phase = phase;
59
60 return (w+5);
61}
62
63static void osc_dsp(t_osc *x, t_signal **sp)
64{
65 post("samplerate %f",sp[0]->s_sr);
66 x->x_conv = ftofix(1000.)/sp[0]->s_sr;
67 post("conf %d",x->x_conv);
68 x->x_conv = mult(x->x_conv + 500,ftofix(0.001));
69 post("conf %d",x->x_conv);
70 dsp_add(osc_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
71}
72
73static void osc_ft1(t_osc *x, t_float f)
74{
75 x->x_phase = ftofix(f); /* *2 ??? */
76}
77
78void osc_tilde_setup(void)
79{
80 osc_class = class_new(gensym("osc~"), (t_newmethod)osc_new, 0,
81 sizeof(t_osc), 0, A_DEFFLOAT, 0);
82 CLASS_MAINSIGNALIN(osc_class, t_osc, x_f);
83 class_addmethod(osc_class, (t_method)osc_dsp, gensym("dsp"), 0);
84 class_addmethod(osc_class, (t_method)osc_ft1, gensym("ft1"), A_FLOAT, 0);
85}
86
87
88
89
90#include <m_pd.h>
91#include <m_fixed.h>
92#include "cos_table.h"
93
94/* ------------------------ osc~ ----------------------------- */
95
96static t_class *osc_class, *scalarosc_class;
97
98typedef struct _osc
99{
100 t_object x_obj;
101 unsigned int x_phase;
102 t_sample x_conv;
103 t_sample x_f; /* frequency if scalar */
104} t_osc;
105
106static void *osc_new(t_floatarg f)
107{
108 t_osc *x = (t_osc *)pd_new(osc_class);
109 x->x_f = ftofix(f);
110 outlet_new(&x->x_obj, gensym("signal"));
111 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
112 x->x_phase = 0;
113 x->x_conv = 0;
114 return (x);
115}
116
117
118static t_int *osc_perform(t_int *w)
119{
120 t_osc *x = (t_osc *)(w[1]);
121 t_sample *in = (t_sample *)(w[2]);
122 t_sample *out = (t_sample *)(w[3]);
123 int n = (int)(w[4]);
124 t_sample *tab = cos_table;
125 unsigned int phase = x->x_phase;
126 int conv = x->x_conv;
127 int off;
128 int frac;
129 while (n--) {
130 phase+= mult(conv ,(*in++));
131 phase &= (itofix(1) -1);
132 off = fixtoi((long long)phase<<ILOGCOSTABSIZE);
133
134#ifdef NO_INTERPOLATION
135 *out = *(tab+off);
136#else
137// frac = phase & (itofix(1)-1);
138 frac = phase & ((1<<ILOGCOSTABSIZE)-1);
139 frac <<= (fix1-ILOGCOSTABSIZE);
140 *out = mult(*(tab + off),(itofix(1) - frac)) +
141 mult(*(tab + off + 1),frac);
142#endif
143 out++;
144 }
145 x->x_phase = phase;
146
147 return (w+5);
148}
149
150static void osc_dsp(t_osc *x, t_signal **sp)
151{
152 post("samplerate %f",sp[0]->s_sr);
153 x->x_conv = ftofix(1000.)/sp[0]->s_sr;
154 post("conf %d",x->x_conv);
155 x->x_conv = mult(x->x_conv + 500,ftofix(0.001));
156 post("conf %d",x->x_conv);
157 dsp_add(osc_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
158}
159
160static void osc_ft1(t_osc *x, t_float f)
161{
162 x->x_phase = ftofix(f); /* *2 ??? */
163}
164
165void osc_tilde_setup(void)
166{
167 osc_class = class_new(gensym("osc~"), (t_newmethod)osc_new, 0,
168 sizeof(t_osc), 0, A_DEFFLOAT, 0);
169 CLASS_MAINSIGNALIN(osc_class, t_osc, x_f);
170 class_addmethod(osc_class, (t_method)osc_dsp, gensym("dsp"), 0);
171 class_addmethod(osc_class, (t_method)osc_ft1, gensym("ft1"), A_FLOAT, 0);
172}
173
174