summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/cos~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/cos~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/cos~.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/cos~.c b/apps/plugins/pdbox/PDa/intern/cos~.c
new file mode 100644
index 0000000000..30ec4e49a7
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/cos~.c
@@ -0,0 +1,122 @@
1
2#include <m_pd.h>
3#include <m_fixed.h>
4#include "cos_table.h"
5
6/* ------------------------ cos~ ----------------------------- */
7#define FRAC ((1<<(fix1-ILOGCOSTABSIZE))-1)
8
9static t_class *cos_class;
10
11typedef struct _cos
12{
13 t_object x_obj;
14 float x_f;
15} t_cos;
16
17static void *cos_new(void)
18{
19 t_cos *x = (t_cos *)pd_new(cos_class);
20 outlet_new(&x->x_obj, gensym("signal"));
21 x->x_f = 0;
22 return (x);
23}
24
25static t_int *cos_perform(t_int *w)
26{
27 t_sample *in = (t_sample *)(w[1]);
28 t_sample *out = (t_sample *)(w[2]);
29 int n = (int)(w[3]);
30 t_sample *tab = cos_table;
31 int off;
32 int frac;
33 unsigned int phase;
34
35 while (n--) {
36 phase = *in++;
37 phase &= ((1<<fix1)-1);
38 off = fixtoi((long long)phase<<ILOGCOSTABSIZE);
39
40 frac = phase&(itofix(1)-1);
41 *out = mult(*(tab + off),itofix(1) - frac) +
42 mult(*(tab + off + 1),frac);
43 out++;
44 }
45 return (w+4);
46}
47
48static void cos_dsp(t_cos *x, t_signal **sp)
49{
50 dsp_add(cos_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
51}
52
53
54void cos_tilde_setup(void)
55{
56 cos_class = class_new(gensym("cos~"), (t_newmethod)cos_new, 0,
57 sizeof(t_cos), 0, A_DEFFLOAT, 0);
58 CLASS_MAINSIGNALIN(cos_class, t_cos, x_f);
59 class_addmethod(cos_class, (t_method)cos_dsp, gensym("dsp"), 0);
60 class_sethelpsymbol(cos_class, gensym("osc~-help.pd"));
61}
62
63#include <m_pd.h>
64#include <m_fixed.h>
65#include "cos_table.h"
66
67/* ------------------------ cos~ ----------------------------- */
68#define FRAC ((1<<(fix1-ILOGCOSTABSIZE))-1)
69
70static t_class *cos_class;
71
72typedef struct _cos
73{
74 t_object x_obj;
75 float x_f;
76} t_cos;
77
78static void *cos_new(void)
79{
80 t_cos *x = (t_cos *)pd_new(cos_class);
81 outlet_new(&x->x_obj, gensym("signal"));
82 x->x_f = 0;
83 return (x);
84}
85
86static t_int *cos_perform(t_int *w)
87{
88 t_sample *in = (t_sample *)(w[1]);
89 t_sample *out = (t_sample *)(w[2]);
90 int n = (int)(w[3]);
91 t_sample *tab = cos_table;
92 int off;
93 int frac;
94 unsigned int phase;
95
96 while (n--) {
97 phase = *in++;
98 phase &= ((1<<fix1)-1);
99 off = fixtoi((long long)phase<<ILOGCOSTABSIZE);
100
101 frac = phase&(itofix(1)-1);
102 *out = mult(*(tab + off),itofix(1) - frac) +
103 mult(*(tab + off + 1),frac);
104 out++;
105 }
106 return (w+4);
107}
108
109static void cos_dsp(t_cos *x, t_signal **sp)
110{
111 dsp_add(cos_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
112}
113
114
115void cos_tilde_setup(void)
116{
117 cos_class = class_new(gensym("cos~"), (t_newmethod)cos_new, 0,
118 sizeof(t_cos), 0, A_DEFFLOAT, 0);
119 CLASS_MAINSIGNALIN(cos_class, t_cos, x_f);
120 class_addmethod(cos_class, (t_method)cos_dsp, gensym("dsp"), 0);
121 class_sethelpsymbol(cos_class, gensym("osc~-help.pd"));
122}