tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Boot time configuration of audio devices



Introduce /etc/audio.conf for configuring audio hardware parameters
at boot.

This provides a file which can be used to load audiocfg(1) settings
at boot-time if audiocfg=YES is set in /etc/rc.conf.

This is useful if you want to change the hardware format of an audio
device at boot, for example, to enable or disable surround sound,
change sample rate, and so on. These settings are not exposed
and are not possible to change with /etc/mixerctl.conf.

/etc/audio.conf is read _before_ /etc/mixerctl.conf so that if the
default device is changed in /etc/audio.conf, mixerctl settings
will be applied to the correct device.

An example of an /etc/audio.conf:

# Configure first device to play CD audio
set 0 p slinear_le 16 2 44100
# Configure second device to play 5.1 surround sound
set 1 p slinear_le 16 5 48000
# Configure third device to record in mono
set 2 r slinear_le 16 1 44100
# Use second device as the default
default 1

These are identical to arguments to audiocfg(1).

Comments and suggestions welcome.
Index: etc/defaults/rc.conf
===================================================================
RCS file: /cvsroot/src/etc/defaults/rc.conf,v
retrieving revision 1.161
diff -u -r1.161 rc.conf
--- etc/defaults/rc.conf	10 Jan 2021 23:24:25 -0000	1.161
+++ etc/defaults/rc.conf	16 Apr 2021 12:06:49 -0000
@@ -363,6 +363,11 @@
 #
 tpctl=NO		tpctl_flags=""
 
+
+# Read audio hardware configuration from /etc/audio.conf
+#
+audiocfg=NO		audiocfg_flags=""
+
 # Mixer setting
 #
 mixerctl=NO		mixerctl_mixers=""	# "mixer0 mixer1" means saving
Index: etc/mtree/special
===================================================================
RCS file: /cvsroot/src/etc/mtree/special,v
retrieving revision 1.171
diff -u -r1.171 special
--- etc/mtree/special	26 Feb 2021 18:39:10 -0000	1.171
+++ etc/mtree/special	16 Apr 2021 12:06:50 -0000
@@ -198,6 +198,7 @@
 ./etc/rc.d/altqd		type=file mode=0555
 ./etc/rc.d/amd			type=file mode=0555
 ./etc/rc.d/apmd			type=file mode=0555
+./etc/rc.d/audiocfg		type=file mode=0555
 ./etc/rc.d/bluetooth		type=file mode=0555
 ./etc/rc.d/bootconf.sh		type=file mode=0555
 ./etc/rc.d/bootparams		type=file mode=0555
Index: etc/rc.d/Makefile
===================================================================
RCS file: /cvsroot/src/etc/rc.d/Makefile,v
retrieving revision 1.111
diff -u -r1.111 Makefile
--- etc/rc.d/Makefile	26 Jan 2021 15:08:02 -0000	1.111
+++ etc/rc.d/Makefile	16 Apr 2021 12:06:50 -0000
@@ -15,8 +15,8 @@
 
 CONFIGFILES=\
 		CRITLOCALMOUNTED DAEMON DISKS LOGIN NETWORKING SERVERS \
-		accounting altqd amd apmd automount automountd autounmountd \
-		bluetooth bootconf.sh bootparams \
+		accounting altqd amd apmd audiocfg automount automountd \
+		autounmountd bluetooth bootconf.sh bootparams \
 		ccd cgd clearcritlocal cleartmp cron \
 		devpubd dhcpcd dhcpd dhcpd6 dhcrelay dmesg \
 		downinterfaces \
Index: etc/rc.d/audiocfg
===================================================================
RCS file: etc/rc.d/audiocfg
diff -N etc/rc.d/audiocfg
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ etc/rc.d/audiocfg	16 Apr 2021 12:06:50 -0000
@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# $NetBSD$
+#
+
+# PROVIDE: audiocfg
+# REQUIRE: mountcritremote
+
+$_rc_subr_loaded . /etc/rc.subr
+
+name="audiocfg"
+rcvar=$name
+start_cmd="audiocfg_start"
+
+audiocfg_start()
+{
+	if [ -r /etc/audio.conf ]; then
+		echo "Setting audiocfg options..."
+		while read setting; do
+			case "$setting" in
+			\#*|"")
+				continue
+				;;
+			esac
+			/usr/bin/audiocfg $setting
+		done < /etc/audio.conf
+	fi
+}
+
+load_rc_config $name
+run_rc_command "$1"
Index: etc/rc.d/mixerctl
===================================================================
RCS file: /cvsroot/src/etc/rc.d/mixerctl,v
retrieving revision 1.10
diff -u -r1.10 mixerctl
--- etc/rc.d/mixerctl	16 Mar 2007 22:30:22 -0000	1.10
+++ etc/rc.d/mixerctl	16 Apr 2021 12:06:50 -0000
@@ -4,7 +4,7 @@
 #
 
 # PROVIDE: mixerctl
-# REQUIRE: mountcritremote
+# REQUIRE: mountcritremote audiocfg
 # KEYWORD: shutdown
 
 $_rc_subr_loaded . /etc/rc.subr
Index: distrib/sets/lists/etc/mi
===================================================================
RCS file: /cvsroot/src/distrib/sets/lists/etc/mi,v
retrieving revision 1.265
diff -u -r1.265 mi
--- distrib/sets/lists/etc/mi	26 Jan 2021 13:31:19 -0000	1.265
+++ distrib/sets/lists/etc/mi	16 Apr 2021 12:06:50 -0000
@@ -187,6 +187,7 @@
 ./etc/rc.d/altqd				etc-router-rc
 ./etc/rc.d/amd					etc-amd-rc
 ./etc/rc.d/apmd					etc-sys-rc
+./etc/rc.d/audiocfg				etc-sys-rc
 ./etc/rc.d/automount				etc-sys-rc
 ./etc/rc.d/automountd				etc-sys-rc
 ./etc/rc.d/autounmountd				etc-sys-rc
Index: distrib/sets/lists/man/mi
===================================================================
RCS file: /cvsroot/src/distrib/sets/lists/man/mi,v
retrieving revision 1.1717
diff -u -r1.1717 mi
--- distrib/sets/lists/man/mi	1 Apr 2021 00:03:01 -0000	1.1717
+++ distrib/sets/lists/man/mi	16 Apr 2021 12:06:50 -0000
@@ -2126,6 +2126,7 @@
 ./usr/share/man/cat5/amd.conf.0			man-amd-catman		.cat
 ./usr/share/man/cat5/ar.0			man-sys-catman		.cat
 ./usr/share/man/cat5/atf-formats.0		man-atf-catman		.cat,atf
+./usr/share/man/cat5/audio.conf.0		man-audio-catman	.cat
 ./usr/share/man/cat5/audit-packages.conf.0	man-obsolete		obsolete
 ./usr/share/man/cat5/auto_master.0		man-sysutil-catman	.cat
 ./usr/share/man/cat5/autofs.0			man-sysutil-catman	.cat
@@ -5276,6 +5277,7 @@
 ./usr/share/man/html5/amd.conf.html		man-amd-htmlman		html
 ./usr/share/man/html5/ar.html			man-sys-htmlman		html
 ./usr/share/man/html5/atf-formats.html		man-atf-htmlman		html,atf
+./usr/share/man/html5/audio.conf.html		man-audio-htmlman	html
 ./usr/share/man/html5/audit-packages.conf.html	man-obsolete		obsolete
 ./usr/share/man/html5/auto_master.html		man-sysutil-htmlman	html
 ./usr/share/man/html5/autofs.html		man-sysutil-htmlman	html
@@ -8358,6 +8360,7 @@
 ./usr/share/man/man5/amd.conf.5			man-amd-man		.man
 ./usr/share/man/man5/ar.5			man-sys-man		.man
 ./usr/share/man/man5/atf-formats.5		man-atf-man		.man,atf
+./usr/share/man/man5/audio.conf.5		man-audio-man		.man
 ./usr/share/man/man5/audit-packages.conf.5	man-obsolete		obsolete
 ./usr/share/man/man5/auto_master.5		man-sysutil-man		.man
 ./usr/share/man/man5/autofs.5			man-sysutil-man		.man
Index: share/man/man5/Makefile
===================================================================
RCS file: /cvsroot/src/share/man/man5/Makefile,v
retrieving revision 1.73
diff -u -r1.73 Makefile
--- share/man/man5/Makefile	13 Jul 2020 09:10:35 -0000	1.73
+++ share/man/man5/Makefile	16 Apr 2021 12:06:51 -0000
@@ -3,7 +3,7 @@
 
 # missing: dump.5 plot.5
 
-MAN=	a.out.5 acct.5 ar.5 autofs.5 boot.cfg.5 \
+MAN=	a.out.5 acct.5 ar.5 autofs.5 audio.conf.5 boot.cfg.5 \
 	capfile.5 changelist.5 core.5 daily.5 disktab.5 elf.5 \
 	ethers.5 floppytab.5 forward.5 \
 	fs.5 fstab.5 genassym.cf.5 gpio.conf.5 group.5 hesiod.conf.5 \
Index: share/man/man5/audio.conf.5
===================================================================
RCS file: share/man/man5/audio.conf.5
diff -N share/man/man5/audio.conf.5
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ share/man/man5/audio.conf.5	16 Apr 2021 12:06:51 -0000
@@ -0,0 +1,72 @@
+.\"
+.\" Copyright (c) 2021 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Nia Alarie.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd April 16, 2021
+.Dt AUDIO.CONF 5
+.Os
+.Sh NAME
+.Nm audio.conf
+.Nd audio device configuration file
+.Sh SYNOPSIS
+.Nm
+.Sh DESCRIPTION
+The
+.Pa /etc/audio.conf
+file consists of
+.Xr audiocfg 1
+arguments to configure at boot time.
+.Pp
+Set
+.Sy audiocfg
+to YES in
+.Xr rc.conf 5
+to read the settings at boot time.
+.Sh FILES
+.Bl -tag -width /etc/audio.conf -compact
+.It Pa /etc/audio.conf
+.El
+.Sh EXAMPLES
+.Bd -literal
+# Configure first device to play CD audio
+set 0 p slinear_le 16 2 44100
+# Configure second device to play 5.1 surround sound
+set 1 p slinear_le 16 5 48000
+# Configure third device to record in mono
+set 2 r slinear_le 16 1 44100
+# Use second device as the default
+default 1
+.Ed
+.Sh SEE ALSO
+.Xr audiocfg 1 ,
+.Xr mixerctl.conf 5 ,
+.Xr rc.conf 5
+.Sh HISTORY
+The
+.Nm
+configuration file first appeared in
+.Nx 10.0 .
Index: share/man/man5/mixerctl.conf.5
===================================================================
RCS file: /cvsroot/src/share/man/man5/mixerctl.conf.5,v
retrieving revision 1.7
diff -u -r1.7 mixerctl.conf.5
--- share/man/man5/mixerctl.conf.5	3 Jul 2017 21:30:59 -0000	1.7
+++ share/man/man5/mixerctl.conf.5	16 Apr 2021 12:06:51 -0000
@@ -106,6 +106,7 @@
 .Ed
 .Sh SEE ALSO
 .Xr mixerctl 1 ,
+.Xr audio.conf 5 ,
 .Xr rc.conf 5
 .Sh HISTORY
 The
Index: share/man/man5/rc.conf.5
===================================================================
RCS file: /cvsroot/src/share/man/man5/rc.conf.5,v
retrieving revision 1.190
diff -u -r1.190 rc.conf.5
--- share/man/man5/rc.conf.5	15 Jan 2021 15:18:32 -0000	1.190
+++ share/man/man5/rc.conf.5	16 Apr 2021 12:06:51 -0000
@@ -55,7 +55,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd September 11, 2020
+.Dd April 16, 2021
 .Dt RC.CONF 5
 .Os
 .Sh NAME
@@ -426,6 +426,11 @@
 Requires
 .Pa /var/account/acct
 to exist.
+.It Sy audiocfg
+Boolean value.
+Read
+.Xr audio.conf 5
+for audio device configuration.
 .It Sy clear_tmp
 Boolean value.
 Clear


Home | Main Index | Thread Index | Old Index