[PD-cvs] pd/src builtins_dsp.c,1.1.2.27,1.1.2.28
Mathieu Bouchard
matju at users.sourceforge.net
Thu Jul 19 21:20:21 CEST 2007
Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3780
Modified Files:
Tag: desiredata
builtins_dsp.c
Log Message:
interleaved the code of the FFT classes
Index: builtins_dsp.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/builtins_dsp.c,v
retrieving revision 1.1.2.27
retrieving revision 1.1.2.28
diff -C2 -d -r1.1.2.27 -r1.1.2.28
*** builtins_dsp.c 19 Jul 2007 18:53:39 -0000 1.1.2.27
--- builtins_dsp.c 19 Jul 2007 19:20:19 -0000 1.1.2.28
***************
*** 11,14 ****
--- 11,16 ----
*/
+ //#define HAVE_LIBFFTW3F
+
#define PD_PLUSPLUS_FACE
#include "desire.h"
***************
*** 2015,2023 ****
#ifndef HAVE_LIBFFTW3F
/* ------------------------ fft~ and ifft~ -------------------------------- */
! static t_class *sigfft_class, *sigifft_class;
!
! struct t_sigfft : t_object {
! float a;
! };
static void *sigfft_new() {
--- 2017,2026 ----
#ifndef HAVE_LIBFFTW3F
/* ------------------------ fft~ and ifft~ -------------------------------- */
! /* ----------------------- rfft~ -------------------------------- */
! /* ----------------------- rifft~ -------------------------------- */
! static t_class *sigfft_class; struct t_sigfft : t_object {float a;};
! static t_class *sigifft_class; struct t_sigifft : t_object {float a;};
! static t_class *sigrfft_class; struct t_sigrfft : t_object {float a;};
! static t_class *sigrifft_class; struct t_sigrifft : t_object {float a;};
static void *sigfft_new() {
***************
*** 2025,2041 ****
outlet_new(x, &s_signal);
outlet_new(x, &s_signal);
! inlet_new(x, x, &s_signal, &s_signal);
! x->a = 0;
! return x;
! }
!
static void *sigifft_new() {
! t_sigfft *x = (t_sigfft *)pd_new(sigifft_class);
outlet_new(x, &s_signal);
outlet_new(x, &s_signal);
inlet_new(x, x, &s_signal, &s_signal);
! x->a = 0;
! return x;
! }
static t_int *sigfft_swap(t_int *w) {
--- 2028,2047 ----
outlet_new(x, &s_signal);
outlet_new(x, &s_signal);
! inlet_new(x, x, &s_signal, &s_signal); x->a=0; return x;}
static void *sigifft_new() {
! t_sigifft *x = (t_sigifft *)pd_new(sigifft_class);
! outlet_new(x, &s_signal);
! outlet_new(x, &s_signal);
! inlet_new(x, x, &s_signal, &s_signal); x->a=0; return x;}
! static void *sigrfft_new() {
! t_sigrfft *x = (t_sigrfft *)pd_new(sigrfft_class);
outlet_new(x, &s_signal);
outlet_new(x, &s_signal);
+ x->a = 0; return x;}
+ static void *sigrifft_new() {
+ t_sigrifft *x = (t_sigrifft *)pd_new(sigrifft_class);
inlet_new(x, x, &s_signal, &s_signal);
! outlet_new(x, &s_signal);
! x->a = 0; return x;}
static t_int *sigfft_swap(t_int *w) {
***************
*** 2050,2067 ****
return w+4;
}
! static t_int *sigfft_perform(t_int *w) {
! float *in1 = (t_float *)w[1];
! float *in2 = (t_float *)w[2];
! int n = w[3];
! mayer_fft(n, in1, in2);
! return w+4;
! }
! static t_int *sigifft_perform(t_int *w) {
! float *in1 = (t_float *)w[1];
! float *in2 = (t_float *)w[2];
! int n = w[3];
! mayer_ifft(n, in1, in2);
! return w+4;
! }
static void sigfft_dspx(t_sigfft *x, t_signal **sp, t_int *(*f)(t_int *w)) {
int n = sp[0]->n;
--- 2056,2064 ----
return w+4;
}
! static t_int * sigfft_perform(t_int *w) {float *in1=(t_float *)w[1], *in2=(t_float *)w[2]; int n=w[3]; mayer_fft(n,in1,in2); return w+4;}
! static t_int * sigifft_perform(t_int *w) {float *in1=(t_float *)w[1], *in2=(t_float *)w[2]; int n=w[3]; mayer_ifft(n,in1,in2); return w+4;}
! static t_int * sigrfft_perform(t_int *w) {float *in =(t_float *)w[1]; int n = w[2]; mayer_realfft(n, in); return w+3;}
! static t_int *sigrifft_perform(t_int *w) {float *in =(t_float *)w[1]; int n = w[2]; mayer_realifft(n, in); return w+3;}
!
static void sigfft_dspx(t_sigfft *x, t_signal **sp, t_int *(*f)(t_int *w)) {
int n = sp[0]->n;
***************
*** 2081,2112 ****
dsp_add(f, 3, sp[2]->v, sp[3]->v, n);
}
! static void sigfft_dsp(t_sigfft *x, t_signal **sp) {
! sigfft_dspx(x, sp, sigfft_perform);
! }
! static void sigifft_dsp(t_sigfft *x, t_signal **sp) {
! sigfft_dspx(x, sp, sigifft_perform);
! }
! static void sigfft_setup() {
! sigfft_class = class_new2("fft~",sigfft_new,0,sizeof(t_sigfft),0,"");
! CLASS_MAINSIGNALIN(sigfft_class, t_sigfft, a);
! class_addmethod2(sigfft_class, sigfft_dsp, "dsp","");
! sigifft_class = class_new2("ifft~",sigifft_new,0,sizeof(t_sigfft),0,"");
! CLASS_MAINSIGNALIN(sigifft_class, t_sigfft, a);
! class_addmethod2(sigifft_class, sigifft_dsp, "dsp","");
! class_sethelpsymbol(sigifft_class, gensym("fft~"));
! }
- /* ----------------------- rfft~ -------------------------------- */
- static t_class *sigrfft_class;
- struct t_sigrfft : t_object {
- float a;
- };
- static void *sigrfft_new() {
- t_sigrfft *x = (t_sigrfft *)pd_new(sigrfft_class);
- outlet_new(x, &s_signal);
- outlet_new(x, &s_signal);
- x->a = 0;
- return x;
- }
static t_int *sigrfft_flip(t_int *w) {
float *in = (t_float *)w[1];
--- 2078,2084 ----
dsp_add(f, 3, sp[2]->v, sp[3]->v, n);
}
! static void sigfft_dsp(t_sigfft *x, t_signal **sp) {sigfft_dspx(x, sp, sigfft_perform);}
! static void sigifft_dsp(t_sigfft *x, t_signal **sp) {sigfft_dspx(x, sp, sigifft_perform);}
static t_int *sigrfft_flip(t_int *w) {
float *in = (t_float *)w[1];
***************
*** 2114,2126 ****
int n = w[3];
while (n--) *(--out) = *in++;
! *(--out) = 0; /* to hell with it */
return w+4;
}
- static t_int *sigrfft_perform(t_int *w) {
- float *in = (t_float *)w[1];
- int n = w[2];
- mayer_realfft(n, in);
- return w+3;
- }
static void sigrfft_dsp(t_sigrfft *x, t_signal **sp) {
int n = sp[0]->n, n2 = (n>>1);
--- 2086,2092 ----
int n = w[3];
while (n--) *(--out) = *in++;
! *(--out) = 0; /* to hell with it */
return w+4;
}
static void sigrfft_dsp(t_sigrfft *x, t_signal **sp) {
int n = sp[0]->n, n2 = (n>>1);
***************
*** 2145,2173 ****
dsp_add_zero(out2 + n2, n2);
}
- static void sigrfft_setup() {
- sigrfft_class = class_new2("rfft~",sigrfft_new,0,sizeof(t_sigrfft),0,"");
- CLASS_MAINSIGNALIN(sigrfft_class, t_sigrfft, a);
- class_addmethod2(sigrfft_class, sigrfft_dsp, "dsp","");
- class_sethelpsymbol(sigrfft_class, gensym("fft~"));
- }
- /* ----------------------- rifft~ -------------------------------- */
- static t_class *sigrifft_class;
- struct t_sigrifft : t_object {
- float a;
- };
- static void *sigrifft_new() {
- t_sigrifft *x = (t_sigrifft *)pd_new(sigrifft_class);
- inlet_new(x, x, &s_signal, &s_signal);
- outlet_new(x, &s_signal);
- x->a = 0;
- return x;
- }
- static t_int *sigrifft_perform(t_int *w) {
- float *in = (t_float *)w[1];
- int n = w[2];
- mayer_realifft(n, in);
- return w+3;
- }
static void sigrifft_dsp(t_sigrifft *x, t_signal **sp) {
int n = sp[0]->n, n2 = (n>>1);
--- 2111,2115 ----
***************
*** 2185,2193 ****
dsp_add(sigrifft_perform, 2, out1, n);
}
! static void sigrifft_setup() {
sigrifft_class = class_new2("rifft~",sigrifft_new,0,sizeof(t_sigrifft),0,"");
! CLASS_MAINSIGNALIN(sigrifft_class, t_sigrifft, a);
! class_addmethod2(sigrifft_class, sigrifft_dsp, "dsp","");
! class_sethelpsymbol(sigrifft_class, gensym("fft~"));
}
--- 2127,2146 ----
dsp_add(sigrifft_perform, 2, out1, n);
}
! static void sigfft_setup() {
! sigfft_class = class_new2("fft~", sigfft_new, 0,sizeof(t_sigfft), 0,"");
! sigifft_class = class_new2("ifft~", sigifft_new, 0,sizeof(t_sigfft), 0,"");
! sigrfft_class = class_new2("rfft~", sigrfft_new, 0,sizeof(t_sigrfft), 0,"");
sigrifft_class = class_new2("rifft~",sigrifft_new,0,sizeof(t_sigrifft),0,"");
! CLASS_MAINSIGNALIN(sigfft_class, t_sigfft, a);
! CLASS_MAINSIGNALIN(sigifft_class, t_sigfft, a);
! CLASS_MAINSIGNALIN(sigrfft_class, t_sigrfft, a);
! CLASS_MAINSIGNALIN(sigrifft_class,t_sigrifft,a);
! class_addmethod2(sigfft_class, sigfft_dsp, "dsp","");
! class_addmethod2(sigifft_class, sigifft_dsp, "dsp","");
! class_addmethod2(sigrfft_class, sigrfft_dsp, "dsp","");
! class_addmethod2(sigrifft_class,sigrifft_dsp,"dsp","");
! class_sethelpsymbol(sigifft_class, gensym("fft~"));
! class_sethelpsymbol(sigrfft_class, gensym("fft~"));
! class_sethelpsymbol(sigrifft_class,gensym("fft~"));
}
***************
*** 2195,2215 ****
/* Support for fftw3 by Tim Blechmann */
/* ------------------------ fft~ and ifft~ -------------------------------- */
- static t_class *sigfftw_class, *sigifftw_class;
- struct t_sigfftw : t_object {
- float a;
- fftwf_plan plan;
- fftwf_iodim dim;
- } t_sigfftw;
static void *sigfftw_new() {
! t_sigfftw *x = (t_sigfftw *)pd_new(sigfftw_class);
! outlet_new(x, &s_signal);
! outlet_new(x, &s_signal);
inlet_new(x, x, &s_signal, &s_signal);
! x->a = 0;
! return x;
! }
! static void sigfftw_free(t_sigfftw * x) {
! fftwf_destroy_plan(x->plan);
}
static t_int *sigfftw_perform(t_int *w) {
--- 2148,2181 ----
/* Support for fftw3 by Tim Blechmann */
/* ------------------------ fft~ and ifft~ -------------------------------- */
+ /* ----------------------- rfft~ --------------------------------- */
+ /* ----------------------- rifft~ -------------------------------- */
+
+ static t_class *sigfftw_class; struct t_sigfftw : t_object {float a; fftwf_plan plan; fftwf_iodim dim;};
+ static t_class *sigifftw_class; struct t_sigifftw : t_object {float a; fftwf_plan plan; fftwf_iodim dim;};
+ static t_class *sigrfftw_class; struct t_sigrfftw : t_object {float a; fftwf_plan plan; fftwf_iodim dim;};
+ static t_class *sigrifftw_class;struct t_sigrifftw : t_object {float a; fftwf_plan plan; fftwf_iodim dim;};
static void *sigfftw_new() {
! t_sigfftw *x = (t_sigfftw *)pd_new(sigfftw_class); outlet_new(x, &s_signal); outlet_new(x, &s_signal);
! inlet_new(x, x, &s_signal, &s_signal); x->a=0; return x;}
! static void *sigifftw_new() {
! t_sigifftw *x = (t_sigifftw *)pd_new(sigfftw_class); outlet_new(x, &s_signal); outlet_new(x, &s_signal);
! inlet_new(x, x, &s_signal, &s_signal); x->a=0; return x;}
! static void *sigrfftw_new() {
! t_sigrfftw *x = (t_sigrfftw *)pd_new(sigrfftw_class);
! outlet_new(x, &s_signal); outlet_new(x, &s_signal); x->a=0; return x;}
! static void *sigrifftw_new() {
! t_sigrifftw *x = (t_sigrifftw *)pd_new(sigrifftw_class);
inlet_new(x, x, &s_signal, &s_signal);
! outlet_new(x, &s_signal); x->a=0; return x;}
!
! static void sigfftw_free( t_sigfftw *x) {fftwf_destroy_plan(x->plan);}
! static void sigifftw_free( t_sigifftw *x) {fftwf_destroy_plan(x->plan);}
! static void sigrfftw_free( t_sigrfftw *x) {fftwf_destroy_plan(x->plan);}
! static void sigrifftw_free(t_sigrifftw *x) {fftwf_destroy_plan(x->plan);}
!
! /* for compatibility reasons with the mayer fft, we'll have to invert some samples. this is ugly, but someone might rely on that. */
! static void sigrfftw_invert(t_sample * s, t_int n) {
! while (n!=0) {--n; s[n]=-s[n];}
}
static t_int *sigfftw_perform(t_int *w) {
***************
*** 2217,2220 ****
--- 2183,2197 ----
return w+2;
}
+ static t_int *sigrfftw_perform(t_int *w) {
+ fftwf_execute(*(fftwf_plan*)w[1]);
+ sigrfftw_invert((t_sample*)w[2],(t_int)w[3]);
+ return w+4;
+ }
+ static t_int *sigrifftw_perform(t_int *w) {
+ sigrfftw_invert((t_sample *)w[2],w[3]);
+ fftwf_execute(*(fftwf_plan*)w[1]);
+ return w+4;
+ }
+
static void sigfftw_dsp(t_sigfftw *x, t_signal **sp) {
int n = sp[0]->n;
***************
*** 2241,2283 ****
dsp_add(sigfftw_perform, 1, &x->plan);
}
- static void sigfftw_setup() {
- sigfftw_class = class_new2("fft~",sigfftw_new,sigfftw_free,sizeof(t_sigfftw),0,"");
- CLASS_MAINSIGNALIN(sigfftw_class, t_sigfftw, a);
- class_addmethod2(sigfftw_class, sigfftw_dsp,"dsp","");
- sigifftw_class = class_new2("ifft~",sigfftw_new,sigfftw_free,sizeof(t_sigfftw),0,"");
- CLASS_MAINSIGNALIN(sigifftw_class, t_sigfftw, a);
- class_addmethod2(sigifftw_class, sigifftw_dsp,"dsp","");
- class_sethelpsymbol(sigifftw_class, gensym("fft~"));
- }
-
- /* ----------------------- rfft~ --------------------------------- */
- static t_class *sigrfftw_class;
- struct t_sigrfftw : t_object {
- float a;
- fftwf_plan plan;
- fftwf_iodim dim;
- };
- static void *sigrfftw_new() {
- t_sigrfftw *x = (t_sigrfftw *)pd_new(sigrfftw_class);
- outlet_new(x, &s_signal);
- outlet_new(x, &s_signal);
- x->a = 0;
- return x;
- }
- static void sigrfftw_free(t_sigrfftw *x) {fftwf_destroy_plan(x->plan);}
- /* for compatibility reasons with the mayer fft, we'll have to invert
- * some samples ... this is ugly, but someone might rely on that ... */
- static void sigrfftw_invert(t_sample * s, t_int n) {
- while (n!=0) {
- --n;
- s[n]=-s[n];
- }
- }
- static t_int *sigrfftw_perform(t_int *w) {
- fftwf_execute(*(fftwf_plan*)w[1]);
- sigrfftw_invert((t_sample*)w[2],(t_int)w[3]);
- return w+4;
- }
static void sigrfftw_dsp(t_sigrfftw *x, t_signal **sp) {
int n = sp[0]->n, n2 = (n>>1);
--- 2218,2222 ----
***************
*** 2285,2332 ****
float *out1 = sp[1]->v;
float *out2 = sp[2]->v;
! if (n < 4) {
! error("fft: minimum 4 points");
! return;
! } else {
! x->dim.n=n;
! x->dim.is=1;
! x->dim.os=1;
! x->plan = fftwf_plan_guru_split_dft_r2c(1, &(x->dim), 0, NULL,
! in, out1, out2, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT);
dsp_add(sigrfftw_perform,3,&x->plan,out2+1,n2-1);
- }
dsp_add_zero(out1 + n2, n2);
dsp_add_zero(out2 + n2, n2);
}
- static void sigrfftw_setup() {
- sigrfftw_class = class_new2("rfft~",sigrfftw_new,sigrfftw_free,sizeof(t_sigrfftw),0,0);
- CLASS_MAINSIGNALIN(sigrfftw_class, t_sigrfftw, a);
- class_addmethod2(sigrfftw_class, sigrfftw_dsp,"dsp","");
- class_sethelpsymbol(sigrfftw_class, gensym("fft~"));
- }
- /* ----------------------- rifft~ -------------------------------- */
- static t_class *sigrifftw_class;
- struct t_sigrifftw : t_object {
- t_object obj;
- float a;
- fftwf_plan plan;
- fftwf_iodim dim;
- } t_sigrifftw;
- static void *sigrifftw_new() {
- t_sigrifftw *x = (t_sigrifftw *)pd_new(sigrifftw_class);
- inlet_new(x, x, &s_signal, &s_signal);
- outlet_new(x, &s_signal);
- x->a = 0;
- return x;
- }
- static void sigrifftw_free(t_sigrifftw *x) {
- fftwf_destroy_plan(x->plan);
- }
- static t_int *sigrifftw_perform(t_int *w) {
- sigrfftw_invert((t_sample *)w[2],w[3]);
- fftwf_execute(*(fftwf_plan*)w[1]);
- return w+4;
- }
static void sigrifftw_dsp(t_sigrifftw *x, t_signal **sp) {
int n = sp[0]->n, n2 = (n>>1);
--- 2224,2237 ----
float *out1 = sp[1]->v;
float *out2 = sp[2]->v;
! if (n < 4) {error("fft: minimum 4 points"); return;}
! x->dim.n=n;
! x->dim.is=1;
! x->dim.os=1;
! x->plan = fftwf_plan_guru_split_dft_r2c(1, &(x->dim), 0, NULL, in, out1, out2, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT);
dsp_add(sigrfftw_perform,3,&x->plan,out2+1,n2-1);
dsp_add_zero(out1 + n2, n2);
dsp_add_zero(out2 + n2, n2);
}
static void sigrifftw_dsp(t_sigrifftw *x, t_signal **sp) {
int n = sp[0]->n, n2 = (n>>1);
***************
*** 2347,2355 ****
}
}
! static void sigrifftw_setup() {
sigrifftw_class = class_new2("rifft~",sigrifftw_new,sigrifftw_free,sizeof(t_sigrifftw),0,"");
! CLASS_MAINSIGNALIN(sigrifftw_class, t_sigrifftw, a);
! class_addmethod2(sigrifftw_class, sigrifftw_dsp, "dsp","");
! class_sethelpsymbol(sigrifftw_class, gensym("fft~"));
}
#endif /* HAVE_LIBFFTW3F */
--- 2252,2271 ----
}
}
! static void sigfftw_setup() {
! sigfftw_class = class_new2( "fft~",sigfftw_new, sigfftw_free, sizeof(t_sigfftw), 0,"");
! sigifftw_class = class_new2( "ifft~",sigifftw_new, sigifftw_free, sizeof(t_sigfftw), 0,"");
! sigrfftw_class = class_new2( "rfft~",sigrfftw_new, sigrfftw_free, sizeof(t_sigrfftw), 0,"");
sigrifftw_class = class_new2("rifft~",sigrifftw_new,sigrifftw_free,sizeof(t_sigrifftw),0,"");
! CLASS_MAINSIGNALIN(sigfftw_class, t_sigfftw, a);
! CLASS_MAINSIGNALIN(sigifftw_class, t_sigfftw, a);
! CLASS_MAINSIGNALIN(sigrfftw_class, t_sigrfftw, a);
! CLASS_MAINSIGNALIN(sigrifftw_class,t_sigrifftw,a);
! class_addmethod2(sigfftw_class, sigfftw_dsp, "dsp","");
! class_addmethod2(sigifftw_class, sigifftw_dsp, "dsp","");
! class_addmethod2(sigrfftw_class, sigrfftw_dsp, "dsp","");
! class_addmethod2(sigrifftw_class, sigrifftw_dsp,"dsp","");
! class_sethelpsymbol(sigifftw_class, gensym("fft~"));
! class_sethelpsymbol(sigrfftw_class, gensym("fft~"));
! class_sethelpsymbol(sigrifftw_class,gensym("fft~"));
}
#endif /* HAVE_LIBFFTW3F */
***************
*** 3918,3925 ****
sig_tilde_setup();
! line_tilde_setup();
! vline_tilde_setup();
! snapshot_tilde_setup();
! vsnapshot_tilde_setup();
env_tilde_setup();
threshold_tilde_setup();
--- 3834,3839 ----
sig_tilde_setup();
! line_tilde_setup(); snapshot_tilde_setup();
! vline_tilde_setup(); vsnapshot_tilde_setup();
env_tilde_setup();
threshold_tilde_setup();
***************
*** 3933,3944 ****
sigframp_setup();
! #ifndef HAVE_LIBFFTW3F
! sigfft_setup();
! sigrfft_setup();
! sigrifft_setup();
! #else
sigfftw_setup(); /* added by Tim Blechmann to support fftw */
! sigrifftw_setup();
! sigrfftw_setup();
#endif /* HAVE_LIBFFTW3F */
--- 3847,3854 ----
sigframp_setup();
! #ifdef HAVE_LIBFFTW3F
sigfftw_setup(); /* added by Tim Blechmann to support fftw */
! #else
! sigfft_setup();
#endif /* HAVE_LIBFFTW3F */
More information about the Pd-cvs
mailing list