tags:

views:

267

answers:

1

I am trying to made a musical iPhone application and I am having some problems playing looped samples.

I have read this question: audio-on-the-iphone

and several other posts and blogs in the web about the "RemoteIO"/AudioUnits framework but without success.

I have been able to do a sample application that plays a finite sound with a predefined duration (I am using a playbackCallback) but I need the sound to start playing with the user touches the screen and stop playing when the user lift the finger.

Any ideas?

Thanks in advance.

+1  A: 

Assuming your code is correct, you're probably omitting one (or more) of these steps:

  1. Stopping reading/writing at the wrong times (because you're likely writing 'a power of 2' samples per render call)
  2. Not providing a fade in/fade out (start at 10 ms fade out and adjust as desired)
  3. Not stopping write on a zero crossing
  4. not resetting the read position to 0 when the user lifts their finger - resuming in the middle of the sample
  5. Your samples are not properly trimmed to zero crossings at start, end, and/or loop positions
  6. Not resetting internal effects, filters, or convertors

You will not need all of these to avoid clicks.

Justin
I don't know if it is related but to avoid long start delays I am always "playing sounds", just with the buffer full of zeros. When I want to play something I just feed the buffer with my sampled sound and when I want to stop I just enter zeros. Is that correct?
Rafael Munoz
Yes, that is fine (though you will want to stop when you have long pauses because it is wasteful).
Justin
Just playing zeroes is fine, and I don't think it uses much CPU time, but it does prevent the device from going to sleep, which means that even if the screen is locked, you're still playing "sound" even if it is silent.
lucius