#!/bin/sh

WITHOUT_RC_COMPAT=1
# Source functions library.
. /etc/init.d/functions

mixer()
{
    echo sset "$1" "$2"
    echo sset "$1" "$3"
}

if [ -d /proc/asound ]
then
    alsactl init

    for card in /proc/asound/card[0-9]*
    do
        {
            mixer Master           75% unmute
            mixer PCM              90% unmute
            mixer Front           100% unmute
            mixer Synth            90% unmute
            mixer CD               90% unmute
            # ESS 1969 chipset has 2 PCM channels
            mixer PCM,1            90% unmute
            # Trident/YMFPCI/emu10k1
            mixer Wave            100% unmute
            mixer Music           100% unmute
            mixer AC97            100% unmute
            # CS4237B chipset:
            mixer 'Master Digital' 75% unmute
            # Envy24 chips with analog outs
            mixer DAC              90% unmute
            mixer DAC,0            90% unmute
            mixer DAC,1            90% unmute
            # some notebooks use headphone instead of master
            mixer Headphone        75% unmute
            mixer Playback        100% unmute
            mixer Speaker          75% unmute
            # mute mic
            mixer Mic               0% mute
        } | amixer -c "${card##*/card}" -s >/dev/null 2>&1 &
    done
    wait

    if modprobe snd-seq-midi >/dev/null 2>&1
    then
        if [ -e /etc/modules ]
        then
            if [ -s /etc/modules ]
            then
                echo
            fi
            echo "# by alsa-set-initial-options"
            echo "snd-seq-midi"
        fi >> /etc/modules
    fi

    action "Setup initial ALSA mixer state:" true
else
    action "Do NOT setup ALSA:" true
fi
