BpmDj & Jack
Thanks
to Bernard Fortz BpmDj has JACK support since February 2009. This opens
up a lot of possibilities, like routing bpmdj to jack-rack to add
ladspa effects, using jack mixers with midi control surface, mixing
with other jack audio apps...
Below we discuss the following steps, necessary to get jackd support to
work
1. First the jack driver should be
compiled in
2. The jackd daemon should be able to
access multiple cards.
3. The jackd daemon should be running
4. The jack driver should be
activated in the player and the
appropriate device selected
Compiling
If
the jack tab is
greyed out then it was not compiled in.
In your defines file, you need to add
-ljack to LDFLAGS and -D
COMPILE_JACK to CFLAGS. Then compile as usual.
Jackd & Multiple Sound Cards
It seems rather difficult (if not
impossible) to instantiate multiple jackd daemons, eg: one for each
soundcard. The best solution found by various people seems to be to use
an alsa multi device and route
everything through that one. In my case the alsa .asoundrc file
contains:
pcm.multi {
type multi;
slaves.a.pcm "hw:1,0";
slaves.a.channels 2;
slaves.b.pcm "hw:2,0";
slaves.b.channels 2;
bindings.0.slave a;
bindings.0.channel 0;
bindings.1.slave a;
bindings.1.channel 1;
bindings.2.slave b;
bindings.2.channel 0;
bindings.3.slave b;
bindings.3.channel 1;
}
ctl.multi {
type hw;
card 1;
}
pcm.ttable {
type route;
slave.pcm "multi";
ttable.0.0 1;
ttable.1.1 1;
ttable.2.2 1;
ttable.3.3 1;
}
ctl.ttable {
type hw;
card 1;
}
Beware
of the slaves.a.pcm and slaves.b.pcm. They might be hw:0 and hw:1 in
your specific setup.
Start Jackd
The next step is to start the jack
daemon (jackd) with sufficient playing latency and a
proper playing rate of 44100.
This can be done for example with:
jackd -d
alsa -d multi -r 44100 -n10
which states that we use the alsa
driver, the multi card (which opens up the appropriate output channels)
at a playing rate of 44100 Hz and 10 small buffers, leading to a
playing latency of around 150ms, which avoid ticks, clicks etcetera.
Now
start qjackctl and push the play button.
Routing bpmplay's output to the system output

To create the
outputroutes we must first start two bpmplayers, so that we can
announce which routes we will need.
In the Setup tab for
each player, go to Jack, check "use Jack device" and in the device
field choose a different output port name for each player. We choose
bpmplay0 and bpmplay1. These will
appear as output ports in jack.
Theses are NOT connected to physical
outputs by default, you should use for example qjackctl to setup
connections. Use qjackctl patchbay to make these persistent. To
actually set up the proper routes, creating a patchbay which will
always automatically link the bpmplay0 to system outputs 0 and 1 and
which will link bpmplay1 to system outputs 3 and 4. The picture below
shows a potential setup
Some last remarks: although the
jack support currently is in an experimental phase, one should realize
that jack has a substantial performance penalty for two reaons:
a- the various routes through which the sound goes hurts performance:
bpmplay -> jackd -> jackcontrol -> alsa multi ->alsa
hardware. If one simply wants to get sound out of bpmplay it might be
useful as well to kill all artsd drivers, jackd daemons and directly
output the sound from bpmplay into a single soundcard. This will be
more optimal. And b- jack works with floating points (32 bits long at least),
while most sound is in essense 16 bit integers. This means that each sample
is doubled in size through a non straightforward convertion. However, this again makes
it downstream possible to easily implement nice filters. So it really becomes
a bit of a tradeoff.
Having said this: the jack daemon offers the possibility
to go through different routes as well, so the availability of this
driver gives you the choice of doing so,
[Optional: Low Latency Support /
An Asynchronouse JACK Driver]
We have also been experimenting a bit
with a low latency jack driver, which in essence turned out difficult
to implement due to a number of software design restrictions in BpmDj.
We are currently addressing these. In the meantime however the bits and
pieces necessary to imploemnent a low latency driver (or asynchronous
driver) can be enabled with the ASYNC_JACK compile time option.
- It's very important to run jackd in realtime mode, and the kernel
should be compiled with CONFIG_PREEMPT=y (preemption allowed). There is
also a patched realtime kernel with supposed better performance, but I
tried it some time ago and it was very unstable under heavy load, so I
just work with a preemptible kernel.
- So the user running jackd and bpmplay should have realtime
permissions (I'm using pam - http://www.gentoo.org/proj/en/desktop/sound/realtime.xml)
- - the corollary is that bpmplay should also run realtime, which I
forgot to implement (but this is just 4 lines of codes... and the gain
is impressive, even with other heavy processes running on my computer,
bpmplay does'nt skip anymore). Note that this idea of realtime
scheduling might also be beneficial for the other drivers.