Difference between revisions of "Setting A Button On Your Remote To Toggle The S/PDIF Audio Source"

From MythTV Official Wiki
Jump to: navigation, search
m (Create the script)
m (Create the script)
Line 33: Line 33:
 
# Manually configure the mixer settings so that PCM output, i.e. the output from DVDs or MythMusic, goes to the S/PDIF port
 
# Manually configure the mixer settings so that PCM output, i.e. the output from DVDs or MythMusic, goes to the S/PDIF port
 
# Execute “sudo /sbin/alsactl -f /home/mythtv/asound.pcm2spdif store 0”
 
# Execute “sudo /sbin/alsactl -f /home/mythtv/asound.pcm2spdif store 0”
 
Your remote's button names are available in the /etc/lircd.conf.  We'll assume that your remote has a red button that is named RED in that file and this is the button we want to use to toggle the audio setting.
 
  
 
===Make sure irexec is running===
 
===Make sure irexec is running===

Revision as of 20:22, 15 October 2006

If you are using digital output for MythTV, you may have a need to toggle between PCM and analog audio output to your S/PDIF port. This switch can be accomplished manually using “alsamixer”, “amixer” or your favorite graphical mixer but that's not very convenient. If you are using a remote control via the lirc package then these directions will help you set a button on the remote to toggle this setting.

We'll assume that your MythTV frontend userid is “mythtv” which would make your home directory “/home/mythtv”. If you have used a different userid, then substitute its home directory in all of what follows.

Create the script

Create a script in your home directory named /home/mythtv/bin/toggleAudio:

#!/bin/sh

#  Get current setting of PCM/analog switch
AUDIO=`amixer get 'IEC958 Playback Source' | grep 'Item0:' | cut -d\' -f 2`

if [ "${AUDIO}" == "PCM" ]; then
  #  Route analog signal to S/PDIF
  amixer set 'IEC958 Playback Source',0 'Analog1 In'
  # Could also be: sudo /sbin/alsactl -f /home/mythtv/asound.analog2spdif restore 0
else
  #  Route PCM signal to S/PDIF
  amixer set 'IEC958 Playback Source',0 'PCM'
  #  Could also be: sudo /sbin/alsactl -f /home/mythtv/asound.pcm2spdif restore 0
fi

This script uses “amixer” commands to switch the IEC958 source. The exact options used on this command depend on what audio device you computer contains and the driver that it uses. Entering the “amixer” without any options will list all of the controls that are exposed for your audio device. You should be able to use the output of this command to figure out how to modify the “amixer” commands in this script to work with your sound card.

The “Could also be:” lines above suggest an alternate approach. This would be to manually configure your card for each type of output and then use “alsactl” to save the entire mixer configuration into a file for each type. In the script you call “alsactl” to restore the approariate mixer configuration for each type. With this approach we're restoring the entire set of mixer settings rather than just changing one setting.

The following procedure could be used to create the alsactl files used in the script.

  1. Manually configure the mixer settings so that analog output, i.e. the output from the TV, goes to the S/PDIF port
  2. Execute “sudo /sbin/alsactl -f /home/mythtv/asound.analog2spdif store 0”
  3. Manually configure the mixer settings so that PCM output, i.e. the output from DVDs or MythMusic, goes to the S/PDIF port
  4. Execute “sudo /sbin/alsactl -f /home/mythtv/asound.pcm2spdif store 0”

Make sure irexec is running

The irexec progarm is a lirc client that can execute system commands when buttons are pressed on the remote. It needs to be started either at a system level or by your MythTV user. If you start it at the system level during system boot then you need to specify a configuration file for it using its “-f” If you start it as a user it uses your ~/.lircrc file as its configuration file.

The command “ps -e | grep irexec” will show you if irexec is running or not. If it isn't, the following directions will help you set things up so that it starts at system boot.

Assuming that you are using KDE as the desktop for your MythTV userid, you can start irexec when your MythTV userid logs in by putting the following command into a script file in your ~/.kde/Autostart folder. If you used Jarod Wilson's Howto as a guide to installing MythTV then you already have a script there called myth-load.sh and you could just add this command to that script:

irexec &

The “&” at the end of the line causes this command to run in background so that the script can continue executing the rest of the commands that it contains.

Add the definition for the button to the .lricrc file

The names of the buttons on your remote are listed in the /etc/lircd.conf file. We'll assume you have a button called “RED” in that file that refers to the button you want to use to execute the script that toggles the audio setting. Add the following stanza to your /home/mythtv/.lircrc file:

# toggle ALSA output between Analog1 and PCM audio output to the S/PDIF port
begin
prog = irexec
button = red
repeat = 3
config = /home/mythtv/bin/audioToggle
end