Alternative OpenSL ES on Android

I am creating an android application where necessary to play pcm data in a queue as a float. As far as I can see, this is not possible. Description says:

SL_DATAFORMAT_PCM does not allow an application to specify a data representation as a signed integer, an unsigned integer, or a floating point. The Android implementation assumes that 8-bit data is an unsigned integer, and 16-bit data is a signed integer. In addition, PerSec field samples are incorrect because the actual units are in milliHz. It is expected that these problems will be addressed in the next version of OpenSL ES, which will introduce a new advanced PCM data format that allows the application to explicitly specify the view and adjust the field name. Since this will be a new data format, and the current PCM data format will still be available (although outdated), it should not require immediate changes to your code.

Is it possible to get this work through opensl es (1.0.1) OR is there an alternative to opensl es for android ndk?

+4
source share
3 answers

You can convert the floating point waveform to 16 bits and pass it to OpenSL.

Since you need access to wave data in order to pass it to OpenSL, it needs to be straightforward to do the conversion at runtime - without much overhead.

OpenSL requests that the memory cell remain valid until it no longer needs it. That way you can use an intermediate buffer to convert and reuse it.

Here is how I did it. In fact, I use only one stream and do all the mixing of the source code in the software.

+2
source

You can use ffmpeg to perform such a conversion. It has a specific library along with a set of APIs for this purpose, all of which are defined in libresample / avresample.h. I could not find much information or any tutorial on how to do this, but looking at the header file should be enough. It is pretty simple:

http://ffmpeg.org/doxygen/trunk/avresample_8h.html

Hope this helps you!

+1
source

SND_PCM_FLOAT is supported on Android L and above.

However, it may make sense to do the conversion yourself. There is currently no guarantee that any particular device will support floating-stream output natively. Even on devices whose hardware supports float, the kernel or Android HAL cannot be configured to use it. So at some point, the software will convert. And if you pay for the conversion in the software, you can also do it yourself so that you can choose your own range correction and anti-aliasing algorithm.

0
source

Source: https://habr.com/ru/post/1442293/


All Articles