# Retreiving samples and sample rate from song

**URL:** <https://qa.fmod.com/t/retreiving-samples-and-sample-rate-from-song/20876>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [November 14, 2023, 6:14pm UTC](https://qa.fmod.com/t/retreiving-samples-and-sample-rate-from-song/20876 "2023-11-14T18:14:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![theoceanwashedoveryo](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@theoceanwashedoveryo](https://qa.fmod.com/u/theoceanwashedoveryo)\
**Post date:** [November 14, 2023, 6:14pm UTC](https://qa.fmod.com/t/retreiving-samples-and-sample-rate-from-song/20876/1 "2023-11-14T18:14:10Z")

</div>

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.

Thanks.

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [November 14, 2023, 10:51pm UTC](https://qa.fmod.com/t/retreiving-samples-and-sample-rate-from-song/20876/2 "2023-11-14T22:51:24Z")

</div>

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`](https://www.fmod.com/docs/2.02/api/core-api-channel.html#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`](https://www.fmod.com/docs/2.02/api/studio-api-eventinstance.html#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`](https://www.fmod.com/docs/2.02/api/studio-api-eventinstance.html#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.
