Jeff Tung
Jeff Tung

Reputation: 99

Get frequency from guitar input in real time

I'm trying to get input from plug-in guitar, get the frequency from it and check whether the users is playing the right note or not. Something like a guitar tuner (I'll need to do a guitar tuner as well).

My first question is, how can I get the frequency of guitar input in real time?

and is it possible to do something like :

if (frequency == noteCFrequency)
{
//print This is a C note!!
}

I'm now able to get input from the soundcard, record and playback the input sound already.

Upvotes: 2

Views: 3860

Answers (3)

Bjorn Roche
Bjorn Roche

Reputation: 11469

The other answers don't really explain how to do this, they just kinda waive their arms. For example, you would have no idea from reading those answers that the output of an FFT is a set of complex numbers, and you wouldn't have any clue how to interpret them.

Moreover FFT is not even the best available method, although for your purposes it works fine and most people find it to be the most intuitive. Anyway, this question has been asked to death, so I'll just refer you to other questions on SO. Not all apply to C#, but you are going to need to understand the (non-trivial) concepts first. You can find an answer to your question by reading answers to these questions and following the links.

frequency / pitch detection for dummies

Get the frequency of an audio file in every 1/4 seconds in android

How to detect sound frequency / pitch on an iPhone?

How to calculate sound frequency in android?

how to retrieve the different original frequency in each FFT caculating and without any frequency leakage in java

Upvotes: 1

DasKrümelmonster
DasKrümelmonster

Reputation: 6060

For an implementation of FFT in C# you can have a look at this. Whiel I think that you do not need to fully understand the FFT to use it, you should know about some basic limitations:

  1. You always need a sample window. You may have a sliding window but the essence of being fast here is to take a chunk of signal and accept some error.
  2. You have "buckets" of frequencies not exact ones. The result is something like "In the range 420Hz - 440Hz you have 30% of the signal". (The "width" of the buckets should be adjustable)
  3. The window size must contain a number of samples that is a power of 2.
  4. The window size must be at least two wavelengths of the longest wavelength you want to detect.
  5. The highest frequency is given by the sampling rate. (You don't need to worry about this so much)
  6. The more precise you want your frequencies separated, the longer shall your window be.

Upvotes: 1

Didac Perez Parera
Didac Perez Parera

Reputation: 3824

You must compute the FFT -Fast Fourier Transform- of a piece of signal and look for a peak. For kinds of FFT, window type, window size... you must read some documentation regarding signal processing. Anyway a 25 ms window is OK and use a Hamming window, for example. On the net there is lot of code for computing FFT. Good luck!

Upvotes: 0

Related Questions