I want to display audio waveforms color-coded in each part by the local frequency content. Basically exactly what Serato/Traktor or any other DJ software does where you can look at the sound and tell what frequencies are there. It looks like this:
So essentially, I will do an FFT to get frequencies at whatever bin-width I specify, but can anyone refer me to some code (preferably c) that would be useful in actually DRAWING it?
Let's try a real answer this time. :-)
The problem is too complex to give a complete solution with all the code in this space, but I will use pseudocode and assume you have some library that can window a block of samples and compute FFTs.
It's similar to building a waveform display. When you build your waveform display, you determine how many samples "fit" into a single horizontal pixel at the current zoom level, where they start given your X-scroll position, calculate the minimum and maximum sample value for that segment and gives you the min/max Y position for that waveform pixel. (This is actually a bit simplified, I've written waveform rendering code back in the day but this is a good approximation.)
To color your waves with frequency, you want to preproces the wave data using a short time FFT with smallish bins, and for each bin determine what the predominant frequency is and then map it to a color on the spectrum from red to violet.
Let's say your audio samples in an array called
samples
, here's the pseudo code.This will give you an array of RGB which you can zoom in and out of as your zoom your waveform display in and out. As you zoom you probably want to average the RGB values of adjancent frames to give you an overall view.
I hope this helps.