# Audio clipping when spamming parameters

**URL:** <https://qa.fmod.com/t/audio-clipping-when-spamming-parameters/14360>\
**Category:** Unity\
**Created:** [February 8, 2019, 2:45pm UTC](https://qa.fmod.com/t/audio-clipping-when-spamming-parameters/14360 "2019-02-08T14:45:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loktarg](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@Loktarg](https://qa.fmod.com/u/Loktarg)\
**Post date:** [February 8, 2019, 2:45pm UTC](https://qa.fmod.com/t/audio-clipping-when-spamming-parameters/14360/1 "2019-02-08T14:45:57Z")

</div>

Hi. I have some trouble with me menuscreen. When you click or spam hovering over menu elements, the sound gives of nasty clicks  
I have 2 nested events in an event- One for clicking and one for hovering.

public class FMODMenuSoundManager : MonoBehaviour {

```
public string menuOptionsPath = "event:/Menu/Ui/MenuOptions";
FMOD.Studio.EventInstance menuOptions;
FMOD.Studio.ParameterInstance soundSelect;

void Awake ()
{
   menuOptions = FMODUnity.RuntimeManager.CreateInstance(menuOptionsPath);
   menuOptions.getParameter("soundSelect", out soundSelect);
}

public void PlaySound(float parameter)
{
    soundSelect.setValue(parameter);
    menuOptions.start();
}

```

}

The last 3 lines are where the action is. The parameter is set and the sound is played. Again, if I spam click, the sound starts clicking ingame. I’ve tried setting the files to stream, using 48kbps files

thanks in advance, if theres anything wrong with the thread, please let me know, first time posting here.

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [February 10, 2019, 11:10pm UTC](https://qa.fmod.com/t/audio-clipping-when-spamming-parameters/14360/2 "2019-02-10T23:10:54Z")

</div>

Hi Loktarg,

From the looks of your script, you are restarting the same event over and over again when the `PlaySound()` function is called (re: when the button is hovered over or clicked).

The clipping sound may be due to the audio suddenly having to stop and restart, with no ramping out in place. If these are short UI sounds, I would recommend having a new instance play and placing a Max Instance value on the event. Perhaps set it to around 5 max instances with the oldest instance being stolen.

Then you can instead create and release the event instance in the `PlaySound()` function like below:

```auto
public void PlaySound(float parameter)
{
    menuOptions = FMODUnity.RuntimeManager.CreateInstance(menuOptionsPath);
    menuOptions.getParameter("soundSelect", out soundSelect);
    soundSelect.setValue(parameter);
    menuOptions.start();
    menuOptions.release();
}

```

You shouldn’t need to set short UI sounds to stream so feel free to change them to not stream.

If this is still causing issues, please let me know.

Thanks,  
Richard

---

<div class="post-metadata">

**Author:** ![Loktarg](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@Loktarg](https://qa.fmod.com/u/Loktarg)\
**Post date:** [February 11, 2019, 10:30am UTC](https://qa.fmod.com/t/audio-clipping-when-spamming-parameters/14360/3 "2019-02-11T10:30:51Z")

</div>

Hi Richard- thanks very much, it fixed it.

Can I ask if creating new instances affects performance for the worse?

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [February 11, 2019, 12:53pm UTC](https://qa.fmod.com/t/audio-clipping-when-spamming-parameters/14360/4 "2019-02-11T12:53:59Z")

</div>

It’s a give-and-take situation.

With your old setup you had one event instance created and never released. So this event instance will remain in memory. However one event instance takes up less memory than 5 event instances.

On the other hand, the new setup will not create any instances until required and will release them from memory as soon as they are finished playing. If you set up a max instance value of 5, then it is possible to have 5 event instances in memory.

With typical short UI sounds, the performance hit for the new setup won’t be noticeable. This new set up is definitely preferable.

---

<div class="post-metadata">

**Author:** ![Loktarg](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@Loktarg](https://qa.fmod.com/u/Loktarg)\
**Post date:** [February 11, 2019, 1:53pm UTC](https://qa.fmod.com/t/audio-clipping-when-spamming-parameters/14360/5 "2019-02-11T13:53:46Z")

</div>

Super, thanks for clearing it up 🙂

I just started an internship and I have to get used to working with a coder, so the lingo isn’t quite there yet for me.
