Added triple buffer to avoid gaps between frames.

This commit is contained in:
Armin Novak 2013-09-27 15:07:32 +02:00
parent 84610f02e7
commit b07caafdbf
2 changed files with 24 additions and 4 deletions

View File

@ -288,6 +288,18 @@ void android_CloseRecDevice(OPENSL_STREAM *p)
free(p->next); free(p->next);
} }
if (p->middle)
{
free(p->middle->data);
free(p->middle);
}
if (p->prep)
{
free(p->prep->data);
free(p->prep);
}
openSLDestroyEngine(p); openSLDestroyEngine(p);
free(p); free(p);
@ -310,12 +322,18 @@ void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
e->data = calloc(p->buffersize, p->bits_per_sample / 8); e->data = calloc(p->buffersize, p->bits_per_sample / 8);
e->size = p->buffersize; e->size = p->buffersize;
if (p->next) p->next = p->middle;
Queue_Enqueue(p->queue, p->next); p->middle = p->prep;
p->prep = e;
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, (*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,
e->data, e->size); e->data, e->size);
p->next = e;
if (p->next)
{
Queue_Enqueue(p->queue, p->next);
p->next = NULL;
}
} }
// gets a buffer of size samples from the device // gets a buffer of size samples from the device
@ -329,7 +347,7 @@ int android_RecIn(OPENSL_STREAM *p,short *buffer,int size)
assert(size > 0); assert(size > 0);
/* Initial trigger for the queue. */ /* Initial trigger for the queue. */
if (!p->next) if (!p->prep)
{ {
(*p->recorderRecord)->SetRecordState(p->recorderRecord, SL_RECORDSTATE_RECORDING); (*p->recorderRecord)->SetRecordState(p->recorderRecord, SL_RECORDSTATE_RECORDING);
bqRecorderCallback(p->recorderBufferQueue, p); bqRecorderCallback(p->recorderBufferQueue, p);

View File

@ -67,6 +67,8 @@ typedef struct opensl_stream {
unsigned int bits_per_sample; unsigned int bits_per_sample;
wQueue *queue; wQueue *queue;
queue_element *prep;
queue_element *middle;
queue_element *next; queue_element *next;
} OPENSL_STREAM; } OPENSL_STREAM;