I want a sketch which can analyse the dominant frequency band of a sound. So for example, with a kick drum it would analyse all the frequencies and tell me the low frequencies are the loudest in the spectrum. At the moment I have got a spectogram, but it shows all frequencies. How can I adapt this so it tells me which band has the most gain in it please?
int xPos = 0;
int hueLimit = 160;
// create a screen width=512, height=256
// create a minim audio application object
minim = new Minim(this);
// create a file object (can be a MP3 file or a WAV file)
//jingle = minim.loadFile("jingle.mp3", 512);
jingle = minim.loadFile("Drum_Loop_01.wav", 512);
// loop the file
// create an FFT object that has a time-domain buffer the same size as jingle's sample buffer
// note that this needs to be a power of two
// and that it means the size of the spectrum will be 1024.
// see the online tutorial for more info.
fftLin = new FFT(jingle.bufferSize(), jingle.sampleRate());
// calculate the averages by grouping frequency bands linearly. use 30 averages.
// perform a forward FFT on the samples in jingle's mix buffer
// note that if jingle were a MONO file, this would be the same as using jingle.left or jingle.right
You'll get both by decreasing the buffer size e.g.: jingle = minim.loadFile("Drum_Loop_01.wav", 128);
Some of that code doesn't make much sense. sin() and cos() take a value in radians so when you feed then with an xPos that's being incremented by 1 every time you're covering an entire circle in 6 frames (2 * pi being one circle). There's also no reason to reset xPos when it's greater than width. I'd have thought it would make more sense for xPos to be a float and increase it by around 0.2 each frame but maybe how it is is how you want it.