What kind of sound files should I use for the bge?

Hi fellow blender game devs,

I’ve been recently experimenting with running my game through virtual box with some great results, aside for a few issues. The first one I noticed, and the biggest one so far, is that it freezes for a few frames when a given sound is activated, whether it be through the logic brick or via python. This rarely occurs when I run the game in blender or in the blender player, but it almost always occurs only when virtualized. So far I used OGG files and then WAV files, thinking that the lag was caused by decompressing, but regardless of each file type didn’t seem to do anything. What is the “fastest” or most optimized way to handle sound, or sound file type, that I should use to minimize this lag?

I’m pretty sure your not ‘buffering’ your sounds, so that might be producing the ‘performance-lag’ - I get this all the time myself.
You can buffer/play sounds with the AUD module, which is a built-in Blender API module.


sfx_music = aud.Factory.buffer(aud.Factory(bge.logic.expandPath(str("//Audio/music.wav"))))
music = aud.device().play(sfx_music)
music.volume = 0.5
music.loop_count = -1

volume & loop_count are just 2 of very many functions that you can enable for per-sound.
If you want to find out more of them do print(dir(music)) at the end of the code-block I mentioned above.

What does buffering sounds even do you might ask?
It keeps the chosen sounds in your computer’s RAM, which helps less ‘performance-lag’ as Blender doesn’t need to keep re-importing the sound(s)