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.

8 thoughts on “Fun With Jack and Pulseaudio”

  1. Well done!
    I used your routing suggestions to get my Ubuntu Ardour/Jack-based DAW monitored through PulseAudio-controlled line out, so I can hear my bass through headphones while playing.
    thank you 😉

    1. Awesome, glad it helped! Both audio systems are great and have their places, but I do wish that some more attention would be paid toward integrating them.

      Also nice to hear from a fellow Linux-using bassist!

  2. Ben,

    I followed your instructions using pulseaudio’s module-jack-source and module-jack-sink to get skype to work with my Phonic helix board (a firewire mixer). This indeed does work, but I had to increase jack’s latency to more than 20 msecs. Also I was confused by figuring out a proper startup sequence (pulseaudio just starts “by itself”). All doable, but I felt uncomfortable.

    Eventually I uninstalled pulseaudio entirely and let skype use my soundcard instead. Wherever possible I configured applications to use jack (muse, amarok, clementine, vlc) and let the others (firefox, skype) use the soundcard. I set up my .asoundrc with the dmix/dsnoop plugin, so many applications can use the soundcard without any problem.

    The soundcard is connected to my Phonic via the 2-track (rec/return) connectors and the phonic allows routing either firewire (aka muse, amarok …) or 2-track-return (aka firefox, skype) or both to the control room output.

    This runs flawlessly with 10ms latency and all the “important” apps use jack.

    BTW the Phonic runs fine with ffado, even though it is just “reported to work”.

    1. When I wrote this I think I was still trying to troubleshoot the Saffire a bit, so I don’t think I tried all of what I described (PulseAudio < -> Jack) under the harshest conditions, but if I recall I was able to get Jack running with pretty low latency at the time. (The really killer, I think was when I was using Ethernet.) I will have to revisit this; I haven’t tried to do a Skype session with the two sound servers in a while.

      On the other hand, while PulseAudio offers some nice conveniences I think that setting up Alsa to do the mixing was probably what the distros should have started doing before jumping on the PA bandwagon. For most people, it would be fine, and much simpler.

      I was checking out the Phonic a little, I’ll keep it in mind if I’m ever looking for another FireWire interface. Thanks for the tip that it works!

  3. Hi,
    Nice article! I was thinking, how you would handle the following situation:
    Assume you don’t have a Saffire card (with multiple inputs), but you’ve got 2 (exactly the same) old pci cards which work well with pulseaudio. You want to record from 2 input sources simultaneously. Plug in each input source in each pci card. Now you want to use Ardour (with jack) to record from the 2 pci cards.
    How would you do that?
    That’s a question that has bothered me for a long time, so I decided to make a pulse to jack audio pipe. It’s called ‘p2jaudio’, you can find it at http://code.google.com/p/p2jaudio/
    I’m curious if it’s superfluous for that kind of situation.

    1. I think it’s possible with ALSA to bond two cards together, so that they appear as one, but I’ve never tried this. I think there actually is another plugin for Jack that will let you include another ALSA device too. Your program looks neat, though, maybe a little easier than loading the Jack modules for Pulse. Thanks for posting the link, I’ll give it a try later.

Leave a Reply

Your email address will not be published. Required fields are marked *