Iphone – Play a sound of indefinite duration on the iPhone

audiococoa-touchiphone

I need to play a "horn" sound when a user touches the screen.

The horn sound needs to play for as long as the user's finger remains in contact with the screen.

The ending of the sound effect will be different. Imagine the horn "petering" out at the end as airflow decreases.

Would I have to stitch 2 sound files together? Do I need to use Remote I/O since the timing will be so critical?

This library looks like a possibility:
http://www.surina.net/soundtouch/

It seems like I could play a sound indefinitely, but I haven't implemented it yet, so I am not sure.

I feel like this would be a common problem in game programming, but I have little experience in that area.

I've never used audio to this extent before so I am at a loss of where to begin. (I have only required the use of AVAudioPlayer in my apps until now).

Any suggestions on a library to use or at a technology to use would be great.

Best Answer

To make it realistic, you need three sounds:

  1. Attack. This is the start of the sound; it is the most important part of the sound, as it is the part that the brain uses to identify what the sound is. The sound then decays slightly, and becomes the...

  2. Sustain. This is the part of the sound that you will need to loop continuously until the user lifts his finger. You will have to craft this part of the sound carefully to avoid "ticks" or other artifacts while looping the sound.

  3. Release This is the sound that you play when the user lifts his finger.

There are audio tools such as Audacity that will make the creation of these three files easier. You can use an actual recording of a horn to create the three sound pieces.