flame-engine / flame

A Flutter based game engine.
https://flame-engine.org
MIT License
9.29k stars 913 forks source link

Only One Sound Plays when Playing Simultaneous Sounds #118

Closed shawnlg closed 5 years ago

shawnlg commented 5 years ago

Audio Player does not play simultaneous sounds. In the documentation it talks about 2 ways of calling the audio player. One shares the flame cache and one has its own cache. I tried making different audio players for each sound FlameAudio audio = new FlameAudio(); When I play two sounds at once, only the second one plays. I'm using the play() method for short audio clips. Is it supposed to work with multiple simultaneous tracks? I'm using flame 0.11.0 with the release channel of flutter.

luanpotter commented 5 years ago

Hi, @shawnlg, FlameAudio uses AudioCache without a fixedPlayer, which means each call to play should return a new instance of AP, which means it should play two audios at once. Certainly you've stumble upon some problem. FlameAudio uses the new LOW_LATENCY mode for AP; I wonder if you could try creating your own AudioCache not in LOW_LATENCY mode to see if it's a problem specific to that feature? Also, do you have a code to show us so we can test the problem? Thanks for your feedback.

shawnlg commented 5 years ago

You can find some code here: https://github.com/shawnlg/flutter_ball/tree/12_drum_machine

Just hit record. It will play a beat and let you record drum sounds. If a recorded sound happens at the same time as the beat sound, you do not hear the beat.

Shawn

On Sat, Jul 6, 2019 at 5:11 PM Luan Nico notifications@github.com wrote:

Hi, @shawnlg https://github.com/shawnlg, FlameAudio uses AudioCache without a fixedPlayer, which means each call to play should return a new instance of AP, which means it should play two audios at once. Certainly you've stumble upon some problem. FlameAudio uses the new LOW_LATENCY mode for AP; I wonder if you could try creating your own AudioCache not in LOW_LATENCY mode to see if it's a problem specific to that feature? Also, do you have a code to show us so we can test the problem? Thanks for your feedback.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/flame-engine/flame/issues/118?email_source=notifications&email_token=ABUQTLVI5ZKWFQSLPQKCTY3P6EJ75A5CNFSM4H447ANKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZLBBZY#issuecomment-508956903, or mute the thread https://github.com/notifications/unsubscribe-auth/ABUQTLT3SNCBL7BJAR4OQBTP6EJ75ANCNFSM4H447ANA .

luanpotter commented 5 years ago

@shawnlg so you can record sounds? What lib are you using for that? AFAICR audioplayers does not provide recording capabilities. Maybe this other lib is conflicting with AP for media resources and thus the cancelling occur... Can you try to comment out the recording bit and try to play some sounds at the same time? Probably that should work better and we can then focus on this specific interference.

shawnlg commented 5 years ago

No I don't record sounds. It's a drum machine where I record drum patterns and play them back. I play back the sounds in the order and time they were tapped on.

BTW, it works fine on an iOS device. Multiple sounds play together just fine. It's Android where only the last sound plays when sounds play together.

erickzanardo commented 5 years ago

@shawnlg I see that you are using version 0.11.0 of Flame, have you tried on new versions? A lot of improvements were done on audio regarding android on newer versions.

shawnlg commented 5 years ago

I updated all my branches to version 14 and I hear the same. Only 1 sound.

The drum machine branch is the easiest to hear this. When it starts up, it plays the sound of every sprite component as it is created so you should hear all the sounds at once. On android you hear one sound and on ios you hear all of them.

Shawn Gordhamer

On Fri, Aug 30, 2019, 9:04 AM Erick (CptBlackPixel) < notifications@github.com> wrote:

@shawnlg https://github.com/shawnlg I see that you are using version 0.11.0 of Flame, have you tried on new versions? A lot of improvements were done on audio regarding android on newer versions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/flame-engine/flame/issues/118?email_source=notifications&email_token=ABUQTLRW7VVHXA62RBPBF3DQHESGFA5CNFSM4H447ANKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5RX4UY#issuecomment-526614099, or mute the thread https://github.com/notifications/unsubscribe-auth/ABUQTLVE7ZJ6SUOKT562OY3QHESGFANCNFSM4H447ANA .

erickzanardo commented 5 years ago

I am gone mark this as a bug them, and try to solve it.

luanpotter commented 5 years ago

Hi, @shawnlg , it seems that indeed there is a bug with the LOW_LATENCY mode if you play two audios EXACTLY at the same time (a few instructions apart on the same method chain). It indeed seems to play only a portion of the audios. However I switched to the old api in a fork I made:

https://github.com/shawnlg/flutter_ball/pull/1

And it seem to work fine. Certainly this is a bug in audioplayers, not flame, so I'm going to close this. Please open an inssue on audioplayers repo so we can take a better look at it.

https://github.com/luanpotter/audioplayers

But thinking ahead it might be a bug with the underlying android api that AudioPlayer LOW LATENCY mode uses... Of course that's why on iOS both work fine. Android audio apis are severely lacking IMHO (and iOS are way better but could also use some improvements).

So I'm closing this but please open an issue on audioplayers repo, @shawnlg

Thanks for reporting