• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker How to get audio current play position (For rhythm game)

ac585318

Member
I'm following this guide for making a rhythm game. At this point I need a song position variable, which is the audio track position, but GMS2 seems to make it difficult getting this in a direct and simple way.

Looking at previous threads the audio_sound_get_track_position() function may have used to return the audio's current playing position, but it now seems to get the position the sound will play from (aka the start pos), not it's current position...

The information within audio_debug seems to have "Play Offset" which seems to be exactly what I need, except it's in hexadecimal when I want it in milliseconds and I don't know how to / if I can access this in code... I could probably find another method but this is seeming the most direct and appealing.

Plz help :confused:

Edit: So it works a bit differently than I thought it did, the audio_sound_get_track_position() function does actually get position but it's not in milliseconds and not the most precise...
 
Last edited:

TheouAegis

Member
Isn't it number of seconds? In which case, it's got all the joys of floating points. But yeah, it should return a value like 153.32153563032 seconds.
 

ac585318

Member
Isn't it number of seconds? In which case, it's got all the joys of floating points. But yeah, it should return a value like 153.32153563032 seconds.
Which do you mean? For me anyway audio_sound_get_track_position() seems to return hundredths of a second instead of thousandths which the GMS2 sound/audio system seems to run on, which can be seen in audio_debug, but I don't know if there is a way to access this in GML code...
 

obscene

Member
It will only display 2 decimal points, but in reality the function is returning a much more precise value.
 

TheouAegis

Member
It is actually pretty precise and also somewhat forgiving. For example, there is a short example, either in the manual or something I found on the forums, about how to loop an audio track. It took a little bit of tinkering, but I was able to get a track to loop practically seamlessly. Now, if you use a audio editor that breaks everything down into milliseconds but you want something that happened at a microsecond, then find out what that millisecond point is -- that is your decimal value -- then start adding digits after that decimal until you get the proper number of microseconds.

In my case, I just did it the hard way and eyeballed audio_sound_get_track_position() repeatedly until I could narrow down which timestamps I wanted.
 
Top