Results 1 to 4 of 4

Thread: strange sound after headphones are unplugged in suspension

  1. #1
    Join Date
    Apr 2016
    Beans
    9

    strange sound after headphones are unplugged in suspension

    Hey all,
    I've been having this issue for a while and found my work-around, but I'd like to fix this once and for all. Maybe someone here can help me.
    I use a Chromebook 2 with Xubuntu (GalliumOS).

    Whenever I put the computer into suspension with headphones plugged in and then unplug the headphones before I wake up the computer again, the sound is either off or sounds like an alien talking, until I either play around with Pulseaudio or plug the headphones back in and out.
    I imagine that Pulseaudio somehow doesn't realize that the headphones were unplugged while in suspension, so is there a way I can make it confirm every time after suspension or so?

    Would appreciate any lead.

  2. #2
    Join Date
    Mar 2011
    Location
    19th Hole
    Beans
    Hidden!
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: strange sound after headphones are unplugged in suspension

    Are you trying to run a script whenever resuming from suspend? If so, then this strategy might help: https://blog.christophersmart.com/20...-with-systemd/
    Also this: https://ubuntuforums.org/showthread....7#post13605747
    And this: https://mariogalan.com/en/content/ex...nd-ubuntu-1604 …which explains the "post" option.

    However, because you do not describe your workaround, I have no idea what the contents of said script might be. If your workaround involves resetting pulse audio, then a very simple script might do it.

  3. #3
    Join Date
    Apr 2016
    Beans
    9

    Re: strange sound after headphones are unplugged in suspension

    Thanks for the suggestions. Running a post-script should do the trick. My workaround is more manual, plugging the headphones back in and out.
    So the trick would be to add an executable script in /usr/lib/systemd/system-sleep/ with a post-script?
    Regarding the code, would this work? (novice)

    #!/bin/sh

    # restart pulseaudio

    case"$1"in
    post)
    /usr/sbin/service pulseaudio -k && pulseaudio -v
    ;;
    esac

  4. #4
    Join Date
    Mar 2011
    Location
    19th Hole
    Beans
    Hidden!
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: strange sound after headphones are unplugged in suspension

    Sorry for the delayed response. For some strange reason, I didn't get a notice of your reply.

    Since my last post, I've done some experimenting and discovered the following: Pulseaudio is a user service and not a system service. Therefore, if it is killed and restarted with systemd, it will be running as a system service under root. This is awkward and inadvisable for security reasons, if nothing else. A better solution is to create a shortcut key to a simple user script. By invoking the user script, you cycle a kill and restart of pulseaudio.

    1. Create a directory under /home/<your-username>/ called /home/<your-username>/.bin as a container for your own scripts:
      Code:
      mkdir -P -m 755 ~/.bin
    2. Check to make sure that ~/.profile contains the following:
      Code:
      # set PATH so it includes user's private bin if it exists
      if [ -d "$HOME/.bin" ] ; then
          PATH="$HOME/.bin:$PATH"
      fi
    3. Create a file in this directory called pulse-reset.sh:
      Code:
      nano ~/.bin/pulse-reset.sh
    4. Type something like the following:
      Code:
      #!/bin/bash
      # Kill and restart pulseaudio
      pulseaudio -k
      sleep 5
      pulseaudio
    5. Make the script executable:
      Code:
      chmod -c 775 ~/.bin/pulse-reset.sh
    6. Create a keyboard shortcut for this script.
      If using Ubuntu Artful: https://help.ubuntu.com/stable/ubunt...tcuts-set.html
      If using Ubuntu Xenial: https://help.ubuntu.com/lts/ubuntu-h...tcuts-set.html
      You will have to experiment with different key combos to avoid those already in use.

    It bears noting that the best solution is to remember to unplug your headphones before you suspend. Consider: when suspending, you are asking your system to take a complete snapshot of its system state before going into deep sleep. When you disconnect your headphones while suspended, this is like sawing off an appendage while it is frozen in its state of deep sleep. Asking it to elegantly recover from such a brutal assault is a big ask. It's no wonder it complains with wonky sounds.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •