• 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!

Syncing Music with game lag

kupo15

Member
I'm running into a little problem lining up my music when the FPS drops below 60. The only reason I have this issue is because I my music has an intro so in order to loop the music without the intro I have to split it up into two files. Here is a diagram



I line this up by measuring the number of frames the intro takes and set an alarm to play the loop when the alarm goes off. But I noticed when the frame rate drops below 60 this doesn't line up anymore because the alarm is tied to the frame rate but the music continues to play as if there is no lag.

How do I fix this? Do I have to decrease the alarm timer proportional to the lower frame rate or is there a simple solution I didn't think about?
 
M

Misty

Guest
You should play the second song when the first one ends.

audio_is_playing()
 

kupo15

Member
the only problem with that is that is also tied to the FPS as well. If the FPS drops then the game doesn't check as often as it would at 60 fps and it will miss the timing again
 

FrostyCat

Redemption Seeker
That would still give a lag of at least 1000/room_speed milliseconds.

Break the song into two sound buffers. Start a buffer queue with the intro and twice the main loop. Play it and top it up periodically with the main loop.
 

kupo15

Member
Oh buffers, I guess I'll have to read up on them as I don't know how they work...at least there is another tool to look into to try and fix this. Thanks!
 
M

Misty

Guest
the only problem with that is that is also tied to the FPS as well. If the FPS drops then the game doesn't check as often as it would at 60 fps and it will miss the timing again
If there is a 1/60th of a second gap between the intro and the loop. player's won't be conscious of it.

Or are you saying you have a movie, and you want the orchestra hits to play during the key sequences of the movie?
I would say, just choose a different style of background music that doesn't need to mickeymouse the movie, or just save it as a .wmv movie instead of a realtime movie and play it in game maker.
 

kupo15

Member
If there is a 1/60th of a second gap between the intro and the loop. player's won't be conscious of it.

Or are you saying you have a movie, and you want the orchestra hits to play during the key sequences of the movie?
I would say, just choose a different style of background music that doesn't need to mickeymouse the movie, or just save it as a .wmv movie instead of a realtime movie and play it in game maker.
No movie, its just a basic soundtrack with an intro part, think Soul Calibure's music. They do that a lot. Players will definitely notice. Even if I shorten the timer a little to overlap it, really bad slowdowns will still cause a gap. Its coming from a massive loading zone so the fps starts off lower than usual but even without that if your computer happens to lag badly do to some background program during the intro to like 40 fps or something there will be a gap
 
I

icuurd12b42

Guest
use get_timer() in combination with the sound length as opposed to a tick/frame counter
 

FrostyCat

Redemption Seeker
use get_timer() in combination with the sound length as opposed to a tick/frame counter
The problem here isn't just about real time falling out of sync with frame time. It is also about frame-timed code not reacting quickly enough, in this case causing an audible click at the loop point. get_timer() isn't going to do much here.
 
I

icuurd12b42

Guest
then make a sound file with <intro><mainloop> and another with <mainloop>

swap to the mainloop only when the complete intro+mainloop has concluded. surely the chances of being in a lag situation at that time is slim since your lag as you say is from the loading...

also you should start both sounds at the same time but pause the mainloop one immediately and unpause it when it's time for it to play. this will eliminate any delay when you swap to it.
 
M

Misty

Guest
In Raptor, Call of the Shadows, they had this where each song had an intro, but did not loop back to the intro, but looped to the 1/3 segment of the song.

If it can be done in 1994, it can be done in 2016 in GM.

audio_sound_set_track_position(index, time); is what you need.

There is also an audio_sound_get_track_position, you can set it to slightly before the end so there is no miniscule gap.

Also, there seems to be bigger problems at hand....why is a 60 fps game running at 40 fps during only the intro? If it runs 40 fps during the intro, what does it run like during gameplay? Also, if a player has a bunch of background programs running the game to 38 fps, is he or she really invested in the game, and such a mind probably won't mind a minuscule gap in the audio.
 

kupo15

Member
Thanks for the responses! I think this is the solution I was looking for but will look into the other solutions if somehow this doesn't work. Thanks for the tip about pausing to avoid stutter during swaps Icuurd!

In Raptor, Call of the Shadows, they had this where each song had an intro, but did not loop back to the intro, but looped to the 1/3 segment of the song.

If it can be done in 1994, it can be done in 2016 in GM.

audio_sound_set_track_position(index, time); is what you need.

There is also an audio_sound_get_track_position, you can set it to slightly before the end so there is no miniscule gap.
I think this is exactly what I need and was something I was looking for a while back when implementing this. For some reason I just never found it in the manual which is strange...must have been me
Also, there seems to be bigger problems at hand....why is a 60 fps game running at 40 fps during only the intro? If it runs 40 fps during the intro, what does it run like during gameplay? Also, if a player has a bunch of background programs running the game to 38 fps, is he or she really invested in the game, and such a mind probably won't mind a minuscule gap in the audio.
It shouldn't be a problem really. Firstly my cpu is pretty terrible and can't handle when an internet page refreshes plus dual monitors plus the game running with everything else I have going on so the frame rate tends to dip for me when that happens. I'm mainly just thinking about what if someone else doesn't have a gaming cpu like myself. Even with my integrated gpu the game runs at a steady 600 frames so someone with a good gpu will be even better. The FPS counter just displays a really low number after loading textures and stuff probably because the game freezes when things load

I'll check out those functions though!

EDIT:
There isn't a way that GM triggers an event when the music loops if you set it to loop does it?
 
Last edited:
M

Misty

Guest
Same here, the real fps is like 600 but the actual fps is like 60...it aint because of loading freezing though, still does it when nothing's loading...
 
watch out with audio_sound_get_track_position(), you'll need your event to take place when audio_sound_get_track_position is larger than a set value, not equal to it. For instance:

if audio_sound_get_track_position(snd_intro)>end_position
{
audio_stop_sound(snd_intro);
audio_play_sound(snd_mainloop);
}

I suggest you create yourself a temporary display that draws audio_sound_get_track_position() the corner of your screen.
 

kupo15

Member
watch out with audio_sound_get_track_position(), you'll need your event to take place when audio_sound_get_track_position is larger than a set value, not equal to it. For instance:

if audio_sound_get_track_position(snd_intro)>end_position
{
audio_stop_sound(snd_intro);
audio_play_sound(snd_mainloop);
}

I suggest you create yourself a temporary display that draws audio_sound_get_track_position() the corner of your screen.
Just noticed that variable and method also, thanks for bringing it up. On a side notes, the step events all are tied to the games performance and FPS when checking it. Are there any events that aren't affected by lag and run internally all the time that is always reliably checked?
 
I

icuurd12b42

Guest
>Are there any events that aren't affected by lag and run internally all the time that is always reliably checked?

No
 
Just noticed that variable and method also, thanks for bringing it up. On a side notes, the step events all are tied to the games performance and FPS when checking it. Are there any events that aren't affected by lag and run internally all the time that is always reliably checked?
There are asynchronous events you can use, but they can get very technical at times. Mostly anything regarding communication and data buffers.

I suggest instead of xorking on asynchronous events, you try to improve your game's FPS :) maybe give the user a quality slider he can decrease if the FPS is too low.
 
I

icuurd12b42

Guest
There are asynchronous events you can use, but they can get very technical at times. Mostly anything regarding communication and data buffers.
The content is processed asynchronously up to the point where it is ready, then the event triggers in the next step... so it's still step based and so still subject to lag.

I suggest instead of xorking on asynchronous events, you try to improve your game's FPS :) maybe give the user a quality slider he can decrease if the FPS is too low.
Exactly...
 

kupo15

Member
Yea will do. Its already pretty good but will always improve. That means I can't lower the room speed for the slow motion option in case the player does that during the intro haha but that's still not the ideal solution I planned to implement anyway :p
 
Top