diff --git a/tools/alsa_in.c b/tools/alsa_in.c index 5f26ec8..c6a1a79 100644 --- a/tools/alsa_in.c +++ b/tools/alsa_in.c @@ -464,6 +464,34 @@ again: return 0; } +/** + * the latency callback. + * sets up the latencies on the ports. + */ + +int +latency_cb (jack_latency_callback_mode_t mode, void *arg) +{ + jack_latency_range_t range; + JSList *node; + + range.min = range.max = target_delay; + + if (mode == JackCaptureLatency) { + for (node = capture_ports; node; node = jack_slist_next (node)) { + jack_port_t *port = node->data; + jack_port_set_latency_range (port, mode, &range); + } + } else { + for (node = playback_ports; node; node = jack_slist_next (node)) { + jack_port_t *port = node->data; + jack_port_set_latency_range (port, mode, &range); + } + } + + return 0; +} + /** * Allocate the necessary jack ports... @@ -660,6 +688,8 @@ int main (int argc, char *argv[]) { jack_on_shutdown (client, jack_shutdown, 0); + if (jack_set_latency_callback) + jack_set_latency_callback (client, latency_cb, 0); // get jack sample_rate diff --git a/tools/alsa_out.c b/tools/alsa_out.c index e7016db..4499894 100644 --- a/tools/alsa_out.c +++ b/tools/alsa_out.c @@ -462,6 +462,34 @@ again: return 0; } +/** + * the latency callback. + * sets up the latencies on the ports. + */ + +int +latency_cb (jack_latency_callback_mode_t mode, void *arg) +{ + jack_latency_range_t range; + JSList *node; + + range.min = range.max = target_delay; + + if (mode == JackCaptureLatency) { + for (node = capture_ports; node; node = jack_slist_next (node)) { + jack_port_t *port = node->data; + jack_port_set_latency_range (port, mode, &range); + } + } else { + for (node = playback_ports; node; node = jack_slist_next (node)) { + jack_port_t *port = node->data; + jack_port_set_latency_range (port, mode, &range); + } + } + + return 0; +} + /** * Allocate the necessary jack ports... @@ -658,6 +686,8 @@ int main (int argc, char *argv[]) { jack_on_shutdown (client, jack_shutdown, 0); + if (jack_set_latency_callback) + jack_set_latency_callback (client, latency_cb, 0); // get jack sample_rate