diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
commit | 513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch) | |
tree | 10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/intern/clip~.c | |
parent | 95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff) | |
download | rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip |
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/clip~.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/intern/clip~.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/clip~.c b/apps/plugins/pdbox/PDa/intern/clip~.c new file mode 100644 index 0000000000..e2c697d1d8 --- /dev/null +++ b/apps/plugins/pdbox/PDa/intern/clip~.c | |||
@@ -0,0 +1,116 @@ | |||
1 | #include <m_pd.h> | ||
2 | #include <m_fixed.h> | ||
3 | |||
4 | static t_class *clip_class; | ||
5 | |||
6 | typedef struct _clip | ||
7 | { | ||
8 | t_object x_obj; | ||
9 | float x_f; | ||
10 | t_float x_lo; | ||
11 | t_float x_hi; | ||
12 | } t_clip; | ||
13 | |||
14 | static void *clip_new(t_floatarg lo, t_floatarg hi) | ||
15 | { | ||
16 | t_clip *x = (t_clip *)pd_new(clip_class); | ||
17 | x->x_lo = lo; | ||
18 | x->x_hi = hi; | ||
19 | outlet_new(&x->x_obj, gensym("signal")); | ||
20 | floatinlet_new(&x->x_obj, &x->x_lo); | ||
21 | floatinlet_new(&x->x_obj, &x->x_hi); | ||
22 | x->x_f = 0; | ||
23 | return (x); | ||
24 | } | ||
25 | |||
26 | static t_int *clip_perform(t_int *w) | ||
27 | { | ||
28 | t_clip *x = (t_clip *)(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 | t_sample lo; | ||
33 | t_sample hi; | ||
34 | lo = ftofix(x->x_lo); | ||
35 | hi = ftofix(x->x_hi); | ||
36 | |||
37 | while (n--) | ||
38 | { | ||
39 | t_sample f = *in++; | ||
40 | if (f < lo) f = lo; | ||
41 | if (f > hi) f = hi; | ||
42 | *out++ = f; | ||
43 | } | ||
44 | return (w+5); | ||
45 | } | ||
46 | |||
47 | static void clip_dsp(t_clip *x, t_signal **sp) | ||
48 | { | ||
49 | dsp_add(clip_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); | ||
50 | } | ||
51 | |||
52 | void clip_tilde_setup(void) | ||
53 | { | ||
54 | clip_class = class_new(gensym("clip~"), (t_newmethod)clip_new, 0, | ||
55 | sizeof(t_clip), 0, A_DEFFLOAT, A_DEFFLOAT, 0); | ||
56 | CLASS_MAINSIGNALIN(clip_class, t_clip, x_f); | ||
57 | class_addmethod(clip_class, (t_method)clip_dsp, gensym("dsp"), 0); | ||
58 | } | ||
59 | #include <m_pd.h> | ||
60 | #include <m_fixed.h> | ||
61 | |||
62 | static t_class *clip_class; | ||
63 | |||
64 | typedef struct _clip | ||
65 | { | ||
66 | t_object x_obj; | ||
67 | float x_f; | ||
68 | t_float x_lo; | ||
69 | t_float x_hi; | ||
70 | } t_clip; | ||
71 | |||
72 | static void *clip_new(t_floatarg lo, t_floatarg hi) | ||
73 | { | ||
74 | t_clip *x = (t_clip *)pd_new(clip_class); | ||
75 | x->x_lo = lo; | ||
76 | x->x_hi = hi; | ||
77 | outlet_new(&x->x_obj, gensym("signal")); | ||
78 | floatinlet_new(&x->x_obj, &x->x_lo); | ||
79 | floatinlet_new(&x->x_obj, &x->x_hi); | ||
80 | x->x_f = 0; | ||
81 | return (x); | ||
82 | } | ||
83 | |||
84 | static t_int *clip_perform(t_int *w) | ||
85 | { | ||
86 | t_clip *x = (t_clip *)(w[1]); | ||
87 | t_sample *in = (t_sample *)(w[2]); | ||
88 | t_sample *out = (t_sample *)(w[3]); | ||
89 | int n = (int)(w[4]); | ||
90 | t_sample lo; | ||
91 | t_sample hi; | ||
92 | lo = ftofix(x->x_lo); | ||
93 | hi = ftofix(x->x_hi); | ||
94 | |||
95 | while (n--) | ||
96 | { | ||
97 | t_sample f = *in++; | ||
98 | if (f < lo) f = lo; | ||
99 | if (f > hi) f = hi; | ||
100 | *out++ = f; | ||
101 | } | ||
102 | return (w+5); | ||
103 | } | ||
104 | |||
105 | static void clip_dsp(t_clip *x, t_signal **sp) | ||
106 | { | ||
107 | dsp_add(clip_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); | ||
108 | } | ||
109 | |||
110 | void clip_tilde_setup(void) | ||
111 | { | ||
112 | clip_class = class_new(gensym("clip~"), (t_newmethod)clip_new, 0, | ||
113 | sizeof(t_clip), 0, A_DEFFLOAT, A_DEFFLOAT, 0); | ||
114 | CLASS_MAINSIGNALIN(clip_class, t_clip, x_f); | ||
115 | class_addmethod(clip_class, (t_method)clip_dsp, gensym("dsp"), 0); | ||
116 | } | ||