A way to use OpenSL ES like OpenAL or SoundPool ?

1,519 views
Skip to first unread message

Cedric

unread,
Aug 13, 2011, 3:52:26 AM8/13/11
to android-ndk
Hello,

I made a game library in C using OpenGL ES and OpenAL, now I'm working
on porting this library to android using ndk.
I tried the OpenAL port but I get errors at initialization, If I
discard the errors, then it works on 2.3.3 but crash on 2.1
So I tried native OpenSL ES and I'm getting stuck with the way this
api works.
With OpenAL I'm creating about 8 sources, buffer all my sounds, and
when I want to play one, I simply start a source with one of my
buffered sounds.
With OpenSL I'm trying to do the same, loading all my sounds into
memory, then CreateAudioPlayer each time I want to play a sound.
It works great with a single sound playing, but when trying multiples
sounds/audioplayer at the same time it doesn't work that well.
Either I get randoms crashes when enqueing the buffer, or I get only
one sound playing (and not the others)
Sometimes CreateAudioPlayer returns invalid parameters error.
I don't really understand what is going on.
Is OpenSL ES designed to work that way (playing multiples sounds and
big buffers ?)
Or is it designed to play only one small ring buffer and the
programmers have to create its own sound mixer ?

Do you know a simple way or a library to play multiples sounds easily
using ndk ?
I'm not very familiar with java so I tend to avoid using it.

Chris

unread,
Aug 15, 2011, 4:54:35 AM8/15/11
to android-ndk
Sounds on Android is a bit of mess.

OpenSL is only available on API level 9 (Android version 2.3) so it's
not a great option yet.

You can use SoundPool or MediaPlayer objects and then use JNI to call
them - that works pretty well though you will have to roll your own
distance attenuation and logic for positional sound.

SoundPool has some serious issues on the Samsung Galaxy S2 if you try
and play more than a couple of sounds at once.

MediaPlayer objects seem to work pretty well for short sound effects.
In the latest version of my game I'm only using SoundPool for one
sound effect and that is only because it's an engine noise and I want
to be able to change the pitch as the tank moves more quickly. You
can't do this with the MediaPlayer.

Calling from your C++ code back into java is actually pretty painless.

You can try it out here. I'm happy to share the sound engine code with
you - it's pretty basic though...

https://market.android.com/details?id=com.cmgresearch.tankgamefree&feature=search_result

Cheers
Chris.

www.rzr.online.fr

unread,
Aug 16, 2011, 6:13:20 AM8/16/11
to android-ndk
> On Aug 13, 8:52 am, Cedric <ced...@globz.com> wrote:
>
>> Hello,
>
>> Do you know a simple way or a library to play multiples sounds easily
>> using ndk ?
>> I'm not very familiar with java so I tend to avoid using it.


On 15 aout, 09:54, Chris <cmgreen...@googlemail.com> wrote:
> Sounds on Android is a bit of mess.

hi

I confirm audio support on android can be frustrating :

* opensl learning curve and support does not worth the effort now
* java api has some limitations I wish I could overcome (see later)
* simulator needs to improve support
* finally direct access to audio controller seems pretty obscure...

For instance,

I asked about "How to set Audio Sampling rate higher than 44.1kHz"
and
I got no reply yet

http://stackoverflow.com/questions/7023821/how-to-set-audio-sampling-rate-higher-than-44-1khz

So I dont know where to push this question ? (here?)

But I wont give up :-)

BTW, can you suggest some OpenAL@android resources , or alsa@android
ones ?

Thanks

Cedric

unread,
Aug 16, 2011, 11:28:12 AM8/16/11
to android-ndk
I tried SoundPool but the 1Mbytes limit is not acceptable for me.
So I tried MediaPlayer, and it seems to work...
It's just that my library Sound API is not really working the same way
MediaPlayer do, but I will try to overcome this.

But I'm still wondering why OpenSL have so much problem, it's really
heavy to init and use, and yet it seems not even appropriate to be
used in a game :/

Eric Wing

unread,
Aug 16, 2011, 2:47:22 PM8/16/11
to andro...@googlegroups.com
> So I dont know where to push this question ? (here?)
>
> But I wont give up :-)
>
> BTW, can you suggest some OpenAL@android resources , or alsa@android
> ones ?

There is somebody working on an OpenSL ES implementation of OpenAL for
OpenAL Soft. I need to follow up on the status. (Last I recall, there
were legal hoops to jump through before the source code could be
released.)

I think this appeared on the OpenAL mailing list at one point. For
OpenAL info in general, the OpenAL mailing list is a good place to go
(it's a bit low traffic though).

-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

Christopher Van Kirk

unread,
Aug 16, 2011, 3:58:22 PM8/16/11
to andro...@googlegroups.com
Tell me again that software patent law doesn't impede progress.
Reply all
Reply to author
Forward
0 new messages