diff options
author | Cyrille Henry <nusmuk@users.sourceforge.net> | 2009-06-01 13:53:17 +0000 |
---|---|---|
committer | Cyrille Henry <nusmuk@users.sourceforge.net> | 2009-06-01 13:53:17 +0000 |
commit | d0a14104c6848efc384075f6669a301b515c5a16 (patch) | |
tree | 81f58a270ce6e06df23e26cd6e98b92ac94d09ea | |
parent | 5414bf29966bf440fba17c9d4e6998a88d443321 (diff) |
add a work in progress vd~ object with "better" interpolation
algorythm.
svn path=/trunk/externals/nusmuk/; revision=11606
-rw-r--r-- | tab/vdc~-help.pd | 18 | ||||
-rw-r--r-- | tab/vdc~.c | 93 |
2 files changed, 111 insertions, 0 deletions
diff --git a/tab/vdc~-help.pd b/tab/vdc~-help.pd new file mode 100644 index 0000000..ce59096 --- /dev/null +++ b/tab/vdc~-help.pd @@ -0,0 +1,18 @@ +#N canvas 695 59 307 351 12; +#X floatatom 35 39 0 0 0 0 - - -; +#X text 115 131 signal output (delayed signal); +#X obj 35 67 sig~; +#X text 84 64 signal input (delay time in ms); +#X text 178 97 creation argument: name of delay line; +#X obj 31 297 phasor~; +#X msg 31 272 222; +#X obj 31 248 loadbang; +#X obj 34 159 oscillo~; +#X obj 34 92 vdc~ test; +#X obj 32 322 delwrite~ test 1000; +#X connect 0 0 2 0; +#X connect 2 0 9 0; +#X connect 5 0 10 0; +#X connect 6 0 5 0; +#X connect 7 0 6 0; +#X connect 9 0 8 0; diff --git a/tab/vdc~.c b/tab/vdc~.c new file mode 100644 index 0000000..c2efbd0 --- /dev/null +++ b/tab/vdc~.c @@ -0,0 +1,93 @@ +#include "m_pd.h" +#include "d_delay.c" + + +/* ----------------------------- vdc~ ----------------------------- */ +static t_class *sigvdc_class; + +typedef struct _sigvdc +{ + t_object x_obj; + t_symbol *x_sym; + t_float x_sr; /* samples per msec */ + int x_zerodel; /* 0 or vecsize depending on read/write order */ + t_float x_f; +} t_sigvdc; + +static void *sigvdc_new(t_symbol *s) +{ + t_sigvdc *x = (t_sigvdc *)pd_new(sigvdc_class); + if (!*s->s_name) s = gensym("vdc~"); + x->x_sym = s; + x->x_sr = 1; + x->x_zerodel = 0; + outlet_new(&x->x_obj, &s_signal); + x->x_f = 0; + return (x); +} + + +static t_int *sigvdc_perform(t_int *w) +{ + t_sample *in = (t_sample *)(w[1]); + t_sample *out = (t_sample *)(w[2]); + t_delwritectl *ctl = (t_delwritectl *)(w[3]); + t_sigvdc *x = (t_sigvdc *)(w[4]); + int n = (int)(w[5]); + + int nsamps = ctl->c_n; + t_sample limit = nsamps - n - 1; + t_sample fn = n-1; + t_sample *vp = ctl->c_vec, *bp, *wp = vp + ctl->c_phase; + t_sample zerodel = x->x_zerodel; + while (n--) + { + t_sample delsamps = x->x_sr * *in++ - zerodel, frac; + int idelsamps; + t_sample a, b, c, d, cminusb; + if (delsamps < 1.00001f) delsamps = 1.00001f; + if (delsamps > limit) delsamps = limit; + delsamps += fn; + fn = fn - 1.0f; + idelsamps = delsamps; + frac = delsamps - (t_sample)idelsamps; + bp = wp - idelsamps; + if (bp < vp + 4) bp += nsamps; + d = bp[-3]; + c = bp[-2]; + b = bp[-1]; + a = bp[0]; + cminusb = c-b; + *out++ = b + frac * ( + cminusb - 0.1666667f * (1.-frac) * ( + (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b) + ) + ); + } + return (w+6); +} + +static void sigvdc_dsp(t_sigvdc *x, t_signal **sp) +{ + t_sigdelwrite *delwriter = + (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class); + x->x_sr = sp[0]->s_sr * 0.001; + if (delwriter) + { + sigdelwrite_checkvecsize(delwriter, sp[0]->s_n); + x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ? + 0 : delwriter->x_vecsize); + dsp_add(sigvdc_perform, 5, + sp[0]->s_vec, sp[1]->s_vec, + &delwriter->x_cspace, x, sp[0]->s_n); + } + else error("vdc~: %s: no such delwrite~",x->x_sym->s_name); +} + +void vdc_tilde_setup(void) +{ + sigvdc_class = class_new(gensym("vdc~"), (t_newmethod)sigvdc_new, 0, + sizeof(t_sigvdc), 0, A_DEFSYM, 0); + class_addmethod(sigvdc_class, (t_method)sigvdc_dsp, gensym("dsp"), 0); + CLASS_MAINSIGNALIN(sigvdc_class, t_sigvdc, x_f); +} |