Restart audio after waking from suspend

  • Problem: My nettop box doesn't restart the audio driver when awaking from Suspend. Because the computer doesn't respond to IR when completely powered down, I have to reboot after waking from suspend.

    This is how I currently do it:

    /storage/.kodi/addons/00restart/sleep.d/restart.power:

    Bash
    #!/bin/sh
    [ "$1" = "post" ] && reboot

    Is there a better way to restart the audio driver than rebooting the entire system?

    I tried killing kodi.bin, but that doesn't work. It looks like I have to restart the kernel. Not sure how to do that without ``````"reboot". Or is there a way to restart the audio subsystem? :(

  • I had/have the same exact problem but with an Intel NUC. Turning it on from suspend produced no audio. I found out that if I toggled the refresh rate from 60.00 to 59.94, the audio returned. When asked to save 59.94, I said no to the user interface. Someone wrote a script for me over at the Kodi website and it worked for a while but it has since stopped working and I have to do the refresh rate toggling myself. I suspect it's a timing issue with the order the devices are turned on.

  • Thanks for the hint. It definitely worked on the UI. I have to give it a try on the commandline. But somehow doing it once on the UI fixed it for me. 🤷‍♂️

    For future reference and for others that are running into the same problem, this is how to change the refresh rate to 59.94 and then back to 60.00 on the command line:

    Code
    xrandr --output HDMI-0 --mode 1920x1080 --rate 59.94
    xrandr --output HDMI-0 --mode 1920x1080 --rate 60.00
  • Using the above, I think I have a solution. When awaking from suspend, I will kill Kodi so that it will restart and rescan the database. I will then change the refresh rate and then change it back a couple seconds later.

    Works so far. 🤞

    /storage/.kodi/addons/00restart/sleep.d/restart.power

    Bash
    #!/bin/sh
    [ "$1" = "post" ] && sleep 5 && kill -9 `pidof kodi.bin` \
    && xrandr --output HDMI-0 --mode 1920x1080 --rate 59.94 && sleep 2 \
    && xrandr --output HDMI-0 --mode 1920x1080 --rate 60.00

    If it doesn't work, I would check if xrandr gives the same results before and after suspending.

  • Here's the entire thread I posted back in 2019. Post #32 contains the script that worked for me. Unfortunately, it stopped working a few months later.

    No Audio after wake from suspend

    Thanks for the link. Sounds like I have almost the same solution. 😁

    I think xrandr changed it's options and if you add the hyphen to HDMI-1 it should work again.

    I used my script and suspended and resumed a few times and things are working great for me.

    Thanks again for pointing me in the right direction. 👍

  • Then maybe you could help me. How do I SSH in and remove the non-working script and replace it with a working one ? I am sort of lost once I SSH using Putty. I'm not sure what you mean by "I think xrandr changed it's options and if you add the hyphen to HDMI-1 it should work again."

    Step-By-Step would be great

  • After I SSH in using Putty, exactly what should I do ? Step by step please. I'm not really sure how to find and edit my script. After I manage to edit it, is it automatically saved when I exit ?

  • I tried to SSH in using FileZilla instead but the login failed

    Host: 192.168.1.153

    Username: root

    Password: libreelec

    Connection attempt failed with "ECONNREFUSED - Connection refused by server".

    Could not connect to server

  • OK, use nano editor:

    nano /storage/.config/sleep.d/99-toggle_rate.power

    use cursor keys to navigate to both HDMI1 words and insert - character to change them to HDMI-1

    Then press CTRL+X and confirm by Y to save the file.

    I recommend using putty as SSH client.

    If LE is refusing the connection, restart the SSH service through Kodi menu Settings - LibreELEC - Services - SSH (disable and re-enable),

    then connect through putty again.

  • (In Filezilla, make sure the Protocol is set to SFTP, not FTP.)

    Question:

    When you remote it with PuTTY, does entering the following two lines re-enable your audio?

    Code
    xrandr --output HDMI-1 --mode 1920x1080 --rate 59.94
    xrandr --output HDMI-1 --mode 1920x1080 --rate 60.00
  • I closed the SSH client but the changes were not saved.

    I made the changes again and now it says:

    File Name to Write: /storage/.coinfig/sleep.d/99-toggle_rate.power

    and the green cursor is after .power

    Do I type exit and press the ENTER key ?

  • The file is saved as soon as you exit from nano editor and confirm saving by Yes and file name by ENTER.

    Open the file again to check, then exit SSH client.

  • I closed the SSH client but the changes were not saved.

    I made the changes again and now it says:

    File Name to Write: /storage/.coinfig/sleep.d/99-toggle_rate.power

    and the green cursor is after .power

    Do I type exit and press the ENTER key ?

    You press ENTER to save the file.

    In nano you can save the file at any time with CTRL-o (hold down the Control key and press o). When you do so, it will ask you for the file name, but it will already be prefilled, you can just hit the ENTER key.

    You can then exit with CTRL-x (hold down the Control key and press x).

    Once you exit nano with CTRL-x, exit PuTTY with 'exit'.