ukasz123 / soundpool

Soundpool plugin for Flutter
87 stars 64 forks source link

Soundpool skipping audio when playing sounds in sequence at high periodic rates. #86

Open Wamwea opened 2 years ago

Wamwea commented 2 years ago

https://user-images.githubusercontent.com/47742225/148381196-f6fed9a9-c0f4-4a78-b740-e886efb8b3d1.mp4

I'm building a metronome app and the player skips the third of four notes in higher tempos on ios. The same does not happen on android so I am hoping I could get some clafirication or help on what to do about this.

ukasz123 commented 2 years ago

Can you provide me a smallest example that shows the issue?

ukasz123 commented 2 years ago

I've build a minimal sample of what I think you are trying to build and it seems that some sounds are not played because on iOS the concurrent maxStreams streams has been reached on higher tempos. The immediate solution is to set the maxStreams option to 2 or more.

_pool = Soundpool.fromOptions(
      options: SoundpoolOptions(maxStreams: 2),
    );

Let me know if it solves your problem.

novas1r1 commented 2 years ago

Hi @ukasz123, I'm using this issue since I'm having the same problem which is not solved yet. I built a metronome as well and it is supposed to be an opensource flutter package very soon. I uploaded it here: https://github.com/novas1r1/flutter_metronome

My issues are the following: I'm using the Timer.periodic to play two different sounds. It is lagging way more on a real device than on the android emulator, which is super weird. Since it's a metronome it has to be as accurate as possible and it starts lagging already at a low bpm amount. I needed to modify the Timer.periodic, since it is not meant to have a callback exactly after one interval, but in the timespan between one and another interval. In the documentation it says: "The exact timing depends on the underlying timer implementation. No more than n callbacks will be made in duration * n time, but the time between two consecutive callbacks can be shorter and longer than duration." (https://api.dart.dev/stable/2.17.3/dart-async/Timer/Timer.periodic.html)

I added an example which you can directly run and test to have a live demo of what I mean. Also if you check the debug console, this log is very often happening:

"D/AudioTrack(22283): createTrack_l(8): AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 0 -> 402"

I tried increasing the maxStreams, but it didn't change anything. It doesn't matter if it's a debug or a release build. You can see the live version of the current implementation in my app (links to the stores are here: drumbitious.com, sorry, don't want to advertise, just provide an example of the real implementation).

It would be so awesome if you have any hint for me on what I could improve or if soundpool might not be the right choice for me.

Thanks in advance <3!!!

versolollo commented 2 years ago

I am working on a metronome as well, increasing to 2 streams wasn't enough, but with 10 it works without lagging! I am developing for MacOS. Thanks for the tip!

novas1r1 commented 2 years ago

@versolollo just because out of curiosity: if you run your metronome on a phone - is it also not lagging? Also how much bpm are working fine?

knight0zh commented 6 months ago

@novas1r1 I encountered the same problem as you, did you finally solve it?