Song Loop doesn't work correctly

Song looping bug
I have an issue, when using the song loop it always creates a weird short pause between each play, song ends ~0.3s pause, song plays. This also happens when music is preloaded, and on every project I checked.

This seems like easy to fix bug, but also very frustrating, cause it destroys whole aspect of “music/ambient” in game.

2 Likes

I have this problem too, and it ruins the vibe. Especially when your game is beat based (mine isn’t just saying).

This likely is caused by one of a few things:

  1. Your audio file is too large to be looped by the music events (as the audio is streamed progressively even if preloaded).
  2. Your audio file has a gap in the actual audio file, either start or end (or both). Many mp3 encoders add a gap at the end.

You should try switching to the sound file events (play as sound on a channel, instead of play as music on a channel), AND ensuring the audio is set to preload as sound (not music) in resources. Note, this will load the entire file at the start of the game and/or scene. So a ton of large music files will lead to longer load times

If that doesn’t work you’ll need to check your audio file in something like Audacity to remove silence at the start or finish.

1 Like

Changing it to “sound” event shortened the gap massively, but there still is like 1 or 2 frame gap between loop. It’s good for now, but it prevents the seamless loop effect.

And yeah, the audio file doesn’t contain any spaces.

Thanks.

I’ve done a few dozen tests with about 100 different audio files, if you have it set to play as sound on a channel, preload set in resources, and you are testing locally (not loading resources from the web), I’ve never had any delays.

If your audio files are mp3s, I’d recommend double checking in audacity at max zoom. That said, you might try converting them to aac to see if it makes a difference as many browsers (including electron from exported games) can decode aac easier.

When you say you’ve not had issues with audio delay in gdev I believe you must be making an error of measurement. In my tests audio operations are locked to framerate. So even at 60 fps your audio event could be 16ms late. That is unusable for audio. Loops always drift, timing is always off. In my experience the audio ops in gdv are useless because of timing. We can’t even fade volume in/out.

Manual loops done via checking the position of the track and then manually setting its offset can be off, agreed.

Playing a sound on a channel , using the loop = yes parameter in that action, appears to be asynchronous. From what I remember about how the action works, it is cached to the howler.js audio system at the time that action is first run rather than checked every frame.

Edit: although its a good callout as the op may be doing a manual loop and none of this will matter. @NikOrzech are you using the loop parameter on the action and having it loop at the end of the song, or are you trying to manually loop based off a position and using the set offset actions?

Using the loop sound action. I wiped Gdevelop files, reinstalled it, and now loop sound feature seems to work great.

Thanks for help!

1 Like

You can fade volume tho, using the channel volume

The following pastebin can be saved as a json file. Add a “snd.wav” in the usual resources folder and open the project in gdevelop. It will play the sample chromatically, like a synth, and vary the tail length of each note gradually. You should be able to hear a clicking sound. I am looking to eliminate this.