]> mj.ucw.cz Git - misc.git/commitdiff
Added experimental utility for controlling jackd in the Ursarium
authorMartin Mares <mj@ucw.cz>
Sat, 14 Apr 2012 18:55:21 +0000 (20:55 +0200)
committerMartin Mares <mj@ucw.cz>
Sat, 14 Apr 2012 18:55:21 +0000 (20:55 +0200)
ursaryd/Makefile [new file with mode: 0644]
ursaryd/jt.c [new file with mode: 0644]

diff --git a/ursaryd/Makefile b/ursaryd/Makefile
new file mode 100644 (file)
index 0000000..110823b
--- /dev/null
@@ -0,0 +1,10 @@
+JACK_CFLAGS:=$(shell pkg-config --cflags jack)
+JACK_LIBS:=$(shell pkg-config --libs jack)
+
+CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -std=gnu99 $(JACK_CFLAGS)
+LDLIBS=$(JACK_LIBS)
+
+all: jt
+
+clean:
+       rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core -or -name .depend -or -name .#*`
diff --git a/ursaryd/jt.c b/ursaryd/jt.c
new file mode 100644 (file)
index 0000000..3fa5558
--- /dev/null
@@ -0,0 +1,97 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <jack/jack.h>
+
+typedef jack_default_audio_sample_t sample_t;
+
+static jack_client_t *jc;
+static jack_port_t *inport[2], *outport[4];
+
+static int process_callback(jack_nframes_t nframes, void *arg __attribute__((unused)))
+{
+       for (int ch=0; ch<2; ch++) {
+               sample_t *in = jack_port_get_buffer(inport[ch], nframes);
+               sample_t *out = jack_port_get_buffer(outport[ch], nframes);
+               sample_t *out2 = jack_port_get_buffer(outport[2+ch], nframes);
+               for (jack_nframes_t i=0; i<nframes; i++) {
+                       out[i] = in[i];
+                       out2[i] = in[i];
+               }
+       }
+       return 0;
+}
+
+static void port_callback(jack_port_id_t id, int reg, void *arg __attribute__((unused)))
+{
+       jack_port_t *p = jack_port_by_id(jc, id);
+       if (!p) {
+               puts("port_callback: lookup failed");
+               return;
+       }
+       const char *name = jack_port_name(p);
+       printf("%s port %s\n", (reg ? "Registered" : "Unregistered"), name);
+
+       const char *ss = strstr(name, ":from_slave_");
+       if (reg && ss) {
+               char *to = (ss[12] == '1' ? "brum:in1" : "brum:in2");
+               printf("\t... connecting to %s\n", to);
+               if (jack_connect(jc, name, to))
+                       puts("jack_connect failed");
+       }
+}
+
+int main(void)
+{
+       jc = jack_client_open("brum", JackNoStartServer, NULL);
+       if (!jc) {
+               puts("jack_client_open failed");
+               return 1;
+       }
+
+       for (int i=0; i<2; i++) {
+               char name[16];
+               sprintf(name, "in%d", i+1);
+               inport[i] = jack_port_register(jc, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
+               if (!inport[i]) {
+                       puts("jack_port_register failed");
+                       return 1;
+               }
+       }
+
+       for (int i=0; i<4; i++) {
+               char name[16];
+               sprintf(name, "out%d", i+1);
+               outport[i] = jack_port_register(jc, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
+               if (!outport[i]) {
+                       puts("jack_port_register failed");
+                       return 1;
+               }
+       }
+
+       jack_set_process_callback(jc, process_callback, NULL);
+       jack_set_port_registration_callback(jc, port_callback, NULL);
+
+       if (jack_activate(jc)) {
+               puts("jack_activate failed");
+               return 1;
+       }
+
+       puts("Connecting ports...");
+       for (int i=1; i<=4; i++) {
+               char a[32], b[32];
+               sprintf(a, "brum:out%d", i);
+               sprintf(b, "system:playback_%d", i);
+               if (jack_connect(jc, a, b))
+                       printf("Failed to connect %s -> %s\n", a, b);
+       }
+
+       puts("Running...");
+       char xxx[16];
+       read(0, xxx, sizeof(xxx));
+
+       puts("exiting");
+       jack_client_close(jc);
+       return 0;
+}