Audio settings to save memory/cpu

W

Wild_West

Guest
I think I'm finally ready to add my music to my game now but the last time I tried to run it with all the music files included, songs I made about 5 or so minutes in length, .wav format, the game would be extremely laggy, so I took it all out while I continued debugging the game play aspects.
and it doesn't help that I already have high memory and cpu usage on my very basic windows 7 computer (I've had trouble with the gameplay screen freezing the graphics while the game runs too because of this high cpu and memory thing so adding all the music will only make it worse I'm sure.)

so if someone could explain what the differences of the sound properties attributes are. By which I mean compressed vs uncompressed. What exactly does one do over the other?

It might not even help my cpu and memory problem but I'd like to know and the manual always just seems to leave me lost. I don't know why I can never follow it that well on bigger articles. Maybe I'm just not very bright :p
 

obscene

Member
Use the first option: https://docs.yoyogames.com/source/dadiospice/000_using gamemaker/006_sounds and music.html

To manage audio in memory, you need to use audio groups and load/unload them manually when you need them (with a loading screen or some smart on-the-fly loading).

https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sounds/audio groups.html

When you call the load_audiogroup function only what you need is pulled into memory and it will be low CPU. You CAN do this for music too but that's high memory if your song is long/high quality. You would typically use the last option for large music files.

However you already have problems to solve it sounds like. If your game is huge in memory you should be using Create Textures on Demand and loading / unloading texture pages in a similar fashion to audio. If your game is using high CPU, you should use the profiler to see what you can optimize / cut. If your game is using high GPU you should be working to reduce texture swaps / vertex batches etc.

If any of that sounds foreign let me know I'll be glad to advise.
 
W

Wild_West

Guest
I'm clueless about the texture pages/swaps, vertex patches and the profiler.
I'm not 100% sure on how high the memory usage is, I can send you the compile form section where it mentions that, but another member told me before when I was trying to figure out where my screen freeze was coming from said that it didn't seem to be using a lot. So it might just be that my computer doesn't have enough RAM. But yeah if that's the case reducing the usage of any memory or cpu will help.
 

NightFrost

Member
This blog post by YoYo about optimization is a little old but still largely relevant. It suggests that music should always be compressed (streamed from disk).
 
W

Wild_West

Guest
This blog post by YoYo about optimization is a little old but still largely relevant. It suggests that music should always be compressed (streamed from disk).
Yeah that's what all my sound effects are set to, os that better for them too or just the music?

Put show_debug_overlay(true) in the start of your game and you'll see your swaps / batches.

https://docs.yoyogames.com/source/dadiospice/002_reference/debugging/show_debug_overlay.html

The higher these numbers the more problems you're going to have.
Alright so I ran the game with debug_overlay active, and I'm getting numbers for what I assume are the vertex batches or texture swaps the manual said it would display.
The numbers are both showing around (11) (12) max and are about (4) (5) when I'm on pause.
The bar at the top is showing mostly an equal amount of yellow and red, not any of the other colores mentioned like green or white.
 
Last edited by a moderator:

obscene

Member
Yeah that's what all my sound effects are set to, os that better for them too or just the music?
Your sound effects should NOT be compressed or set to streamed from disk. They should be uncompressed (unless disk space is somehow an issue) and set into audiogroups. Look at my game for example...

upload_2016-11-25_12-57-10.png

You'll see I have a ton of audiogroups. All of these are sound effects, but none of these are in memory normally. When I start a level, certain groups will be opened and loaded into memory while others will be unloaded. They are not compressed so they can play back fast with no lag.

On the other hand you'll see a bunch of ogg music files. These are here because I set them to compressed (streamed on disk). They are directly on the hard drive now in the game folder in raw OGG form. Not audiogroups. Because they are so big I don't want them in memory so GM reads them in real time off the hard drive. This is more CPU intensive, but it's only being done for one song and not 30 or 40 sound effects at once. If you have your sound effects all set like this, this means your install folder would be full of OGG files and they would have to be ran every time you played a sound effect. Very slow.

IF you had a song that was a short one minute loop or something, sure, choose the top option (Uncompressed, not streamed) becuase it's not going to be a big memory hog and you'll get more efficient playback.

...

On your texture swaps, those are extremely low numbers so that's good. So if you are getting slowdown it's from something else. Time for the profiler.
 
W

Wild_West

Guest
Okay I see now, that was helpful, thanks.
I'll set up some audio groups for my sfx then, there are of course way more of those than I have music.
I just have a persistent object that plays what music I need in the different rooms.

And actually everything was working okay for a while until I came to a certain point in he first practice level I did. I got close to this enemy object, and I was using a power up my character had that sets these floating stones circling him, that damage enemies they touch, and as soon as the stone object hit the screen's current frame froze but I could still play the game , sounds and other functionality all working, just the scene never updated past that frozen frame.
So that'd be gpu right?
 

obscene

Member
It's probably GPU if you don't see the yellow line on the debugger going through the roof or your swaps/batches going up. You could have a memory link, or running some heavy functions like collisions etc that are too slow for the situation. Only way to tell is using the profiler. Also you might want to create yourself a handy little debug object that draws important things to screen for you, like the number of instances in a room (instance_count()); and other variables you need to keep track of. For instance you might be creating a ton of objects on a loop and not realizing it.
 
W

Wild_West

Guest
It's probably GPU if you don't see the yellow line on the debugger going through the roof or your swaps/batches going up. You could have a memory link, or running some heavy functions like collisions etc that are too slow for the situation. Only way to tell is using the profiler. Also you might want to create yourself a handy little debug object that draws important things to screen for you, like the number of instances in a room (instance_count()); and other variables you need to keep track of. For instance you might be creating a ton of objects on a loop and not realizing it.
No I'm sure that's not it, since I ran into trouble with a while loop for collisions just like that when I first started this game.Hence my never using any loos other than for.
Plus the number of stone projectiles my player can generate at any one time is limited to 8.
As for the collisions going on, at the time of the freeze there'd only be a wall collision for my player on the ground and a collision between the enemy hit and the stones , none of which are exactly complex, but I'll lok into the profiler thing.

slight problem I don't have an option for making an audio group
 
Last edited by a moderator:
Top