2

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

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

我的源代码是:

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);

错误日志是:

08-20 21:05:56.960: A/libc(2015): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)
4

1 回答 1

1

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

于 2013-08-26T18:52:06.837 回答