diff options
author | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2006-09-20 11:22:29 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2006-09-20 11:22:29 +0000 |
commit | 6c61b72cc7be59138b59b1d64b64377fc5c54395 (patch) | |
tree | 10bb031fabe7b578a38d6cc8533bd45785fea0af /fftw~.c |
library providing FFT-objects using the (fast!) libFFTWsvn2git-root
svn path=/trunk/externals/fftw/; revision=5978
Diffstat (limited to 'fftw~.c')
-rw-r--r-- | fftw~.c | 71 |
1 files changed, 71 insertions, 0 deletions
@@ -0,0 +1,71 @@ +/* Copyright (c) 1997-1999 Miller Puckette and others. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +#include "fftw~.h" + +#ifdef HAVE_LIBFFTW3F + +/* Support for fftw3 by Tim Blechmann */ + +/* ------------------------ fft~ -------------------------------- */ +static t_class *sigfftw_class; + +typedef struct fftw +{ + t_object x_obj; + float x_f; + + fftwf_plan plan; + fftwf_iodim dim; +} t_sigfftw; + +static void *sigfftw_new(void) +{ + t_sigfftw *x = (t_sigfftw *)pd_new(sigfftw_class); + outlet_new(&x->x_obj, gensym("signal")); + outlet_new(&x->x_obj, gensym("signal")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + x->x_f = 0; + return (x); +} + +static void sigfftw_free(t_sigfftw * x) +{ + fftwf_destroy_plan(x->plan); +} + +static t_int *sigfftw_perform(t_int *w) +{ + fftwf_execute(*(fftwf_plan *)w[1]); + + return (w+2); +} + +static void sigfftw_dsp(t_sigfftw *x, t_signal **sp) +{ + int n = sp[0]->s_n; + float *in1 = sp[0]->s_vec; + float *in2 = sp[1]->s_vec; + float *out1 = sp[2]->s_vec; + float *out2 = sp[3]->s_vec; + + x->dim.n=n; + x->dim.is=1; + x->dim.os=1; + x->plan = fftwf_plan_guru_split_dft(1, &(x->dim), 0, NULL, + in1, in2, out1, out2, + FFTW_ESTIMATE); + dsp_add(sigfftw_perform, 1, &x->plan); +} + +EXTERNAL_SETUP fftw_tilde_setup(void) +{ + sigfftw_class = class_new(gensym("fftw~"), sigfftw_new, + (t_method) sigfftw_free, + sizeof(t_sigfftw), 0, 0); + CLASS_MAINSIGNALIN(sigfftw_class, t_sigfftw, x_f); + class_addmethod(sigfftw_class, (t_method)sigfftw_dsp, + gensym("dsp"), 0); +} +#endif |