From 85b2d2247f811c66cb4b2c4bd5f7f331ebdbe743 Mon Sep 17 00:00:00 2001 From: Cyrille Henry Date: Wed, 16 Sep 2015 16:59:34 +0000 Subject: new tab manipulation object : integration and derivative svn path=/trunk/externals/nusmuk/; revision=17566 --- nusmuk-utils/tab_derivate-help.pd | 62 ++++++++++++++++++++++++++++ nusmuk-utils/tab_derivate.c | 84 ++++++++++++++++++++++++++++++++++++++ nusmuk-utils/tab_integrate-help.pd | 62 ++++++++++++++++++++++++++++ nusmuk-utils/tab_integrate.c | 84 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 292 insertions(+) create mode 100644 nusmuk-utils/tab_derivate-help.pd create mode 100644 nusmuk-utils/tab_derivate.c create mode 100644 nusmuk-utils/tab_integrate-help.pd create mode 100644 nusmuk-utils/tab_integrate.c diff --git a/nusmuk-utils/tab_derivate-help.pd b/nusmuk-utils/tab_derivate-help.pd new file mode 100644 index 0000000..b0244d8 --- /dev/null +++ b/nusmuk-utils/tab_derivate-help.pd @@ -0,0 +1,62 @@ +#N canvas 432 355 859 564 10; +#N canvas 0 50 450 300 (subpatch) 0; +#X array src1 100 float 1; +#A 0 0.328571 0.307143 0.285714 0.257143 0.235714 0.214286 0.171429 +0.157143 0.157143 0.128572 0.0714288 3.57628e-07 -0.0428567 -0.0857137 +-0.199999 -0.257142 -0.314285 -0.42857 -0.485713 -0.542856 -0.657141 +-0.707141 -0.757141 -0.799998 -0.842855 -0.928569 -0.971426 -1.01428 +-1.07143 -0.714284 -0.257142 0.285714 3.57628e-07 -0.257142 -0.371427 +-0.457142 -0.571427 -0.62857 -0.642855 -0.585713 -0.499999 -0.385713 +-0.321428 -0.257142 -0.199999 -0.142856 -0.0857137 -0.028571 0.0714288 +0.121429 0.242857 0.314285 0.114286 -0.128571 -0.342856 -0.471427 -0.485713 +-0.228571 -0.0714281 0.0571431 0.2 0.257143 0.314285 0.414285 0.528571 +0.457142 0.364285 0.271428 0.0714288 -0.0214282 -0.114285 -0.199999 +-0.285713 -0.364285 -0.442856 -0.492856 -0.542856 -0.62857 -0.671427 +-0.685712 -0.685712 -0.62857 -0.542856 -0.492856 -0.442856 -0.404761 +-0.366666 -0.32857 -0.264285 -0.199999 -0.15238 -0.104761 -0.0571424 +-0.00952343 0.0380955 0.0857145 0.128572 0.171429 0.214286 0.614285 +; +#X coords 0 1 99 -1 200 140 1; +#X restore 537 27 graph; +#N canvas 0 50 450 300 (subpatch) 0; +#X array dst 100 float 0; +#X coords 0 1 99 -1 200 140 1; +#X restore 540 217 graph; +#X obj 61 31 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 61 106 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 60 264 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 78 199 dst dst; +#X msg 60 170 src1 src1; +#X text 108 465 IEM KUG; +#X text 88 453 musil; +#X text 122 453 @; +#X text 130 453 iem.at; +#X text 91 475 Graz \, Austria; +#X text 174 269 initial arguments:; +#X text 73 243 output; +#X text 129 198 xxx : change destination name; +#X text 225 86 the minimum of the 3 array lengths); +#X text 123 170 xxx : change source name 1; +#X text 151 283 1.arg: source-name 1; +#X text 212 72 (the number of samples which were added are:; +#X text 43 442 (c) Thomas Musil 2000 - 2009; +#X text 12 3 tab_max; +#X text 90 29 max the 2 src-arrays to dst-array; +#X text 54 420 ch \, help file based on :; +#X text 152 299 2.arg: destination-name; +#X obj 34 156 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj 60 225 tab_derivate dst dst; +#X obj 61 78 tab_derivate src1 dst; +#X msg 89 53 20; +#X text 123 54 only first 20 points; +#X connect 2 0 26 0; +#X connect 5 0 25 0; +#X connect 6 0 25 0; +#X connect 24 0 25 0; +#X connect 25 0 4 0; +#X connect 26 0 3 0; +#X connect 27 0 26 0; diff --git a/nusmuk-utils/tab_derivate.c b/nusmuk-utils/tab_derivate.c new file mode 100644 index 0000000..f035b99 --- /dev/null +++ b/nusmuk-utils/tab_derivate.c @@ -0,0 +1,84 @@ +#include "m_pd.h" + +#define MIN(a,b) (((a)<(b))?(a):(b)) + +static t_class *tab_derivate_class; + +typedef struct _tab_derivate { + t_object x_obj; + t_symbol *x_arrayname_src1; + t_symbol *x_arrayname_dst; + t_outlet *b_out; +} t_tab_derivate; + +void *tab_derivate_new(t_symbol *s_src1, t_symbol *s_dst) { + t_tab_derivate *x = (t_tab_derivate *)pd_new(tab_derivate_class); + + x->x_arrayname_src1 = s_src1; + x->x_arrayname_dst = s_dst; + + x->b_out = outlet_new(&x->x_obj, &s_bang); + + return (void *)x; +} + +void tab_derivate_compute(t_tab_derivate *x, t_float nb) { + t_garray *a_src1, *a_dst; + int npoints_src1, npoints_dst; + t_word *vec_src1, *vec_dst; + t_float tmp2, tmp1; + + int nb_derivate, i; + + if (!(a_src1 = (t_garray *)pd_findbyclass(x->x_arrayname_src1, garray_class))) + pd_error(x, "%s: no such array", x->x_arrayname_src1->s_name); + else if (!garray_getfloatwords(a_src1, &npoints_src1, &vec_src1)) + pd_error(x, "%s: bad template for tab_derivate", x->x_arrayname_src1->s_name); + else if (!(a_dst = (t_garray *)pd_findbyclass(x->x_arrayname_dst, garray_class))) + pd_error(x, "%s: no such array", x->x_arrayname_dst->s_name); + else if (!garray_getfloatwords(a_dst, &npoints_dst, &vec_dst)) + pd_error(x, "%s: bad template for tab_derivate", x->x_arrayname_dst->s_name); + else + { + nb_derivate = MIN(npoints_src1, npoints_dst); + // post("nb_derivate = %d",nb_derivate); + + if (nb > 0) + nb_derivate = MIN(nb_derivate, nb); + + tmp1 = 0; + for (i=0; ib_out); +} + +void tab_derivate_bang(t_tab_derivate *x) { + tab_derivate_compute(x, -1) ; +} + +void tab_derivate_float(t_tab_derivate *x, t_float nb) { + tab_derivate_compute(x, nb) ; +} + +void tab_derivate_src1(t_tab_derivate *x, t_symbol *s_src) { + x->x_arrayname_src1 = s_src; +} + +void tab_derivate_dst(t_tab_derivate *x, t_symbol *s_dst) { + x->x_arrayname_dst = s_dst; +} + +void tab_derivate_setup(void) { + tab_derivate_class = class_new(gensym("tab_derivate"), (t_newmethod)tab_derivate_new, + 0, sizeof(t_tab_derivate), CLASS_DEFAULT, A_DEFSYM, A_DEFSYM, A_DEFSYM, 0); + class_addbang(tab_derivate_class, tab_derivate_bang); + class_addfloat(tab_derivate_class, tab_derivate_float); + class_addmethod(tab_derivate_class, (t_method)tab_derivate_src1, gensym("src1"), A_DEFSYM, 0); + class_addmethod(tab_derivate_class, (t_method)tab_derivate_dst, gensym("dst"), A_DEFSYM, 0); +} + diff --git a/nusmuk-utils/tab_integrate-help.pd b/nusmuk-utils/tab_integrate-help.pd new file mode 100644 index 0000000..fe6491a --- /dev/null +++ b/nusmuk-utils/tab_integrate-help.pd @@ -0,0 +1,62 @@ +#N canvas 436 345 859 564 10; +#N canvas 0 50 450 300 (subpatch) 0; +#X array src1 100 float 1; +#A 0 0.128572 -0.0714291 -0.0714291 -0.0857149 -0.100001 -0.114286 +-0.114286 -0.114286 -0.114286 -0.114286 -0.114286 -0.100001 -0.100001 +-0.0857149 -0.0857149 -0.0714291 -0.0571433 -0.0285717 -0.0142859 -0.0142859 +0.0142857 0.0142857 0.0857178 0.100004 0.128575 0.142861 0.157147 0.171433 +0.185718 0.185718 0.185718 0.185718 0.157147 0.142861 0.128575 0.100004 +0.0428572 0.0428572 0.0428572 0.0428572 0.0285714 0.0285714 0.0285714 +0.0142856 0.0142856 -1.78814e-07 -1.78814e-07 -0.014286 -0.014286 -0.014286 +-0.0285718 -0.0285718 -0.0285718 -0.0428576 -0.0428576 -0.0428576 -0.0428576 +-0.0428576 -0.0428576 -0.0428576 -0.0428576 -0.0428576 -0.0428576 -0.0428576 +-0.0428576 -0.0285718 -0.014286 -0.014286 -1.78814e-07 -1.78814e-07 +0.0142856 0.0285714 0.0285714 0.0428572 0.0428572 0.0428572 0.057143 +0.0714288 0.0285715 0.0285715 0.0285715 0.0285715 0.0285715 0.0285715 +0.0285715 0.0285715 0.0285715 0.0142857 -0.0142859 -0.0285717 -0.0428575 +-0.0571433 -0.0857149 -0.114286 -0.142858 -0.17143 -0.214287 -0.242859 +-0.27143 -0.300002; +#X coords 0 1 99 -1 200 140 1; +#X restore 534 10 graph; +#N canvas 0 50 450 300 (subpatch) 0; +#X array dst 100 float 0; +#X coords 0 1 99 -1 200 140 1; +#X restore 540 217 graph; +#X obj 61 31 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 61 106 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 60 264 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 78 199 dst dst; +#X msg 60 170 src1 src1; +#X text 108 465 IEM KUG; +#X text 88 453 musil; +#X text 122 453 @; +#X text 130 453 iem.at; +#X text 91 475 Graz \, Austria; +#X text 174 269 initial arguments:; +#X text 73 243 output; +#X text 129 198 xxx : change destination name; +#X text 225 86 the minimum of the 3 array lengths); +#X text 123 170 xxx : change source name 1; +#X text 151 283 1.arg: source-name 1; +#X text 212 72 (the number of samples which were added are:; +#X text 43 442 (c) Thomas Musil 2000 - 2009; +#X text 12 3 tab_max; +#X text 90 29 max the 2 src-arrays to dst-array; +#X text 54 420 ch \, help file based on :; +#X text 152 299 2.arg: destination-name; +#X obj 60 225 tab_integrate src1 dst; +#X obj 34 156 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj 61 78 tab_integrate src1 dst; +#X msg 89 54 10; +#X text 127 53 only the first 10 moints; +#X connect 2 0 26 0; +#X connect 5 0 24 0; +#X connect 6 0 24 0; +#X connect 24 0 4 0; +#X connect 25 0 24 0; +#X connect 26 0 3 0; +#X connect 27 0 26 0; diff --git a/nusmuk-utils/tab_integrate.c b/nusmuk-utils/tab_integrate.c new file mode 100644 index 0000000..7d83489 --- /dev/null +++ b/nusmuk-utils/tab_integrate.c @@ -0,0 +1,84 @@ +#include "m_pd.h" + +#define MIN(a,b) (((a)<(b))?(a):(b)) + +static t_class *tab_integrate_class; + +typedef struct _tab_integrate { + t_object x_obj; + t_symbol *x_arrayname_src1; + t_symbol *x_arrayname_dst; + t_outlet *b_out; +} t_tab_integrate; + +void *tab_integrate_new(t_symbol *s_src1, t_symbol *s_dst) { + t_tab_integrate *x = (t_tab_integrate *)pd_new(tab_integrate_class); + + x->x_arrayname_src1 = s_src1; + x->x_arrayname_dst = s_dst; + + x->b_out = outlet_new(&x->x_obj, &s_bang); + + return (void *)x; +} + +void tab_integrate_compute(t_tab_integrate *x, t_float nb) { + t_garray *a_src1, *a_dst; + int npoints_src1, npoints_dst; + t_word *vec_src1, *vec_dst; + t_float integral; + + int nb_integrate, i; + + integral = 0; + + if (!(a_src1 = (t_garray *)pd_findbyclass(x->x_arrayname_src1, garray_class))) + pd_error(x, "%s: no such array", x->x_arrayname_src1->s_name); + else if (!garray_getfloatwords(a_src1, &npoints_src1, &vec_src1)) + pd_error(x, "%s: bad template for tab_integrate", x->x_arrayname_src1->s_name); + else if (!(a_dst = (t_garray *)pd_findbyclass(x->x_arrayname_dst, garray_class))) + pd_error(x, "%s: no such array", x->x_arrayname_dst->s_name); + else if (!garray_getfloatwords(a_dst, &npoints_dst, &vec_dst)) + pd_error(x, "%s: bad template for tab_integrate", x->x_arrayname_dst->s_name); + else + { + nb_integrate = MIN(npoints_src1, npoints_dst); + // post("nb_integrate = %d",nb_integrate); + + if (nb > 0) + nb_integrate = MIN(nb_integrate, nb); + + for (i=0; ib_out); +} + +void tab_integrate_bang(t_tab_integrate *x) { + tab_integrate_compute(x, -1) ; +} + +void tab_integrate_float(t_tab_integrate *x, t_float nb) { + tab_integrate_compute(x, nb) ; +} + +void tab_integrate_src1(t_tab_integrate *x, t_symbol *s_src) { + x->x_arrayname_src1 = s_src; +} + +void tab_integrate_dst(t_tab_integrate *x, t_symbol *s_dst) { + x->x_arrayname_dst = s_dst; +} + +void tab_integrate_setup(void) { + tab_integrate_class = class_new(gensym("tab_integrate"), (t_newmethod)tab_integrate_new, + 0, sizeof(t_tab_integrate), CLASS_DEFAULT, A_DEFSYM, A_DEFSYM, A_DEFSYM, 0); + class_addbang(tab_integrate_class, tab_integrate_bang); + class_addfloat(tab_integrate_class, tab_integrate_float); + class_addmethod(tab_integrate_class, (t_method)tab_integrate_src1, gensym("src1"), A_DEFSYM, 0); + class_addmethod(tab_integrate_class, (t_method)tab_integrate_dst, gensym("dst"), A_DEFSYM, 0); +} + -- cgit v1.2.1