RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Where do I find the Audio selection GUI scripts?

    Scheduled Pinned Locked Moved Ideas and Development
    audioscripts
    14 Posts 2 Posters 818 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.
    • mituM
      mitu Global Moderator
      last edited by mitu

      The Audio menu is driven by the audiosettings.sh script. It only supports the on-board audio on the Pi, that's why you can't see other audio cards.

      RedMarsBlueMoonR 1 Reply Last reply Reply Quote 0
      • RedMarsBlueMoonR
        RedMarsBlueMoon @mitu
        last edited by

        @mitu

        Thank you!
        I'll see if I can make a script work. I'll post back here if I do.

        RedMarsBlueMoonR 1 Reply Last reply Reply Quote 0
        • RedMarsBlueMoonR
          RedMarsBlueMoon @RedMarsBlueMoon
          last edited by RedMarsBlueMoon

          Hi so I have a script that works in the RaspianOS desktop environment.
          I then tried to copy the script into,
          ~/RetroPie/retropiemenu

          it shows up in the list of menu items but when I run it nothing happens.
          Is there something special I need to have in my script to make it work inside Emulationstation?

          This is it currently:

          #!/usr/bin/env bash
          
          #  Script to change audio out device on a RPi4.
          #  Tested on RPi4, Buster 32bit, Kernel 5.10, pulseaudio.
          #  Not tested with HDMI2. Works with Apple AirPods (Bluetooth).
          
          function gui() {
          		
          	cmd=(pactl list sinks short)
          	IFS=$'\n' read -r -d '' -a array < <( ${cmd[@]} && printf '\0' )
          	
          	#arraylen=${#array[@]}
          	local options=()
          	
          	count=0
          	for i in "${array[@]}"
          	do
          	   echo "$i" | cut -f 2
          	   options+=($count "$i")
          	   ((count++))
          	done
          	
          	
          	
          	dialogCmd=(dialog --menu "Choose Audio output" 22 100 16)
          	choice=$("${dialogCmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
          	
          	newSink=$(echo ${array[$choice]}|cut '-d ' -f1)
          
          	pactl list short sink-inputs|while read stream; do
          		streamId=$(echo $stream|cut '-d ' -f1)
          		echo "moving stream $streamId to sink $newSink"
          		pactl move-sink-input "$streamId" "$newSink"
          	done
          
          }
          
          gui
          

          UPDATE: Actually I do get the dialog menu but it doesn't do the switch as it consistently does on the desktop. Could it be because there's no active audio returned by 'pactl list short sink-inputs' ? As the script relies on having that source id to move.

          Does Emulationstation get shut down when running scripts?

          Is there a way to keep it running?

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

            @redmarsbluemoon said in Where do I find the Audio selection GUI scripts?:

            Does Emulationstation get shut down when running scripts?

            EmulationStation disables the video and input processing and goes into background when something is launched.

            Is there a way to keep it running?

            Why ?

            RedMarsBlueMoonR 1 Reply Last reply Reply Quote 0
            • RedMarsBlueMoonR
              RedMarsBlueMoon @mitu
              last edited by

              @mitu

              To be able to switch audio on the fly 'pactl move-sink-input' needs the Id of a currently active audio stream and that's not listed when running the command presumably because ES is backgrounded then.

              I also notice that the Bluetooth control menu does not let me connect to my Bluetooth speakers (airpods) though they work perfectly on the RPiOS desktop.

              But the first issue is that actually I was correct the first time and that the above script does not even show the dialog menu when running. I only get to see the menu when launching Emulationstation from a Desktop shell.

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

                To be able to switch audio on the fly 'pactl move-sink-input' needs the Id of a currently active audio stream and that's not listed when running the command presumably because ES is backgrounded then.

                Why do you think that ? ES is just a front-end.

                I also notice that the Bluetooth control menu does not let me connect to my Bluetooth speakers (airpods) though they work perfectly on the RPiOS desktop.

                The BT menu is geared toward input device, some other types of clients may not work so well.

                But the first issue is that actually I was correct the first time and that the above script does not even show the dialog menu when running. I only get to see the menu when launching Emulationstation from a Desktop shell.

                If you run it from the shell, outside of the desktop, does it work ?

                RedMarsBlueMoonR 1 Reply Last reply Reply Quote 0
                • RedMarsBlueMoonR
                  RedMarsBlueMoon @mitu
                  last edited by

                  @mitu

                  It works as far as giving me the menu with two audiodevices, the jack and the hdmi1.
                  When running from ES I don't get the menu. I can fleetingly see some printout messages but I don't have time to read it as ES starts up again.

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

                    @redmarsbluemoon Exit ES (F4 or just quit from the menu), then run your script and you'll see the errors.

                    RedMarsBlueMoonR 1 Reply Last reply Reply Quote 0
                    • RedMarsBlueMoonR
                      RedMarsBlueMoon @mitu
                      last edited by RedMarsBlueMoon

                      @mitu
                      Unfortunately it seems like the terminal I end up in after quitting ES has cleared previous outputs, or its a different tty. The text is no longer there.
                      I have tried to find other active tty's but don't think there are any.

                      Ah, you said to run again. Ok I did that too now and I don't see the output when running my script.

                      I think I need to do some more problem solving. I just made a new tiny minimal script with a menu and that works. So just need to see what breaks.

                      RedMarsBlueMoonR 1 Reply Last reply Reply Quote 0
                      • RedMarsBlueMoonR
                        RedMarsBlueMoon @RedMarsBlueMoon
                        last edited by

                        @mitu
                        I'm seeing that pulseaudio is not actually running when ES is on.
                        I'm getting the error 'pa_context() failed'.

                        I'd be interested to know if that is knowingly turned off for ES as it is on when running the Desktop?

                        I tried starting PA up again at the start of my script and that gets me a bit further. But now I see only one of the Audio out devices. If I close down ES and run the script from the prompt I get the usual two (Jack + HDMI1)

                        RedMarsBlueMoonR 1 Reply Last reply Reply Quote 0
                        • RedMarsBlueMoonR
                          RedMarsBlueMoon @RedMarsBlueMoon
                          last edited by RedMarsBlueMoon

                          @redmarsbluemoon

                          I realised that this was a fresh microcard and I was still on the 5.4 kernel so ran an update-upgrade to get onto 5.10.

                          I made a new little script to run that just checks for pulse audio with

                          pulseaudio --check -v
                          pactl info
                          

                          That's showing me that now pa seems to be actually running and I don't get the pa_context() error.
                          Not sure if that was the kernel upgrade or something else.

                          Also if I run my main script twice I get the two out devices on the second run.

                          Still, the switch does not happen and when I get back into ES the same device is active no matter what I do in my script. (which works on desktop)

                          I feel like ES or Retropie is overriding the audio device choice somehow?
                          Or maybe not using pulseaudio even when it seems to be running? And that's why my pulseaudio switching doesn't take?

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

                            EmulationStation doesn't use PulseAudio, it uses ALSA for audio.
                            Also, the kernel update has no influence on how PulseAudio is initialized/working, it's most likely other updates - the Dec 2020 updates include PulseAudio if you have the desktop installed (as a dependency).

                            What might happen is that ALSA's default card is set to PulseAudio and this might trigger the PulseAudio starting. AFAIK (and this is how RetroPie's Audio menu works) PulseAudio is started on-demand as a user service. If you want to make sure that it's started before your script, try to initialize it (with systemctl) before EmulationStation starts, in the autostart.sh script.

                            RedMarsBlueMoonR 1 Reply Last reply Reply Quote 0
                            • RedMarsBlueMoonR
                              RedMarsBlueMoon @mitu
                              last edited by RedMarsBlueMoon

                              @mitu

                              Ok I see.
                              So, EmulationStation and its emulator cores use ALSA and not PulseAudio so I shouldn't be doing anything with PulseAudio to get the switching to Bluetooth output.

                              I should just focus on getting ALSA to work with my Bluetooth headphones.

                              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.