Obtain the audio frequence across the microphone

Nibbie
Posts: 4
Joined: 2009.09
Post: #1
Hello,
I am trying to obtain the audio frequency across the microphone of the iphone.
I don't want to record audio (i have seen a lot of examples about it), I only want get sounds and obtain the frequency (I have not seen anything about this).
How can I do it? Could do it with OpenAL?

The class CSListener has a attribute named format of type AudioStreamBasicDescription. The structure AudioStreamBasicDescription has a attribute named mSampleRate, might I use mSampleRate to obtain the frequency of a sound?

Regards.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #2
No, mSampleRate contains how many samples per second the sound is taken into the machine at. Typically you'll use/see 44100 for that, which is the ever-popular 44.1 kHz sample rate. It has nothing to do with the frequency of the sound (other than double the upper limit of the digitally represented frequency).

You'll need to use RemoteIO and create a small buffer to read samples into if you want to do it in real-time. Here's a blog article on how to get started with RemoteIO on iPhone. It's not easy to understand the sparse and poorly written Apple docs, but RemoteIO isn't too bad once you figure it out. You might prefer to "record" audio instead, and instead of saving it to disk, simply analyze the samples and discard them. It wouldn't be exactly real-time, but it'd be close, and it'd likely be easier to get going than RemoteIO.

Once you have that then you'll need to use some Digital Signal Processing (DSP) techniques to analyze the signal. Google for pitch detection algorithm. It's not easy, if you're new to it.
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.09
Post: #3
thanks for reply.
Already, I have created a buffer to read samples. Now I have to use DSP techniques to analyze the signal. A DSP technique could be fast fourier transform (FFT)???
If is it, please can you say me where find information about it?
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #4
There are three ways I can think of to do pitch detection:

1) Count zeroes, which is simply counting how many times per second the waveform crosses it's midpoint. You'd want to use a moving average for this to filter out high frequencies. This is not a very accurate method, and not for all purposes, but I've used it with good success in the past. Definitely the most simple.

2) FFT. Here's a good article on it. I've never used FFT for pitch detection but I can imagine it'd work. I guess you'd find the bin with the highest amplitude. Then you'd still run the risk of a narrow band frequency fitting in between bins, but hey, it might work just fine. I don't know...

3) Autocorrelation. I'm sure you can find some already made implementations. Try googling: autocorrelation filetype:c

Also be sure to google: pitch detection algorithm
Quote this message in a reply
Post Reply