postplug/postplug.d/35sound

129 lines
3.6 KiB
Plaintext
Raw Normal View History

2011-04-27 19:57:03 +02:00
#!/bin/bash
#
# sound - sound configuration plugin for postplug
# Copyright (c) 2005-2007 by Davide Madrisan <davide.madrisan@gmail.com>
# Copyright (c) 2005-2011 by Silvan Calarco <silvan.calarco@mambasoft.it>
2011-04-27 19:57:03 +02:00
# Note: Some code has been stolen from /usr/sbin/alsaconf version 1.0.13
if [ $UID != 0 ]; then
echo "$0: must be superuser." >&2
exit 1
fi
me="sound"
[ -r /etc/sysconfig/machine ] && . /etc/sysconfig/machine
. /etc/postplug/postplug.defs
[ -r /etc/sysconfig/postplug ] && . /etc/sysconfig/postplug
SYSCONFIG_SOUNDCARDS=/etc/sysconfig/soundcards
[ -e /etc/asound.state ] && rm -f /etc/asound.state
2011-04-27 19:57:03 +02:00
# set default mixer volumes
function set_mixers() {
[ -x /usr/bin/amixer ] || return
channel=$1
[ "$channel" ] || channel=0
2011-04-27 19:57:03 +02:00
/usr/bin/amixer -s -c $channel -q <<_EOF
# Playback channels
set 'Master' 90% unmute
# some notebooks use headphone instead of master
set 'Headphone' 75% unmute
set 'Playback' 100% unmute
2011-04-27 19:57:03 +02:00
set 'Master Mono' 75% unmute
set 'Front' 90% unmute
set 'Speaker' 90% unmute
set 'PCM' 90% unmute
set 'Surround' 90% unmute
set 'Center' 90% unmute
set 'LFE' 90% unmute
set 'Line' 75% unmute
set 'CD' 90% unmute
set 'Synth' 90% unmute
2011-04-27 19:57:03 +02:00
# mute mic
set 'Front Mic' 75% mute
set 'Mic' 75% mute
2011-04-27 19:57:03 +02:00
# ESS 1969 chipset has 2 PCM channels
set 'PCM,1' 90% unmute
2011-04-27 19:57:03 +02:00
# Trident/YMFPCI/emu10k1
set 'Wave' 100% unmute
set 'Music' 100% unmute
set 'AC97' 100% unmute
2011-04-27 19:57:03 +02:00
# CS4237B chipset:
set 'Master Digital' 75% unmute
# Envy24 chips with analog outs
set 'DAC' 90% unmute
set 'DAC,0' 90% unmute
set 'DAC,1' 90% unmute
# Capture channels
set 'Capture' 90% unmute
set 'Capture 1' 90% unmute
set 'Capture 2' 90% unmute
# virtual channels
set 'Capture Gain' 50% unmute
set 'Output Gain' 75% unmute
2011-04-27 19:57:03 +02:00
# turn off digital switches
set 'SB Live Analog/Digital Output Jack' off
set 'Audigy Analog/Digital Output Jack' off
2011-04-27 19:57:03 +02:00
_EOF
}
if [ -e /proc/bus/pci ]; then
SOUND_DEV="`lspci -n 2>/dev/null| grep " 04[0-9][0-9]: "`"
fi
if [ ! "$SOUND_DEV" ]; then
if [ -e /proc/asound/cards ]; then
SOUND_DEV="`md5sum /proc/asound/cards 2>/dev/null`"
else
SOUND_DEV="missing"
fi
fi
2011-04-27 19:57:03 +02:00
if [ -e /sys/module/spi_bcm2708 -a ! -e /proc/asound/card0 ]; then
# Raspberry PI
modprobe snd-bcm2835
if [ -e /proc/asound/card0 ]; then
echo "snd-bcm2835" > /etc/modules.d/snd-bcm2835.conf
update-alternatives --set asound.conf /etc/asound.conf.dummy
SOUND_DEV="`md5sum /proc/asound/cards 2>/dev/null`"
fi
elif [ -e /proc/asound/MidasWM1811 ]; then
# Galaxy Note 10.1
/usr/sbin/alsactl restore -f /usr/share/alsa/ucm/Midas_WM1811/init.state
# enable speaker for output and builtin mic for input
/usr/bin/alsaucm -c Midas_WM1811 set _verb HiFi set _enadev Speaker
/usr/bin/alsaucm -c Midas_WM1811 set _verb HiFi set _enadev Mic
fi
if [ "$SOUND_FORCE_RESCAN" != "on" -a "$SOUND_FORCE_RESCAN" != "1" ]; then
if [ -e $postpluglibdir/sound.cache ]; then
SOUND_DEV_CACHED="`cat $postpluglibdir/sound.cache`"
[ "$SOUND_DEV" = "$SOUND_DEV_CACHED" ] && exit 0
logmsg "$me" "warning: audio device appears to have changed; re-probing"
mv $SYSCONFIG_SOUNDCARDS $SYSCONFIG_SOUNDCARDS.postplug.save
2011-04-27 19:57:03 +02:00
fi
fi
echo "$SOUND_DEV" > $postpluglibdir/sound.cache
for c in /proc/asound/card[0-9]*; do
id=`cat $c/id`
codec=`grep Codec: $c/codec* 2>/dev/null | head -n1`
logmsg "$me" $"setting volumes for $id sound card ($codec)"
index=${d1/*card}
set_mixers $index
done
if [ -x /usr/sbin/alsactl ]; then
logmsg "$me" $"saving the mixer setup (/var/lib/sound/asound.state)"
/usr/sbin/alsactl store >/dev/null
2011-04-27 19:57:03 +02:00
fi
2011-04-27 19:57:03 +02:00
echo "$SOUND_DEV" > $postpluglibdir/sound.cache
2011-04-27 19:57:03 +02:00
exit 0