alnitak/flutter_soloud

fix: A lot of RAM is needed

synchronisator opened this issue ยท 10 comments

Description

I load a bunch of audiofiles.
Round about 35 mp3 files with round about 5MB per file a complete size of 180mb.
On Linux i can see, that the RAM usage goes ob from ~450MB to 3,1GB
On Android this leads to a shutdown of the app by the system

Steps To Reproduce

Load a lot of big files.

Expected Behavior

The RAM usage should not go up this high.

Hi @synchronisator, you are right. The sounds are loaded into memory to make them accessible as fast as possible, useful for game sounds.
When you load a file, the sound handle is persistent and that sound can be played without lags. When you dispose that handle, also the memory is freed. So I suggest you to dispose the SoundProp when it ends.

Actually SoLoud::Wav.load() function is used for which the doc states:
For lengthy samples like background music, you may want to use SoLoud::WavStream instead. The Wav is all about speed, and always decodes the whole sample into memory at load time.

I put this on my TODO list

About the huge memory allocated: the audio data in an mp3 file is compressed, while into the allocated memory goes the uncompressed audio data. Since a second of audio takes about 350KB of data, every minute will take about 20 MB of uncompressed data.

Thanks for your answer. I make a practicing app for choir singers with multiple voices. So its essential that the files are played in perfect sync. So i think the Stream is not an option, but i will try.
And i want it to behave like a "normal" mediaplayer.
By the way: SoLoud works great with audio_service so is can use all features like Mediaplayer-notifications with SoLoud. Thats very nice.
So i first will try to only have one song loaded. That will cause every song to load for a few seconds before starting, but thats maybe worth it.

Hi @synchronisator,

I have made some modifications that point to resolve this specific issue.
You can now choose to load sound files not into memory. Please, read the PR to see also an unavoidable seek problem.

I will be very grateful if you will find some time to try it!
You just need to momentarily comment this line in your pubspec.yaml:
flutter_soloud: ^1.2.4

and add this:

  flutter_soloud:
    git:
      url: https://github.com/alnitak/flutter_soloud.git
      ref: wavStream

Thank you!

Wow, thanks. I will, try. maybe today or in the next few days.

I made a quick test and the backward seek is not working correct.
The App plays multiple files in sync.
When seeking back it seems to me, that only one sound is seeking back, the others are just playing from the position they were.
I think this came from this guard:
https://github.com/alnitak/flutter_soloud/pull/30/files#diff-6f194295cc02427090a6f992e889b7c6230ab120c824fae8348dcd670682eb24R393
So maybe this works only for single files being played

You are right, thank you very much.
I think I need to make my use-case-code for this. I will try soon and I will update this.

Hi @synchronisator,

I have updated the PR, but there are some problems. I explained this in the PR comment here.

What do you think about that?

I think this is fixed with #30, right? Should we close this?

Hi,
sorry for my late reply.
My usecase with mp3 is not completely solved, but i think this is maybe impossible. I think this is a great change and all problems occurring with mo3 are solvable by using another format.
So yes. It is absolutely ok to close this issue :)