Grab Length of AudioClip


(keil aloia) #1

Hello, so currently I am working on implementing voice lines and want to have my coroutine last only as long as the fmod.studio audio clip and I’m at a complete loss on how to go about that!
currently, I’m using c# in unity if that’s any consolation.
Please Help


(リチャード清水) #2

Hi Keil,

If you are looking to get the length of the event instance, you can use EventDescription::getLength(). This is the length of the entire event from 0 to the last instrument or marker.

https://www.fmod.com/resources/documentation-api?page=content/generated/FMOD_Studio_EventDescription_GetLength.html#/

However, if you are looking for the length of the audio file being referenced in an instrument that is playing, you will need to set up a callback using FMOD_STUDIO_EVENT_CALLBACK to grab the FMOD_STUDIO_EVENT_CALLBACK_SOUND_PLAYED and then using Sound::getLength().

https://www.fmod.com/resources/documentation-api?page=content/generated/FMOD_STUDIO_EVENT_CALLBACK.html#/
https://www.fmod.com/resources/documentation-api?page=content/generated/FMOD_STUDIO_EVENT_CALLBACK_TYPE.html
https://www.fmod.com/resources/documentation-api?page=content/generated/FMOD_Sound_GetLength.html#/

Thanks,
Richard