aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Henry <nusmuk@users.sourceforge.net>2015-01-19 18:42:40 +0000
committerCyrille Henry <nusmuk@users.sourceforge.net>2015-01-19 18:42:40 +0000
commitfa165552bc09dd56a5ab7c037303b241a8223f46 (patch)
treef3d7e49bced9c36a646b9530f59c798fa779706e
parent3d002b8a19990b771d94de9ad4cb10b81acafa92 (diff)
1st draft of iem_tab style externals dedicated for upsampling and downsampling a table
svn path=/trunk/externals/nusmuk/; revision=17415
-rw-r--r--nusmuk-utils/Makefile2
-rw-r--r--nusmuk-utils/tab_downsample-help.pd20
-rw-r--r--nusmuk-utils/tab_downsample.c95
-rw-r--r--nusmuk-utils/tab_downsample_average-help.pd18
-rw-r--r--nusmuk-utils/tab_downsample_average.c89
-rw-r--r--nusmuk-utils/tab_downsample_max-help.pd18
-rw-r--r--nusmuk-utils/tab_downsample_max.c91
-rw-r--r--nusmuk-utils/tab_downsample_min-help.pd18
-rw-r--r--nusmuk-utils/tab_downsample_min.c91
-rw-r--r--nusmuk-utils/tab_upsample-help.pd20
-rw-r--r--nusmuk-utils/tab_upsample.c95
-rw-r--r--nusmuk-utils/tab_upsample_copy-help.pd20
-rw-r--r--nusmuk-utils/tab_upsample_copy.c93
13 files changed, 669 insertions, 1 deletions
diff --git a/nusmuk-utils/Makefile b/nusmuk-utils/Makefile
index 1a8f821..e109765 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
+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
# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will
# be included automatically
diff --git a/nusmuk-utils/tab_downsample-help.pd b/nusmuk-utils/tab_downsample-help.pd
new file mode 100644
index 0000000..c57106f
--- /dev/null
+++ b/nusmuk-utils/tab_downsample-help.pd
@@ -0,0 +1,20 @@
+#N canvas 102 636 777 410 10;
+#X obj 97 73 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 55 table src2 1000;
+#X msg 139 91 src src2;
+#X msg 152 140 dst dst2;
+#X msg 182 177 factor 2;
+#X obj 85 248 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 105 table dst2 300;
+#X obj 410 33 table src 10;
+#X obj 411 85 table dst 3;
+#X obj 87 205 tab_downsample src dst 3;
+#X msg 236 125 3;
+#X connect 0 0 9 0;
+#X connect 2 0 9 0;
+#X connect 3 0 9 0;
+#X connect 4 0 9 0;
+#X connect 9 0 5 0;
+#X connect 10 0 9 0;
diff --git a/nusmuk-utils/tab_downsample.c b/nusmuk-utils/tab_downsample.c
new file mode 100644
index 0000000..b94c458
--- /dev/null
+++ b/nusmuk-utils/tab_downsample.c
@@ -0,0 +1,95 @@
+#include "m_pd.h"
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+static t_class *tab_downsample_class;
+
+typedef struct _tab_downsample {
+ t_object x_obj;
+ t_symbol *x_arrayname_src;
+ t_symbol *x_arrayname_dst;
+ int factor, offset;
+ t_outlet *b_out;
+} t_tab_downsample;
+
+void *tab_downsample_new(t_symbol *s_src,t_symbol *s_dst, t_float factor)
+{
+ t_tab_downsample *x = (t_tab_downsample *)pd_new(tab_downsample_class);
+
+ x->x_arrayname_src = s_src;
+ x->x_arrayname_dst = s_dst;
+ x->factor = factor;
+ x->offset = 0;
+
+ x->b_out = outlet_new(&x->x_obj, &s_bang);
+
+ return (void *)x;
+}
+
+void tab_downsample_compute(t_tab_downsample *x)
+{
+
+ t_garray *a_src, *a_dst;
+ int npoints_src, npoints_dst;
+ t_word *vec_src, *vec_dst;
+
+ int nb_max, i, index_src;
+
+ if (!(a_src = (t_garray *)pd_findbyclass(x->x_arrayname_src, garray_class)))
+ pd_error(x, "%s: no such array", x->x_arrayname_src->s_name);
+ else if (!garray_getfloatwords(a_src, &npoints_src, &vec_src))
+ pd_error(x, "%s: bad template for tab_downsample", x->x_arrayname_src->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_downsample", x->x_arrayname_dst->s_name);
+ else
+ {
+ nb_max = MIN((npoints_src - x->offset)/x->factor, npoints_dst);
+
+ // post("nb_max = %d",nb_max);
+ index_src = x->offset;
+ for (i=0; i<nb_max;i++) {
+ vec_dst[i].w_float = vec_src[index_src].w_float;
+ index_src += x->factor;
+ }
+ garray_redraw(a_dst);
+ }
+ outlet_bang(x->b_out);
+}
+
+ void tab_downsample_bang(t_tab_downsample *x)
+{
+ x->offset = 0;
+ tab_downsample_compute(x) ;
+}
+
+void tab_downsample_float(t_tab_downsample *x, t_float offset)
+{
+ x->offset = offset;
+ tab_downsample_compute(x) ;
+}
+
+void tab_downsample_src(t_tab_downsample *x, t_symbol *s_src) {
+ x->x_arrayname_src = s_src;
+}
+
+void tab_downsample_dst(t_tab_downsample *x, t_symbol *s_dst) {
+ x->x_arrayname_dst = s_dst;
+}
+
+void tab_downsample_factor(t_tab_downsample *x, t_float factor) {
+ x->factor = factor;
+}
+
+void tab_downsample_setup(void) {
+ tab_downsample_class = class_new(gensym("tab_downsample"), (t_newmethod)tab_downsample_new,
+ 0, sizeof(t_tab_downsample), CLASS_DEFAULT, A_DEFSYM, A_DEFSYM, A_DEFFLOAT, 0);
+ class_addbang(tab_downsample_class, tab_downsample_bang);
+ class_addmethod(tab_downsample_class, (t_method)tab_downsample_src, gensym("src"), A_DEFSYM, 0);
+ class_addmethod(tab_downsample_class, (t_method)tab_downsample_dst, gensym("dst"), A_DEFSYM, 0);
+ class_addmethod(tab_downsample_class, (t_method)tab_downsample_factor, gensym("factor"), A_DEFFLOAT, 0);
+ class_addfloat(tab_downsample_class, (t_method)tab_downsample_float);
+}
+
diff --git a/nusmuk-utils/tab_downsample_average-help.pd b/nusmuk-utils/tab_downsample_average-help.pd
new file mode 100644
index 0000000..8f4d2e3
--- /dev/null
+++ b/nusmuk-utils/tab_downsample_average-help.pd
@@ -0,0 +1,18 @@
+#N canvas 102 636 777 410 10;
+#X obj 97 73 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 55 table src2 1000;
+#X msg 139 91 src src2;
+#X msg 152 140 dst dst2;
+#X msg 182 177 factor 2;
+#X obj 85 248 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 105 table dst2 300;
+#X obj 87 206 tab_downsample_average src dst 3;
+#X obj 410 33 table src 10;
+#X obj 411 85 table dst 3;
+#X connect 0 0 7 0;
+#X connect 2 0 7 0;
+#X connect 3 0 7 0;
+#X connect 4 0 7 0;
+#X connect 7 0 5 0;
diff --git a/nusmuk-utils/tab_downsample_average.c b/nusmuk-utils/tab_downsample_average.c
new file mode 100644
index 0000000..610b6dd
--- /dev/null
+++ b/nusmuk-utils/tab_downsample_average.c
@@ -0,0 +1,89 @@
+#include "m_pd.h"
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+static t_class *tab_downsample_average_class;
+
+typedef struct _tab_downsample_average {
+ t_object x_obj;
+ t_symbol *x_arrayname_src;
+ t_symbol *x_arrayname_dst;
+ int factor;
+ t_outlet *b_out;
+} t_tab_downsample_average;
+
+void *tab_downsample_average_new(t_symbol *s_src,t_symbol *s_dst, t_float factor)
+{
+ t_tab_downsample_average *x = (t_tab_downsample_average *)pd_new(tab_downsample_average_class);
+
+ x->x_arrayname_src = s_src;
+ x->x_arrayname_dst = s_dst;
+ x->factor = factor;
+
+ x->b_out = outlet_new(&x->x_obj, &s_bang);
+
+ return (void *)x;
+}
+
+void tab_downsample_average_bang(t_tab_downsample_average *x)
+{
+
+ t_garray *a_src, *a_dst;
+ int npoints_src, npoints_dst;
+ t_word *vec_src, *vec_dst;
+
+ int nb_max, i, j, index_src;
+ t_float tmp;
+
+ if (!(a_src = (t_garray *)pd_findbyclass(x->x_arrayname_src, garray_class)))
+ pd_error(x, "%s: no such array", x->x_arrayname_src->s_name);
+ else if (!garray_getfloatwords(a_src, &npoints_src, &vec_src))
+ pd_error(x, "%s: bad template for tab_downsample", x->x_arrayname_src->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_downsample", x->x_arrayname_dst->s_name);
+ else
+ {
+ nb_max = MIN(npoints_src/x->factor, npoints_dst);
+
+ // post("nb_max = %d",nb_max);
+ index_src = 0;
+ for (i=0; i<nb_max;i++) {
+ tmp=0;
+ for (j=0; j<x->factor;j++) {
+ tmp += vec_src[index_src].w_float;
+ // post("read : %d, %f",index_src, vec_src[index_src].w_float);
+ // post("tmp : %f",tmp);
+ index_src++;
+ }
+ vec_dst[i].w_float = tmp / x->factor;
+ // post("write : %d, %f",i, tmp);
+ }
+ garray_redraw(a_dst);
+ }
+ outlet_bang(x->b_out);
+}
+
+void tab_downsample_average_src(t_tab_downsample_average *x, t_symbol *s_src) {
+ x->x_arrayname_src = s_src;
+}
+
+void tab_downsample_average_dst(t_tab_downsample_average *x, t_symbol *s_dst) {
+ x->x_arrayname_dst = s_dst;
+}
+
+void tab_downsample_average_factor(t_tab_downsample_average *x, t_float factor) {
+ x->factor = factor;
+}
+
+void tab_downsample_average_setup(void) {
+ tab_downsample_average_class = class_new(gensym("tab_downsample_average"), (t_newmethod)tab_downsample_average_new,
+ 0, sizeof(t_tab_downsample_average), CLASS_DEFAULT, A_DEFSYM, A_DEFSYM, A_DEFFLOAT, 0);
+ class_addbang(tab_downsample_average_class, tab_downsample_average_bang);
+ class_addmethod(tab_downsample_average_class, (t_method)tab_downsample_average_src, gensym("src"), A_DEFSYM, 0);
+ class_addmethod(tab_downsample_average_class, (t_method)tab_downsample_average_dst, gensym("dst"), A_DEFSYM, 0);
+ class_addmethod(tab_downsample_average_class, (t_method)tab_downsample_average_factor, gensym("factor"), A_DEFFLOAT, 0);
+}
+
diff --git a/nusmuk-utils/tab_downsample_max-help.pd b/nusmuk-utils/tab_downsample_max-help.pd
new file mode 100644
index 0000000..b824fcb
--- /dev/null
+++ b/nusmuk-utils/tab_downsample_max-help.pd
@@ -0,0 +1,18 @@
+#N canvas 108 621 777 410 10;
+#X obj 87 206 tab_downsample_max src dst 3;
+#X obj 97 73 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 85 table dst 300;
+#X obj 410 33 table src 1000;
+#X obj 411 55 table src2 1000;
+#X msg 139 91 src src2;
+#X msg 152 140 dst dst2;
+#X msg 182 177 factor 2;
+#X obj 85 248 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 105 table dst2 300;
+#X connect 0 0 8 0;
+#X connect 1 0 0 0;
+#X connect 5 0 0 0;
+#X connect 6 0 0 0;
+#X connect 7 0 0 0;
diff --git a/nusmuk-utils/tab_downsample_max.c b/nusmuk-utils/tab_downsample_max.c
new file mode 100644
index 0000000..63766b7
--- /dev/null
+++ b/nusmuk-utils/tab_downsample_max.c
@@ -0,0 +1,91 @@
+#include "m_pd.h"
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+static t_class *tab_downsample_max_class;
+
+typedef struct _tab_downsample_max {
+ t_object x_obj;
+ t_symbol *x_arrayname_src;
+ t_symbol *x_arrayname_dst;
+ int factor;
+ t_outlet *b_out;
+} t_tab_downsample_max;
+
+void *tab_downsample_max_new(t_symbol *s_src,t_symbol *s_dst, t_float factor)
+{
+ t_tab_downsample_max *x = (t_tab_downsample_max *)pd_new(tab_downsample_max_class);
+
+ x->x_arrayname_src = s_src;
+ x->x_arrayname_dst = s_dst;
+ x->factor = factor;
+
+ x->b_out = outlet_new(&x->x_obj, &s_bang);
+
+ return (void *)x;
+}
+
+void tab_downsample_max_bang(t_tab_downsample_max *x)
+{
+
+ t_garray *a_src, *a_dst;
+ int npoints_src, npoints_dst;
+ t_word *vec_src, *vec_dst;
+
+ int nb_max, i, j, index_src;
+ t_float tmp;
+
+ if (!(a_src = (t_garray *)pd_findbyclass(x->x_arrayname_src, garray_class)))
+ pd_error(x, "%s: no such array", x->x_arrayname_src->s_name);
+ else if (!garray_getfloatwords(a_src, &npoints_src, &vec_src))
+ pd_error(x, "%s: bad template for tab_downsample", x->x_arrayname_src->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_downsample", x->x_arrayname_dst->s_name);
+ else
+ {
+ nb_max = MIN(npoints_src/x->factor, npoints_dst);
+
+ // post("nb_max = %d",nb_max);
+ index_src = 0;
+ for (i=0; i<nb_max;i++) {
+ tmp = vec_src[index_src].w_float;
+ // post("read : %d, %f",index_src, vec_src[index_src].w_float);
+ index_src++;
+ for (j=1; j<x->factor;j++) {
+ tmp = MAX(tmp, vec_src[index_src].w_float);
+ // post("read : %d, %f",index_src, vec_src[index_src].w_float);
+ // post("tmp : %f",tmp);
+ index_src++;
+ }
+ vec_dst[i].w_float = tmp;
+ // post("write : %d, %f",i, tmp);
+ }
+ garray_redraw(a_dst);
+ }
+ outlet_bang(x->b_out);
+}
+
+void tab_downsample_max_src(t_tab_downsample_max *x, t_symbol *s_src) {
+ x->x_arrayname_src = s_src;
+}
+
+void tab_downsample_max_dst(t_tab_downsample_max *x, t_symbol *s_dst) {
+ x->x_arrayname_dst = s_dst;
+}
+
+void tab_downsample_max_factor(t_tab_downsample_max *x, t_float factor) {
+ x->factor = factor;
+}
+
+void tab_downsample_max_setup(void) {
+ tab_downsample_max_class = class_new(gensym("tab_downsample_max"), (t_newmethod)tab_downsample_max_new,
+ 0, sizeof(t_tab_downsample_max), CLASS_DEFAULT, A_DEFSYM, A_DEFSYM, A_DEFFLOAT, 0);
+ class_addbang(tab_downsample_max_class, tab_downsample_max_bang);
+ class_addmethod(tab_downsample_max_class, (t_method)tab_downsample_max_src, gensym("src"), A_DEFSYM, 0);
+ class_addmethod(tab_downsample_max_class, (t_method)tab_downsample_max_dst, gensym("dst"), A_DEFSYM, 0);
+ class_addmethod(tab_downsample_max_class, (t_method)tab_downsample_max_factor, gensym("factor"), A_DEFFLOAT, 0);
+}
+
diff --git a/nusmuk-utils/tab_downsample_min-help.pd b/nusmuk-utils/tab_downsample_min-help.pd
new file mode 100644
index 0000000..8f9381d
--- /dev/null
+++ b/nusmuk-utils/tab_downsample_min-help.pd
@@ -0,0 +1,18 @@
+#N canvas 106 626 777 410 10;
+#X obj 97 73 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 85 table dst 300;
+#X obj 410 33 table src 1000;
+#X obj 411 55 table src2 1000;
+#X msg 139 91 src src2;
+#X msg 152 140 dst dst2;
+#X msg 182 177 factor 2;
+#X obj 85 248 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 105 table dst2 300;
+#X obj 87 206 tab_downsample_min src dst 3;
+#X connect 0 0 9 0;
+#X connect 4 0 9 0;
+#X connect 5 0 9 0;
+#X connect 6 0 9 0;
+#X connect 9 0 7 0;
diff --git a/nusmuk-utils/tab_downsample_min.c b/nusmuk-utils/tab_downsample_min.c
new file mode 100644
index 0000000..36f2e7f
--- /dev/null
+++ b/nusmuk-utils/tab_downsample_min.c
@@ -0,0 +1,91 @@
+#include "m_pd.h"
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+static t_class *tab_downsample_min_class;
+
+typedef struct _tab_downsample_min {
+ t_object x_obj;
+ t_symbol *x_arrayname_src;
+ t_symbol *x_arrayname_dst;
+ int factor;
+ t_outlet *b_out;
+} t_tab_downsample_min;
+
+void *tab_downsample_min_new(t_symbol *s_src,t_symbol *s_dst, t_float factor)
+{
+ t_tab_downsample_min *x = (t_tab_downsample_min *)pd_new(tab_downsample_min_class);
+
+ x->x_arrayname_src = s_src;
+ x->x_arrayname_dst = s_dst;
+ x->factor = factor;
+
+ x->b_out = outlet_new(&x->x_obj, &s_bang);
+
+ return (void *)x;
+}
+
+void tab_downsample_min_bang(t_tab_downsample_min *x)
+{
+
+ t_garray *a_src, *a_dst;
+ int npoints_src, npoints_dst;
+ t_word *vec_src, *vec_dst;
+
+ int nb_max, i, j, index_src;
+ t_float tmp;
+
+ if (!(a_src = (t_garray *)pd_findbyclass(x->x_arrayname_src, garray_class)))
+ pd_error(x, "%s: no such array", x->x_arrayname_src->s_name);
+ else if (!garray_getfloatwords(a_src, &npoints_src, &vec_src))
+ pd_error(x, "%s: bad template for tab_downsample", x->x_arrayname_src->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_downsample", x->x_arrayname_dst->s_name);
+ else
+ {
+ nb_max = MIN(npoints_src/x->factor, npoints_dst);
+
+ // post("nb_max = %d",nb_max);
+ index_src = 0;
+ for (i=0; i<nb_max;i++) {
+ tmp = vec_src[index_src].w_float;
+ // post("read : %d, %f",index_src, vec_src[index_src].w_float);
+ index_src++;
+ for (j=1; j<x->factor;j++) {
+ tmp = MIN(tmp, vec_src[index_src].w_float);
+ // post("read : %d, %f",index_src, vec_src[index_src].w_float);
+ // post("tmp : %f",tmp);
+ index_src++;
+ }
+ vec_dst[i].w_float = tmp;
+ // post("write : %d, %f",i, tmp);
+ }
+ garray_redraw(a_dst);
+ }
+ outlet_bang(x->b_out);
+}
+
+void tab_downsample_min_src(t_tab_downsample_min *x, t_symbol *s_src) {
+ x->x_arrayname_src = s_src;
+}
+
+void tab_downsample_min_dst(t_tab_downsample_min *x, t_symbol *s_dst) {
+ x->x_arrayname_dst = s_dst;
+}
+
+void tab_downsample_min_factor(t_tab_downsample_min *x, t_float factor) {
+ x->factor = factor;
+}
+
+void tab_downsample_min_setup(void) {
+ tab_downsample_min_class = class_new(gensym("tab_downsample_min"), (t_newmethod)tab_downsample_min_new,
+ 0, sizeof(t_tab_downsample_min), CLASS_DEFAULT, A_DEFSYM, A_DEFSYM, A_DEFFLOAT, 0);
+ class_addbang(tab_downsample_min_class, tab_downsample_min_bang);
+ class_addmethod(tab_downsample_min_class, (t_method)tab_downsample_min_src, gensym("src"), A_DEFSYM, 0);
+ class_addmethod(tab_downsample_min_class, (t_method)tab_downsample_min_dst, gensym("dst"), A_DEFSYM, 0);
+ class_addmethod(tab_downsample_min_class, (t_method)tab_downsample_min_factor, gensym("factor"), A_DEFFLOAT, 0);
+}
+
diff --git a/nusmuk-utils/tab_upsample-help.pd b/nusmuk-utils/tab_upsample-help.pd
new file mode 100644
index 0000000..6e11040
--- /dev/null
+++ b/nusmuk-utils/tab_upsample-help.pd
@@ -0,0 +1,20 @@
+#N canvas 98 645 777 410 10;
+#X obj 97 73 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 55 table src2 1000;
+#X msg 139 91 src src2;
+#X msg 152 140 dst dst2;
+#X obj 85 248 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 105 table dst2 300;
+#X obj 410 33 table src 10;
+#X obj 411 85 table dst 50;
+#X obj 87 205 tab_upsample src dst 3;
+#X msg 182 177 factor 5;
+#X msg 237 125 1;
+#X connect 0 0 8 0;
+#X connect 2 0 8 0;
+#X connect 3 0 8 0;
+#X connect 8 0 4 0;
+#X connect 9 0 8 0;
+#X connect 10 0 8 0;
diff --git a/nusmuk-utils/tab_upsample.c b/nusmuk-utils/tab_upsample.c
new file mode 100644
index 0000000..36d2188
--- /dev/null
+++ b/nusmuk-utils/tab_upsample.c
@@ -0,0 +1,95 @@
+#include "m_pd.h"
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+static t_class *tab_upsample_class;
+
+typedef struct _tab_upsample {
+ t_object x_obj;
+ t_symbol *x_arrayname_src;
+ t_symbol *x_arrayname_dst;
+ int factor, offset;
+ t_outlet *b_out;
+} t_tab_upsample;
+
+void *tab_upsample_new(t_symbol *s_src,t_symbol *s_dst, t_float factor)
+{
+ t_tab_upsample *x = (t_tab_upsample *)pd_new(tab_upsample_class);
+
+ x->x_arrayname_src = s_src;
+ x->x_arrayname_dst = s_dst;
+ x->factor = factor;
+ x->offset = 0;
+
+ x->b_out = outlet_new(&x->x_obj, &s_bang);
+
+ return (void *)x;
+}
+
+void tab_upsample_compute(t_tab_upsample *x)
+{
+
+ t_garray *a_src, *a_dst;
+ int npoints_src, npoints_dst;
+ t_word *vec_src, *vec_dst;
+
+ int nb_max, i, index_dst;
+
+ if (!(a_src = (t_garray *)pd_findbyclass(x->x_arrayname_src, garray_class)))
+ pd_error(x, "%s: no such array", x->x_arrayname_src->s_name);
+ else if (!garray_getfloatwords(a_src, &npoints_src, &vec_src))
+ pd_error(x, "%s: bad template for tab_upsample", x->x_arrayname_src->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_upsample", x->x_arrayname_dst->s_name);
+ else
+ {
+ nb_max = MIN(npoints_src, 1+(npoints_dst - x->offset - 1)/x->factor);
+
+ // post("nb_max = %d",nb_max);
+ index_dst = x->offset;
+ for (i=0; i<nb_max;i++) {
+ vec_dst[index_dst].w_float = vec_src[i].w_float;
+ index_dst += x->factor;
+ }
+ garray_redraw(a_dst);
+ }
+ outlet_bang(x->b_out);
+}
+
+ void tab_upsample_bang(t_tab_upsample *x)
+{
+ x->offset = 0;
+ tab_upsample_compute(x) ;
+}
+
+void tab_upsample_float(t_tab_upsample *x, t_float offset)
+{
+ x->offset = offset;
+ tab_upsample_compute(x) ;
+}
+
+void tab_upsample_src(t_tab_upsample *x, t_symbol *s_src) {
+ x->x_arrayname_src = s_src;
+}
+
+void tab_upsample_dst(t_tab_upsample *x, t_symbol *s_dst) {
+ x->x_arrayname_dst = s_dst;
+}
+
+void tab_upsample_factor(t_tab_upsample *x, t_float factor) {
+ x->factor = factor;
+}
+
+void tab_upsample_setup(void) {
+ tab_upsample_class = class_new(gensym("tab_upsample"), (t_newmethod)tab_upsample_new,
+ 0, sizeof(t_tab_upsample), CLASS_DEFAULT, A_DEFSYM, A_DEFSYM, A_DEFFLOAT, 0);
+ class_addbang(tab_upsample_class, tab_upsample_bang);
+ class_addmethod(tab_upsample_class, (t_method)tab_upsample_src, gensym("src"), A_DEFSYM, 0);
+ class_addmethod(tab_upsample_class, (t_method)tab_upsample_dst, gensym("dst"), A_DEFSYM, 0);
+ class_addmethod(tab_upsample_class, (t_method)tab_upsample_factor, gensym("factor"), A_DEFFLOAT, 0);
+ class_addfloat(tab_upsample_class, (t_method)tab_upsample_float);
+}
+
diff --git a/nusmuk-utils/tab_upsample_copy-help.pd b/nusmuk-utils/tab_upsample_copy-help.pd
new file mode 100644
index 0000000..c97ed25
--- /dev/null
+++ b/nusmuk-utils/tab_upsample_copy-help.pd
@@ -0,0 +1,20 @@
+#N canvas 96 645 777 410 10;
+#X obj 97 73 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 55 table src2 1000;
+#X msg 139 91 src src2;
+#X msg 152 140 dst dst2;
+#X obj 85 248 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 411 105 table dst2 300;
+#X obj 410 33 table src 10;
+#X obj 411 85 table dst 50;
+#X msg 182 177 factor 5;
+#X msg 237 125 1;
+#X obj 87 205 tab_upsample_copy src dst 3;
+#X connect 0 0 10 0;
+#X connect 2 0 10 0;
+#X connect 3 0 10 0;
+#X connect 8 0 10 0;
+#X connect 9 0 10 0;
+#X connect 10 0 4 0;
diff --git a/nusmuk-utils/tab_upsample_copy.c b/nusmuk-utils/tab_upsample_copy.c
new file mode 100644
index 0000000..5b5687b
--- /dev/null
+++ b/nusmuk-utils/tab_upsample_copy.c
@@ -0,0 +1,93 @@
+#include "m_pd.h"
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+static t_class *tab_upsample_copy_class;
+
+typedef struct _tab_upsample_copy {
+ t_object x_obj;
+ t_symbol *x_arrayname_src;
+ t_symbol *x_arrayname_dst;
+ int factor, offset;
+ t_outlet *b_out;
+} t_tab_upsample_copy;
+
+void *tab_upsample_copy_new(t_symbol *s_src,t_symbol *s_dst, t_float factor)
+{
+ t_tab_upsample_copy *x = (t_tab_upsample_copy *)pd_new(tab_upsample_copy_class);
+
+ x->x_arrayname_src = s_src;
+ x->x_arrayname_dst = s_dst;
+ x->factor = factor;
+ x->offset = 0;
+
+ x->b_out = outlet_new(&x->x_obj, &s_bang);
+
+ return (void *)x;
+}
+
+void tab_upsample_copy_compute(t_tab_upsample_copy *x)
+{
+
+ t_garray *a_src, *a_dst;
+ int npoints_src, npoints_dst;
+ t_word *vec_src, *vec_dst;
+
+ int nb_max, i, j;
+
+ if (!(a_src = (t_garray *)pd_findbyclass(x->x_arrayname_src, garray_class)))
+ pd_error(x, "%s: no such array", x->x_arrayname_src->s_name);
+ else if (!garray_getfloatwords(a_src, &npoints_src, &vec_src))
+ pd_error(x, "%s: bad template for tab_upsample_copy", x->x_arrayname_src->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_upsample_copy", x->x_arrayname_dst->s_name);
+ else
+ {
+ nb_max = MIN(npoints_src*x->factor, npoints_dst-x->offset);
+
+ // post("nb_max = %d",nb_max);
+ for (i=0; i<nb_max;i++) {
+ vec_dst[i+x->offset].w_float = vec_src[i/x->factor].w_float;
+ }
+ garray_redraw(a_dst);
+ }
+ outlet_bang(x->b_out);
+}
+
+ void tab_upsample_copy_bang(t_tab_upsample_copy *x)
+{
+ x->offset = 0;
+ tab_upsample_copy_compute(x) ;
+}
+
+void tab_upsample_copy_float(t_tab_upsample_copy *x, t_float offset)
+{
+ x->offset = offset;
+ tab_upsample_copy_compute(x) ;
+}
+
+void tab_upsample_copy_src(t_tab_upsample_copy *x, t_symbol *s_src) {
+ x->x_arrayname_src = s_src;
+}
+
+void tab_upsample_copy_dst(t_tab_upsample_copy *x, t_symbol *s_dst) {
+ x->x_arrayname_dst = s_dst;
+}
+
+void tab_upsample_copy_factor(t_tab_upsample_copy *x, t_float factor) {
+ x->factor = factor;
+}
+
+void tab_upsample_copy_setup(void) {
+ tab_upsample_copy_class = class_new(gensym("tab_upsample_copy"), (t_newmethod)tab_upsample_copy_new,
+ 0, sizeof(t_tab_upsample_copy), CLASS_DEFAULT, A_DEFSYM, A_DEFSYM, A_DEFFLOAT, 0);
+ class_addbang(tab_upsample_copy_class, tab_upsample_copy_bang);
+ class_addmethod(tab_upsample_copy_class, (t_method)tab_upsample_copy_src, gensym("src"), A_DEFSYM, 0);
+ class_addmethod(tab_upsample_copy_class, (t_method)tab_upsample_copy_dst, gensym("dst"), A_DEFSYM, 0);
+ class_addmethod(tab_upsample_copy_class, (t_method)tab_upsample_copy_factor, gensym("factor"), A_DEFFLOAT, 0);
+ class_addfloat(tab_upsample_copy_class, (t_method)tab_upsample_copy_float);
+}
+