gergonzalez
gergonzalez

Reputation: 2488

Play several sound effects simultaneously using OpenSL ES Android

I'm using OpenSL ES for playing music and sounds in my project. I've used native-audio sample as start and it's fine for reproduce background music and a single sound but when I try to reproduce two or more sounds at same time the sounds aren't reproduced simultaneously because the sound buffers are enqueued for playback when all previous buffers are played.

Then, after a little research, I've found two ways to fix it, in short:

  1. Use several audio players (and therefore buffer queues) for reproduce the sounds.
  2. Mix the sound effects buffers together into a single buffer and then enqueue.

My questions are: What do you think is the best approach? There's a better way that I've ignored?

Thanks in advance.

Upvotes: 2

Views: 2089

Answers (2)

Stefano Vuerich
Stefano Vuerich

Reputation: 996

I'm working with OpenSL ES as well. Little bit complicated ay the beginning...

Anyway you can create as much ObjectPlayer you want, always remember that the maximum ammount of objects is 32.

So, ideally, if you want to play 4 sounds at the same time, you need 4 PlayerObject and 1 OutputMixObject

Hope you can find usefull

Upvotes: 1

Joel
Joel

Reputation: 3454

Here's a completely different approach: I'm using SoundPool to do this: It's very simple and it works perfectly.

Upvotes: 0

Related Questions