Game Over Sound Effect gets worse the further into the game I go

So, the game that I’ve been working on has a two second game over mp3 sound effect that starts playing when my character changes to its “dying” animation, and if I play a random level and then die in that same level, it works just fine.
However, I’ve noticed an issue that occurs the more levels I play. Each scene in my game is its own level. When I complete one level, the scene switches over to the next on. But if I play multiple levels in and then die, something odd happens. If I die after having completed at least two levels prior to the one that I’m playing, the sound is not only delayed, but it also cuts off roughly halfway (and it’s always halfway). I suspect that the latter may have to do with my character being deleted after the death animation is finished, as the sound only plays during the death animation, but I don’t get why the sound is getting delayed. All of my gameplay scenes more or less have the same events, and I can play a preview of any level and then die on it and the sound plays just fine, but if I die after playing two or more levels in a row the sound gets delayed.
This issue has been going on for several months now and I’ve restarted my browser multiple times since then to see if that would help, but nothing has changed.

Any insight on how would be highly appreciated!

Are you preloading the sound in the resource tab?

1 Like

This wouldn’t matter in this case, since upon playing a sound for the first time, it is loaded into memory permanently the same way as preloading does.

Try using .wav for sound effects. And .ogg for music.

MP3s don’t perform as well.

1 Like

Could someone explain the reason for this? I’m curious.

It’s not GD specific, most game devs don’t use mp3s for sound effects. Beyond that I don’t know the specifics, other than .wav is much smaller and more efficient.

1 Like

So, is there any way I can convert an mp3 file to either a wav or and ogg file? I’ve tried seeing if there are any free online ones, but I don’t know if any of them are trustworthy.

Just to double check this isn’t something simple, can you show your actual events to play the game over sound?

Okay, but as mentioned earlier it only happens when I play levels consecutively.

The only thing I could think of from that event is if the MP3 isn’t getting unloaded from memory somehow.

Before you try changing the audio file (freeconvert’s site should work fine), you might try changing from “Play the sound” to “play the sound on a channel” and choose a very low or very high channel number you don’t use for something else. As far as I know “play the sound” puts all audio onto the same channel and maybe there’s some sort of memory leak over time?

Before I try that I just discovered something.
If I don’t start on the scene with the intro to the game, the game over sound plays just fine. The intro has a six second long theme song that plays during it. Could that be what’s causing this, possibly the memory leak that you proposed?

Update:

Unfortunately, the delay still occurs even if the audio is playing on a wav file. Additionally, I’ve also discovered that during the second level, how much of the audio file plays actually varies depending on how soon you die. It only plays the full audio file if I die right at the beginning, but the further into that level you die, the shorter the audio gets, until it reaches the halfway point mentioned earlier.

So, some interesting developments have happened in the past two days.
For one thing, by choosing to preload wav files as sounds, I was able to make the game over sounds play fully during level 2, at least to an extent. Basically sometimes it works, sometimes it doesn’t. Two days ago is when I first got it to work. About two hours later I went to try it again, and for some reason it no longer worked, despite not having made any changes before I turned it of earlier (and I did save).

Then I ran a preview again yesterday, and for some reason it suddenly worked again. I experimented on replacing the audio files with wav counterparts in levels 3 & 4 but the audio cut of about halfway in them as well, and the game over sound continued to play normally in level 2, until it didn’t and reverted back to being cut off, despite not making any changes to the preview or the first two levels.

I tried running a preview this morning, and the audio cut off again while playing level 2, and I closed gdevelop without making any changes to the project. I opened it again about seven hours later without making any changes and it played normally as intended.

I still can’t get levels 3 and 4 to play normally, and I don’t know what’s going on with the game over sound selectively working/not working on level 2. I ran the preview with a debugger about an hour ago and these were my results:

So, I don’t exactly know where to go from here.