Question

I am building an app for android where it is nessessary, to play pcm data in a queue-player as float. As far as I can see that it is not possible. The description says:

SL_DATAFORMAT_PCM does not permit the application to specify the representation of the data as signed integer, unsigned integer, or floating-point. The Android implementation assumes that 8-bit data is unsigned integer and 16-bit is signed integer. In addition, the field samplesPerSec is a misnomer, as the actual units are milliHz. These issues are expected to be addressed in the next OpenSL ES version, which will introduce a new extended PCM data format that permits the application to explicitly specify the representation, and corrects the field name. As this will be a new data format, and the current PCM data format will still be available (though deprecated), it should not require any immediate changes to your code.

Is there any chance to get this work via opensl es (1.0.1) OR is there an alternative to opensl es for the android ndk?

Était-ce utile?

La solution

You can convert your floating point wave form over to signed 16 bit and feed this to OpenSL.

Since you need access to the wave data in order to feed it to OpenSL, it should be straight forward to do the conversion at run time -- without much overhead.

OpenSL is asking for the memory location to stay valid until it no longer needs it. So you can use an intermediate buffer to do you conversion it and re-use this.

This is how I did it. In fact I am using just one stream and do all source mixing in software.

Autres conseils

You can use ffmpeg in order to perform such conversion. It has specific library along with a set of APIs for that purpose, all defined in libresample/avresample.h. I couldn't find much info or any tutorial on how to do it, but by looking at the header file itself should be enough. It's pretty straightforward:

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

Hope this helps you!

SND_PCM_FLOAT is supported in Android L and above.

However, it might still make sense to do the conversion yourself. At present there's no guarantee that any particular device will support float output natively. Even on devices whose hardware supports float, the kernel or the Android HAL may not be set up to take advantage of it. So there will be a software conversion at some point. And if you're paying for conversion in software, you might as well do it yourself so that you can choose your own range correction and dithering algorithm.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top