Looping Music with Intro?

F

FroggestSpirit

Guest
I've just come back to Game Maker after a hiatus (I'm pretty sure GM7 or 8 was the last one I used). Anyways, I noticed a plethora of new features, including more support for audio (like buffers and such). I want to be able to play a song that has an intro that plays once, then seemlessly loop the rest of the song. I've thought of two ways to do this, and unfortunately, they don't seem to be the best for their own reasons.
1. use audio buffers and queues to create a callback to loop the second part
Con: This only works with uncompressed wav
2. split the music into 2 parts, an intro and a main loop, and have the intro play. In the step event, check if the intro finished playing, then loop the main part
Con: timing won't always be accurate. Even the slightest delay will cause a skip or a pop during the transition.

I was hoping there may be another way, like a callback for when audio is done playing, or a future feature.
Any insight is appreciated :)
 

chorrus

Member
https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sounds/index.html

Here you have all audio functions, anyway your second option looks good, if you check every step if the intro has finished and play the loop just after that, it would be something that anybbody would notice for sure(1/60 second is something that a human probably won't notice, I havn't tested but I guess it would work fine).

However, check this function https://docs.yoyogames.com/source/d...ce/game assets/sounds/audio_sound_length.html
This could be exactly what you are looking for, play the intro, ask for the length of the intro, start an alarm with that length, and in that alarm you add the code to play the loop.
 
A

Aura

Guest
audio_sound_set_track_position() and audio_sound_get_position() are the functions that you'll want. Say the part that has to be looped starts after 29 seconds you'll do this:

Create:
Code:
s = audio_play_sound(snd_music, 10, true);
played = false;
alarm[0] = 29 * room_speed;
Alarm 0:
Code:
played = true;
Step:
Code:
if (played and audio_sound_get_track_position(s) < 29)
{
   audio_sound_set_track_position(29);
}
 
Sorry for the very very late reply, but would that also work as a script? I'm using WreckingPrograms' Mega Engine, and I want to edit some scripts to make the engine independent of FMOD. If that can't be done, what about the creating code?
 
Last edited:
Top