androidaudioandroid-ndkopensl

OpenSL ES alternative on Android


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?


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.