Retreiving samples and sample rate from song

public static double GetAudioSourceTime()
return (double)Instance.audioSource.timeSamples / Instance.audioSource.clip.frequency;

Above is a method using unityaudio that returns the timesamples divided by the sample frequency of a track as a double which is used to determine the ‘location’ in the song.

I am just wondering if there are any FMOD functions that allow me to do what i’m doing above in unityaudio? - I apologise, as i’m a little bad at making sense of the documention, but would appreciate any help regarding this.


Yes, there are functions that allow you to do the same or similar, but it depends on what exactly you’re doing.

If you’re using the Core API to play a sound on a channel, you don’t need to calculate it yourself - you can use Channel::getPosition to get the playback position in a specific timeunit, e.g. milliseconds, samples, bytes, etc.

If you’re using the Studio API to play events, it’s a little more complex due to the higher level nature of Studio events. You can retrieve the playback position of an event’s timeline with Studio::EventInstance::getTimelinePosition, but this isn’t the same as the position of the currently playing instrument(s) in the event, and doesn’t apply to parameter or action sheets. You can retrieve the event instance’s underlying ChannelGroup with Studio::EventInstance::getChannelGroup, traverse to the child channel that corresponds to a specific instrument, and get the channel position from there, but this can be a hassle, especially if your event is complex.

If you are playing event instances with the Studio API, can I ask what exactly you’re trying to do with the playback position? I may be able to point you in the direction of a specific Studio API functionality that can address your use-case.