diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2010-03-15 21:24:35 +0000 |
---|---|---|
committer | Martin Peach <mrpeach@users.sourceforge.net> | 2010-03-15 21:24:35 +0000 |
commit | 5e3a338b129e9ce6b5369c829ccd7290ed53c7e7 (patch) | |
tree | db0e8db43c0aad73955a046b1f2453107cc80339 /rc~ | |
parent | fc59cf402f250e398efa5691dae8f76085d807ca (diff) |
An external that emulates an RC timer, similar to lop~ but good for envelope generation.
svn path=/trunk/externals/mrpeach/; revision=13207
Diffstat (limited to 'rc~')
-rw-r--r-- | rc~/rc~-help.pd | 27 | ||||
-rw-r--r-- | rc~/rc~.c | 68 |
2 files changed, 95 insertions, 0 deletions
diff --git a/rc~/rc~-help.pd b/rc~/rc~-help.pd new file mode 100644 index 0000000..3222b7e --- /dev/null +++ b/rc~/rc~-help.pd @@ -0,0 +1,27 @@ +#N canvas 632 273 450 377 10; +#X obj 52 180 dac~; +#X obj 53 143 *~; +#X obj 52 79 tgl 15 0 empty empty empty 17 7 0 10 -4034 -13381 -1 0 +1; +#X obj 79 79 nbx 5 14 0 1e+37 0 1 empty empty seconds 60 8 0 10 -4034 +-13381 -13381 0.73 256; +#X obj 52 57 metro 1000; +#X obj 52 36 tgl 15 0 empty empty empty 17 7 0 10 -4034 -13381 -1 1 +1; +#X obj 52 99 rc~ 1; +#X text 191 167 Author: Martin Peach; +#X text 191 186 2010/03/15; +#X obj 67 121 noise~; +#X obj 136 230 lop~; +#X text 63 230 similar to:; +#X text 49 -22 rc~ emulates a capacitor charging through a resistor. +The creation argument can be overriden by the right inlet \, and represents +a charging time constant in seconds.; +#X connect 1 0 0 0; +#X connect 1 0 0 1; +#X connect 2 0 6 0; +#X connect 3 0 6 1; +#X connect 4 0 2 0; +#X connect 5 0 4 0; +#X connect 6 0 1 0; +#X connect 9 0 1 1; diff --git a/rc~/rc~.c b/rc~/rc~.c new file mode 100644 index 0000000..87525b8 --- /dev/null +++ b/rc~/rc~.c @@ -0,0 +1,68 @@ +/* rc~.c by Martin Peach 20100315 */ +/* Pd external emulating a resistor-capacitor low-pass filter */ +/* The control parameter is a time constant in seconds (or resistance X capacitance) */ + +#include "m_pd.h" + +static t_class *rc_tilde_class; + +typedef struct _rc_tilde +{ + t_object rc_obj; + t_float rc_rc; + t_float rc_f; + t_sample rc_node; +} t_rc_tilde; + +t_int *rc_tilde_perform(t_int *w) +{ + t_rc_tilde *x = (t_rc_tilde *)(w[1]); + t_sample *in = (t_sample *)(w[2]); + t_sample *out = (t_sample *)(w[3]); + int n = (int)(w[4]); + float slewrate; + float sp = 1.0/sys_getsr(); + + if (x->rc_rc < sp) slewrate = 1.0; + else slewrate = sp/x->rc_rc; + + while (n--) + { + x->rc_node += (*in++ - x->rc_node)*slewrate; + *out++ = x->rc_node; + } + + return (w+5); +} + +void rc_tilde_dsp(t_rc_tilde *x, t_signal **sp) +{ + dsp_add(rc_tilde_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); +} + +void *rc_tilde_new(t_floatarg f) +{ + t_rc_tilde *x = (t_rc_tilde *)pd_new(rc_tilde_class); + + x->rc_rc = f; + x->rc_node = 0.0; + + floatinlet_new (&x->rc_obj, &x->rc_rc); + outlet_new(&x->rc_obj, &s_signal); + return (void *)x; +} + +void rc_tilde_setup(void) +{ + rc_tilde_class = class_new(gensym("rc~"), + (t_newmethod)rc_tilde_new, + 0, sizeof(t_rc_tilde), + CLASS_DEFAULT, + A_DEFFLOAT, 0); + + class_addmethod(rc_tilde_class, (t_method)rc_tilde_dsp, gensym("dsp"), 0); + CLASS_MAINSIGNALIN(rc_tilde_class, t_rc_tilde, rc_f); +} + +/* fin rc~.c */ + |