Hello Josep,<br><br><div class="gmail_quote">2008/4/14 Josep Comajuncosas <<a href="mailto:josep.comajuncosas@gmail.com">josep.comajuncosas@gmail.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>Hi,</div>
<div>well just this, does anyone have a nice working example of an FFT library implemented in the stk framework?</div>
<div>Thanks in advance</div>
<div>Josep M </div></blockquote></div><br>Not quite what you want, but close: I have a C++ interface for FFTW<br>(<a href="http://www.fftw.org">http://www.fftw.org</a>) which is probably the most efficient FFT library <br>
available for free.<br><br>Here is my C++ interface class to FFTW:<br> <a href="http://sv.mazurka.org.uk/src/MazurkaTransformer.cpp">http://sv.mazurka.org.uk/src/MazurkaTransformer.cpp</a><br> <a href="http://sv.mazurka.org.uk/include/MazurkaTransformer.h">http://sv.mazurka.org.uk/include/MazurkaTransformer.h</a><br>
which I use to make vamp plugins for the Sonic Visualiser<br>audio editor (<a href="http://www.sonicvisualiser.org">http://www.sonicvisualiser.org</a>).<br><br>The MazurkaTransformer::initialize function demonstrates the<br>
setup requried for running the FFTW transform, and the function<br>doTransform() does the actual work of calculating the transform<br>using FFTW's function called fftw_execute().<br><br>Example usage:<br><br><span style="font-family: courier new,monospace;">////////////////////////////////</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include "MazurkaTransformer.h"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <iostream></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include <iomanip></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <math.h></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#define SIZE 32</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">using namespace std;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">int main(void) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> MazurkaTransformer bumblebee;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> bumblebee.setSize(SIZE);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> int i;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> double signal[SIZE];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> double window[SIZE];</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for (i=0; i<SIZE; i++) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> signal[i] = sin(2.0 * M_PI * 5 * i / SIZE); // putting energy in bin 5</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> window[i] = 0.5 - 0.5 * cos(2.0 * M_PI * i / SIZE); // Hann window</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for (i=0; i<SIZE; i++) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> bumblebee.signalNonCausal(i) = signal[i] * window[i];</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> bumblebee.doTransform();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for (i=0; i<SIZE; i++) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> cout << "bin " << i << ":"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> << setiosflags(ios::fixed)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> << setprecision(3)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> << "\treal= " << setw(7) << bumblebee.getSpectrum(i).re</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> << "\timag= " << setw(7) << bumblebee.getSpectrum(i).im</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> << "\tmag= " << setw(7) << bumblebee.getSpectrumMagnitude(i)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> << "\n";</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return 0;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">/* compiling example:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> g++ -Iinclude MazurkaTransformer.cpp test.cpp -Lfftw/lib -lfftw3 -o test</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">*/</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"><br>/////////////////////////////////</span><br><br>Which produces the following printout (bin 0 = 0 Hz, bins 1-15 are the positive frequencies):<br><br><span style="font-family: courier new,monospace;">bin 0: real= -0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 1: real= -0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 2: real= 0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 3: real= 0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 4: real= 0.000 imag= 4.000 mag= 4.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 5: real= 0.000 imag= 8.000 mag= 8.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 6: real= 0.000 imag= 4.000 mag= 4.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 7: real= 0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 8: real= 0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 9: real= -0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 10: real= -0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 11: real= -0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 12: real= 0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 13: real= -0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 14: real= -0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 15: real= 0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 16: real= -0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 17: real= 0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 18: real= -0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 19: real= -0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 20: real= 0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 21: real= -0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 22: real= -0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 23: real= -0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 24: real= 0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 25: real= 0.000 imag= -0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 26: real= 0.000 imag= -4.000 mag= 4.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 27: real= 0.000 imag= -8.000 mag= 8.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 28: real= 0.000 imag= -4.000 mag= 4.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 29: real= 0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 30: real= 0.000 imag= 0.000 mag= 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 31: real= -0.000 imag= -0.000 mag= 0.000</span><br><br>-=+Craig<br><br><br>