I was thinking of something like this the other day.
I'm not sure how to get the notes from the frequencies.
Based on, and combination of, some of the Minim examples. It will highlight the frequency with the highest amplitude with a blue line.
Quote:
import ddf.minim.*;
import ddf.minim.analysis.*;
AudioInput in;
FFT fft;
int highest=0, bsize=512;
//float[] strings = new float[6];
void setup() {
size(512, 200);
// always start Minim before you do anything with it
Minim.start(this);
// get a line in from Minim, default bit depth is 16
in = Minim.getLineIn(Minim.MONO, bsize, 44100);
//Create a new FFT
fft = new FFT(in.left.size(), 44100);
fft.window(FFT.HAMMING); //Choose a windowing method
//fft.window(FourierTransform.NONE);
}
void draw() {
background(0);
stroke(255);
fft.forward(in.left);
highest=0;
for(int n = 0; n < fft.specSize(); n++) {
// draw the line for frequency band n, scaling it by 4 so we can see it a bit better
line(n, height, n, height - fft.getBand(n)*4);
//find frequency with highest amplitude
if (fft.getBand(n)>fft.getBand(highest))
highest=n;
}
//Highlight frequency with highest amplitude
stroke(0,0,255);
line(highest, height, highest, height - fft.getBand(highest)*4);
/* Guitar strings from howstuffworks.com
strings[0] = fft.getFreq(82.4); //E
strings[1] = fft.getFreq(110.0); //A
strings[2] = fft.getFreq(146.8); //D
strings[3] = fft.getFreq(196.0); //G
strings[4] = fft.getFreq(246.9); //B
strings[5] = fft.getFreq(329.6); //E
*/
// draw the audio waveforms
for(int i = 0; i < in.bufferSize() - 1; i++) {
line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
}
}
void stop() {
// always close Minim audio classes when you are done with them
in.close();
super.stop();
}