I'm trying to programm an electric tuner for my guitar with processing and the minim-library.
I thought the best way to do this is with a fft.
so I startet with this: I made a sineWave generator to test it and a fft in log mode.
public void setup() {
size(512, 200, P2D);
background(0);
// initialize Minim and catching the output
minim = new Minim(this);
out = minim.getLineOut(Minim.STEREO, 2048);
//making a sineWave generator
freq = 440;
sine = new SineWave(freq, 0.5f, out.sampleRate());
sine.portamento(200);
out.addSignal(sine);
//making a fft in log mode
fft = new FFT(out.bufferSize(), out.sampleRate());
fft.logAverages(55, 12)
}
but i don't understand the fft and the fft.logAverages() properly.
Is it right that now it starts with the frequency of 55 Hz and one octave is diveded into 12 parts?
And the next octave starts with 110 and ends at 220?
next i tryed something like this: going from 0Hz to 20000Hz and searching for the biggest amplitude
draw() {
highestAmp=0;
amplitude=0;
frequency = 0;
//searching from 0Hz to 20000Hz. getting the band, and from the band the frequency
for(int i = 0; i < 20000; i++) {
amplitude = fft.getFreq(i);
if (amplitude > highestAmp){
highestAmp = amplitude;
frequency = i;
}
}
//write the frequency on the screen
fill(255);
text(frequency,200,100);
}
but it doesn't work...
Where did I make the mistakes? Or is my concept wrong?
Thankfull for all advices
jo