Hello Josep,<br><br><div class="gmail_quote">2008/4/14 Josep Comajuncosas &lt;<a href="mailto:josep.comajuncosas@gmail.com">josep.comajuncosas@gmail.com</a>&gt;:<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&nbsp;</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>&nbsp;&nbsp;&nbsp; <a href="http://sv.mazurka.org.uk/src/MazurkaTransformer.cpp">http://sv.mazurka.org.uk/src/MazurkaTransformer.cpp</a><br>&nbsp;&nbsp;&nbsp; <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&#39;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 &quot;MazurkaTransformer.h&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &lt;iostream&gt;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &lt;iomanip&gt;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &lt;math.h&gt;</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;">&nbsp;&nbsp; MazurkaTransformer bumblebee;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; 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;">&nbsp;&nbsp; int i;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; double signal[SIZE];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp; 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;">&nbsp;&nbsp; for (i=0; i&lt;SIZE; i++) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; signal[i] = sin(2.0 * M_PI * 5 * i / SIZE);&nbsp; // putting energy in bin 5</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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;">&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp; for (i=0; i&lt;SIZE; i++) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bumblebee.signalNonCausal(i) = signal[i] * window[i];</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp; bumblebee.doTransform();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp; for (i=0; i&lt;SIZE; i++) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; &quot;bin &quot; &lt;&lt; i &lt;&lt; &quot;:&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt; setiosflags(ios::fixed)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt; setprecision(3)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt; &quot;\treal= &quot; &lt;&lt; setw(7) &lt;&lt; bumblebee.getSpectrum(i).re</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt; &quot;\timag= &quot; &lt;&lt; setw(7) &lt;&lt; bumblebee.getSpectrum(i).im</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt; &quot;\tmag= &quot;&nbsp; &lt;&lt; setw(7) &lt;&lt; bumblebee.getSpectrumMagnitude(i)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt; &quot;\n&quot;;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp; 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;">&nbsp;&nbsp;&nbsp; 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:&nbsp; real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 1:&nbsp; real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 2:&nbsp; real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 3:&nbsp; real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 4:&nbsp; real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 4.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 4.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 5:&nbsp; real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 8.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 8.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 6:&nbsp; real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 4.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 4.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 7:&nbsp; real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 8:&nbsp; real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 9:&nbsp; real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 10: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 11: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 12: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 13: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 14: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 15: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 16: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 17: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 18: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 19: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 20: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 21: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 22: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 23: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 24: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 25: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 26: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp; -4.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 4.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 27: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp; -8.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 8.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 28: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp; -4.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 4.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 29: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bin 30: real=&nbsp;&nbsp; 0.000&nbsp;&nbsp; imag=&nbsp;&nbsp; 0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bin 31: real=&nbsp; -0.000&nbsp;&nbsp; imag=&nbsp; -0.000&nbsp;&nbsp; mag=&nbsp;&nbsp; 0.000</span><br><br>-=+Craig<br><br><br>