Fun With Jack and Pulseaudio

So, recently my Focusrite Saffire Pro 10 came in the mail.  It’s a decent firewire interface, with 8 mic preamps.  And, it’s supported by FFADO in Linux.  This, along with Ardour and Jack will make a nice little studio whether for just me by myself or with a band.  Not to mention that with a laptop it’s great for recording shows.  Getting it to work in Linux was a little interesting at first, and may be the subject of a future post.  Long story short, I used the old firewire stack, made sure I could write to the /dev/raw1394 device, and then basically turned the interface on and off and I could start using it.  Well, it works well now…

Anyway, now a new adventure was beginning as I started messing with Jack.  (There’s a lot of dirt on Linux audio floating around, so don’t be afraid to Google and/or comment.)  Now, I usually have at least two sound cards in my main computer: the normal, somewhat-crappy onboard card, and something a little better for recording with.  Previous to the Saffire this second card was an M Audio Delta 44 (also a nice interface, with good Linux support).  The Saffire doesn’t connect  through ALSA (unlike the Delta 44; it uses FFADO), but nonetheless it is my designated “recording” interface, for when I want to make something that kind of sounds nice.  The nifty thing about this is that it allows two systems, the crappy onboard card (for normal desktop stuff like listening to music or watching crap on YouTube), and the Saffire+Jack+Ardour+whatever tangle to be used for recording.  In fact, I can use these two at the same time without problems.  However, when you have multiple things on your computer that can input and output sound, after a while it becomes tempting to route between things.

For desktop stuff I, like most Linux users, use the Pulseaudio daemon.  (Lots of people have complained about this, especially when it was first being introduced.  However, it is very nice for desktop audio.)  This works with the onboard card fine.  But, what if I want to use the Saffire for my desktop audio?  Or, what if I want to do something like play the output of Ardour into Skype (which uses Pulseaudio)?  Or, even just play something from Jack out my main computer speakers (crappy onboard)?  In my case, this started when I wanted to play with NetJack (an awesome feature of Jack, I might add), and stream music from my desktop to another Jack daemon on my laptop – which only has one sound card.  Which is also used by Pulseaudio.

Just so we’re clear, here’ s a picture of what I spent a good portion of the other night trying to make work:

Basically, I wanted to set up the Ethernet transport for Jack, but to do this I also wanted to be able to send audio from Jack to Pulse on the laptop.  I could stop Pulseaudio and let Jack take over, but I’d rather not.  So, I will say this right now, for anyone Googling: What I want to do is route Jack through Pulseaudio.  NOT route Pulseaudio through Jack.  IE, Jack is a secondary function on the laptop.  There are tons of guides for having pulse not use a physical sound device but play through Jack; this was not the intent – though you can achieve much of the same functionality.  In fact, the setup is almost the same.

Basically, the key lies in setting Jack up as a source and/or sink for Pulseaudio.  The best way to do this, it seems, is to use the aptly-named module-jack-source and module-jack-sink modules in Pulseaudio.  I was able to load them like this ($ being the prompt):

$ pactl load-module module-jack-source

$ pactl load-module module-jack-sink

Actually, for my setup I only did the first line.  I just wanted to have Jack appear as a source to Pulseaudio, as I just wanted to play music.  Now, to just pass through Pulseaudio, you’ll want another module, which will let you connect a source and a sink…  In this case, we are going to connect the Jack source to our normal ALSA sink, the laptop’s sound card:

$ pactl load-module module-loopback

With this loaded, in Ubuntu I opened pavucontrol (Applications -> Sound & Video -> Pulseaudio Volume Control).  Under the Recording tab, I set Show: to All Streams, and then the loopback device presented itself.  with an option to pick a source to loopback from.  Just pick the Jack source.  Then, under Playback, again you would pick All Streams, and now you can control the volume of the loopback.  And that’s that.

Using this, you can route audio from Jack applications into Pulseaudio, and vice-versa.  With Netjack, you can even go across hosts.  (On a side note, if you just want to say play back from Rhythmbox on a different computer, Pulseaudio does have networking built in, so you don’t need Jack.  But if you’re using Jack, this is nice.)  You can even go between sound cards, or between hosts as we saw here.  There is more latency with what I described, of course (mostly from the networking, I think, but combining two audio servers probably contributes too), but it’s a handy setup to be able to have.