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