How to stop loop without cutting off audio

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

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?

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?

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 :woman_shrugging:)

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.

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:

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?

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

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).

1 Like