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/samphold~.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/samphold~.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/intern/samphold~.c | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/samphold~.c b/apps/plugins/pdbox/PDa/intern/samphold~.c new file mode 100644 index 0000000000..5ccf3d9cfe --- /dev/null +++ b/apps/plugins/pdbox/PDa/intern/samphold~.c | |||
@@ -0,0 +1,150 @@ | |||
1 | #include <m_pd.h> | ||
2 | #include <m_fixed.h> | ||
3 | |||
4 | typedef struct sigsamphold | ||
5 | { | ||
6 | t_object x_obj; | ||
7 | t_sample x_f; | ||
8 | t_sample x_lastin; | ||
9 | t_sample x_lastout; | ||
10 | } t_sigsamphold; | ||
11 | |||
12 | t_class *sigsamphold_class; | ||
13 | |||
14 | static void *sigsamphold_new(void) | ||
15 | { | ||
16 | t_sigsamphold *x = (t_sigsamphold *)pd_new(sigsamphold_class); | ||
17 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); | ||
18 | outlet_new(&x->x_obj, gensym("signal")); | ||
19 | x->x_lastin = 0; | ||
20 | x->x_lastout = 0; | ||
21 | x->x_f = 0; | ||
22 | return (x); | ||
23 | } | ||
24 | |||
25 | static t_int *sigsamphold_perform(t_int *w) | ||
26 | { | ||
27 | t_sample *in1 = (t_sample *)(w[1]); | ||
28 | t_sample *in2 = (t_sample *)(w[2]); | ||
29 | t_sample *out = (t_sample *)(w[3]); | ||
30 | t_sigsamphold *x = (t_sigsamphold *)(w[4]); | ||
31 | int n = (t_int)(w[5]); | ||
32 | int i; | ||
33 | t_sample lastin = x->x_lastin; | ||
34 | t_sample lastout = x->x_lastout; | ||
35 | for (i = 0; i < n; i++, *in1++) | ||
36 | { | ||
37 | t_sample next = *in2++; | ||
38 | if (next < lastin) lastout = *in1; | ||
39 | *out++ = lastout; | ||
40 | lastin = next; | ||
41 | } | ||
42 | x->x_lastin = lastin; | ||
43 | x->x_lastout = lastout; | ||
44 | return (w+6); | ||
45 | } | ||
46 | |||
47 | static void sigsamphold_dsp(t_sigsamphold *x, t_signal **sp) | ||
48 | { | ||
49 | dsp_add(sigsamphold_perform, 5, | ||
50 | sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, | ||
51 | x, sp[0]->s_n); | ||
52 | } | ||
53 | |||
54 | static void sigsamphold_reset(t_sigsamphold *x) | ||
55 | { | ||
56 | x->x_lastin = 0x7fffffff; | ||
57 | } | ||
58 | |||
59 | static void sigsamphold_set(t_sigsamphold *x, t_float f) | ||
60 | { | ||
61 | x->x_lastout = f; | ||
62 | } | ||
63 | |||
64 | void samphold_tilde_setup(void) | ||
65 | { | ||
66 | sigsamphold_class = class_new(gensym("samphold~"), | ||
67 | (t_newmethod)sigsamphold_new, 0, sizeof(t_sigsamphold), 0, 0); | ||
68 | CLASS_MAINSIGNALIN(sigsamphold_class, t_sigsamphold, x_f); | ||
69 | class_addmethod(sigsamphold_class, (t_method)sigsamphold_set, | ||
70 | gensym("set"), A_FLOAT, 0); | ||
71 | class_addmethod(sigsamphold_class, (t_method)sigsamphold_reset, | ||
72 | gensym("reset"), 0); | ||
73 | class_addmethod(sigsamphold_class, (t_method)sigsamphold_dsp, | ||
74 | gensym("dsp"), 0); | ||
75 | } | ||
76 | #include <m_pd.h> | ||
77 | #include <m_fixed.h> | ||
78 | |||
79 | typedef struct sigsamphold | ||
80 | { | ||
81 | t_object x_obj; | ||
82 | t_sample x_f; | ||
83 | t_sample x_lastin; | ||
84 | t_sample x_lastout; | ||
85 | } t_sigsamphold; | ||
86 | |||
87 | t_class *sigsamphold_class; | ||
88 | |||
89 | static void *sigsamphold_new(void) | ||
90 | { | ||
91 | t_sigsamphold *x = (t_sigsamphold *)pd_new(sigsamphold_class); | ||
92 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); | ||
93 | outlet_new(&x->x_obj, gensym("signal")); | ||
94 | x->x_lastin = 0; | ||
95 | x->x_lastout = 0; | ||
96 | x->x_f = 0; | ||
97 | return (x); | ||
98 | } | ||
99 | |||
100 | static t_int *sigsamphold_perform(t_int *w) | ||
101 | { | ||
102 | t_sample *in1 = (t_sample *)(w[1]); | ||
103 | t_sample *in2 = (t_sample *)(w[2]); | ||
104 | t_sample *out = (t_sample *)(w[3]); | ||
105 | t_sigsamphold *x = (t_sigsamphold *)(w[4]); | ||
106 | int n = (t_int)(w[5]); | ||
107 | int i; | ||
108 | t_sample lastin = x->x_lastin; | ||
109 | t_sample lastout = x->x_lastout; | ||
110 | for (i = 0; i < n; i++, *in1++) | ||
111 | { | ||
112 | t_sample next = *in2++; | ||
113 | if (next < lastin) lastout = *in1; | ||
114 | *out++ = lastout; | ||
115 | lastin = next; | ||
116 | } | ||
117 | x->x_lastin = lastin; | ||
118 | x->x_lastout = lastout; | ||
119 | return (w+6); | ||
120 | } | ||
121 | |||
122 | static void sigsamphold_dsp(t_sigsamphold *x, t_signal **sp) | ||
123 | { | ||
124 | dsp_add(sigsamphold_perform, 5, | ||
125 | sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, | ||
126 | x, sp[0]->s_n); | ||
127 | } | ||
128 | |||
129 | static void sigsamphold_reset(t_sigsamphold *x) | ||
130 | { | ||
131 | x->x_lastin = 0x7fffffff; | ||
132 | } | ||
133 | |||
134 | static void sigsamphold_set(t_sigsamphold *x, t_float f) | ||
135 | { | ||
136 | x->x_lastout = f; | ||
137 | } | ||
138 | |||
139 | void samphold_tilde_setup(void) | ||
140 | { | ||
141 | sigsamphold_class = class_new(gensym("samphold~"), | ||
142 | (t_newmethod)sigsamphold_new, 0, sizeof(t_sigsamphold), 0, 0); | ||
143 | CLASS_MAINSIGNALIN(sigsamphold_class, t_sigsamphold, x_f); | ||
144 | class_addmethod(sigsamphold_class, (t_method)sigsamphold_set, | ||
145 | gensym("set"), A_FLOAT, 0); | ||
146 | class_addmethod(sigsamphold_class, (t_method)sigsamphold_reset, | ||
147 | gensym("reset"), 0); | ||
148 | class_addmethod(sigsamphold_class, (t_method)sigsamphold_dsp, | ||
149 | gensym("dsp"), 0); | ||
150 | } | ||