alnitak / flutter_soloud

Flutter low-level audio plugin using SoLoud C++ library and FFI
MIT License
209 stars 21 forks source link

feat: Make it possible to "instance" SoLoud? #35

Closed filiph closed 6 months ago

filiph commented 6 months ago

Description

SoLoud is currently always a singleton. There's a single SoLoud underlying engine, and the Dart API exposes it via SoLoud(). We could go that way but I wonder if it's possible (even easy?) to make SoLoud instanced.

This would mean that every time you call SoLoud(), you'd get a new instance of the engine. You could have multiple running at the same time.

PROs:

CONs:

Requirements

filiph commented 6 months ago

Hey @alnitak, this will evidently need some thinking, but a first, relatively straightforward thing to answer would be:

Is SoLoud (the underlying C library) capable of being instanced?

If that's not the case, then we can clearly close this issue.

alnitak commented 6 months ago

Is SoLoud (the underlying C library) capable of being instanced?

I was thinking about this. Is not possible to have for example 2 SoLoud instances because there can be only one player instance on C side. But, yes, you can implement final engine = SoLoud(sampleRate: 44100); easily, but this engine will have that sampleRate for its entire life cycle. So I think we can close this.

filiph commented 6 months ago

Ok, this is really helpful. If it's not possible to have two instances on the C side, it shouldn't be possible to have two instances on the Dart side. This simplifies things. Thanks for the quick reply!