aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/mtx_unpack~-help.pd35
-rw-r--r--src/mtx_unpack~.c159
2 files changed, 194 insertions, 0 deletions
diff --git a/doc/mtx_unpack~-help.pd b/doc/mtx_unpack~-help.pd
new file mode 100644
index 0000000..593701c
--- /dev/null
+++ b/doc/mtx_unpack~-help.pd
@@ -0,0 +1,35 @@
+#N canvas 682 0 450 300 12;
+#X msg 310 164 \; pd dsp 1;
+#X msg 309 202 \; pd dsp 0;
+#X obj 292 114 mtx_print;
+#X text 43 29 packing signal vectors (usually 64 samples);
+#X text 42 52 of multiple inputs into a matrix;
+#X text 214 268 [iemmatrix];
+#X text 238 248 Franz Zotter \, 2008;
+#X obj 77 162 mtx_unpack~ 3;
+#X obj 47 115 mtx_rand;
+#X obj 47 138 t b a a;
+#X obj 292 87 block~ 8;
+#X msg 47 93 3 8;
+#X obj 5 162 t b b b;
+#X obj 192 220 print~ C;
+#X obj 133 244 print~ B;
+#X obj 77 267 print~ A;
+#X obj 19 96 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 126 115 mtx_ones;
+#X msg 126 93 3 8;
+#X connect 7 0 15 0;
+#X connect 7 1 14 0;
+#X connect 7 2 13 0;
+#X connect 8 0 9 0;
+#X connect 9 0 12 0;
+#X connect 9 1 7 0;
+#X connect 9 2 2 0;
+#X connect 11 0 8 0;
+#X connect 12 0 15 0;
+#X connect 12 1 14 0;
+#X connect 12 2 13 0;
+#X connect 16 0 9 0;
+#X connect 17 0 9 0;
+#X connect 18 0 17 0;
diff --git a/src/mtx_unpack~.c b/src/mtx_unpack~.c
new file mode 100644
index 0000000..5f5c294
--- /dev/null
+++ b/src/mtx_unpack~.c
@@ -0,0 +1,159 @@
+#include "iemmatrix.h"
+#define MTX_PACK_MAXCHANNELS 200
+
+static t_class *mtx_unpack_tilde_class;
+
+typedef struct _mtx_unpack_tilde {
+ t_object x_obj;
+ int rows;
+ int cols;
+ int block_size;
+ int num_chan;
+ t_float **sig_out;
+ t_atom *list_in;
+ t_int *(*perform_fcn)(t_int*);
+} mtx_unpack_tilde;
+
+static t_int *mTxUnPackTildePerform (t_int *arg) {
+ mtx_unpack_tilde *x = (mtx_unpack_tilde *) (arg[1]);
+ return (x->perform_fcn(arg));
+}
+
+
+static t_int *mTxUnPackTildePerformInactive (t_int *arg)
+{
+ return(arg+2);
+}
+
+static t_int *mTxUnPackTildePerformSetInactive (t_int *arg)
+{
+ mtx_unpack_tilde *x = (mtx_unpack_tilde *) (arg[1]);
+ int chan;
+ int samp;
+ t_atom *lptr=x->list_in;
+
+ for (chan=0; chan<x->num_chan; chan++) {
+ for (samp=0; samp<x->block_size; samp++) {
+ x->sig_out[chan][samp]=0;
+ }
+ lptr+=x->cols;
+ }
+ x->perform_fcn=mTxUnPackTildePerformInactive;
+ return(arg+2);
+}
+
+static t_int *mTxUnPackTildePerformActive (t_int *arg)
+{
+ mtx_unpack_tilde *x = (mtx_unpack_tilde *) (arg[1]);
+ int chan;
+ int samp;
+ const int maxchan = (x->rows < x->num_chan) ? x->rows : x->num_chan;
+ const int maxsamp = (x->cols < x->block_size) ? x->cols : x->block_size;
+ t_atom *lptr=x->list_in;
+
+ for (chan=0; chan<maxchan; chan++) {
+ for (samp=0; samp<maxsamp; samp++) {
+ x->sig_out[chan][samp]=atom_getfloat(&lptr[samp]);
+ }
+ lptr+=x->cols;
+ }
+
+ // zero missing signal samples
+ lptr=x->list_in;
+ for (chan=0; chan<maxchan; chan++) {
+ for (; samp<x->block_size; samp++) {
+ x->sig_out[chan][samp]=0;
+ lptr+=x->cols;
+ }
+ }
+ // zero missing channels
+ for (chan=maxchan; chan<x->num_chan; chan++) {
+ for (samp=0; samp<x->block_size; samp++) {
+ x->sig_out[chan][samp]=0;
+ }
+ lptr+=x->cols;
+ }
+
+ // delete in the next dsp cycle, unless overwritten
+ // by new matrix:
+ x->perform_fcn=mTxUnPackTildePerformSetInactive;
+
+ return(arg+2);
+}
+
+
+void *newMtxUnPackTilde (t_floatarg f)
+{
+ int num_chan=1;
+ mtx_unpack_tilde *x = (mtx_unpack_tilde*) pd_new(mtx_unpack_tilde_class);
+ num_chan=(int)f;
+ if ((num_chan<1) || (num_chan>MTX_PACK_MAXCHANNELS)) {
+ num_chan=1;
+ }
+ x->num_chan=num_chan;
+ x->sig_out=0;
+ x->list_in=0;
+ x->rows=0;
+ x->cols=0;
+ x->perform_fcn=mTxUnPackTildePerformInactive;
+ while (num_chan--) {
+ outlet_new(&x->x_obj, &s_signal);
+ }
+ x->sig_out = (t_float**)getbytes(sizeof(t_float*)*x->num_chan);
+
+ return (void *) x;
+}
+void deleteMtxUnPackTilde (mtx_unpack_tilde *x)
+{
+ if (x->sig_out)
+ freebytes (x->sig_out, x->num_chan * sizeof (t_float));
+}
+static void mTxUnPackTildeMatrix (mtx_unpack_tilde *x, t_symbol *s, int argc, t_atom *argv) {
+ int rows, cols;
+ if (argc<2) {
+ post("[mtx_unpack~]: corrupt matrix passed!");
+ x->rows=0;
+ x->cols=0;
+ }
+ else {
+ rows=(int) atom_getfloat (argv++);
+ cols=(int) atom_getfloat (argv++);
+ argc-=2;
+ if ((rows<1)||(cols<1)||(rows*cols < argc)) {
+ post("[mtx_unpack~]: corrupt matrix passed!");
+ x->rows=0;
+ x->cols=0;
+ }
+ else {
+ x->rows=rows;
+ x->cols=cols;
+ x->list_in=argv;
+ x->perform_fcn=mTxUnPackTildePerformActive;
+ }
+ }
+}
+
+static void mTxUnPackTildeDsp (mtx_unpack_tilde *x, t_signal **sp)
+{
+ int chan;
+ for (chan=0; chan<x->num_chan; chan++)
+ x->sig_out[chan]=sp[chan]->s_vec;
+
+ x->block_size=sp[0]->s_n;
+ x->perform_fcn=mTxUnPackTildePerformInactive;
+ dsp_add(mTxUnPackTildePerform,1,x);
+}
+
+void mtx_unpack_tilde_setup (void)
+{
+ mtx_unpack_tilde_class = class_new(gensym("mtx_unpack~"), (t_newmethod)newMtxUnPackTilde, (t_method) deleteMtxUnPackTilde, sizeof(mtx_unpack_tilde), CLASS_DEFAULT, A_DEFFLOAT, 0);
+ class_addmethod (mtx_unpack_tilde_class, (t_method) mTxUnPackTildeMatrix, gensym("matrix"),A_GIMME,0);
+ class_addmethod (mtx_unpack_tilde_class, (t_method) mTxUnPackTildeDsp, gensym("dsp"),0);
+}
+
+void iemtx_unpack__setup(void)
+{
+ mtx_unpack_tilde_setup();
+}
+
+