Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAudio detect note/pitch/etc. iPhone xcode objective-c

I'm making an app on the iphone and I need a way of detecting the tune of the sounds coming in through the microphone. (I.e. A#, G, C♭, etc.) I assumed I'd use AVAudio but I really don't know and I can't find anything in the documentation..

Any help?

like image 209
Albert Renshaw Avatar asked Oct 01 '11 21:10

Albert Renshaw


3 Answers

Musical notes are nothing more than specific frequencies of sound. You will need a way to analyze all of the frequencies in your input signal, and then find a way to isolate the individual notes.

Finding frequencies in an audio signal is done using the Fast Fourier Transform (FFT). There is plenty of source code available online to compute the FFT from an audio signal. In particular, oScope offers an open-source solution for the iPhone.

Edit: Pitch detection seems to be the technical name for what you are trying to do. The answers to a similar question here on SO may be of use.

like image 143
e.James Avatar answered Sep 29 '22 18:09

e.James


There's nothing built-in to the iOS APIs for musical pitch estimation. You will have to code your own DSP function. The FFTs in the Accelerate framework will give you spectral frequency information from a PCM sampled waveform, but frequency is different from psycho-perceptual pitch.

There are a bunch of good and bad ways to estimate frequency and pitch. I have a long partial list of various estimation methods on my DSP resources web page.

You can look at Apple's aurioTouch sample app for an example of getting iOS device audio input and displaying it's frequency spectrum.

like image 41
hotpaw2 Avatar answered Sep 27 '22 18:09

hotpaw2


Like @e.James said, you are looking to find the pitch of a note, its called Pitch Detection. There are a ton of resources at CCRMA, Stanford University for what you are looking for. Just google for Pitch Detection and you will see a brilliant collection of algorithms. As far as wanting to find the FFT of blocks of Audio Samples, you could use the built-in FFT function of the Accelerate Framework (see this and this) or use the MoMu toolkit. Using MoMu has the benefit of it's functions decomposing the audio stream into samples for you and easy application of the FFT using it's own functions.

like image 42
Ravi Avatar answered Oct 01 '22 18:10

Ravi