diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/tabread~.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/intern/tabread~.c | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/tabread~.c b/apps/plugins/pdbox/PDa/intern/tabread~.c new file mode 100644 index 0000000000..f1f4fd4729 --- /dev/null +++ b/apps/plugins/pdbox/PDa/intern/tabread~.c | |||
@@ -0,0 +1,194 @@ | |||
1 | #define FIXEDPOINT | ||
2 | #include <m_pd.h> | ||
3 | #include <m_fixed.h> | ||
4 | |||
5 | static t_class *tabread_tilde_class; | ||
6 | |||
7 | typedef struct _tabread_tilde | ||
8 | { | ||
9 | t_object x_obj; | ||
10 | int x_npoints; | ||
11 | t_sample *x_vec; | ||
12 | t_symbol *x_arrayname; | ||
13 | float x_f; | ||
14 | } t_tabread_tilde; | ||
15 | |||
16 | static void *tabread_tilde_new(t_symbol *s) | ||
17 | { | ||
18 | t_tabread_tilde *x = (t_tabread_tilde *)pd_new(tabread_tilde_class); | ||
19 | x->x_arrayname = s; | ||
20 | x->x_vec = 0; | ||
21 | outlet_new(&x->x_obj, gensym("signal")); | ||
22 | x->x_f = 0; | ||
23 | return (x); | ||
24 | } | ||
25 | |||
26 | static t_int *tabread_tilde_perform(t_int *w) | ||
27 | { | ||
28 | t_tabread_tilde *x = (t_tabread_tilde *)(w[1]); | ||
29 | t_sample *in = (t_sample *)(w[2]); | ||
30 | t_sample *out = (t_sample *)(w[3]); | ||
31 | int n = (int)(w[4]); | ||
32 | int maxindex; | ||
33 | t_sample *buf = x->x_vec, *fp; | ||
34 | int i; | ||
35 | |||
36 | maxindex = x->x_npoints - 1; | ||
37 | if (!buf) goto zero; | ||
38 | |||
39 | for (i = 0; i < n; i++) | ||
40 | { | ||
41 | int index = ((long long) mult((*in++),ftofix(44.1)) >> fix1); | ||
42 | if (index < 0) | ||
43 | index = 0; | ||
44 | else if (index > maxindex) | ||
45 | index = maxindex; | ||
46 | *out++ = buf[index]; | ||
47 | } | ||
48 | return (w+5); | ||
49 | zero: | ||
50 | while (n--) *out++ = 0; | ||
51 | |||
52 | return (w+5); | ||
53 | } | ||
54 | |||
55 | void tabread_tilde_set(t_tabread_tilde *x, t_symbol *s) | ||
56 | { | ||
57 | t_garray *a; | ||
58 | |||
59 | x->x_arrayname = s; | ||
60 | if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) | ||
61 | { | ||
62 | if (*s->s_name) | ||
63 | error("tabread~: %s: no such array", x->x_arrayname->s_name); | ||
64 | x->x_vec = 0; | ||
65 | } | ||
66 | else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec)) | ||
67 | { | ||
68 | error("%s: bad template for tabread~", x->x_arrayname->s_name); | ||
69 | x->x_vec = 0; | ||
70 | } | ||
71 | else garray_usedindsp(a); | ||
72 | } | ||
73 | |||
74 | static void tabread_tilde_dsp(t_tabread_tilde *x, t_signal **sp) | ||
75 | { | ||
76 | tabread_tilde_set(x, x->x_arrayname); | ||
77 | |||
78 | dsp_add(tabread_tilde_perform, 4, x, | ||
79 | sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); | ||
80 | |||
81 | } | ||
82 | |||
83 | static void tabread_tilde_free(t_tabread_tilde *x) | ||
84 | { | ||
85 | } | ||
86 | |||
87 | void tabread_tilde_setup(void) | ||
88 | { | ||
89 | tabread_tilde_class = class_new(gensym("tabread~"), | ||
90 | (t_newmethod)tabread_tilde_new, (t_method)tabread_tilde_free, | ||
91 | sizeof(t_tabread_tilde), 0, A_DEFSYM, 0); | ||
92 | CLASS_MAINSIGNALIN(tabread_tilde_class, t_tabread_tilde, x_f); | ||
93 | class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_dsp, | ||
94 | gensym("dsp"), 0); | ||
95 | class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_set, | ||
96 | gensym("set"), A_SYMBOL, 0); | ||
97 | } | ||
98 | #define FIXEDPOINT | ||
99 | #include <m_pd.h> | ||
100 | #include <m_fixed.h> | ||
101 | |||
102 | static t_class *tabread_tilde_class; | ||
103 | |||
104 | typedef struct _tabread_tilde | ||
105 | { | ||
106 | t_object x_obj; | ||
107 | int x_npoints; | ||
108 | t_sample *x_vec; | ||
109 | t_symbol *x_arrayname; | ||
110 | float x_f; | ||
111 | } t_tabread_tilde; | ||
112 | |||
113 | static void *tabread_tilde_new(t_symbol *s) | ||
114 | { | ||
115 | t_tabread_tilde *x = (t_tabread_tilde *)pd_new(tabread_tilde_class); | ||
116 | x->x_arrayname = s; | ||
117 | x->x_vec = 0; | ||
118 | outlet_new(&x->x_obj, gensym("signal")); | ||
119 | x->x_f = 0; | ||
120 | return (x); | ||
121 | } | ||
122 | |||
123 | static t_int *tabread_tilde_perform(t_int *w) | ||
124 | { | ||
125 | t_tabread_tilde *x = (t_tabread_tilde *)(w[1]); | ||
126 | t_sample *in = (t_sample *)(w[2]); | ||
127 | t_sample *out = (t_sample *)(w[3]); | ||
128 | int n = (int)(w[4]); | ||
129 | int maxindex; | ||
130 | t_sample *buf = x->x_vec, *fp; | ||
131 | int i; | ||
132 | |||
133 | maxindex = x->x_npoints - 1; | ||
134 | if (!buf) goto zero; | ||
135 | |||
136 | for (i = 0; i < n; i++) | ||
137 | { | ||
138 | int index = ((long long) mult((*in++),ftofix(44.1)) >> fix1); | ||
139 | if (index < 0) | ||
140 | index = 0; | ||
141 | else if (index > maxindex) | ||
142 | index = maxindex; | ||
143 | *out++ = buf[index]; | ||
144 | } | ||
145 | return (w+5); | ||
146 | zero: | ||
147 | while (n--) *out++ = 0; | ||
148 | |||
149 | return (w+5); | ||
150 | } | ||
151 | |||
152 | void tabread_tilde_set(t_tabread_tilde *x, t_symbol *s) | ||
153 | { | ||
154 | t_garray *a; | ||
155 | |||
156 | x->x_arrayname = s; | ||
157 | if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) | ||
158 | { | ||
159 | if (*s->s_name) | ||
160 | error("tabread~: %s: no such array", x->x_arrayname->s_name); | ||
161 | x->x_vec = 0; | ||
162 | } | ||
163 | else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec)) | ||
164 | { | ||
165 | error("%s: bad template for tabread~", x->x_arrayname->s_name); | ||
166 | x->x_vec = 0; | ||
167 | } | ||
168 | else garray_usedindsp(a); | ||
169 | } | ||
170 | |||
171 | static void tabread_tilde_dsp(t_tabread_tilde *x, t_signal **sp) | ||
172 | { | ||
173 | tabread_tilde_set(x, x->x_arrayname); | ||
174 | |||
175 | dsp_add(tabread_tilde_perform, 4, x, | ||
176 | sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); | ||
177 | |||
178 | } | ||
179 | |||
180 | static void tabread_tilde_free(t_tabread_tilde *x) | ||
181 | { | ||
182 | } | ||
183 | |||
184 | void tabread_tilde_setup(void) | ||
185 | { | ||
186 | tabread_tilde_class = class_new(gensym("tabread~"), | ||
187 | (t_newmethod)tabread_tilde_new, (t_method)tabread_tilde_free, | ||
188 | sizeof(t_tabread_tilde), 0, A_DEFSYM, 0); | ||
189 | CLASS_MAINSIGNALIN(tabread_tilde_class, t_tabread_tilde, x_f); | ||
190 | class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_dsp, | ||
191 | gensym("dsp"), 0); | ||
192 | class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_set, | ||
193 | gensym("set"), A_SYMBOL, 0); | ||
194 | } | ||