#!/bin/sh # Load the mixer settings and OSS compatibility for ALSA. # (the Advanced Linux Sound Architecture) # A function to try setting some sane defaults for ALSA: set_alsa_defaults() { local cards=`cat /proc/asound/cards | \ sed 's/^\([0-9][0-9]*\) .*/\1/;s/^ .*//;'` for card in $cards; do for output in 'Master' 'PCM' 'Line' 'CD' 'PC Speaker'; do /usr/bin/amixer --card $card sset $output unmute 77% &>/dev/null done /usr/bin/amixer --card $card sset 'Mic' mute capture 77% &>/dev/null /usr/sbin/alsactl store $card done } # A function to load the ALSA mixer settings: load_alsa_mixer() { if [ -r /etc/asound.state ]; then echo "Loading ALSA mixer settings: /usr/sbin/alsactl restore" /usr/sbin/alsactl restore else set_alsa_defaults echo "ALSA warning: No mixer settings were found in /etc/asound.state." echo "Common devices have now been set to 77% and unmuted. You may still" echo "wish to adjust the sound levels with alsamixer." fi } # A function to generate the names for the ALSA mixer devices: create_alsa_names() { if [ ! -r /etc/asound.names ]; then echo "Generating device names for ALSA mixer devices." /usr/sbin/alsactl names fi } # A function to load the ALSA OSS compat modules: load_alsa_oss_modules() { if ! cat /proc/modules | grep -wq snd-pcm-oss ; then if ! cat /proc/modules | grep -wq snd_pcm_oss ; then echo "Loading OSS compatibility modules for ALSA." modprobe snd-pcm-oss modprobe snd-mixer-oss fi fi } # If hotplug or something else has loaded the ALSA modules, then # simply load the mixer settings and make sure the OSS compat # modules are loaded: if [ -d /proc/asound ]; then create_alsa_names load_alsa_mixer load_alsa_oss_modules else # If there are ALSA modules defined in /etc/modules.conf, but # ALSA is not yet loaded, then load the modules now: DRIVERS=`modprobe -c | grep -E "^[[:space:]]*alias[[:space:]]+snd-card-[[:digit:]]" | awk '{ print $3 }'` if [ ! "$DRIVERS" = "" ]; then echo "Loading ALSA kernel modules." for module in $DRIVERS; do modprobe $module done fi # If ALSA is now up, then load the mixer settings and OSS modules: if [ -d /proc/asound ]; then create_alsa_names load_alsa_mixer load_alsa_oss_modules fi fi