RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Can switch from USB audio to HDMI, but not back to USB (defaults to headphones)

    Scheduled Pinned Locked Moved Help and Support
    usb audiohdmi audioraspi-config
    3 Posts 2 Posters 509 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      octopopit
      last edited by

      Been trying so hard to figure this out on my own over the past week, and have gotten extremely close, but I think it's time to ask for help.

      Main issue:
      I want to use HDMI audio when connected to HDMI, and USB audio when not connected to HDMI. USB audio works fine if I change ~/.asoundrc

      pcm.output {
        type hw
        card 0
      }
      ctl.!default {
        type hw
        card 0
      }
      

      to

      pcm.output {
        type hw
        card 1
      }
      ctl.!default {
        type hw
        card 1
      }
      

      Then if I connect the system to HDMI, I can go to raspi-config and set HDMI audio as default and it works great. The problem is, for some reason, USB audio is not an option in raspi-config. So when I set HDMI as default, it also defaults ~/.asoundrc back to card 0 and I need to SSH back in to fix it.

      Is there a way around this? I'm making this device for someone else, so I want it to be as user friendly as possible. I tried modifying alsa.conf and aliases.conf to make USB card 0, but that doesn't fix my problem since it just switches the device numbers around (and for some reason makes it so that my splash screen has no audio).

      Any help would be appreciated! I just wish a USB audio device showed up in the raspi-config menu, would make everything so much easier.

      System Info
      Pi Zero W
      Retropie 4.7
      Official RetroPie image
      Gameboy Zero build
      USB Audio
      Composite or HDMI Video

      mituM 1 Reply Last reply Reply Quote 0
      • mituM
        mitu Global Moderator @octopopit
        last edited by

        @octopopit said in Can switch from USB audio to HDMI, but not back to USB (defaults to headphones):

        Any help would be appreciated! I just wish a USB audio device showed up in the raspi-config menu, would make everything so much easier.

        raspi-config, just like the Audio menu in RetroPie, only configures the on-board audio, it doesn't handle any external audio card (USB/I2S).

        What you could do is create 2 configuration files (~/.asoundrc.hdmi and ~/.asoundrc.usb) and toggle between them with a shell (.sh) script. Put the script in $HOME/RetroPie/retropiemenu and it will show up in the RetroPie system in EmulationStation, so it's easy to switch between them without SSH.

        You can also run a script whenever an USB audio device is detected/connected via udev rules but it's a bit more complicated since you need to handle the default case with a different start-up script.

        O 1 Reply Last reply Reply Quote 0
        • O
          octopopit @mitu
          last edited by

          @mitu Thank you! Very simple solution, and it works perfectly! I didn't realize you could add scripts in there.

          I still get the fun "failed to find mixer element" when I run the script, run a rom, or shutdown the system, but I'm not too worried about that. At least the audio works in both configurations now.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

          Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.