summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/threshold~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/threshold~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/threshold~.c134
1 files changed, 0 insertions, 134 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/threshold~.c b/apps/plugins/pdbox/PDa/intern/threshold~.c
index 78b15f7342..2b8fcf8629 100644
--- a/apps/plugins/pdbox/PDa/intern/threshold~.c
+++ b/apps/plugins/pdbox/PDa/intern/threshold~.c
@@ -133,138 +133,4 @@ void threshold_tilde_setup( void)
133 class_addmethod(threshold_tilde_class, (t_method)threshold_tilde_dsp, 133 class_addmethod(threshold_tilde_class, (t_method)threshold_tilde_dsp,
134 gensym("dsp"), 0); 134 gensym("dsp"), 0);
135} 135}
136#include <m_pd.h>
137#include <m_fixed.h>
138
139static t_class *threshold_tilde_class;
140
141typedef struct _threshold_tilde
142{
143 t_object x_obj;
144 t_outlet *x_outlet1; /* bang out for high thresh */
145 t_outlet *x_outlet2; /* bang out for low thresh */
146 t_clock *x_clock; /* wakeup for message output */
147 float x_f; /* scalar inlet */
148 int x_state; /* 1 = high, 0 = low */
149 t_sample x_hithresh; /* value of high threshold */
150 t_sample x_lothresh; /* value of low threshold */
151 float x_deadwait; /* msec remaining in dead period */
152 float x_msecpertick; /* msec per DSP tick */
153 float x_hideadtime; /* hi dead time in msec */
154 float x_lodeadtime; /* lo dead time in msec */
155} t_threshold_tilde;
156
157static void threshold_tilde_tick(t_threshold_tilde *x);
158static void threshold_tilde_set(t_threshold_tilde *x,
159 t_floatarg hithresh, t_floatarg hideadtime,
160 t_floatarg lothresh, t_floatarg lodeadtime);
161
162static t_threshold_tilde *threshold_tilde_new(t_floatarg hithresh,
163 t_floatarg hideadtime, t_floatarg lothresh, t_floatarg lodeadtime)
164{
165 t_threshold_tilde *x = (t_threshold_tilde *)
166 pd_new(threshold_tilde_class);
167 x->x_state = 0; /* low state */
168 x->x_deadwait = 0; /* no dead time */
169 x->x_clock = clock_new(x, (t_method)threshold_tilde_tick);
170 x->x_outlet1 = outlet_new(&x->x_obj, &s_bang);
171 x->x_outlet2 = outlet_new(&x->x_obj, &s_bang);
172 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
173 x->x_msecpertick = 0.;
174 x->x_f = 0;
175 threshold_tilde_set(x, hithresh, hideadtime, lothresh, lodeadtime);
176 return (x);
177}
178
179 /* "set" message to specify thresholds and dead times */
180static void threshold_tilde_set(t_threshold_tilde *x,
181 t_floatarg hithresh, t_floatarg hideadtime,
182 t_floatarg lothresh, t_floatarg lodeadtime)
183{
184 if (lothresh > hithresh)
185 lothresh = hithresh;
186 x->x_hithresh = ftofix(hithresh);
187 x->x_hideadtime = hideadtime;
188 x->x_lothresh = ftofix(lothresh);
189 x->x_lodeadtime = lodeadtime;
190}
191
192 /* number in inlet sets state -- note incompatible with JMAX which used
193 "int" message for this, impossible here because of auto signal conversion */
194static void threshold_tilde_ft1(t_threshold_tilde *x, t_floatarg f)
195{
196 x->x_state = (f != 0);
197 x->x_deadwait = 0;
198}
199
200static void threshold_tilde_tick(t_threshold_tilde *x)
201{
202 if (x->x_state)
203 outlet_bang(x->x_outlet1);
204 else outlet_bang(x->x_outlet2);
205}
206 136
207static t_int *threshold_tilde_perform(t_int *w)
208{
209 t_sample *in1 = (t_sample *)(w[1]);
210 t_threshold_tilde *x = (t_threshold_tilde *)(w[2]);
211 int n = (t_int)(w[3]);
212 if (x->x_deadwait > 0)
213 x->x_deadwait -= x->x_msecpertick;
214 else if (x->x_state)
215 {
216 /* we're high; look for low sample */
217 for (; n--; in1++)
218 {
219 if (*in1 < x->x_lothresh)
220 {
221 clock_delay(x->x_clock, 0L);
222 x->x_state = 0;
223 x->x_deadwait = x->x_lodeadtime;
224 goto done;
225 }
226 }
227 }
228 else
229 {
230 /* we're low; look for high sample */
231 for (; n--; in1++)
232 {
233 if (*in1 >= x->x_hithresh)
234 {
235 clock_delay(x->x_clock, 0L);
236 x->x_state = 1;
237 x->x_deadwait = x->x_hideadtime;
238 goto done;
239 }
240 }
241 }
242done:
243 return (w+4);
244}
245
246void threshold_tilde_dsp(t_threshold_tilde *x, t_signal **sp)
247{
248 x->x_msecpertick = 1000. * sp[0]->s_n / sp[0]->s_sr;
249 dsp_add(threshold_tilde_perform, 3, sp[0]->s_vec, x, sp[0]->s_n);
250}
251
252static void threshold_tilde_ff(t_threshold_tilde *x)
253{
254 clock_free(x->x_clock);
255}
256
257void threshold_tilde_setup( void)
258{
259 threshold_tilde_class = class_new(gensym("threshold~"),
260 (t_newmethod)threshold_tilde_new, (t_method)threshold_tilde_ff,
261 sizeof(t_threshold_tilde), 0,
262 A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
263 CLASS_MAINSIGNALIN(threshold_tilde_class, t_threshold_tilde, x_f);
264 class_addmethod(threshold_tilde_class, (t_method)threshold_tilde_set,
265 gensym("set"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
266 class_addmethod(threshold_tilde_class, (t_method)threshold_tilde_ft1,
267 gensym("ft1"), A_FLOAT, 0);
268 class_addmethod(threshold_tilde_class, (t_method)threshold_tilde_dsp,
269 gensym("dsp"), 0);
270}