Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android process audio for guitar tuner [closed]

What is the best way to process audio so I can output what note is being played? I am creating a guitar tuner for a college assignment and I am new to Android development.

I have seen the Android example on recording sounds from the Google API, but I was wondering where to go from there?

I understand I have to do a Fourier Transform, or something, to get the frequency, just wondering if anybody has any advice on how to do this?

Once we can get the correct frequency displayed on screen we will have the bulk of our project done.

Thanks for any help.

like image 812
Ayohaych Avatar asked Feb 06 '13 23:02

Ayohaych


3 Answers

If you're never done Android development and have little or no experience with digital signal processing and the Fourier transform, you're tackling a difficult challenge.

On the other hand, if you can use an existing library for your assignment, as anthropomo suggested, you may have a good chance to pull it off.

However, if your professor won't let you use an existing library, you'll need to solve the following difficult problems:

How does your program automatically find the fundamental frequency of the note being played? Take a look at this frequency/frequency_decibelMagnitude plot of a real classical acoustic guitar playing an E2 note. Observe that the fundamental frequency (82.4 Hz) is attenuated about 17 decibels (17 dB) below the first harmonic (the first harmonic is at 164.8 Hz).

GuitarE2frequency_decibelMagnitude

Below is a closeup of the same plot, where you can see the fundamental peak more clearly:

GuitarE2frequency_decibelMagnitudeCloseup

The fundamental frequency being attenuated 17 dB below the first harmonic is a large attenuation. Below is the same E2 note spectrum, but now it's plotted on a linear frequency-magnitude axis (the vertical axis is now linear frequency magnitude instead of decibel frequency magnitude). Now you can see more clearly how far below the first harmonic the fundamental frequency peak really is.

GuitarE2frequency_linearMagnitudeCloseup

Your program will have to automatically detect the 17 dB attenuated fundamental at 82.4 Hz, but how do you do that in the general case where your program won't know ahead of time which note the user is playing on his guitar?

The above frequency spectrum is for E2 on a classical acoustic guitar. How does the spectrum differ for E2 on a steel string guitar? What about E2 on an amplified electric guitar? How will your program deal with the differences between those different spectra?

The problem is not trivial. The question is how much time do you have for this assignment, and what will your professor consider to be a completed assignment.

This reference gives deeper understanding: Musical instrument spectra to 102.4 KHz

You can plot frequency spectra and hear guitar notes E2 to Bb5, here: Musical instrument spectrum

like image 113
Babson Avatar answered Nov 16 '22 01:11

Babson


Do not use a bare FFT magnitude or other frequency peak estimator. They will give you very bad/wrong results for the lower note strings of most guitars. Musical pitch is a human psychoacoustic perception phenomena, very often not the same as FFT frequency (except for pure sinusoidal tones unlike those produced by real stringed instruments).

Google "pitch detection" and "pitch estimation" methods instead. Some possibilities include weighted auto-correlations, AMDF, ASDF, cepstrum/cepstral analysis, harmonic product spectrum analysis, and composite algorithms such as RAAPT and YAPT. References to several academic papers on some of these estimator algorithms might be on my web page: http://www.nicholson.com/rhn/dsp.html#1

like image 21
hotpaw2 Avatar answered Nov 15 '22 23:11

hotpaw2


If your instructor is okay with you using a library for the audio processing, here is the source of a complete android guitar tuner app using libpd:

https://github.com/nettoyeurny/Making-Musical-Apps/tree/master/android/GuitarTuner

To use it, you will also need to learn the basics of the Pure Data audio synthesis programming language. The tools needed for a tuner are not too extensive, and are laid out in the above app. Obviously you would need to do some work to make this your own work.

Here is a very good intro to using Pure Data:

http://en.flossmanuals.net/pure-data/

like image 4
anthropomo Avatar answered Nov 16 '22 00:11

anthropomo