Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: A lot of RAM is needed #26

Closed
synchronisator opened this issue Feb 25, 2024 · 10 comments
Closed

fix: A lot of RAM is needed #26

synchronisator opened this issue Feb 25, 2024 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@synchronisator
Copy link

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.

@synchronisator synchronisator added the bug Something isn't working label Feb 25, 2024
@alnitak
Copy link
Owner

alnitak commented Feb 25, 2024

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

@alnitak alnitak added enhancement New feature or request and removed bug Something isn't working labels Feb 25, 2024
@alnitak
Copy link
Owner

alnitak commented Feb 25, 2024

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.

@alnitak alnitak self-assigned this Feb 25, 2024
@synchronisator
Copy link
Author

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.

@alnitak
Copy link
Owner

alnitak commented Mar 1, 2024

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!

@synchronisator
Copy link
Author

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

@synchronisator
Copy link
Author

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

@alnitak
Copy link
Owner

alnitak commented Mar 1, 2024

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.

@alnitak
Copy link
Owner

alnitak commented Mar 5, 2024

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?

@filiph
Copy link
Collaborator

filiph commented Mar 8, 2024

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

@alnitak alnitak closed this as completed Mar 8, 2024
@synchronisator
Copy link
Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants