无法播放pcm>带有AndroidSimpleBufferQueue的60kb [英] Cannot play pcm > 60kb with the AndroidSimpleBufferQueue
问题描述
我已经初始化了一个AndroidSimpleBufferQueue,例如值:
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())
它对于小于60k的缓冲区效果很好,但是当缓冲区较大时,则不会播放声音,有时甚至只是伪像.
It works well for buffer smaller than 60k however when the buffer is bigger no sound are played or sometime just an artifact.
推荐答案
从规格:
已排队的缓冲区就位使用,不需要 由设备复制,尽管这可能是 与实施有关.应用程序开发人员应注意 在缓冲区排队后修改缓冲区的内容是 未定义并会导致音频损坏
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.
阅读文档,并注意意外的结构副本:)
这篇关于无法播放pcm>带有AndroidSimpleBufferQueue的60kb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!