views:

45

answers:

1

Ok,

So I am trying to seamlessly loop together three sound files with the second file being looped against itself n times. Let's assume I can get them to loop seemlessly together in another program by butting them together. however when I use audioPlayerDidFinishPlaying delegate method of avaudioplayer there is a slight delay in the butting together (even with using the "prepareToPlay" method. The other bit of complexity is that the middle sound needs to continue looping n times AKA as long as the touchesDidEnd method has not been called, at which point the program would play the 3rd and final clip to end the sound "playlist."

As an example think an audience giving applause after a show. sound file A would contain the initial swell of applause, sound file 2 would contain a loopable sample of the crowd cheering at a continuous rate until the user lifts up on the button, at which time the program should kick into the 3rd sound file, which would be the applause of the crowd tailing off.

So my initial attempt using AVAudioPlayer seemed not quick enough to loop back to back without delay so I need another quicker way to do this, suggestions?

A: 

For the looping, check out the numberOfLoops property of AVAudioPlayer. Works better than trying to handle the loop logic yourself using the player's delegate.

As for fading smoothly from one looping sample to a 'tail' sample, that's going to be difficult to pull off with AVAudioPlayer. Probably your best bet is to start another player with the trailing sound file and use a timer to rapidly cross fade between the two using the volume property of each.

If that's not satisfactory (and I suspect it may not be) I don't think you'll have much choice but to drop down to the AudioQueue API to pull this off.

Art Gillespie
that's what I was afraid of, not looking forward to messing with audioqueue api. i did mess with number of loops last night and it did make the looping part seemless, but yes that is only half of the equation. Thanks, hoping someone else might pop in with an easier answer.
nickthedude