Answered
0
0

I’ve managed to hook up an FMOD callback that fires when an event instance plays:


FMOD.Studio.EventInstance evt = ...;
evt.setCallback(OnFMODSoundplayed, FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED);

And within the callback I managed to get the name of the chosen sound within a scatterer sound:


private static FMOD.RESULT OnFMODSoundPlayed(FMOD.Studio.EVENT_CALLBACK_TYPE type, System.IntPtr eventInstance, System.IntPtr parameters)
{
var sound = new FMOD.Sound(parameters);
int nameLen = 1024;
var nameBuilder = new System.Text.StringBuilder(nameLen);
sound.getName(nameBuilder, nameLen);
Debug.LogFormat("Playing sound {0}", nameBuilder);
}

That is all fine and well, but it’s a lot of overhead and allocates tons of garbage each time a sound is playing, so not really practical in Unity.

I don’t really need the name of the sound, any identifier to tell them apart would be enough. For example I’d be perfectly happy if I could query the index of the sound within the list of sounds of a scatterer sound.

My idea was to go up from the sound playing to its parent scatterer sound and then down again into the list of children sounds, iterating over the list until I find a match. I have tried combinations of getSubSoundParent, getNumSubSounds, getSubSound, getSoundGroup, getNumSounds, and getSound, but to no avail. Both getNumSubSounds and getNumSounds always return 1.

So my questions are:
1) Is there a way to query the index of a sound playing within a scatterer sound?
2) Are scatterer sounds related to parent/sub sounds or sound groups at all?
3) Is the parameters IntPtr in the callback guaranteed to be unique and non-changing for the entire runtime of a process, i.e. is the same sound within a scatterer sound always going to result in the exact same IntPtr value in the callback? That way I could cache sound names by IntPtr.

  • You must to post comments
Best Answer
0
0

If it just a unique identifier for the one event, then the parameters IntPtr is unique for each sound added to the Scatterer. The scatterer creates an FMOD.Sound for each sound that it can then play when needed.

This uniqueness cannot be guaranteed globally though, as sounds get freed an created it may get replaced with another.

We are planning on reducing the overall overhead and garbage allocations of the Unity Integration in the near future.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.