diff --git a/NEWS b/NEWS index 94c2cf2e3..b698d4f5f 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ ver 0.21.26 (not yet released) +* output + - sles: support floating point samples ver 0.21.25 (2020/07/06) * protocol: diff --git a/src/output/plugins/sles/SlesOutputPlugin.cxx b/src/output/plugins/sles/SlesOutputPlugin.cxx index b2e1b311d..bf1d2154a 100644 --- a/src/output/plugins/sles/SlesOutputPlugin.cxx +++ b/src/output/plugins/sles/SlesOutputPlugin.cxx @@ -173,12 +173,12 @@ SlesOutput::Open(AudioFormat &audio_format) if (audio_format.channels > 2) audio_format.channels = 1; - SLDataFormat_PCM format_pcm; + SLAndroidDataFormat_PCM_EX format_pcm; format_pcm.formatType = SL_DATAFORMAT_PCM; format_pcm.numChannels = audio_format.channels; /* from the Android NDK docs: "Note that the field samplesPerSec is actually in units of milliHz, despite the misleading name." */ - format_pcm.samplesPerSec = audio_format.sample_rate * 1000u; + format_pcm.sampleRate = audio_format.sample_rate * 1000u; format_pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; format_pcm.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16; format_pcm.channelMask = audio_format.channels == 1 @@ -187,6 +187,7 @@ SlesOutput::Open(AudioFormat &audio_format) format_pcm.endianness = IsLittleEndian() ? SL_BYTEORDER_LITTLEENDIAN : SL_BYTEORDER_BIGENDIAN; + format_pcm.representation = SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT; switch (audio_format.format) { /* note: Android doesn't support @@ -201,6 +202,16 @@ SlesOutput::Open(AudioFormat &audio_format) bit */ break; + case SampleFormat::FLOAT: + /* Android has an OpenSLES extension for floating + point samples: + https://developer.android.com/ndk/guides/audio/opensl/android-extensions */ + format_pcm.formatType = SL_ANDROID_DATAFORMAT_PCM_EX; + format_pcm.bitsPerSample = format_pcm.containerSize = + SL_PCMSAMPLEFORMAT_FIXED_32; + format_pcm.representation = SL_ANDROID_PCM_REPRESENTATION_FLOAT; + break; + default: /* fall back to 16 bit */ audio_format.format = SampleFormat::S16;