2

Possible Duplicate:
Real time pitch detection
Determine the audio frequency of sound received via the microphone

I'm developing my own android guitar tuner. Here I will have to use the guitar note frequency. Therefore, I want to know how to convert the sound coming through the mic port into its frequency in android?

Community
  • 1
  • 1
Sahan De Silva
  • 441
  • 8
  • 21

2 Answers2

1

You will need a pitch estimation algorithm (there have been many published, such as autocorrelation, ASDF/AMDF, cepstral processing, harmonic product spectrum, RAPT, YAAPT, etc.). Frequency estimation alone is not suitable for guitar tuning, as note pitch is different from spectral frequency.

hotpaw2
  • 68,014
  • 12
  • 81
  • 143
  • Am gonna store all the frequency values of the guitar notes, so that when the tuner captures a sound with a particular frequency which is similar to a frequency value stored in the device, it has to inform the user. So, if I can convert the sound coming from the mic port into its frequency value, I can get that value into a variable and match with the already stored frequency values. – Sahan De Silva Jan 19 '12 at 15:38
  • Frequency value of a guitar note (pitch), and the particular frequency value of sound captured (audio spectrum) are not the same thing. So your table will have to contain much more data than one frequency per guitar note. – hotpaw2 Jan 19 '12 at 16:17
  • I don't get it..What should I include more in the table other than the frequency value of the guitar note? – Sahan De Silva Jan 19 '12 at 17:50
  • More than one combination of audio frequencies sound like the exact same guitar note pitch frequency, as a guitar sounds very different from a pure sine wave generator. – hotpaw2 Jan 19 '12 at 20:15
  • Can you provide me an example? Because am actually new to this language... So I got to study the whole multimedia API to implement this application... – Sahan De Silva Jan 20 '12 at 01:14
  • 2
    The subject to read would be something like musical psychoacoustics, or the physics of musical instruments. Nothing to do with mobile programming outside of DSP. – hotpaw2 Jan 20 '12 at 02:52
0

EDIT: link dead ---This problem is already solved here---

I shall summarize the paper :

  1. Record stuff :

        int minSize = AudioRecord.getMinBufferSize(sampleRate,AudioFormat.
        CHANNEL_CONFIGURATION_MONO,
        AudioFormat.ENCODING_PCM_16BIT);
        AudioRecord audioInput = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate,
        AudioFormat.CHANNEL_CONFIGURATION_MONO,
        AudioFormat.ENCODING_PCM_16BIT);
        minSize);
        ...
        short[] buffer = new short[readSize];
        audioInput.startRecording();
        audioInput.read(buffer, index, readSize); // record data from mic into buffer
    
  2. Anayze the frequency using FFT.

I'd say you record about 4 seconds of apply FFT on it. Like hotpaw2 says you have to use pitch estimation algorithms to determine the range of frequencies in recorded sound from the strum.

Reno
  • 32,851
  • 11
  • 85
  • 99
  • Long time since you posted this answer, but your link is 404 – DroidDev Dec 04 '13 at 11:57
  • Oh that's unfortunate - for the FFT part you can check this answer : http://stackoverflow.com/questions/5774104/android-audio-fft-to-retrieve-specific-frequency-magnitude-using-audiorecord – Reno Dec 04 '13 at 13:41
  • Thnx a lot for reply, I was looking for a proper solution with proper code. Because, as i am new to android, it might take me while to wrap my head around this. already reading that thread. – DroidDev Dec 04 '13 at 13:44