# How to stop loop without cutting off audio

**URL:** <https://qa.fmod.com/t/how-to-stop-loop-without-cutting-off-audio/16817>\
**Category:** FMOD Studio\
**Created:** [February 26, 2021, 6:53pm UTC](https://qa.fmod.com/t/how-to-stop-loop-without-cutting-off-audio/16817 "2021-02-26T18:53:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fahrenheit737](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/fahrenheit737/32/1943_2.png) [@Fahrenheit737](https://qa.fmod.com/u/Fahrenheit737)\
**Post date:** [February 26, 2021, 6:53pm UTC](https://qa.fmod.com/t/how-to-stop-loop-without-cutting-off-audio/16817/1 "2021-02-26T18:53:05Z")

</div>

hey guys  
i am working on a boeing 747 soundpack for x plane. an issue i’ve been facing is looping. for the alarm sounds, annunciations like “pull up” loop, and when you pull up, the loop will stop. however, i want the sound to finish the audio, and then stop the loop, but right now, when i end the loop, it cuts the sound off midway. is there any way to fix this  
thanks

---

<div class="post-metadata">

**Author:** ![Alcibiade](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alcibiade/32/4284_2.png) [@Alcibiade](https://qa.fmod.com/u/Alcibiade)\
**Post date:** [February 28, 2021, 10:32am UTC](https://qa.fmod.com/t/how-to-stop-loop-without-cutting-off-audio/16817/2 "2021-02-28T10:32:18Z")

</div>

There are several ways of achieving this. What kind of sound is the one in the loop? Is there a transition (ie cross fade) between each loop?

---

<div class="post-metadata">

**Author:** ![joseph](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joseph/32/264_2.png) [@joseph](https://qa.fmod.com/u/joseph)\
**Post date:** [March 2, 2021, 1:04am UTC](https://qa.fmod.com/t/how-to-stop-loop-without-cutting-off-audio/16817/3 "2021-03-02T01:04:24Z")

</div>

As Alcibiade has said, there are multiple different ways of doing this. Which one you should use depends on your circumstances and what you want to achieve.

Are you stopping the loop by sending a stop command to an event, or by changing the value of a parameter? Are you looping the sound using a loop region, or by enabling an instrument’s loop mode? Are the instruments involved synchronous or asynchronous?

---

<div class="post-metadata">

**Author:** ![Casey](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/casey/32/4452_2.png) [@Casey](https://qa.fmod.com/u/Casey)\
**Post date:** [March 6, 2023, 2:29pm UTC](https://qa.fmod.com/t/how-to-stop-loop-without-cutting-off-audio/16817/4 "2023-03-06T14:29:14Z")

</div>

I have the same question.

We have a minigame where you stomp to the beat (a soundloop), and once you complete the last stomp I want to play a completion sound once the soundloop ends.

I got this all working but currently the soundloop still plays like “the first frame” of its loop through the completion sound and it’s really jarring, so telling it to stop looping seems the way to go (destroying the loop from its stop-event crashes the editor so 🤷‍♀️)

This is the loop in question. Markers define when you need to stomp and as you can see I use a simple loop region here to make it work. Since it’s just a minigame we don’t expect things to get much more complicated than this.

 ![The loop in question](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/9/9d7e338aa30fa9522985db183f60864be908bade.png)

---

<div class="post-metadata">

**Author:** ![Casey](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/casey/32/4452_2.png) [@Casey](https://qa.fmod.com/u/Casey)\
**Post date:** [March 6, 2023, 3:06pm UTC](https://qa.fmod.com/t/how-to-stop-loop-without-cutting-off-audio/16817/5 "2023-03-06T15:06:58Z")

</div>

Now that I think about it though, it _would_ be better for me if I can stop the sound from the stop event (since currently this event checks if you have completed the beat in the first place) and it leads to the same result as asked by the question, so I’ll post it here as well.

My Code:

```auto
public class Confidential : MonoBehaviour
{
    private bool beatCompleted;
    private bool callComplete;

    private void Update()
    {
        if (callComplete)
        {
            Complete();
        }   
    }

    public void Complete()
    {
        Destroy(gameObject);
    }

    // Called by EVENT_CALLBACK_TYPE.SOUND_STOPPED.
    private static RESULT SoundStoppedCallback(/*params*/) 
    {
        var instance = new EventInstance(instancePtr);
        Confidential confidential = instance.getUserData(); // Pretend I wrote GCHandle code and caught all errors.
        if (confidential.beatCompleted)
        {
            confidential.callComplete = true;

            // The following doesn't work as it still plays "one frame" of sound.
            instance.setPaused(true);
            instance.setVolume(0f);

            // The following crashes the editor.
            instance.stop(STOP_MODE.IMMEDIATE);

            // The following freezes the editor because Destroy may only be called from the main thread.
            // (And it would likely still play one frame of sound).
            confidential.Complete();
        }
    }
}

```

The astute will notice this might trigger an infinite loop with the callback called over and over, but my own code handles that.

So I’ve tried a bunch of stuff already, but no luck. Anything I’m missing with the sound stopped event?

---

<div class="post-metadata">

**Author:** ![joseph](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joseph/32/264_2.png) [@joseph](https://qa.fmod.com/u/joseph)\
**Post date:** [March 7, 2023, 2:56am UTC](https://qa.fmod.com/t/how-to-stop-loop-without-cutting-off-audio/16817/6 "2023-03-07T02:56:33Z")

</div>

> [@Casey](#):
>
> currently the soundloop still plays like “the first frame” of its loop through the completion sound and it’s really jarring

I’m afraid I don’t understand what you mean by this.

> [@Casey](#):
>
> it _would_ be better for me if I can stop the sound from the stop event

If you want the event to play a stopping sound upon being sent a stop command, you’ll need to stop the event with FMOD\_STUDIO\_STOP\_ALLOWFADEOUT instead of FMOD\_STUDIO\_STOP\_IMMEDIATE. You’ll also want to define some stopping behavior for the event by using an “event stopping” event state condition on one or more logic markers or instruments (most likely one transition marker at or near the positions of the destination markers in your screenshot).
