Audio clipping when spamming parameters

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.

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:

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

Hi Richard- thanks very much, it fixed it.

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

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.

1 Like

Super, thanks for clearing it up :slight_smile:

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.