Mix_FadeOutMusic(500) causes a delay similar to SDL_Delay(500)

Hello,

I’ve created an Audio object that wraps up some of the SDL2_mixer functions to play background music in my game.

A call to Mix_FadeOutMusic(500); causes a significant delay in my program. It basically locks up the play of the game for 500 ms.

Also note I get nearly the same results by doing the following, but without the actual fade:

MixFadeOutMusic(0);
SDL_Delay(500);

1.) Does the audio system run on its own thread out of the box?
2.) What can I do differently to have my game keep running smoothly but still have the benefits of having the music fade out?

Thanks for your time,
Electrosys

This shouldn’t happen if your game loop is set up correctly, so my guess is that’s where the problem is. Would need to see more code to be sure. I’ve wrapped SDL2_mixer in a class and have faded out music without any problems like this. What platform are you using?

I am building my app in Fedora using VSCode. I’m currently building against SDL2-devel.x86_64 2.0.16-3.fc34 and SDL2_mixer-devel.x86_64 2.0.4-8.fc34. I was hoping to find a threads window in VSCode (much like the threads window in Visual Studio). Does anyone know if there is a threads window in VSCode?

Also I’m wondering, does the audio system run in it’s own thread by default? It is possible that maybe the audio is running in the rendering thread. I need to look at my code a bit and do a little refactoring probably. I don’t think it will be all that useful to just copy and paste blocks of code here. Let me do some refactoring and see where I’m at. I have my project on github so maybe I will create another thread and ask for a code review. This is my first SDL app, its a tetris clone and I’m pretty close to getting it finished up.

The other thing I notice in my program is that it will lock up once in a while for a moment, much like the old nes games did (if your familiar with that). There is certainly a small memory leak somewhere that I need to work out as well. Let me figure out the best way to share my code.

Thanks for your help,
Electrosys

I understand (some of it).

Try this. Make a very basic game loop in main() and add to it until you find the problem. You can draw a moving square and hit any key to play a sound in under 50 lines of code. That’s the best place to start