cadence: pulseaudio bridge disabled after suspend

Unofficial support for the KXStudio Linux distribution and applications.
More info at http://kxstudio.linuxaudio.org/

Moderators: MattKingUSA, khz

User avatar
sysrqer
Established Member
Posts: 2527
Joined: Thu Nov 14, 2013 11:47 pm
Has thanked: 320 times
Been thanked: 153 times
Contact:

Re: cadence: pulseaudio bridge disabled after suspend

Post by sysrqer »

Wait, these files need to be executable? Maybe that's why it's not working.
wolftune
Established Member
Posts: 1350
Joined: Fri Feb 24, 2012 7:40 pm
Location: Portland, OR
Been thanked: 2 times
Contact:

Re: cadence: pulseaudio bridge disabled after suspend

Post by wolftune »

sysrqer wrote:Thanks Chibchan, I tried that one in both locations but it doesn't restart the pulseaudio bridge. I was using systemd with kubuntu and kde neon and didn't have this issue, whatever cadence does or installs in those distros worked ok for me as it was. Something somewhere much be different in manjaro/arch but I have no idea what it could be. Alsa works fine, it's just pulseaudio which is being stubborn.

I think I need to get this systemd script working to solve this, at least as a workaround. Is what I have above correct for triggering a command after resume?
You have to have the one with the pre syntax in the systemd location in order to have *any* effect on systemd
Aaron Wolf
Music teacher, scholar
http://wolftune.com
User avatar
sysrqer
Established Member
Posts: 2527
Joined: Thu Nov 14, 2013 11:47 pm
Has thanked: 320 times
Been thanked: 153 times
Contact:

Re: cadence: pulseaudio bridge disabled after suspend

Post by sysrqer »

wolftune wrote:
You have to have the one with the pre syntax in the systemd location in order to have *any* effect on systemd
I did try both ways but neither had any effect. As far as I can see it would only affect alsa though, unless I am wrong?
tramp
Established Member
Posts: 2348
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 468 times

Re: cadence: pulseaudio bridge disabled after suspend

Post by tramp »

sysrqer wrote:When I resume my laptop from suspend the pulseaudio bridge is disabled and I have to start it manually. I read some threads here about this issue but they were reported as resolved bugs.
I have tried setting up a systemd service but that doesn't seem to work or fix the problem. Executing the Execstart command does start the bridge again so maybe something is wrong with the service itself?

/etc/systemd/system/resume-fix-pulseaudio.service

Code: Select all

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

[Service]
User=alex
Type=oneshot
ExecStart=/usr/bin/cadence-pulse2jack

[Install]
WantedBy=suspend.target

Code: Select all

systemctl is-enabled resume-fix-pulseaudio.service 
enabled
How can I make this work? Or fix cadence so I don't need to use a service?
I'm using manjaro at the moment and have experienced this before with this distro, didn't have the same thing kubuntu or neon.

Hi
I'm using a similar approve, which works well for me on debian/sid. I must admit, that I don't know what cadence-pulse2jack does, nor do I use jack-dbus. But, from my research and experience it is simply that the pulse module-jack-sink and module-jack-source been unloaded during suspend, and needs to be reloaded after suspend. In older pulse versions, even pulse fails to restart, but as you are on arch, I guess you've a newer version of pulse so reload and re-connect module-jack-sink and module-jack-source will do the trick.

I've a little script which I run from the systemd.service file, which looks otherwise exactly then yours, including the name it has. :)
So, what I found was that I need to add a little timeout, before reload the jack modules for pulse, here is the related contend of my script:

It does a lot more then you'll need (check if jackd is running, check if pasuspender is running, check if pulse is running, reload and re-connect the pulse jack modules or pulse audio, if needed, and writing anything to a log file in tmp), but you could take the parts you need from it, to make your own.

Code: Select all


# variable to fetch pasuspender status 
p=`ps ax | grep pasuspender`

function restart() {
	# reload pulse jack module after resume from suspend.
	# give the system time to reload pulse deamon before load the modules.
	sleep 10
	# if command-line option restart is given
	# check if pasuspender waiting for jack, if so, exit here. Nothing more
	# to do.
	# echo "restart"
	if [[ "$p"  =~ "jackd" ]]; then
		#echo "pasuspender is active"
		exit 0
	else
	# check if pulse jack modules are loaded
	jc=`pacmd list | grep jack-sink`
	# check if jack is running
	ja=`pidof jackd | wc -w`
	# check if pulseaudio is running
	pa=`pidof pulseaudio | wc -w`
	# check if pasuspender is running
	ps=`pidof pasuspender | wc -w`
	# write results to log file
	`date +%H:%M:%S  >>/tmp/pajack.log`
	`echo 'jack-sink =' $jc  >>/tmp/pajack.log`
	`echo 'jack =' $ja >>/tmp/pajack.log`
	`echo 'pulse =' $pa >>/tmp/pajack.log`
	`echo 'pasuspender =' $ps >>/tmp/pajack.log`
		if [[ ! "$jc" =~ "jack" ]] && [[ "$ja" == "1" ]]; then
			# if pulseaudio didn't run, let's try start it
			if [[ ! "$pa" == "1" ]]; then
				sleep 5
				`pulseaudio -D`
				`echo reload pulseaudio >>/tmp/pajack.log`
				sleep 10
			elif [[ "$ps" == "1" ]]; then
				pasuspender -- /bin/true
			fi
			# if jack is running and pulse jack modules aren't loaded,
			# let's load them and set them as default ports
			sleep 5
			pacmd load-module module-jack-sink channels=2 2>&1>>/tmp/pajack.log
			pacmd load-module module-jack-source channels=2 2>&1>>/tmp/pajack.log
			pacmd unload-module module-suspend-on-idle 2>&1>>/tmp/pajack.log
			sleep 1
			pacmd set-default-sink jack_out 2>&1>>/tmp/pajack.log
			# move around source port, seems to make pulseaudio work with jack
			# otherwise it seems that pulseaudio is connected, but it didn't work.
			pacmd set-default-source jack_in && sleep 1 
			source=`cat /tmp/pasourcej`
			pacmd set-default-source $source && sleep 1 
			pacmd set-default-source jack_in 
			# echo "pa source switched"
			`echo reloaded jack modules >>/tmp/pajack.log`
		else
			`echo already run >>/tmp/pajack.log`
		fi
	fi
}
as a reference, here is a content of my log file:

Code: Select all

04:25:17
jack-sink =
jack = 1
pulse = 1
pasuspender = 0
reloaded jack modules
07:15:53
jack-sink =
jack = 1
pulse = 1
pasuspender = 0
reloaded jack modules
04:16:52
jack-sink =
jack = 1
pulse = 1
pasuspender = 0
reloaded jack modules
06:22:59
jack-sink =
jack = 1
pulse = 1
pasuspender = 0
reloaded jack modules
09:01:08
jack-sink =
jack = 1
pulse = 1
pasuspender = 0
reloaded jack modules
09:31:14
jack-sink =
jack = 1
pulse = 1
pasuspender = 0
reloaded jack modules
15:26:59
jack-sink =
jack = 1
pulse = 1
pasuspender = 0
reloaded jack modules
16:30:09
jack-sink =
jack = 1
pulse = 1
pasuspender = 0
reloaded jack modules

On the road again.
User avatar
sysrqer
Established Member
Posts: 2527
Joined: Thu Nov 14, 2013 11:47 pm
Has thanked: 320 times
Been thanked: 153 times
Contact:

Re: cadence: pulseaudio bridge disabled after suspend

Post by sysrqer »

Thank you tramp, that looks very promising, I will give it a try tonight.
I did get the systemd script from a post you made here a while ago :D
User avatar
sysrqer
Established Member
Posts: 2527
Joined: Thu Nov 14, 2013 11:47 pm
Has thanked: 320 times
Been thanked: 153 times
Contact:

Re: cadence: pulseaudio bridge disabled after suspend

Post by sysrqer »

tramp wrote:
I've a little script which I run from the systemd.service file, which looks otherwise exactly then yours, including the name it has. :)
So, what I found was that I need to add a little timeout, before reload the jack modules for pulse, here is the related contend of my script:
Do you just add another ExecStart line to that service file to load the script?
tramp
Established Member
Posts: 2348
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 468 times

Re: cadence: pulseaudio bridge disabled after suspend

Post by tramp »

sysrqer wrote:Do you just add another ExecStart line to that service file to load the script?
No, I just use one other command-line, as I said, I didn't have cadence or jack-dbus here.

However, I just notice a remarkable difference, which makes it work lately, forgot to mention it.
It's to set the user runtime Environment $XDG_RUNTIME_DIR, to make pulseaudio and pacmd available in the otherwise systemd (root) environment.
It's possible, that with this extension, your previous script from cadence work, don't know,

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
you could check if your script works, by running after resume

Code: Select all

systemctl status resume-fix-pulseaudio.service
On the road again.
User avatar
sysrqer
Established Member
Posts: 2527
Joined: Thu Nov 14, 2013 11:47 pm
Has thanked: 320 times
Been thanked: 153 times
Contact:

Re: cadence: pulseaudio bridge disabled after suspend

Post by sysrqer »

Thanks for the information tramp. I think I did try a version with that in it after seeing something on the arch wiki about pulseaudio not working after suspend but it still didn't seem to work. Actually, I've managed to purge pulseaudio from my system, I had no real use for it and I felt like I had spent far too much time on it trying to make it work properly. I know this isn't a one off problem though, I've had it before on different computers with arch/manjaro and pulseaudio is sometimes hard to avoid so I will definitely keep your scripts and advice bookmarked. Thanks again.
tramp
Established Member
Posts: 2348
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 468 times

Re: cadence: pulseaudio bridge disabled after suspend

Post by tramp »

sysrqer wrote:. I think I did try a version with that in it after seeing something on the arch wiki about pulseaudio not working after suspend but it still didn't seem to work.
Well, on the ARCH wiki they said to use

Code: Select all

Environment="XDG_RUNTIME_DIR=/run/user/%U"
which translated here to

Code: Select all

Environment="XDG_RUNTIME_DIR=/run/user/0"
but it must be the user id, not the root id, to make it work, hence, on a single user machine

Code: Select all

Environment="XDG_RUNTIME_DIR=/run/user/1000"
sysrqer wrote: Actually, I've managed to purge pulseaudio from my system
uff, thats sound like a lot of work to hold this state on a arch based system. :roll:
On the road again.
User avatar
sysrqer
Established Member
Posts: 2527
Joined: Thu Nov 14, 2013 11:47 pm
Has thanked: 320 times
Been thanked: 153 times
Contact:

Re: cadence: pulseaudio bridge disabled after suspend

Post by sysrqer »

tramp wrote:

Code: Select all

Environment="XDG_RUNTIME_DIR=/run/user/0"
but it must be the user id, not the root id, to make it work, hence, on a single user machine
That's interesting, I had used the %U version but maybe that's why it wasn't working then. Thank you for the clarification.
tramp wrote: uff, thats sound like a lot of work to hold this state on a arch based system. :roll:
I don't know, it's wasn't that difficult to remove it and nothing seems to rely on it as far as I can tell. I thought kde plasma 5 depended on it now but maybe not. If I have any problems I'll reinstall it but honestly I feel more comfortable without it, it gave me no benefit whatsoever, at least for now. I've adjusted the service files though according to your suggestions so if I need to install it again then at least I'm ready for the problems it brings (for me).
Post Reply