4 typedef struct sigsamphold
12 t_class
*sigsamphold_class
;
14 static void *sigsamphold_new(void)
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"));
25 static t_int
*sigsamphold_perform(t_int
*w
)
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]);
33 t_sample lastin
= x
->x_lastin
;
34 t_sample lastout
= x
->x_lastout
;
35 for (i
= 0; i
< n
; i
++, *in1
++)
37 t_sample next
= *in2
++;
38 if (next
< lastin
) lastout
= *in1
;
43 x
->x_lastout
= lastout
;
47 static void sigsamphold_dsp(t_sigsamphold
*x
, t_signal
**sp
)
49 dsp_add(sigsamphold_perform
, 5,
50 sp
[0]->s_vec
, sp
[1]->s_vec
, sp
[2]->s_vec
,
54 static void sigsamphold_reset(t_sigsamphold
*x
)
56 x
->x_lastin
= 0x7fffffff;
59 static void sigsamphold_set(t_sigsamphold
*x
, t_float f
)
64 void samphold_tilde_setup(void)
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
,
73 class_addmethod(sigsamphold_class
, (t_method
)sigsamphold_dsp
,
79 typedef struct sigsamphold
87 t_class
*sigsamphold_class
;
89 static void *sigsamphold_new(void)
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"));
100 static t_int
*sigsamphold_perform(t_int
*w
)
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]);
108 t_sample lastin
= x
->x_lastin
;
109 t_sample lastout
= x
->x_lastout
;
110 for (i
= 0; i
< n
; i
++, *in1
++)
112 t_sample next
= *in2
++;
113 if (next
< lastin
) lastout
= *in1
;
117 x
->x_lastin
= lastin
;
118 x
->x_lastout
= lastout
;
122 static void sigsamphold_dsp(t_sigsamphold
*x
, t_signal
**sp
)
124 dsp_add(sigsamphold_perform
, 5,
125 sp
[0]->s_vec
, sp
[1]->s_vec
, sp
[2]->s_vec
,
129 static void sigsamphold_reset(t_sigsamphold
*x
)
131 x
->x_lastin
= 0x7fffffff;
134 static void sigsamphold_set(t_sigsamphold
*x
, t_float f
)
139 void samphold_tilde_setup(void)
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
,
148 class_addmethod(sigsamphold_class
, (t_method
)sigsamphold_dsp
,