How to make JACK work with laptop suspend?

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

Post Reply
Hafting
Established Member
Posts: 5
Joined: Fri Sep 28, 2012 11:17 pm

How to make JACK work with laptop suspend?

Post by Hafting »

I occationally play some music using my laptop using jack, and occationally use games using alsa.
Starting jack for music used to be a problem, as some browser or whatever might hold the soundcard exclusively. But then I found out about the alsa loop device, so now alsa sound is just another input to jack, and jack runs all the time.

This setup works very well, allowing music as well as games - even at the same time. It works well until I close the lid and suspend the machine. Of course I expect sound dropout (and perhaps some odd sounds) as the machine is stopped and restarted. But the problem is, sound is dead when it resumes.

The soundcard itself is fine. (HDA Intel PCH) So I can get sound again by killing the jack process and start it all up again. But that is precisely what I don't want to do. I want to be able to close the lid, open it later, and have everything work. No restarting of anything, no re-connecting in jack. If I had a couple of sw synths and a midi keyboard in use, all shold "just work" a few seconds after resume.

One suggestion was to use "jack_control stop" before suspend. Which can be done from a suspend script. But this breaks all jack connections and disrupts zita-a2j (and possibly other connected programs?) So it is not a solution at all.

Another suggestion I have seen was to switch jack to the dummy soundcard before suspend, and switch back to alsa after resume. Again, easy enough to script, but "jack_control sm" not only switches jacks sound devide - it also breaks all jack connections which is what I don't want.

So what to do? I don't expect sound to work during suspend (obviously), but I want everything - including jack and software using jack - to survive suspend and resume and work as well after resume as they did before suspend. Without me having to do anything more than lower and raise the lid on the machine.

Is this possible? I can run scripts automatically before suspend and after resume. But tearing down everything and restarting it all is NOT really an option. I could make a script that recreates my standard configuration, but that would not be good enough. Jack supports connecting and disconnecting stuff, the "graph" may not be the same from time to time. And some programs, like zita-a2j does not recover if I restart jack. So, is it possible to have jack survive a suspend - and if so, how is that done?

My laptop is not a dedicated music machine, so I don't want to disable suspend. I get 5.6ms latency which is good enough without increasing power usage. I use 64-bit arch linux, on a dell precision m6600.
User avatar
bluebell
Established Member
Posts: 1924
Joined: Sat Sep 15, 2012 11:44 am
Location: Saarland, Germany
Has thanked: 112 times
Been thanked: 119 times

Re: How to make JACK work with laptop suspend?

Post by bluebell »

Maybe you can use jack.plumbing to reconnect everything. You have to write some rules. I use jack.plumbing to disconnect clients from system:playback and connect them to jack_mixer. My audio interface (Scarlett 2i2) has no software controllable mixer.

Here are my rules as an example:

Code: Select all

(connect    "alsa-jack\..*jackP\..*:out_000" "jack_mixer:ALSA L")
(connect    "alsa-jack\..*jackP\..*:out_001" "jack_mixer:ALSA R")
(disconnect "alsa-jack\..*jackP\..*:out_.*" "system:playback_.*")

(connect    "Clementine:out_jackaudiosink-.*_1" "jack_mixer:JACK L")
(connect    "Clementine:out_jackaudiosink-.*_2" "jack_mixer:JACK R")
(disconnect "Clementine:out_jackaudiosink-.*" "system:playback_.*")

(connect    "Qtractor:Master/out_1" "jack_mixer:JACK L")
(connect    "Qtractor:Master/out_2" "jack_mixer:JACK R")
(disconnect "Qtractor:Master/out_.*" "system:playback_.*")

(connect    "ardour:Master/audio_out 1" "jack_mixer:JACK L")
(connect    "ardour:Master/audio_out 2" "jack_mixer:JACK R")
(disconnect "ardour:Master/audio_out.*" "system:playback_.*")

(connect    "rosegarden:master out L" "jack_mixer:JACK L")
(connect    "rosegarden:master out R" "jack_mixer:JACK R")
(disconnect "rosegarden:master out .*" "system:playback_.*")

(connect    "MPlayer.*:out_0" "jack_mixer:ALSA L")
(connect    "MPlayer.*:out_1" "jack_mixer:ALSA R")
(disconnect "MPlayer.*:out_.*" "system:playback_.*")

(connect    "PortAudio:out_.*[13579]" "jack_mixer:JACK L")
(connect    "PortAudio:out_.*[02468]" "jack_mixer:JACK R")
(disconnect "PortAudio:out_.*" "system:playback_.*")

(connect    "PulseAudio.*:front-left"  "jack_mixer:PULSE L")
(connect    "PulseAudio.*:front-right" "jack_mixer:PULSE R")
(disconnect "PulseAudio.*:front-.*" "system:playback_.*")

(connect "netjack:capture_1" "jack_mixer:JACK L")
(connect "netjack:capture_2" "jack_mixer:JACK R")

(connect "jack_mixer:MAIN L" "system:playback_1")
(connect "jack_mixer:MAIN R" "system:playback_2")

Linux – MOTU UltraLite AVB – Qtractor – http://suedwestlicht.saar.de/

Luc
Established Member
Posts: 741
Joined: Fri Mar 27, 2015 1:04 pm
Been thanked: 1 time

Re: How to make JACK work with laptop suspend?

Post by Luc »

Sorry if my comment is useless, but maybe it helps to know that I suspend and resume my computer at least once a day, sometimes several times in a day, and have none of that problem you're describing. So it must be something in your machine specifically.
emarsk
Established Member
Posts: 96
Joined: Wed Jul 27, 2011 3:50 pm

Re: How to make JACK work with laptop suspend?

Post by emarsk »

I use the ALSA JACK plugin (not the loop device) (http://jackaudio.org/faq/routing_alsa.html) and it works perfectly after a suspend.
Please, avoid some common spelling errors:
http://theoatmeal.com/comics/misspelling
Hafting
Established Member
Posts: 5
Joined: Fri Sep 28, 2012 11:17 pm

Re: How to make JACK work with laptop suspend?

Post by Hafting »

Good to hear that it is possible to make things work!

Some experimentation has shown that there are no problems with JACK when suspending, only zita-a2j which connects the alsa loop device to jack.

After suspend/resume, zita-a2j keeps printing "Starting synchronisation" continously, using up 100% of one cpu core. And of course, there is no sound from the ALSA applications anymore. It'd be nicer if this did not happen.

Still, I believe I can work around this. I can run a script on resume, that kills zita-a2j, restarts zita-a2j and finally reconnect the alsa loop to system playback in jack.
Post Reply