wwmm / easyeffects

Limiter, compressor, convolver, equalizer and auto volume and many other plugins for PipeWire applications
GNU General Public License v3.0
6.42k stars 268 forks source link

No audio after suspension until program is closed #1083

Open gigabz666 opened 3 years ago

gigabz666 commented 3 years ago

I noticed this same issue had been closed earlier before the project had updated some but I've been noticing this issue for a little while. It was suggested to open a new issue if this was still a problem.

I've noticed that after waking my system from suspend, no audio can be heard from my headphones. This is only fixed by closing the instance of easyeffects I have running. I can then run easyeffects again with no issue until next time my system is suspended.

I'm running Endeavour OS with XFCE and I installed it natively. I've attached the output of G_MESSAGES_DEBUG=easyeffects easyeffects below. freeze on suspend.txt

wwmm commented 3 years ago

I wonder if in some situations Pipewire/Pulseaudio dies after returning from suspending. Run pw-dot after you see that the problem happened and attach the file here on github. You may have to zip it first because it is not a file type github accepts.

The output of pw-dump while the problem is happening may also help.

gigabz666 commented 3 years ago

Attached both. Also just to quickly note. I suspended with EasyEffects not running as a sanity check and on wakeup, audio is fine. It only consistently happens with EasyEffects running.

pw.dot.zip pwdumpoutput.txt

wwmm commented 3 years ago

It seems that the link between filters is not being remade after going back from suspending in your machine. What is odd. I just tested on my desktop and as soon as I try to play something after going back from suspending the links are remade and there is audio.

I don't understand what happens on some computers. Suspending has been an eternal source of problems since we used Pulseaudio. And even after a total change in how we handle things(from GStreamer to PipeWire filters and from gtk3 to gtk4) suspending still causes problems in some installations.

vchernin commented 3 years ago

I wonder if different suspend modes available behave differently.

What is the output of cat /sys/power/mem_sleep? The one surrounded by square brackets should be your current suspend mode.

s2idle is suspend to idle, and not particularly power efficient AFAIK. deep is usually suspend to RAM, possibly S3 or S0ix.

Relevant docs.

gigabz666 commented 3 years ago

Deep is surrounded by square brackets on my system. Glad to know my system is being more power efficient when sleeping, haha! I wonder if this is the difference?

wwmm commented 3 years ago

Same thing on my desktop

$ cat /sys/power/mem_sleep 
s2idle [deep]
FPSUsername commented 3 years ago

I have a less elegant workaround, but at least it works. My fix is to change the audio sink and source to another one and then back to easyeffects. I automated it to work on boot and when resuming from sleep. First make sure to use the correct sink and source names, you can get them from these commands:

$ pactl list sources | grep Name

Create a sh script (with executable rights) as following and change the USERNAME, sinks and sources according to your sinks and sources (the lines with pactl set-default-). Note that I do a check wether my default sink is available with USB_Audio. I can only assume that if you do not have a USB DAC and use the build in DAC from your motherboard, that you'd want to switch it to the correct one.

_~/.easyeffectsfix.sh

#!/bin/sh

# Remove this loop if your systemd service runs after the sound device is present.
while true; do
    output=$(sudo -u USERNAME env XDG_RUNTIME_DIR=/run/user/$(id -u USERNAME) pactl list sources | grep USB_Audio)
    if [ -n "$output" ]; then
        break
    fi
    sleep .5
done

$(sudo -u USERNAME env XDG_RUNTIME_DIR=/run/user/$(id -u USERNAME) pactl set-default-source alsa_input.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo)
$(sudo -u USERNAME env XDG_RUNTIME_DIR=/run/user/$(id -u USERNAME) pactl set-default-sink alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo)
echo "Switched to USB audio"

while true; do
    output=$(sudo -u USERNAME env XDG_RUNTIME_DIR=/run/user/$(id -u USERNAME) pactl list sources | grep easyeffects)
    if [ -n "$output" ]; then
        break
    fi
    sleep .5
done

$(sudo -u USERNAME env XDG_RUNTIME_DIR=/run/user/$(id -u USERNAME) pactl set-default-source easyeffects_source)
$(sudo -u USERNAME env XDG_RUNTIME_DIR=/run/user/$(id -u USERNAME) pactl set-default-sink easyeffects_sink)
echo "Switched to EasyEffects"

Then create a service and enable it. That's it. _/etc/systemd/system/easyeffectsfix.service

[Unit]                                                                                                       
Description=Change audio sink and source on startup and resume from sleep to fix audio
After=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target sound.target

[Service]
ExecStart=/home/USERNAME/.easyeffects_fix.sh

[Install]
WantedBy=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target multi-user.target default.target

ps: I know that this script will endlessly run if the sink/source isn't found (see the edit below to partially solve this problem). You can make this script as fancy as you want, but keep in mind, it's a simple workaround.

Edit: Using a user service won't work (explanation). Modified the stuff above.

What you can do is to add your audio device in the After= tag (you can find it with systemctl), then remove the first while loop in the .easyeffects_fix.sh file. What I couldn't figure out is how to embed the easyeffects service, since it's a user service, which doesn't work in combination with a system service.

DanMan commented 3 years ago

I haven't had this problem 1 or 2 Pipewire versions ago. This is a recent problem for me. I'm on On Fedora 33 with Pipewire 0.3.35 and EE 6.1.0 now.

Edit: I've just installed Pw 0.3.36 and I've noticed that sound partially still works. Any new sounds like system alert sounds or indeed a newly started audio player do work, also through EE (if enabled in EE). The sound source (my browser running YT) that was running before I put my system in standby (STR) does not work at all until I kill EE.

Oh, btw: I think when it was working normally before, I was using a native (?) installation of EE. I'm using the Flatpak now. But even then, I think it was still working 1 or 2 Pw versions ago.

adql commented 2 years ago

I had everything working fine until the recent Manjaro stable update. Now I also experience this bug, there is no sound at all after suspend until restarting EasyEffects. The version changes are:

EasyEffects: 6.1.5-2 -> 6.2.1-1 Pipewire: 0.3.42-2 -> 0.3.43-1

Maybe looking at that particular upgrade of Manjaro can provide more clues to the more general problem.

wwmm commented 2 years ago

@adql try to use the AUR package. This problem may be fixed in our master branch. Take a look at #1345.

adql commented 2 years ago

@wwmm I tried your suggestion and gave it some time to see how it works, and looks like it is indeed fixed. Thanks!

wildcard-f8 commented 1 year ago

manjaro here. after suspend audio reverts back to normal as if easyeffects was turned off. closing easyeffects and turning it back on fixes it but when you close it to background acts like it closes it even if shutdown on window closing is off. what seems to work for me is turning process all outputstreams off then back on.

wwmm commented 1 year ago

manjaro here. after suspend audio reverts back to normal as if easyeffects was turned off. closing easyeffects and turning it back on fixes it but when you close it to background acts like it closes it even if shutdown on window closing is off. what seems to work for me is turning process all outputstreams off then back on.

Did you notice if PipeWire's process died and was restarted after coming back from suspension? If yes I understand why EasyEffects stopped working. But if not then I have no idea about what is the cause.

wildcard-f8 commented 1 year ago

manjaro here. after suspend audio reverts back to normal as if easyeffects was turned off. closing easyeffects and turning it back on fixes it but when you close it to background acts like it closes it even if shutdown on window closing is off. what seems to work for me is turning process all outputstreams off then back on.

Did you notice if PipeWire's process died and was restarted after coming back from suspension? If yes I understand why EasyEffects stopped working. But if not then I have no idea about what is the cause.

sorry, i didn't notice it and my solution may have been premature. it recently happened again and my workaround doesn't seem to work. i think it worked a couple of times but now it doesn't. also it seems to happen after playing a game. i play this game and i have it excluded from easyeffects. most of the time it works fine after closing the game and going back to say watching a youtube video on my browser which is enabled in easyeffects. but yesterday i noticed that after closing the game the problem happens. i have to restart may laptop for everything to work as it should.

is it possible that the shutdown on window closing option is not working properly?

wwmm commented 1 year ago

is it possible that the shutdown on window closing option is not working properly?

This option only purpose is allowing EasyEffects to finish after the window is closed. A problem in it would mean EasyEffects dying when people do not want it to. If this were happening many people would be affected. Myself included. So something else must be going on.