jack: partial writes to ring buffer
Don't wait until there is room for the full data chunk passed to jack_playAudio(). Try to incrementally send as much as possible into the ring buffer.
This commit is contained in:
parent
91ad576aad
commit
4ecdaabbb0
@ -386,12 +386,10 @@ static int jack_playAudio(void *data,
|
|||||||
const char *buff, size_t size)
|
const char *buff, size_t size)
|
||||||
{
|
{
|
||||||
JackData *jd = data;
|
JackData *jd = data;
|
||||||
size_t space;
|
size_t space, space1;
|
||||||
size_t i;
|
|
||||||
const short *buffer = (const short *) buff;
|
const short *buffer = (const short *) buff;
|
||||||
static const size_t frame_size = sizeof(*buffer) * 2;
|
static const size_t frame_size = sizeof(*buffer) * 2;
|
||||||
jack_default_audio_sample_t sample;
|
jack_default_audio_sample_t sample;
|
||||||
size_t samples = size / frame_size;
|
|
||||||
|
|
||||||
/*DEBUG("jack_playAudio: (pid=%d)!\n", getpid());*/
|
/*DEBUG("jack_playAudio: (pid=%d)!\n", getpid());*/
|
||||||
|
|
||||||
@ -402,14 +400,21 @@ static int jack_playAudio(void *data,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (samples && !jd->shutdown) {
|
size /= frame_size;
|
||||||
|
while (size > 0 && !jd->shutdown) {
|
||||||
space = jack_ringbuffer_write_space(jd->ringbuffer[0]);
|
space = jack_ringbuffer_write_space(jd->ringbuffer[0]);
|
||||||
if (space >= samples * sample_size) {
|
space1 = jack_ringbuffer_write_space(jd->ringbuffer[1]);
|
||||||
/*space = MIN(space, samples*sample_size);*/
|
if (space > space1)
|
||||||
/*space = samples*sample_size;*/
|
/* send data symmetrically */
|
||||||
|
space = space1;
|
||||||
|
|
||||||
/*for(i=0; i<space/sample_size; i++) {*/
|
space /= sample_size;
|
||||||
for (i = 0; i < samples; i++) {
|
if (space > 0) {
|
||||||
|
if (space > size)
|
||||||
|
space = size;
|
||||||
|
|
||||||
|
size -= space;
|
||||||
|
while (space-- > 0) {
|
||||||
sample = (jack_default_audio_sample_t) *(buffer++)/32768.0;
|
sample = (jack_default_audio_sample_t) *(buffer++)/32768.0;
|
||||||
|
|
||||||
jack_ringbuffer_write(jd->ringbuffer[0], (void*)&sample,
|
jack_ringbuffer_write(jd->ringbuffer[0], (void*)&sample,
|
||||||
@ -419,12 +424,7 @@ static int jack_playAudio(void *data,
|
|||||||
|
|
||||||
jack_ringbuffer_write(jd->ringbuffer[1], (void*)&sample,
|
jack_ringbuffer_write(jd->ringbuffer[1], (void*)&sample,
|
||||||
sample_size);
|
sample_size);
|
||||||
|
|
||||||
/*samples--;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
samples = 0;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
pthread_mutex_lock(&jd->play_audio_lock);
|
pthread_mutex_lock(&jd->play_audio_lock);
|
||||||
pthread_cond_wait(&jd->play_audio,
|
pthread_cond_wait(&jd->play_audio,
|
||||||
|
Loading…
Reference in New Issue
Block a user