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

10,547

Solution 1

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.

Solution 2

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.

Solution 3

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.

Share:
10,547
Albert Renshaw
Author by

Albert Renshaw

CEO, Apps4Life, LLC.

Updated on June 15, 2022

Comments

  • Albert Renshaw
    Albert Renshaw almost 2 years

    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?

  • hotpaw2
    hotpaw2 over 12 years
    Pitch is not the same as frequency. A note can have a missing fundamental.
  • Mathias
    Mathias over 12 years
    @hotpaw2: Interesting. Shows how much I know about music ;). In case anyone else is unclear on the difference, the following article spells it out quite nicely: emusician.com/tutorials/emusic_pitch_vs_frequency
  • Ravi
    Ravi over 12 years
    Hey, do you have a weblink for the audioTouch app?
  • hotpaw2
    hotpaw2 over 12 years
    Look under Development Resources : Sample Code on developer.apple.com
  • Chris
    Chris almost 10 years
    It's actually called aurioTouch
  • Gabriel Jensen
    Gabriel Jensen almost 10 years
    @e.James The article at emusician moved to: emusician.com/gear/1332/pitch-vs-frequency/36924
  • pwcremin
    pwcremin almost 8 years