[PD-cvs] SF.net SVN: pure-data:[10208] trunk/externals/iem/iemmatrix

fzotter at users.sourceforge.net fzotter at users.sourceforge.net
Tue Jul 22 19:23:43 CEST 2008


Revision: 10208
          http://pure-data.svn.sourceforge.net/pure-data/?rev=10208&view=rev
Author:   fzotter
Date:     2008-07-22 17:23:43 +0000 (Tue, 22 Jul 2008)

Log Message:
-----------
corrected [mtx_rfft] and [mtx_rifft] memory bugs. 

Modified Paths:
--------------
    trunk/externals/iem/iemmatrix/doc/mtx_rfft-help.pd
    trunk/externals/iem/iemmatrix/doc/mtx_rifft-help.pd
    trunk/externals/iem/iemmatrix/src/mtx_rfft.c
    trunk/externals/iem/iemmatrix/src/mtx_rifft.c

Modified: trunk/externals/iem/iemmatrix/doc/mtx_rfft-help.pd
===================================================================
--- trunk/externals/iem/iemmatrix/doc/mtx_rfft-help.pd	2008-07-22 15:30:52 UTC (rev 10207)
+++ trunk/externals/iem/iemmatrix/doc/mtx_rfft-help.pd	2008-07-22 17:23:43 UTC (rev 10208)
@@ -13,8 +13,8 @@
 #X obj 11 169 mtx_ones;
 #X obj 11 213 mtx_- 1;
 #X obj 49 255 mtx_* 0;
-#X floatatom 172 234 5 0 0 0 - - -;
-#X text 212 232 <-- scroll here to select frequency;
+#X floatatom 140 210 5 0 0 0 - - -;
+#X text 184 208 <-- scroll here to select frequency;
 #X obj 172 255 / 8;
 #X obj 49 306 t a a;
 #X obj 92 306 mtx_print original;
@@ -31,13 +31,14 @@
 #X obj 261 438 mtx_rifft;
 #X obj 121 353 mtx_+ 0.5;
 #X obj 49 373 mtx_+ 0.5;
+#X obj 140 231 t b f;
 #X connect 4 0 8 0;
 #X connect 7 0 10 0;
 #X connect 8 0 9 0;
 #X connect 9 0 7 0;
 #X connect 10 0 11 0;
 #X connect 11 0 20 0;
-#X connect 12 0 14 0;
+#X connect 12 0 30 0;
 #X connect 14 0 21 0;
 #X connect 15 0 26 0;
 #X connect 15 1 16 0;
@@ -49,3 +50,5 @@
 #X connect 26 1 28 0;
 #X connect 28 0 23 0;
 #X connect 29 0 24 0;
+#X connect 30 0 4 0;
+#X connect 30 1 14 0;

Modified: trunk/externals/iem/iemmatrix/doc/mtx_rifft-help.pd
===================================================================
--- trunk/externals/iem/iemmatrix/doc/mtx_rifft-help.pd	2008-07-22 15:30:52 UTC (rev 10207)
+++ trunk/externals/iem/iemmatrix/doc/mtx_rifft-help.pd	2008-07-22 17:23:43 UTC (rev 10208)
@@ -8,8 +8,8 @@
 #X obj 11 169 mtx_ones;
 #X obj 11 213 mtx_- 1;
 #X obj 49 255 mtx_* 0;
-#X floatatom 177 234 5 0 0 0 - - -;
-#X obj 177 255 / 8;
+#X floatatom 155 202 5 0 0 0 - - -;
+#X obj 187 255 / 8;
 #X obj 49 278 t a a;
 #X text 266 443 see also:;
 #X text 46 34 real ifft in each matrix row;
@@ -19,7 +19,7 @@
 #X msg 11 147 1 9;
 #X obj 49 307 mtx_cos;
 #X obj 104 307 mtx_sin;
-#X text 217 232 <-- scroll here to select delay;
+#X text 199 203 <-- scroll here to select delay;
 #X obj 49 411 mtx_print rifft;
 #X obj 49 389 mtx_int;
 #X obj 103 255 * -3.14159;
@@ -27,12 +27,13 @@
 #X obj 262 463 mtx_rfft;
 #X obj 49 336 mtx_rifft;
 #X obj 49 362 mtx_+ 0.5;
+#X obj 155 223 t b f;
 #X connect 4 0 15 0;
 #X connect 5 0 7 0;
 #X connect 6 0 5 0;
 #X connect 7 0 8 0;
 #X connect 8 0 11 0;
-#X connect 9 0 10 0;
+#X connect 9 0 26 0;
 #X connect 10 0 21 0;
 #X connect 11 0 16 0;
 #X connect 11 1 17 0;
@@ -43,3 +44,5 @@
 #X connect 21 0 8 1;
 #X connect 24 0 25 0;
 #X connect 25 0 20 0;
+#X connect 26 0 4 0;
+#X connect 26 1 10 0;

Modified: trunk/externals/iem/iemmatrix/src/mtx_rfft.c
===================================================================
--- trunk/externals/iem/iemmatrix/src/mtx_rfft.c	2008-07-22 15:30:52 UTC (rev 10207)
+++ trunk/externals/iem/iemmatrix/src/mtx_rfft.c	2008-07-22 17:23:43 UTC (rev 10208)
@@ -137,10 +137,13 @@
 }
 
 #ifdef HAVE_FFTW3_H
-static void writeFFTWComplexPartIntoList (int n, t_atom *l, fftw_complex *f, enum ComplexPart p) 
+static void writeFFTWComplexPartIntoList (int n, t_atom *l, fftw_complex *c, enum ComplexPart p) 
 {
-  for (;n--;f++, l++) 
-    SETFLOAT (l, ((t_float)*f[p]));
+   t_float f;
+  while (n--) {
+     f=(t_float)c[n][p];
+    SETFLOAT (l+n, f);
+  }
 }
 static void readDoubleFromList (int n, t_atom *l, double *f) 
 {

Modified: trunk/externals/iem/iemmatrix/src/mtx_rifft.c
===================================================================
--- trunk/externals/iem/iemmatrix/src/mtx_rifft.c	2008-07-22 15:30:52 UTC (rev 10207)
+++ trunk/externals/iem/iemmatrix/src/mtx_rifft.c	2008-07-22 17:23:43 UTC (rev 10208)
@@ -33,13 +33,12 @@
   int columns_re;
   int size;
   int size2;
+  t_float renorm_fac;
 #ifdef HAVE_FFTW3_H  
   fftw_plan *fftplan;
   fftw_complex *f_in;
   double *f_out;
 #else
-  t_float renorm_fac;
-
   t_float *f_re;
   t_float *f_im;
 #endif
@@ -94,14 +93,24 @@
 #ifdef HAVE_FFTW3_H
 static void readFFTWComplexPartFromList (int n, t_atom *l, fftw_complex *f, enum ComplexPart p) 
 {
-  for (;n--;f++, l++) 
-    *f[p] = (double) atom_getfloat (l);
+  for (;n--;) 
+    f[n][p] = (double) atom_getfloat (l+n);
 }
-static void writeDoubleIntoList (int n, t_atom *l, double *f) 
+static void writeDoubleIntoList (int n, t_atom *l, double *d) 
 {
-  while (n--) 
-    SETFLOAT (l++,((t_float)(*f++)));
+   t_float f;
+  while (n--) { 
+    f=(t_float) d[n];
+    SETFLOAT (l+n,f);
+  }
 }
+static void multiplyDoubleVector (int n, double *f, t_float fac)
+{
+   double fd=(double)fac;
+  while (n--)
+    *f++ *= (double)fd;
+}
+
 #endif
 
 static void *newMTXRifft (t_symbol *s, int argc, t_atom *argv)
@@ -152,6 +161,8 @@
       x->fftplan=(fftw_plan*)realloc(x->fftplan,sizeof(fftw_plan)*rows);
       f_in=(fftw_complex*)realloc(f_in,sizeof(fftw_complex)*size2);
       f_out=(double*)realloc(f_out,sizeof(double)*size);
+      list_re=(t_atom*)realloc(list_re, sizeof(t_atom)*(size+2));
+      x->list_re = list_re;
       x->f_out = f_out;
       x->f_in = f_in;
       for (ifft_count=0;ifft_count<rows;ifft_count++) {
@@ -167,22 +178,20 @@
     f_im=(t_float*)realloc(f_im, sizeof(t_float)*size);
     x->f_re = f_re;
     x->f_im = f_im;
+    list_re=(t_atom*)realloc(list_re, sizeof(t_atom)*(size+2));
+    x->list_re = list_re;
 #endif
 
-    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;
       
     /* main part: reading imaginary part */
     ifft_count = rows;
-#ifndef HAVE_FFTW3_H
     x->renorm_fac = 1.0f / columns;
-#endif
-    while (ifft_count--) {
+    for (ifft_count=0;ifft_count<rows;ifft_count++) {
 #ifdef HAVE_FFTW3_H
       readFFTWComplexPartFromList(columns_re, argv, f_in, IMAGPART);
       f_in += columns_re;
@@ -210,12 +219,11 @@
   int ifft_count;
 #ifdef HAVE_FFTW3_H
   fftw_complex *f_in = x->f_in;
-  double *f_out = x->f_out;
 #else
   t_float *f_re = x->f_re;
   t_float *f_im = x->f_im;
+#endif
   t_float renorm_fac = x->renorm_fac;
-#endif
 
   /* ifftsize check */
   if ((rows != x->rows) || 
@@ -235,7 +243,6 @@
       readFloatFromList (columns_re, argv, f_re);
       ifftPrepareReal (columns, f_re, f_im);
       mayer_realifft (columns, f_re);
-      multiplyVector (columns, f_re, renorm_fac);
       f_im += columns;
       f_re += columns;
 #endif
@@ -249,8 +256,10 @@
     SETFLOAT(x->list_re, rows);
     SETFLOAT(x->list_re+1, x->columns);
 #ifdef HAVE_FFTW3_H
-    writeDoubleIntoList (size, x->list_re+2, f_out);
+    multiplyDoubleVector (size, x->f_out, renorm_fac);
+    writeDoubleIntoList (size, x->list_re+2, x->f_out);
 #else
+    multiplyVector (size, f_re, renorm_fac);
     writeFloatIntoList  (size, x->list_re+2, f_re);
 #endif
     outlet_anything(x->list_re_out, gensym("matrix"), size+2, x->list_re);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Pd-cvs mailing list