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

Legacy GM Sound loops

Sk8dududu

Member
I'm attempting to play a short sound clip (~10 seconds), and if the player has progressed enough by that time, it plays a new sound, if not it will loop that sound again, and then check for completion.
Is there a function for checking if the song has ended? or make something happen when it ends.

What I've used is setting an alarm 1 frame before the sound clip ends to check if the progress has been made. And then playing the clip again if it hasn't. I'm concerned about the sound clips getting out of sync with the alarm though if the game drops any frames.
is this not something I should worry about?

The other idea I thought of was to check if the sound is still playing in step event, and if its not, then check if should play that sound again. But this is concerning because there cannot be any frames between the two tracks, it has to be seamless. (because the two tracks are part of 1 song, the first track loops perfectly into itself and into track 2.)
 

YoSniper

Member
Code:
audio_sound_get_track_position
If you are using one track that has multiple sections in it, and the transitions are meant to be seamless, then you can check the track position in real time.

When you first play the sound, make sure to track the index of the sound you are playing. Then, on any given step, you can check the relevant conditions, and if the track reaches the end of the loop range, allow it to move on to the next part of the track.
 

Sk8dududu

Member
Code:
audio_sound_get_track_position
If you are using one track that has multiple sections in it, and the transitions are meant to be seamless, then you can check the track position in real time.

When you first play the sound, make sure to track the index of the sound you are playing. Then, on any given step, you can check the relevant conditions, and if the track reaches the end of the loop range, allow it to move on to the next part of the track.
This is exactly what I was looking for, instead of splitting the track up my self, way easier.
I'm not sure what you mean by getting the sound index.
So in this controller in the create event I have the audio_play_sound(s,1,0), am I supposed to have it set to loop so that each part will loop?
And then in the step event, something like checking when the sound is at the loop section, and restarting it? I'm sorry, I'm just not really understanding how to use audio_sound_get_track_position yet.
Also if it has multiple sections that I want to loop, how can I loop from a specific point not to the beginning of the song, but rather to like 10 seconds in or whatever.
 

YoSniper

Member
The sound index is the number that is returned by the function.

It is important to keep track of that in a variable, I've found (rather than just querying the track position of a sound ID as listed under your Sounds folder.)

For instance:
Code:
sound_loop = audio_play_sound(track_name, false, 2);
//...
var track_pos = audio_sound_get_track_position(sound_loop);
var LOOP_START, LOOP_STOP;
if condition1 {
    LOOP_START = 0;
    LOOP_STOP = 30; //For example, the first 30 seconds of the track
} else if condition2 {
    LOOP_START = 30;
    LOOP_STOP = 60; //Second 30 seconds, which the first loop would transition into seamlessly
}
//...and so on...
if track_pos >= LOOP_STOP {
    track_pos -= (LOOP_STOP - LOOP_START);
    audio_sound_set_track_position(sound_loop, track_pos);
}
In my games, when I don't keep track of the returned sound index, controlling the looping and the volume of that sound were less easy, or not possible. Maybe you'll have a different experience, but I still recommend tracking it.
 
Top