I'd like to play a synthesised sound in an iPhone. Instead of using a pre-recorded sound and using SystemSoundID to play an existing binary, I'd like to synthesise it. Partially, that's because I want to be able to play the sound continuously (e.g. when the user's finger is on the screen) instead of a one-off sound sample.
If I wanted to synthesise a Middle A+1 (A4) (440Hz), I can calculate a sine wave using sin(); what I don't know is how to arrange those bits into a packet which CoreAudio can then play. Most of the tutorials that exist on the net are concerned with simply playing existing binaries.
Can anyone help me with a simple synthesised sine sound wave at 440Hz?
What you want to do it probably to setup an AudioQueue. It allows you to fill a buffer with synthesized audio data in a callback. You would setup the AudeioQueue to run in a new thread as such:
You callback method AudioQueueCallback will then be called whenever the AudioQueue needs more data. Implement with something like:
Many of the audio technologies allow for data to be passed in instead of a sound file. AVAudioPlayer, for example, has:
However, I am not sure how you would pass in a data ptr, start the sound, and then keeping it looping by passing in other data ptrs, or repeating the same, etc.
Davide Vosti's link to http://lists.apple.com/archives/coreaudio-api/2008/Dec/msg00173.html no longer works, since Apple lists seem to be unresponsive. Here is Google's cache for completeness.