updated on Wed Jan 25 16:08:47 UTC 2012
[aur-mirror.git] / alsa-tools-emu10k1 / alsa-emu10k1d
blob02f98fa80c74b719b450fff3b35ecf3d046ca905
1 #!/bin/bash
2 # alsa-emu10k1d v0.5 RC1 (GPL3) by 3ED <krzysztof1987@gamil.com>
4 . /etc/rc.conf
5 . /etc/rc.d/functions
6 . /etc/conf.d/alsa-emu10k1d
9 # DSP state file..
10 ETC_DIR="/var/lib/alsa"
11 DSP_STATE="${ETC_DIR}/asound.dsp"
12 MASTER_STATE="${ETC_DIR}/amixer.state"
13 ASOUND_STATE="${ETC_DIR}/asound.state"
16 #-------------------------------------------------------------------------------
17 # Initial functions - setup and update
18 #-------------------------------------------------------------------------------
19 sub_update_to_new_version() {
20 sub_update_0_4_to_0_5
22 sub_update_0_4_to_0_5() { #TODO ${ETC_DIR}
23 # Now you can simple mount rootfs as read-only and this program is not the barier
24 [ ! -d "/var/lib/alsa" ] && install -dm755 "/var/lib/alsa" || return
26 if [ ! -f "/var/lib/alsa/asound.dsp" ] && [ -f "/etc/asound.dsp" ]; then
27 install -m600 "/etc/asound.dsp" "/var/lib/alsa/asound.dsp"
30 if [ ! -f "/var/lib/alsa/asound.state" ] && [ -f "/etc/asound.state" ]; then
31 install -m600 "/etc/asound.state" "/var/lib/alsa/asound.state"
34 sub_first_run() {
35 echo -n "Turn off any audio programs and speakers.. [enter to continue]"
36 read
37 /etc/rc.d/alsa stop
38 echo "==> Backuping rc.conf.."
39 cp -v /etc/rc.conf /etc/rc.conf.backup-emu10k1d
40 echo "==> Replacing \"alsa\" --> \"alsa-emu10k1d\" in rc.conf.."
41 sed -i 's/\(DAEMONS.*\)alsa[[:space:]]\(.*)\)/\1alsa-emu10k1d \2/g' /etc/rc.conf
45 #---------------------------------------------------------------------------
46 # Common functions
47 #---------------------------------------------------------------------------
48 sub_stat_return() {
49 if [ "$1" = "0" ]; then
50 stat_done
51 else
52 stat_fail
53 return 1
56 sub_lock_touch() {
57 [ -f "/tmp/.lo10k1.lock" ] || touch /tmp/.lo10k1.lock || return 1
61 #-------------------------------------------------------------------------------
62 # Storing functions
63 #-------------------------------------------------------------------------------
64 sub_store_master_mixer() {
65 local OPH="`amixer get Master`" OPH_MODE=0 L="" R=""
67 while read LINE; do
68 # 1 channel - mono
69 if [ $OPH_MODE = 1 ] && [ "${LINE:0:5}" = "Mono:" ]; then
70 L="`expr "$LINE" : ".*Playback [0-9]* \[\([0-9]*%\).*"`" || return 1
73 # 2 channels - stereo
74 if [ $OPH_MODE = 2 ] && [ "${LINE:0:11}" = "Front Left:" ]; then
75 L="`expr "$LINE" : ".*Playback [0-9]* \[\([0-9]*%\).*"`" || return 1
78 if [ $OPH_MODE = 2 ] && [ "${LINE:0:12}" = "Front Right:" ]; then
79 R="`expr "$LINE" : ".*Playback [0-9]* \[\([0-9]*%\).*"`" || return 1
82 # detecting mixer type: mono/stereo
83 if [ $OPH_MODE = 0 ] && [ "${LINE:0:18}" = "Playback channels:" ]; then
84 expr "$LINE" : ".*Mono" &> /dev/null && OPH_MODE=1
85 expr "$LINE" : ".*Front Left - Front Right" &> /dev/null && OPH_MODE=2
87 done << LINE
88 $OPH
89 LINE
91 [ -z "$L" ] && return 1
93 echo $L $R > "$MASTER_STATE"
95 sub_store_DSP(){
96 /usr/bin/lo10k1 --store "$DSP_STATE" || return 1
98 sub_store_ALSA(){
99 /usr/sbin/alsactl $ALSA_ARGS --file "$ASOUND_STATE" store || return 1
103 #-------------------------------------------------------------------------------
104 # Restoring functions
105 #-------------------------------------------------------------------------------
106 sub_restore_DSP() {
107 test -f "/tmp/.lo10k1.lock" && return 0
108 case $INIT_NAME in
109 "auto")
110 if [ -f "$DSP_STATE" ]; then
111 /usr/bin/lo10k1 --restore "$DSP_STATE"
112 else
113 for cardid in {0..20}; do [ -f "/proc/asound/card$cardid/emu10k1" ] && break; done
114 card="$(expr "$(cat /proc/asound/card$cardid/id)" : '.*\(Live\|Audigy\)')" 2> /dev/null
115 case $card in
116 "Audigy") init_audigy_eq10 || return 1;;
117 "Live") init_live || return 1 ;;
119 if (( "$cardid" >= 20 )); then
120 echo "Do you realy have emu10k1 card?"
121 else
122 echo "FIXME: Send me your /proc/asound/card$cardid/id entry and oryginal card name."
124 echo "Workaround: Change INIT_NAME=(your) in conf.d and then run daemon start and store."
125 return 1
126 esac
129 *) init_$INIT_NAME &> /dev/null || return 1
130 esac
132 sub_restore_ALSA() {
133 /usr/sbin/alsactl $ALSA_ARGS --file "$ASOUND_STATE" restore > /dev/null || return 1
135 POWERSAVE=${POWERSAVE:-0}
136 if [ -e /sys/module/snd_ac97_codec/parameters/power_save -a $POWERSAVE -ne 0 ]; then
137 echo $POWERSAVE > /sys/module/snd_ac97_codec/parameters/power_save
138 [ -c /dev/dsp ] && echo 1 > /dev/dsp
141 if [ -e /sys/module/snd_hda_intel/parameters/power_save -a $POWERSAVE -ne 0 ]; then
142 echo $POWERSAVE > /sys/module/snd_hda_intel/parameters/power_save
143 [ -c /dev/dsp ] && echo 1 > /dev/dsp
146 return 0
150 #-------------------------------------------------------------------------------
151 # Daemon functions
152 #-------------------------------------------------------------------------------
153 sub_daemon_mute_master_mixer() {
154 if [[ "$MUTE_MASTER_MIXER" =~ [Yy] ]]; then
155 stat_busy "Mute ALSA Master Mixer"
156 amixer set Master 0 &> /dev/null
157 sub_stat_return $?
160 sub_daemon_store_master_mixer() {
161 if [[ "$STORE_MASTER_MIXER" =~ [Yy] ]]
162 then
163 stat_busy "Saving ALSA Master Mixer"
164 sub_store_master_mixer
165 sub_stat_return $?
168 sub_daemon_store_alsa() {
169 if [[ "$STORE_ALSA" =~ [Yy] ]]; then
170 stat_busy "Saving ALSA Levels"
171 sub_store_ALSA
172 sub_stat_return $?
173 else
174 sub_daemon_store_master_mixer
177 sub_daemon_store_dsp() {
178 if [[ $STORE_DSP =~ [Yy] ]]; then
179 stat_busy "Saving ALSA DSP Levels"
180 sub_store_DSP
181 sub_stat_return $? && sub_lock_touch
186 #-------------------------------------------------------------------------------
187 # Main functions
188 #-------------------------------------------------------------------------------
189 sub_daemon_store() {
190 if [[ "$STOP_WITH_STORE" =~ [Yy] ]]; then
191 sub_daemon_store_alsa
192 sub_daemon_store_dsp
193 else
194 sub_daemon_store_master_mixer
197 sub_daemon_mute_master_mixer
199 sub_daemon_restore_master_mixer() {
200 if [[ "$STORE_MASTER_MIXER" =~ [Yy] ]]
201 then
202 [[ "$STOP_WITH_STORE" =~ [Yy] ]] && [[ "$STORE_ALSA" =~ [Yy] ]] && return 0
203 stat_busy "Restoring ALSA Master Mixer"
204 amixer set Master `cat "$MASTER_STATE"` > /dev/null
205 sub_stat_return $?
208 sub_daemon_restore(){
209 stat_busy "Restoring ALSA DSP Levels"
210 sub_restore_DSP
211 sub_stat_return $? && sub_lock_touch
213 stat_busy "Restoring ALSA Levels"
214 sub_restore_ALSA
215 sub_stat_return $?
217 sub_daemon_restore_master_mixer
219 sub_daemon_start() {
220 test -f "/var/run/daemons/alsa" && sub_first_run
221 stat_busy "Starting ALSA DSP Processor"
222 /usr/sbin/ld10k1d start &> /dev/null
223 if sub_stat_return $?; then
224 add_daemon alsa-emu10k1d
225 sub_daemon_restore
228 sub_daemon_stop() {
229 sub_daemon_store
230 stat_busy "Stopping ALSA DSP processor"
231 /usr/sbin/ld10k1d stop &> /dev/null
232 sub_stat_return $? && rm_daemon alsa-emu10k1d
234 sub_daemon_restart() {
235 sub_daemon_stop
236 sleep 1
237 sub_daemon_start
240 sub_update_to_new_version
242 case "$1" in
243 start) sub_daemon_start;;
244 stop) sub_daemon_stop;;
245 store) STOP_WITH_STORE="Yes" STORE_ALSA="Yes" STORE_DSP="Yes" sub_daemon_store;;
246 restore) sub_daemon_restore;;
247 restart) sub_daemon_restart;;
248 *) echo "usage: $0 {start|stop|store|restore|restart}"
249 esac
251 exit 0