Cannot play pcm > 60kb with the AndroidSimpleBufferQueue

拥有回忆 提交于 2020-01-06 05:51:29

问题


I've initialized an AndroidSimpleBufferQueue such as values:

SLDataLocator_AndroidSimpleBufferQueue bufferLocator = {
  SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
SLDataFormat_PCM pcmFormat = {
  SL_DATAFORMAT_PCM,           1,
  SL_SAMPLINGRATE_44_1,        SL_PCMSAMPLEFORMAT_FIXED_16,
  SL_PCMSAMPLEFORMAT_FIXED_16, SL_SPEAKER_FRONT_CENTER,
  SL_BYTEORDER_LITTLEENDIAN};

SLDataSource            audioSource      = {&bufferLocator, &pcmFormat};
SLDataLocator_OutputMix locatorOutputMix = {SL_DATALOCATOR_OUTPUTMIX,
                                            outputMixObj.getObject()};
SLDataSink audioSink = {&locatorOutputMix, nullptr};
[...]

Then when I need to play a sound I enqueue such as:

bufferQueue->Enqueue(bufferQueue, (uint8_t*)buffer.data(),
          buffer.size())

It works well for buffer smaller than 60k however when the buffer is bigger no sound are played or sometime just an artifact.


回答1:


From the Specifications:

The buffers that are queued are used in place and are not required to be copied by the device, although this may be implementation-dependent. The application developer should be aware that modifying the content of a buffer after it has been queued is undefined and can cause audio corruption

So the memory must remains valid until the sound fully played.

Read the documentation and be aware of unintended struct copy :)



来源:https://stackoverflow.com/questions/44949972/cannot-play-pcm-60kb-with-the-androidsimplebufferqueue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!