tarina

git clone https://git.tarina.org/tarina
Log | Files | Refs | README | LICENSE

utils.sh (4704B)


      1 # Shell snippet.
      2 
      3 bugout() { echo "${MYNAME}: Programming error" >&2 ; exit 123 ; }
      4 
      5 echo_card_indices()
      6 {
      7 	if [ -f /proc/asound/cards ] ; then
      8 		sed -n -e's/^[[:space:]]*\([0-7]\)[[:space:]].*/\1/p' /proc/asound/cards
      9 	fi
     10 }
     11 
     12 filter_amixer_output()
     13 {
     14 	sed \
     15 		-e '/Unable to find simple control/d' \
     16 		-e '/Unknown playback setup/d' \
     17 		-e '/^$/d'
     18 }
     19 
     20 # The following functions try to set many controls.
     21 # No card has all the controls and so some of the attempts are bound to fail.
     22 # Because of this, the functions can't return useful status values.
     23 
     24 # $1 <control>
     25 # $2 <level>
     26 # $CARDOPT
     27 unmute_and_set_level()
     28 {
     29 	{ [ "$2" ] && [ "$CARDOPT" ] ; } || bugout
     30 	amixer $CARDOPT -q set "$1" "$2" unmute 2>&1 | filter_amixer_output || :
     31 	return 0
     32 }
     33 
     34 # $1 <control>
     35 # $CARDOPT
     36 mute_and_zero_level()
     37 {
     38 	{ [ "$1" ] && [ "$CARDOPT" ] ; } || bugout
     39 	amixer $CARDOPT -q set "$1" "0%" mute 2>&1 | filter_amixer_output || :
     40 	return 0
     41 }
     42 
     43 # $1 <control>
     44 # $2 "on" | "off"
     45 # $CARDOPT
     46 switch_control()
     47 {
     48 	{ [ "$2" ] && [ "$CARDOPT" ] ; } || bugout
     49 	amixer $CARDOPT -q set "$1" "$2" 2>&1 | filter_amixer_output || :
     50 	return 0
     51 }
     52 
     53 # $1 <card ID>
     54 sanify_levels_on_card()
     55 {
     56 	CARDOPT="-c $1"
     57 
     58 	unmute_and_set_level "Master" "80%"
     59 	unmute_and_set_level "Master Mono" "80%"   # See Bug#406047
     60 	unmute_and_set_level "Master Digital" "80%"   # E.g., cs4237B
     61 	unmute_and_set_level "Playback" "80%"
     62 	unmute_and_set_level "Headphone" "70%"
     63 	unmute_and_set_level "PCM" "80%"
     64 	unmute_and_set_level "PCM,1" "80%"   # E.g., ess1969
     65 	unmute_and_set_level "DAC" "80%"     # E.g., envy24, cs46xx
     66 	unmute_and_set_level "DAC,0" "80%"   # E.g., envy24
     67 	unmute_and_set_level "DAC,1" "80%"   # E.g., envy24
     68 	unmute_and_set_level "Synth" "80%"
     69 	unmute_and_set_level "CD" "80%"
     70 
     71 	mute_and_zero_level "Mic"
     72 	mute_and_zero_level "IEC958"         # Ubuntu #19648
     73 
     74 	# Intel P4P800-MX  (Ubuntu bug #5813)
     75 	switch_control "Master Playback Switch" on
     76 	switch_control "Master Surround" on
     77 
     78 	# Trident/YMFPCI/emu10k1:
     79 	unmute_and_set_level "Wave" "80%"
     80 	unmute_and_set_level "Music" "80%"
     81 	unmute_and_set_level "AC97" "80%"
     82 
     83 	# DRC:
     84 	unmute_and_set_level "Dynamic Range Compression" "80%"
     85 
     86 	# Required for HDA Intel (hda-intel):
     87 	unmute_and_set_level "Front" "80%"
     88 	unmute_and_set_level "Master Front" "80%"
     89 
     90 	# Required for SB Live 7.1/24-bit (ca0106):
     91 	unmute_and_set_level "Analog Front" "80%"
     92 
     93 	# Required at least for Via 823x hardware on DFI K8M800-MLVF Motherboard with kernels 2.6.10-3/4 (see ubuntu #7286):
     94 	switch_control "IEC958 Capture Monitor" off
     95 
     96 	# Required for hardware allowing toggles for AC97 through IEC958,
     97 	#  valid values are 0, 1, 2, 3. Needs to be set to 0 for PCM1.
     98 	unmute_and_set_level "IEC958 Playback AC97-SPSA" "0"
     99 
    100 	# Required for newer Via hardware (see Ubuntu #31784)
    101 	unmute_and_set_level "VIA DXS,0" "80%"
    102 	unmute_and_set_level "VIA DXS,1" "80%"
    103 	unmute_and_set_level "VIA DXS,2" "80%"
    104 	unmute_and_set_level "VIA DXS,3" "80%"
    105 
    106 	# Required on some notebooks with ICH4:
    107 	switch_control "Headphone Jack Sense" off
    108 	switch_control "Line Jack Sense" off
    109 
    110 	# Some machines need one or more of these to be on;
    111 	# others need one or more of these to be off:
    112 	#
    113 	# switch_control "External Amplifier" on
    114 	# switch_control "Audigy Analog/Digital Output Jack" on
    115 	# switch_control "SB Live Analog/Digital Output Jack" on
    116 	
    117 	# D1984 -- Thinkpad T61/X61
    118 	switch_control "Speaker" on
    119 	switch_control "Headphone" on
    120 
    121 	# HDA-Intel w/ "Digital" capture mixer (See Ubuntu #193823)
    122 	unmute_and_set_level "Digital" "80%"
    123 
    124 	# On MacBookPro5,3 and later models (See Bug#597791)
    125 	unmute_and_set_level "Front Speaker" "80%"
    126 	# On MacBook5,2 models (See Bug#602973)
    127 	unmute_and_set_level "LFE" "80%"
    128 
    129 	# On Intel 82801H (See Bug#603550)
    130 	unmute_and_set_level "Speaker" "80%"
    131 
    132 	return 0
    133 }
    134 
    135 # $1 <card ID> | "all"
    136 sanify_levels()
    137 {
    138 	TTSDML_RETURNSTATUS=0
    139 	case "$1" in
    140 	  all)
    141 		for CARD in $(echo_card_indices) ; do
    142 			sanify_levels_on_card "$CARD" || TTSDML_RETURNSTATUS=1
    143 		done
    144 		;;
    145 	  *)
    146 		sanify_levels_on_card "$1" || TTSDML_RETURNSTATUS=1
    147 		;;
    148 	esac
    149 	return $TTSDML_RETURNSTATUS
    150 }
    151 
    152 # $1 <card ID>
    153 preinit_levels_on_card()
    154 {
    155 	CARDOPT="-c $1"
    156 
    157 	# Silly dance to activate internal speakers by default on PowerMac
    158 	# Snapper and Tumbler
    159 	id=$(cat /proc/asound/card$1/id 2>/dev/null)
    160 	if [ "$id" = "Snapper" -o "$id" = "Tumbler" ]; then
    161 		switch_control "Auto Mute" off
    162 		switch_control "PC Speaker" off
    163 		switch_control "Auto Mute" on
    164 	fi
    165 }
    166 
    167 # $1 <card ID> | "all"
    168 preinit_levels()
    169 {
    170 	TTSDML_RETURNSTATUS=0
    171 	case "$1" in
    172 	  all)
    173 		for CARD in $(echo_card_indices) ; do
    174 			preinit_levels_on_card "$CARD" || TTSDML_RETURNSTATUS=1
    175 		done
    176 		;;
    177 	  *)
    178 		preinit_levels_on_card "$1" || TTSDML_RETURNSTATUS=1
    179 		;;
    180 	esac
    181 	return $TTSDML_RETURNSTATUS
    182 }