Sustain a part of an audio clip

Hey everybody,

I am trying to find the most efficient and simple way to sustain a part of an audio clip. The ultimate objective is to have that sound play longer or shorter, depending on external parameter (e.g. play as long as the player presses a button).

To illustrate: I wish to play the sound file from the beginning, loop between A and B for as long as I want (maybe even a ping pong loop), and when done, continue playing from the same point through to the end.


My findings so far:

  1. I found this ADSR forum thread that talks about it a little more.
  2. Slicing the file to three parts and playing them as needed produces artifacts, and in any case I prefer to avoid this approach.
  3. I was hoping GetData and SetData would perhaps help me do it, but I didn’t figure out if it is true, and how to do it.
  4. I have tried an alternative approach, which has a long sample by default, and I fade its volume out prematurely, if a short sound is needed. This of course, loses any actual sample data that may be present at the real end of the sample.

If anyone can suggest a way to achieve this, it would be great.

Option 2.

The sounds artifacts are natural, you can’t just brake a sound without “poc”. You wan’t something like this :


You need to create three sounds :

A     -> B
B     -> END

Then you need to create a quick fade out at the end of START->A and A->B, then a fade in at the beginning of A->B and B->END.

If we zoom on this beautiful ascii time line, we have need to do this for the first fade out of START->A :

        Start fade Out|   |End fade Out

Then, the fade in of A->B :

         Start fade In|   |End fade In

You do this for the three sounds, then you create three audio behaviors and start the START->A sound, launch and loop the A->B sound the right amount of time (setted on a var) before the end of START->A.

The same when you switch from A->B to B->END.

Then you have a composed sound without “poc”.