Working microphone input without sound gaps.

This commit is contained in:
Armin Novak 2013-09-30 10:08:22 +02:00
parent 95468dcf17
commit 6d14739ada
3 changed files with 35 additions and 44 deletions

View File

@ -74,6 +74,7 @@ static void* audin_opensles_thread_func(void* arg)
BYTE *b;
} buffer;
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) arg;
const size_t raw_size = opensles->frames_per_packet * opensles->bytes_per_channel;
DEBUG_DVC("opensles=%p", opensles);
@ -83,8 +84,8 @@ static void* audin_opensles_thread_func(void* arg)
assert(opensles->stopEvent);
assert(opensles->stream);
buffer.v = calloc(opensles->bytes_per_channel, opensles->frames_per_packet);
ZeroMemory(buffer.v, opensles->frames_per_packet);
buffer.v = malloc(raw_size);
ZeroMemory(buffer.v, raw_size);
freerdp_dsp_context_reset_adpcm(opensles->dsp_context);
while (!(WaitForSingleObject(opensles->stopEvent, 0) == WAIT_OBJECT_0))
@ -92,19 +93,18 @@ static void* audin_opensles_thread_func(void* arg)
size_t encoded_size;
void *encoded_data;
int rc = android_RecIn(opensles->stream, buffer.s,
opensles->frames_per_packet);
int rc = android_RecIn(opensles->stream, buffer.s, raw_size);
if (rc < 0)
{
DEBUG_WARN("android_RecIn %d", rc);
continue;
}
assert(rc == raw_size);
if (opensles->format == WAVE_FORMAT_ADPCM)
{
opensles->dsp_context->encode_ms_adpcm(opensles->dsp_context,
buffer.b, rc * opensles->bytes_per_channel,
opensles->channels, opensles->block_size);
buffer.b, rc, opensles->channels, opensles->block_size);
encoded_data = opensles->dsp_context->adpcm_buffer;
encoded_size = opensles->dsp_context->adpcm_size;
@ -112,7 +112,7 @@ static void* audin_opensles_thread_func(void* arg)
else if (opensles->format == WAVE_FORMAT_DVI_ADPCM)
{
opensles->dsp_context->encode_ima_adpcm(opensles->dsp_context,
buffer.b, rc * opensles->bytes_per_channel,
buffer.b, rc,
opensles->channels, opensles->block_size);
encoded_data = opensles->dsp_context->adpcm_buffer;
@ -121,11 +121,9 @@ static void* audin_opensles_thread_func(void* arg)
else
{
encoded_data = buffer.v;
encoded_size = rc * opensles->bytes_per_channel;
encoded_size = rc;
}
DEBUG_DVC("encoded %d [%d] to %d [%X]", rc,
opensles->bytes_per_channel, encoded_size, opensles->format);
rc = opensles->receive(encoded_data, encoded_size, opensles->user_data);
if (!rc)
break;
@ -252,8 +250,8 @@ static void audin_opensles_set_format(IAudinDevice* device,
break;
default:
DEBUG_WARN("Encoding '%s' [%08X] not supported",
rdpsnd_get_audio_tag_string(format->wFormatTag),
DEBUG_WARN("Encoding '%d' [%08X] not supported",
(format->wFormatTag),
format->wFormatTag);
return;
}

View File

@ -288,12 +288,6 @@ void android_CloseRecDevice(OPENSL_STREAM *p)
free(p->next);
}
if (p->middle)
{
free(p->middle->data);
free(p->middle);
}
if (p->prep)
{
free(p->prep->data);
@ -315,37 +309,21 @@ void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
DEBUG_DVC("p=%p", p);
assert(p);
assert(p->next);
assert(p->prep);
assert(p->queue);
printf("Signalled");
e = calloc(1, sizeof(queue_element));
e->data = calloc(p->buffersize, p->bits_per_sample / 8);
e->size = p->buffersize;
e->size = p->buffersize * p->bits_per_sample / 8;
/* Initial fill up. */
if (!p->middle)
{
p->prep = e;
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,
e->data, e->size);
e = calloc(1, sizeof(queue_element));
e->data = calloc(p->buffersize, p->bits_per_sample / 8);
e->size = p->buffersize;
}
p->next = p->middle;
p->middle = p->prep;
Queue_Enqueue(p->queue, p->next);
p->next = p->prep;
p->prep = e;
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,
e->data, e->size);
if (p->next)
{
Queue_Enqueue(p->queue, p->next);
p->next = NULL;
}
}
// gets a buffer of size samples from the device
@ -361,11 +339,26 @@ int android_RecIn(OPENSL_STREAM *p,short *buffer,int size)
/* Initial trigger for the queue. */
if (!p->prep)
{
p->prep = calloc(1, sizeof(queue_element));
p->prep->data = calloc(p->buffersize, p->bits_per_sample / 8);
p->prep->size = p->buffersize * p->bits_per_sample / 8;
p->next = calloc(1, sizeof(queue_element));
p->next->data = calloc(p->buffersize, p->bits_per_sample / 8);
p->next->size = p->buffersize * p->bits_per_sample / 8;
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,
p->next->data, p->next->size);
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,
p->prep->data, p->prep->size);
(*p->recorderRecord)->SetRecordState(p->recorderRecord, SL_RECORDSTATE_RECORDING);
bqRecorderCallback(p->recorderBufferQueue, p);
}
WaitForSingleObject(p->queue->event, INFINITE);
/* Wait for queue to be filled... */
if (!Queue_Count(p->queue))
WaitForSingleObject(p->queue->event, INFINITE);
e = Queue_Dequeue(p->queue);
if (!e)
{
@ -374,9 +367,10 @@ int android_RecIn(OPENSL_STREAM *p,short *buffer,int size)
}
rc = (e->size < size) ? e->size : size;
assert(p->buffersize == e->size);
assert(size == e->size);
assert(p->buffersize * p->bits_per_sample / 8 == size);
memcpy(buffer, e->data, rc * sizeof(short));
memcpy(buffer, e->data, rc);
free(e->data);
free(e);

View File

@ -68,7 +68,6 @@ typedef struct opensl_stream {
wQueue *queue;
queue_element *prep;
queue_element *middle;
queue_element *next;
} OPENSL_STREAM;