Timers and music question!

Hello again, I have two questions this time!

  1. We are starting to get into music for our game, what I’m asking is what is the “norm” or “average” length of songs and formats you guys use? Ex. I am in my dungeon is the song on a 5 or 15 or 30 sec loops? The starting app screen have maybe a 30sec loop? I’m already pushing hard for 30fps and I’ve heard music is rough on performance and I would not like to cheap out on this part.

  2. I have this “whirlpool or geyser” thing that turns on and off, the code itself is fine but the timer itself seems to jitter or get weird over time where I would like it to turn on every 5 seconds and after it turns off 2 seconds later something very simple. But after some time it will start spamming every milliseconds and go nuts or speed up and change times etc.

    game.geyserTimer_1 = timer.performWithDelay(5000, function() game.geyser_1.isBodyActive = true; game.geyser_1:setSequence(“geyser”); game.geyser_1:play(); end, -1) game.geyserTimer_1 = timer.performWithDelay(7000, function() game.geyser_1.isBodyActive = false; game.geyser_1:setSequence(“geyserOff”); game.geyser_1:play(); end, -1)

I tried infinite loop and it also gives weird behaviours, I tried doing stuff like os.time(5000) inside the timers instead, etc.

Thanks for your time and input, all advice is greatly appreciated!

Hi Azmar,

  1. If you stream the music in, it shouldn’t cause a performance issue no matter the length of song. Only rarely should a complete song be pre-loaded fully into memory.

  2. I generally recommend timer onComplete functionality for things that swap on and off in an endless cycle. For example, I start one timer only, and when it completes I change the state of whatever (i.e. geyser turns off and I set some flag or property of the geyser which tells me it’s off). Then I start another timer with an onComplete pointed at the same function, and when it completes, I revert the state (geyser turns on). Repeat the process, and you’re good to go. It’s also easier to pause and resume one timer instead of trying to manage two concurrently.

Hope this helps,

Brent

Thank you this helped a lot! #2 is complete and working now on figuring out #1!

May I ask what could a possible scenario be for pre-loading a song fully into memory? I noticed when I change composer scenes the songs still play through so I guess I have to manage them between scenes which make sense. But I start the stream( 1min song) when I load the new composer scene? To have it shut down on the removeScene and start a new stream when loading  a new scene (1min song)?

Hi Azmar,

I can’t think of any great reason why somebody would pre-load a full song (over 30 seconds) into memory, instead of streaming it, but who knows, it suppose it’s conceivable for some rare cases.

Yes, when you change scenes, you need to stop the audio streaming, clear the channel, and discard the audio handle. Otherwise you will likely get a memory leak.

Hope this helps,

Brent

Hi Azmar,

  1. If you stream the music in, it shouldn’t cause a performance issue no matter the length of song. Only rarely should a complete song be pre-loaded fully into memory.

  2. I generally recommend timer onComplete functionality for things that swap on and off in an endless cycle. For example, I start one timer only, and when it completes I change the state of whatever (i.e. geyser turns off and I set some flag or property of the geyser which tells me it’s off). Then I start another timer with an onComplete pointed at the same function, and when it completes, I revert the state (geyser turns on). Repeat the process, and you’re good to go. It’s also easier to pause and resume one timer instead of trying to manage two concurrently.

Hope this helps,

Brent

Thank you this helped a lot! #2 is complete and working now on figuring out #1!

May I ask what could a possible scenario be for pre-loading a song fully into memory? I noticed when I change composer scenes the songs still play through so I guess I have to manage them between scenes which make sense. But I start the stream( 1min song) when I load the new composer scene? To have it shut down on the removeScene and start a new stream when loading  a new scene (1min song)?

Hi Azmar,

I can’t think of any great reason why somebody would pre-load a full song (over 30 seconds) into memory, instead of streaming it, but who knows, it suppose it’s conceivable for some rare cases.

Yes, when you change scenes, you need to stop the audio streaming, clear the channel, and discard the audio handle. Otherwise you will likely get a memory leak.

Hope this helps,

Brent