Using Qjackctl with jackd and pulseaudio

Post fully complete "how to" guides and tutorials here. This is a great place to get feedback on stuff you might put in the wiki.

Moderators: khz, MattKingUSA

tramp
Established Member
Posts: 1422
Joined: Mon Jul 01, 2013 8:13 am

Using Qjackctl with jackd and pulseaudio

Postby tramp » Sat Dec 13, 2014 8:00 am

Pulseaudio becomes to be the standard audio server in nearly all distributions,
so it wasn’t sufficient to ignore/avoid it any longer.
It turns out, that pulseaudio indeed could work smooth together with jackd.

In my case, I’ve two different scenarios, in which way I wont to use my system.

First one is, using jackd for serious audio work, pushing pulseaudio out of the way.
That's easy, pulseaudio provide a tool for that. pasuspender
The syntax is easy, just start jackd with
pasuspender -- jackd -your -commandline -options -for -jack -here
or, for simplify, just put pasuspender -- in the qjackctl settings window,
in the server path field before jackd. You can save this settings in qjackctl.
Now, when you start jackd with qjackctl, pulseaudio will suspend as long jackd runs,
when you stop jackd, pulseaudio will re-span. Easy, eh?
Image
Next scenario, make pulse a client of jackd. This way, applications witch usually
use pulseaudio for audio out-in-put works as well.

This requires some configuration hints for the pulse daemon.
Pulseaudio comes therefor with the user-space tools pacmd/pactl.
To make pulseaudio a jack-client, we need to load the pulseaudio jack modules.

pacmd load-module module-jack-sink channels=2
pacmd load-module module-jack-source channels=2

and make them to the default in-out-puts for pulse.

pacmd set-default-sink jack_out
pacmd set-default-source jack_in

eh voila, pulseaudio is now a jack-client. When you stop jackd,
you must set back pulseaudio to use the previous used alsa ports.

Sounds as easy as the scenario before, but it isn’t. Often, this
will fail to work proper, timing is the key here.

I’ve found a script here:
https://github.com/ldo/pajackconnect

which try to solve the second scenario, but it don’t do it proper enough.
It didn’t take care about the previous used ports, witch is important
when you have multiple soundcards installed, and often it fail to
make pulse a proper jack client, as well it didn’t allow the first scenario.
So I forked it and rework it for my use-case. (pull-request is send)

https://github.com/brummer10/pajackconnect

This script is intend to be added in the qjackctl option window,
Usage: in QjackCtl’s Settings window, in the “Options” tab, enter
the command

./path/to/pajackconnect start &

in the field labeled “Execute script after Startup”, and put

./path/to/pajackconnect stop &

in the field labeled “Execute script on Shutdown”.

./path/to/pajackconnect reset &

in the field labeled “Execute script after Shutdown”.
Image

Add a new setting in the QjackCtl’s Settings window first tab, and remove
the pasuspender command from the server prefix. Save it.
Now, when you start jackd with qjackctl, pulseaudio will become a proper
jack-client, and when you stop jackd, pulseaudio will switch back to the
previous used alsa-ports.
Image
Now, you can, when ever you start jackd with qjackctl, select from the
Settings window, if you would use pulseaudio as a jack-client,
or if you would suspend pulseaudio for the session.

regards
hermann
On the road again.

User avatar
thetotalchaos
Established Member
Posts: 151
Joined: Mon Sep 29, 2014 8:29 pm
Contact:

Re: Using Qjackctl with jackd and pulseaudio

Postby thetotalchaos » Tue Jan 20, 2015 4:06 am

I think that this is important to be stated. I as a user, that is using a single sound card, supported by pulseaudio, am not having any issues with pulseaudio to jack integration. I even prefer to use my multimedia tailored system, with pulseaudio, because it gives me advantages, that i don't have when i use only alsa and jack. For instance the pulseaudio to jack bridge is far less DSP hungry than alsa-loop bridge and even from a standard alsa bridge, which allows me to start jack on much lower latency frames. Also having the option to control the volume of any application, that is connected to jack through pulseaudio, is quite handy too. My configuration includes pulseaudio-5.0 jack2 and qjackctl on a system with kernel preemption . (to check if your linux kernel is preempt-able, run the command 'uname -a').
Configure qjackctl in a standard way, without any special modifications or scripts, just tick the 'Enable D-Bus Interface' and 'Stop JACK server on application exit' in Setup/Misc. After Jack is started, open the pulseaudio volume control app and set the pulseaudio input and output to jack.
So bottom line, if your current hardware allows it, use pulseaudio and don't hesitate about it.

PS: I forgot to mention another advantage, more precisely the ability to start and stop jack, when an application is currently using pulseaudio.
Last edited by thetotalchaos on Tue Jan 20, 2015 5:02 am, edited 2 times in total.
Check out my latest music album The girl with the stars in her eyes
https://totalchaos-music.bandcamp.com/album/the-girl-with-the-stars-in-her-eyes

tramp
Established Member
Posts: 1422
Joined: Mon Jul 01, 2013 8:13 am

Re: Using Qjackctl with jackd and pulseaudio

Postby tramp » Tue Jan 20, 2015 4:39 am

thetotalchaos wrote:Configure qjackctl in a standard way, without any special modifications or scripts, just tick the 'Enable D-Bus Interface' and 'Stop JACK server on application exit' in Setup/Misc. After Jack is started, open the pulseaudio volume control app and set the pulseaudio input and output to jack.


I'm to lazy to do that by hand, if a script could do the job.
thetotalchaos wrote: think that this is important to be stated. I as a user, that is using a single sound card, supported by pulseaudio, am not having any issues with pulseaudio to jack integration. I even prefer to use my multimedia tailored system, with pulseaudio, because it gives me advantages, that i don't have when i use only alsa and jack. For instance the pulseaudio to jack bridge is far less DSP hungry than alsa-loop bridge and even from a standard alsa bridge, which allows me to start jack on much lower latency frames.


Well, I was as well surprised how well the pulse in jack integration works, but indeed, I can receive lower latencies when I suspend pulse. However, most times I just start jack with pulse enabled, but for sessions, I switch pulse of. I find it handy by do it by just a config. selection in qjackctl.
On the road again.

User avatar
thetotalchaos
Established Member
Posts: 151
Joined: Mon Sep 29, 2014 8:29 pm
Contact:

Re: Using Qjackctl with jackd and pulseaudio

Postby thetotalchaos » Tue Jan 20, 2015 4:50 am

tramp wrote:...I'm to lazy to do that by hand, if a script could do the job.


Actually i did this only the first time. Then the system somehow remembers it, and switches automatically :)


tramp wrote:Well, I was as well surprised how well the pulse in jack integration works, but indeed, I can receive lower latencies when I suspend pulse. However, most times I just start jack with pulse enabled, but for sessions, I switch pulse of. I find it handy by do it by just a config. selection in qjackctl.


If you suspend pulseaudio when jack is started you are using only jack and only apps with jack support will work. So its not much of a integration, is it? With similar success you can start jack without D-Bus. A dormant pulseaudio hardly is using any resources apart from "few bytes" of ram.
Check out my latest music album The girl with the stars in her eyes
https://totalchaos-music.bandcamp.com/album/the-girl-with-the-stars-in-her-eyes

tramp
Established Member
Posts: 1422
Joined: Mon Jul 01, 2013 8:13 am

Re: Using Qjackctl with jackd and pulseaudio

Postby tramp » Tue Jan 20, 2015 5:02 am

thetotalchaos wrote:Actually i did this only the first time. Then the system somehow remembers it, and switches automatically :)


Here it doesn’t.
But the main problem is, that after stop jack, pulse select the default soundcard, which isn't the one I usually use.

thetotalchaos wrote:If you suspend pulseaudio when jack is started you are using only jack and only apps with jack support will work. So its not much of a integration, is it? With similar success you can start jack without D-Bus. A dormant pulseaudio hardly is using any resources apart from "few bytes" of ram.

Here pulse use ~1% dsp load on demand. I can go down to 32 farmes without any xrun when pulse is suspended, otherwise, I bounded to 128 frames.
When I run a session, I've no need to use pulse, or any app which will use pulse, so yes, when pulse is suspend, only jack aware apps work, and that's why I suspend pulse.
Pulse integration is, when I start the other configuration.
On the road again.

User avatar
thetotalchaos
Established Member
Posts: 151
Joined: Mon Sep 29, 2014 8:29 pm
Contact:

Re: Using Qjackctl with jackd and pulseaudio

Postby thetotalchaos » Tue Jan 20, 2015 5:20 am

tramp wrote:Here pulse use ~1% dsp load on demand. I can go down to 32 farmes without any xrun when pulse is suspended, otherwise, I bounded to 128 frames.
When I run a session, I've no need to use pulse, or any app which will use pulse, so yes, when pulse is suspend, only jack aware apps work, and that's why I suspend pulse.
Pulse integration is, when I start the other configuration.


Is there any significant difference in DSP load when you suspend pulseaudio "manually", compared to simply start jack without D-Bus enabled? Because here i cannot see any difference even on 32 frames. Also here i can start jack with pulseaudio bridge on 32 frames, which is pretty unstable with alsa bridge and impossible using alsa-loop.

The point of all of is that, like it or not, pulseaudio is and will be the default sound server on GNU/Linux, and if linux audio community refuse to accept this fact, than the whole "linux as professional audio" thing will slowly cease to exist.
Check out my latest music album The girl with the stars in her eyes
https://totalchaos-music.bandcamp.com/album/the-girl-with-the-stars-in-her-eyes

tramp
Established Member
Posts: 1422
Joined: Mon Jul 01, 2013 8:13 am

Re: Using Qjackctl with jackd and pulseaudio

Postby tramp » Tue Jan 20, 2015 5:33 am

thetotalchaos wrote:Is there any significant difference in DSP load when you suspend pulseaudio "manually", compared to simply start jack without D-Bus enabled?

I didn't use jack with D-Bus enabled, plain jackd2 here.
I never have used any alsa bridge, as my previous soundcard supported hardware mixing, I never have any use for pulse or alsa bridges. However, my current soundcard didn't support hardware mixing, so new way's needs to be checked out.
thetotalchaos wrote: Also here i can start jack with pulseaudio bridge on 32 frames

Well I can start it as well, but simply receive Xruns much earlier then without pulse. And, when there is no need to use pulse, why not suspend it?
thetotalchaos wrote:The point of all of is that, like it or not, pulseaudio is and will be the default sound server on GNU/Linux, and if linux audio community refuse to accept this fact, than the whole "linux as professional audio" thing will slowly cease to exist.

Did you read my entry post?
The way I describe above, makes it possible to easily switch between different use cases, in a system with pulse audio as default audio server.

tramp wrote:Pulseaudio becomes to be the standard audio server in nearly all distributions,
so it wasn’t sufficient to ignore/avoid it any longer.
It turns out, that pulseaudio indeed could work smooth together with jackd.
On the road again.

User avatar
thetotalchaos
Established Member
Posts: 151
Joined: Mon Sep 29, 2014 8:29 pm
Contact:

Re: Using Qjackctl with jackd and pulseaudio

Postby thetotalchaos » Tue Jan 20, 2015 5:48 am

tramp wrote:
thetotalchaos wrote:The point of all of is that, like it or not, pulseaudio is and will be the default sound server on GNU/Linux, and if linux audio community refuse to accept this fact, than the whole "linux as professional audio" thing will slowly cease to exist.

Did you read my entry post?
The way I describe above, makes it possible to easily switch between different use cases, in a system with pulse audio as default audio server.

tramp wrote:Pulseaudio becomes to be the standard audio server in nearly all distributions,
so it wasn’t sufficient to ignore/avoid it any longer.
It turns out, that pulseaudio indeed could work smooth together with jackd.


This wasn't intended as an argument, more of a rephrase.
The idea of my post is to show that pulseaudio and jack and pretty well integrated these days, to a point that they can be used together out-of-the-box, without any special modifications necessary. Of course as a power user, you are free to make any modifications to improve the overall user experience. My point is that those modifications are not mandatory, but more are recommendations.
Check out my latest music album The girl with the stars in her eyes
https://totalchaos-music.bandcamp.com/album/the-girl-with-the-stars-in-her-eyes

tramp
Established Member
Posts: 1422
Joined: Mon Jul 01, 2013 8:13 am

Re: Using Qjackctl with jackd and pulseaudio

Postby tramp » Tue Jan 20, 2015 6:00 am

thetotalchaos wrote:The idea of my post is to show that pulseaudio and jack and pretty well integrated these days, to a point that they can be used together out-of-the-box, without any special modifications necessary.


Indeed, that is true. :)
And gladly pulseaudio comes with the needed tools to satisfy power users as well.
I'm pretty sure the same will turn out for systemd when the dust has settled.
On the road again.

danboid
Established Member
Posts: 1305
Joined: Sun Aug 26, 2012 11:28 am
Location: England

Re: Using Qjackctl with jackd and pulseaudio

Postby danboid » Thu Feb 19, 2015 9:46 am

I'd just like to add that I had to use jackdbus and enable qjack's jackdbus support to get pasuspender to work.

Regular JACK1/2 crash on my Arch install when I stop JACK after it has been started via qjack / pasuspender.
Are you new to Linux Audio? This manual explains how to install KXStudio, set up and use JACK, mimimize latency, lists the best Linux AV apps and much more all in a concise and easy to understand format.

http://wiki.linuxaudio.org/wiki/kxstudio_manual

tramp
Established Member
Posts: 1422
Joined: Mon Jul 01, 2013 8:13 am

Re: Using Qjackctl with jackd and pulseaudio

Postby tramp » Tue Feb 24, 2015 4:52 am

danboid wrote:I'd just like to add that I had to use jackdbus and enable qjack's jackdbus support to get pasuspender to work.

Regular JACK1/2 crash on my Arch install when I stop JACK after it has been started via qjack / pasuspender.


That seems to be a timing issue. In the script I've posted above, I've added a small timeout (sleep 5) for pasuspender during jack shutdown, which allow jack to finish the cleanup before pulse take over the alsa ports.
On the road again.

Shadow_7
Established Member
Posts: 169
Joined: Tue Jun 08, 2010 3:35 pm

Re: Using Qjackctl with jackd and pulseaudio

Postby Shadow_7 » Mon Apr 06, 2015 2:30 pm

I guess I tend towards the old ways. Yes, pulseaudio is getting harder and harder to avoid. But you can enable "autospawn = no" which gives you the ability to STOP pulseaudio versus suspending pulseaudio. Which is a difference of about 100MB of available RAM (not that I've checked the specs on that on recent things). But it's been the route that I tend towards since most of my devices have 2GB of RAM at most and tend towards 512MB of RAM in more commonly used bits. As in the spare bits that I might use for synth type things while using the beefier machine for productivity things.

tramp
Established Member
Posts: 1422
Joined: Mon Jul 01, 2013 8:13 am

Re: Using Qjackctl with jackd and pulseaudio

Postby tramp » Tue Aug 11, 2015 4:24 am

I've updated my version of pajackconnect and add a restart function call, thus is meant to be involved via a systemd script and check/reload the pulse jack modules after resume from suspend. The systemd script looks as followed:

Code: Select all

[Unit]
Description=Fix PulseAudio after resume from suspend
After=suspend.target

[Service]
User=your_user_name_here
Type=oneshot
ExecStart=/path/to/pajackconnect restart

[Install]
WantedBy=suspend.target


and is stored in /etc/systemd/system as resume-fix-pulseaudio.service
after it's created it needs to be loaded by the systemd daemon by:

Code: Select all

systemctl daemon-reload

(you need to be root to do that.)
On the road again.

User avatar
GMaq
Established Member
Posts: 1398
Joined: Fri Sep 25, 2009 1:42 pm

Re: Using Qjackctl with jackd and pulseaudio

Postby GMaq » Mon Dec 19, 2016 1:36 pm

@tramp

Thanks very much for sharing this, I'm testing it on several systems and it seems to work quite well. I personally don't really need PulseAudio but you are absolutely right it is pretty much unavoidable and is an included part of pretty much all the common Desktop Environments now.

I think I will shift from the current default ALSA Loopback configuration to pajackconnect for the next AV Linux release, thanks for your extra work on perfecting the original script.

tramp
Established Member
Posts: 1422
Joined: Mon Jul 01, 2013 8:13 am

Re: Using Qjackctl with jackd and pulseaudio

Postby tramp » Mon Dec 19, 2016 6:32 pm

I'm glad if it is useful for you.
Actual, for the systemd.service file, you need a addition (XDG_RUNTIME_DIR) to make it work 100% after resume from suspend. It should be:

Code: Select all

[Unit]
Description=Fix PulseAudio after resume from suspend
After=suspend.target

[Service]
User=your_user_name
Type=oneshot
Environment="XDG_RUNTIME_DIR=/run/user/1000"
ExecStart=/path/to/your/script

[Install]
WantedBy=suspend.target
On the road again.


Return to “HOW TOs, Tips & Tricks”

Who is online

Users browsing this forum: No registered users and 2 guests