1
votes

I am trying to create a processing app that is able to detect musical notes from an instrument(guitar). If, for example, the open "A" note is played, I would like to do something based on that, like show the note on the screen or show an image.

I am stuck and not sure if I am doing it right or how to proceed. From what I understand, I need to get the fundamental frequency? If so, how do I get that? It seems like when I play a note right now, the sketch shows a bunch of different frequencies as the note progresses. Am I supposed to only try to get the beginning of the note or something?

If you can't tell, I'lm a newb, so be gentle ;) Here's what I have so far:

/* sketch to measure frequencies */

import ddf.minim.analysis.*;
import ddf.minim.*;

Minim minim;
AudioInput in;
FFT fft;

void setup()

{
  size(512, 200, P3D);
  minim = new Minim(this);

  in = minim.getLineIn(Minim.STEREO, 2048);

  // 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 512. see the online tutorial for more info.
  fft = new FFT(in.bufferSize(), 44100);
}

void draw()
{
  background(0);
  stroke(255);
  // perform a forward FFT on the audip that's coming in
  fft.forward(in.mix);
  for(int i = 0; i < fft.specSize(); i++)
  {
    // draw the line for frequency band i, scaling it by 4 so we can see it a bit better
    line(i, height, i, height - fft.getBand(i) * 4);
    //print out the frequency. Am I supposed to be multiplying the value by 2048?
    println( (fft.getFreq(i) * 2048)); 
  }

  fill(255);

}


void stop()
{
  // always close Minim audio classes when you finish with them
  in.close();
  minim.stop();
  super.stop();
}
1
I think you need to do some more research on the basics of pitch detection. Try wikipedia, other questions on SO, or this blog post: blog.bjornroche.com/2012/07/…Bjorn Roche
Thanks Bjorn. This looks like a great article. I will read it and try to learn as much theory as possible. I don't code in C however. Is there any advice you can give me that will move me forward on this processing wise?Roman Epicnerd Sharf
The C code samples in the post are very similar to anything you'd do in Java/Processing, and the concepts are identical.Bjorn Roche

1 Answers

2
votes

Don't use a bare FFT for guitar pitch estimation. Even a windowed one. Don't use the bjorneroche blog post above.

An FFT peak detector works very poorly for sounds that are mostly made up of overtones (such as found in most music). Use a more robust pitch detection/estimation method instead, such as RAPT, YAAPT, autocorrelation variants, harmonic product spectrum, or cepstral/cepstrum methods instead.