#!/bin/sh

################################################################################
#      Copyright (C) 2009-2010 OpenELEC.tv
#      http://www.openelec.tv
#
#  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, 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 OpenELEC.tv; see the file COPYING.  If not, write to
#  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

# setup alsa (especially the mixer config)

mixer() {
  parm=${4:-on}
  amixer -c "$1" sset "$2" "$3" $parm >/dev/null 2>&1
  amixer -c "$1" sset "$2" $parm >/dev/null 2>&1
}

(
. /etc/profile

progress "Setting up sound card"

if [ -f $HOME/.config/sound.conf ]; then

  alsactl restore -f $HOME/.config/sound.conf

else

# set common mixer params
  mixer 0 Master 100%
  mixer 0 Front 100%
  mixer 0 PCM 100%
  mixer 0 Synth 100%

# mute CD, since using digital audio instead
  mixer 0 CD 0% mute

# Only unmute Line and Aux if they are possibly used.
  mixer 0 Line 100%
  mixer 0 Aux 100%

# mute mic
  mixer 0 Mic 0% mute

# ESS 1969 chipset has 2 PCM channels
  mixer 0 PCM,1 100%

# Trident/YMFPCI/emu10k1
  mixer 0 Wave 100%
  mixer 0 Music 100%
  mixer 0 AC97 100%
  mixer 0 Surround 90%
  mixer 0 'Surround Digital' 90%
  mixer 0 'Wave Surround' 90%
  mixer 0 'Duplicate Front' 90%
  mixer 0 'Sigmatel 4-Speaker Stereo' 90%

# CS4237B chipset:
  mixer 0 'Master Digital' 100%

# DRC
  mixer 0 'Dynamic Range Compression' 90%

# Envy24 chips with analog outs
  mixer 0 DAC 100%
  mixer 0 DAC,0 100%
  mixer 0 DAC,1 100%

# some notebooks use headphone instead of master
  mixer 0 Headphone 100%
  mixer 0 Speaker 100%
  mixer 0 'Internal Speaker' 0% mute
  mixer 0 Playback 100%

  mixer 0 Center 100%
  mixer 0 LFE 100%
  mixer 0 Center/LFE 100%

# Intel P4P800-MX  (Ubuntu bug #5813)
  mixer 0 'Master Playback Switch' on

# set digital output mixer params
  mixer 0 'IEC958' 100% on
  mixer 0 'IEC958 Output' 100%
  mixer 0 'IEC958 Coaxial' 100%
  mixer 0 'IEC958 LiveDrive' 100%
  mixer 0 'IEC958 Optical Raw' 100%
  mixer 0 'SPDIF Out' 100%
  mixer 0 'SPDIF Front' 100%
  mixer 0 'SPDIF Rear' 100%
  mixer 0 'SPDIF Center/LFE' 100%
  mixer 0 'Master Digital' 100%

  mixer 0 'Analog Front' 100%
  mixer 0 'Analog Rear' 100%
  mixer 0 'Analog Center/LFE' 100%

# ASRock ION 330 (and perhaps others) has 2 IEC958 channels
  mixer 0 IEC958,0 on
  mixer 0 IEC958,1 on

# some ION2 has much more IEC958 channels ...
  mixer 0 IEC958,2 on
  mixer 0 IEC958,3 on

# ... or "simply" more soundchips
  mixer 1 IEC958,0 on
  mixer 1 IEC958,1 on
  mixer 1 IEC958,2 on
  mixer 1 IEC958,3 on

# ASRock ION 330 has Master Front set to 0
  mixer 0 'Master Front' 100%

# Shuttle XS35GT needs this too
  mixer 0 Master,0 100%


fi

exit 0
)&

