Very huge delay to load streamed .mp3 files

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Sulunia
Party member
Posts: 203
Joined: Tue Mar 22, 2016 1:10 pm
Location: SRS, Brazil

Very huge delay to load streamed .mp3 files

Post by Sulunia »

So, here goes nothing.

So far, everything works in my current project. But there is something annoying me quite.

Whenever i load a new .mp3 file, the entire game freezes for almost 1.5 seconds whilst the file loads.

I know all love systems run on the main thread, so is there any way to speed up this loading process?

It's not crucial though, it's just that that's pretty annoying. :halloween:
Don't check my github! It contains thousands of lines of spaghetti code in many different languages cool software! :neko:
https://github.com/Sulunia
zerocoolisgod
Prole
Posts: 28
Joined: Fri Jan 22, 2016 2:48 am

Re: Very huge delay to load streamed .mp3 files

Post by zerocoolisgod »

Load all of your MP3s into a table when the game or level or whatever starts. Then access them from that table when you need them. It'll move all of your load times to the beginning where timing isn't an issue.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Very huge delay to load streamed .mp3 files

Post by slime »

Sulunia wrote:Whenever i load a new .mp3 file, the entire game freezes for almost 1.5 seconds whilst the file loads.
Are you loading the mp3 into a streaming or a static source? How big is the file? Can you post a .love that has the long load time?
User avatar
Sulunia
Party member
Posts: 203
Joined: Tue Mar 22, 2016 1:10 pm
Location: SRS, Brazil

Re: Very huge delay to load streamed .mp3 files

Post by Sulunia »

zerocoolisgod wrote:Load all of your MP3s into a table when the game or level or whatever starts. Then access them from that table when you need them. It'll move all of your load times to the beginning where timing isn't an issue.
This is a rather bad idea. Since i'm developing a rhythm game, let's say, for an example, a user has 130 songs installed in the game. If i loaded all 130 mp3's file @ startup, besides the fact the game would take an infinity to load, memory usage would SKYROCKET.

So, i don't think that's a good idea, it would work fine if the user had something about ~10 songs.
slime wrote:
Sulunia wrote:Whenever i load a new .mp3 file, the entire game freezes for almost 1.5 seconds whilst the file loads.
Are you loading the mp3 into a streaming or a static source? How big is the file? Can you post a .love that has the long load time?
I'm loading then into a streaming source. File sizes are about a music size (3.6Mb~4.5Mb), mp3 type.
It's rather hard for me to post the .love here, because this particular section is tied up to a lot of other spaghetti code.
I could post the entire game here if it's absolutely necessary.. (there is actually no game yet, just UI and splashscreen).

The function i call to load the song follows:

Code: Select all

function loadSong(songLoad)
	debugLog("Loading song at filepath "..songLoad, 1, moduleName)
	songData = love.sound.newSoundData(songLoad)
	songPlay = love.audio.newSource(songLoad, "stream")
	debugLog("Done!", 1, moduleName)
	debugLog("Information: Sampling rate is "..songData:getSampleRate(), 1, moduleName)
	debugLog("Information: Size is "..songData:getSampleCount().." samples", 1, moduleName)
	songPlay:setVolume(0.75)
end
(Obs: the reason why i also create a songData is to be able to perform an FFT transformation to get frequency data.)
Don't check my github! It contains thousands of lines of spaghetti code in many different languages cool software! :neko:
https://github.com/Sulunia
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Very huge delay to load streamed .mp3 files

Post by slime »

If you load the file into a SoundData, then the entire thing has to get decoded at once when you call newSoundData. When you pass a SoundData to newSource it's always static. So by using a SoundData you won't have a streaming Source.

If you really need the SoundData, you could load it in a separate thread to prevent the game from stalling while it loads. A library like love-loader can make it pretty easy to load things in another thread.
User avatar
Sulunia
Party member
Posts: 203
Joined: Tue Mar 22, 2016 1:10 pm
Location: SRS, Brazil

Re: Very huge delay to load streamed .mp3 files

Post by Sulunia »

I see. I'm gonna modify the function then a little bit, so it only loads the SoundData to a song if we need the FFT processed values.

Many many thanks!
Don't check my github! It contains thousands of lines of spaghetti code in many different languages cool software! :neko:
https://github.com/Sulunia
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Very huge delay to load streamed .mp3 files

Post by T-Bone »

I just want to add that if you're really loading the songs for streaming, then preloading everything wouldn't cause memory usage to skyrocket much at all. It's essentially just pointers to the files, it doesn't store much audio data for the files until you start playing.
User avatar
Sulunia
Party member
Posts: 203
Joined: Tue Mar 22, 2016 1:10 pm
Location: SRS, Brazil

Re: Very huge delay to load streamed .mp3 files

Post by Sulunia »

I see, i didn't know it worked like that.

I already modified the loading routine, now it can optionally load or not the soundData. Now it loads the music too fast.. Hahaha

I'll see if i can finish at least a bit of the ingame tonight, so i have something to show you guys!
Don't check my github! It contains thousands of lines of spaghetti code in many different languages cool software! :neko:
https://github.com/Sulunia
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Very huge delay to load streamed .mp3 files

Post by T-Bone »

Now that I think some more about it, I'm not quite sure how streaming in Löve works. It could be that it reads and loads the sound files compressed into RAM, and then transform that into uncompressed, playable audio when you start playing. Compressed sound files can be quite small...
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Very huge delay to load streamed .mp3 files

Post by slime »

T-Bone wrote:Now that I think some more about it, I'm not quite sure how streaming in Löve works. It could be that it reads and loads the sound files compressed into RAM, and then transform that into uncompressed, playable audio when you start playing.
Yep, that's how it works currently. It loads the entire encoded file into memory, and then gradually decodes it a dozen or two kilobytes at a time when you play the source.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 209 guests