gcardozo

Memory usage increases 10x after sound loading

Recommended Posts

Hi,

I have a folder with 23MB of sounds (including music), all of them are in .ogg format because I need to support really old browsers.

When loading those sounds, memory usage goes up to 900MB. If I comment the lines below, it stays about 90MB.

What am I doing wrong?

 


       

        Controller.numMusic = 5;
        //Load music:
        for (var i = 0; i < Controller.numMusic; i++) 
        {
            let soundName:string = "music" + i;
            this.game.load.audio(soundName, "assets/audios/music/" + soundName + ".ogg");
        }
        this.game.load.audio("menu", "assets/audios/music/menu.ogg");
        this.game.load.audio(ESounds.ACERTOU, "assets/audios/" + ESounds.ACERTOU + ".ogg");
        this.game.load.audio(ESounds.ERROU, "assets/audios/" + ESounds.ERROU + ".ogg");
        this.game.load.audio(ESounds.ANDANDO, "assets/audios/" + ESounds.ANDANDO + ".ogg");
        this.game.load.audio(ESounds.CAINDO, "assets/audios/" + ESounds.CAINDO + ".ogg");
        this.game.load.audio(ESounds.CLICK_BT, "assets/audios/" + ESounds.CLICK_BT + ".ogg");
        this.game.load.audio(ESounds.CLICK_RUN, "assets/audios/" + ESounds.CLICK_RUN + ".ogg");
        this.game.load.audio(ESounds.GRAB_ARTIFACT, "assets/audios/" + ESounds.GRAB_ARTIFACT + ".ogg");
        this.game.load.audio(ESounds.PUT_ARTIFACT_ALTAR, "assets/audios/" + ESounds.PUT_ARTIFACT_ALTAR + ".ogg");
        this.game.load.audio(ESounds.BREAK_ARTIFACT, "assets/audios/" + ESounds.BREAK_ARTIFACT + ".ogg");

 

Share this post


Link to post
Share on other sites

 

I have no clue, it will still depend on final filesize come to think of it. For my own game  the music was pretty repetitive, so I would chop the unncessary and have an intro and chorus part and  loop those two using markers. the music went from 800kB to 100kB, but it depends on what kind of music you have if this will work or not. 

Share this post


Link to post
Share on other sites

I don't think it's unusual that the memory use is larger than the size of the compressed audio files. The browser needs to decode them before it can play them.

I'd guess the music accounts for most of that.

Share this post


Link to post
Share on other sites

It's best practice to stage loading files. 23mb is a lot to load right from the outset.

Try only loading sounds just before the scene where they are to be used. Then after that scene clear the cache before you load the new ones needed for the next scene.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.