首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我可以在安卓OpenSL SE中创建多少个PCM AudioPlayer

我可以在安卓OpenSL SE中创建多少个PCM AudioPlayer
EN

Stack Overflow用户
提问于 2013-08-22 09:18:03
回答 1查看 451关注 0票数 2

我只知道我们可以在PCM安卓中创建32个对象,但是当我用下面的代码创建OpenSL AudioPlayer时,当创建了第11个AudioPlayer时,我得到了错误。AudioPlayer可以正常使用,声音可以正常播放。但是为什么我不能一次创建更多。

任何人遇到同样的问题,请帮助我。谢谢。

我的源码是:

代码语言:javascript
复制
SLresult result;

// Set-up sound audio source.
SLDataLocator_AndroidSimpleBufferQueue lDataLocatorIn;
lDataLocatorIn.locatorType =
    SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE;
// At most one buffer in the queue.
lDataLocatorIn.numBuffers = 1;

SLDataFormat_PCM lDataFormat;
lDataFormat.formatType = SL_DATAFORMAT_PCM;
lDataFormat.numChannels = 2; //
lDataFormat.samplesPerSec = SL_SAMPLINGRATE_44_1;
lDataFormat.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
lDataFormat.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16;
lDataFormat.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
lDataFormat.endianness = SL_BYTEORDER_LITTLEENDIAN;

SLDataSource lDataSource;
lDataSource.pLocator = &lDataLocatorIn;
lDataSource.pFormat = &lDataFormat;

SLDataLocator_OutputMix lDataLocatorOut;
lDataLocatorOut.locatorType = SL_DATALOCATOR_OUTPUTMIX;
lDataLocatorOut.outputMix = s_pOutputMixObject;

SLDataSink lDataSink;
lDataSink.pLocator = &lDataLocatorOut;
lDataSink.pFormat = NULL;

SLAndroidConfigurationItf playerConfig;
SLint32 streamType = SL_ANDROID_STREAM_VOICE;

// Creates the sounds player and retrieves its interfaces.
const SLuint32 lSoundPlayerIIDCount = 3;
const SLInterfaceID lSoundPlayerIIDs[] =
    { getInterfaceID("SL_IID_PLAY"), getInterfaceID("SL_IID_BUFFERQUEUE") , getInterfaceID("SL_IID_VOLUME")};
const SLboolean lSoundPlayerReqs[] =
    { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };

    //create audioplayer for enqueue
    result = (*s_pEngineEngine)->CreateAudioPlayer(s_pEngineEngine, &m_PlayerObj[channelIndex],
        &lDataSource, &lDataSink, lSoundPlayerIIDCount,
        lSoundPlayerIIDs, lSoundPlayerReqs);
    assert(SL_RESULT_SUCCESS == result);

    result = (*m_PlayerObj[channelIndex])->Realize(m_PlayerObj[channelIndex], SL_BOOLEAN_FALSE);
    assert(SL_RESULT_SUCCESS == result);

    result = (*m_PlayerObj[channelIndex])->GetInterface(m_PlayerObj[channelIndex],
                            getInterfaceID("SL_IID_PLAY"), &m_Player[channelIndex]);
    assert(SL_RESULT_SUCCESS == result);


    result = (*m_PlayerObj[channelIndex])->GetInterface(m_PlayerObj[channelIndex],
                            getInterfaceID("SL_IID_BUFFERQUEUE"), &m_PlayerQueue[channelIndex]);
    assert(SL_RESULT_SUCCESS == result);

    // get the volume interface
    result = (*m_PlayerObj[channelIndex])->GetInterface(m_PlayerObj[channelIndex],
                            getInterfaceID("SL_IID_VOLUME"), &m_PlayerVolume[channelIndex]);
    assert(SL_RESULT_SUCCESS == result);

    // Starts the sound player. Nothing can be heard while the
    // sound queue remains empty.
    result = (*m_Player[channelIndex])->SetPlayState(m_Player[channelIndex], SL_PLAYSTATE_PLAYING);
    assert(SL_RESULT_SUCCESS == result);

错误日志为:

代码语言:javascript
复制
08-20 21:05:56.960: A/libc(2015): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)
EN

回答 1

Stack Overflow用户

发布于 2013-08-27 02:52:07

这不是一个特别有用的答案,但是与OpenGL功能非常相似,OpenSL的技术限制将取决于用户拥有的特定硬件。您应该重新审视您的用例,并确定减少所需通道数量的方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18370178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档