# Guitar Tuner Theory

This topic is 5042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am planning to implement a guitar tuner in C++ but i need some help to go in the correct direction. I understand the over all concept. I need to take in a sound recording for example 10 times every second and find the pitch of the wav form and then compare it against what is the known pitch of the the note the person wants to tune the guitar to. What kind of algorithm is best suited to this. Would there be some kind of filter algorithm that is needed to be run to clean out back ground noise ? Are there any other proceedures needed to prepare the sqçple sounds? Any advice would be much apprecited. Thanks Guys

##### Share on other sites
Get FFTW.

With a FFT you can transform amplitude(time) to amplitude(frequency). Finding the pitch is then simply iterating through an array looking for the maximum.

the routine you need

##### Share on other sites
Though you could do it with a fourier-transform, i think this would be overkill.
Search for 'Autocorrelation', that's what i would try. The idea is basically that you compare(multiply) your wave-data with a shifted copy of it. for each 'lag'-value you get a measure for the correlation. If you shift your wave-data one period your correlation should be high. so you can find the period of your wave-data by finding the biggest correlation. I hope that gets you started

Thies

##### Share on other sites
Either that, or just generate a pure waveform of whatever frequency your note is meant to be, scale it to be equal in amplitude to the incoming sound, and add it to the incoming sound. You'll get a resulting frequency which is the difference between the two, and if it's anywhere near in tune this frequency should be in the 10s of Hz, which you can then just sample directly at 100Hz or so to find out how close to 'in tune' your guitar is.

/end stream-of-conciousness. this may not work.

##### Share on other sites
I don't know other methods, but once I did this using Fourier Transform (FFTW as implementation). It was a bit hard because I never worked with sounds and FFT, but at the end I came out with something working (a little).
I used FMOD to record the sound, and then I processed it with FFTW that returns a buffer filled with coefficients. Using an equation on them you get the frequency of the sound. I tried with a diapason (<-don't know the english word) and it worked. With my guitar the result was not always correct, because sometimes it told 110hz or 220hz, other armonics of the 440hz of the A note, but there should be some alg. to filter out what you don't need.
If you want to have more infos you can look throught my previous posts where many people helped me. If you think it can help you I can send my code (but it is very bad designed and written) in a Dev-c++ project.

##### Share on other sites
When you get the basics working...:

My brother has a guitar tuner that (I think) takes into account the fact that the pitch changes as the note continues to sound. I _think_ his tuner locks onto the note a fraction of a second after it starts - which is presumably the pitch you tend to hear when playing.

If you use a FT to get a power spectrum, the pitch that you perceive isn't necessarily going to be at the frequency containing the highest power-density - it's probably offset a little bit because the ear/brain has its own frequency response. Maybe it's an insignificant effect... but I'd read up on it if I was doing this.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 27
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634100
• Total Posts
3015527
×