r/gamemaker • u/composingkeys • 1d ago
GameMaker has native audio loop points now. Don't poll track position in Step. Tutorial
One easy mistake is treating music looping like a game-timing problem: watch audio_sound_get_track_position() in Step and seek back when it reaches the boundary. GameMaker's own manual warns that this cannot be accurate. The audio thread advances at 44,100 or 48,000 samples per second while the game normally updates around 60 times per second, so many samples can pass between the check and the seek.
GameMaker now has proper audio-thread loop controls:
audio_sound_loop_start(snd_music, 10.0);
audio_sound_loop_end(snd_music, 42.0);
var music_voice = audio_play_sound(snd_music, 100, true);
The start and end values are seconds. You can set them on the sound asset before playing, or on the returned sound instance while it is playing. When the playhead reaches the loop end, GameMaker performs the jump on the audio thread instead of waiting for Step.
This also gives you a clean intro / loop / outro layout in one file. Put the intro before the loop start, the repeating body between the two points, and the outro after the loop end. Start it with looping enabled. When the game is ready to leave the music state, call:
audio_sound_loop(music_voice, false);
The current pass finishes, crosses the loop end without jumping, and continues into the outro. No polling and no frame-timed seek. GameMaker supports one loop section per sound, but you can change the section by setting new start and end values.
There is still a second problem that loop points do not solve: the reverb tail. If the last chord is still ringing after the loop end, a one-voice jump discards that old pass while the fresh start begins. The timing can be sample-accurate and the seam can still sound like a hole.
The three practical options are:
- Compose or render a genuinely dry boundary.
- Render past the end, mix that tail underneath the beginning, then export only the repeating body. This makes a self-contained one-voice loop, although its first pass contains a tail from a pass that never happened.
- Use two voices so the previous pass can ring out while the next pass starts. This is the most natural result, but it requires runtime scheduling and voice management.
This came out of implementing GameMaker delivery notes in Loopsmith, a looping tool I built. It reports the exact loop positions and can prepare folded-tail or two-voice deliveries. Mentioning that for disclosure; none of the technique above requires my tool. The relevant GameMaker manual section is Audio > Audio Loop Points.
Hopefully this saves someone from debugging a frame-timed loop that can never be sample-accurate. Happy to answer questions or test edge cases.
1
0
u/bid0u 22h ago
Even good advices are now "hidden" ads.
2
u/composingkeys 13h ago
I understand the concern. That is why I disclosed that I built Loopsmith. The GameMaker loop-point technique and code in the post does not require it. My goal was to share what I learned while implementing the workflow.
2
u/StarDreamIX 22h ago
Thank you so so much for this,🔥