2011
Mar 
31

Understanding how Rivendell and JACK plug together

Filed under: JACK,Rivendell — Tags: , — frederickjh @ 22:48  

I think one of the confusing things to many new users is how JACK and Rivendell interconnect and how things are labeled. For example Rivendell starts numbering Cards and Ports at 0 while in JACK Ports start at 1.

I am basically going to be  demystifying the JACK.txt file that comes with the standard documentation from Rivendell.

When you setup a [JackSession] section in the Rivendell configuration file, /etc/rd.conf, Rivendell will if it finds the JACK daemon, jackd, running create a virtual JACK card in Rivendell.  The Rivendell daemon caed (Core Audio Engine Daemon) will look first to see if you have any Audio Science audio adapters in the system and will initialize them first. caed will number the first card 0 (Zero). If you have no Audio Science cards in your system  then the virtual JACK card will be card number 0. ALSA cards in Rivendell will come last. You need to have setup an /etc/asound.conf with entries for ALSA (see ALSA.txt for details).

If you look in JACK Control under connections you will see that Rivendell appends the Rivendell JACK client with the number of the virtual sound card that it will be available under in Rivendell. So for example the Rivendell JACK client for cardo will be rivendell_0.

When you first come in to the JACK Control Connections window you will see a list of clients. Clients are JACK aware audio applications that have created JACK ports that you can connect. Clicking the plus next to a client opens the list of ports that that client is making available.

If there is one Audio Science card, the Audio Science card would be numbered card 0. The virtual JACK card would then be numbered card 1 and appear in JACK Control under connections as the client named rivendell_1.

Rivendell will automatically make the JACK connections that are setup in /etc/rd.conf. These consist of a Source and Destination line in rd.conf. This is followed by a number that need to match. So, that Source1  will be connected to Destination1.  Sources are on the left-hand side in JACK Control in the column with the heading “Readable Clients / Output Ports”. Destinations are in the right-hand side column with the heading “Writable Clients / Input Ports”.

Rivendell’s output and input ports are stereo. JACK’s ports are mono. This means that if you setup and application to use Card0 and Port0 in the connections window in JACK Control you will have 2 ports one for the left and one for the right channel.

On an Ubuntu computer the ALSA sound card show up as the client system.

You might get confused by the terminology used for the port names, but if you remember the ports on the left are providing audio and the ports on the right are wanting to receive audio it makes things easier. Also note the icons to the left of the port names. Microphone icons are by the ports providing sound while the ports that we can send sound to have speaker icons next to them.

For  an example of the terminology the Rivendell client uses the terms for the ports playout and record.  The system client uses the terms capture and playback.

Now for an example to put it all together.  The JACK Virtual card in this example is Card0 and we are assigning RDAirplay to playout on port0. We want to monitor this on our computer speakers which are attached to our ALSA sound card that is represented by the playback_1 and playback_2 ports (Left and Right channels).

To have the port connected automatically when Rivendell starts we have the 4 lines in the [JackSession] section of /etc/rd.conf

Source1=rivendell_0:playout_0L
Destination1=system:playback_1

Source2=rivendell_0:playout_0R
Destination2=rivendell_0:playback_2

OK, so lets break it down. The Source and Destination with the same number will be connected. So, each pair needs a unique number in the configuration file. Easy enough, I hope.

The part on each line after the equal sign (=) is the client name and port name with a colon(:) in between.

So in the example lines from rd.conf the first two lines connect the left channel of RDAirplay with the left channel of the sound card and eventually with the left speaker. The next two lines do the same for the right channel.

I hope that helps someone to understand a bit better interfacing JACK and Rivendell.

2011
Mar 
28

So you want to have JACK with your RRAbuntu?

Filed under: JACK,Rivendell,Rivendell Installation — frederickjh @ 23:26  

After folks get past the easy install of Rivendell they many times hear about JACK and all the neat things you can do with it. However, JACK is a program that has a lot of twists and turn to figure out mostly because the packagers have decided against a one-size-fits-all setup. The Ubuntu/Debian packages for Rivendell seem a bit that way too considering how much “tweeking” we do after the packages are installed to get it to work correctly on RRAbuntu.

Now I would not say RRAbuntu is a one-size-fits-all installation. It is more like a it-is-a-good-place-to-start-and-it-works-this-way-so-why-fix-it installation (Just try and say that 5 times fast! ;) ).

The biggest issues with getting JACK setup are:

1) Figuring out JACK’s idiosyncrasies

2) Figuring out the best way to interface JACK with current sound systems

3) Figuring out the best way to interconnect JACK aware programs with JACK

Now before we begin, why might you want to setup JACK with RRAbuntu? With the default RRAbuntu installation we use ALSA and disable Pulse Audio. We do the later because we do not want Pulse Audio to grab the sound card and then Rivendell cannot use it.

ALSA only allows one audio application at a time to use a sound card. You could install another sound card and use one for Rivendell and the other sound card for other applications. However, I am not going to cover that in this post.

With JACK we still use ALSA but JACK handles all the connection to ALSA. The best way to think of JACK is like a big patch panel for audio. We can connect audio applications and sound devices together automatically or manually. This allows us to have Rivendell on a computer and also run Audacity to edit some audio and still be able to hear it. JACK stands for the Jack Audio Connection Kit . It is a recursive acronym in that it refers to itself. Considering that ack is a sound of disgust in some places in the world it is all the better to name it JACK and not ACK.

But some of you may say, “Hey what about Pulse Audio? It is the default sound system on Ubuntu and I want to hear the system sounds and such.” Well since the last version of RRAbuntu was released (1.13) I have learned how to interface JACK and PulseAudio so that you can have sound from non-JACK aware applications as well, however this has proved not so stable in testing when stopping and restarting jackd. I am still working on this but the fact that a reboot was needed to allow jackd to start again is not a good thing in my book. I need to research that setup more.

So, on to the setup. First the assumptions. You did an install from the RRAbuntu 1.13 CD and ran the First Run script. This may work with other Rivendell versions (1.7.2 is what we are testing with) or other releases or Ubuntu distros (Ubuntu Lucid 10.04 LTS in what we are using). And once again the point is not to assume you know anything nor to teach you, so if you learn something that is great bit it may take a bit of reading up on your part.

1)  Stop the Rivendell daemons

sudo /etc/init.d/rivendell stop 

2) Setup a startup script which waits to start Rivendell until jackd has started. Download the startup script from my blog post here (right-click> “Save Linked Content As…”) and save it as /etc/init.d/rivendell. Make it executable and change the variable WAITFORJACK=0 to WAITFORJACK=1.

You can do this with the commands:

sudo wget -t 0 -O /tmp/rivendell.init http://ubuntuone.com/p/HNF/
sed s/WAITFORJACK=0\ \ #1=yes\ 0=no/WAITFORJACK=1\ \ #1=yes\ 0=no/ /tmp/rivendell.init | sudo tee /etc/init.d/rivendell >/dev/null
rm /tmp/rivendell.init


3) Setup Jack Control as a Startup Application with the following command:

echo "
[Desktop Entry]
Type=Application
Exec=qjackctl
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=Quick Jack Control
Name=Jack Control
Comment[en_US]=Starts Jack Control and the jack daemon
Comment=Starts Jack Control and the jack daemon
 " > ~/.config/autostart/qjackctl.desktop 

4) Add a  Jack section to /etc/rd.conf with the command:

echo "
; JACK Session Management
;
; See /usr/share/doc/rivendell/JACK.txt for details
;
[JackSession]
Source1=rivendell_0:playout_0L
Destination1=system:playback_1

Source2=rivendell_0:playout_0R
Destination2=system:playback_2

Source3=rivendell_0:playout_1L
Destination3=system:playback_1

Source4=rivendell_0:playout_1R
Destination4=system:playback_2

Source5=rivendell_0:playout_2L
Destination5=system:playback_1

Source6=rivendell_0:playout_2R
Destination6=system:playback_2

Source7=rivendell_0:playout_3L
Destination7=system:playback_1

Source8=rivendell_0:playout_3R
Destination8=system:playback_2

Source9=rivendell_0:playout_4L
Destination9=system:playback_1

Source10=rivendell_0:playout_4R
Destination10=system:playback_2

Source11=rivendell_0:playout_5L
Destination11=system:playback_1

Source12=rivendell_0:playout_5R
Destination12=system:playback_2

Source13=rivendell_0:playout_6L
Destination13=system:playback_1

Source14=rivendell_0:playout_6R
Destination14=system:playback_2

Source15=rivendell_0:playout_7L
Destination15=system:playback_1

Source16=rivendell_0:playout_7R
Destination16=system:playback_2

Source17=system:capture_1
Destination17=rivendell_0:record_0L

Source18=system:capture_2
Destination18=rivendell_0:record_0R

Source19=system:capture_1
Destination19=rivendell_0:record_1L

Source20=system:capture_2
Destination20=rivendell_0:record_1R

Source21=system:capture_1
Destination21=rivendell_0:record_2L

Source22=system:capture_2
Destination22=rivendell_0:record_2R

Source23=system:capture_1
Destination23=rivendell_0:record_3L

Source24=system:capture_2
Destination24=rivendell_0:record_3R

Source25=system:capture_1
Destination25=rivendell_0:record_4L

Source26=system:capture_2
Destination26=rivendell_0:record_4R

Source27=system:capture_1
Destination27=rivendell_0:record_5L

Source28=system:capture_2
Destination28=rivendell_0:record_5R

Source29=system:capture_1
Destination29=rivendell_0:record_6L

Source30=system:capture_2
Destination30=rivendell_0:record_6R

Source31=system:capture_1
Destination31=rivendell_0:record_7L

Source32=system:capture_2
Destination32=rivendell_0:record_7R
" | sudo tee -a /etc/rd.conf > /dev/null

5) Setup Jack Control to start jackd and other needed settings with the commands:

mkdir ~/.config/rncbc.org/


echo "[Splitter]
AudioConnectView\sizes=248, 83, 248
MidiConnectView\sizes=34, 20, 34
AlsaConnectView\sizes=34, 20, 34
PatchbayView\sizes=34, 20, 34

[Geometry]
qjackctlMessagesForm\x=0
qjackctlMessagesForm\y=0
qjackctlMessagesForm\width=328
qjackctlMessagesForm\height=200
qjackctlMessagesForm\visible=false
qjackctlStatusForm\x=0
qjackctlStatusForm\y=0
qjackctlStatusForm\width=378
qjackctlStatusForm\height=231
qjackctlStatusForm\visible=false
qjackctlConnectionsForm\x=0
qjackctlConnectionsForm\y=0
qjackctlConnectionsForm\width=1206
qjackctlConnectionsForm\height=795
qjackctlConnectionsForm\visible=false
qjackctlPatchbayForm\x=0
qjackctlPatchbayForm\y=0
qjackctlPatchbayForm\width=726
qjackctlPatchbayForm\height=333
qjackctlPatchbayForm\visible=false
qjackctlMainForm\x=163
qjackctlMainForm\y=39
qjackctlMainForm\width=474
qjackctlMainForm\height=100
qjackctlMainForm\visible=false

[Program]
Version=0.3.4

[Presets]
DefPreset=(default)

[Options]
StartJack=true
StartupScript=false
StartupScriptShell=artsshell -q terminate
PostStartupScript=false
PostStartupScriptShell=
ShutdownScript=false
ShutdownScriptShell=
PostShutdownScript=false
PostShutdownScriptShell=killall jackd
StdoutCapture=true
XrunRegex=xrun of at least ([0-9|]+) msecs
XrunIgnoreFirst=false
ActivePatchbay=false
ActivePatchbayPath=
MessagesLog=false
MessagesLogPath=qjackctl.log
BezierLines=true
TimeDisplay=0
TimeFormat=0
MessagesFont="Sans,10,-1,5,50,0,0,0,0,0"
MessagesLimit=true
MessagesLimitLines=1000
DisplayFont1="Sans,12,-1,5,75,0,0,0,0,0"
DisplayFont2="Sans,10,-1,5,50,0,0,0,0,0"
DisplayEffect=true
DisplayBlink=true
JackClientPortAlias=0
ConnectionsIconSize=0
ConnectionsFont="Sans,10,-1,5,50,0,0,0,0,0"
QueryClose=true
KeepOnTop=false
SystemTray=true
StartMinimized=true
DelayedSetup=false
ServerConfig=true
ServerConfigName=.jackdrc
ServerConfigTemp=false
QueryShutdown=true
AlsaSeqEnabled=true
AliasesEnabled=false
AliasesEditing=false
LeftButtons=true
RightButtons=true
TransportButtons=true
TextLabels=true
BaseFontSize=0

[Defaults]
PatchbayPath=

[Settings]
Server=/usr/bin/jackd
Realtime=true
SoftMode=false
Monitor=false
Shorts=false
NoMemLock=false
UnlockMem=false
HWMon=false
HWMeter=false
IgnoreHW=false
Priority=0
Frames=1024
SampleRate=44100
Periods=2
WordLength=16
Wait=21333
Chan=0
Driver=alsa
Interface=
Audio=0
Dither=0
Timeout=500
InDevice=
OutDevice=
InChannels=0
OutChannels=0
InLatency=0
OutLatency=0
StartDelay=2
Verbose=false
PortMax=256
MidiDriver=none

[History]
ServerComboBox\Item1=/usr/bin/jackd
ServerComboBox\Item2=jackd
ServerComboBox\Item3=jackdmp
ServerComboBox\Item4=jackstart
ServerComboBox\Item5=jackd-realtime
InterfaceComboBox\Item1=(default)
InterfaceComboBox\Item2=hw:0
InterfaceComboBox\Item3=plughw:0
InterfaceComboBox\Item4=/dev/audio
InterfaceComboBox\Item5=/dev/dsp
InDeviceComboBox\Item1=(default)
InDeviceComboBox\Item2=hw:0
InDeviceComboBox\Item3=plughw:0
InDeviceComboBox\Item4=/dev/audio
InDeviceComboBox\Item5=/dev/dsp
OutDeviceComboBox\Item1=(default)
OutDeviceComboBox\Item2=hw:0
OutDeviceComboBox\Item3=plughw:0
OutDeviceComboBox\Item4=/dev/audio
OutDeviceComboBox\Item5=/dev/dsp
StartupScriptShellComboBox\Item1=artsshell -q terminate
PostShutdownScriptShellComboBox\Item1=killall jackd
XrunRegexComboBox\Item1=xrun of at least ([0-9|]+) msecs
MessagesLogPathComboBox\Item1=qjackctl.log
ServerConfigNameComboBox\Item1=.jackdrc
" > ~/.config/rncbc.org/QjackCtl.conf

6) At this point the easiest thing to do is reboot the computer. This will start the Rivendell daemons, JACK Control and jackd and set the proper group permissions.

7) Set Audio Output and Inputs up in RDAdmin to use the outputs and inputs you want for each Rivendell application. First go to RDAdmin>Manage Hosts> select the host >Edit>Audio Resources Scroll down and look for the title “AUDIO ADAPTERS“. Under it it should say:

Card0: JACK Audio Connection Kit
  Driver: JACK Audio Connection Kit
  Inputs: 8
  Outputs: 8 

If it does then you can click Close.  In the Host: menu that you will be looking at you can go in to RDLibrary, RDCatch, RDAirplay, RDPanel and RDLogEdit and assign what inputs and outputs you want to use for what functions in those programs. Jack has 8 inputs and outputs numbered 0-7 The card number will be 0 as that is what card we have JACK setup as. By default they will be set to Card 0, Port 0.

8 ) Check connections in Jack Control. Click on the JACK icon in the task bar, then click on the Connect button.   Check that you have connections between the rivendell_0:playback ports and the system:playback ports so you can hear sound in Rivendell. You should see a line connecting them.

JACK Control Taskbar Icon - A Diagonal TRS (Tip, Ring, Sleeve connector) or a headphone plug if your not sure what that is ;) and a white circle with, hopefully a yellow play symbol

JACK Control Taskbar Icon

The yellow play symbol in the JACK Control taskbar icon means jackd was started by a program other than JACK Control. A green play symbol means jackd was started by JACK Control. In the screen shot above I had started it from the command line.

9) Test: Play a sound in Rivendell and see if it works!

Again if you don’t want to do all that copy and pasting I am providing a script that will do all this for you. One word of warning do not have any other package managers running when you try to run the script. Especially keep an eye out for the update manager. It has a way of automatically starting and then minimizing itself.

You can download the rrabuntuandjack.sh script here.

Happy patching!