Feedback on Removing the Isolate & Latency Questions #95
Replies: 4 comments 4 replies
-
Hi @Cornfritter, thanks for your feedback!! Hope the PR without the isolate will land soon. As I understand your wish is to implement an audio sequencer. Here a low latency is important, but we are using a language with a Garbage Collector. This means that we cannot prevent/predict when GC will do its job. This job is always made on the main isolate and can produce the latency problem. It could take 20 ms when it needs to generate collection and up to (IIRC) 100 or more ms when it compacts memory. Saying that, the C code does not have a GC and maybe it's possible to optimize it for a sequencer use case. On the Dart side IMHO there is not much we can do, but maybe, I never tried, the use of microtasks ( There is also the "audio buffer" length variable when we encounter latency problem. This is discussed here. If you want to look at the code, it could be somehow simple: in the I'll appreciate any of your findings! |
Beta Was this translation helpful? Give feedback.
-
@alnitak, thank you! That's very helpful info. I was thinking about buffer size. I'll report back anything which might be useful. |
Beta Was this translation helpful? Give feedback.
-
Reducing the buffer size resolves most of the fluctuations I was hearing! And I agree with the discussion in that other thread that a feature to configure buffer size in Dart would be really helpful. Inspired by this, I'll probably implement the audio loop in C with FFI to improve things further. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Let me know your progress, even by email if you want. |
Beta Was this translation helpful? Give feedback.
-
Happy to have found out about this plugin! I've been looking for more precise audio playback in Flutter for a project which is basically an audio sequencer. It has an audio event loop in an isolate which triggers sounds.
First, I've tried the branch without the built-in isolate, and it's great for this project. I can run SoLoud in the same isolate as the event loop, eliminating latency from sending messages between the event loop and playback isolates. I hope this is incorporated into the main branch.
I'm running into other latency issues though, and hope someone might have some advice.
The elapsed time of
await play
seems to spike 10x every once in a while (when playing a series of short sounds), from on the order of 0.1ms to 1ms.Measuring latency with only the elapsed time of
await play
doesn't seem sufficient. I hear more fluctuations than are represented by that. So I think there must be something in SoLoud taking a variable amount of time after the handle is returned.When initially playing a series of sounds, the elapsed time for the first sound is significantly higher, around 4ms, than the rest (excluding the above issues). This can be mitigated by around half by playing the loaded sounds at 0 volume before playing the sequence. It's still quite high though.
Any suggestions or info about this would be much appreciated! And/or where to start looking in the source code for causes of these things; I assume SoLoud has been well optimized over the years though... I also realize my environment might be a factor, running in an iPhone simulator.
Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions