functions 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. # Functions for setting up sound on the live CD.
  2. # This library is released under the GNU General Public License,
  3. # and it incorporates code from the /etc/init.d/alsa-utils included with
  4. # Ubuntu 8.04. Proper credit also goes to Debian.
  5. # Start code copied from Debian / Ubuntu:
  6. bugout () {
  7. printf "/etc/rc.d/livecdsound: programming error"
  8. stat_fail
  9. }
  10. echo_card_indices()
  11. {
  12. if [ -f /proc/asound/cards ] ; then
  13. sed -n -e's/^[[:space:]]*\([0-7]\)[[:space:]].*/\1/p' /proc/asound/cards
  14. fi
  15. }
  16. filter_amixer_output()
  17. {
  18. sed \
  19. -e '/Unable to find simple control/d' \
  20. -e '/Unknown playback setup/d' \
  21. -e '/^$/d'
  22. }
  23. # The following functions try to set many controls.
  24. # No card has all the controls and so some of the attempts are bound to fail.
  25. # Because of this, the functions can't return useful status values.
  26. # $1 <control>
  27. # $2 <level>
  28. # $CARDOPT
  29. unmute_and_set_level()
  30. {
  31. { [ "$2" ] && [ "$CARDOPT" ] ; } || bugout
  32. amixer $CARDOPT -q set "$1" "$2" unmute 2>&1 | filter_amixer_output || :
  33. return 0
  34. }
  35. # $1 <control>
  36. # $CARDOPT
  37. mute_and_zero_level()
  38. {
  39. { [ "$1" ] && [ "$CARDOPT" ] ; } || bugout
  40. amixer $CARDOPT -q set "$1" "0%" mute 2>&1 | filter_amixer_output || :
  41. return 0
  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. # $1 <card ID>
  53. sanify_levels_on_card()
  54. {
  55. CARDOPT="-c $1"
  56. unmute_and_set_level "Front" "80%"
  57. unmute_and_set_level "Master" "80%"
  58. unmute_and_set_level "Master Mono" "80%"
  59. unmute_and_set_level "Master Digital" "80%" # E.g., cs4237B
  60. unmute_and_set_level "Playback" "80%"
  61. unmute_and_set_level "Headphone" "100%"
  62. unmute_and_set_level "PCM" "80%"
  63. unmute_and_set_level "PCM,1" "80%" # E.g., ess1969
  64. unmute_and_set_level "DAC" "80%" # E.g., envy24, cs46xx
  65. unmute_and_set_level "DAC,0" "80%" # E.g., envy24
  66. unmute_and_set_level "DAC,1" "80%" # E.g., envy24
  67. unmute_and_set_level "Synth" "80%"
  68. unmute_and_set_level "CD" "80%"
  69. unmute_and_set_level "PC Speaker" "100%"
  70. mute_and_zero_level "Mic"
  71. mute_and_zero_level "IEC958" # Ubuntu #19648
  72. # Intel P4P800-MX
  73. switch_control "Master Playback Switch" on
  74. switch_control "Master Surround" on
  75. # Trident/YMFPCI/emu10k1:
  76. unmute_and_set_level "Wave" "80%"
  77. unmute_and_set_level "Music" "80%"
  78. unmute_and_set_level "AC97" "80%"
  79. # DRC:
  80. unmute_and_set_level "Dynamic Range Compression" "80%"
  81. # Required for HDA Intel (hda-intel):
  82. unmute_and_set_level "Front" "80%"
  83. # Required for SB Live 7.1/24-bit (ca0106):
  84. unmute_and_set_level "Analog Front" "80%"
  85. # Required at least for Via 823x hardware on DFI K8M800-MLVF Motherboard
  86. switch_control "IEC958 Capture Monitor" off
  87. # Required for hardware allowing toggles for AC97 through IEC958,
  88. # valid values are 0, 1, 2, 3. Needs to be set to 0 for PCM1.
  89. unmute_and_set_level "IEC958 Playback AC97-SPSA" "0"
  90. # Required for newer Via hardware
  91. unmute_and_set_level "VIA DXS,0" "80%"
  92. unmute_and_set_level "VIA DXS,1" "80%"
  93. unmute_and_set_level "VIA DXS,2" "80%"
  94. unmute_and_set_level "VIA DXS,3" "80%"
  95. # Required on some notebooks with ICH4:
  96. switch_control "Headphone Jack Sense" off
  97. switch_control "Line Jack Sense" off
  98. # Some machines need one or more of these to be on;
  99. # others need one or more of these to be off:
  100. #
  101. # switch_control "External Amplifier" on
  102. switch_control "Audigy Analog/Digital Output Jack" on
  103. switch_control "SB Live Analog/Digital Output Jack" on
  104. # D1984 -- Thinkpad T61/X61
  105. switch_control "Speaker" on
  106. switch_control "Headphone" on
  107. # HDA-Intel w/ "Digital" capture mixer (See Ubuntu #193823)
  108. unmute_and_set_level "Digital" "80%"
  109. return 0
  110. }
  111. # $1 <card ID> | "all"
  112. sanify_levels()
  113. {
  114. TTSDML_RETURNSTATUS=0
  115. case "$1" in
  116. all)
  117. for CARD in $(echo_card_indices) ; do
  118. sanify_levels_on_card "$CARD" || TTSDML_RETURNSTATUS=1
  119. done
  120. ;;
  121. *)
  122. sanify_levels_on_card "$1" || TTSDML_RETURNSTATUS=1
  123. ;;
  124. esac
  125. return $TTSDML_RETURNSTATUS
  126. }
  127. # $1 <card ID>
  128. preinit_levels_on_card()
  129. {
  130. CARDOPT="-c $1"
  131. # Silly dance to activate internal speakers by default on PowerMac
  132. # Snapper and Tumbler
  133. id=`cat /proc/asound/card$1/id 2>/dev/null`
  134. if [ "$id" = "Snapper" -o "$id" = "Tumbler" ]; then
  135. switch_control "Auto Mute" off
  136. switch_control "PC Speaker" off
  137. switch_control "Auto Mute" on
  138. fi
  139. }
  140. # $1 <card ID> | "all"
  141. preinit_levels()
  142. {
  143. TTSDML_RETURNSTATUS=0
  144. case "$1" in
  145. all)
  146. for CARD in $(echo_card_indices) ; do
  147. preinit_levels_on_card "$CARD" || TTSDML_RETURNSTATUS=1
  148. done
  149. ;;
  150. *)
  151. preinit_levels_on_card "$1" || TTSDML_RETURNSTATUS=1
  152. ;;
  153. esac
  154. return $TTSDML_RETURNSTATUS
  155. }
  156. # End copied code.
  157. # List all cards that *should* be usable for PCM audio. In my experience,
  158. # the console speaker (handled by the pcsp driver) isn't a suitable playback
  159. # device, so we'll exclude it.
  160. list_non_pcsp_cards()
  161. {
  162. for card in $(echo_card_indices); do
  163. local cardfile="/proc/asound/card${card}/id"
  164. if [ -r "$cardfile" -a -f "$cardfile" ] && \
  165. [ "$(cat "$cardfile")" != pcsp ]; then
  166. echo "$card"
  167. fi
  168. done
  169. }