Friday, July 1, 2016

Game Development: Alien Planet - SDL_Mixer audio problem

One of the issues I had to fix in the game was playing sound effects. For sound effects I am using SDL_Mixer. The issue I am facing was whenever I issue the command to play a new wave file/stream, the previous audio stream stops. There is no mixing happening. So, for example if you are picking a fruit while walking the audio of picking the fruit get cut and the walking audio starts immediately.

To solve this issue I used the "Mix_PlayingMusic()" function which returns true if an audio effect is playing, and false otherwise. First I created a function that loops over all the sound effects and see if any is playing. If none is doing so, then the function returns false. The game checks the result of this function before playing a new audio effect.

This solved the problem partially, what happened is that the walking sound disappears for few seconds after picking fruit. It turns out that the picking fruit audio file has few seconds of silent audio at the end. So, SDL_Mixer was playing silent audio and returning true for few seconds. The solution to this was to use Audacity to remove the trialing silent audio from all the other files, and everything worked perfectly fine.

No comments:

Post a Comment