# Audio stuttering

**URL:** <https://qa.fmod.com/t/audio-stuttering/20044>\
**Category:** Unity\
**Tags:** unity\
**Created:** [March 30, 2023, 7:29pm UTC](https://qa.fmod.com/t/audio-stuttering/20044 "2023-03-30T19:29:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Angelo13C](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@Angelo13C](https://qa.fmod.com/u/Angelo13C)\
**Post date:** [March 30, 2023, 7:29pm UTC](https://qa.fmod.com/t/audio-stuttering/20044/1 "2023-03-30T19:29:16Z")

</div>

Hi, I am developing a game and testing it in my Unity editor (Windows 11).

In the game you are a person walking in streets and there are a lot of cars, so I made a script in Unity that checks if there are nearby cars (at max 5) every frame, and for each of them I do RuntimeManager.PlayOneShot(carEngineSound, carPosition).  
For now I don’t even stop sounds if there aren’t enough cars nearby because I just installed FMOD today and I am still a noob, but I can see in the FMOD Studio Debug I don’t have memory issues or things like that.

Now when I test it (in the editor, can’t test in a build because of a Unity bug), the FPS is good (around 60 fps) but I hear a lot of stuttering in the sounds of the engine, like the car engine sounds are playing correctly but very frequently they are suddenly mute for some frames and then they become unmute… It’s unusable right now

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [March 30, 2023, 11:57pm UTC](https://qa.fmod.com/t/audio-stuttering/20044/2 "2023-03-30T23:57:04Z")

</div>

Hi,

> [@Angelo13C](#):
>
> I made a script in Unity that checks if there are nearby cars (at max 5) every frame, and for each of them I do RuntimeManager.PlayOneShot(carEngineSound, carPosition).

Could I get you to provide a code snippet of how you’re calling `RuntimeManager.PlayOneShot()`?

This issue can be caused by having too many streaming assets streaming at once. When an asset it set to “stream” in FMOD Studio’s Asset browser, instead of being loaded into memory in its entirety before playback, the asset streamed from your storage media (i.e. loaded piece by piece on demand) during playback. This can be useful for saving memory, but most systems cannot support running a large amount of concurrent streams at once, which can lead to stuttering behavior like you’re describing. If the asset(s) you’re using for your event is set to stream in FMOD Studio, can you toggle it off and see if that resolves the issue?

> [@Angelo13C](#):
>
> I can see in the FMOD Studio Debug I don’t have memory issues or things like that.

The FMOD Studio Debug overlay only provides a general insight - if you want to look more in-depth at the performance of your FMOD Studio project, you should connect the Unity editor to the FMOD Studio application via Live Update and use FMOD Studio’s profiler, which will let you record and examine things like File I/O, event instances and lifetimes, virtualization, and more. Info on how to do this can be found in our FMOD Unity docs on [Connecting Using Live Update](https://www.fmod.com/docs/2.02/unity/user-guide.html#connecting-using-live-update).

---

<div class="post-metadata">

**Author:** ![Angelo13C](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@Angelo13C](https://qa.fmod.com/u/Angelo13C)\
**Post date:** [March 31, 2023, 8:12am UTC](https://qa.fmod.com/t/audio-stuttering/20044/3 "2023-03-31T08:12:10Z")

</div>

> [@Leah\_FMOD](#):
>
> Could I get you to provide a code snippet of how you’re calling `RuntimeManager.PlayOneShot()`?

Ok so this is a simplified version of my code (the actual code is in Unity ECS so it’s a bit different, but the FMOD part is the same):

```auto
public class NearbyCarsEngineAudioPlayer : MonoBehaviour
{
    [SerializeField] private EventReference _carEngineSound;
    private List<Vector3> _nearbyCarsPosition = new List<Vector3>();

    void Update()
    {
        foreach(var nearbyCar in _nearbyCarsPosition)
            RuntimeManager.PlayOneShot(_carEngineSound, nearbyCar);
    }

    void FixedUpdate()
    {
        _nearbyCarsPosition.Clear();
        // Here there is some physics overlap sphere logic to get only the 5 nearest cars' position that are near enough
    }
}

```

> [@Leah\_FMOD](#):
>
> This issue can be caused by having too many streaming assets streaming at once. When an asset it set to “stream” in FMOD Studio’s Asset browser, instead of being loaded into memory in its entirety before playback, the asset streamed from your storage media (i.e. loaded piece by piece on demand) during playback. This can be useful for saving memory, but most systems cannot support running a large amount of concurrent streams at once, which can lead to stuttering behavior like you’re describing. If the asset(s) you’re using for your event is set to stream in FMOD Studio, can you toggle it off and see if that resolves the issue?

Ok thanks, I tried it and it seemed to have solved this issue!  
But it still seems like there’s a general stuttering in the audio (even with other SFX), don’t know why.

I may also need to try to improve the engine’s sound audio because it doesn’t sound that good with a combination of 5 of them running all at once, but that’s another thing.

> [@Leah\_FMOD](#):
>
> The FMOD Studio Debug overlay only provides a general insight - if you want to look more in-depth at the performance of your FMOD Studio project, you should connect the Unity editor to the FMOD Studio application via Live Update and use FMOD Studio’s profiler, which will let you record and examine things like File I/O, event instances and lifetimes, virtualization, and more. Info on how to do this can be found in our FMOD Unity docs on [Connecting Using Live Update](https://www.fmod.com/docs/2.02/unity/user-guide.html#connecting-using-live-update).

Ok I’ll see with the FMOD’s profiler what is going on

---

<div class="post-metadata">

**Author:** ![Angelo13C](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@Angelo13C](https://qa.fmod.com/u/Angelo13C)\
**Post date:** [March 31, 2023, 10:12am UTC](https://qa.fmod.com/t/audio-stuttering/20044/4 "2023-03-31T10:12:46Z")

</div>

I think I’ve majorly solved the issue (camera shake was also moving the camera and there were some weird artifacts), now it’s mostly a problem of the cars engines’ sound overlapping which I don’t like, probably I need better SFX or add some effects to improve it

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [April 2, 2023, 11:24pm UTC](https://qa.fmod.com/t/audio-stuttering/20044/5 "2023-04-02T23:24:27Z")

</div>

It good to hear that you’ve mostly solved the issue.

As far as overlapping sounds go, you may wish to explicitly set the 3D attributes of each event instance to the corresponding nearby cars instead of simply playing them as a oneshot. This will apply spatialization and doppler over the lifetime of the event, instead of just based on the initial position. Using a multi-instrument with a variety of different car engine sounds can also help.

Since your code snippet is not exactly what you’ve implemented with Unity ECS, it’s impossible for me to tell for sure that this is the case, but your code appears to be playing a new oneshot event every single update for each car. Creating a large amount of events extremely frequently can also cause stuttering, though typically this is accompanied by warnings for buffer starvation in the mixer thread and command buffer. This could also contribute towards your overlapping audio .If you are running into these warnings, you may wish to do something like remove nearby cars from the `_nearbyCarPosition` list after creating an event to ensure you’re only playing a single event for a single car.
