aboutsummaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-12-24 22:58:25 +0100
committerMax Kellermann <max@duempel.org>2014-12-24 23:14:15 +0100
commitc4c2da06b7bc2351c16cc9471c54a125179d858f (patch)
tree426b9fb08faff81285a620138cbd11e9dc457025 /src/output
parent8928cd53bf3a2f312b0d80000e983e82600e5fa7 (diff)
downloadmpd-c4c2da06b7bc2351c16cc9471c54a125179d858f.tar.gz
mpd-c4c2da06b7bc2351c16cc9471c54a125179d858f.tar.xz
mpd-c4c2da06b7bc2351c16cc9471c54a125179d858f.zip
output/jack: use jack_ringbuffer_get_write_vector()
Reduce number of libjack calls.
Diffstat (limited to 'src/output')
-rw-r--r--src/output/plugins/JackOutputPlugin.cxx30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/output/plugins/JackOutputPlugin.cxx b/src/output/plugins/JackOutputPlugin.cxx
index 653a73328..854d2536f 100644
--- a/src/output/plugins/JackOutputPlugin.cxx
+++ b/src/output/plugins/JackOutputPlugin.cxx
@@ -647,13 +647,20 @@ JackOutput::WriteSamples(const float *src, size_t n_frames)
const unsigned n_channels = audio_format.channels;
- size_t space = jack_ringbuffer_write_space(ringbuffer[0]);
- for (unsigned i = 1; i < n_channels; ++i) {
- size_t space1 =
- jack_ringbuffer_write_space(ringbuffer[i]);
- if (space1 < space)
+ float *dest[MAX_CHANNELS];
+ size_t space = -1;
+ for (unsigned i = 0; i < n_channels; ++i) {
+ jack_ringbuffer_data_t d[2];
+ 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 */
- space = space1;
+ space = e->len;
+
+ dest[i] = (float *)e.buf;
}
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);
while (n_frames-- > 0)
- for (unsigned i = 0; i < n_channels; ++i, ++src)
- jack_ringbuffer_write(ringbuffer[i],
- (const char *)src,
- sizeof(*src));
+ for (unsigned i = 0; i < n_channels; ++i)
+ *dest[i]++ = *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;
}