#!/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=${3:-on}
  amixer sset "$1" "$2" $parm >/dev/null 2>&1
  amixer sset "$1" $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 Master 100%
  mixer Front 100%
  mixer PCM 100%
  mixer Synth 100%

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

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

# mute mic
  mixer Mic 0% mute

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

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

# CS4237B chipset:
  mixer 'Master Digital' 100%

# DRC
  mixer 'Dynamic Range Compression' 90%

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

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

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

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

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

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

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

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

fi

)&

