aboutsummaryrefslogtreecommitdiffhomepage
path: root/applause.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-11-03 06:52:31 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-11-03 06:52:31 +0100
commit4f800f22dcf18830a53bc8e736c51e4e7707b4a2 (patch)
tree7df7d97e594de85c83735fb3453240bbee8ec5b2 /applause.c
parentbb7cf91eec8c52aae0c73ae0fa7e73976de9be48 (diff)
downloadapplause2-4f800f22dcf18830a53bc8e736c51e4e7707b4a2.tar.gz
enforce minimum buffer size for lua<->realtime communication based on jack_get_buffer_size()
Diffstat (limited to 'applause.c')
-rw-r--r--applause.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/applause.c b/applause.c
index fb659bb..a16244b 100644
--- a/applause.c
+++ b/applause.c
@@ -21,6 +21,8 @@
#define LUA_MODULE "applause.lua"
+#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
+
static jack_port_t *output_port;
static jack_client_t *client = NULL;
@@ -202,13 +204,26 @@ init_audio(int buffer_size)
}
/*
+ * Calculate the buffer size in bytes given the `buffer_size`
+ * in milliseconds.
+ * Make sure it is at least the Jack server's buffer size,
+ * else jack_process() is very likely not able to provide
+ * enough bytes.
+ * FIXME: The Jack server's sample rate and buffer size can
+ * theoretically change at runtime but currently,
+ * the buffer size is not adapted
+ * which means it could be too small after the change.
+ */
+ buffer_bytes = sizeof(jack_default_audio_sample_t)*
+ MAX(jack_get_sample_rate(client)*buffer_size/1000,
+ jack_get_buffer_size(client));
+
+ /*
* Initialize ring buffer of samples.
* The semaphore is initialized with the same size
* since it represents the available bytes in the ring
* buffer.
*/
- buffer_bytes = sizeof(jack_default_audio_sample_t)*
- jack_get_sample_rate(client)*buffer_size/1000;
buffer = jack_ringbuffer_create(buffer_bytes);
if (!buffer) {
fprintf(stderr, "cannot create ringbuffer\n");