aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtbext/config-pd-linux.txt4
-rwxr-xr-xtbext/make-files.txt5
-rw-r--r--tbext/makefile.pd-linux8
-rw-r--r--tbext/source/main.cpp15
-rw-r--r--tbext/source/rfftw~.cpp138
-rw-r--r--tbext/source/rifftw~.cpp161
6 files changed, 324 insertions, 7 deletions
diff --git a/tbext/config-pd-linux.txt b/tbext/config-pd-linux.txt
index b1479f8..b1acfa1 100755
--- a/tbext/config-pd-linux.txt
+++ b/tbext/config-pd-linux.txt
@@ -32,6 +32,10 @@ HELPDIR=${PD}/doc/5.reference
UFLAGS=-g -xW -tpp7 -ip -ipo_obj # icc
# UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2
+#compile support for the fftw3 library
+#make sure that you compiled fftw3 for single precision floats!!!
+FFTW=1
+
# define to link against shared flext library (flext version >= 0.5.0)
FLEXT_SHARED=1
diff --git a/tbext/make-files.txt b/tbext/make-files.txt
index 559a851..cf7bc8e 100755
--- a/tbext/make-files.txt
+++ b/tbext/make-files.txt
@@ -4,7 +4,10 @@ SRCS= \
main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp \
tbpow~.cpp tbfft1.cpp tbfft2.cpp fftbuf.cpp fftgrsort.cpp \
fftgrshuf.cpp fftgrrev.cpp
-
+
+ifdef FFTW
+SRCS+=fftw~.cpp ifftw~.cpp rfftw~.cpp rifftw~.cpp
+endif
#HDRS= \
main.h
diff --git a/tbext/makefile.pd-linux b/tbext/makefile.pd-linux
index 7948a19..3546d99 100644
--- a/tbext/makefile.pd-linux
+++ b/tbext/makefile.pd-linux
@@ -1,5 +1,4 @@
-# xsample - extended sample objects for Max/MSP and pd (pure data)
-# Copyright (c) 2001-2003 Thomas Grill (xovo@gmx.net)
+# makefile adapted from thomas grill's xsample makefile
#
# Makefile for gcc @ linux
#
@@ -28,6 +27,11 @@ else
LINKFLEXT=$(FLEXTLIB)
endif
+ifdef FFTW
+LDFLAGS+=-lfftw3f
+CFLAGS+=-DFFTW
+endif
+
# ----------------------------------------------
# the rest can stay untouched
# ----------------------------------------------
diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp
index 5a3bb14..07a0713 100644
--- a/tbext/source/main.cpp
+++ b/tbext/source/main.cpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2003 Tim Blechmann. */
+/* Copyright (c) 2003-2004 Tim Blechmann. */
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */
/* WARRANTIES, see the file, "COPYING" in this distribution. */
/* */
@@ -40,7 +40,7 @@
#include <flext.h>
-#define TBEXT_VERSION "0.03"
+#define TBEXT_VERSION "0.04"
#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400)
#error upgrade your flext version!!!!!!
@@ -52,7 +52,7 @@ void ttbext_setup()
post("version "TBEXT_VERSION);
post("compiled on "__DATE__);
post("contains: tbroute(~), tbsig~, tbpow~, tbfft1~, tbfft2~, bufline~, fftgrrev~");
- post(" fftgrsort~, fftgrshuf~");
+ post(" fftgrsort~, fftgrshuf~, rfftw~, rifftw~");
FLEXT_SETUP(tbroute);
FLEXT_DSP_SETUP(tbsroute);
@@ -66,7 +66,14 @@ void ttbext_setup()
FLEXT_DSP_SETUP(fftgrsort);
FLEXT_DSP_SETUP(fftgrshuf);
FLEXT_DSP_SETUP(fftgrrev);
- FLEXT_DSP_SETUP(spigot_tilde);
+
+
+#if (FFTW == 1)
+ FLEXT_DSP_SETUP(rfftw);
+ FLEXT_DSP_SETUP(rifftw);
+#endif
+
+
}
FLEXT_LIB_SETUP(tbext,ttbext_setup)
diff --git a/tbext/source/rfftw~.cpp b/tbext/source/rfftw~.cpp
new file mode 100644
index 0000000..dd10517
--- /dev/null
+++ b/tbext/source/rfftw~.cpp
@@ -0,0 +1,138 @@
+/* Copyright (c) 2004 Tim Blechmann. */
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */
+/* WARRANTIES, see the file, "COPYING" in this distribution. */
+/* */
+/* */
+/* rfftw~ is doing the same as rfft~, but it's based on the fftw library, */
+/* that is much faster that pd's internal fft ... */
+/* */
+/* */
+/* rfftw~ uses the flext C++ layer for Max/MSP and PD externals. */
+/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */
+/* thanks to Thomas Grill */
+/* */
+/* */
+/* */
+/* This program is free software; you can redistribute it and/or */
+/* modify it under the terms of the GNU General Public License */
+/* as published by the Free Software Foundation; either version 2 */
+/* of the License, or (at your option) any later version. */
+/* */
+/* See file LICENSE for further informations on licensing terms. */
+/* */
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software */
+/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+/* */
+/* Based on PureData by Miller Puckette and others. */
+/* */
+/* */
+/* */
+/* coded while listening to: Wolfgang Mitterer: Radiofractal & Beat Music */
+/* Sun Ra: Reflections In Blue */
+/* */
+/* */
+
+
+
+#include <flext.h>
+
+#include "fftw3.h"
+#include <algorithm>
+
+#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401)
+#error upgrade your flext version!!!!!!
+#endif
+
+class rfftw: public flext_dsp
+{
+ FLEXT_HEADER(rfftw,flext_dsp);
+
+public: // constructor
+ rfftw();
+ ~rfftw();
+
+protected:
+ virtual void m_signal (int n, float *const *in, float *const *out);
+
+ fftwf_plan p; //fftw plan
+ int bins; //number of bins
+ float * outreal; //pointer to real output
+ float * outimag; //pointer to imaginary output
+
+ float * infft; //array fftw is working on
+ float * outfft; //array fftw uses to output it's values
+
+
+ private:
+};
+
+
+FLEXT_LIB_DSP("rfftw~",rfftw);
+
+rfftw::rfftw()
+ :bins(64)
+{
+ //get ready for the default blocksize
+ infft = fftwf_malloc(sizeof(float) * bins);
+ outfft = fftwf_malloc(sizeof(float) * bins);
+ p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_FORWARD,FFTW_MEASURE);
+
+ AddInSignal();
+ AddOutSignal();
+ AddOutSignal();
+}
+
+rfftw::~rfftw()
+{
+ fftwf_free(infft);
+ fftwf_free(outfft);
+ fftwf_destroy_plan(p);
+}
+
+
+void rfftw::m_signal(int n, float *const *in, float *const *out)
+{
+ //set output pointers
+ outreal = out[0];
+ outimag = out[1];
+
+ //if blocksize changed, we have to set a new plan for the fft
+ if (n!=bins)
+ {
+ bins=n;
+
+ //re-allocate fft buffers
+ fftwf_free(infft);
+ infft = fftwf_malloc(sizeof(float) * bins);
+ fftwf_free(outfft);
+ outfft = fftwf_malloc(sizeof(float) * bins);
+
+ //set plan, this might take a few seconds
+ //but you don't have to do that on the fly...
+ fftwf_destroy_plan(p);
+ p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_FORWARD,FFTW_MEASURE);
+ }
+
+ CopySamples(infft,in[0],n);
+
+ //execute
+ fftwf_execute(p);
+
+ //Copy samples to outlets
+ CopySamples(outreal,outfft,n/2);
+ std::reverse_copy(outfft+n/2+1,outfft+n,outimag+1);
+
+ //why do we have to invert the samples???
+ for (int i = n/2+1; i!=0;--i)
+ {
+ *(outimag+i)=-*(outimag+i);
+ }
+
+}
+
diff --git a/tbext/source/rifftw~.cpp b/tbext/source/rifftw~.cpp
new file mode 100644
index 0000000..ee6f126
--- /dev/null
+++ b/tbext/source/rifftw~.cpp
@@ -0,0 +1,161 @@
+/* Copyright (c) 2004 Tim Blechmann. */
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */
+/* WARRANTIES, see the file, "COPYING" in this distribution. */
+/* */
+/* */
+/* rifftw~ is doing the same as rifft~, but it's based on the fftw library, */
+/* that is much faster that pd's internal fft ... */
+/* */
+/* */
+/* rifftw~ uses the flext C++ layer for Max/MSP and PD externals. */
+/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */
+/* thanks to Thomas Grill */
+/* */
+/* */
+/* */
+/* This program is free software; you can redistribute it and/or */
+/* modify it under the terms of the GNU General Public License */
+/* as published by the Free Software Foundation; either version 2 */
+/* of the License, or (at your option) any later version. */
+/* */
+/* See file LICENSE for further informations on licensing terms. */
+/* */
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software */
+/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+/* */
+/* Based on PureData by Miller Puckette and others. */
+/* */
+/* */
+/* */
+/* coded while listening to: Caged/Uncaged */
+/* Sunny Murray: Hommage To Africa */
+/* */
+/* */
+
+
+
+#include <flext.h>
+
+#include "fftw3.h"
+#include <algorithm>
+
+#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401)
+#error upgrade your flext version!!!!!!
+#endif
+
+class rifftw: public flext_dsp
+{
+ FLEXT_HEADER(rifftw,flext_dsp);
+
+public: // constructor
+ rifftw();
+ ~rifftw();
+
+protected:
+ virtual void m_signal (int n, float *const *in, float *const *out);
+
+ fftwf_plan p; //fftw plan
+ int bins; //number of bins
+ float * inreal; //pointer to real input
+ float * inimag; //pointer to imaginary input
+
+ fftwf_complex * incomplex;
+
+ //float * infft; //array fftw is working on
+ float * outfft; //array fftw uses to output it's values
+
+
+ private:
+};
+
+
+FLEXT_LIB_DSP("rifftw~",rifftw);
+
+rifftw::rifftw()
+ :bins(64)
+{
+ //get ready for the default blocksize
+ // infft = fftwf_malloc(sizeof(float) * bins);
+ outfft = fftwf_malloc(sizeof(float) * bins);
+
+
+ incomplex = fftwf_malloc(sizeof(fftwf_complex) * bins);
+
+
+ // p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_BACKWARD,FFTW_MEASURE);
+ p=fftwf_plan_dft_c2r_1d(bins,incomplex,outfft,FFTW_BACKWARD,FFTW_MEASURE);
+
+ AddInSignal();
+ AddInSignal();
+ AddOutSignal();
+}
+
+rifftw::~rifftw()
+{
+ // fftwf_free(infft);
+ fftwf_free(outfft);
+ fftwf_free(incomplex);
+ fftwf_destroy_plan(p);
+}
+
+
+void rifftw::m_signal(int n, float *const *in, float *const *out)
+{
+ //set output pointers
+ inreal = in[0];
+ inimag = in[1];
+
+ //if blocksize changed, we have to set a new plan for the fft
+ if (n!=bins)
+ {
+ bins=n;
+
+ //re-allocate fft buffers
+ // fftwf_free(infft);
+ // infft = fftwf_malloc(sizeof(float) * bins);
+ fftwf_free(outfft);
+ outfft = fftwf_malloc(sizeof(float) * bins);
+
+ fftwf_free(incomplex);
+ incomplex = fftwf_malloc(sizeof(fftwf_complex) * bins);
+
+ //set plan, this might take a few seconds
+ //but you don't have to do that on the fly...
+ fftwf_destroy_plan(p);
+ //p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_BACKWARD,FFTW_MEASURE);
+ p=fftwf_plan_dft_c2r_1d(bins,incomplex,outfft,FFTW_BACKWARD,FFTW_MEASURE);
+
+ }
+
+ //Copy samples to the fft
+ // CopySamples(infft,inreal,n/2);
+ // std::reverse_copy(inimag,inimag+n/2,infft+n/2);
+
+
+ /*
+ //why do we have to invert the samples???
+ for (int i = n/2+1; i!=n;++i)
+ {
+ *(infft+i)=-*(infft+i);
+ }
+ */
+
+ for (int i=0;i!=n/2;++i)
+ {
+ incomplex[i][0]=inreal[i];
+ incomplex[i][1]=-inimag[i];
+ }
+
+ //execute
+ fftwf_execute(p);
+
+ CopySamples(out[0],outfft,n);
+
+}
+