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

Flame.audio performance issues #34

Closed
JamesMudge opened this issue Jan 21, 2019 · 3 comments
Closed

Flame.audio performance issues #34

JamesMudge opened this issue Jan 21, 2019 · 3 comments

Comments

@JamesMudge
Copy link

JamesMudge commented Jan 21, 2019

Calls to Flame.audio.play() have a high performance impact.

I lose 5-15 frames making as few as two calls per second on a physical android s5.

@luanpotter
Copy link
Member

Hi, @JamesMudge , thanks for your feedback! If you are playing audios on that high frequency, you probably should consider using an AudioPool, instead of Flame.audio. Creating and buffering audioplayers instances is indeed very, very expensive. There is nothing you can do, other than preload everything before you use it. Could you please test that and see if the results are better?

@JamesMudge
Copy link
Author

I should have noted that I am using Flame.audio.loadAll([...]) to pre cache all the sounds well before I try to use them.

@JamesMudge
Copy link
Author

Using AudioPool does improve this situation greatly. For anybody who ends up here is what you're looking for:

// in a global place
AudioPool pool = new AudioPool('fire.ogg', minPlayers: 2, maxPlayers: 2); // default prefix is assets/audio/sfx/

// will play once the sound specified, very quickly, you can repeat up to 2 times simultaneously very quicky. if you request more, it will create a third player and so on, but it might take longer, and those extra players will be disposed later
pool.start()

and make sure you import 'package:flame/audio_pool.dart';

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

No branches or pull requests

2 participants