Sample code to decode audio with OpenSL ES to AndroidSimpleBufferQueue

1,494 views
Skip to first unread message

fritzr

unread,
Mar 27, 2012, 4:25:07 PM3/27/12
to android-ndk
Hi together,
I was trying to write a small application which will use the new
OpenSL ES features to decode audio files to PCM. I was wondering if
there is anyone who can help us, as we have problems with it. One
question is for example, if it is possible to init the decoder and
than pull the decoded pcm data from the buffers. As for my
understanding it is working the other way around, which means that the
decoder will start and fill the different buffers and invokes the
callbacks. From within the callback method you should enqueue the next
buffer. This is more a push mechanism right?

There is one post http://groups.google.com/group/android-ndk/browse_thread/thread/b795132da7e6a2d1
which is not answered and complete. Any ideas?

Cheers
Fritz

Glenn Kasten

unread,
Mar 29, 2012, 10:31:37 PM3/29/12
to android-ndk
Your description in first paragraph is correct ... the app enqueues
empty buffers, the system then fills them with decoded PCM and calls
completion callback after each is filled. And as you've said, you
should enqueue a new empty buffer (typically the same one but doesn't
have to be) from within the callback after copying out the data.
> There is one posthttp://groups.google.com/group/android-ndk/browse_thread/thread/b7951...

fritzr

unread,
Mar 31, 2012, 7:39:55 PM3/31/12
to android-ndk
Thanks for your reply. Actually I made my code running. There was one
page with some test classes which helps me somehow.
You can have a look here:
http://source-android.frandroid.com/system/media/wilhelm/tests/examples/slesTestDecodeToBuffQueue.cpp

There is another problem for which I have to find a explanation/
solution.
It seems that the buffer size (the last parameter in the Enqueue
method) is really important. It seems that you have to define the
correct size depending on the input format.
If you want to decode mp3 you have to use 2*1152 bytes. If you want to
decode ACC you have to user 2*1024 bytes.

I assume, that you have to identify the input source first (mp3, acc
etc.) and then set the correct buffer size?

Kind regards
fritzr
Reply all
Reply to author
Forward
0 new messages