2 # alsa-emu10k1d v0.5 RC1 (GPL3) by 3ED <krzysztof1987@gamil.com>
6 .
/etc
/conf.d
/alsa-emu10k1d
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
() {
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"
35 echo -n "Turn off any audio programs and speakers.. [enter to continue]"
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 #---------------------------------------------------------------------------
47 #---------------------------------------------------------------------------
49 if [ "$1" = "0" ]; then
57 [ -f "/tmp/.lo10k1.lock" ] ||
touch /tmp
/.lo10k1.lock ||
return 1
61 #-------------------------------------------------------------------------------
63 #-------------------------------------------------------------------------------
64 sub_store_master_mixer
() {
65 local OPH
="`amixer get Master`" OPH_MODE
=0 L
="" R
=""
69 if [ $OPH_MODE = 1 ] && [ "${LINE:0:5}" = "Mono:" ]; then
70 L
="`expr "$LINE" : ".
*Playback
[0-9]* \
[\
([0-9]*%\
).
*"`" ||
return 1
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
91 [ -z "$L" ] && return 1
93 echo $L $R > "$MASTER_STATE"
96 /usr
/bin
/lo10k1
--store "$DSP_STATE" ||
return 1
99 /usr
/sbin
/alsactl
$ALSA_ARGS --file "$ASOUND_STATE" store ||
return 1
103 #-------------------------------------------------------------------------------
104 # Restoring functions
105 #-------------------------------------------------------------------------------
107 test -f "/tmp/.lo10k1.lock" && return 0
110 if [ -f "$DSP_STATE" ]; then
111 /usr
/bin
/lo10k1
--restore "$DSP_STATE"
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
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?"
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."
129 *) init_
$INIT_NAME &> /dev
/null ||
return 1
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
150 #-------------------------------------------------------------------------------
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
160 sub_daemon_store_master_mixer
() {
161 if [[ "$STORE_MASTER_MIXER" =~
[Yy
] ]]
163 stat_busy
"Saving ALSA Master Mixer"
164 sub_store_master_mixer
168 sub_daemon_store_alsa
() {
169 if [[ "$STORE_ALSA" =~
[Yy
] ]]; then
170 stat_busy
"Saving ALSA Levels"
174 sub_daemon_store_master_mixer
177 sub_daemon_store_dsp
() {
178 if [[ $STORE_DSP =~
[Yy
] ]]; then
179 stat_busy
"Saving ALSA DSP Levels"
181 sub_stat_return $?
&& sub_lock_touch
186 #-------------------------------------------------------------------------------
188 #-------------------------------------------------------------------------------
190 if [[ "$STOP_WITH_STORE" =~
[Yy
] ]]; then
191 sub_daemon_store_alsa
194 sub_daemon_store_master_mixer
197 sub_daemon_mute_master_mixer
199 sub_daemon_restore_master_mixer
() {
200 if [[ "$STORE_MASTER_MIXER" =~
[Yy
] ]]
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
208 sub_daemon_restore
(){
209 stat_busy
"Restoring ALSA DSP Levels"
211 sub_stat_return $?
&& sub_lock_touch
213 stat_busy
"Restoring ALSA Levels"
217 sub_daemon_restore_master_mixer
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
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
() {
240 sub_update_to_new_version
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}"