home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
tusportal.tus.k12.pa.us
/
tusportal.tus.k12.pa.us.tar
/
tusportal.tus.k12.pa.us
/
Wyse
/
latest-image.raw
/
0.img
/
etc
/
init.d
/
alsasound
< prev
next >
Wrap
Text File
|
2012-08-08
|
11KB
|
454 lines
#!/bin/sh
#
# alsasound This shell script takes care of starting and stopping
# the ALSA sound driver.
#
# This script requires /usr/sbin/alsactl program from alsa-utils package.
#
# Copyright (c) by Jaroslav Kysela <perex@suse.cz>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# For RedHat 5.0+:
# chkconfig: 2345 87 14
# description: ALSA driver
#
# modified to visually fit into SuSE 6.0+ by Philipp Thomas <pthomas@suse.de>
# further improvements by Bernd Kaindl, Olaf Hering and Takashi Iwai.
#
### BEGIN INIT INFO
# Provides: alsasound
# Required-Start:
# Should-Start: $remote_fs resmgr
# Required-Stop:
# Should-Stop: $remote_fs resmgr
# Default-Start: 2 3 5
# Default-Stop:
# Short-Description: Set up ALSA sound system
# Description: Loading ALSA drivers and store/restore the current setting
### END INIT INFO
. /etc/rc.status
. /etc/sysconfig/sound
# Shell functions sourced from /etc/rc.status:
# rc_check check and set local and overall rc status
# rc_status check and set local and overall rc status
# rc_status -v ditto but be verbose in local rc status
# rc_status -v -r ditto and clear the local rc status
# rc_failed set local and overall rc status to failed
# rc_reset clear local rc status (overall remains)
# rc_exit exit appropriate to overall rc status
# First reset status of this service
rc_reset
alsactl=/usr/sbin/alsactl
asoundcfg=/etc/asound.state
aconnect=/usr/bin/aconnect
bugout() { echo "${MYNAME}: Programming error" >&2 ; exit 123 ; }
echo_card_indices()
{
if [ -f /proc/asound/cards ] ; then
sed -n -e's/^[[:space:]]*\([0-7]\)[[:space:]].*/\1/p' /proc/asound/cards
fi
}
filter_amixer_output()
{
sed \
-e '/Unable to find simple control/d' \
-e '/Unknown playback setup/d' \
-e '/^$/d'
}
# The following functions try to set many controls.
# No card has all the controls and so some of the attempts are bound to fail.
# Because of this, the functions can't return useful status values.
# $1 <control>
# $2 <level>
# $CARDOPT
unmute_and_set_level()
{
{ [ "$2" ] && [ "$CARDOPT" ] ; } || bugout
amixer $CARDOPT -q set "$1" "$2" unmute 2>&1 | filter_amixer_output || :
return 0
}
# $1 <control>
# $CARDOPT
mute_and_zero_level()
{
{ [ "$1" ] && [ "$CARDOPT" ] ; } || bugout
amixer $CARDOPT -q set "$1" "0%" mute 2>&1 | filter_amixer_output || :
return 0
}
# $1 <control>
# $2 "on" | "off"
# $CARDOPT
switch_control()
{
{ [ "$2" ] && [ "$CARDOPT" ] ; } || bugout
amixer $CARDOPT -q set "$1" "$2" 2>&1 | filter_amixer_output || :
return 0
}
# $1 <card ID>
sanify_levels_on_card()
{
CARDOPT="-c $1"
unmute_and_set_level "Master" "80%"
unmute_and_set_level "Master Mono" "80%" # Debian #406047
unmute_and_set_level "Master Digital" "80%" # E.g., cs4237B
unmute_and_set_level "Playback" "80%"
unmute_and_set_level "Headphone" "70%"
unmute_and_set_level "Speaker" "100%"
unmute_and_set_level "PCM" "80%"
unmute_and_set_level "PCM,1" "80%" # E.g., ess1969
unmute_and_set_level "DAC" "80%" # E.g., envy24, cs46xx
unmute_and_set_level "DAC,0" "80%" # E.g., envy24
unmute_and_set_level "DAC,1" "80%" # E.g., envy24
unmute_and_set_level "Synth" "80%"
unmute_and_set_level "CD" "80%"
mute_and_zero_level "Mic"
mute_and_zero_level "IEC958" # Ubuntu #19648
# Intel P4P800-MX (Ubuntu bug #5813)
switch_control "Master Playback Switch" on
switch_control "Master Surround" on
# Trident/YMFPCI/emu10k1:
unmute_and_set_level "Wave" "80%"
unmute_and_set_level "Music" "80%"
unmute_and_set_level "AC97" "80%"
# DRC:
unmute_and_set_level "Dynamic Range Compression" "80%"
# Required for HDA Intel (hda-intel):
unmute_and_set_level "Front" "80%"
# Required for SB Live 7.1/24-bit (ca0106):
unmute_and_set_level "Analog Front" "80%"
# Required at least for Via 823x hardware on DFI K8M800-MLVF Motherboard with kernels 2.6.10-3/4 (see ubuntu #7286):
switch_control "IEC958 Capture Monitor" off
# Required for hardware allowing toggles for AC97 through IEC958,
# valid values are 0, 1, 2, 3. Needs to be set to 0 for PCM1.
unmute_and_set_level "IEC958 Playback AC97-SPSA" "0"
# Required for newer Via hardware (see Ubuntu #31784)
unmute_and_set_level "VIA DXS,0" "80%"
unmute_and_set_level "VIA DXS,1" "80%"
unmute_and_set_level "VIA DXS,2" "80%"
unmute_and_set_level "VIA DXS,3" "80%"
# Required on some notebooks with ICH4:
switch_control "Headphone Jack Sense" off
switch_control "Line Jack Sense" off
# Some machines need one or more of these to be on;
# others need one or more of these to be off:
#
# switch_control "External Amplifier" on
switch_control "Audigy Analog/Digital Output Jack" on
switch_control "SB Live Analog/Digital Output Jack" on
return 0
}
# $1 <card ID> | "all"
sanify_levels()
{
TTSDML_RETURNSTATUS=0
case "$1" in
all)
for CARD in $(echo_card_indices) ; do
sanify_levels_on_card "$CARD" || TTSDML_RETURNSTATUS=1
done
;;
*)
sanify_levels_on_card "$1" || TTSDML_RETURNSTATUS=1
;;
esac
return $TTSDML_RETURNSTATUS
}
# $1 <card ID>
preinit_levels_on_card()
{
CARDOPT="-c $1"
# Silly dance to activate internal speakers by default on PowerMac
# Snapper and Tumbler
id=`cat /proc/asound/card$1/id 2>/dev/null`
if [ "$id" = "Snapper" -o "$id" = "Tumbler" ]; then
switch_control "Auto Mute" off
switch_control "PC Speaker" off
switch_control "Auto Mute" on
fi
}
# $1 <card ID> | "all"
preinit_levels()
{
TTSDML_RETURNSTATUS=0
case "$1" in
all)
for CARD in $(echo_card_indices) ; do
preinit_levels_on_card "$CARD" || TTSDML_RETURNSTATUS=1
done
;;
*)
preinit_levels_on_card "$1" || TTSDML_RETURNSTATUS=1
;;
esac
return $TTSDML_RETURNSTATUS
}
# $1 <card ID>
mute_and_zero_levels_on_card()
{
CARDOPT="-c $1"
for CTL in \
Master \
PCM \
Synth \
CD \
Line \
Mic \
"PCM,1" \
Wave \
Music \
AC97 \
"Master Digital" \
DAC \
"DAC,0" \
"DAC,1" \
Headphone \
Playback
do
mute_and_zero_level "$CTL"
done
# for CTL in \
# "Audigy Analog/Digital Output Jack" \
# "SB Live Analog/Digital Output Jack"
# do
# switch_control "$CTL" off
# done
return 0
}
# $1 <card ID> | "all"
mute_and_zero_levels()
{
TTZML_RETURNSTATUS=0
case "$1" in
all)
for CARD in $(echo_card_indices) ; do
mute_and_zero_levels_on_card "$CARD" || TTZML_RETURNSTATUS=1
done
;;
*)
mute_and_zero_levels_on_card "$1" || TTZML_RETURNSTATUS=1
;;
esac
return $TTZML_RETURNSTATUS
}
function start_all_cards ()
{
if ! test -f $asoundcfg; then
preinit_levels all
sanify_levels all
alsactl -f $asoundcfg store
fi
}
#
# insert sequencer modules
#
load_sequencer() {
test "$LOAD_SEQUENCER" = "yes" && modprobe -q snd-seq
if [ x"$LOAD_SEQUENCER" = xyes -a -r /proc/asound/seq/drivers ]; then
OLDIFS="$IFS"
IFS=","
while read t x c; do
/sbin/modprobe $t
done < /proc/asound/seq/drivers
IFS="$OLDIFS"
fi
}
get_drivers() {
if [ -f /etc/modprobe.d/sound ]; then
cat /etc/modprobe.d/sound
else
/sbin/modprobe -c
fi | \
grep -E "^[[:space:]]*alias[[:space:]]+snd-card-[[:digit:]]" | sort | \
while read a b card; do
echo $card
done
}
#
# insert all sound modules
#
load_modules() {
module_loaded=0
c=""
drivers=`get_drivers`
for i in $drivers; do
if [ $i != off ]; then
if [ x$c = x ]; then
echo -n ": "
c=1
fi
echo -n " ${i##snd-}"
/sbin/modprobe $i && module_loaded=1
fi
done
rc_status -v -r
test $module_loaded -eq 0 && return 1
return 0
}
#
# rest of start action
#
start_rest() {
load_sequencer
if [ x"$LOAD_OSS_EMUL_MODULES" = xyes ]; then
/sbin/modprobe snd-pcm-oss
if [ x"$LOAD_OSS_SEQ_MODULE" = xyes ]; then
/sbin/modprobe snd-seq-oss
fi
fi
}
# manual load and force to store the status
start_all() {
echo -n "Starting sound driver"
load_modules && start_rest
# hack - in case the mixer isn't restored
# this shouldn't be needed anymore since udev cares
# (sleep 1; $alsactl -F -f $asoundcfg restore >/dev/null 2>&1)
rc_status
}
terminate() {
#
# Kill processes holding open sound devices
#
fuser -k /dev/admmidi* /dev/adsp* /dev/amidi* /dev/audio* /dev/dmfm* \
/dev/dmmidi* /dev/dsp* /dev/dspW* /dev/midi* /dev/mixer* /dev/music \
/dev/patmgr* /dev/sequencer* /dev/sndstat >/dev/null 2>&1
if [ -d /dev/snd ]; then
fuser -k /dev/snd/* >/dev/null 2>&1
fi
#
# remove all sequencer connections if any
#
if [ -f /proc/asound/seq/clients -a -x $aconnect ]; then
$aconnect --removeall
fi
}
# mute master to avoid clicks at unload/shutdown
unmute_system() {
/usr/bin/amixer set Master mute >/dev/null 2>&1
}
#
# remove all sound modules
#
unload_modules() {
unmute_system
mod=$(grep -m1 -E '^(snd[^ ]*|ac97_bus) [0-9]+ 0' /proc/modules)
while [ -n "$mod" ]; do
mod=${mod%% *}
/sbin/modprobe -r $mod
mod=$(grep -m1 -E '^(snd[^ ]*|ac97_bus) [0-9]+ 0' /proc/modules)
done
rc_failed 0
}
unload_all() {
echo -n "Shutting down sound driver"
terminate
unload_modules
rc_status -v
}
stop_all() {
if [ -d /proc/asound ]; then
$alsactl -g -f $asoundcfg store
unload_all
fi
}
# See how we were called.
case "$1" in
start)
start_all
start_all_cards
rc_status
;;
stop)
if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" ]; then
if [ -d /proc/asound ]; then
$alsactl -f $asoundcfg store
unmute_system
fi
else
stop_all
fi
;;
unload)
test -d /proc/asound && unload_all
;;
reload|restart)
stop_all
start_all
start_all_cards
;;
status)
if [ -d /proc/asound ]; then
echo -n "ALSA sound driver loaded."
rc_status -v
else
echo -n "ALSA sound driver not loaded."
rc_status -u
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reload|unload|status}"
exit 1
;;
esac
rc_exit