output/jack: use jack_ringbuffer_get_write_vector()

Reduce number of libjack calls.
This commit is contained in:
Max Kellermann 2014-12-24 22:58:25 +01:00
parent 8928cd53bf
commit c4c2da06b7
2 changed files with 21 additions and 10 deletions

1
NEWS
View File

@ -12,6 +12,7 @@ ver 0.20 (not yet released)
- ffmpeg: support ReplayGain and MixRamp - ffmpeg: support ReplayGain and MixRamp
- ffmpeg: support stream tags - ffmpeg: support stream tags
* output * output
- jack: reduce CPU usage
- pulse: set channel map to WAVE-EX - pulse: set channel map to WAVE-EX
* mixer * mixer
- null: new plugin - null: new plugin

View File

@ -647,13 +647,20 @@ JackOutput::WriteSamples(const float *src, size_t n_frames)
const unsigned n_channels = audio_format.channels; const unsigned n_channels = audio_format.channels;
size_t space = jack_ringbuffer_write_space(ringbuffer[0]); float *dest[MAX_CHANNELS];
for (unsigned i = 1; i < n_channels; ++i) { size_t space = -1;
size_t space1 = for (unsigned i = 0; i < n_channels; ++i) {
jack_ringbuffer_write_space(ringbuffer[i]); jack_ringbuffer_data_t d[2];
if (space1 < space) jack_ringbuffer_get_write_vector(ringbuffer[i], d);
/* choose the first non-empty writable area */
const jack_ringbuffer_data_t &e = d[d[0].len == 0];
if (e.len < space)
/* send data symmetrically */ /* send data symmetrically */
space = space1; space = e->len;
dest[i] = (float *)e.buf;
} }
space /= jack_sample_size; space /= jack_sample_size;
@ -663,10 +670,13 @@ JackOutput::WriteSamples(const float *src, size_t n_frames)
const size_t result = n_frames = std::min(space, n_frames); const size_t result = n_frames = std::min(space, n_frames);
while (n_frames-- > 0) while (n_frames-- > 0)
for (unsigned i = 0; i < n_channels; ++i, ++src) for (unsigned i = 0; i < n_channels; ++i)
jack_ringbuffer_write(ringbuffer[i], *dest[i]++ = *src++;
(const char *)src,
sizeof(*src)); const size_t per_channel_advance = result * jack_sample_size;
for (unsigned i = 0; i < n_channels; ++i)
jack_ringbuffer_write_advance(ringbuffer[i],
per_channel_advance);
return result; return result;
} }