13

Currently I'm using AudioTrack passing to it audio data from native layer to play.

It seems I can use OpenSL ES in the native layer instead of AudioTrack in Java. What are the supposed advantages OpenSL ES gives as opposed to AudioTrack?

Brijesh Kumar
  • 1,685
  • 2
  • 17
  • 28
Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
  • I'd guess advantages come mainly from portability. Assuming other OSes support OpenSL ES too. – harism Jun 26 '12 at 01:13

2 Answers2

12

OpenSL ES:

Advantages:

  1. Low Level Audio API in Android
  2. Device Independent on Android Phones
  3. Good for Gaming

Disadvantages:

  1. Supports only on 2.3+ os

AudioTrack:

Advantages:

  1. High Level API

Disadvantages:

  1. Works on Java layer and Native code has to call javalayer to play audio.
codetiger
  • 2,650
  • 20
  • 37
  • Thank you. How do you mean 'device independent' and 'good for gaming' could you, please, elaborate a bit or give me a link? – Alexander Kulyakhtin Jun 26 '12 at 06:16
  • With OpenSL ES you code everything in Native library and does not need calling Java layer for Audio, which adds some performance advantages in Gaming. And it is more Platform independent than any other API in Android. – codetiger Jun 26 '12 at 06:49
  • 2
    As OpenSL ES is a native C API, non-Dalvik application threads which call OpenSL ES have no Dalvik-related overhead such as garbage collection pauses. However, there is no additional performance benefit to the use of OpenSL ES other than this. In particular, use of OpenSL ES does not result in lower audio latency, higher scheduling priority, etc. than what the platform generally provides. from : http://mobilepearls.com/labs/native-android-api/opensles/index.html – codetiger Jun 26 '12 at 06:54
0

While this is old, others will come here from a search, as I did. I use Android 7 on a rather slow and low-powered tablet (Onda V10 4G, MediaTek processor) with no other app active. When playing .ts files recorded from television, I found that audio had continuous dropouts over Bluetooth, though it was fine through the tablet's speaker (and presumably headphones, though I didn't test). Audio output was set to the default OpenSL ES. I changed to AudioTrack, and audio is now fine, even for files accessed over a network. VLC current as of 1 August 2021. BTW, over Bluetooth I found that sound and subtitles matched what was on the screen (no huge offsets as I have sometimes found), though lip-sync was not exact). I didn't try to compensate for delay, left at default.

Files played fine through Kodi.

So in this case compelling reason to use AudioTrack. There may be settings to make OpenSL work, but I didn't bother.

pol098
  • 11
  • 2