Scripting JACK device configs for Cadence and jackdbus

Unofficial support for the KXStudio Linux distribution and applications.
More info at http://kxstudio.linuxaudio.org/

Moderators: MattKingUSA, khz

Post Reply
danboid
Established Member
Posts: 1327
Joined: Sun Aug 26, 2012 11:28 am
Location: England
Has thanked: 1 time
Been thanked: 4 times

Scripting JACK device configs for Cadence and jackdbus

Post by danboid »

I recently released a small app called j2ds to aid quickly switching audio output devices when using jackdbus. j2ds is very limited in that it only lets you switch between ALSA JACK output devices and it doesn't give other key options like sample rate or period size etc. It was expected the user use Cadence, qjackctl or the terminal to adjust any other settings.

falkTX plans to add config profiles to Cadence but until then you may want to script your common JACK device configs by creating some new functions in your ~/.bashrc . Below are two Cadence/jackdbus config functions took from my ~/.bashrc

For you to take advantage of these functions, you will first need to know working values for JACK's period and nperiod sizes at a specfic samplerate such as 48000 Hz, as used here, and substitute those values in as well as replacing all the hw: definitions with the correct values for your audio devices. You can use the 'aplay -l' command to discover the names of your ALSA audio devices.

Code: Select all

4e() { jack_control stop && jack_control eps realtime true && jack_control ds alsa &&\
 jack_control dps device hw:PCH,0 && jack_control dps capture hw:PCH,0 &&\
 jack_control dps playback hw:UAC3553B,0 && jack_control dps nperiods 2 &&\
 jack_control dps period 1024 && jack_control dps rate 48000 && jack_control start &&\
 nohup /usr/bin/python3 /usr/share/cadence/src/cadence_aloop_daemon.py --channels=2 & }
This function is called 4e which is my shorthand for 48Khz external - I use this to switch to my USB hifi (which doesn't support > 48 Khz operation) for playback and using my internal audio (hw:PCH,0) for the capture device. After adding this to my .bashrc, '4e' is all I need to type in the terminal to stop JACK, enable RT, set the capture and playback devices, period size, sample rate, restart JACK and restart Cadence's ALSA audio bridge. 'nohup' (no hangup) ensures the Cadence ALSA bridge doesn't get killed if you close the terminal window you ran the function in.

Code: Select all

9i() { amixer -c 2 set Speaker mute && jack_control stop && jack_control eps realtime true &&\
 jack_control ds alsa && jack_control dps device hw:PCH,0 && jack_control dps capture hw:PCH,0 &&\
 jack_control dps playback hw:PCH,0 && jack_control dps nperiods 2 && jack_control dps period 512 &&\
 jack_control dps rate 96000 && jack_control start &&\
 nohup /usr/bin/python3 /usr/share/cadence/src/cadence_aloop_daemon.py --channels=2 & }
'9i' (96000 internal) performs a very similar duty to 4e but also mutes my laptop speaker using the amixer command first. '-c 2' tells amixer I want to mute the speaker of ALSA card #2. Again, you can get the ALSA info you need from the output of 'aplay -l'. I have a third bash function called 9o (outboard instead of exernal here due to the proximity of the keys) which switches my JACK playback and capture devices to use my Focusrite Scarlett 2i4 USB sound card @ 96Khz. The following 9o config gives me high quality, xrun-free recording with a 2.7ms latency according to Cadence.

Code: Select all

9o() { jack_control stop && jack_control eps realtime true &&\
 jack_control ds alsa && jack_control dps device hw:USB,0 && jack_control dps capture hw:USB,0 &&\
 jack_control dps playback hw:USB,0 && jack_control dps nperiods 2 && jack_control dps period 256 &&\
 jack_control dps rate 96000 && jack_control start &&\
 nohup /usr/bin/python3 /usr/share/cadence/src/cadence_aloop_daemon.py --channels=2 & }
Note that you need to either reload your terminal emulator or run ~/.bashrc every time you make changes before they take effect.
Last edited by danboid on Sat Jul 05, 2014 1:46 pm, edited 3 times in total.
danboid
Established Member
Posts: 1327
Joined: Sun Aug 26, 2012 11:28 am
Location: England
Has thanked: 1 time
Been thanked: 4 times

Re: Scripting JACK device configs for Cadence and jackdbus

Post by danboid »

F:

I would like to also start the ALSA MIDI bridge with these functions. I thought that I might be able to just run 'a2jmidid dbus' then a2jmidid would start and Cadence would acknowledge it as runing but that doesn't seem to be the case.
danboid
Established Member
Posts: 1327
Joined: Sun Aug 26, 2012 11:28 am
Location: England
Has thanked: 1 time
Been thanked: 4 times

Re: Scripting JACK device configs for Cadence and jackdbus

Post by danboid »

'a2j -e' does do the trick when run manually from a terminal but I've yet to figure out why I can't get it to work at the same time as the ALSA audio bridge when added to those bash functions. It'll be some oddity with nohup I expect.

Thats good to hear about the auto-start issue being solved under 14.04, which I hope to install soon.

Thanks falk!
danboid
Established Member
Posts: 1327
Joined: Sun Aug 26, 2012 11:28 am
Location: England
Has thanked: 1 time
Been thanked: 4 times

Re: Scripting JACK device configs for Cadence and jackdbus

Post by danboid »

I've just added the 9o config function for my Scarlett 2i4 as that will actually be useful to a number of people without modification, unlike the other two examples.
danboid
Established Member
Posts: 1327
Joined: Sun Aug 26, 2012 11:28 am
Location: England
Has thanked: 1 time
Been thanked: 4 times

Re: Scripting JACK device configs for Cadence and jackdbus

Post by danboid »

F:

You are still planning to add device profiles to Cadence right? This thread got me thinking about that and so I was wondering what you think about adding some amixer support to it? This would allow users to do stuff like "Mute my internal laptop speaker and set the headphone volume level to 75% when starting this profile" without having to work out the required amixer command or otherwise get involved in scripting.
tjkluska
Posts: 1
Joined: Thu May 18, 2017 10:57 pm

Re: Scripting JACK device configs for Cadence and jackdbus

Post by tjkluska »

Very useful, even in 2017.
:)
Thank you.
Post Reply