ALT Linux Sisyphus discussions
 help / color / mirror / Atom feed
* [sisyphus] I: sound-scripts-0.2
@ 2003-11-12 12:46 Michael Shigorin
  2003-11-22  7:55 ` [sisyphus] " Michael Shigorin
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Shigorin @ 2003-11-12 12:46 UTC (permalink / raw)
  To: sisyphus; +Cc: vsu, darkstar, rider, ab


[-- Attachment #1.1: Type: text/plain, Size: 973 bytes --]

	Здравствуйте.
Прилагается попытка зафиксить sound-scripts хотя бы немного.

Ее надо проверить на нормальную отработку ситуации:

- одна звуковая карта (точнее, один драйвер);
- alsa или oss;
- наличие/отсутствие /etc/asound.state или /etc/.aumixrc, соотв.

Ожиаемый эффект:

- инициализируется указанный для sound-slot-0 драйвер;
- при отсутствии сохраненных значений уровней выставляются
  более-менее разумные;
- при наличии сохраненных значений уровней они применяются,
  по возможности используя alsactl (alsa-utils) для микшера alsa.

---

* Wed Nov 12 2003 Michael Shigorin <mike@altlinux.ru> 0.2-alt1
- fixed #1049, #1711 -- introduced initial specific ALSA support
  (modified patch by Dmitry Vukolov <dvukol rosmail ru>):
  * alsactl save/restore;
  * if /etc/asound.state is absent, initialize the mixer with
    non-zero values and unmuted channels.
- added TODO

-- 
 ---- WBR, Michael Shigorin <mike@altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/

[-- Attachment #1.2: sound --]
[-- Type: text/plain, Size: 3813 bytes --]

#!/bin/sh
# $Id: sound,v 1.14 2003/10/08 15:03:12 ldv Exp $
#
# sound:   This shell script launch the sound on your system.
#
# chkconfig: 2345 30 70
# description: This shell script launch the sound on your system.
# halt: yes

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

PKLVL=
SOUND_ALSA=

ChangePrintk()
{
	[ -n "$PKLVL" ] || PKLVL=`sed 's/^\(.\).*/\1/' < /proc/sys/kernel/printk`
	sysctl -w kernel.printk=0
}
	
exit_handler()
{
	local rc=$?
	trap - EXIT
	[ -z "$PKLVL" ] || sysctl -w "kernel.printk=$PKLVL"
	exit $rc
}

trap exit_handler SIGHUP SIGPIPE SIGINT SIGQUIT SIGTERM EXIT

LOCKFILE=/var/lock/subsys/sound

AUMIX=
[ ! -x /usr/bin/aumix ] || AUMIX=/usr/bin/aumix
[ ! -x /bin/aumix-minimal ] || AUMIX=/bin/aumix-minimal
ALSACTL=
[ -x /usr/sbin/alsactl ] && ALSACTL=/usr/sbin/alsactl

TMP_ALSA_STATE=`mktemp -t alsa-state.XXXXXX`

LookupDevices()
{
	egrep -qs '(sparcaudio|sound)' /proc/devices
}

LoadModule()
{
	local phrase=$1 pattern=$2 m opt=
	[ -n "$3" ] && opt='-r'
	for m in `modprobe -c |egrep "^alias $pattern " |cut -d\  -f3`; do
		if [ -n "$m" ] && [ "$m" != off ]; then
			action "$phrase ($m):" modprobe "$opt" "$m"
			local rc=$?
			[ $rc -eq 0 ] || return $rc
		fi
	done
}

load_alsa()
{
	modprobe -c |egrep '^alias [^ ]+ snd-' |cut -d\  -f3 |\
		while read line; do
			L=1
			action "Starting ALSA sound driver $line:" modprobe $line
		done
	if [ -d /proc/asound ]; then
 		RETVAL=0 start_mixer alsa
	fi
}

start_alsa()
{
	[ -d /proc/asound ] || load_alsa
	[ -d /proc/asound ] && touch "$LOCKFILE"
}

unload_alsa()
{
	RETVAL=0 stop_mixer alsa;
	/sbin/lsmod |grep "^snd" |
		while read line; do
			/sbin/rmmod `echo $line |cut -d\  -f 1`
		done
	/sbin/rmmod soundcore 2>/dev/null
}

fix_alsa_levels()
{
	# provide sane default audio levels even with alsa
	alsactl -f $TMP_ALSA_STATE store
	# set volume to 67%
	subst 's/(value\w*\S*)\s* 0/\1 20/' $TMP_ALSA_STATE
	# unmute all channels
	subst 's/(value\w*\S*)\s* false/\1 true/' $TMP_ALSA_STATE
	action "Initializing ALSA mixer settings" alsactl -f $TMP_ALSA_STATE restore
	rm -f $TMP_ALSA_STATE
}

start_mixer()
{
	LookupDevices || return
	# ALSA
	if [ "$1" = "alsa" -a -n "$ALSACTL" ]; then
		if [ -r /etc/asound.state ]; then
			action "Loading ALSA mixer settings:" "$ALSACTL" restore
		else 
			fix_alsa_levels
			return 0
		fi
	elif [ -n "$AUMIX" ]; then
		if [ -s /etc/.aumixrc ]; then
			action "Loading OSS mixer settings:" "$AUMIX" -f /etc/.aumixrc -L
		else
			action "Initializing OSS mixer settings:" "$AUMIX" -v90 -w90 -c90
		fi
	fi
}

stop_mixer()
{
	LookupDevices || return
	if [ "$1" = "alsa" -a -n "$ALSACTL" ]; then
		action "Saving ALSA mixer settings:" "$ALSACTL" store
	elif [ -n "$AUMIX" ]; then
		action "Saving OSS mixer settings:" "$AUMIX" -f /etc/.aumixrc -S
	fi
}

start()
{
	ChangePrintk
	# if there is alsa driver configured load it and exit.
	# FIXME: we know it's wrong since there could be OSS too.
	# TODO: for now codepaths are extremely crappy :((
	start_alsa && exit
	RETVAL=0
	LoadModule "Loading sound module" 'sound[^ ]*' || RETVAL=1
	LoadModule "Loading midi module" midi
	start_mixer oss
	touch "$LOCKFILE"
}

stop()
{
	ChangePrintk
	if [ -d /proc/asound ]; then
		unload_alsa
		rm -f "$LOCKFILE"
		return
	fi
	if [ -d /proc/asound ]; then
		stop_mixer alsa
	else
		stop_mixer oss
	fi
	LoadModule "Unloading midi module" midi REMOVE
	LoadModule "Unloading sound module" 'sound[^ ]*' REMOVE
	rm -f "$LOCKFILE"
}

restart()
{
	stop
	start
}

case $1 in
	start)
		start
		;;
	stop|condstop)
		stop
		;;
	restart|reload)
		restart
		;;
	status)
		if lsmod |egrep -qs '^(sound|snd)'; then
			echo "Sound modules loaded"
		fi
		;;
	condrestart|condreload)
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|status}"
		exit 1
esac

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [sisyphus] Re: I: sound-scripts-0.2
  2003-11-12 12:46 [sisyphus] I: sound-scripts-0.2 Michael Shigorin
@ 2003-11-22  7:55 ` Michael Shigorin
  2003-11-22 12:03   ` Alex Yustasov
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Shigorin @ 2003-11-22  7:55 UTC (permalink / raw)
  To: sisyphus; +Cc: vsu, darkstar, rider, ab

[-- Attachment #1: Type: text/plain, Size: 266 bytes --]

On Wed, Nov 12, 2003 at 02:46:45PM +0200, Michael Shigorin wrote:
> Прилагается попытка зафиксить sound-scripts хотя бы немного.

Все хорошо, все плохо или всем не до?

-- 
 ---- WBR, Michael Shigorin <mike@altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [sisyphus] Re: I: sound-scripts-0.2
  2003-11-22  7:55 ` [sisyphus] " Michael Shigorin
@ 2003-11-22 12:03   ` Alex Yustasov
  2003-11-22 12:12     ` Michael Shigorin
  2003-11-22 18:00     ` Michael Shigorin
  0 siblings, 2 replies; 11+ messages in thread
From: Alex Yustasov @ 2003-11-22 12:03 UTC (permalink / raw)
  To: sisyphus; +Cc: vsu, darkstar, rider, ab

On Sat, Nov 22, 2003 at 09:55:58AM +0200, Michael Shigorin wrote:
> On Wed, Nov 12, 2003 at 02:46:45PM +0200, Michael Shigorin wrote:
> > Прилагается попытка зафиксить sound-scripts хотя бы немного.
> 
> Все хорошо, все плохо или всем не до?
В случае OSS (или ALSA и отсутствия alsactl) хорошо.
В случае ALSA кажется не отрабатывает fix_alsa_levels.
До subst и после файл $TMP_ALSA_STATE одинаковый.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [sisyphus] Re: I: sound-scripts-0.2
  2003-11-22 12:03   ` Alex Yustasov
@ 2003-11-22 12:12     ` Michael Shigorin
  2003-11-22 18:00     ` Michael Shigorin
  1 sibling, 0 replies; 11+ messages in thread
From: Michael Shigorin @ 2003-11-22 12:12 UTC (permalink / raw)
  To: sisyphus; +Cc: vsu, darkstar, rider, ab

On Sat, Nov 22, 2003 at 02:03:45PM +0200, Alex Yustasov wrote:
> > > Прилагается попытка зафиксить sound-scripts хотя бы немного.
> > Все хорошо, все плохо или всем не до?
> В случае OSS (или ALSA и отсутствия alsactl) хорошо.
> В случае ALSA кажется не отрабатывает fix_alsa_levels.
> До subst и после файл $TMP_ALSA_STATE одинаковый.

Гм.  Файлы не сравнивал, проверял по результату (основные каналы
микшера).

-- 
 ---- WBR, Michael Shigorin <mike@altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [sisyphus] Re: I: sound-scripts-0.2
  2003-11-22 12:03   ` Alex Yustasov
  2003-11-22 12:12     ` Michael Shigorin
@ 2003-11-22 18:00     ` Michael Shigorin
  2003-11-23  7:41       ` Andrey Rahmatullin
  1 sibling, 1 reply; 11+ messages in thread
From: Michael Shigorin @ 2003-11-22 18:00 UTC (permalink / raw)
  To: sisyphus; +Cc: vsu, darkstar, rider, ab

[-- Attachment #1: Type: text/plain, Size: 674 bytes --]

On Sat, Nov 22, 2003 at 02:03:45PM +0200, Alex Yustasov wrote:
> > > Прилагается попытка зафиксить sound-scripts хотя бы немного.
> > Все хорошо, все плохо или всем не до?
> В случае OSS (или ALSA и отсутствия alsactl) хорошо.
> В случае ALSA кажется не отрабатывает fix_alsa_levels.
> До subst и после файл $TMP_ALSA_STATE одинаковый.

О, спасибо за правки.

Прилагаю текущий /etc/init.d/sound; пакеты можно забрать здесь:
ftp://ftp.altlinux.org/pub/people/mike/SRPMS/sound-scripts-0.3-alt1.src.rpm
ftp://ftp.altlinux.org/pub/people/mike/RPMS/sound-scripts-0.3-alt1.i586.rpm

-- 
 ---- WBR, Michael Shigorin <mike@altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [sisyphus] Re: I: sound-scripts-0.2
  2003-11-22 18:00     ` Michael Shigorin
@ 2003-11-23  7:41       ` Andrey Rahmatullin
  2003-11-23 11:35         ` [sisyphus] ...0.31 (was: I: sound-scripts-0.2) Michael Shigorin
  0 siblings, 1 reply; 11+ messages in thread
From: Andrey Rahmatullin @ 2003-11-23  7:41 UTC (permalink / raw)
  To: sisyphus

[-- Attachment #1: Type: text/plain, Size: 1287 bytes --]

On Sat, Nov 22, 2003 at 08:00:06PM +0200, Michael Shigorin wrote:
> On Sat, Nov 22, 2003 at 02:03:45PM +0200, Alex Yustasov wrote:
> > > > Прилагается попытка зафиксить sound-scripts хотя бы немного.
> > > Все хорошо, все плохо или всем не до?
> > В случае OSS (или ALSA и отсутствия alsactl) хорошо.
> > В случае ALSA кажется не отрабатывает fix_alsa_levels.
> > До subst и после файл $TMP_ALSA_STATE одинаковый.
> 
> О, спасибо за правки.
> 
> Прилагаю текущий /etc/init.d/sound; пакеты можно забрать здесь:
> ftp://ftp.altlinux.org/pub/people/mike/SRPMS/sound-scripts-0.3-alt1.src.rpm
> ftp://ftp.altlinux.org/pub/people/mike/RPMS/sound-scripts-0.3-alt1.i586.rpm

# modprobe -c |egrep '^alias [^ ]+ snd-' |cut -d\  -f3
snd-als4000
snd-als4000

# modprobe -c |egrep '^alias [^ ]+ snd-'
alias sound-slot-0 snd-als4000
alias snd-card-0 snd-als4000

Предлагаю в конце строчки поиска модулей воткнуть |uniq
На всякий случай. В принципе, всё работает, но сообщения некрасивые при
старте ;-)

# service sound start
Starting ALSA sound driver snd-als4000:
Starting ALSA sound driver snd-als4000:
Loading ALSA mixer settings:

-- 
> [...] большие списки с URL'ами пакетов теряют свою ценность. 
Разумеется, теряют.
Когда сообщество решит, что совсем потеряли, мы их уберём.
		-- ldv in devel@

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [sisyphus] ...0.31 (was: I: sound-scripts-0.2)
  2003-11-23  7:41       ` Andrey Rahmatullin
@ 2003-11-23 11:35         ` Michael Shigorin
  2003-11-23 11:49           ` Sergey Vlasov
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Shigorin @ 2003-11-23 11:35 UTC (permalink / raw)
  To: sisyphus; +Cc: darkstar


[-- Attachment #1.1: Type: text/plain, Size: 617 bytes --]

On Sun, Nov 23, 2003 at 12:41:06PM +0500, Andrey Rahmatullin wrote:
> # modprobe -c |egrep '^alias [^ ]+ snd-'
> alias sound-slot-0 snd-als4000
> alias snd-card-0 snd-als4000
> Предлагаю в конце строчки поиска модулей воткнуть |uniq

Тогда |sort |uniq уже. :-)

Хотя вроде сейчас дубли туда не пишут, закладываться на это
действительно не стоит.

0.31 attached.

Если всем понравится -- до конца недели делаю пакет и шлю в
Sisyphus.

2 darkstar: проверь и если ничего не сломано -- в compact. 
Есть серьезные багфиксы.

-- 
 ---- WBR, Michael Shigorin <mike@altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/

[-- Attachment #1.2: sound --]
[-- Type: text/plain, Size: 3869 bytes --]

#!/bin/sh
# $Id: sound,v 1.14 2003/10/08 15:03:12 ldv Exp $
#
# sound:   This shell script launch the sound on your system.
#
# chkconfig: 2345 30 70
# description: This shell script launch the sound on your system.
# halt: yes

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

PKLVL=
SOUND_ALSA=

ChangePrintk()
{
	[ -n "$PKLVL" ] || PKLVL=`sed 's/^\(.\).*/\1/' < /proc/sys/kernel/printk`
	sysctl -w kernel.printk=0
}
	
exit_handler()
{
	local rc=$?
	trap - EXIT
	[ -z "$PKLVL" ] || sysctl -w "kernel.printk=$PKLVL"
	exit $rc
}

trap exit_handler SIGHUP SIGPIPE SIGINT SIGQUIT SIGTERM EXIT

LOCKFILE=/var/lock/subsys/sound

AUMIX=
[ ! -x /usr/bin/aumix ] || AUMIX=/usr/bin/aumix
[ ! -x /bin/aumix-minimal ] || AUMIX=/bin/aumix-minimal
ALSACTL=
[ -x /usr/sbin/alsactl ] && ALSACTL=/usr/sbin/alsactl

TMP_ALSA_STATE=`mktemp -t alsa-state.XXXXXX`

LookupDevices()
{
	egrep -qs '(sparcaudio|sound)' /proc/devices
}

LoadModule()
{
	local phrase=$1 pattern=$2 m opt=
	[ -n "$3" ] && opt='-r'
	for m in `modprobe -c |egrep "^alias $pattern " |cut -d\  -f3 |sort |uniq`; do
		if [ -n "$m" ] && [ "$m" != off ]; then
			action "$phrase ($m):" modprobe "$opt" "$m"
			local rc=$?
			[ $rc -eq 0 ] || return $rc
		fi
	done
}

load_alsa()
# redo with LoadModule?
{
	modprobe -c |egrep '^alias [^ ]+ snd-' |cut -d\  -f3 |sort |uniq\
		while read line; do
			L=1
			action "Starting ALSA sound driver $line:" modprobe $line
		done
	if [ -d /proc/asound ]; then
 		RETVAL=0 start_mixer alsa
	fi
}

start_alsa()
{
	[ -d /proc/asound ] || load_alsa
	[ -d /proc/asound ] && touch "$LOCKFILE"
}

unload_alsa()
{
	RETVAL=0 stop_mixer alsa;
	/sbin/lsmod |grep "^snd" |
		while read line; do
			/sbin/rmmod `echo $line |cut -d\  -f 1`
		done
	/sbin/rmmod soundcore 2>/dev/null
}

fix_alsa_levels()
{
	# provide sane default audio levels even with alsa
	alsactl -f $TMP_ALSA_STATE store
	# set volume to 67%
	subst 's/\(value\.*\w*\S*\)\s* 0/\1 20/' $TMP_ALSA_STATE
	# unmute all channels
	subst 's/\(value\.*\w*\S*\)\s* false/\1 true/' $TMP_ALSA_STATE
	action "Initializing ALSA mixer settings" alsactl -f $TMP_ALSA_STATE restore
	rm -f $TMP_ALSA_STATE
}

start_mixer()
{
	LookupDevices || return
	# ALSA
	if [ "$1" = "alsa" -a -n "$ALSACTL" ]; then
		if [ -r /etc/asound.state ]; then
			action "Loading ALSA mixer settings:" "$ALSACTL" restore
		else 
			fix_alsa_levels
			return 0
		fi
	elif [ -n "$AUMIX" ]; then
		if [ -s /etc/.aumixrc ]; then
			action "Loading OSS mixer settings:" "$AUMIX" -f /etc/.aumixrc -L
		else
			action "Initializing OSS mixer settings:" "$AUMIX" -v90 -w90 -c90
		fi
	fi
}

stop_mixer()
{
	LookupDevices || return
	if [ "$1" = "alsa" -a -n "$ALSACTL" ]; then
		action "Saving ALSA mixer settings:" "$ALSACTL" store
	elif [ -n "$AUMIX" ]; then
		action "Saving OSS mixer settings:" "$AUMIX" -f /etc/.aumixrc -S
	fi
}

start()
{
	ChangePrintk
	# if there is alsa driver configured load it and exit.
	# FIXME: we know it's wrong since there could be OSS too.
	# TODO: for now codepaths are extremely crappy :((
	start_alsa && exit
	RETVAL=0
	LoadModule "Loading sound module" 'sound[^ ]*' || RETVAL=1
	LoadModule "Loading midi module" midi
	start_mixer oss
	touch "$LOCKFILE"
}

stop()
{
	ChangePrintk
	if [ -d /proc/asound ]; then
		unload_alsa
		rm -f "$LOCKFILE"
		return
	fi
	if [ -d /proc/asound ]; then
		stop_mixer alsa
	else
		stop_mixer oss
	fi
	LoadModule "Unloading midi module" midi REMOVE
	LoadModule "Unloading sound module" 'sound[^ ]*' REMOVE
	rm -f "$LOCKFILE"
}

restart()
{
	stop
	start
}

case $1 in
	start)
		start
		;;
	stop|condstop)
		stop
		;;
	restart|reload)
		restart
		;;
	status)
		if lsmod |egrep -qs '^(sound|snd)'; then
			echo "Sound modules loaded"
		fi
		;;
	condrestart|condreload)
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|status}"
		exit 1
esac

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [sisyphus] ...0.31 (was: I: sound-scripts-0.2)
  2003-11-23 11:35         ` [sisyphus] ...0.31 (was: I: sound-scripts-0.2) Michael Shigorin
@ 2003-11-23 11:49           ` Sergey Vlasov
  2003-11-23 11:56             ` [sisyphus] " Michael Shigorin
  0 siblings, 1 reply; 11+ messages in thread
From: Sergey Vlasov @ 2003-11-23 11:49 UTC (permalink / raw)
  To: sisyphus; +Cc: darkstar

[-- Attachment #1: Type: text/plain, Size: 388 bytes --]

On Sun, Nov 23, 2003 at 01:35:46PM +0200, Michael Shigorin wrote:
> On Sun, Nov 23, 2003 at 12:41:06PM +0500, Andrey Rahmatullin wrote:
> > # modprobe -c |egrep '^alias [^ ]+ snd-'
> > alias sound-slot-0 snd-als4000
> > alias snd-card-0 snd-als4000
> > Предлагаю в конце строчки поиска модулей воткнуть |uniq
> 
> Тогда |sort |uniq уже. :-)

Опять sort???  Ходили же уже по этим граблям.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [sisyphus] Re: ...0.31 (was: I: sound-scripts-0.2)
  2003-11-23 11:49           ` Sergey Vlasov
@ 2003-11-23 11:56             ` Michael Shigorin
  2003-11-23 11:59               ` Sergey Vlasov
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Shigorin @ 2003-11-23 11:56 UTC (permalink / raw)
  To: sisyphus; +Cc: darkstar


[-- Attachment #1.1: Type: text/plain, Size: 577 bytes --]

On Sun, Nov 23, 2003 at 02:49:50PM +0300, Sergey Vlasov wrote:
> > > # modprobe -c |egrep '^alias [^ ]+ snd-'
> > > alias sound-slot-0 snd-als4000
> > > alias snd-card-0 snd-als4000
> > > Предлагаю в конце строчки поиска модулей воткнуть |uniq
> > Тогда |sort |uniq уже. :-)
> Опять sort???  Ходили же уже по этим граблям.

Точно.  #1802.  Вернул на место.

Тогда смысл от uniq будет только при отсутствии других алиасов
между этими -- т.е. опять же в части случаев... ну ладно.

-- 
 ---- WBR, Michael Shigorin <mike@altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/

[-- Attachment #1.2: sound --]
[-- Type: text/plain, Size: 3859 bytes --]

#!/bin/sh
# $Id: sound,v 1.14 2003/10/08 15:03:12 ldv Exp $
#
# sound:   This shell script launch the sound on your system.
#
# chkconfig: 2345 30 70
# description: This shell script launch the sound on your system.
# halt: yes

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

PKLVL=
SOUND_ALSA=

ChangePrintk()
{
	[ -n "$PKLVL" ] || PKLVL=`sed 's/^\(.\).*/\1/' < /proc/sys/kernel/printk`
	sysctl -w kernel.printk=0
}
	
exit_handler()
{
	local rc=$?
	trap - EXIT
	[ -z "$PKLVL" ] || sysctl -w "kernel.printk=$PKLVL"
	exit $rc
}

trap exit_handler SIGHUP SIGPIPE SIGINT SIGQUIT SIGTERM EXIT

LOCKFILE=/var/lock/subsys/sound

AUMIX=
[ ! -x /usr/bin/aumix ] || AUMIX=/usr/bin/aumix
[ ! -x /bin/aumix-minimal ] || AUMIX=/bin/aumix-minimal
ALSACTL=
[ -x /usr/sbin/alsactl ] && ALSACTL=/usr/sbin/alsactl

TMP_ALSA_STATE=`mktemp -t alsa-state.XXXXXX`

LookupDevices()
{
	egrep -qs '(sparcaudio|sound)' /proc/devices
}

LoadModule()
{
	local phrase=$1 pattern=$2 m opt=
	[ -n "$3" ] && opt='-r'
	for m in `modprobe -c |egrep "^alias $pattern " |cut -d\  -f3 |uniq`; do
		if [ -n "$m" ] && [ "$m" != off ]; then
			action "$phrase ($m):" modprobe "$opt" "$m"
			local rc=$?
			[ $rc -eq 0 ] || return $rc
		fi
	done
}

load_alsa()
# redo with LoadModule?
{
	modprobe -c |egrep '^alias [^ ]+ snd-' |cut -d\  -f3 |uniq |\
		while read line; do
			L=1
			action "Starting ALSA sound driver $line:" modprobe $line
		done
	if [ -d /proc/asound ]; then
 		RETVAL=0 start_mixer alsa
	fi
}

start_alsa()
{
	[ -d /proc/asound ] || load_alsa
	[ -d /proc/asound ] && touch "$LOCKFILE"
}

unload_alsa()
{
	RETVAL=0 stop_mixer alsa;
	/sbin/lsmod |grep "^snd" |
		while read line; do
			/sbin/rmmod `echo $line |cut -d\  -f 1`
		done
	/sbin/rmmod soundcore 2>/dev/null
}

fix_alsa_levels()
{
	# provide sane default audio levels even with alsa
	alsactl -f $TMP_ALSA_STATE store
	# set volume to 67%
	subst 's/\(value\.*\w*\S*\)\s* 0/\1 20/' $TMP_ALSA_STATE
	# unmute all channels
	subst 's/\(value\.*\w*\S*\)\s* false/\1 true/' $TMP_ALSA_STATE
	action "Initializing ALSA mixer settings" alsactl -f $TMP_ALSA_STATE restore
	rm -f $TMP_ALSA_STATE
}

start_mixer()
{
	LookupDevices || return
	# ALSA
	if [ "$1" = "alsa" -a -n "$ALSACTL" ]; then
		if [ -r /etc/asound.state ]; then
			action "Loading ALSA mixer settings:" "$ALSACTL" restore
		else 
			fix_alsa_levels
			return 0
		fi
	elif [ -n "$AUMIX" ]; then
		if [ -s /etc/.aumixrc ]; then
			action "Loading OSS mixer settings:" "$AUMIX" -f /etc/.aumixrc -L
		else
			action "Initializing OSS mixer settings:" "$AUMIX" -v90 -w90 -c90
		fi
	fi
}

stop_mixer()
{
	LookupDevices || return
	if [ "$1" = "alsa" -a -n "$ALSACTL" ]; then
		action "Saving ALSA mixer settings:" "$ALSACTL" store
	elif [ -n "$AUMIX" ]; then
		action "Saving OSS mixer settings:" "$AUMIX" -f /etc/.aumixrc -S
	fi
}

start()
{
	ChangePrintk
	# if there is alsa driver configured load it and exit.
	# FIXME: we know it's wrong since there could be OSS too.
	# TODO: for now codepaths are extremely crappy :((
	start_alsa && exit
	RETVAL=0
	LoadModule "Loading sound module" 'sound[^ ]*' || RETVAL=1
	LoadModule "Loading midi module" midi
	start_mixer oss
	touch "$LOCKFILE"
}

stop()
{
	ChangePrintk
	if [ -d /proc/asound ]; then
		unload_alsa
		rm -f "$LOCKFILE"
		return
	fi
	if [ -d /proc/asound ]; then
		stop_mixer alsa
	else
		stop_mixer oss
	fi
	LoadModule "Unloading midi module" midi REMOVE
	LoadModule "Unloading sound module" 'sound[^ ]*' REMOVE
	rm -f "$LOCKFILE"
}

restart()
{
	stop
	start
}

case $1 in
	start)
		start
		;;
	stop|condstop)
		stop
		;;
	restart|reload)
		restart
		;;
	status)
		if lsmod |egrep -qs '^(sound|snd)'; then
			echo "Sound modules loaded"
		fi
		;;
	condrestart|condreload)
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|status}"
		exit 1
esac

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [sisyphus] Re: ...0.31 (was: I: sound-scripts-0.2)
  2003-11-23 11:56             ` [sisyphus] " Michael Shigorin
@ 2003-11-23 11:59               ` Sergey Vlasov
  2003-11-23 19:37                 ` Michael Shigorin
  0 siblings, 1 reply; 11+ messages in thread
From: Sergey Vlasov @ 2003-11-23 11:59 UTC (permalink / raw)
  To: sisyphus; +Cc: darkstar

[-- Attachment #1: Type: text/plain, Size: 663 bytes --]

On Sun, Nov 23, 2003 at 01:56:58PM +0200, Michael Shigorin wrote:
> On Sun, Nov 23, 2003 at 02:49:50PM +0300, Sergey Vlasov wrote:
> > > > # modprobe -c |egrep '^alias [^ ]+ snd-'
> > > > alias sound-slot-0 snd-als4000
> > > > alias snd-card-0 snd-als4000
> > > > Предлагаю в конце строчки поиска модулей воткнуть |uniq
> > > Тогда |sort |uniq уже. :-)
> > Опять sort???  Ходили же уже по этим граблям.
> 
> Точно.  #1802.  Вернул на место.
> 
> Тогда смысл от uniq будет только при отсутствии других алиасов
> между этими -- т.е. опять же в части случаев... ну ладно.

Может быть, сделать его как в mkinitrd (TestedModules и
соответствующий кусок в FindModule)?

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [sisyphus] Re: ...0.31 (was: I: sound-scripts-0.2)
  2003-11-23 11:59               ` Sergey Vlasov
@ 2003-11-23 19:37                 ` Michael Shigorin
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Shigorin @ 2003-11-23 19:37 UTC (permalink / raw)
  To: sisyphus; +Cc: vsu

[-- Attachment #1: Type: text/plain, Size: 654 bytes --]

On Sun, Nov 23, 2003 at 02:59:16PM +0300, Sergey Vlasov wrote:
> > > > > Предлагаю в конце строчки поиска модулей воткнуть |uniq
> > > > Тогда |sort |uniq уже. :-)
> > > Опять sort???  Ходили же уже по этим граблям.
> > Точно.  #1802.  Вернул на место.
> > Тогда смысл от uniq будет только при отсутствии других алиасов
> > между этими -- т.е. опять же в части случаев... ну ладно.
> Может быть, сделать его как в mkinitrd (TestedModules и
> соответствующий кусок в FindModule)?

Пошел рассматривать.

...зародилась идиотская мысль:

. /sbin/mkinitrd

;^)

-- 
 ---- WBR, Michael Shigorin <mike@altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-11-23 19:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-12 12:46 [sisyphus] I: sound-scripts-0.2 Michael Shigorin
2003-11-22  7:55 ` [sisyphus] " Michael Shigorin
2003-11-22 12:03   ` Alex Yustasov
2003-11-22 12:12     ` Michael Shigorin
2003-11-22 18:00     ` Michael Shigorin
2003-11-23  7:41       ` Andrey Rahmatullin
2003-11-23 11:35         ` [sisyphus] ...0.31 (was: I: sound-scripts-0.2) Michael Shigorin
2003-11-23 11:49           ` Sergey Vlasov
2003-11-23 11:56             ` [sisyphus] " Michael Shigorin
2003-11-23 11:59               ` Sergey Vlasov
2003-11-23 19:37                 ` Michael Shigorin

ALT Linux Sisyphus discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \
		sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru
	public-inbox-index sisyphus

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.sisyphus


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git