Sam
Sam

Reputation: 41

Playing multiple sounds simultaneously with AVAudioPlayer

Could someone help me with a function that fires multiple AVAudioPlayers at the same time? Right now I am trying to get a total of twelve AVAudioPlayers to fire at once if twelve buttons are activated, but there is a delay and it sounds like someone is running their finger down a piano instead of hitting all the keys at once.

I've looked at Audio Queue Services and can't understand how to actually implement that into code, but it says it can play synchronized sounds. I'm not sure sure how to set all of it up. I'm trying to remake a Tone Grid app.

Upvotes: 4

Views: 4882

Answers (2)

bentford
bentford

Reputation: 33416

Are you calling the method prepareToPlay on all 12 AVAudioPlayer instances. From the docs: "Calling this method, preloads the buffers and acquires hardware, to minimize delay."

See the AVAudioPlayer class reference.

Upvotes: 0

P i
P i

Reputation: 30734

Why don't you use http://www.hollance.com/2011/02/soundbankplayer-using-openal-to-play-musical-instruments-in-your-ios-app/

There you have a polyphonic player, beautifully coded and ready to rock!

I used it in my first app a while back: http://itunes.apple.com/gb/app/chordwheel-pro/id406836326?mt=8

Upvotes: 4

Related Questions