Update of /cvsroot/pure-data/externals/iem/iemmatrix/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18228
Modified Files: mtx_rowrfft.c mtx_rowrifft.c Log Message: made code more readable for me made object less crashy
Index: mtx_rowrifft.c =================================================================== RCS file: /cvsroot/pure-data/externals/iem/iemmatrix/src/mtx_rowrifft.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mtx_rowrifft.c 20 Sep 2005 08:12:38 -0000 1.1 --- mtx_rowrifft.c 17 Oct 2005 16:17:05 -0000 1.2 *************** *** 80,104 **** static void *newMTXRowrifft (t_symbol *s, int argc, t_atom *argv) { ! MTXRowrifft *mtx_rowrifft_obj = (MTXRowrifft *) pd_new (mtx_rowrifft_class); ! inlet_new(&mtx_rowrifft_obj->x_obj, &mtx_rowrifft_obj->x_obj.ob_pd, gensym("matrix"),gensym("")); ! mtx_rowrifft_obj->list_re_out = outlet_new (&mtx_rowrifft_obj->x_obj, gensym("matrix")); ! return ((void *) mtx_rowrifft_obj); }
! static void mTXrowrifftMatrixCold (MTXRowrifft *mtx_rowrifft_obj, t_symbol *s, int argc, t_atom *argv) { ! //mTXrowrifftList (mtx_rowrifft_obj, s, argc-2, argv+2); int rows = atom_getint (argv++); int columns_re = atom_getint (argv++); int in_size = argc-2; ! int columns = (columns_re-1)<<1; int size2 = columns_re * rows; int size = rows * columns; int ifft_count; ! t_atom *ptr_re = mtx_rowrifft_obj->list_re; ! t_float *f_re = mtx_rowrifft_obj->f_re; ! t_float *f_im = mtx_rowrifft_obj->f_im;
// ifftsize check --- 80,104 ---- static void *newMTXRowrifft (t_symbol *s, int argc, t_atom *argv) { ! MTXRowrifft *x = (MTXRowrifft *) pd_new (mtx_rowrifft_class); ! inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("matrix"),gensym("")); ! x->list_re_out = outlet_new (&x->x_obj, gensym("matrix")); ! return ((void *) x); }
! static void mTXrowrifftMatrixCold (MTXRowrifft *x, t_symbol *s, int argc, t_atom *argv) { ! //mTXrowrifftList (x, s, argc-2, argv+2); int rows = atom_getint (argv++); int columns_re = atom_getint (argv++); int in_size = argc-2; ! int columns = columns_re<<1; int size2 = columns_re * rows; int size = rows * columns; int ifft_count; ! t_atom *list_re = x->list_re; ! t_float *f_re = x->f_re; ! t_float *f_im = x->f_im;
// ifftsize check *************** *** 107,142 **** else if (in_size < size2) post("mtx_rowrifft: sparse matrix not yet supported: use "mtx_check""); else if (columns == (1 << ilog2(columns))) { // memory things ! if (f_re) { ! if (size != mtx_rowrifft_obj->size) { ! f_re = (t_float *) resizebytes (f_re, ! sizeof (t_float) * mtx_rowrifft_obj->size, ! sizeof (t_float) * size); ! f_im = (t_float *) resizebytes (f_im, ! sizeof (t_float) * mtx_rowrifft_obj->size, ! sizeof (t_float) * size); ! ptr_re = (t_atom *) resizebytes (ptr_re, ! sizeof (t_atom) * (mtx_rowrifft_obj->size + 2), ! sizeof (t_atom) * (size + 2)); ! } ! } ! else { ! f_re = (t_float *) getbytes (sizeof (t_float) * size); ! f_im = (t_float *) getbytes (sizeof (t_float) * size); ! ptr_re = (t_atom *) getbytes (sizeof (t_atom) * (size + 2)); ! } ! mtx_rowrifft_obj->size = size; ! mtx_rowrifft_obj->size2 = size2; ! mtx_rowrifft_obj->rows = rows; ! mtx_rowrifft_obj->columns = columns; ! mtx_rowrifft_obj->columns_re = columns_re; ! mtx_rowrifft_obj->list_re = ptr_re; ! mtx_rowrifft_obj->f_re = f_re; ! mtx_rowrifft_obj->f_im = f_im;
// main part: reading imaginary part ifft_count = rows; ! mtx_rowrifft_obj->renorm_fac = 1.0f / columns; while (ifft_count--) { readFloatFromList (columns_re, argv, f_im); --- 107,131 ---- else if (in_size < size2) post("mtx_rowrifft: sparse matrix not yet supported: use "mtx_check""); + else if (columns<4) + post("mtx_rowrifft: too small matrices"); else if (columns == (1 << ilog2(columns))) { + // memory things ! f_re=(t_float*)realloc(f_re, sizeof(t_float)*size); ! f_im=(t_float*)realloc(f_im, sizeof(t_float)*size); ! list_re=(t_atom*)realloc(list_re, sizeof(t_atom)*(size+2)); ! ! x->size = size; ! x->size2 = size2; ! x->rows = rows; ! x->columns = columns; ! x->columns_re = columns_re; ! x->list_re = list_re; ! x->f_re = f_re; ! x->f_im = f_im;
// main part: reading imaginary part ifft_count = rows; ! x->renorm_fac = 1.0f / columns; while (ifft_count--) { readFloatFromList (columns_re, argv, f_im); *************** *** 150,181 **** }
! static void mTXrowrifftMatrixHot (MTXRowrifft *mtx_rowrifft_obj, t_symbol *s, int argc, t_atom *argv) { ! //mTXrowrifftList (mtx_rowrifft_obj, s, argc-2, argv+2); int rows = atom_getint (argv++); int columns_re = atom_getint (argv++); ! int columns = mtx_rowrifft_obj->columns; ! int size = mtx_rowrifft_obj->size; int in_size = argc-2; ! int size2 = mtx_rowrifft_obj->size2; int ifft_count; ! t_atom *ptr_re = mtx_rowrifft_obj->list_re; ! t_float *f_re = mtx_rowrifft_obj->f_re; ! t_float *f_im = mtx_rowrifft_obj->f_im; ! t_float renorm_fac;
// ifftsize check ! if ((rows != mtx_rowrifft_obj->rows) || ! (columns_re != mtx_rowrifft_obj->columns_re)) post("mtx_rowrifft: matrix dimensions do not match"); else if (in_size<size2) post("mtx_rowrifft: sparse matrix not yet supported: use "mtx_check""); ! else if (!mtx_rowrifft_obj->size2) post("mtx_rowrifft: invalid right side matrix"); else { // main part ifft_count = rows; ptr_re += 2; - renorm_fac = mtx_rowrifft_obj->renorm_fac; while (ifft_count--){ readFloatFromList (columns_re, argv, f_re); --- 139,169 ---- }
! static void mTXrowrifftMatrixHot (MTXRowrifft *x, t_symbol *s, int argc, t_atom *argv) { ! //mTXrowrifftList (x, s, argc-2, argv+2); int rows = atom_getint (argv++); int columns_re = atom_getint (argv++); ! int columns = x->columns; ! int size = x->size; int in_size = argc-2; ! int size2 = x->size2; int ifft_count; ! t_atom *ptr_re = x->list_re; ! t_float *f_re = x->f_re; ! t_float *f_im = x->f_im; ! t_float renorm_fac = x->renorm_fac;
// ifftsize check ! if ((rows != x->rows) || ! (columns_re != x->columns_re)) post("mtx_rowrifft: matrix dimensions do not match"); else if (in_size<size2) post("mtx_rowrifft: sparse matrix not yet supported: use "mtx_check""); ! else if (!x->size2) post("mtx_rowrifft: invalid right side matrix"); else { // main part ifft_count = rows; ptr_re += 2; while (ifft_count--){ readFloatFromList (columns_re, argv, f_re); *************** *** 188,221 **** argv += columns_re; } ! ptr_re = mtx_rowrifft_obj->list_re; ! f_re = mtx_rowrifft_obj->f_re; ! size2 = mtx_rowrifft_obj->size2;
SETSYMBOL(ptr_re, gensym("matrix")); SETFLOAT(ptr_re, rows); ! SETFLOAT(&ptr_re[1], mtx_rowrifft_obj->columns); writeFloatIntoList (size, ptr_re+2, f_re); ! outlet_anything(mtx_rowrifft_obj->list_re_out, gensym("matrix"), size+2, ptr_re); } }
! static void mTXrowrifftBang (MTXRowrifft *mtx_rowrifft_obj) { ! if (mtx_rowrifft_obj->list_re) ! outlet_anything(mtx_rowrifft_obj->list_re_out, gensym("matrix"), ! mtx_rowrifft_obj->size+2, mtx_rowrifft_obj->list_re); }
! static void deleteMTXRowrifft (MTXRowrifft *mtx_rowrfft_obj) { ! if (mtx_rowrfft_obj->f_re) ! freebytes (mtx_rowrfft_obj->f_re, sizeof(t_float)*mtx_rowrfft_obj->size); ! if (mtx_rowrfft_obj->f_im) ! freebytes (mtx_rowrfft_obj->f_im, sizeof(t_float)*mtx_rowrfft_obj->size); ! if (mtx_rowrfft_obj->list_re) ! freebytes (mtx_rowrfft_obj->list_re, sizeof(t_atom)*(mtx_rowrfft_obj->size2+2)); ! if (mtx_rowrfft_obj->list_im) ! freebytes (mtx_rowrfft_obj->list_im, sizeof(t_atom)*(mtx_rowrfft_obj->size2+2)); }
--- 176,205 ---- argv += columns_re; } ! ptr_re = x->list_re; ! f_re = x->f_re; ! size2 = x->size2;
SETSYMBOL(ptr_re, gensym("matrix")); SETFLOAT(ptr_re, rows); ! SETFLOAT(&ptr_re[1], x->columns); writeFloatIntoList (size, ptr_re+2, f_re); ! outlet_anything(x->list_re_out, gensym("matrix"), size+2, ptr_re); } }
! static void mTXrowrifftBang (MTXRowrifft *x) { ! if (x->list_re) ! outlet_anything(x->list_re_out, gensym("matrix"), ! x->size+2, x->list_re); }
! static void deleteMTXRowrifft (MTXRowrifft *x) { ! free(x->f_re); ! free(x->f_im); ! free(x->list_re); ! free(x->list_im); }
Index: mtx_rowrfft.c =================================================================== RCS file: /cvsroot/pure-data/externals/iem/iemmatrix/src/mtx_rowrfft.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mtx_rowrfft.c 20 Sep 2005 08:12:38 -0000 1.1 --- mtx_rowrfft.c 17 Oct 2005 16:17:05 -0000 1.2 *************** *** 21,30 **** { t_object x_obj; - int rows; - int columns; - int columns_re; int size; int size2; - t_float renorm_fac;
t_float *f_re; --- 21,26 ---- *************** *** 38,66 **** };
! static void deleteMTXRowrfft (MTXRowrfft *mtx_rowrfft_obj) { ! if (mtx_rowrfft_obj->f_re) ! freebytes (mtx_rowrfft_obj->f_re, sizeof(t_float)*mtx_rowrfft_obj->size); ! if (mtx_rowrfft_obj->f_im) ! freebytes (mtx_rowrfft_obj->f_im, sizeof(t_float)*mtx_rowrfft_obj->size); ! if (mtx_rowrfft_obj->list_re) ! freebytes (mtx_rowrfft_obj->list_re, sizeof(t_atom)*(mtx_rowrfft_obj->size2+2)); ! if (mtx_rowrfft_obj->list_im) ! freebytes (mtx_rowrfft_obj->list_im, sizeof(t_atom)*(mtx_rowrfft_obj->size2+2)); }
static void *newMTXRowrfft (t_symbol *s, int argc, t_atom *argv) { ! MTXRowrfft *mtx_rowrfft_obj = (MTXRowrfft *) pd_new (mtx_rowrfft_class); ! mtx_rowrfft_obj->list_re_out = outlet_new (&mtx_rowrfft_obj->x_obj, gensym("matrix")); ! mtx_rowrfft_obj->list_im_out = outlet_new (&mtx_rowrfft_obj->x_obj, gensym("matrix")); ! return ((void *) mtx_rowrfft_obj); }
! static void mTXrowrfftBang (MTXRowrfft *mtx_rowrfft_obj) { ! if (mtx_rowrfft_obj->list_im) { ! outlet_anything(mtx_rowrfft_obj->list_im_out, gensym("matrix"), mtx_rowrfft_obj->size2+2, mtx_rowrfft_obj->list_im); ! outlet_anything(mtx_rowrfft_obj->list_re_out, gensym("matrix"), mtx_rowrfft_obj->size2+2, mtx_rowrfft_obj->list_re); } } --- 34,63 ---- };
! static void deleteMTXRowrfft (MTXRowrfft *x) { ! free (x->f_re); ! free (x->f_im); ! free (x->list_re); ! free (x->list_im); }
static void *newMTXRowrfft (t_symbol *s, int argc, t_atom *argv) { ! MTXRowrfft *x = (MTXRowrfft *) pd_new (mtx_rowrfft_class); ! x->list_re_out = outlet_new (&x->x_obj, gensym("matrix")); ! x->list_im_out = outlet_new (&x->x_obj, gensym("matrix")); ! ! x->size=x->size2=0; ! x->f_re=x->f_im=0; ! x->list_re=x->list_im=0; ! ! return ((void *) x); }
! static void mTXrowrfftBang (MTXRowrfft *x) { ! if (x->list_im) { ! outlet_anything(x->list_im_out, gensym("matrix"), x->size2, x->list_im); ! outlet_anything(x->list_re_out, gensym("matrix"), x->size2, x->list_re); } } *************** *** 99,117 **** }
! static void mTXrowrfftMatrix (MTXRowrfft *mtx_rowrfft_obj, t_symbol *s, int argc, t_atom *argv) { ! //mTXrowrfftList (mtx_rowrfft_obj, s, argc-2, argv+2); int rows = atom_getint (argv++); int columns = atom_getint (argv++); ! int columns_re = (columns>>1)+1; int size = rows * columns; int in_size = argc-2; ! int size2 = columns_re * rows; int fft_count; ! t_atom *ptr_re = mtx_rowrfft_obj->list_re; ! t_atom *ptr_im = mtx_rowrfft_obj->list_im; ! t_float *f_re = mtx_rowrfft_obj->f_re; ! t_float *f_im = mtx_rowrfft_obj->f_im;
// fftsize check --- 96,114 ---- }
! static void mTXrowrfftMatrix (MTXRowrfft *x, t_symbol *s, int argc, t_atom *argv) { ! //mTXrowrfftList (x, s, argc-2, argv+2); int rows = atom_getint (argv++); int columns = atom_getint (argv++); ! int columns_re = (columns>>1); int size = rows * columns; int in_size = argc-2; ! int size2 = columns_re * rows + 2; /* +2 since the list also contains matrix row+col */ int fft_count; ! t_atom *list_re = x->list_re; ! t_atom *list_im = x->list_im; ! t_float *f_re = x->f_re; ! t_float *f_im = x->f_im;
// fftsize check *************** *** 120,189 **** else if (in_size<size) post("mtx_rowrfft: sparse matrix not yet supported: use "mtx_check""); else if (columns == (1 << ilog2(columns))) { // memory things ! if (f_re) { ! if (size != mtx_rowrfft_obj->size) { ! f_re = (t_float *) resizebytes (f_re, ! sizeof (t_float) * mtx_rowrfft_obj->size, ! sizeof (t_float) * size); ! f_im = (t_float *) resizebytes (f_im, ! sizeof (t_float) * mtx_rowrfft_obj->size, ! sizeof (t_float) * size); ! ptr_re = (t_atom *) resizebytes (ptr_re, ! sizeof (t_atom) * (mtx_rowrfft_obj->size2+2), ! sizeof (t_atom) * (size2 + 2)); ! ptr_im = (t_atom *) resizebytes (ptr_im, ! sizeof (t_atom) * (mtx_rowrfft_obj->size2+2), ! sizeof (t_atom) * (size2 + 2)); ! } ! } ! else { ! f_re = (t_float *) getbytes (sizeof (t_float) * size); ! f_im = (t_float *) getbytes (sizeof (t_float) * size); ! ptr_re = (t_atom *) getbytes (sizeof (t_atom) * (size2+2)); ! ptr_im = (t_atom *) getbytes (sizeof (t_atom) * (size2+2)); ! } ! mtx_rowrfft_obj->size = size; ! mtx_rowrfft_obj->size2 = size2; ! mtx_rowrfft_obj->rows = rows; ! mtx_rowrfft_obj->columns = columns; ! mtx_rowrfft_obj->columns_re = columns_re; ! mtx_rowrfft_obj->list_im = ptr_im; ! mtx_rowrfft_obj->list_re = ptr_re; ! mtx_rowrfft_obj->f_re = f_re; ! mtx_rowrfft_obj->f_im = f_im; ! // main part readFloatFromList (size, argv, f_re);
fft_count = rows; ! ptr_re += 2; ! ptr_im += 2; while (fft_count--){ mayer_realfft (columns, f_re); fftRestoreImag (columns, f_re, f_im); ! writeFloatIntoList (columns_re, ptr_re, f_re); ! writeFloatIntoList (columns_re, ptr_im, f_im); f_im += columns; f_re += columns; ! ptr_re += columns_re; ! ptr_im += columns_re; } ! ptr_re = mtx_rowrfft_obj->list_re; ! ptr_im = mtx_rowrfft_obj->list_im;
! SETSYMBOL(ptr_re, gensym("matrix")); ! SETSYMBOL(ptr_im, gensym("matrix")); ! SETFLOAT(ptr_re, rows); ! SETFLOAT(ptr_im, rows); ! SETFLOAT(&ptr_re[1], columns_re); ! SETFLOAT(&ptr_im[1], columns_re); ! outlet_anything(mtx_rowrfft_obj->list_im_out, gensym("matrix"), ! mtx_rowrfft_obj->size2+2, ptr_im); ! outlet_anything(mtx_rowrfft_obj->list_re_out, gensym("matrix"), ! mtx_rowrfft_obj->size2+2, ptr_re); } else post("mtx_rowfft: rowvector size no power of 2!"); }
--- 117,173 ---- else if (in_size<size) post("mtx_rowrfft: sparse matrix not yet supported: use "mtx_check""); + else if (columns < 4){ + post("mtx_rowrfft: matrix must have at least 4 columns"); + } else if (columns == (1 << ilog2(columns))) { + /* ok, do the FFT! */ + // memory things ! f_re=(t_float*)realloc(f_re, sizeof(t_float)*size); ! f_im=(t_float*)realloc(f_im, sizeof(t_float)*size); ! list_re=(t_atom*)realloc(list_re, sizeof(t_atom)*size2); ! list_im=(t_atom*)realloc(list_im, sizeof(t_atom)*size2); ! ! x->size = size; ! x->size2 = size2; ! x->list_im = list_im; ! x->list_re = list_re; ! x->f_re = f_re; ! x->f_im = f_im; ! // main part readFloatFromList (size, argv, f_re);
fft_count = rows; ! list_re += 2; ! list_im += 2; while (fft_count--){ mayer_realfft (columns, f_re); fftRestoreImag (columns, f_re, f_im); ! writeFloatIntoList (columns_re, list_re, f_re); ! writeFloatIntoList (columns_re, list_im, f_im); f_im += columns; f_re += columns; ! list_re += columns_re; ! list_im += columns_re; } ! ! list_re = x->list_re; ! list_im = x->list_im;
! SETSYMBOL(list_re, gensym("matrix")); ! SETSYMBOL(list_im, gensym("matrix")); ! SETFLOAT(list_re, rows); ! SETFLOAT(list_im, rows); ! SETFLOAT(list_re+1, columns_re); ! SETFLOAT(list_im+1, columns_re); ! outlet_anything(x->list_im_out, gensym("matrix"), ! x->size2, list_im); ! outlet_anything(x->list_re_out, gensym("matrix"), ! x->size2, list_re); } else post("mtx_rowfft: rowvector size no power of 2!"); + }