How to replace Pulseaudio with Jack, Jack and PulseAudio Together as Friend

Greetings, it’s been a long time since my last tutorial series in Manjaro forum. The reason is I just don’t feel like talking about something too mainstream, so I always make sure my tutorials are really hard to find elsewhere because they are made with my own experience messing things around. :smile: Check out my other two previous tutorials:

Okay, enough about myself, let’s get right into the topic of this tutorial. I know some of you have already tried replacing PulseAudio with ALSA, or maybe is still using ALSA alone until today. But do you know we have another alternative to choose? Yes, actually Jack is a more suitable replacement for PulseAudio because they are both sound servers and they are both using ALSA as the backend. Unlike ALSA which is more of a sound driver instead of sound server.

##What is Jack?

JACK Audio Connection Kit (or JACK; a recursive acronym) is a professional sound server daemon that provides real-time, low-latency connections for both audio and MIDI data between applications that implement its API. JACK has been developed by a community of open-source developers led by Paul Davis (who won an Open Source Award in 2004 for this work)[2] and has been a key piece of infrastructure and the de facto standard for professional audio software on Linux since its inception in 2002. The server is free software, licensed under the GNU GPL, while the library is licensed under the more permissive GNU LGPL. Source: wikipedia

##What are the differences between Jack and PulseAudio?
JACK is designed for real-time/low-latency response, which is required by professional-level audio solutions. PulseAudio is targeted more at general desktop users. PA seems to be heavier than JACK - being more complex induces more overhead. On Linux both use ALSA for real output in the end.
Here are the advantages of Jack compared to PulseAudio:

  1. Realtime scheduling, which means your sound is processed and transferred in realtime. Latency is displayed and can be set up by yourself depending on your system configurations. This is a really needed feature for professionals to make songs with a lot of instruments mixing.
  2. You can connect the audio inputs and outputs of all your applications together, which will look something like this :slight_smile:
  3. Because of the ability to connect multiple sound cards and streams together in real time, lot of cool things can be done with Jack. For example, live monitoring of your own voice (which is my main reason using Jack :slight_smile:), adding effect in real time to your voice, without making any more headache to you guys, here’s an example of my sound recorded by using a real time effects by a program called Rakarrack which is connected to my input and output transports in Jack: http://vocaroo.com/i/s04tLu7Ci6d7 :smile:

Here are the disadvantage of Jack compared to PulseAudio:

  1. Require more cpu power to do all the real time scheduling. Depending on how you use them, how many transports are you using in your Jack session, Jack will make your CPU work harder (not that much though, mine never hits 2% of my CPU usage on idle)
  2. X Runs. Xruns means your system missed to process some buffers in time, causing underrun or overrun. This is effected by the sample rate, buffer size, periods you set in Jack. More details about this read the FAQ in the bottom of this tutorial.

Why would I use Jack as the client of PulseAudio instead of just replace it entirely?

Because PulseAudio is a hard dependency for a lot of applications now, there’s almost all applications have support for PulseAudio. There’s way to use Jack entirely without PulseAudio though, but I just don’t recommend doing it, because many applications will just stop working (Skype, Steam, etc won’t work without pulseAudio). That’s why, the best approach is to use jack alongside PulseAudio. If you follow my tutorial, Jack input and output will be displayed as “PulseAudio JACK Source” and “PulseAudio JACK Sink” by PulseAudio.

Enough talking, let’s do this guys :slight_smile:

What to Install

These are the packages needed:

  1. jack2, jack2-dbus, pulseaudio-alsa, pulseaudio-jack
  2. cadence or qjackctl (both will work, Cadence is easier but it isn’t in the official repository, QJackCtl requires more setting up but it’s in official repository)
  3. pavucontrol (this is needed to set your applications to use the “PulseAudio Jack Source/Sink” instead of using the client PulseAudio created.

First Way (easier) to Set Up Jack with Cadence

  1. Install the required packages above without installing qjackctl. You can either install cadence or cadence-git in AUR. I prefer cadence-git, both will work just fine.

  2. This step is not needed if you haven’t modify anything to your /etc/default.pa because it’s enabled by default in Manjaro. Just to make sure there’s something like this inside your default.pa: ### Automatically connect sink and source if JACK server is present .ifexists module-jackdbus-detect.so .nofail load-module module-jackdbus-detect channels=2 .fail .endif

  3. Open up Cadence, click Configure. Ignore the settings in the Engine tab, go to Driver tab and change your input and output devices, sample rate, buffer size, and periods. Ignore everything else if you don’t know what you’re doing. Detailed information about what are them and what are the values, read the FAQ in the bottom of this page. :slight_smile:

  4. Now, go back to the Cadence main interface and start the jack server by clicking the Start button. If it’s successfully started, go to the Jack Bridges tab and change the Bridge Type to “ALSA -> Pulseaudio -> JACK (Plugin)”. Click the PulseAudio tab below and click the Start button. Congratulation, you have successfully started Jack as PulseAudio client guys :smile_cat:


  5. Open your Sound Settings of the Desktop Environment you’re using, change the default input and output devices to “PulseAudio JACK Source” and “PulseAudio JACK Sink”. Open pavucontrol, try opening the application of your choice and try opening some media files (you may need to do this on every applications you have to set it up for the first time though some applications will change it automatically). In the Playback and Recording tab, change the default device to “PulseAudio JACK Source” and “PulseAudio JACK Sink”. You maybe can hear the sound now on your speakers or headphones.

  6. Now here’s the fun part, Open up Claudia either from the Tools tab inside Cadence or from your application menu. You will see something like this:


    Now connect it to your desire. The idea is to add applications into your studio, then connect it to your desire and save your studio. More information about how to configure it read the FAQ in the bottom of this page :slight_smile:

  7. Now, assuming you already managed to do all the steps above and saved your own studio that you’ve modified, it’s time to make Cadence start it up for you on login. Just check the “Auto-start JACK or LADISH at login” and click on the small button beside it and make it to load the LADISH Studio you just saved. Make sure the PulseAudio bridge is also set to Auto-start at login.

  8. Enjoy :slight_smile:

Second Way to Set Up Jack with QJackCtl

  1. Install the required packages above without installing cadence.

  2. This step is not needed if you haven’t modify anything to your /etc/default.pa because it’s enabled by default in Manjaro. Just to make sure there’s something like this inside your default.pa: ### Automatically connect sink and source if JACK server is present .ifexists module-jackdbus-detect.so .nofail load-module module-jackdbus-detect channels=2 .fail .endif

  3. Open up QJackCtl, click the Setup button. Change your input and output devices, sample rate, buffer size (frames/period), and periods. Ignore everything else if you don’t know what you’re doing. Detailed information about what are them and what are the values, read the FAQ in the bottom of this page. :slight_smile:
    Note: The screenshots below is not my setup, I just got them from the QJackCtl website, the new QJackCtl has a new layout, but they are basically the same, just added some new tabs. Also, the default parameters are not shown in the picture, just stick with the defaults and make sure Realtime is checked. :slight_smile:

  4. Now, this is what makes QJackCtl and Cadence different. Unlike Cadence which offers you the option to bridge Jack and PulseAudio, in QJackCtl you have to do it with scripts. Here are the scripts needed, put them wherever you want. I put them inside my /usr/local/bin/. If you want to do it just like me, Here are the files you need:

    • /usr/local/bin/jack-pre-start.sh

    #!/bin/bash pacmd suspend true

    • /usr/local/bin/jack-post-start.sh

    #!/bin/bash pacmd set-default-sink jack_out pacmd set-default-source jack_in

    • /usr/local/bin/jack-pre-stop.sh

    #!/bin/bash SINKID=$(pactl list | grep -B 1 "Name: module-jack-sink" | grep Module | sed 's/[^0-9]//g') SOURCEID=$(pactl list | grep -B 1 "Name: module-jack-source" | grep Module | sed 's/[^0-9]//g') pactl unload-module $SINKID pactl unload-module $SOURCEID sleep 5

    • /usr/local/bin/jack-post-stop.sh

    #!/bin/bash pacmd suspend false

    • Don’t forget to make them executable:
    sudo chmod +x /usr/local/bin/jack-p*.sh

    Put them in the order into the Scripting settings of QJackCtl.

  5. Now go to the Misc tab and check the the Start JACK audio server on application startup, Enable system tray icon, Start minimized to system tray, Enable D-Bus interface. Leave the other settings with their default states.

  6. You can now go back and start Jack by pressing the Start button on the main interface of QJackCtl, Congratulations, you have successfully started Jack as PulseAudio client guys :smile_cat: Now click the Connect button to play with connection. To save your connection and start it up after reboot, modify it in the patchbay and make sure the Activate Patchbay persistence is checked in the QJackCtl Setup. More information about how to configure it read the FAQ in the bottom of this page :slight_smile:

  7. Open your Sound Settings of the Desktop Environment you’re using, change the default input and output devices to “PulseAudio JACK Source” and “PulseAudio JACK Sink”. Open pavucontrol, try opening the application of your choice and try opening some media files (you may need to do this on every applications you have to set it up for the first time though some applications will change it automatically). In the Playback and Recording tab, change the default device to “PulseAudio JACK Source” and “PulseAudio JACK Sink”. You maybe can hear the sound now on your speakers or headphones.

  8. Now, assuming you already managed to do all the steps above and saved your own patchbay connection that you’ve modified, it’s time to make QJackCtl start it up for you on login. Just add a desktop file or add it with the settings of your Desktop Environment. If you can’t find the settings, just copy the file in /usr/share/applications/QjackCtl to your ~/.config/autostart/:

cp /usr/share/applications/QjackCtl ~/.config/autostart/
  1. Enjoy :slight_smile:

Frequently Asked Questions

1. What is sample rate, buffer size, and periods? What should I set them too and what results can I get?
I think we all want a simple and headache free answer, so to make it simple, here’s what my answer:
(Buffer size/Sample rate) * Period = Latency
So, to decrease latency, just decrease the buffer size, increase the sample rate, and increase the period. But there are things you need to know before just decrease your latency into 2ms though :smile:. Things you need to know are:

  • Set your sample rate according to the sample rate your sound card can handle, you can check it by running this command: cat /proc/asound/card0/codec\#0 | grep -i rates
    Note: change card0 and codec#0 to the card you are using in Jack. Also, usb devices can be named stream instead of codec.

  • Set your periods only 2 or 3. Use 3 for USB soundcard are said to be more stable. You need to test it out yourself.

2. What do the Hardware Capture, Hardware Playback, PulseAudio JACK Source, PulseAudio JACK Sink mean?

  • Hardware Capture is your microphone. This is the input device you have chosen in your Cadence or QJackCtl setting
  • Hardware Playback is your speaker/headphone. This is the output device you have chosen in your Cadence or QJackCtl setting
  • PulseAudio JACK Source is the bridge between PulseAudio Input and Jack Input. Your applications will capture sound from the JACK Source
  • PulseAudio JACK Sink is the bridge between PulseAudio Output and Jack Output. Your applications will send sound to PulseAudio JACK Source

3.What connections should I connect?
Actually, it all depends on how you are using it. To answer this, I just make a simple diagram showing you how to get your microphone input and speaker output correctly

  • Hardware Capture -> PulseAudio JACK Source = your microphone is now connected and you can record sound into your computer

  • Hardware Playback -> PulseAudio JACK Sink = your speaker is connected and you can hear the output of applications using your speaker/headphone

Those two are the basic connection you need to get your application working. Now, if you want something more complex, these are some examples:

  • If you want to monitor the sound produced by your microphone in realtime, connect Hardware Capture to Hardware Playback which is connected to the PulseAudio JACK Sink.

  • If you want some effects to be applied in realtime to your microphone input while recording, install applications like Rakarrack, Guitarix, Jack Rack, Carla, or other mixing/sound plugins applications and start them up. They will provide their own transports inside your Claudia or QJackCtl patchbay to let you connect. Here’s the basic connection for Rakarrack:
    System Capture -> Rakarrack Input, Rakarrack Output -> PulseAudio JACK Source = The sound you input into your microphone will be processed by Rakarrack and it will send it to your PulseAudio Input, so when it arrives into your recording application, it will produce a sound after the effects or filters are applied. If you want to monitor the result in realtime, you can just connect the Rakarrack Output into your Hardware Playback which is connected to your Hardware Playback.

  • If you have any MIDI input hardware, such as guitars, keyboards, etc you can connect the MIDI Input into PulseAudio JACK Source to record it into your recording applications. You can also install other instrument effects applications and connect the MIDI Input into the application before sending it out from the application into PulseAudio JACK Source.

Those are just examples, the real life applications for Jack are limitless :slight_smile:

4. How to reduce Xruns?
Actually, the best way to do it is to use the kernel specially tweaked for realtime, such as linux-rt or compile it yourself. But if compiling your own kernel is not something you want to do, actually there are a lot of things to tweak to reduce Xruns.

  • Add your user to the audio group
  • Set your cpufreq to performance
  • Decreasing the sample rate from Cadence or QJackCtl, you need to check the sample rate supported by your soundcard though. Note: this will increase the latency of Jack
  • Increase the buffer size from Cadence or QJackCtl. Note: this will increase the latency of Jack
  • Increase the periods / buffer from Cadence or QJackCtl. Note: this will increase the latency of Jack
  • Reduce the number of Jack clients connected in your patchbay
  • Kill processes you don’t need
  • Tweak your Manjaro kernel, further readings: here and here

More FAQs will be added when I can think of what you guys should know :slight_smile:


Troubleshooting

1. Claudia showing two PulseAudio JACK Sinks and PulseAudio JACK Sources
If your Claudia canvas shows another copy of both your PulseAudio JACK Sink and Source as JACK Sink-01 and Source-02, it means JACK dbus is making JACK client for PulseAudio twice. To fix this, either comment out the ### Automatically connect sink and source if JACK server is present .ifexists module-jackdbus-detect.so .nofail load-module module-jackdbus-detect channels=2 .fail .endif in your /etc/pulse/default.pa or uncheck the Autostart PulseAudio bridge in Cadence. Because both of them are doing the same thing.

More Troubleshooting will be added when I can spot on some problems you might encounter :slight_smile:

20 Likes

Great tutorial!
I use cadence but I have a problem with the alsa loopback bridge, every time I suspend or hibernate the bridge is stopped when I resume. I think the module snd_aloop is still loaded upon resume because I can just start the bridge again without any problem. I think this is down to systemd somehow, I have tried other kernels and still the same thing, and I’ve used openrc previously in other distros without problems.

If I could find a way to do it then I would just set systemd to load it after resume but I don’t know how to enabled the bridge in this way, plus it’s not really solving the root of the problem.

Any ideas?

I think that is handled by alsa-restore.service in systemd if I remember correctly. I don’t know much about things like that though, do you have resume=UUID=“uuid-of-your-swap-partition” in your grub kernel line?

Thanks for the tutorial! JACK was the standard at one time, and I’m glad to see you giving it the lovin’ it deserves. :smile:

1 Like

You’re welcome c00ter. Your reply shows that you’re indeed an old fighter here :smile:

1 Like

Yes, I do have the resume=uuid in the grub kernel line, the suspend and hibernate work perfectly well it’s just that the bridge is stopped every time. I was going to make a thread for this soon but saw this and thought you or someone else might know what’s causing it as it’s a related topic, no worries though.

If you want to post the report, post it inside the cadence bug tracker will be a better place. https://github.com/falkTX/Cadence/issues?q=is%3Aopen :slight_smile:

I’m not really convinced it is a cadence bug but I speak to the dev fairly often so I will post there or ask him about it.

Nice. Good luck mate :slight_smile:

Tutorial edited for the second time, added some screenshots on how to connect your transports :slight_smile:

ALSA supports bluetooth speakers, actually PulseAudio is using ALSA as the driver. it’s the bluez5 who doesn’t support ALSA anymore. I don’t know because I don’t have any bluetooth speaker. But all I know is if your run aplay -l and it displays your bluetooth speaker, then JACK will work just fine. But all I know is, you got the driver (ALSA), you got the hardware, but you can’t connect it because you need pulseaudio-bluetooth to connect. You can connect with ALSA only if the bluez developer build something sounds something like alsa-bluetooth, then you can use it with JACK. :slight_smile:

According to Arch Wiki you can use bluez with ALSA, I don’t know but maybe you can try it out :slight_smile:

For your question about multiple speakers, there’s alsa_in and alsa_out, which is what I’m now using in cadence to allow my girlfriend and me to watch video and communicate together with 2 headsets. I’m planning to make a tutorial about this in the future :slight_smile:

1 Like

Sorry i deleted the post and sent you a message as i thought better of posting my question on your tutorial

1 Like

Also. Thanks for the tutorial :birthday:

1 Like

Added Trobleshooting section as I found out something you guys should know before getting any headache :slight_smile

Just read this due to your answer on my question, should’ve been a referenced tutorial for anyone who needs to live with both JACK and PulseAudio. I also just knew that Cadence gives much better UX than QJackCtl. I wouldn’t know that it exists if not from this tutorial. Thanks, mate.

Thanks, man. Your feedback is much appreciated. Hope you’ll get a new headset soon and try it out :slight_smile:

haha, no need. my bluetooth headset also comes with cable and output jack, it can also be used like any other wired headset.

What headset is that? Are you from Indonesia too?

Bluedio Turbine H+. Yes, I am from Indonesia.

Greeting from fellow Indonesian mate :slight_smile:

Forum kindly sponsored by Bytemark