All   Archive   Code   News   Projects  


My name is Stephen Schieberl. I live in the woods near Portland, Oregon. Hit me up to work together.

Ban the Rewind?


Pictured: The Kiss CinderBlock displays live mic input in the time (top) and frequency (bottom) domains PLEASE CHECK OUT THIS PAGE FOR THE NEW VERSION: Cinder excels in graphics performance and general data crunching, but its audio support has not been up to par with the rest of the package. This has been noted by its authors and a new API is in the works. A sticking point has been a complete lack of audio input and fast Fourier transform (FFT) functionality on Windows. Unlike the rest of the package, FFT duties were handled by a Mac-specific library. I've been working on a couple Cinder-based projects at the day job and hit a point where I absolutely needed audio input and FFT. I wrote a framework-agnostic audio input class for Windows 7 and brought that into my project. It works great for streaming data to file, etc, but I still needed something to perform FFT to visualize the data in real time. I'd already spent a good amount of time working on an audio analyzer for Android in native code and felt ready to tackle an original-from-the-ground up suite. While it was a great learning experience, I wasn't getting the accuracy I wanted, despite decent performance. I decided to cut my losses and implement a good package with an open license, hence KissFFT . I took a look at how it was implemented on openFrameworks , since that was the last time I used it, and opted to sketch out my class based on that. I kept the public methods intact (thus keeping it familiar for anyone migrating from ofx) and implemented some Cinder-y updates, like using shared_ptr's and stuff. I've packaged up the first beta release and am hosting it on this page for now. I'll add it to Google code as soon as it gets some more testing. Download KissFFT for Cinder KissFFT 0.0.5 beta The zip includes four sample projects for Visual Studio 2010 demonstrating FFT on generated audio, audio loaded from a file, live mic input (Windows only), and tempo detection. The root folder of the zip is named "blocks", which should tell you where to place the project relative to your Cinder directory. Here's a quick, truncated run down on implementing the block. The following code creates an instance of the FFT class, fills a buffer, sends it to the analyzer, and reads the results in the frequency domain. // Create instance of analyzer Kiss mFft; // Create buffer float * mBuffer = new float[1024]; // TODO: Fill buffer with generated // or input data -- see example // Pass the data to be analyzed mFft.setData(mBuffer); // Analyze and acquire transformed data float * mData = mFft.getAmplitude(); // Iterate through frequencies and report their volumes int mSampleSize = mFft.getBinSize(); for (int n = 0; n < mSampleSize; n++) { console() << "Freq: " << n << ", Vol: " << mData[n] << "\n"; } It should be noted that the sample size will not necessarily (usually never) provide an index for every frequency in your sample rate (eg, 0hz - 22050hz). You'll have to scale the values if you want to get hz-accurate values (not always critical for visualizers). A 1:1 scale will display the frequencies linearly. It's usually more useful to scale the values logarithmically due to the nature of audio. The example included in the package shows you how to do this.