CVS commit: src/usr.bin/audiocfg

2023-04-01 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Apr  1 12:41:02 UTC 2023

Modified Files:
src/usr.bin/audiocfg: main.c

Log Message:
Also report precision from hwinfo.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/main.c
diff -u src/usr.bin/audiocfg/main.c:1.16 src/usr.bin/audiocfg/main.c:1.17
--- src/usr.bin/audiocfg/main.c:1.16	Sat Aug 24 07:39:42 2019
+++ src/usr.bin/audiocfg/main.c	Sat Apr  1 12:41:02 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.16 2019/08/24 07:39:42 isaki Exp $ */
+/* $NetBSD: main.c,v 1.17 2023/04/01 12:41:02 mlelstv Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -91,7 +91,8 @@ print_audiodev(struct audiodev *adev, in
 	printf("\n");
 	printf("   playback: ");
 	if ((adev->hwinfo.mode & AUMODE_PLAY)) {
-		printf("%uch, %uHz\n",
+		printf("%u, %uch, %uHz\n",
+		adev->hwinfo.play.precision,
 		adev->hwinfo.play.channels,
 		adev->hwinfo.play.sample_rate);
 	} else {
@@ -99,7 +100,8 @@ print_audiodev(struct audiodev *adev, in
 	}
 	printf("   record:   ");
 	if ((adev->hwinfo.mode & AUMODE_RECORD)) {
-		printf("%uch, %uHz\n",
+		printf("%u, %uch, %uHz\n",
+		adev->hwinfo.record.precision,
 		adev->hwinfo.record.channels,
 		adev->hwinfo.record.sample_rate);
 	} else {



CVS commit: src/usr.bin/audiocfg

2023-04-01 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Apr  1 12:41:02 UTC 2023

Modified Files:
src/usr.bin/audiocfg: main.c

Log Message:
Also report precision from hwinfo.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
At Sat, 24 Aug 2019 16:28:39 +1000,
matthew green wrote:
> > Log Message:
> > Use device unit number for index.
> > The index number was too confusing such as
> >  0: [ ] audio1 @ wss0
> >  1: [*] audio0 @ yds0
> > in my PC for example.  Here is new format:
> >  [*] audio0 @ yds0
> >  [ ] audio1 @ wss0
> > In this style, devices are always listed in order of unit number
> > and 0 always means audio0, 1 always means audio1.
> 
> this change gives me pause.
> 
> it seems to be a kind-of "cf_unit" abuse to me.  eg, if
> i configure or usb-plug a lot, such that i only end up
> with just "audio10" and "audio23" attached, the index
> doesn't match the cf_unit.

The index may not have been good name in my change.
I intended to type "audiocfg test 23" for audio23 regardless of
current total number of available devices.
I wanted to use device name like "audiocfg test audio23" at final.

> perhaps you can sort the audio devices based upon cf_unit,
> such that your original output would have the lines swapped
> except for the prefix number, and then your sanity will be
> saved for the normal use-case.
> 
> at the very least, please restore the previous output
> format as i've used it in at least one script and perhaps
> others hvae as well.  please consider that, as a general
> rule, tool output is likely to be scraped and changing it
> may break things, so formatting changes should be avoided
> if possible.

It's my wrong.  I reverted these changes.
Thank you for pointing out.
---
Tetsuya Isaki 


CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 07:39:42 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c audiodev.h main.c

Log Message:
Revert about index number changes.  It breaks its usage and output format.
Pointed out by mrg@.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/audiocfg/audiodev.h
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/audiodev.c
diff -u src/usr.bin/audiocfg/audiodev.c:1.14 src/usr.bin/audiocfg/audiodev.c:1.15
--- src/usr.bin/audiocfg/audiodev.c:1.14	Sat Aug 24 06:32:25 2019
+++ src/usr.bin/audiocfg/audiodev.c	Sat Aug 24 07:39:42 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.14 2019/08/24 06:32:25 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.15 2019/08/24 07:39:42 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -49,7 +49,6 @@ static int audiodev_test_chmask(struct a
 
 static TAILQ_HEAD(audiodevhead, audiodev) audiodevlist =
 TAILQ_HEAD_INITIALIZER(audiodevlist);
-static unsigned int maxunit;
 
 static int
 audiodev_getinfo(struct audiodev *adev)
@@ -138,9 +137,6 @@ audiodev_add(const char *pdev, const cha
 
 	TAILQ_INSERT_TAIL(, adev, next);
 
-	if (unit > maxunit)
-		maxunit = unit;
-
 	return 0;
 }
 
@@ -182,22 +178,29 @@ audiodev_refresh(void)
 }
 
 unsigned int
-audiodev_maxunit(void)
+audiodev_count(void)
 {
-	return maxunit;
+	struct audiodev *adev;
+	unsigned int n;
+
+	n = 0;
+	TAILQ_FOREACH(adev, , next)
+		++n;
+
+	return n;
 }
 
-/*
- * Get audiodev corresponding to audio device.
- */
 struct audiodev *
 audiodev_get(unsigned int i)
 {
 	struct audiodev *adev;
+	unsigned int n;
 
+	n = 0;
 	TAILQ_FOREACH(adev, , next) {
-		if (i == adev->unit)
+		if (n == i)
 			return adev;
+		++n;
 	}
 
 	return NULL;

Index: src/usr.bin/audiocfg/audiodev.h
diff -u src/usr.bin/audiocfg/audiodev.h:1.8 src/usr.bin/audiocfg/audiodev.h:1.9
--- src/usr.bin/audiocfg/audiodev.h:1.8	Sat Aug 24 05:45:25 2019
+++ src/usr.bin/audiocfg/audiodev.h	Sat Aug 24 07:39:42 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.h,v 1.8 2019/08/24 05:45:25 isaki Exp $ */
+/* $NetBSD: audiodev.h,v 1.9 2019/08/24 07:39:42 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -60,7 +60,7 @@ struct audiodev {
 };
 
 int			audiodev_refresh(void);
-unsigned int		audiodev_maxunit(void);
+unsigned int		audiodev_count(void);
 struct audiodev *	audiodev_get(unsigned int);
 int			audiodev_set_default(struct audiodev *);
 int			audiodev_set_param(struct audiodev *, int,

Index: src/usr.bin/audiocfg/main.c
diff -u src/usr.bin/audiocfg/main.c:1.15 src/usr.bin/audiocfg/main.c:1.16
--- src/usr.bin/audiocfg/main.c:1.15	Sat Aug 24 06:11:10 2019
+++ src/usr.bin/audiocfg/main.c	Sat Aug 24 07:39:42 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.15 2019/08/24 06:11:10 isaki Exp $ */
+/* $NetBSD: main.c,v 1.16 2019/08/24 07:39:42 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -75,15 +75,15 @@ const char *encoding_names[] = {
 u_int encoding_max = __arraycount(encoding_names);
 
 static void
-print_audiodev(struct audiodev *adev)
+print_audiodev(struct audiodev *adev, int i)
 {
 	struct audiofmt *f;
 	int j;
 
 	assert(adev != NULL);
 
-	printf("[%c] %s @ %s: ",
-	adev->defaultdev ? '*' : ' ',
+	printf("%u: [%c] %s @ %s: ",
+	i, adev->defaultdev ? '*' : ' ',
 	adev->xname, adev->pxname);
 	printf("%s", adev->audio_device.name);
 	if (strlen(adev->audio_device.version) > 0)
@@ -142,28 +142,6 @@ print_audiodev(struct audiodev *adev)
 	}
 }
 
-/* Always return non-null adev, or exit */
-static struct audiodev *
-getadev_fromstr(const char *str)
-{
-	struct audiodev *adev;
-	unsigned int i;
-
-	if (*str < '0' || *str > '9')
-		usage();
-		/* NOTREACHED */
-	errno = 0;
-	i = strtoul(str, NULL, 10);
-	if (errno)
-		usage();
-		/* NOTREACHED */
-	adev = audiodev_get(i);
-	if (adev == NULL) {
-		errx(EXIT_FAILURE, "no such device");
-	}
-	return adev;
-}
-
 int
 main(int argc, char *argv[])
 {
@@ -184,16 +162,36 @@ main(int argc, char *argv[])
 		/* NOTREACHED */
 
 	if (strcmp(argv[1], "list") == 0 && argc == 2) {
-		n = audiodev_maxunit();
-		for (i = 0; i <= n; i++) {
-			adev = audiodev_get(i);
-			if (adev)
-print_audiodev(adev);
-		}
+		n = audiodev_count();
+		for (i = 0; i < n; i++)
+			print_audiodev(audiodev_get(i), i);
 	} else if (strcmp(argv[1], "list") == 0 && argc == 3) {
-		print_audiodev(getadev_fromstr(argv[2]));
+		if (*argv[2] < '0' || *argv[2] > '9')
+			usage();
+			/* NOTREACHED */
+		errno = 0;
+		i = strtoul(argv[2], NULL, 10);
+		if (errno)
+			usage();
+			/* NOTREACHED */
+		adev = audiodev_get(i);
+		if (adev == NULL) {
+			errx(EXIT_FAILURE, "no such device");
+		}
+		print_audiodev(adev, i);
 	} else if (strcmp(argv[1], "default") == 0 && argc == 3) {
-		adev = 

CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 07:39:42 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c audiodev.h main.c

Log Message:
Revert about index number changes.  It breaks its usage and output format.
Pointed out by mrg@.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/audiocfg/audiodev.h
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 06:32:25 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c

Log Message:
Create a waveform in hardware native sample rate which is more efficient.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/audiocfg/audiodev.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 06:32:25 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c

Log Message:
Create a waveform in hardware native sample rate which is more efficient.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/audiocfg/audiodev.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/audiodev.c
diff -u src/usr.bin/audiocfg/audiodev.c:1.13 src/usr.bin/audiocfg/audiodev.c:1.14
--- src/usr.bin/audiocfg/audiodev.c:1.13	Sat Aug 24 06:16:27 2019
+++ src/usr.bin/audiocfg/audiodev.c	Sat Aug 24 06:32:25 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.13 2019/08/24 06:16:27 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.14 2019/08/24 06:32:25 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -51,8 +51,6 @@ static TAILQ_HEAD(audiodevhead, audiodev
 TAILQ_HEAD_INITIALIZER(audiodevlist);
 static unsigned int maxunit;
 
-#define AUDIODEV_SAMPLE_RATE	44100
-
 static int
 audiodev_getinfo(struct audiodev *adev)
 {
@@ -308,7 +306,7 @@ audiodev_test(struct audiodev *adev)
 	}
 
 	AUDIO_INITINFO();
-	info.play.sample_rate = AUDIODEV_SAMPLE_RATE;
+	info.play.sample_rate = adev->hwinfo.play.sample_rate;
 	info.play.channels = adev->hwinfo.play.channels;
 	info.play.precision = 16;
 	info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
@@ -347,7 +345,7 @@ audiodev_test_chmask(struct audiodev *ad
 
 	rv = -1;
 
-	dtmf_new(, , info->play.sample_rate, 2,
+	dtmf_new(, , adev->hwinfo.play.sample_rate, 2,
 	adev->hwinfo.play.channels, chanmask, 350.0, 440.0);
 	if (buf == NULL) {
 		return -1;



re: CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread matthew green
"Tetsuya Isaki" writes:
> Module Name:  src
> Committed By: isaki
> Date: Sat Aug 24 05:45:25 UTC 2019
> 
> Modified Files:
>   src/usr.bin/audiocfg: audiodev.c audiodev.h main.c
> 
> Log Message:
> Use device unit number for index.
> The index number was too confusing such as
>  0: [ ] audio1 @ wss0
>  1: [*] audio0 @ yds0
> in my PC for example.  Here is new format:
>  [*] audio0 @ yds0
>  [ ] audio1 @ wss0
> In this style, devices are always listed in order of unit number
> and 0 always means audio0, 1 always means audio1.

this change gives me pause.

it seems to be a kind-of "cf_unit" abuse to me.  eg, if
i configure or usb-plug a lot, such that i only end up
with just "audio10" and "audio23" attached, the index
doesn't match the cf_unit.

perhaps you can sort the audio devices based upon cf_unit,
such that your original output would have the lines swapped
except for the prefix number, and then your sanity will be
saved for the normal use-case.

at the very least, please restore the previous output
format as i've used it in at least one script and perhaps
others hvae as well.  please consider that, as a general
rule, tool output is likely to be scraped and changing it
may break things, so formatting changes should be avoided
if possible.

thanks.


.mrg.


CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 06:16:27 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c

Log Message:
AUDIO_GETBUFINFO is more efficient for this purpose.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/audiocfg/audiodev.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 06:16:27 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c

Log Message:
AUDIO_GETBUFINFO is more efficient for this purpose.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/audiocfg/audiodev.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/audiodev.c
diff -u src/usr.bin/audiocfg/audiodev.c:1.12 src/usr.bin/audiocfg/audiodev.c:1.13
--- src/usr.bin/audiocfg/audiodev.c:1.12	Sat Aug 24 06:00:49 2019
+++ src/usr.bin/audiocfg/audiodev.c	Sat Aug 24 06:16:27 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.12 2019/08/24 06:00:49 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.13 2019/08/24 06:16:27 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -317,8 +317,8 @@ audiodev_test(struct audiodev *adev)
 		warn("ioctl AUDIO_SETINFO");
 		goto done;
 	}
-	if (ioctl(adev->fd, AUDIO_GETINFO, ) == -1) {
-		warn("ioctl AUDIO_GETINFO");
+	if (ioctl(adev->fd, AUDIO_GETBUFINFO, ) == -1) {
+		warn("ioctl AUDIO_GETBUFINFO");
 		goto done;
 	}
 



CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 06:13:01 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiocfg.1

Log Message:
Fix markup.  index of list command is optional.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/audiocfg/audiocfg.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 06:13:01 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiocfg.1

Log Message:
Fix markup.  index of list command is optional.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/audiocfg/audiocfg.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/audiocfg.1
diff -u src/usr.bin/audiocfg/audiocfg.1:1.5 src/usr.bin/audiocfg/audiocfg.1:1.6
--- src/usr.bin/audiocfg/audiocfg.1:1.5	Thu May  9 09:34:58 2019
+++ src/usr.bin/audiocfg/audiocfg.1	Sat Aug 24 06:13:01 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audiocfg.1,v 1.5 2019/05/09 09:34:58 wiz Exp $
+.\"	$NetBSD: audiocfg.1,v 1.6 2019/08/24 06:13:01 isaki Exp $
 .\"
 .\" Copyright (c) 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -36,6 +36,7 @@
 .Sh SYNOPSIS
 .Nm
 .Cm list
+.Op Ar index
 .Nm
 .Cm default
 .Ar index



CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 06:11:10 UTC 2019

Modified Files:
src/usr.bin/audiocfg: main.c

Log Message:
Make the same code that appears repeatedly a function.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/main.c
diff -u src/usr.bin/audiocfg/main.c:1.14 src/usr.bin/audiocfg/main.c:1.15
--- src/usr.bin/audiocfg/main.c:1.14	Sat Aug 24 06:00:49 2019
+++ src/usr.bin/audiocfg/main.c	Sat Aug 24 06:11:10 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.14 2019/08/24 06:00:49 isaki Exp $ */
+/* $NetBSD: main.c,v 1.15 2019/08/24 06:11:10 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -142,6 +142,28 @@ print_audiodev(struct audiodev *adev)
 	}
 }
 
+/* Always return non-null adev, or exit */
+static struct audiodev *
+getadev_fromstr(const char *str)
+{
+	struct audiodev *adev;
+	unsigned int i;
+
+	if (*str < '0' || *str > '9')
+		usage();
+		/* NOTREACHED */
+	errno = 0;
+	i = strtoul(str, NULL, 10);
+	if (errno)
+		usage();
+		/* NOTREACHED */
+	adev = audiodev_get(i);
+	if (adev == NULL) {
+		errx(EXIT_FAILURE, "no such device");
+	}
+	return adev;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -169,29 +191,9 @@ main(int argc, char *argv[])
 print_audiodev(adev);
 		}
 	} else if (strcmp(argv[1], "list") == 0 && argc == 3) {
-		errno = 0;
-		i = strtoul(argv[2], NULL, 10);
-		if (errno)
-			usage();
-			/* NOTREACHED */
-		adev = audiodev_get(i);
-		if (adev == NULL) {
-			errx(EXIT_FAILURE, "no such device");
-		}
-		print_audiodev(adev);
+		print_audiodev(getadev_fromstr(argv[2]));
 	} else if (strcmp(argv[1], "default") == 0 && argc == 3) {
-		if (*argv[2] < '0' || *argv[2] > '9')
-			usage();
-			/* NOTREACHED */
-		errno = 0;
-		i = strtoul(argv[2], NULL, 10);
-		if (errno)
-			usage();
-			/* NOTREACHED */
-		adev = audiodev_get(i);
-		if (adev == NULL) {
-			errx(EXIT_FAILURE, "no such device");
-		}
+		adev = getadev_fromstr(argv[2]);
 		printf("setting default audio device to %s\n", adev->xname);
 		if (audiodev_set_default(adev) == -1) {
 			errx(EXIT_FAILURE, "couldn't set default device");
@@ -199,19 +201,7 @@ main(int argc, char *argv[])
 	} else if (strcmp(argv[1], "set") == 0 && argc == 8) {
 		/* XXX bad commandline... */
 		/* audiocfg set  [p|r] */
-		if (*argv[2] < '0' || *argv[2] > '9')
-			usage();
-			/* NOTREACHED */
-		errno = 0;
-		i = strtoul(argv[2], NULL, 10);
-		if (errno)
-			usage();
-			/* NOTREACHED */
-		adev = audiodev_get(i);
-		if (adev == NULL) {
-			errx(EXIT_FAILURE, "no such device");
-		}
-
+		adev = getadev_fromstr(argv[2]);
 		mode = 0;
 		for (j = 0; j < strlen(argv[3]); j++) {
 			if (argv[3][j] == 'p')
@@ -243,18 +233,7 @@ main(int argc, char *argv[])
 			errx(EXIT_FAILURE, "couldn't set parameter");
 		}
 	} else if (strcmp(argv[1], "test") == 0 && argc == 3) {
-		if (*argv[2] < '0' || *argv[2] > '9')
-			usage();
-			/* NOTREACHED */
-		errno = 0;
-		i = strtoul(argv[2], NULL, 10);
-		if (errno)
-			usage();
-			/* NOTREACHED */
-		adev = audiodev_get(i);
-		if (adev == NULL) {
-			errx(EXIT_FAILURE, "no such device");
-		}
+		adev = getadev_fromstr(argv[2]);
 		print_audiodev(adev);
 		if (audiodev_test(adev) == -1)
 			return EXIT_FAILURE;



CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 06:11:10 UTC 2019

Modified Files:
src/usr.bin/audiocfg: main.c

Log Message:
Make the same code that appears repeatedly a function.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 06:00:49 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c dtmf.c main.c

Log Message:
Use err(3)/warn(3) instead of perror(3)/fprintf(stderr,...).
Use getprogname(3) for usage().


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/audiocfg/dtmf.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/audiocfg

2019-08-24 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 06:00:49 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c dtmf.c main.c

Log Message:
Use err(3)/warn(3) instead of perror(3)/fprintf(stderr,...).
Use getprogname(3) for usage().


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/audiocfg/dtmf.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/audiodev.c
diff -u src/usr.bin/audiocfg/audiodev.c:1.11 src/usr.bin/audiocfg/audiodev.c:1.12
--- src/usr.bin/audiocfg/audiodev.c:1.11	Sat Aug 24 05:51:06 2019
+++ src/usr.bin/audiocfg/audiodev.c	Sat Aug 24 06:00:49 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.11 2019/08/24 05:51:06 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.12 2019/08/24 06:00:49 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -31,6 +31,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -159,7 +160,7 @@ audiodev_refresh(void)
 
 	fd = open(DRVCTLDEV, O_RDONLY);
 	if (fd == -1) {
-		perror("open " DRVCTLDEV);
+		warn("open %s", DRVCTLDEV);
 		return -1;
 	}
 
@@ -173,7 +174,7 @@ audiodev_refresh(void)
 
 	error = drvctl_foreach(fd, "audio", audiodev_cb, NULL);
 	if (error == -1) {
-		perror("drvctl");
+		warnx("drvctl failed");
 		return -1;
 	}
 
@@ -227,19 +228,19 @@ audiodev_set_default(struct audiodev *ad
 	unlink(_PATH_MIXER);
 
 	if (symlink(audiopath, _PATH_AUDIO) == -1) {
-		perror("symlink " _PATH_AUDIO);
+		warn("symlink %s", _PATH_AUDIO);
 		return -1;
 	}
 	if (symlink(soundpath, _PATH_SOUND) == -1) {
-		perror("symlink " _PATH_SOUND);
+		warn("symlink %s", _PATH_SOUND);
 		return -1;
 	}
 	if (symlink(audioctlpath, _PATH_AUDIOCTL) == -1) {
-		perror("symlink " _PATH_AUDIOCTL);
+		warn("symlink %s", _PATH_AUDIOCTL);
 		return -1;
 	}
 	if (symlink(mixerpath, _PATH_MIXER) == -1) {
-		perror("symlink " _PATH_MIXER);
+		warn("symlink %s", _PATH_MIXER);
 		return -1;
 	}
 
@@ -262,8 +263,7 @@ audiodev_set_param(struct audiodev *adev
 			break;
 	}
 	if (enc >= encoding_max) {
-		fprintf(stderr, "unknown encoding name: %s\n", encname);
-		errno = EINVAL;
+		warnx("unknown encoding name: %s", encname);
 		return -1;
 	}
 
@@ -286,7 +286,7 @@ audiodev_set_param(struct audiodev *adev
 	printf("setting %s to %s:%u, %uch, %uHz\n",
 	adev->xname, encname, prec, ch, freq);
 	if (ioctl(adev->ctlfd, AUDIO_SETFORMAT, ) == -1) {
-		perror("ioctl AUDIO_SETFORMAT");
+		warn("ioctl AUDIO_SETFORMAT");
 		return -1;
 	}
 	return 0;
@@ -303,7 +303,7 @@ audiodev_test(struct audiodev *adev)
 
 	adev->fd = open(adev->path, O_WRONLY);
 	if (adev->fd == -1) {
-		perror("open");
+		warn("open %s", adev->path);
 		return -1;
 	}
 
@@ -314,11 +314,11 @@ audiodev_test(struct audiodev *adev)
 	info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
 	info.mode = AUMODE_PLAY;
 	if (ioctl(adev->fd, AUDIO_SETINFO, ) == -1) {
-		perror("ioctl AUDIO_SETINFO");
+		warn("ioctl AUDIO_SETINFO");
 		goto done;
 	}
 	if (ioctl(adev->fd, AUDIO_GETINFO, ) == -1) {
-		perror("ioctl AUDIO_GETINFO");
+		warn("ioctl AUDIO_GETINFO");
 		goto done;
 	}
 
@@ -363,7 +363,7 @@ audiodev_test_chmask(struct audiodev *ad
 			wlen = buflen;
 		ret = write(adev->fd, (char *)buf + off, wlen);
 		if (ret == -1) {
-			perror("write");
+			warn("write");
 			goto done;
 		}
 		wlen = ret;
@@ -372,7 +372,7 @@ audiodev_test_chmask(struct audiodev *ad
 	}
 
 	if (ioctl(adev->fd, AUDIO_DRAIN) == -1) {
-		perror("ioctl AUDIO_DRAIN");
+		warn("ioctl AUDIO_DRAIN");
 		goto done;
 	}
 

Index: src/usr.bin/audiocfg/dtmf.c
diff -u src/usr.bin/audiocfg/dtmf.c:1.3 src/usr.bin/audiocfg/dtmf.c:1.4
--- src/usr.bin/audiocfg/dtmf.c:1.3	Sun Aug 11 06:31:00 2013
+++ src/usr.bin/audiocfg/dtmf.c	Sat Aug 24 06:00:49 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: dtmf.c,v 1.3 2013/08/11 06:31:00 dholland Exp $ */
+/* $NetBSD: dtmf.c,v 1.4 2019/08/24 06:00:49 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -28,6 +28,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -70,7 +71,7 @@ dtmf_new(int16_t **buf, size_t *buflen, 
 	*buflen = sample_rate * sizeof(int16_t) * sample_length * channels;
 	*buf = calloc(1, *buflen);
 	if (*buf == NULL) {
-		perror("calloc");
+		warn("calloc");
 		return;
 	}
 

Index: src/usr.bin/audiocfg/main.c
diff -u src/usr.bin/audiocfg/main.c:1.13 src/usr.bin/audiocfg/main.c:1.14
--- src/usr.bin/audiocfg/main.c:1.13	Sat Aug 24 05:51:06 2019
+++ src/usr.bin/audiocfg/main.c	Sat Aug 24 06:00:49 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.13 2019/08/24 05:51:06 isaki Exp $ */
+/* $NetBSD: main.c,v 1.14 2019/08/24 06:00:49 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -27,6 +27,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -38,8 +39,10 @@
 #include "drvctl.h"
 
 __dead static 

CVS commit: src/usr.bin/audiocfg

2019-08-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 05:51:06 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c main.c

Log Message:
Check mode argument earlier.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/audiodev.c
diff -u src/usr.bin/audiocfg/audiodev.c:1.10 src/usr.bin/audiocfg/audiodev.c:1.11
--- src/usr.bin/audiocfg/audiodev.c:1.10	Sat Aug 24 05:45:24 2019
+++ src/usr.bin/audiocfg/audiodev.c	Sat Aug 24 05:51:06 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.10 2019/08/24 05:45:24 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.11 2019/08/24 05:51:06 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -282,11 +282,6 @@ audiodev_set_param(struct audiodev *adev
 		ai.record.sample_rate = freq;
 	}
 
-	if (setmode == 0) {
-		errno = EINVAL;
-		return -1;
-	}
-
 	ai.mode = setmode;
 	printf("setting %s to %s:%u, %uch, %uHz\n",
 	adev->xname, encname, prec, ch, freq);

Index: src/usr.bin/audiocfg/main.c
diff -u src/usr.bin/audiocfg/main.c:1.12 src/usr.bin/audiocfg/main.c:1.13
--- src/usr.bin/audiocfg/main.c:1.12	Sat Aug 24 05:45:25 2019
+++ src/usr.bin/audiocfg/main.c	Sat Aug 24 05:51:06 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.12 2019/08/24 05:45:25 isaki Exp $ */
+/* $NetBSD: main.c,v 1.13 2019/08/24 05:51:06 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -222,6 +222,9 @@ main(int argc, char *argv[])
 			else
 usage(argv[0]);
 		}
+		if (mode == 0)
+			usage(argv[0]);
+			/* NOTREACHED */
 		enc = argv[4];
 		prec = strtoul(argv[5], NULL, 10);
 		if (errno)



CVS commit: src/usr.bin/audiocfg

2019-08-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 05:51:06 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c main.c

Log Message:
Check mode argument earlier.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/audiocfg

2019-08-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 05:45:25 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c audiodev.h main.c

Log Message:
Use device unit number for index.
The index number was too confusing such as
 0: [ ] audio1 @ wss0
 1: [*] audio0 @ yds0
in my PC for example.  Here is new format:
 [*] audio0 @ yds0
 [ ] audio1 @ wss0
In this style, devices are always listed in order of unit number
and 0 always means audio0, 1 always means audio1.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/audiocfg/audiodev.h
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/audiodev.c
diff -u src/usr.bin/audiocfg/audiodev.c:1.9 src/usr.bin/audiocfg/audiodev.c:1.10
--- src/usr.bin/audiocfg/audiodev.c:1.9	Sat Aug 24 04:04:10 2019
+++ src/usr.bin/audiocfg/audiodev.c	Sat Aug 24 05:45:24 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.9 2019/08/24 04:04:10 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.10 2019/08/24 05:45:24 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -48,6 +48,7 @@ static int audiodev_test_chmask(struct a
 
 static TAILQ_HEAD(audiodevhead, audiodev) audiodevlist =
 TAILQ_HEAD_INITIALIZER(audiodevlist);
+static unsigned int maxunit;
 
 #define AUDIODEV_SAMPLE_RATE	44100
 
@@ -138,6 +139,9 @@ audiodev_add(const char *pdev, const cha
 
 	TAILQ_INSERT_TAIL(, adev, next);
 
+	if (unit > maxunit)
+		maxunit = unit;
+
 	return 0;
 }
 
@@ -179,29 +183,22 @@ audiodev_refresh(void)
 }
 
 unsigned int
-audiodev_count(void)
+audiodev_maxunit(void)
 {
-	struct audiodev *adev;
-	unsigned int n;
-
-	n = 0;
-	TAILQ_FOREACH(adev, , next)
-		++n;
-
-	return n;
+	return maxunit;
 }
 
+/*
+ * Get audiodev corresponding to audio device.
+ */
 struct audiodev *
 audiodev_get(unsigned int i)
 {
 	struct audiodev *adev;
-	unsigned int n;
 
-	n = 0;
 	TAILQ_FOREACH(adev, , next) {
-		if (n == i)
+		if (i == adev->unit)
 			return adev;
-		++n;
 	}
 
 	return NULL;

Index: src/usr.bin/audiocfg/audiodev.h
diff -u src/usr.bin/audiocfg/audiodev.h:1.7 src/usr.bin/audiocfg/audiodev.h:1.8
--- src/usr.bin/audiocfg/audiodev.h:1.7	Sat Aug 24 04:04:10 2019
+++ src/usr.bin/audiocfg/audiodev.h	Sat Aug 24 05:45:25 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.h,v 1.7 2019/08/24 04:04:10 isaki Exp $ */
+/* $NetBSD: audiodev.h,v 1.8 2019/08/24 05:45:25 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -60,7 +60,7 @@ struct audiodev {
 };
 
 int			audiodev_refresh(void);
-unsigned int		audiodev_count(void);
+unsigned int		audiodev_maxunit(void);
 struct audiodev *	audiodev_get(unsigned int);
 int			audiodev_set_default(struct audiodev *);
 int			audiodev_set_param(struct audiodev *, int,

Index: src/usr.bin/audiocfg/main.c
diff -u src/usr.bin/audiocfg/main.c:1.11 src/usr.bin/audiocfg/main.c:1.12
--- src/usr.bin/audiocfg/main.c:1.11	Sat Aug 24 04:04:10 2019
+++ src/usr.bin/audiocfg/main.c	Sat Aug 24 05:45:25 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.11 2019/08/24 04:04:10 isaki Exp $ */
+/* $NetBSD: main.c,v 1.12 2019/08/24 05:45:25 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -72,15 +72,15 @@ const char *encoding_names[] = {
 u_int encoding_max = __arraycount(encoding_names);
 
 static void
-print_audiodev(struct audiodev *adev, int i)
+print_audiodev(struct audiodev *adev)
 {
 	struct audiofmt *f;
 	int j;
 
 	assert(adev != NULL);
 
-	printf("%u: [%c] %s @ %s: ",
-	i, adev->defaultdev ? '*' : ' ',
+	printf("[%c] %s @ %s: ",
+	adev->defaultdev ? '*' : ' ',
 	adev->xname, adev->pxname);
 	printf("%s", adev->audio_device.name);
 	if (strlen(adev->audio_device.version) > 0)
@@ -159,9 +159,12 @@ main(int argc, char *argv[])
 		/* NOTREACHED */
 
 	if (strcmp(argv[1], "list") == 0 && argc == 2) {
-		n = audiodev_count();
-		for (i = 0; i < n; i++)
-			print_audiodev(audiodev_get(i), i);
+		n = audiodev_maxunit();
+		for (i = 0; i <= n; i++) {
+			adev = audiodev_get(i);
+			if (adev)
+print_audiodev(adev);
+		}
 	} else if (strcmp(argv[1], "list") == 0 && argc == 3) {
 		errno = 0;
 		i = strtoul(argv[2], NULL, 10);
@@ -173,7 +176,7 @@ main(int argc, char *argv[])
 			fprintf(stderr, "no such device\n");
 			return EXIT_FAILURE;
 		}
-		print_audiodev(adev, i);
+		print_audiodev(adev);
 	} else if (strcmp(argv[1], "default") == 0 && argc == 3) {
 		if (*argv[2] < '0' || *argv[2] > '9')
 			usage(argv[0]);
@@ -252,7 +255,7 @@ main(int argc, char *argv[])
 			fprintf(stderr, "no such device\n");
 			return EXIT_FAILURE;
 		}
-		print_audiodev(adev, i);
+		print_audiodev(adev);
 		if (audiodev_test(adev) == -1)
 			return EXIT_FAILURE;
 	} else



CVS commit: src/usr.bin/audiocfg

2019-08-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 05:45:25 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c audiodev.h main.c

Log Message:
Use device unit number for index.
The index number was too confusing such as
 0: [ ] audio1 @ wss0
 1: [*] audio0 @ yds0
in my PC for example.  Here is new format:
 [*] audio0 @ yds0
 [ ] audio1 @ wss0
In this style, devices are always listed in order of unit number
and 0 always means audio0, 1 always means audio1.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/audiocfg/audiodev.h
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/audiocfg

2019-08-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 04:04:10 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c audiodev.h main.c

Log Message:
Revert to use single descriptor for "audiocfg test" as before.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/audiocfg/audiodev.h
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/audiocfg

2019-08-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 04:04:10 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c audiodev.h main.c

Log Message:
Revert to use single descriptor for "audiocfg test" as before.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/audiocfg/audiodev.h
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/audiodev.c
diff -u src/usr.bin/audiocfg/audiodev.c:1.8 src/usr.bin/audiocfg/audiodev.c:1.9
--- src/usr.bin/audiocfg/audiodev.c:1.8	Sat Aug 24 03:28:37 2019
+++ src/usr.bin/audiocfg/audiodev.c	Sat Aug 24 04:04:10 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.8 2019/08/24 03:28:37 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.9 2019/08/24 04:04:10 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -43,6 +43,9 @@
 #include "drvctl.h"
 #include "dtmf.h"
 
+static int audiodev_test_chmask(struct audiodev *, unsigned int,
+	audio_info_t *);
+
 static TAILQ_HEAD(audiodevhead, audiodev) audiodevlist =
 TAILQ_HEAD_INITIALIZER(audiodevlist);
 
@@ -298,17 +301,16 @@ audiodev_set_param(struct audiodev *adev
 }
 
 int
-audiodev_test(struct audiodev *adev, unsigned int chanmask)
+audiodev_test(struct audiodev *adev)
 {
 	audio_info_t info;
-	int16_t *buf;
-	size_t buflen;
-	off_t off;
-	int fd;
-	int rv = -1;
+	unsigned int i;
+	int rv;
 
-	fd = open(adev->path, O_WRONLY);
-	if (fd == -1) {
+	rv = -1;
+
+	adev->fd = open(adev->path, O_WRONLY);
+	if (adev->fd == -1) {
 		perror("open");
 		return -1;
 	}
@@ -319,19 +321,44 @@ audiodev_test(struct audiodev *adev, uns
 	info.play.precision = 16;
 	info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
 	info.mode = AUMODE_PLAY;
-	if (ioctl(fd, AUDIO_SETINFO, ) == -1) {
+	if (ioctl(adev->fd, AUDIO_SETINFO, ) == -1) {
 		perror("ioctl AUDIO_SETINFO");
-		goto abort;
+		goto done;
 	}
-	if (ioctl(fd, AUDIO_GETINFO, ) == -1) {
+	if (ioctl(adev->fd, AUDIO_GETINFO, ) == -1) {
 		perror("ioctl AUDIO_GETINFO");
-		goto abort;
+		goto done;
+	}
+
+	for (i = 0; i < adev->hwinfo.play.channels; i++) {
+		printf("  testing channel %u...", i);
+		fflush(stdout);
+		if (audiodev_test_chmask(adev, 1 << i, ) == -1)
+			goto done;
+		printf(" done\n");
 	}
 
-	dtmf_new(, , info.play.sample_rate, 2,
+	rv = 0;
+done:
+	close(adev->fd);
+	return rv;
+}
+
+static int
+audiodev_test_chmask(struct audiodev *adev, unsigned int chanmask,
+	audio_info_t *info)
+{
+	int16_t *buf;
+	size_t buflen;
+	off_t off;
+	int rv;
+
+	rv = -1;
+
+	dtmf_new(, , info->play.sample_rate, 2,
 	adev->hwinfo.play.channels, chanmask, 350.0, 440.0);
 	if (buf == NULL) {
-		goto abort;
+		return -1;
 	}
 
 	off = 0;
@@ -339,10 +366,10 @@ audiodev_test(struct audiodev *adev, uns
 		size_t wlen; 
 		ssize_t ret;
 
-		wlen = info.play.buffer_size;
+		wlen = info->play.buffer_size;
 		if (wlen > buflen)
 			wlen = buflen;
-		ret = write(fd, (char *)buf + off, wlen);
+		ret = write(adev->fd, (char *)buf + off, wlen);
 		if (ret == -1) {
 			perror("write");
 			goto done;
@@ -352,7 +379,7 @@ audiodev_test(struct audiodev *adev, uns
 		buflen -= wlen;
 	}
 
-	if (ioctl(fd, AUDIO_DRAIN) == -1) {
+	if (ioctl(adev->fd, AUDIO_DRAIN) == -1) {
 		perror("ioctl AUDIO_DRAIN");
 		goto done;
 	}
@@ -360,8 +387,5 @@ audiodev_test(struct audiodev *adev, uns
 	rv = 0;
 done:
 	free(buf);
-abort:
-	close(fd);
-
 	return rv;
 }

Index: src/usr.bin/audiocfg/audiodev.h
diff -u src/usr.bin/audiocfg/audiodev.h:1.6 src/usr.bin/audiocfg/audiodev.h:1.7
--- src/usr.bin/audiocfg/audiodev.h:1.6	Sat Aug 24 03:28:37 2019
+++ src/usr.bin/audiocfg/audiodev.h	Sat Aug 24 04:04:10 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.h,v 1.6 2019/08/24 03:28:37 isaki Exp $ */
+/* $NetBSD: audiodev.h,v 1.7 2019/08/24 04:04:10 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -46,6 +46,7 @@ struct audiodev {
 	uint16_t unit;
 	char path[PATH_MAX+1];
 	char ctlpath[PATH_MAX+1];
+	int fd;
 	int ctlfd;
 
 	dev_t dev;
@@ -65,7 +66,7 @@ int			audiodev_set_default(struct audiod
 int			audiodev_set_param(struct audiodev *, int,
 const char *, unsigned int, unsigned int,
 unsigned int);
-int			audiodev_test(struct audiodev *, unsigned int);
+int			audiodev_test(struct audiodev *);
 
 extern const char *	encoding_names[];
 extern u_int		encoding_max;

Index: src/usr.bin/audiocfg/main.c
diff -u src/usr.bin/audiocfg/main.c:1.10 src/usr.bin/audiocfg/main.c:1.11
--- src/usr.bin/audiocfg/main.c:1.10	Sat Aug 24 03:28:37 2019
+++ src/usr.bin/audiocfg/main.c	Sat Aug 24 04:04:10 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.10 2019/08/24 03:28:37 isaki Exp $ */
+/* $NetBSD: main.c,v 1.11 2019/08/24 04:04:10 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -253,13 +253,8 @@ main(int argc, char *argv[])
 			return EXIT_FAILURE;
 		}
 		

CVS commit: src/usr.bin/audiocfg

2019-08-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 03:28:38 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c audiodev.h main.c

Log Message:
Rename some members in adev for clarity.  No functional changes intended.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/audiocfg/audiodev.h
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/audiocfg

2019-08-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 24 03:28:38 UTC 2019

Modified Files:
src/usr.bin/audiocfg: audiodev.c audiodev.h main.c

Log Message:
Rename some members in adev for clarity.  No functional changes intended.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/audiocfg/audiodev.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/audiocfg/audiodev.h
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/audiodev.c
diff -u src/usr.bin/audiocfg/audiodev.c:1.7 src/usr.bin/audiocfg/audiodev.c:1.8
--- src/usr.bin/audiocfg/audiodev.c:1.7	Wed May  8 14:36:12 2019
+++ src/usr.bin/audiocfg/audiodev.c	Sat Aug 24 03:28:37 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.7 2019/05/08 14:36:12 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.8 2019/08/24 03:28:37 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -63,26 +63,26 @@ audiodev_getinfo(struct audiodev *adev)
 	if (stat(_PATH_AUDIOCTL, ) != -1 && st.st_rdev == adev->dev)
 		adev->defaultdev = true;
 
-	adev->fd = open(adev->ctlpath, O_RDONLY);
-	if (adev->fd == -1) {
+	adev->ctlfd = open(adev->ctlpath, O_RDONLY);
+	if (adev->ctlfd == -1) {
 			return -1;
 	}
-	if (ioctl(adev->fd, AUDIO_GETDEV, >audio_device) == -1) {
-		close(adev->fd);
+	if (ioctl(adev->ctlfd, AUDIO_GETDEV, >audio_device) == -1) {
+		close(adev->ctlfd);
 		return -1;
 	}
 
 	for (i = 0; ;i++) {
 		memset(, 0, sizeof(query));
 		query.index = i;
-		if (ioctl(adev->fd, AUDIO_QUERYFORMAT, ) == -1) {
+		if (ioctl(adev->ctlfd, AUDIO_QUERYFORMAT, ) == -1) {
 			if (errno == ENODEV) {
 /* QUERYFORMAT not supported. */
 break;
 			}
 			if (errno == EINVAL)
 break;
-			close(adev->fd);
+			close(adev->ctlfd);
 			return -1;
 		}
 
@@ -91,8 +91,8 @@ audiodev_getinfo(struct audiodev *adev)
 		TAILQ_INSERT_TAIL(>formats, f, next);
 	}
 
-	if (ioctl(adev->fd, AUDIO_GETFORMAT, >info) == -1) {
-		close(adev->fd);
+	if (ioctl(adev->ctlfd, AUDIO_GETFORMAT, >hwinfo) == -1) {
+		close(adev->ctlfd);
 		return -1;
 	}
 
@@ -158,8 +158,8 @@ audiodev_refresh(void)
 
 	while (!TAILQ_EMPTY()) {
 		adev = TAILQ_FIRST();
-		if (adev->fd != -1)
-			close(adev->fd);
+		if (adev->ctlfd != -1)
+			close(adev->ctlfd);
 		TAILQ_REMOVE(, adev, next);
 		free(adev);
 	}
@@ -250,12 +250,12 @@ int
 audiodev_set_param(struct audiodev *adev, int mode,
 	const char *encname, unsigned int prec, unsigned int ch, unsigned int freq)
 {
-	struct audio_info ai;
+	audio_info_t ai;
 	int setmode;
 	u_int enc;
 
 	setmode = 0;
-	ai = adev->info;
+	ai = adev->hwinfo;
 
 	for (enc = 0; enc < encoding_max; enc++) {
 		if (strcmp(encname, encoding_names[enc]) == 0)
@@ -290,7 +290,7 @@ audiodev_set_param(struct audiodev *adev
 	ai.mode = setmode;
 	printf("setting %s to %s:%u, %uch, %uHz\n",
 	adev->xname, encname, prec, ch, freq);
-	if (ioctl(adev->fd, AUDIO_SETFORMAT, ) == -1) {
+	if (ioctl(adev->ctlfd, AUDIO_SETFORMAT, ) == -1) {
 		perror("ioctl AUDIO_SETFORMAT");
 		return -1;
 	}
@@ -315,7 +315,7 @@ audiodev_test(struct audiodev *adev, uns
 
 	AUDIO_INITINFO();
 	info.play.sample_rate = AUDIODEV_SAMPLE_RATE;
-	info.play.channels = adev->info.play.channels;
+	info.play.channels = adev->hwinfo.play.channels;
 	info.play.precision = 16;
 	info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
 	info.mode = AUMODE_PLAY;
@@ -329,7 +329,7 @@ audiodev_test(struct audiodev *adev, uns
 	}
 
 	dtmf_new(, , info.play.sample_rate, 2,
-	adev->info.play.channels, chanmask, 350.0, 440.0);
+	adev->hwinfo.play.channels, chanmask, 350.0, 440.0);
 	if (buf == NULL) {
 		goto abort;
 	}

Index: src/usr.bin/audiocfg/audiodev.h
diff -u src/usr.bin/audiocfg/audiodev.h:1.5 src/usr.bin/audiocfg/audiodev.h:1.6
--- src/usr.bin/audiocfg/audiodev.h:1.5	Wed May  8 14:36:12 2019
+++ src/usr.bin/audiocfg/audiodev.h	Sat Aug 24 03:28:37 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.h,v 1.5 2019/05/08 14:36:12 isaki Exp $ */
+/* $NetBSD: audiodev.h,v 1.6 2019/08/24 03:28:37 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -46,14 +46,14 @@ struct audiodev {
 	uint16_t unit;
 	char path[PATH_MAX+1];
 	char ctlpath[PATH_MAX+1];
+	int ctlfd;
 
-	int fd;
 	dev_t dev;
 	bool defaultdev;
 
 	audio_device_t audio_device;
 	TAILQ_HEAD(, audiofmt) formats;
-	struct audio_info info;
+	audio_info_t hwinfo;
 
 	TAILQ_ENTRY(audiodev) next;
 };

Index: src/usr.bin/audiocfg/main.c
diff -u src/usr.bin/audiocfg/main.c:1.9 src/usr.bin/audiocfg/main.c:1.10
--- src/usr.bin/audiocfg/main.c:1.9	Thu Aug 22 14:40:14 2019
+++ src/usr.bin/audiocfg/main.c	Sat Aug 24 03:28:37 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.9 2019/08/22 14:40:14 isaki Exp $ */
+/* $NetBSD: main.c,v 1.10 2019/08/24 03:28:37 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -87,17 +87,21 @@ print_audiodev(struct audiodev *adev, in
 		printf(" %s", 

CVS commit: src/usr.bin/audiocfg

2019-08-22 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Aug 22 14:40:14 UTC 2019

Modified Files:
src/usr.bin/audiocfg: main.c

Log Message:
Fix assertion of "audiocfg list " when n is an illegal index.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/audiocfg/main.c
diff -u src/usr.bin/audiocfg/main.c:1.8 src/usr.bin/audiocfg/main.c:1.9
--- src/usr.bin/audiocfg/main.c:1.8	Wed May  8 14:36:12 2019
+++ src/usr.bin/audiocfg/main.c	Thu Aug 22 14:40:14 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.8 2019/05/08 14:36:12 isaki Exp $ */
+/* $NetBSD: main.c,v 1.9 2019/08/22 14:40:14 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill 
@@ -164,7 +164,12 @@ main(int argc, char *argv[])
 		if (errno)
 			usage(argv[0]);
 			/* NOTREACHED */
-		print_audiodev(audiodev_get(i), i);
+		adev = audiodev_get(i);
+		if (adev == NULL) {
+			fprintf(stderr, "no such device\n");
+			return EXIT_FAILURE;
+		}
+		print_audiodev(adev, i);
 	} else if (strcmp(argv[1], "default") == 0 && argc == 3) {
 		if (*argv[2] < '0' || *argv[2] > '9')
 			usage(argv[0]);



CVS commit: src/usr.bin/audiocfg

2019-08-22 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Aug 22 14:40:14 UTC 2019

Modified Files:
src/usr.bin/audiocfg: main.c

Log Message:
Fix assertion of "audiocfg list " when n is an illegal index.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/audiocfg/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/usr.bin/audiocfg

2010-10-24 Thread David Holland
On Mon, Sep 13, 2010 at 01:32:38PM +1000, matthew green wrote:
  Should we make perror() produce a warning so people will stop using it?
 
  No, as it is not a NetBSD specific API.
  
  Neither is gets()
  
  using perror() doesn't lead to fatal security flaws.
  
  i don't see any good reason to warn on it.

The man page should, however, at least mention warn() and perhaps note
that warn() is preferred. I will attend to this.

And, btw, the man page also claims that perror first appeared in
4.4BSD. Is this really correct?

-- 
David A. Holland
dholl...@netbsd.org


Re: CVS commit: src/usr.bin/audiocfg

2010-09-13 Thread Christos Zoulas
On Sep 12, 11:45pm, t...@zhadum.org.uk (Matthias Scheler) wrote:
-- Subject: Re: CVS commit: src/usr.bin/audiocfg

| On 11 Sep 2010, at 23:44, Christos Zoulas wrote:
| 
| Well, but gets() is clearly broken by design, perror(3) isn't. And the obvi=
| ous replacement for gets(3) is fgets(3) which is portable. I don't think th=
| at warnx(3), etc. are portable.

They are portable enough (linux has them too, so does OpenSolaris).
Not having the program name in an error message is a big lose for me.

christos


Re: CVS commit: src/usr.bin/audiocfg

2010-09-11 Thread Matthias Scheler

On 6 Sep 2010, at 23:35, Christos Zoulas wrote:
 Should we make perror() produce a warning so people will stop using it?

No, as it is not a NetBSD specific API.

Kind regards

-- 
Matthias Scheler   http://zhadum.org.uk/




Re: CVS commit: src/usr.bin/audiocfg

2010-09-11 Thread Christos Zoulas
In article 5217ce1f-57c2-40bc-9281-50f90bba0...@zhadum.org.uk,
Matthias Scheler  t...@zhadum.org.uk wrote:

On 6 Sep 2010, at 23:35, Christos Zoulas wrote:
 Should we make perror() produce a warning so people will stop using it?

No, as it is not a NetBSD specific API.

Neither is gets()

christos



Re: CVS commit: src/usr.bin/audiocfg

2010-09-06 Thread Christos Zoulas
In article 20100903192037.c6aa517...@cvs.netbsd.org,
Jared D. McNeill source-changes-d@NetBSD.org wrote:

[...]

   if (wlen  buflen)
   wlen = buflen;
-  write(adev-fd, (char *)buf + off, wlen);
+  wlen = write(adev-fd, (char *)buf + off, wlen);
+  if (wlen == -1) {
+  perror(write);
+  rv = -1;
+  goto done;
+  }

Should we make perror() produce a warning so people will stop using it?
Please use warn{,x}() instead, so we get the program name printed!

christos