I've seen many questions on this forum regarding pitch detection for musical instruments (commonly guitar), and spent a while reading through the answers to create a basic implementation of auto-correlation to make an Android guitar tuner.
This is the algorithm I'm using (implemented in Java on an Android phone):
1) Record a short array of raw audio data from an Android phone's microphone at 48kHz sample rate 2) Apply a Hanning window to the raw audio data 3) Zero-pad the result to double the length (8192) 4) Apply auto-correlation with FFTs 5) Normalize the auto-correlation result 6) Get the periodicity from the peak bin indexes
My problem is that with an actual guitar it is not robust (around 50% accurate at best), and I don't know how to filter noise either (without any loud noise, just ambient white noise, it outputs garbage frequencies).
It fares much better when I whistle at it, or play a generated sine tone from a computer, but that's expected.
In my search for ways to improve my implementation, many answers (on this forum and others) usually point to using a better algorithm like YIN, but I think its more likely that I've made a mistake in my implementation.
Does anything seem obviously incorrect from the algorithm I posted? Are there tweaks I can apply?
And does anybody have any idea how I could filter out noise by using the auto-correlation result?
1) Increase the Android microphone sensitivty 2) Band-pass the raw data before the algorithm 3) Record more samples 4) ???
Thanks in advance.