From 76fd8bc21e49036a8187e7a6b75c36daa842cbc6 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 31 Dec 2010 03:00:34 +0000 Subject: refactored d_fft.c and d_math.c into separate objectclases svn path=/trunk/; revision=14683 --- externals/vanilla/rfft~.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 externals/vanilla/rfft~.c (limited to 'externals/vanilla/rfft~.c') diff --git a/externals/vanilla/rfft~.c b/externals/vanilla/rfft~.c new file mode 100644 index 00000000..5012f750 --- /dev/null +++ b/externals/vanilla/rfft~.c @@ -0,0 +1,68 @@ +/* Copyright (c) 1997- 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 "m_pd.h" +#include "e_fft.h" + +/* This file interfaces to one of the Mayer, Ooura, or fftw FFT packages +to implement the "fft~", etc, Pd objects. If using Mayer, also compile +d_fft_mayer.c; if ooura, use d_fft_fftsg.c instead; if fftw, use d_fft_fftw.c +and also link in the fftw library. You can only have one of these three +linked in. The configure script can be used to select which one. +*/ + +static t_class *sigrfft_class; + +typedef struct rfft +{ + t_object x_obj; + t_float x_f; +} t_sigrfft; + +static void *sigrfft_new(void) +{ + t_sigrfft *x = (t_sigrfft *)pd_new(sigrfft_class); + outlet_new(&x->x_obj, gensym("signal")); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); +} + +static t_int *sigrfft_perform(t_int *w) +{ + t_sample *in = (t_sample *)(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]->s_n, n2 = (n>>1); + t_sample *in1 = sp[0]->s_vec; + t_sample *out1 = sp[1]->s_vec; + t_sample *out2 = sp[2]->s_vec; + if (n < 4) + { + error("fft: minimum 4 points"); + return; + } + if (in1 != out1) + dsp_add(copy_perform, 3, in1, out1, n); + dsp_add(sigrfft_perform, 2, out1, n); + dsp_add(sigrfft_flip, 3, out1 + (n2+1), out2 + n2, n2-1); + dsp_add_zero(out1 + (n2+1), ((n2-1)&(~7))); + dsp_add_zero(out1 + (n2+1) + ((n2-1)&(~7)), ((n2-1)&7)); + dsp_add_zero(out2 + n2, n2); + dsp_add_zero(out2, 1); +} + +void rfft_tilde_setup(void) +{ + sigrfft_class = class_new(gensym("rfft~"), sigrfft_new, 0, + sizeof(t_sigrfft), 0, 0); + CLASS_MAINSIGNALIN(sigrfft_class, t_sigrfft, x_f); + class_addmethod(sigrfft_class, (t_method)sigrfft_dsp, gensym("dsp"), 0); + class_sethelpsymbol(sigrfft_class, gensym("fft~")); +} -- cgit v1.2.1