diff options
Diffstat (limited to 'nusmuk-utils')
-rw-r--r-- | nusmuk-utils/Makefile | 2 | ||||
-rw-r--r-- | nusmuk-utils/tab_max-help.pd | 84 | ||||
-rw-r--r-- | nusmuk-utils/tab_max.c | 117 | ||||
-rw-r--r-- | nusmuk-utils/tab_min-help.pd | 84 | ||||
-rw-r--r-- | nusmuk-utils/tab_min.c | 117 |
5 files changed, 403 insertions, 1 deletions
diff --git a/nusmuk-utils/Makefile b/nusmuk-utils/Makefile index e109765..c38a97f 100644 --- a/nusmuk-utils/Makefile +++ b/nusmuk-utils/Makefile @@ -5,7 +5,7 @@ LIBRARY_NAME = nusmuk-utils # add your .c source files, one object per file, to the SOURCES # variable, help files will be included automatically -SOURCES = line3.c pbank.c mtx_preset.c tab_downsample_max.c tab_downsample_min.c tab_downsample_average.c tab_downsample.c tab_upsample.c tab_upsample_copy.c +SOURCES = line3.c pbank.c mtx_preset.c tab_downsample_max.c tab_downsample_min.c tab_downsample_average.c tab_downsample.c tab_upsample.c tab_upsample_copy.c tab_max.c tab_min.c # list all pd objects (i.e. myobject.pd) files here, and their helpfiles will # be included automatically diff --git a/nusmuk-utils/tab_max-help.pd b/nusmuk-utils/tab_max-help.pd new file mode 100644 index 0000000..b35a72d --- /dev/null +++ b/nusmuk-utils/tab_max-help.pd @@ -0,0 +1,84 @@ +#N canvas 112 102 859 564 10; +#N canvas 0 50 450 300 (subpatch) 0; +#X array src1 100 float 1; +#A 0 -0.442858 -0.414287 -0.385715 -0.342858 -0.314287 -0.257144 -0.128572 +-0.0428573 0.128572 0.228572 0.285715 0.328572 0.400001 0.414287 0.457144 +0.457144 0.442858 0.385715 0.314287 0.257144 0.214286 0.1 0.0428572 +-0.0142858 -0.0428573 -0.114286 -0.142858 -0.200001 -0.242858 -0.285715 +-0.328572 -0.342858 -0.37143 -0.385715 -0.414287 -0.414287 -0.414287 +-0.414287 -0.400001 -0.357144 -0.314287 -0.257144 -0.185715 -0.0714288 +0.0142857 0.0571429 0.171429 0.328572 0.400001 0.442858 0.47143 0.485715 +0.485715 0.485715 0.485715 0.485715 0.442858 0.357144 0.242858 0.185715 +0.114286 0.0714285 -0.071429 -0.242858 -0.300001 -0.328573 -0.357144 +-0.37143 -0.385715 -0.400001 -0.442858 -0.457144 -0.47143 -0.457144 +-0.428573 -0.400001 -0.378573 -0.328572 -0.271429 -0.242858 -0.200001 +-0.128572 -0.0428574 -0.0285717 0.0142858 0.114286 0.128572 0.185715 +0.214286 0.257144 0.285715 0.314287 0.342858 0.357144 0.357144 0.357144 +0.357144 0.357144 0.342858 0.328572; +#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 535 358 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 59 340 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 255 276 dst dst; +#N canvas 0 50 450 300 (subpatch) 0; +#X array src2 100 float 1; +#A 0 -0.471423 -0.714277 -0.685706 -0.657135 -0.614278 -0.557136 -0.471423 +-0.428566 -0.342853 -0.299996 -0.242854 -0.185712 -0.128569 -0.071427 +-0.0499987 -0.0285704 0.0428575 0.0714286 0.357136 0.399993 0.44285 +0.457135 0.485706 0.514278 0.542849 0.557134 0.557134 0.542849 0.471421 +0.428564 0.385707 0.31428 0.285709 0.257137 0.18571 0.149996 0.114282 +0.0571395 -2.74181e-06 -0.0428594 -0.142858 -0.228572 -0.271428 -0.328571 +-0.357142 -0.385713 -0.342856 -0.3 -0.242857 -0.214286 -0.185715 -0.128573 +-0.0714306 -2.74181e-06 0.042854 0.0999962 0.142853 0.257137 0.31428 +0.371422 0.414279 0.514278 0.557134 0.628562 0.657133 0.685704 0.657133 +0.599991 0.542849 0.457135 0.371422 0.214281 0.157138 0.0857106 -0.057145 +-0.17143 -0.228572 -0.328571 -0.385713 -0.442855 -0.471426 -0.499997 +-0.514283 -0.542854 -0.55714 -0.571425 -0.585711 -0.585711 -0.571425 +-0.564283 -0.55714 -0.528569 -0.50714 -0.485712 -0.471426 -0.457141 +-0.414284 -0.399999 -0.385713 -0.0428594; +#X coords 0 1 99 -1 200 140 1; +#X restore 535 161 graph; +#X msg 136 233 src1 src1; +#X msg 195 255 src2 src2; +#X msg 59 211 50 50 20 50; +#X text 45 139 list of 4 floats:; +#X text 212 353 3.arg: <symbol> destination-name; +#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 234 312 initial arguments:; +#X text 72 319 <bang> output; +#X text 306 275 <dst> xxx : change destination name; +#X text 225 86 the minimum of the 3 array lengths); +#X text 56 177 3.) dst onset; +#X text 56 155 1.) src_1 onset; +#X text 56 166 2.) src_2 onset; +#X text 56 187 4.) n samples to add; +#X text 199 233 <src1> xxx : change source name 1; +#X text 257 255 <src2> xxx : change source name 2; +#X text 211 326 1.arg: <symbol> source-name 1; +#X text 211 339 2.arg: <symbol> source-name 2; +#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 <bang> max the 2 src-arrays to dst-array; +#X obj 61 78 tab_max src1 src2 dst; +#X text 54 420 ch \, help file based on :; +#X obj 59 301 tab_max src1 src2 dst; +#X connect 2 0 33 0; +#X connect 5 0 35 0; +#X connect 7 0 35 0; +#X connect 8 0 35 0; +#X connect 9 0 35 0; +#X connect 33 0 3 0; +#X connect 35 0 4 0; diff --git a/nusmuk-utils/tab_max.c b/nusmuk-utils/tab_max.c new file mode 100644 index 0000000..5789261 --- /dev/null +++ b/nusmuk-utils/tab_max.c @@ -0,0 +1,117 @@ +#include "m_pd.h" + +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) + +static t_class *tab_max_class; + +typedef struct _tab_max { + t_object x_obj; + t_symbol *x_arrayname_src1; + t_symbol *x_arrayname_src2; + t_symbol *x_arrayname_dst; + int offset_src1, offset_src2, offset_dst, nb_max; + t_outlet *b_out; +} t_tab_max; + +void *tab_max_new(t_symbol *s_src1, t_symbol *s_src2, t_symbol *s_dst) +{ + t_tab_max *x = (t_tab_max *)pd_new(tab_max_class); + + x->x_arrayname_src1 = s_src1; + x->x_arrayname_src2 = s_src2; + x->x_arrayname_dst = s_dst; + x->offset_src1 = 0; + x->offset_src2 = 0; + x->offset_dst = 0; + + x->b_out = outlet_new(&x->x_obj, &s_bang); + + return (void *)x; +} + +void tab_max_compute(t_tab_max *x) +{ + t_garray *a_src1, *a_src2, *a_dst; + int npoints_src1, npoints_src2, npoints_dst; + t_word *vec_src1, *vec_src2, *vec_dst; + + int nb_max, 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_max", x->x_arrayname_src1->s_name); + if (!(a_src2 = (t_garray *)pd_findbyclass(x->x_arrayname_src2, garray_class))) + pd_error(x, "%s: no such array", x->x_arrayname_src2->s_name); + else if (!garray_getfloatwords(a_src2, &npoints_src2, &vec_src2)) + pd_error(x, "%s: bad template for tab_max", x->x_arrayname_src2->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_max", x->x_arrayname_dst->s_name); + else + { + nb_max = MIN(npoints_src1 - x->offset_src1, npoints_src2 - x->offset_src2); + nb_max = MIN(npoints_dst, nb_max); + if (x->nb_max >0) + nb_max = MIN(nb_max, x->nb_max); + post("nb_max = %d",nb_max); + + for (i=0; i<nb_max;i++) { + vec_dst[i + x->offset_dst].w_float = MAX(vec_src1[i + x->offset_src1].w_float, vec_src2[i + x->offset_src2].w_float); + } + garray_redraw(a_dst); + } + outlet_bang(x->b_out); +} + +void tab_max_bang(t_tab_max *x) +{ + x->offset_src1 = 0; + x->offset_src2 = 0; + x->offset_dst = 0; + x->nb_max = -1; + tab_max_compute(x) ; +} + +void tab_max_list(t_tab_max *x, t_symbol *s, int argc, t_atom *argv) +{ + x->offset_src1 = 0; + x->offset_src2 = 0; + x->offset_dst = 0; + x->nb_max = -1; + + if ((argc>=1) && (argv[0].a_type == A_FLOAT)) + x->offset_src1 = atom_getfloatarg(0, argc, argv); + if ((argc>=2) && (argv[1].a_type == A_FLOAT)) + x->offset_src2 = atom_getfloatarg(1, argc, argv); + if ((argc>=3) && (argv[2].a_type == A_FLOAT)) + x->offset_dst = atom_getfloatarg(2, argc, argv); + if ((argc>=4) && (argv[3].a_type == A_FLOAT)) + x->nb_max = atom_getfloatarg(3, argc, argv); + + tab_max_compute(x) ; +} + +void tab_max_src1(t_tab_max *x, t_symbol *s_src) { + x->x_arrayname_src1 = s_src; + +}void tab_max_src2(t_tab_max *x, t_symbol *s_src) { + x->x_arrayname_src2 = s_src; +} + +void tab_max_dst(t_tab_max *x, t_symbol *s_dst) { + x->x_arrayname_dst = s_dst; +} + +void tab_max_setup(void) { + tab_max_class = class_new(gensym("tab_max"), (t_newmethod)tab_max_new, + 0, sizeof(t_tab_max), CLASS_DEFAULT, A_DEFSYM, A_DEFSYM, A_DEFSYM, 0); + class_addbang(tab_max_class, tab_max_bang); + class_addlist(tab_max_class, (t_method)tab_max_list); + class_addmethod(tab_max_class, (t_method)tab_max_src1, gensym("src1"), A_DEFSYM, 0); + class_addmethod(tab_max_class, (t_method)tab_max_src2, gensym("src2"), A_DEFSYM, 0); + class_addmethod(tab_max_class, (t_method)tab_max_dst, gensym("dst"), A_DEFSYM, 0); +} + diff --git a/nusmuk-utils/tab_min-help.pd b/nusmuk-utils/tab_min-help.pd new file mode 100644 index 0000000..ea80c5e --- /dev/null +++ b/nusmuk-utils/tab_min-help.pd @@ -0,0 +1,84 @@ +#N canvas 110 107 859 564 10; +#N canvas 0 50 450 300 (subpatch) 0; +#X array src1 100 float 1; +#A 0 -0.442858 -0.414287 -0.385715 -0.342858 -0.314287 -0.257144 -0.128572 +-0.0428573 0.128572 0.228572 0.285715 0.328572 0.400001 0.414287 0.457144 +0.457144 0.442858 0.385715 0.314287 0.257144 0.214286 0.1 0.0428572 +-0.0142858 -0.0428573 -0.114286 -0.142858 -0.200001 -0.242858 -0.285715 +-0.328572 -0.342858 -0.37143 -0.385715 -0.414287 -0.414287 -0.414287 +-0.414287 -0.400001 -0.357144 -0.314287 -0.257144 -0.185715 -0.0714288 +0.0142857 0.0571429 0.171429 0.328572 0.400001 0.442858 0.47143 0.485715 +0.485715 0.485715 0.485715 0.485715 0.442858 0.357144 0.242858 0.185715 +0.114286 0.0714285 -0.071429 -0.242858 -0.300001 -0.328573 -0.357144 +-0.37143 -0.385715 -0.400001 -0.442858 -0.457144 -0.47143 -0.457144 +-0.428573 -0.400001 -0.378573 -0.328572 -0.271429 -0.242858 -0.200001 +-0.128572 -0.0428574 -0.0285717 0.0142858 0.114286 0.128572 0.185715 +0.214286 0.257144 0.285715 0.314287 0.342858 0.357144 0.357144 0.357144 +0.357144 0.357144 0.342858 0.328572; +#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 535 358 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 59 340 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 255 276 dst dst; +#N canvas 0 50 450 300 (subpatch) 0; +#X array src2 100 float 1; +#A 0 -0.471423 -0.714277 -0.685706 -0.657135 -0.614278 -0.557136 -0.471423 +-0.428566 -0.342853 -0.299996 -0.242854 -0.185712 -0.128569 -0.071427 +-0.0499987 -0.0285704 0.0428575 0.0714286 0.357136 0.399993 0.44285 +0.457135 0.485706 0.514278 0.542849 0.557134 0.557134 0.542849 0.471421 +0.428564 0.385707 0.31428 0.285709 0.257137 0.18571 0.149996 0.114282 +0.0571395 -2.74181e-06 -0.0428594 -0.142858 -0.228572 -0.271428 -0.328571 +-0.357142 -0.385713 -0.342856 -0.3 -0.242857 -0.214286 -0.185715 -0.128573 +-0.0714306 -2.74181e-06 0.042854 0.0999962 0.142853 0.257137 0.31428 +0.371422 0.414279 0.514278 0.557134 0.628562 0.657133 0.685704 0.657133 +0.599991 0.542849 0.457135 0.371422 0.214281 0.157138 0.0857106 -0.057145 +-0.17143 -0.228572 -0.328571 -0.385713 -0.442855 -0.471426 -0.499997 +-0.514283 -0.542854 -0.55714 -0.571425 -0.585711 -0.585711 -0.571425 +-0.564283 -0.55714 -0.528569 -0.50714 -0.485712 -0.471426 -0.457141 +-0.414284 -0.399999 -0.385713 -0.0428594; +#X coords 0 1 99 -1 200 140 1; +#X restore 535 161 graph; +#X msg 136 233 src1 src1; +#X msg 195 255 src2 src2; +#X msg 59 211 50 50 20 50; +#X text 45 139 list of 4 floats:; +#X text 212 353 3.arg: <symbol> destination-name; +#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 234 312 initial arguments:; +#X text 72 319 <bang> output; +#X text 306 275 <dst> xxx : change destination name; +#X text 225 86 the minimum of the 3 array lengths); +#X text 56 177 3.) dst onset; +#X text 56 155 1.) src_1 onset; +#X text 56 166 2.) src_2 onset; +#X text 56 187 4.) n samples to add; +#X text 199 233 <src1> xxx : change source name 1; +#X text 257 255 <src2> xxx : change source name 2; +#X text 211 326 1.arg: <symbol> source-name 1; +#X text 211 339 2.arg: <symbol> source-name 2; +#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 <bang> max the 2 src-arrays to dst-array; +#X text 54 420 ch \, help file based on :; +#X obj 61 78 tab_min src1 src2 dst; +#X obj 59 301 tab_min src1 src2 dst; +#X connect 2 0 34 0; +#X connect 5 0 35 0; +#X connect 7 0 35 0; +#X connect 8 0 35 0; +#X connect 9 0 35 0; +#X connect 34 0 3 0; +#X connect 35 0 4 0; diff --git a/nusmuk-utils/tab_min.c b/nusmuk-utils/tab_min.c new file mode 100644 index 0000000..d1d57bd --- /dev/null +++ b/nusmuk-utils/tab_min.c @@ -0,0 +1,117 @@ +#include "m_pd.h" + +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) + +static t_class *tab_min_class; + +typedef struct _tab_min { + t_object x_obj; + t_symbol *x_arrayname_src1; + t_symbol *x_arrayname_src2; + t_symbol *x_arrayname_dst; + int offset_src1, offset_src2, offset_dst, nb_max; + t_outlet *b_out; +} t_tab_min; + +void *tab_min_new(t_symbol *s_src1, t_symbol *s_src2, t_symbol *s_dst) +{ + t_tab_min *x = (t_tab_min *)pd_new(tab_min_class); + + x->x_arrayname_src1 = s_src1; + x->x_arrayname_src2 = s_src2; + x->x_arrayname_dst = s_dst; + x->offset_src1 = 0; + x->offset_src2 = 0; + x->offset_dst = 0; + + x->b_out = outlet_new(&x->x_obj, &s_bang); + + return (void *)x; +} + +void tab_min_compute(t_tab_min *x) +{ + t_garray *a_src1, *a_src2, *a_dst; + int npoints_src1, npoints_src2, npoints_dst; + t_word *vec_src1, *vec_src2, *vec_dst; + + int nb_max, 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_min", x->x_arrayname_src1->s_name); + if (!(a_src2 = (t_garray *)pd_findbyclass(x->x_arrayname_src2, garray_class))) + pd_error(x, "%s: no such array", x->x_arrayname_src2->s_name); + else if (!garray_getfloatwords(a_src2, &npoints_src2, &vec_src2)) + pd_error(x, "%s: bad template for tab_min", x->x_arrayname_src2->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_min", x->x_arrayname_dst->s_name); + else + { + nb_max = MIN(npoints_src1 - x->offset_src1, npoints_src2 - x->offset_src2); + nb_max = MIN(npoints_dst, nb_max); + if (x->nb_max >0) + nb_max = MIN(nb_max, x->nb_max); + post("nb_max = %d",nb_max); + + for (i=0; i<nb_max;i++) { + vec_dst[i + x->offset_dst].w_float = MIN(vec_src1[i + x->offset_src1].w_float, vec_src2[i + x->offset_src2].w_float); + } + garray_redraw(a_dst); + } + outlet_bang(x->b_out); +} + +void tab_min_bang(t_tab_min *x) +{ + x->offset_src1 = 0; + x->offset_src2 = 0; + x->offset_dst = 0; + x->nb_max = -1; + tab_min_compute(x) ; +} + +void tab_min_list(t_tab_min *x, t_symbol *s, int argc, t_atom *argv) +{ + x->offset_src1 = 0; + x->offset_src2 = 0; + x->offset_dst = 0; + x->nb_max = -1; + + if ((argc>=1) && (argv[0].a_type == A_FLOAT)) + x->offset_src1 = atom_getfloatarg(0, argc, argv); + if ((argc>=2) && (argv[1].a_type == A_FLOAT)) + x->offset_src2 = atom_getfloatarg(1, argc, argv); + if ((argc>=3) && (argv[2].a_type == A_FLOAT)) + x->offset_dst = atom_getfloatarg(2, argc, argv); + if ((argc>=4) && (argv[3].a_type == A_FLOAT)) + x->nb_max = atom_getfloatarg(3, argc, argv); + + tab_min_compute(x) ; +} + +void tab_min_src1(t_tab_min *x, t_symbol *s_src) { + x->x_arrayname_src1 = s_src; + +}void tab_min_src2(t_tab_min *x, t_symbol *s_src) { + x->x_arrayname_src2 = s_src; +} + +void tab_min_dst(t_tab_min *x, t_symbol *s_dst) { + x->x_arrayname_dst = s_dst; +} + +void tab_min_setup(void) { + tab_min_class = class_new(gensym("tab_min"), (t_newmethod)tab_min_new, + 0, sizeof(t_tab_min), CLASS_DEFAULT, A_DEFSYM, A_DEFSYM, A_DEFSYM, 0); + class_addbang(tab_min_class, tab_min_bang); + class_addlist(tab_min_class, (t_method)tab_min_list); + class_addmethod(tab_min_class, (t_method)tab_min_src1, gensym("src1"), A_DEFSYM, 0); + class_addmethod(tab_min_class, (t_method)tab_min_src2, gensym("src2"), A_DEFSYM, 0); + class_addmethod(tab_min_class, (t_method)tab_min_dst, gensym("dst"), A_DEFSYM, 0); +} + |