I'm trying to create an AudioPlayer
with a bufferqueue source and outputmix sink. I've configured the source with a pcm format very similar to that shown in the ndk samples, but OpenSL is rejecting SL_DATAFORMAT_PCM
("data format 2"). This doesn't make any sense to me.
Here's the error (on a Samsung Galaxy S2):
02-27 15:43:47.315: E/libOpenSLES(12681): pAudioSrc: data format 2 not allowed
02-27 15:43:47.315: W/libOpenSLES(12681): Leaving Engine::CreateAudioPlayer (SL_RESULT_CONTENT_UNSUPPORTED)
and here's the relevant code:
SLuint32 channels = 2;
SLuint32 speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
SLuint32 sr = SL_SAMPLINGRATE_48;
//...
SLDataFormat_PCM format_pcm = {
SL_DATAFORMAT_PCM,
channels,
sr,
SL_PCMSAMPLEFORMAT_FIXED_16,
SL_PCMSAMPLEFORMAT_FIXED_16,
speakers,
SL_BYTEORDER_LITTLEENDIAN
};
// Configure audio player source
SLDataLocator_AndroidBufferQueue loc_bufq =
{SL_DATALOCATOR_ANDROIDBUFFERQUEUE, 2};
SLDataSource audioSrc = {&loc_bufq, &format_pcm};
// configure audio player sink
SLDataLocator_OutputMix loc_outmix =
{SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
SLDataSink audioSnk = {&loc_outmix, NULL};
// create audio player
const SLInterfaceID iidsOutPlayer[] = {SL_IID_ANDROIDBUFFERQUEUESOURCE};
const SLboolean reqsOutPlayer[] = {SL_BOOLEAN_TRUE};
result = (*engineItf)->CreateAudioPlayer(
engineItf,
&(outPlayerObject),
&audioSrc, &audioSnk,
1, iidsOutPlayer,reqsOutPlayer);
Does anyone know what's causing this? Thanks!
It turns out I needed to be using the SLDataLocator_AndroidSimpleBufferQueue
instead of SLDataLocator_AndroidBufferQueue
.