Don't use the same buffer segment for enqueueing in OpenSL

This commit is contained in:
Chris Robinson
2014-01-15 15:27:38 -08:00
parent 1739998045
commit 5fdc3c093e
+11 -4
View File
@@ -97,6 +97,7 @@ typedef struct {
void *buffer;
ALuint bufferSize;
ALuint curBuffer;
ALuint frameSize;
} osl_data;
@@ -175,12 +176,16 @@ static void opensl_callback(SLAndroidSimpleBufferQueueItf bq, void *context)
{
ALCdevice *Device = context;
osl_data *data = Device->ExtraData;
ALvoid *buf;
SLresult result;
aluMixData(Device, data->buffer, data->bufferSize/data->frameSize);
buf = (ALbyte*)data->buffer + data->curBuffer*data->bufferSize;
aluMixData(Device, buf, data->bufferSize/data->frameSize);
result = (*bq)->Enqueue(bq, data->buffer, data->bufferSize);
result = (*bq)->Enqueue(bq, buf, data->bufferSize);
PRINTERR(result, "bq->Enqueue");
data->curBuffer = (data->curBuffer+1) % Device->NumUpdates;
}
@@ -354,7 +359,7 @@ static ALCboolean opensl_start_playback(ALCdevice *Device)
{
data->frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType);
data->bufferSize = Device->UpdateSize * data->frameSize;
data->buffer = calloc(1, data->bufferSize);
data->buffer = calloc(Device->NumUpdates, data->bufferSize);
if(!data->buffer)
{
result = SL_RESULT_MEMORY_FAILURE;
@@ -366,10 +371,12 @@ static ALCboolean opensl_start_playback(ALCdevice *Device)
{
if(SL_RESULT_SUCCESS == result)
{
result = (*bufferQueue)->Enqueue(bufferQueue, data->buffer, data->bufferSize);
ALvoid *buf = (ALbyte*)data->buffer + i*data->bufferSize;
result = (*bufferQueue)->Enqueue(bufferQueue, buf, data->bufferSize);
PRINTERR(result, "bufferQueue->Enqueue");
}
}
data->curBuffer = 0;
if(SL_RESULT_SUCCESS == result)
{
result = SLObjectItf_GetInterface(data->bufferQueueObject, SL_IID_PLAY, &player);