tags:

views:

709

answers:

3

Can someone help me use the AudioQueue services on the iPhone to play a certain frequency (say, 440 Hz)? I've looked at the documentation, but I can't seem to figure out quite how to do it. Apple's sample code also isn't helping me too much.

Thanks!

A: 

ok, this is kinda lame, but if no one comes up with the real answer, you could just pre-record a sine wave and loop it. If it's cut well, it should play just fine. Of course this response would only work if you had only a few different frequencies to play.

Aftermathew
+2  A: 

/Developer/Examples/CoreAudio/SimpleSDK/DefaultOutputUnit has a sample of how to play a tone at a given frequency and sample rate.

I basically copied the code (also using a bit from this blog entry) and it worked with basically no change on the iPhone.

Ben Alpert
+1  A: 

It isn't hard at all to do this. Take a look at the AudioQueue examples. If you look at the code to play back an audio file, you're going to just do that, except without actually reading a file.

You just divide the sampling rate by your frequency, calculate a sine wave, and feed those values into the audioqueue in your playback callback function.

Mark Bessey