tags:

views:

702

answers:

2

I am trying to make a small music app on the iphone. I want to have an octave a piano which will respond to touches and play the key or keys that the user touches. How would i be able to get two or more sounds to play at the same time so it sounds like a chord? I tried using AVFoundation but the two sounds just play one after the other.

+2  A: 

You would have to use AudioQueueServices. The docs are here:

Apple.com - AudioQueueServices Reference

Essentially you would have to write some code to open up multiple outputs, and then prime the queue and have them block before AudioQueueStart(AudioQueueRef aq) until everything was primed and ready and then let them go.

AVAudioPlayer isn't really good enough for this sort of thing, unfortunately.

Jeffrey Forbes
A: 

If you create multiple AVAudioPlayers you can play them at the same time, and they will mix per the restrictions outlined in the documentation (not all file types can be played simultaneously).

If you allocate them first, then play them in order, they will play at virtually the same time.

If you need absolutely perfect timing, use the AudioQueue as described above or use OpenAL.

Jeff