报错1 – E/libOpenSLES: pAudioSrc: data format 2 not allowed
修复:
// SLDataLocator_AndroidBufferQueue android_queue = {SL_DATALOCATOR_ANDROIDBUFFERQUEUE, 2};
改为
SLDataLocator_AndroidSimpleBufferQueue android_queue = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
报错2 – Front channels must be present
E/libOpenSLES: Mask 0x21 is invalid: Front channels must be present
E/libOpenSLES: Cannot create audio player: unsupported PCM data source with 2 channels
代码
const SLInterfaceID ids[3] = {SL_IID_BUFFERQUEUE, SL_IID_VOLUME, SL_IID_EFFECTSEND,/*SL_IID_MUTESOLO,*/};
const SLboolean req[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE,
/*SL_BOOLEAN_TRUE,*/ };
LOGD("CreateAudioPlayer start bqPlayerSampleRate:%ld, numInterfaces:%d", bqPlayerSampleRate, bqPlayerSampleRate? 2 : 3);
result = (*mEngineEngine)->CreateAudioPlayer(mEngineEngine, &mPlayerObject, &audioSrc, &audioSnk,
bqPlayerSampleRate? 2 : 3, ids, req);
问题点:
format_pcm.channelMask 和 format_pcm.numChannels 设置的问题,把这个屏蔽就ok了,但是出现了问题3
SLDataFormat_PCM format_pcm = {
SL_DATAFORMAT_PCM,//播放pcm格式的数据
(SLuint32)channel,//1个声道
(SLuint32)sampleRate,//8000hz的频率
SL_PCMSAMPLEFORMAT_FIXED_16,//位数 16位
16,//和位数一致就行
SL_SPEAKER_FRONT_LEFT| SL_SPEAKER_FRONT_RIGHT,//立体声(前左前右)
SL_BYTEORDER_LITTLEENDIAN //字节序,小端
};
// 尽可能启用快速音频:一旦我们将相同的速率设置为本机,将触发快速音频路径
if (sampleRate >= 0) {
bqPlayerSampleRate = sampleRate * 1000;
}
/*
if (bqPlayerSampleRate) {
format_pcm.samplesPerSec = (SLuint32)bqPlayerSampleRate;
}
format_pcm.numChannels = (SLuint32) channel;
if (channel == 2) {
format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_BACK_RIGHT;
} else {
format_pcm.channelMask = SL_SPEAKER_FRONT_CENTER;
}*/
问题3 – samplesPerSec=44100
E/libOpenSLES: pAudioSrc: samplesPerSec=44100
W/libOpenSLES: Leaving Engine::CreateAudioPlayer (SL_RESULT_CONTENT_UNSUPPORTED)
解决:
SLDataFormat_PCM format_pcm = {
SL_DATAFORMAT_PCM,//播放pcm格式的数据
(SLuint32)channel,//1个声道
(SLuint32)sampleRate,//8000hz的频率
SL_PCMSAMPLEFORMAT_FIXED_16,//位数 16位
16,//和位数一致就行
SL_SPEAKER_FRONT_LEFT| SL_SPEAKER_FRONT_RIGHT,//立体声(前左前右)
SL_BYTEORDER_LITTLEENDIAN //字节序,小端
};
改为
SLDataFormat_PCM format_pcm = {
SL_DATAFORMAT_PCM,//播放pcm格式的数据
(SLuint32)channel,//1个声道
SL_SAMPLINGRATE_44_1,//8000hz的频率
SL_PCMSAMPLEFORMAT_FIXED_16,//位数 16位
SL_PCMSAMPLEFORMAT_FIXED_16,//和位数一致就行
SL_SPEAKER_FRONT_LEFT| SL_SPEAKER_FRONT_RIGHT,//立体声(前左前右)
SL_BYTEORDER_LITTLEENDIAN //字节序,小端
};