CVS commit: src/usr.bin/audio/record

2024-03-20 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Mar 20 20:19:31 UTC 2024

Modified Files:
src/usr.bin/audio/record: record.c

Log Message:
match message & conversion function name properly.

probably should make this into an array with two members.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/audio/record/record.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/audio/record/record.c
diff -u src/usr.bin/audio/record/record.c:1.58 src/usr.bin/audio/record/record.c:1.59
--- src/usr.bin/audio/record/record.c:1.58	Tue Feb 27 20:40:30 2024
+++ src/usr.bin/audio/record/record.c	Wed Mar 20 20:19:31 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: record.c,v 1.58 2024/02/27 20:40:30 gson Exp $	*/
+/*	$NetBSD: record.c,v 1.59 2024/03/20 20:19:31 mrg Exp $	*/
 
 /*
  * Copyright (c) 1999, 2002, 2003, 2005, 2010 Matthew R. Green
@@ -32,7 +32,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: record.c,v 1.58 2024/02/27 20:40:30 gson Exp $");
+__RCSID("$NetBSD: record.c,v 1.59 2024/03/20 20:19:31 mrg Exp $");
 #endif
 
 
@@ -322,9 +322,9 @@ main(int argc, char *argv[])
 			s = "change sign (little-endian, 32 bit)";
 		else if (conv_func == change_sign16_swap_bytes_be)
 			s = "change sign & swap bytes (big-endian, 16 bit)";
-		else if (conv_func == change_sign24_swap_bytes_le)
+		else if (conv_func == change_sign16_swap_bytes_le)
 			s = "change sign & swap bytes (little-endian, 16 bit)";
-		else if (conv_func == change_sign16_swap_bytes_be)
+		else if (conv_func == change_sign24_swap_bytes_be)
 			s = "change sign & swap bytes (big-endian, 24 bit)";
 		else if (conv_func == change_sign24_swap_bytes_le)
 			s = "change sign & swap bytes (little-endian, 24 bit)";



CVS commit: src/usr.bin/audio/record

2024-03-20 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Mar 20 20:19:31 UTC 2024

Modified Files:
src/usr.bin/audio/record: record.c

Log Message:
match message & conversion function name properly.

probably should make this into an array with two members.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/audio/record/record.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/audio/common

2024-03-20 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Mar 20 20:18:39 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c

Log Message:
audio_wav_parse_hdr: handle zero-length data files again

the previous clean up turns zero-length data into no data and thus
an error, instead of simply doing nothing.  noted by gson.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/audio/common/wav.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/audio/common/wav.c
diff -u src/usr.bin/audio/common/wav.c:1.23 src/usr.bin/audio/common/wav.c:1.24
--- src/usr.bin/audio/common/wav.c:1.23	Thu Mar 14 00:00:31 2024
+++ src/usr.bin/audio/common/wav.c	Wed Mar 20 20:18:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: wav.c,v 1.23 2024/03/14 00:00:31 mrg Exp $	*/
+/*	$NetBSD: wav.c,v 1.24 2024/03/20 20:18:39 mrg Exp $	*/
 
 /*
  * Copyright (c) 2002, 2009, 2013, 2015, 2019, 2024 Matthew R. Green
@@ -33,7 +33,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: wav.c,v 1.23 2024/03/14 00:00:31 mrg Exp $");
+__RCSID("$NetBSD: wav.c,v 1.24 2024/03/20 20:18:39 mrg Exp $");
 #endif
 
 
@@ -101,7 +101,7 @@ find_riff_chunk(const char *search, size
 	*partlen = 0;
 
 #define ADJUST(l) do {\
-	if (l >= *(remainp))			\
+	if (l > *(remainp))			\
 		return false;			\
 	*(wherep) += (l);			\
 	*(remainp) -= (l);			\
@@ -160,7 +160,7 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 		return (AUDIO_ENOENT);
 
 #define ADJUST(l) do {\
-	if (l >= remain)			\
+	if ((l) > remain)			\
 		return (AUDIO_ESHORTHDR);	\
 	where += (l);\
 	remain -= (l);\
@@ -281,20 +281,17 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 	if (!found)
 		return (AUDIO_EWAVNODATA);
 
-	if (len) {
-		if (channels)
-			*channels = (u_int)getle16(fmt.channels);
-		if (sample)
-			*sample = getle32(fmt.sample_rate);
-		if (enc)
-			*enc = newenc;
-		if (prec)
-			*prec = newprec;
-		if (datasize)
-			*datasize = (off_t)len;
-		return (where - (char *)hdr);
-	}
-	return (AUDIO_EWAVNODATA);
+	if (channels)
+		*channels = (u_int)getle16(fmt.channels);
+	if (sample)
+		*sample = getle32(fmt.sample_rate);
+	if (enc)
+		*enc = newenc;
+	if (prec)
+		*prec = newprec;
+	if (datasize)
+		*datasize = (off_t)len;
+	return (where - (char *)hdr);
 
 #undef ADJUST
 }



CVS commit: src/usr.bin/audio/common

2024-03-20 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Mar 20 20:18:39 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c

Log Message:
audio_wav_parse_hdr: handle zero-length data files again

the previous clean up turns zero-length data into no data and thus
an error, instead of simply doing nothing.  noted by gson.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/audio/common/wav.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/audio/common

2024-03-13 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Mar 14 00:00:31 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c

Log Message:
fix some sizeof() confusion.

using "const char search[4]" as a function parameter means that
"search" is actually a pointer type so "sizeof search" returns
8 on 64-bit platforms.  i mis-read this and used "sizeof *search"
which is always 1, noted by rillig.

instead of trying to avoid writing "4" twice, put it in a define
and use that in various places instead.  annoying.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/audio/common/wav.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/audio/common/wav.c
diff -u src/usr.bin/audio/common/wav.c:1.22 src/usr.bin/audio/common/wav.c:1.23
--- src/usr.bin/audio/common/wav.c:1.22	Tue Mar 12 00:34:38 2024
+++ src/usr.bin/audio/common/wav.c	Thu Mar 14 00:00:31 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: wav.c,v 1.22 2024/03/12 00:34:38 mrg Exp $	*/
+/*	$NetBSD: wav.c,v 1.23 2024/03/14 00:00:31 mrg Exp $	*/
 
 /*
  * Copyright (c) 2002, 2009, 2013, 2015, 2019, 2024 Matthew R. Green
@@ -33,7 +33,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: wav.c,v 1.22 2024/03/12 00:34:38 mrg Exp $");
+__RCSID("$NetBSD: wav.c,v 1.23 2024/03/14 00:00:31 mrg Exp $");
 #endif
 
 
@@ -91,8 +91,10 @@ wav_enc_from_val(int encoding)
  * WAV format helpers
  */
 
+#define RIFFNAMELEN	4
+
 static bool
-find_riff_chunk(const char search[4], size_t *remainp, char **wherep, uint32_t *partlen)
+find_riff_chunk(const char *search, size_t *remainp, char **wherep, uint32_t *partlen)
 {
 	wav_audioheaderpart part;
 
@@ -116,7 +118,7 @@ find_riff_chunk(const char search[4], si
 			emsg = " (odd length, adjusted)";
 			len += 1;
 		}
-		if (strncmp(part.name, search, sizeof *search) == 0) {
+		if (strncmp(part.name, search, RIFFNAMELEN) == 0) {
 			*partlen = len;
 			if (verbose > 1)
 fprintf(stderr, "Found part %.04s length %d%s\n",
@@ -148,10 +150,10 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 	uint32_t len = 0;
 	u_int16_t fmttag;
 	static const char
-	strfmt[4] = "fmt ",
-	strRIFF[4] = "RIFF",
-	strWAVE[4] = "WAVE",
-	strdata[4] = "data";
+	strfmt[RIFFNAMELEN] = "fmt ",
+	strRIFF[RIFFNAMELEN] = "RIFF",
+	strWAVE[RIFFNAMELEN] = "WAVE",
+	strdata[RIFFNAMELEN] = "data";
 	bool found;
 
 	if (sz < 32)



CVS commit: src/usr.bin/audio/common

2024-03-13 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Mar 14 00:00:31 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c

Log Message:
fix some sizeof() confusion.

using "const char search[4]" as a function parameter means that
"search" is actually a pointer type so "sizeof search" returns
8 on 64-bit platforms.  i mis-read this and used "sizeof *search"
which is always 1, noted by rillig.

instead of trying to avoid writing "4" twice, put it in a define
and use that in various places instead.  annoying.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/audio/common/wav.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/audio/common

2024-03-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Mar 12 00:34:38 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c

Log Message:
audioplay(1): handle mis-aligned RIFF chunks.

put the code to find RIFF chunks into a new find_riff_chunk() function,
and handle mis-aligned chunk lengths.  can now play files with chunks
that say they are 7 bytes long, and have 1 byte padding.

add some -V -V extra-verbose for the wav parser.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/audio/common/wav.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/audio/common/wav.c
diff -u src/usr.bin/audio/common/wav.c:1.21 src/usr.bin/audio/common/wav.c:1.22
--- src/usr.bin/audio/common/wav.c:1.21	Mon Mar 11 23:12:29 2024
+++ src/usr.bin/audio/common/wav.c	Tue Mar 12 00:34:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: wav.c,v 1.21 2024/03/11 23:12:29 mrg Exp $	*/
+/*	$NetBSD: wav.c,v 1.22 2024/03/12 00:34:38 mrg Exp $	*/
 
 /*
  * Copyright (c) 2002, 2009, 2013, 2015, 2019, 2024 Matthew R. Green
@@ -33,7 +33,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: wav.c,v 1.21 2024/03/11 23:12:29 mrg Exp $");
+__RCSID("$NetBSD: wav.c,v 1.22 2024/03/12 00:34:38 mrg Exp $");
 #endif
 
 
@@ -90,6 +90,49 @@ wav_enc_from_val(int encoding)
 /*
  * WAV format helpers
  */
+
+static bool
+find_riff_chunk(const char search[4], size_t *remainp, char **wherep, uint32_t *partlen)
+{
+	wav_audioheaderpart part;
+
+	*partlen = 0;
+
+#define ADJUST(l) do {\
+	if (l >= *(remainp))			\
+		return false;			\
+	*(wherep) += (l);			\
+	*(remainp) -= (l);			\
+} while (0)
+
+	while (*remainp >= sizeof part) {
+		const char *emsg = "";
+		uint32_t len;
+
+		memcpy(, *wherep, sizeof part);
+		ADJUST(sizeof part);
+		len = getle32(part.len);
+		if (len % 2) {
+			emsg = " (odd length, adjusted)";
+			len += 1;
+		}
+		if (strncmp(part.name, search, sizeof *search) == 0) {
+			*partlen = len;
+			if (verbose > 1)
+fprintf(stderr, "Found part %.04s length %d%s\n",
+part.name, len, emsg);
+			return true;
+		}
+		ADJUST(len);
+		if (verbose > 1)
+			fprintf(stderr, "Skipping part %.04s length %d%s\n",
+			part.name, len, emsg);
+	}
+#undef ADJUST
+
+	return false;
+}
+
 /*
  * find a .wav header, etc. returns header length on success
  */
@@ -98,7 +141,6 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 u_int *sample, u_int *channels, off_t *datasize)
 {
 	char	*where = hdr;
-	wav_audioheaderpart part;
 	wav_audioheaderfmt fmt;
 	wav_audiohdrextensible ext;
 	size_t remain = sz;
@@ -131,17 +173,7 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 		return (AUDIO_ENOENT);
 	ADJUST(sizeof strWAVE);
 
-	found = false;
-	while (remain >= sizeof part) {
-		memcpy(, where, sizeof part);
-		ADJUST(sizeof part);
-		len = getle32(part.len);
-		if (strncmp(part.name, strfmt, sizeof strfmt) == 0) {
-			found = true;
-			break;
-		}
-		ADJUST(len);
-	}
+	found = find_riff_chunk(strfmt, , , );
 
 	/* too short ? */
 	if (!found || remain <= sizeof fmt)
@@ -243,20 +275,9 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 		break;
 	}
 
-	found = false;
-	while (remain >= sizeof part) {
-		memcpy(, where, sizeof part);
-		ADJUST(sizeof part);
-		len = getle32(part.len);
-		if (strncmp(part.name, strdata, sizeof strdata) == 0) {
-			found = true;
-			break;
-		}
-		/* Adjust len here only for non-data parts. */
-		ADJUST(len);
-	}
+	found = find_riff_chunk(strdata, , , );
 	if (!found)
-		return (AUDIO_ENOENT);
+		return (AUDIO_EWAVNODATA);
 
 	if (len) {
 		if (channels)



CVS commit: src/usr.bin/audio/common

2024-03-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Mar 12 00:34:38 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c

Log Message:
audioplay(1): handle mis-aligned RIFF chunks.

put the code to find RIFF chunks into a new find_riff_chunk() function,
and handle mis-aligned chunk lengths.  can now play files with chunks
that say they are 7 bytes long, and have 1 byte padding.

add some -V -V extra-verbose for the wav parser.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/audio/common/wav.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/audio/common

2024-03-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Mar 11 23:12:29 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c

Log Message:
minor clean up in the RIFF/WAVE header checking.

use memcmp() not strncmp() to check for "RIFF" and "WAVE".
avoid endian convesion on part.len 3 times.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/audio/common/wav.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/audio/common/wav.c
diff -u src/usr.bin/audio/common/wav.c:1.20 src/usr.bin/audio/common/wav.c:1.21
--- src/usr.bin/audio/common/wav.c:1.20	Mon Mar 11 19:17:52 2024
+++ src/usr.bin/audio/common/wav.c	Mon Mar 11 23:12:29 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: wav.c,v 1.20 2024/03/11 19:17:52 mrg Exp $	*/
+/*	$NetBSD: wav.c,v 1.21 2024/03/11 23:12:29 mrg Exp $	*/
 
 /*
  * Copyright (c) 2002, 2009, 2013, 2015, 2019, 2024 Matthew R. Green
@@ -33,7 +33,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: wav.c,v 1.20 2024/03/11 19:17:52 mrg Exp $");
+__RCSID("$NetBSD: wav.c,v 1.21 2024/03/11 23:12:29 mrg Exp $");
 #endif
 
 
@@ -122,12 +122,14 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 	remain -= (l);\
 } while (0)
 
-	if (strncmp(where, strRIFF, sizeof strRIFF) != 0)
-		return (AUDIO_ENOENT);
-	ADJUST(8);
-	if (strncmp(where, strWAVE, sizeof strWAVE) != 0)
+	if (memcmp(where, strRIFF, sizeof strRIFF) != 0)
 		return (AUDIO_ENOENT);
+	ADJUST(sizeof strRIFF);
+	/* XXX we ignore the RIFF length here */
 	ADJUST(4);
+	if (memcmp(where, strWAVE, sizeof strWAVE) != 0)
+		return (AUDIO_ENOENT);
+	ADJUST(sizeof strWAVE);
 
 	found = false;
 	while (remain >= sizeof part) {
@@ -245,18 +247,18 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 	while (remain >= sizeof part) {
 		memcpy(, where, sizeof part);
 		ADJUST(sizeof part);
+		len = getle32(part.len);
 		if (strncmp(part.name, strdata, sizeof strdata) == 0) {
 			found = true;
 			break;
 		}
 		/* Adjust len here only for non-data parts. */
-		len = getle32(part.len);
 		ADJUST(len);
 	}
 	if (!found)
 		return (AUDIO_ENOENT);
 
-	if (getle32(part.len)) {
+	if (len) {
 		if (channels)
 			*channels = (u_int)getle16(fmt.channels);
 		if (sample)
@@ -266,7 +268,7 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 		if (prec)
 			*prec = newprec;
 		if (datasize)
-			*datasize = (off_t)getle32(part.len);
+			*datasize = (off_t)len;
 		return (where - (char *)hdr);
 	}
 	return (AUDIO_EWAVNODATA);



CVS commit: src/usr.bin/audio/common

2024-03-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Mar 11 23:12:29 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c

Log Message:
minor clean up in the RIFF/WAVE header checking.

use memcmp() not strncmp() to check for "RIFF" and "WAVE".
avoid endian convesion on part.len 3 times.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/audio/common/wav.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/audio/common

2024-03-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Mar 11 19:17:52 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c

Log Message:
be sure to byte swap ext.len when checking/printing it.

noted by rillig@.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/audio/common/wav.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/audio/common

2024-03-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Mar 11 19:17:52 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c

Log Message:
be sure to byte swap ext.len when checking/printing it.

noted by rillig@.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/audio/common/wav.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/audio/common/wav.c
diff -u src/usr.bin/audio/common/wav.c:1.19 src/usr.bin/audio/common/wav.c:1.20
--- src/usr.bin/audio/common/wav.c:1.19	Fri Mar  8 06:57:59 2024
+++ src/usr.bin/audio/common/wav.c	Mon Mar 11 19:17:52 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: wav.c,v 1.19 2024/03/08 06:57:59 mrg Exp $	*/
+/*	$NetBSD: wav.c,v 1.20 2024/03/11 19:17:52 mrg Exp $	*/
 
 /*
  * Copyright (c) 2002, 2009, 2013, 2015, 2019, 2024 Matthew R. Green
@@ -33,7 +33,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: wav.c,v 1.19 2024/03/08 06:57:59 mrg Exp $");
+__RCSID("$NetBSD: wav.c,v 1.20 2024/03/11 19:17:52 mrg Exp $");
 #endif
 
 
@@ -175,8 +175,10 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 		 *
 		 * warn about this, but don't consider it an error.
 		 */
-		if (ext.len != 22 && verbose)
-			fprintf(stderr, "warning: WAVE ext.len %u not 22\n", ext.len);
+		if (getle16(ext.len) != 22 && verbose) {
+			fprintf(stderr, "warning: WAVE ext.len %u not 22\n",
+			getle16(ext.len));
+		}
 	} else if (len < sizeof(fmt)) {
 		if (verbose)
 			fprintf(stderr, "WAVE fmt unsupported size %u\n", len);



CVS commit: src/usr.bin/audio/common

2024-03-07 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Mar  8 06:57:59 UTC 2024

Modified Files:
src/usr.bin/audio/common: libaudio.h wav.c

Log Message:
audio_wav_parse_hdr(): avoid buffer overreads and clean up

reimplement most of this function using a new method of buffer
management to ensure that we never read beyond the provided size.

properly handle RIFF chunk lengths, instead of assuming various
offsets from most files are right.

update list of consumed documentation and fill the list of WAVE
formats from RFC 2361 (most remain not supported.)

should fix PR#57973.

tested against a large number of .wav files i have handy and with
a testsuite generator that should be incoming soon.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/audio/common/libaudio.h
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/audio/common/wav.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/audio/common/libaudio.h
diff -u src/usr.bin/audio/common/libaudio.h:1.21 src/usr.bin/audio/common/libaudio.h:1.22
--- src/usr.bin/audio/common/libaudio.h:1.21	Sat Nov  9 12:46:44 2019
+++ src/usr.bin/audio/common/libaudio.h	Fri Mar  8 06:57:59 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: libaudio.h,v 1.21 2019/11/09 12:46:44 mrg Exp $	*/
+/*	$NetBSD: libaudio.h,v 1.22 2024/03/08 06:57:59 mrg Exp $	*/
 
 /*
- * Copyright (c) 1999, 2009, 2013, 2015, 2019 Matthew R. Green
+ * Copyright (c) 1999, 2009, 2013, 2015, 2019, 2024 Matthew R. Green
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -106,7 +106,10 @@ int	audio_sun_to_encoding (int, u_int *,
 int	audio_encoding_to_sun (int, int, int *);
 
 /*
- * M$ WAV files, info gleamed from sox sources
+ * RIFF WAVE files.  Sources: RFC 2361, and various Microsoft docs
+ * https://learn.microsoft.com/en-us/windows/win32/xaudio2/resource-interchange-file-format--riff-
+ * https://learn.microsoft.com/en-us/previous-versions/windows/hardware/design/dn653308(v=vs.85)
+ * "Multimedia Programming Interface and Data Specifications 1.0" chapter 4
  */
 
 /*
@@ -118,30 +121,112 @@ int	audio_encoding_to_sun (int, int, int
 #define	WAVAUDIO_FILE_MAGIC_FMT		((u_int32_t)0x666d7420)
 #define	WAVAUDIO_FILE_MAGIC_DATA	((u_int32_t)0x64617461)
 
-/* purloined from public Microsoft RIFF docs via sox, mplayer, or directly */
+/* From RFC 2361 */
 #define WAVE_FORMAT_UNKNOWN		(0x)
 #define WAVE_FORMAT_PCM			(0x0001)
 #define WAVE_FORMAT_ADPCM		(0x0002)
 #define WAVE_FORMAT_IEEE_FLOAT		(0x0003)
+#define WAVE_FORMAT_VSELP		(0x0004)
+#define WAVE_FORMAT_IBM_CVSD		(0x0005)
 #define WAVE_FORMAT_ALAW		(0x0006)
 #define WAVE_FORMAT_MULAW		(0x0007)
 #define WAVE_FORMAT_OKI_ADPCM		(0x0010)
 #define WAVE_FORMAT_IMA_ADPCM		(0x0011)
+#define WAVE_FORMAT_MEDIASPACE_ADPCM	(0x0012)
+#define WAVE_FORMAT_SIERRA_ADPCM	(0x0013)
+#define WAVE_FORMAT_G723_ADPCM		(0x0014)
 #define WAVE_FORMAT_DIGISTD		(0x0015)
 #define WAVE_FORMAT_DIGIFIX		(0x0016)
+#define WAVE_FORMAT_DIALOGIC_OKI_ADPCM	(0x0017)
+#define WAVE_FORMAT_MEDIAVISION_ADPCM	(0x0018)
+#define WAVE_FORMAT_CU_CODEC		(0x0019)
+#define WAVE_FORMAT_YAMAHA_ADPCM	(0x0020)
+#define WAVE_FORMAT_SONARC		(0x0021)
+#define WAVE_FORMAT_DSPGROUP_TRUESPEECH	(0x0022)
+#define WAVE_FORMAT_ECHOSC1		(0x0023)
+#define WAVE_FORMAT_AUDIOFILE_AF36	(0x0024)
+#define WAVE_FORMAT_APTX		(0x0025)
+#define WAVE_FORMAT_AUDIOFILE_AF10	(0x0026)
+#define WAVE_FORMAT_PROSODY_1612	(0x0027)
+#define WAVE_FORMAT_LRC			(0x0028)
 #define WAVE_FORMAT_DOLBY_AC2		(0x0030)
 #define WAVE_FORMAT_GSM610		(0x0031)
+#define WAVE_FORMAT_MSNAUDIO		(0x0032)
+#define WAVE_FORMAT_ANTEX_ADPCME	(0x0033)
+#define WAVE_FORMAT_CONTROL_RES_VQLPC	(0x0034)
+#define WAVE_FORMAT_DIGIREAL		(0x0035)
+#define WAVE_FORMAT_DIGIADPCM		(0x0036)
+#define WAVE_FORMAT_CONTROL_RES_CR10	(0x0037)
+#define WAVE_FORMAT_NMS_VBXADPCM	(0x0038)
+#define WAVE_FORMAT_ROLAND_RDAC		(0x0039)
+#define WAVE_FORMAT_ECHOSC3		(0x003a)
 #define WAVE_FORMAT_ROCKWELL_ADPCM	(0x003b)
 #define WAVE_FORMAT_ROCKWELL_DIGITALK	(0x003c)
+#define WAVE_FORMAT_XEBEC		(0x003d)
 #define WAVE_FORMAT_G721_ADPCM		(0x0040)
 #define WAVE_FORMAT_G728_CELP		(0x0041)
+#define WAVE_FORMAT_MSG723		(0x0042)
 #define WAVE_FORMAT_MPEG		(0x0050)
+#define WAVE_FORMAT_RT24		(0x0052)
+#define WAVE_FORMAT_PAC			(0x0053)
 #define WAVE_FORMAT_MPEGLAYER3		(0x0055)
+#define WAVE_FORMAT_LUCENT_G723		(0x0059)
+#define WAVE_FORMAT_CIRRUS		(0x0060)
+#define WAVE_FORMAT_ESPCM		(0x0061)
+#define WAVE_FORMAT_VOXWARE		(0x0062)
+#define WAVE_FORMAT_CANOPUS_ATRAC	(0x0063)
 #define WAVE_FORMAT_G726_ADPCM		(0x0064)
 #define WAVE_FORMAT_G722_ADPCM		(0x0065)
-#define IBM_FORMAT_MULAW		(0x0101)
-#define IBM_FORMAT_ALAW			(0x0102)
-#define IBM_FORMAT_ADPCM		(0x0103)
+#define WAVE_FORMAT_DSAT		(0x0066)
+#define WAVE_FORMAT_DSAT_DISPLAY	(0x0067)
+#define WAVE_FORMAT_VOXWARE_BYTE_ALIGNED (0x0069)
+#define WAVE_FORMAT_VOXWARE_AC8		(0x0070)
+#define 

CVS commit: src/usr.bin/audio/common

2024-03-07 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Mar  8 06:57:59 UTC 2024

Modified Files:
src/usr.bin/audio/common: libaudio.h wav.c

Log Message:
audio_wav_parse_hdr(): avoid buffer overreads and clean up

reimplement most of this function using a new method of buffer
management to ensure that we never read beyond the provided size.

properly handle RIFF chunk lengths, instead of assuming various
offsets from most files are right.

update list of consumed documentation and fill the list of WAVE
formats from RFC 2361 (most remain not supported.)

should fix PR#57973.

tested against a large number of .wav files i have handy and with
a testsuite generator that should be incoming soon.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/audio/common/libaudio.h
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/audio/common/wav.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/audio/play

2024-03-03 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Mar  4 06:29:35 UTC 2024

Modified Files:
src/usr.bin/audio/play: audioplay.1 play.c

Log Message:
audioplay: add -n flag that doesn't write audio data.

this will be used in an upcoming testsuite for the wav parser.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/audio/play/audioplay.1
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/audio/play/play.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/audio/play/audioplay.1
diff -u src/usr.bin/audio/play/audioplay.1:1.33 src/usr.bin/audio/play/audioplay.1:1.34
--- src/usr.bin/audio/play/audioplay.1:1.33	Sun Feb  4 05:43:07 2024
+++ src/usr.bin/audio/play/audioplay.1	Mon Mar  4 06:29:35 2024
@@ -1,6 +1,6 @@
-.\"	$NetBSD: audioplay.1,v 1.33 2024/02/04 05:43:07 mrg Exp $
+.\"	$NetBSD: audioplay.1,v 1.34 2024/03/04 06:29:35 mrg Exp $
 .\"
-.\" Copyright (c) 1998, 1999, 2002, 2010, 2019 Matthew R. Green
+.\" Copyright (c) 1998, 1999, 2002, 2010, 2019, 2024 Matthew R. Green
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd April 10, 2020
+.Dd March 3, 2024
 .Dt AUDIOPLAY 1
 .Os
 .Sh NAME
@@ -32,7 +32,7 @@
 .Nd play audio files
 .Sh SYNOPSIS
 .Nm
-.Op Fl hiqV
+.Op Fl hinqV
 .Op Fl B Ar buffersize
 .Op Fl b Ar balance
 .Op Fl d Ar device
@@ -118,6 +118,8 @@ sample rate.
 Print a help message.
 .It Fl i
 If the audio device cannot be opened, exit now rather than wait for it.
+.It Fl n
+Do not write audio data, only parse files for sanity.
 .It Fl P
 When combined with the
 .Fl f

Index: src/usr.bin/audio/play/play.c
diff -u src/usr.bin/audio/play/play.c:1.63 src/usr.bin/audio/play/play.c:1.64
--- src/usr.bin/audio/play/play.c:1.63	Sat Apr 15 16:54:39 2023
+++ src/usr.bin/audio/play/play.c	Mon Mar  4 06:29:35 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: play.c,v 1.63 2023/04/15 16:54:39 mlelstv Exp $	*/
+/*	$NetBSD: play.c,v 1.64 2024/03/04 06:29:35 mrg Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000, 2001, 2002, 2010, 2015, 2019, 2021 Matthew R. Green
@@ -28,7 +28,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: play.c,v 1.63 2023/04/15 16:54:39 mlelstv Exp $");
+__RCSID("$NetBSD: play.c,v 1.64 2024/03/04 06:29:35 mrg Exp $");
 #endif
 
 #include 
@@ -65,6 +65,7 @@ static int	volume;
 static int	balance;
 static int	port;
 static int	fflag;
+static int	nflag;
 static int	qflag;
 int	verbose;
 static int	sample_rate;
@@ -75,7 +76,7 @@ static int	channels;
 
 static char	const *play_errstring = NULL;
 static size_t	bufsize;
-static int	audiofd;
+static int	audiofd = -1;
 static int	exitstatus = EXIT_SUCCESS;
 
 int
@@ -87,7 +88,7 @@ main(int argc, char *argv[])
 	const char *defdevice = _PATH_SOUND;
 	const char *device = NULL;
 
-	while ((ch = getopt(argc, argv, "b:B:C:c:d:e:fhip:P:qs:Vv:")) != -1) {
+	while ((ch = getopt(argc, argv, "b:B:C:c:d:e:fhinp:P:qs:Vv:")) != -1) {
 		switch (ch) {
 		case 'b':
 			decode_int(optarg, );
@@ -118,6 +119,9 @@ main(int argc, char *argv[])
 		case 'i':
 			iflag++;
 			break;
+		case 'n':
+			nflag++;
+			break;
 		case 'q':
 			qflag++;
 			break;
@@ -173,22 +177,22 @@ main(int argc, char *argv[])
 	(device = getenv("AUDIODEV")) == NULL) /* Sun compatibility */
 		device = defdevice;
 
-	audiofd = open(device, O_WRONLY);
-	if (audiofd < 0 && device == defdevice) {
-		device = _PATH_SOUND0;
+	if (!nflag) {
 		audiofd = open(device, O_WRONLY);
-	}
-
-	if (audiofd < 0)
-		err(1, "failed to open %s", device);
+		if (audiofd < 0 && device == defdevice) {
+			device = _PATH_SOUND0;
+			audiofd = open(device, O_WRONLY);
+		}
+		if (audiofd < 0)
+			err(1, "failed to open %s", device);
 
-	if (ioctl(audiofd, AUDIO_GETINFO, ) < 0)
-		err(1, "failed to get audio info");
-	if (bufsize == 0) {
-		bufsize = info.play.buffer_size;
-		if (bufsize < 32 * 1024)
-			bufsize = 32 * 1024;
+		if (ioctl(audiofd, AUDIO_GETINFO, ) < 0)
+			err(1, "failed to get audio info");
+		if (bufsize == 0)
+			bufsize = info.play.buffer_size;
 	}
+	if (bufsize == 0)
+		bufsize = 32 * 1024;
 
 	signal(SIGINT, cleanup);
 	signal(SIGTERM, cleanup);
@@ -208,9 +212,12 @@ static void
 cleanup(int signo)
 {
 
-	(void)ioctl(audiofd, AUDIO_FLUSH, NULL);
-	(void)ioctl(audiofd, AUDIO_SETINFO, );
-	close(audiofd);
+	if (audiofd != -1) {
+		(void)ioctl(audiofd, AUDIO_FLUSH, NULL);
+		(void)ioctl(audiofd, AUDIO_SETINFO, );
+		close(audiofd);
+		audiofd = -1;
+	}
 	if (signo != 0) {
 		(void)raise_default_signal(signo);
 	}
@@ -283,6 +290,9 @@ audio_write(int fd, void *buf, size_t le
 	static void *convert_buffer;
 	static size_t convert_buffer_size;
 
+	if (nflag)
+		return len;
+
 	if (conv == NULL)
 		return write(fd, buf, len);
 
@@ -317,8 +327,7 @@ play(char *file)
 
 	fd = open(file, O_RDONLY);
 	if (fd < 0) {
-		if (!qflag)
-	

CVS commit: src/usr.bin/audio/play

2024-03-03 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Mar  4 06:29:35 UTC 2024

Modified Files:
src/usr.bin/audio/play: audioplay.1 play.c

Log Message:
audioplay: add -n flag that doesn't write audio data.

this will be used in an upcoming testsuite for the wav parser.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/audio/play/audioplay.1
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/audio/play/play.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/audio/common

2024-02-27 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Feb 27 21:05:34 UTC 2024

Modified Files:
src/usr.bin/audio/common: audio.c decode.c sun.c wav.c

Log Message:
Clean up lines containing only tabs.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/audio/common/audio.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/audio/common/decode.c
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/audio/common/sun.c
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/audio/common/wav.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/audio/common/audio.c
diff -u src/usr.bin/audio/common/audio.c:1.26 src/usr.bin/audio/common/audio.c:1.27
--- src/usr.bin/audio/common/audio.c:1.26	Sat Nov  9 12:46:44 2019
+++ src/usr.bin/audio/common/audio.c	Tue Feb 27 21:05:34 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.26 2019/11/09 12:46:44 mrg Exp $	*/
+/*	$NetBSD: audio.c,v 1.27 2024/02/27 21:05:34 gson Exp $	*/
 
 /*
  * Copyright (c) 1999, 2013, 2015, 2019 Matthew R. Green
@@ -32,7 +32,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: audio.c,v 1.26 2019/11/09 12:46:44 mrg Exp $");
+__RCSID("$NetBSD: audio.c,v 1.27 2024/02/27 21:05:34 gson Exp $");
 #endif
 
 
@@ -205,7 +205,7 @@ write_header(struct track_info *ti)
 
 	veclen = 0;
 	tlen = 0;
-		
+
 	if (hdrlen != 0) {
 		iv[veclen].iov_base = hdr;
 		iv[veclen].iov_len = hdrlen;

Index: src/usr.bin/audio/common/decode.c
diff -u src/usr.bin/audio/common/decode.c:1.1 src/usr.bin/audio/common/decode.c:1.2
--- src/usr.bin/audio/common/decode.c:1.1	Sun Jun 21 06:06:01 2015
+++ src/usr.bin/audio/common/decode.c	Tue Feb 27 21:05:34 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: decode.c,v 1.1 2015/06/21 06:06:01 mrg Exp $	*/
+/*	$NetBSD: decode.c,v 1.2 2024/02/27 21:05:34 gson Exp $	*/
 
 /*
  * Copyright (c) 1999 Matthew R. Green
@@ -29,7 +29,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: decode.c,v 1.1 2015/06/21 06:06:01 mrg Exp $");
+__RCSID("$NetBSD: decode.c,v 1.2 2024/02/27 21:05:34 gson Exp $");
 #endif
 
 #include 
@@ -85,7 +85,7 @@ decode_time(const char *arg, struct time
 
 	tvp->tv_sec = tvp->tv_usec = 0;
 	s = copy;
-	
+
 	/* handle [hh:]mm:ss.dd */
 	if ((colon = strchr(s, ':')) != NULL) {
 		*colon++ = '\0';

Index: src/usr.bin/audio/common/sun.c
diff -u src/usr.bin/audio/common/sun.c:1.10 src/usr.bin/audio/common/sun.c:1.11
--- src/usr.bin/audio/common/sun.c:1.10	Sat Nov  9 12:46:44 2019
+++ src/usr.bin/audio/common/sun.c	Tue Feb 27 21:05:34 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: sun.c,v 1.10 2019/11/09 12:46:44 mrg Exp $	*/
+/*	$NetBSD: sun.c,v 1.11 2024/02/27 21:05:34 gson Exp $	*/
 
 /*
  * Copyright (c) 2002, 2013, 2015 Matthew R. Green
@@ -32,7 +32,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: sun.c,v 1.10 2019/11/09 12:46:44 mrg Exp $");
+__RCSID("$NetBSD: sun.c,v 1.11 2024/02/27 21:05:34 gson Exp $");
 #endif
 
 
@@ -149,7 +149,7 @@ sun_prepare_header(struct track_info *ti
 		break;
 #endif
 	}
-	
+
 	/* if we can't express this as a Sun header, don't write any */
 	if (audio_encoding_to_sun(ti->encoding, ti->precision, ) != 0) {
 		if (!ti->qflag && !warned) {

Index: src/usr.bin/audio/common/wav.c
diff -u src/usr.bin/audio/common/wav.c:1.17 src/usr.bin/audio/common/wav.c:1.18
--- src/usr.bin/audio/common/wav.c:1.17	Tue Feb 27 20:40:29 2024
+++ src/usr.bin/audio/common/wav.c	Tue Feb 27 21:05:34 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: wav.c,v 1.17 2024/02/27 20:40:29 gson Exp $	*/
+/*	$NetBSD: wav.c,v 1.18 2024/02/27 21:05:34 gson Exp $	*/
 
 /*
  * Copyright (c) 2002, 2009, 2013, 2015, 2019 Matthew R. Green
@@ -33,7 +33,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: wav.c,v 1.17 2024/02/27 20:40:29 gson Exp $");
+__RCSID("$NetBSD: wav.c,v 1.18 2024/02/27 21:05:34 gson Exp $");
 #endif
 
 
@@ -374,7 +374,7 @@ wav_prepare_header(struct track_info *ti
 	abps = (double)align*ti->sample_rate / (double)1 + 0.5;
 
 	nsample = (datalen / ti->precision) / ti->sample_rate;
-	
+
 	/*
 	 * now we've calculated the info, write it out!
 	 */



CVS commit: src/usr.bin/audio/common

2024-02-27 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Feb 27 21:05:34 UTC 2024

Modified Files:
src/usr.bin/audio/common: audio.c decode.c sun.c wav.c

Log Message:
Clean up lines containing only tabs.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/audio/common/audio.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/audio/common/decode.c
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/audio/common/sun.c
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/audio/common/wav.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/audio

2024-02-27 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Feb 27 20:40:30 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c
src/usr.bin/audio/record: record.c

Log Message:
Clean up lines containing only spaces.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/audio/common/wav.c
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/audio/record/record.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/audio/common/wav.c
diff -u src/usr.bin/audio/common/wav.c:1.16 src/usr.bin/audio/common/wav.c:1.17
--- src/usr.bin/audio/common/wav.c:1.16	Sat Apr 15 12:39:44 2023
+++ src/usr.bin/audio/common/wav.c	Tue Feb 27 20:40:29 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: wav.c,v 1.16 2023/04/15 12:39:44 mlelstv Exp $	*/
+/*	$NetBSD: wav.c,v 1.17 2024/02/27 20:40:29 gson Exp $	*/
 
 /*
  * Copyright (c) 2002, 2009, 2013, 2015, 2019 Matthew R. Green
@@ -33,7 +33,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: wav.c,v 1.16 2023/04/15 12:39:44 mlelstv Exp $");
+__RCSID("$NetBSD: wav.c,v 1.17 2024/02/27 20:40:29 gson Exp $");
 #endif
 
 
@@ -108,7 +108,7 @@ audio_wav_parse_hdr(void *hdr, size_t sz
 	strRIFF[4] = "RIFF",
 	strWAVE[4] = "WAVE",
 	strdata[4] = "data";
-		
+
 	if (sz < 32)
 		return (AUDIO_ENOENT);
 

Index: src/usr.bin/audio/record/record.c
diff -u src/usr.bin/audio/record/record.c:1.57 src/usr.bin/audio/record/record.c:1.58
--- src/usr.bin/audio/record/record.c:1.57	Sat Apr 15 12:39:44 2023
+++ src/usr.bin/audio/record/record.c	Tue Feb 27 20:40:30 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: record.c,v 1.57 2023/04/15 12:39:44 mlelstv Exp $	*/
+/*	$NetBSD: record.c,v 1.58 2024/02/27 20:40:30 gson Exp $	*/
 
 /*
  * Copyright (c) 1999, 2002, 2003, 2005, 2010 Matthew R. Green
@@ -32,7 +32,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: record.c,v 1.57 2023/04/15 12:39:44 mlelstv Exp $");
+__RCSID("$NetBSD: record.c,v 1.58 2024/02/27 20:40:30 gson Exp $");
 #endif
 
 
@@ -332,7 +332,7 @@ main(int argc, char *argv[])
 			s = "change sign (big-endian, 32 bit)";
 		else if (conv_func == change_sign32_swap_bytes_le)
 			s = "change sign & swap bytes (little-endian, 32 bit)";
-		
+
 		if (s)
 			fprintf(stderr, "%s: converting, using function: %s\n",
 			getprogname(), s);



CVS commit: src/usr.bin/audio

2024-02-27 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Feb 27 20:40:30 UTC 2024

Modified Files:
src/usr.bin/audio/common: wav.c
src/usr.bin/audio/record: record.c

Log Message:
Clean up lines containing only spaces.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/audio/common/wav.c
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/audio/record/record.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/audio/play

2023-06-30 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Fri Jun 30 23:36:48 UTC 2023

Modified Files:
src/usr.bin/audio/play: audioplay.1

Log Message:
audioplay.1: fix sentence punctuation


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/audio/play/audioplay.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/audio/play/audioplay.1
diff -u src/usr.bin/audio/play/audioplay.1:1.31 src/usr.bin/audio/play/audioplay.1:1.32
--- src/usr.bin/audio/play/audioplay.1:1.31	Mon Feb 13 13:35:45 2023
+++ src/usr.bin/audio/play/audioplay.1	Fri Jun 30 23:36:47 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audioplay.1,v 1.31 2023/02/13 13:35:45 uwe Exp $
+.\"	$NetBSD: audioplay.1,v 1.32 2023/06/30 23:36:47 gutteridge Exp $
 .\"
 .\" Copyright (c) 1998, 1999, 2002, 2010, 2019 Matthew R. Green
 .\" All rights reserved.
@@ -175,7 +175,7 @@ files.
 In addition to the audio driver encodings list in the EXAMPLES section,
 .Nm
 supports playing IEEE floating point data in RIFF WAVE audio files
-(with one caveat that the floating point size must be native.)
+(with one caveat that the floating point size must be native).
 In this case
 .Nm
 converts the floating point data into signed linear samples before



CVS commit: src/usr.bin/audio/play

2023-06-30 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Fri Jun 30 23:36:48 UTC 2023

Modified Files:
src/usr.bin/audio/play: audioplay.1

Log Message:
audioplay.1: fix sentence punctuation


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/audio/play/audioplay.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/audio/play

2023-04-15 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Apr 15 16:54:39 UTC 2023

Modified Files:
src/usr.bin/audio/play: play.c

Log Message:
Revert accidentially committed part. The 'latency' report isn't ready
to be useful.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/audio/play/play.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/audio/play/play.c
diff -u src/usr.bin/audio/play/play.c:1.62 src/usr.bin/audio/play/play.c:1.63
--- src/usr.bin/audio/play/play.c:1.62	Sat Apr 15 12:39:44 2023
+++ src/usr.bin/audio/play/play.c	Sat Apr 15 16:54:39 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: play.c,v 1.62 2023/04/15 12:39:44 mlelstv Exp $	*/
+/*	$NetBSD: play.c,v 1.63 2023/04/15 16:54:39 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000, 2001, 2002, 2010, 2015, 2019, 2021 Matthew R. Green
@@ -28,7 +28,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: play.c,v 1.62 2023/04/15 12:39:44 mlelstv Exp $");
+__RCSID("$NetBSD: play.c,v 1.63 2023/04/15 16:54:39 mlelstv Exp $");
 #endif
 
 #include 
@@ -65,7 +65,6 @@ static int	volume;
 static int	balance;
 static int	port;
 static int	fflag;
-static int	lflag;
 static int	qflag;
 int	verbose;
 static int	sample_rate;
@@ -88,7 +87,7 @@ main(int argc, char *argv[])
 	const char *defdevice = _PATH_SOUND;
 	const char *device = NULL;
 
-	while ((ch = getopt(argc, argv, "b:B:C:c:d:e:fhilp:P:qs:Vv:")) != -1) {
+	while ((ch = getopt(argc, argv, "b:B:C:c:d:e:fhip:P:qs:Vv:")) != -1) {
 		switch (ch) {
 		case 'b':
 			decode_int(optarg, );
@@ -119,9 +118,6 @@ main(int argc, char *argv[])
 		case 'i':
 			iflag++;
 			break;
-		case 'l':
-			lflag++;
-			break;
 		case 'q':
 			qflag++;
 			break;
@@ -301,57 +297,6 @@ audio_write(int fd, void *buf, size_t le
 	return write(fd, convert_buffer, len);
 }
 
-/*
- * print audio output offset
- */
-static void
-print_offset(off_t written, int ratelimit)
-{
-	static time_t last;
-	time_t now;
-	static off_t base = 0;
-	static off_t played = 0;
-	off_t bps;
-	audio_offset_t aoff;
-	u_int blocksize;
-
-	if (!lflag)
-		return;
-
-	if (ioctl(audiofd, AUDIO_GETOOFFS, ))
-		return;
-
-	bps = info.play.sample_rate
-	  * info.play.channels
-	  * info.play.precision / NBBY;
-	blocksize = info.blocksize > 0 ? info.blocksize : 1;
-
-	/* Check if aoff.samples overflowed */
-	if (aoff.samples < played) {
-		base += UINT_MAX;
-		base += 1;
-	}
-
-	/* Overflow base + number of samples in completed blocks + offset in currently played block */
-	played = base + aoff.samples + (aoff.offset % blocksize);
-
-	/* Print only every second */
-	if (ratelimit) {
-		time();
-		if (now == last)
-			return;
-		last = now;
-	}
-
-	if (bps > 0) {
-		printf("%jdms\n", (written - played) * 1000 / bps);
-	} else {
-		/* unknown rate, report bytes */
-		printf("%jd\n", written - played);
-	}
-	fflush(stdout);
-}
-
 static void
 play(char *file)
 {
@@ -360,7 +305,7 @@ play(char *file)
 	void *addr, *oaddr;
 	off_t	filesize;
 	size_t	sizet_filesize;
-	off_t datasize = 0, written = 0;
+	off_t datasize = 0;
 	ssize_t	hdrlen;
 	int fd;
 	int nw;
@@ -424,7 +369,6 @@ play(char *file)
 	}
 
 	while ((uint64_t)datasize > bufsize) {
-		print_offset(written, 0);
 		nw = audio_write(audiofd, addr, bufsize, conv);
 		if (nw == -1)
 			err(1, "write failed");
@@ -432,17 +376,13 @@ play(char *file)
 			errx(1, "write failed");
 		addr = (char *)addr + bufsize;
 		datasize -= bufsize;
-		written += nw;
 	}
-	print_offset(written, 0);
 	nw = audio_write(audiofd, addr, datasize, conv);
 	if (nw == -1)
 		err(1, "final write failed");
 	if ((off_t)nw != datasize)
 		errx(1, "final write failed");
-	written += nw;
 
-	print_offset(written, 0);
 	if (ioctl(audiofd, AUDIO_DRAIN) < 0 && !qflag)
 		warn("audio drain ioctl failed");
 	if (munmap(oaddr, sizet_filesize) < 0)
@@ -461,7 +401,7 @@ play_fd(const char *file, int fd)
 	char*buffer = malloc(bufsize);
 	ssize_t hdrlen;
 	int nr, nw;
-	off_t	datasize = 0, written = 0;
+	off_t	datasize = 0;
 	off_t	dataout = 0;
 
 	if (buffer == NULL)
@@ -490,8 +430,6 @@ play_fd(const char *file, int fd)
 		memmove(buffer, buffer + hdrlen, nr - hdrlen);
 		nr -= hdrlen;
 	}
-
-	print_offset(written, 0);
 	while (datasize == 0 || dataout < datasize) {
 		if (datasize != 0 && dataout + nr > datasize)
 			nr = datasize - dataout;
@@ -506,13 +444,10 @@ play_fd(const char *file, int fd)
 			goto read_error;
 		if (nr == 0)
 			break;
-		print_offset(written, 1);
-		written += nw;
 	}
 	/* something to think about: no message given for dataout < datasize */
 	if (ioctl(audiofd, AUDIO_DRAIN) < 0 && !qflag)
 		warn("audio drain ioctl failed");
-	print_offset(written, 0);
 	return;
 read_error:
 	err(1, "read of standard input failed");
@@ -638,8 +573,6 @@ set_audio_mode:
 
 	if (ioctl(fd, AUDIO_SETINFO, ) < 0)
 		err(1, "failed to set audio info");
-	if (ioctl(fd, AUDIO_GETINFO, ) < 0)
-		err(1, 

CVS commit: src/usr.bin/audio/play

2023-04-15 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Apr 15 16:54:39 UTC 2023

Modified Files:
src/usr.bin/audio/play: play.c

Log Message:
Revert accidentially committed part. The 'latency' report isn't ready
to be useful.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/audio/play/play.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/audio

2023-04-15 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Apr 15 12:39:44 UTC 2023

Modified Files:
src/usr.bin/audio/common: auconv.h wav.c
src/usr.bin/audio/play: play.c
src/usr.bin/audio/record: record.c

Log Message:
Add support for recording 24bit wav files.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/audio/common/auconv.h
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/audio/common/wav.c
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/audio/play/play.c
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/audio/record/record.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/audio/common/auconv.h
diff -u src/usr.bin/audio/common/auconv.h:1.5 src/usr.bin/audio/common/auconv.h:1.6
--- src/usr.bin/audio/common/auconv.h:1.5	Mon Apr 28 20:24:12 2008
+++ src/usr.bin/audio/common/auconv.h	Sat Apr 15 12:39:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: auconv.h,v 1.5 2008/04/28 20:24:12 martin Exp $	*/
+/*	$NetBSD: auconv.h,v 1.6 2023/04/15 12:39:44 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -78,6 +78,24 @@ change_sign16_be(u_char *p, int cc)
 }
 
 static inline void
+change_sign24_le(u_char *p, int cc)
+{
+	while ((cc -= 3) >= 0) {
+		p[2] ^= 0x80;
+		p += 3;
+	}
+}
+
+static inline void
+change_sign24_be(u_char *p, int cc)
+{
+	while ((cc -= 3) >= 0) {
+		p[0] ^= 0x80;
+		p += 3;
+	}
+}
+
+static inline void
 change_sign32_le(u_char *p, int cc)
 {
 	while ((cc -= 4) >= 0) {
@@ -163,6 +181,44 @@ change_sign16_swap_bytes_be(u_char *p, i
 }
 
 static inline void
+swap_bytes_change_sign24_le(u_char *p, int cc)
+{
+	u_char t;
+
+	while ((cc -= 3) >= 0) {
+		t = p[2];
+		p[2] = p[0] ^ 0x80;
+		p[0] = t;
+		p += 3;
+	}
+}
+
+static inline void
+swap_bytes_change_sign24_be(u_char *p, int cc)
+{
+	u_char t;
+
+	while ((cc -= 3) >= 0) {
+		t = p[0];
+		p[0] = p[2] ^ 0x80;
+		p[2] = t;
+		p += 3;
+	}
+}
+
+static inline void
+change_sign24_swap_bytes_le(u_char *p, int cc)
+{
+	swap_bytes_change_sign24_be(p, cc);
+}
+
+static inline void
+change_sign24_swap_bytes_be(u_char *p, int cc)
+{
+	swap_bytes_change_sign24_le(p, cc);
+}
+
+static inline void
 swap_bytes_change_sign32_le(u_char *p, int cc)
 {
 	u_char t;

Index: src/usr.bin/audio/common/wav.c
diff -u src/usr.bin/audio/common/wav.c:1.15 src/usr.bin/audio/common/wav.c:1.16
--- src/usr.bin/audio/common/wav.c:1.15	Sat Nov  9 12:46:44 2019
+++ src/usr.bin/audio/common/wav.c	Sat Apr 15 12:39:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: wav.c,v 1.15 2019/11/09 12:46:44 mrg Exp $	*/
+/*	$NetBSD: wav.c,v 1.16 2023/04/15 12:39:44 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 2002, 2009, 2013, 2015, 2019 Matthew R. Green
@@ -33,7 +33,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: wav.c,v 1.15 2019/11/09 12:46:44 mrg Exp $");
+__RCSID("$NetBSD: wav.c,v 1.16 2023/04/15 12:39:44 mlelstv Exp $");
 #endif
 
 
@@ -287,6 +287,8 @@ wav_prepare_header(struct track_info *ti
 		break;
 	case 16:
 		break;
+	case 24:
+		break;
 	case 32:
 		break;
 	default:

Index: src/usr.bin/audio/play/play.c
diff -u src/usr.bin/audio/play/play.c:1.61 src/usr.bin/audio/play/play.c:1.62
--- src/usr.bin/audio/play/play.c:1.61	Sun May 15 02:16:06 2022
+++ src/usr.bin/audio/play/play.c	Sat Apr 15 12:39:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: play.c,v 1.61 2022/05/15 02:16:06 mrg Exp $	*/
+/*	$NetBSD: play.c,v 1.62 2023/04/15 12:39:44 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000, 2001, 2002, 2010, 2015, 2019, 2021 Matthew R. Green
@@ -28,7 +28,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: play.c,v 1.61 2022/05/15 02:16:06 mrg Exp $");
+__RCSID("$NetBSD: play.c,v 1.62 2023/04/15 12:39:44 mlelstv Exp $");
 #endif
 
 #include 
@@ -65,6 +65,7 @@ static int	volume;
 static int	balance;
 static int	port;
 static int	fflag;
+static int	lflag;
 static int	qflag;
 int	verbose;
 static int	sample_rate;
@@ -87,7 +88,7 @@ main(int argc, char *argv[])
 	const char *defdevice = _PATH_SOUND;
 	const char *device = NULL;
 
-	while ((ch = getopt(argc, argv, "b:B:C:c:d:e:fhip:P:qs:Vv:")) != -1) {
+	while ((ch = getopt(argc, argv, "b:B:C:c:d:e:fhilp:P:qs:Vv:")) != -1) {
 		switch (ch) {
 		case 'b':
 			decode_int(optarg, );
@@ -118,6 +119,9 @@ main(int argc, char *argv[])
 		case 'i':
 			iflag++;
 			break;
+		case 'l':
+			lflag++;
+			break;
 		case 'q':
 			qflag++;
 			break;
@@ -297,6 +301,57 @@ audio_write(int fd, void *buf, size_t le
 	return write(fd, convert_buffer, len);
 }
 
+/*
+ * print audio output offset
+ */
+static void
+print_offset(off_t written, int ratelimit)
+{
+	static time_t last;
+	time_t now;
+	static off_t base = 0;
+	static off_t played = 0;
+	off_t bps;
+	audio_offset_t aoff;
+	u_int blocksize;
+
+	if (!lflag)
+		return;
+
+	if (ioctl(audiofd, AUDIO_GETOOFFS, ))
+		return;
+
+	bps = info.play.sample_rate
+	  * info.play.channels
+	  * info.play.precision / NBBY;
+	blocksize = info.blocksize > 0 ? info.blocksize : 1;
+
+	/* 

CVS commit: src/usr.bin/audio

2023-04-15 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Apr 15 12:39:44 UTC 2023

Modified Files:
src/usr.bin/audio/common: auconv.h wav.c
src/usr.bin/audio/play: play.c
src/usr.bin/audio/record: record.c

Log Message:
Add support for recording 24bit wav files.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/audio/common/auconv.h
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/audio/common/wav.c
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/audio/play/play.c
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/audio/record/record.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/audio/play

2023-02-13 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon Feb 13 13:35:45 UTC 2023

Modified Files:
src/usr.bin/audio/play: audioplay.1

Log Message:
audioplay(1): fix typo

>From Jim Spath in PR/57228


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/audio/play/audioplay.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/audio/play/audioplay.1
diff -u src/usr.bin/audio/play/audioplay.1:1.30 src/usr.bin/audio/play/audioplay.1:1.31
--- src/usr.bin/audio/play/audioplay.1:1.30	Fri Apr 10 21:33:27 2020
+++ src/usr.bin/audio/play/audioplay.1	Mon Feb 13 13:35:45 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audioplay.1,v 1.30 2020/04/10 21:33:27 gutteridge Exp $
+.\"	$NetBSD: audioplay.1,v 1.31 2023/02/13 13:35:45 uwe Exp $
 .\"
 .\" Copyright (c) 1998, 1999, 2002, 2010, 2019 Matthew R. Green
 .\" All rights reserved.
@@ -181,7 +181,7 @@ In this case
 converts the floating point data into signed linear samples before
 they are passed to the chosen audio device.
 .Sh ERRORS
-If the audio device or the control device can not be opened, and error is
+If the audio device or the control device can not be opened, an error is
 returned.
 .Pp
 If an invalid parameter is specified, an error is returned.



CVS commit: src/usr.bin/audio/play

2023-02-13 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon Feb 13 13:35:45 UTC 2023

Modified Files:
src/usr.bin/audio/play: audioplay.1

Log Message:
audioplay(1): fix typo

>From Jim Spath in PR/57228


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/audio/play/audioplay.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/audio/play

2022-05-14 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun May 15 02:16:06 UTC 2022

Modified Files:
src/usr.bin/audio/play: play.c

Log Message:
fix verbose log for 64 bit float


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.bin/audio/play/play.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/audio/play/play.c
diff -u src/usr.bin/audio/play/play.c:1.60 src/usr.bin/audio/play/play.c:1.61
--- src/usr.bin/audio/play/play.c:1.60	Mon Nov 11 15:40:42 2019
+++ src/usr.bin/audio/play/play.c	Sun May 15 02:16:06 2022
@@ -1,7 +1,7 @@
-/*	$NetBSD: play.c,v 1.60 2019/11/11 15:40:42 joerg Exp $	*/
+/*	$NetBSD: play.c,v 1.61 2022/05/15 02:16:06 mrg Exp $	*/
 
 /*
- * Copyright (c) 1999, 2000, 2001, 2002, 2010, 2015, 2019 Matthew R. Green
+ * Copyright (c) 1999, 2000, 2001, 2002, 2010, 2015, 2019, 2021 Matthew R. Green
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: play.c,v 1.60 2019/11/11 15:40:42 joerg Exp $");
+__RCSID("$NetBSD: play.c,v 1.61 2022/05/15 02:16:06 mrg Exp $");
 #endif
 
 #include 
@@ -559,7 +559,7 @@ set_audio_mode:
 			if (sizeof(double) * CHAR_BIT != 64)
 return -1;
 			*conv = float64_to_linear32;
-			msg = "32";
+			msg = "64";
 		}
 		info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
 		info.play.precision = 32;



CVS commit: src/usr.bin/audio/play

2022-05-14 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun May 15 02:16:06 UTC 2022

Modified Files:
src/usr.bin/audio/play: play.c

Log Message:
fix verbose log for 64 bit float


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.bin/audio/play/play.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/audio/record

2022-01-08 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jan  9 06:33:13 UTC 2022

Modified Files:
src/usr.bin/audio/record: record.c

Log Message:
Let user gracefully abort recording with SIGINT.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/audio/record/record.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/audio/record

2022-01-08 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jan  9 06:33:13 UTC 2022

Modified Files:
src/usr.bin/audio/record: record.c

Log Message:
Let user gracefully abort recording with SIGINT.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/audio/record/record.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/audio/record/record.c
diff -u src/usr.bin/audio/record/record.c:1.55 src/usr.bin/audio/record/record.c:1.56
--- src/usr.bin/audio/record/record.c:1.55	Tue Jun  1 21:08:48 2021
+++ src/usr.bin/audio/record/record.c	Sun Jan  9 06:33:13 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: record.c,v 1.55 2021/06/01 21:08:48 riastradh Exp $	*/
+/*	$NetBSD: record.c,v 1.56 2022/01/09 06:33:13 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1999, 2002, 2003, 2005, 2010 Matthew R. Green
@@ -32,7 +32,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: record.c,v 1.55 2021/06/01 21:08:48 riastradh Exp $");
+__RCSID("$NetBSD: record.c,v 1.56 2022/01/09 06:33:13 mlelstv Exp $");
 #endif
 
 
@@ -68,6 +68,7 @@ static char	*encoding_str;
 static struct track_info ti;
 static struct timeval record_time;
 static struct timeval start_time;
+static int no_time_limit = 1;
 
 static void (*conv_func) (u_char *, int);
 
@@ -75,6 +76,13 @@ static void usage (void) __dead;
 static int timeleft (struct timeval *, struct timeval *);
 static void cleanup (int) __dead;
 static void rewrite_header (void);
+static void stop (int);
+
+static void stop (int sig)
+{
+	no_time_limit = 0;
+	timerclear(_time);
+}
 
 int
 main(int argc, char *argv[])
@@ -82,7 +90,7 @@ main(int argc, char *argv[])
 	u_char	*buffer;
 	size_t	len, bufsize = 0;
 	ssize_t	nread;
-	int	ch, no_time_limit = 1;
+	int	ch;
 	const char *defdevice = _PATH_SOUND;
 
 	/*
@@ -284,7 +292,7 @@ main(int argc, char *argv[])
 	if (ioctl(audiofd, AUDIO_SETINFO, ) < 0)
 		err(1, "failed to set audio info");
 
-	signal(SIGINT, cleanup);
+	signal(SIGINT, stop);
 
 	ti.total_size = 0;
 
@@ -341,14 +349,12 @@ main(int argc, char *argv[])
 		if ((nread = read(audiofd, buffer, bufsize)) == -1)
 			err(1, "read failed");
 		if (nread == 0)
-			errx(1, "read eof");
-		if ((size_t)nread != bufsize)
-			errx(1, "invalid read");
+			break;
 		if (conv_func)
-			(*conv_func)(buffer, bufsize);
-		if ((size_t)write(ti.outfd, buffer, bufsize) != bufsize)
+			(*conv_func)(buffer, nread);
+		if (write(ti.outfd, buffer, nread) != nread)
 			err(1, "write failed");
-		ti.total_size += bufsize;
+		ti.total_size += nread;
 	}
 	cleanup(0);
 }
@@ -391,7 +397,6 @@ rewrite_header(void)
 	/* can't do this here! */
 	if (ti.outfd == STDOUT_FILENO)
 		return;
-
 	if (lseek(ti.outfd, (off_t)0, SEEK_SET) == (off_t)-1)
 		err(1, "could not seek to start of file for header rewrite");
 	write_header();



CVS commit: src/usr.bin/audio/play

2019-11-12 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Nov 12 12:50:30 UTC 2019

Modified Files:
src/usr.bin/audio/play: audioplay.1

Log Message:
Remove list of audio drivers, moved to audio(4).


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/audio/play/audioplay.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/audio/play/audioplay.1
diff -u src/usr.bin/audio/play/audioplay.1:1.28 src/usr.bin/audio/play/audioplay.1:1.29
--- src/usr.bin/audio/play/audioplay.1:1.28	Mon Nov 11 11:04:15 2019
+++ src/usr.bin/audio/play/audioplay.1	Tue Nov 12 12:50:30 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audioplay.1,v 1.28 2019/11/11 11:04:15 wiz Exp $
+.\"	$NetBSD: audioplay.1,v 1.29 2019/11/12 12:50:30 wiz Exp $
 .\"
 .\" Copyright (c) 1998, 1999, 2002, 2010, 2019 Matthew R. Green
 .\" All rights reserved.
@@ -191,55 +191,7 @@ hardware driver.
 .Sh SEE ALSO
 .Xr audioctl 1 ,
 .Xr audiorecord 1 ,
-.Xr arcofi 4 ,
-.Xr aria 4 ,
-.Xr audio 4 ,
-.Xr auich 4 ,
-.Xr auixp 4 ,
-.\" .Xr ausoc 4 ,
-.Xr autri 4 ,
-.Xr auvia 4 ,
-.Xr bba 4 ,
-.Xr btsco 4 ,
-.Xr clcs 4 ,
-.Xr clct 4 ,
-.Xr cmpci 4 ,
-.Xr dreamcast/aica 4 ,
-.Xr eap 4 ,
-.Xr emuxki 4 ,
-.Xr esm 4 ,
-.Xr eso 4 ,
-.Xr ess 4 ,
-.Xr fms 4 ,
-.Xr gcscaudio 4 ,
-.Xr gus 4 ,
-.Xr guspnp 4 ,
-.Xr hdafg 4 ,
-.Xr hppa/harmony 4 ,
-.Xr macppc/awacs 4 ,
-.Xr macppc/snapper 4 ,
-.Xr neo 4 ,
-.Xr pad 4 ,
-.Xr pas 4 ,
-.\" .Xr paud 4 ,
-.\" .Xr repluse 4 ,
-.Xr sb 4 ,
-.Xr sgimips/haltwo 4 ,
-.Xr sgimips/mavb 4 ,
-.Xr sparc/audioamd 4 ,
-.Xr sparc/dbri 4 ,
-.Xr sv 4 ,
-.\" .Xr toccata 4 ,
-.Xr uaudio 4 ,
-.\" .Xr vaudio 4 ,
-.\" .Xr vcaudio 4 ,
-.\" .Xr vraiu 4 ,
-.\" .Xr vsaudio 4 ,
-.Xr wss 4 ,
-.Xr x68k/vs 4 ,
-.Xr yds 4 ,
-.Xr ym 4
-.\" .Xr zaudio 4
+.Xr audio 4
 .Sh HISTORY
 The
 .Nm



CVS commit: src/usr.bin/audio/play

2019-11-12 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Nov 12 12:50:30 UTC 2019

Modified Files:
src/usr.bin/audio/play: audioplay.1

Log Message:
Remove list of audio drivers, moved to audio(4).


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/audio/play/audioplay.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/audio/play

2019-11-11 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Nov 11 15:40:42 UTC 2019

Modified Files:
src/usr.bin/audio/play: play.c

Log Message:
Spell the largest 32bit signed value as INT32_MAX. Explicitly cast to
float, because it is not precisely representable.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/audio/play/play.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/audio/play

2019-11-11 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Nov 11 15:40:42 UTC 2019

Modified Files:
src/usr.bin/audio/play: play.c

Log Message:
Spell the largest 32bit signed value as INT32_MAX. Explicitly cast to
float, because it is not precisely representable.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/audio/play/play.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/audio/play/play.c
diff -u src/usr.bin/audio/play/play.c:1.59 src/usr.bin/audio/play/play.c:1.60
--- src/usr.bin/audio/play/play.c:1.59	Sat Nov  9 12:54:34 2019
+++ src/usr.bin/audio/play/play.c	Mon Nov 11 15:40:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: play.c,v 1.59 2019/11/09 12:54:34 mrg Exp $	*/
+/*	$NetBSD: play.c,v 1.60 2019/11/11 15:40:42 joerg Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000, 2001, 2002, 2010, 2015, 2019 Matthew R. Green
@@ -28,7 +28,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: play.c,v 1.59 2019/11/09 12:54:34 mrg Exp $");
+__RCSID("$NetBSD: play.c,v 1.60 2019/11/11 15:40:42 joerg Exp $");
 #endif
 
 #include 
@@ -236,7 +236,7 @@ float32_to_linear32(void *inbuf, void *o
 			f = 1.0;
 
 		/* Convert -1.0 to +1.0 into a 32 bit signed value */
-		i = f * ((1u << 31) - 1);
+		i = f * (float)INT32_MAX;
 
 		memcpy(outbuf8, , sizeof i);
 



CVS commit: src/usr.bin/audio/play

2019-11-11 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Nov 11 11:04:15 UTC 2019

Modified Files:
src/usr.bin/audio/play: audioplay.1

Log Message:
Fix a typo. Fix some xrefs, comment out references to non-existing man pages.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/audio/play/audioplay.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/audio/play

2019-11-11 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Nov 11 11:04:15 UTC 2019

Modified Files:
src/usr.bin/audio/play: audioplay.1

Log Message:
Fix a typo. Fix some xrefs, comment out references to non-existing man pages.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/audio/play/audioplay.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/audio/play/audioplay.1
diff -u src/usr.bin/audio/play/audioplay.1:1.27 src/usr.bin/audio/play/audioplay.1:1.28
--- src/usr.bin/audio/play/audioplay.1:1.27	Sat Nov  9 12:46:44 2019
+++ src/usr.bin/audio/play/audioplay.1	Mon Nov 11 11:04:15 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audioplay.1,v 1.27 2019/11/09 12:46:44 mrg Exp $
+.\"	$NetBSD: audioplay.1,v 1.28 2019/11/11 11:04:15 wiz Exp $
 .\"
 .\" Copyright (c) 1998, 1999, 2002, 2010, 2019 Matthew R. Green
 .\" All rights reserved.
@@ -176,7 +176,7 @@ web browser as the program to use when p
 In addition to the audio driver encodings list in the EXAMPLES section,
 .Nm
 supports playing IEEE floating point data in RIFF WAVE audio files
-(with one caveat that the flaoting point size must be native.)
+(with one caveat that the floating point size must be native.)
 In this case
 .Nm
 converts the floating point data into signed linear samples before
@@ -191,23 +191,20 @@ hardware driver.
 .Sh SEE ALSO
 .Xr audioctl 1 ,
 .Xr audiorecord 1 ,
-.Xr aica 4 ,
 .Xr arcofi 4 ,
 .Xr aria 4 ,
 .Xr audio 4 ,
-.Xr audioamd 4 ,
 .Xr auich 4 ,
 .Xr auixp 4 ,
-.Xr ausoc 4 ,
+.\" .Xr ausoc 4 ,
 .Xr autri 4 ,
 .Xr auvia 4 ,
-.Xr awacs 4 ,
 .Xr bba 4 ,
 .Xr btsco 4 ,
 .Xr clcs 4 ,
 .Xr clct 4 ,
 .Xr cmpci 4 ,
-.Xr dbri 4 ,
+.Xr dreamcast/aica 4 ,
 .Xr eap 4 ,
 .Xr emuxki 4 ,
 .Xr esm 4 ,
@@ -217,29 +214,32 @@ hardware driver.
 .Xr gcscaudio 4 ,
 .Xr gus 4 ,
 .Xr guspnp 4 ,
-.Xr haltwo 4 ,
-.Xr harmony 4 ,
 .Xr hdafg 4 ,
-.Xr mavb 4 ,
+.Xr hppa/harmony 4 ,
+.Xr macppc/awacs 4 ,
+.Xr macppc/snapper 4 ,
 .Xr neo 4 ,
 .Xr pad 4 ,
 .Xr pas 4 ,
-.Xr paud 4 ,
-.Xr repluse 4 ,
+.\" .Xr paud 4 ,
+.\" .Xr repluse 4 ,
 .Xr sb 4 ,
-.Xr snapper 4 ,
+.Xr sgimips/haltwo 4 ,
+.Xr sgimips/mavb 4 ,
+.Xr sparc/audioamd 4 ,
+.Xr sparc/dbri 4 ,
 .Xr sv 4 ,
-.Xr toccata 4 ,
+.\" .Xr toccata 4 ,
 .Xr uaudio 4 ,
-.Xr vaudio 4 ,
-.Xr vcaudio 4 ,
-.Xr vraiu 4 ,
-.Xr vs 4 ,
-.Xr vsaudio 4 ,
+.\" .Xr vaudio 4 ,
+.\" .Xr vcaudio 4 ,
+.\" .Xr vraiu 4 ,
+.\" .Xr vsaudio 4 ,
 .Xr wss 4 ,
+.Xr x68k/vs 4 ,
 .Xr yds 4 ,
-.Xr ym 4 ,
-.Xr zaudio 4
+.Xr ym 4
+.\" .Xr zaudio 4
 .Sh HISTORY
 The
 .Nm



CVS commit: src/usr.bin/audio/play

2019-11-09 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Nov  9 12:54:34 UTC 2019

Modified Files:
src/usr.bin/audio/play: play.c

Log Message:
copyright maint.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/audio/play/play.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/audio/play

2019-11-09 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Nov  9 12:54:34 UTC 2019

Modified Files:
src/usr.bin/audio/play: play.c

Log Message:
copyright maint.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/audio/play/play.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/audio/play/play.c
diff -u src/usr.bin/audio/play/play.c:1.58 src/usr.bin/audio/play/play.c:1.59
--- src/usr.bin/audio/play/play.c:1.58	Sat Nov  9 12:46:44 2019
+++ src/usr.bin/audio/play/play.c	Sat Nov  9 12:54:34 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: play.c,v 1.58 2019/11/09 12:46:44 mrg Exp $	*/
+/*	$NetBSD: play.c,v 1.59 2019/11/09 12:54:34 mrg Exp $	*/
 
 /*
- * Copyright (c) 1999, 2000, 2001, 2002, 2010 Matthew R. Green
+ * Copyright (c) 1999, 2000, 2001, 2002, 2010, 2015, 2019 Matthew R. Green
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: play.c,v 1.58 2019/11/09 12:46:44 mrg Exp $");
+__RCSID("$NetBSD: play.c,v 1.59 2019/11/09 12:54:34 mrg Exp $");
 #endif
 
 #include 



CVS commit: src/usr.bin/audio

2019-11-09 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Nov  9 12:46:44 UTC 2019

Modified Files:
src/usr.bin/audio/common: audio.c libaudio.h sun.c wav.c
src/usr.bin/audio/play: audioplay.1 play.c

Log Message:
add support for playing IEEE float32 and float64 RIFF WAVE
samples on platforms that have these types natively, and
can handle signed linear 32 bit samples.  explicitly
disabled on vax, run-or-compile-time sizeof() check
disabled for everyone else

now i can play a float32 .wav file i found.
float64 not tested.

copyright maint, update HISTORY, update audio drivers list.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/audio/common/audio.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/audio/common/libaudio.h
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/audio/common/sun.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/audio/common/wav.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/audio/play/audioplay.1
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/audio/play/play.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/audio

2019-11-09 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Nov  9 12:46:44 UTC 2019

Modified Files:
src/usr.bin/audio/common: audio.c libaudio.h sun.c wav.c
src/usr.bin/audio/play: audioplay.1 play.c

Log Message:
add support for playing IEEE float32 and float64 RIFF WAVE
samples on platforms that have these types natively, and
can handle signed linear 32 bit samples.  explicitly
disabled on vax, run-or-compile-time sizeof() check
disabled for everyone else

now i can play a float32 .wav file i found.
float64 not tested.

copyright maint, update HISTORY, update audio drivers list.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/audio/common/audio.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/audio/common/libaudio.h
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/audio/common/sun.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/audio/common/wav.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/audio/play/audioplay.1
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/audio/play/play.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/audio/common/audio.c
diff -u src/usr.bin/audio/common/audio.c:1.25 src/usr.bin/audio/common/audio.c:1.26
--- src/usr.bin/audio/common/audio.c:1.25	Wed Aug  5 06:54:39 2015
+++ src/usr.bin/audio/common/audio.c	Sat Nov  9 12:46:44 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: audio.c,v 1.25 2015/08/05 06:54:39 mrg Exp $	*/
+/*	$NetBSD: audio.c,v 1.26 2019/11/09 12:46:44 mrg Exp $	*/
 
 /*
- * Copyright (c) 1999 Matthew R. Green
+ * Copyright (c) 1999, 2013, 2015, 2019 Matthew R. Green
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: audio.c,v 1.25 2015/08/05 06:54:39 mrg Exp $");
+__RCSID("$NetBSD: audio.c,v 1.26 2019/11/09 12:46:44 mrg Exp $");
 #endif
 
 
@@ -110,6 +110,8 @@ static const struct {
 	{ AudioEmpeg_l2_packets,AUDIO_ENCODING_MPEG_L2_PACKETS },
 	{ AudioEmpeg_l2_system,	AUDIO_ENCODING_MPEG_L2_SYSTEM },
 	{ AudioEac3,		AUDIO_ENCODING_AC3 },
+	{ "ieee_float32",	AUDIO_ENCODING_LIBAUDIO_FLOAT32 },
+	{ "ieee_float64",	AUDIO_ENCODING_LIBAUDIO_FLOAT64 },
 	{ NULL, -1 }
 };
 

Index: src/usr.bin/audio/common/libaudio.h
diff -u src/usr.bin/audio/common/libaudio.h:1.20 src/usr.bin/audio/common/libaudio.h:1.21
--- src/usr.bin/audio/common/libaudio.h:1.20	Wed Aug  5 06:54:39 2015
+++ src/usr.bin/audio/common/libaudio.h	Sat Nov  9 12:46:44 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: libaudio.h,v 1.20 2015/08/05 06:54:39 mrg Exp $	*/
+/*	$NetBSD: libaudio.h,v 1.21 2019/11/09 12:46:44 mrg Exp $	*/
 
 /*
- * Copyright (c) 1999, 2009 Matthew R. Green
+ * Copyright (c) 1999, 2009, 2013, 2015, 2019 Matthew R. Green
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -37,6 +37,17 @@
 int	audio_format_from_str (char *);
 
 /*
+ * Audio encoding formats; this is a additional to those set
+ * in sys/audioio.h, but with a large offset to avoid future
+ * conflicts (additional ones are libaudio-software only.)
+ *
+ * This is to support floating-point WAV files.  These require
+ * software conversion to a supported format.
+ */
+#define	AUDIO_ENCODING_LIBAUDIO_FLOAT321001	/* 32-bit IEEE FP. */
+#define	AUDIO_ENCODING_LIBAUDIO_FLOAT641002	/* 64-bit IEEE FP. */
+
+/*
  * We copy the Sun/NeXT on-disk audio header format and document what
  * we know of it here.
  *
@@ -107,10 +118,11 @@ int	audio_encoding_to_sun (int, int, int
 #define	WAVAUDIO_FILE_MAGIC_FMT		((u_int32_t)0x666d7420)
 #define	WAVAUDIO_FILE_MAGIC_DATA	((u_int32_t)0x64617461)
 
-/* purloined from public Microsoft RIFF docs via sox or mplayer */
+/* purloined from public Microsoft RIFF docs via sox, mplayer, or directly */
 #define WAVE_FORMAT_UNKNOWN		(0x)
 #define WAVE_FORMAT_PCM			(0x0001)
 #define WAVE_FORMAT_ADPCM		(0x0002)
+#define WAVE_FORMAT_IEEE_FLOAT		(0x0003)
 #define WAVE_FORMAT_ALAW		(0x0006)
 #define WAVE_FORMAT_MULAW		(0x0007)
 #define WAVE_FORMAT_OKI_ADPCM		(0x0010)

Index: src/usr.bin/audio/common/sun.c
diff -u src/usr.bin/audio/common/sun.c:1.9 src/usr.bin/audio/common/sun.c:1.10
--- src/usr.bin/audio/common/sun.c:1.9	Wed Aug  5 06:54:39 2015
+++ src/usr.bin/audio/common/sun.c	Sat Nov  9 12:46:44 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: sun.c,v 1.9 2015/08/05 06:54:39 mrg Exp $	*/
+/*	$NetBSD: sun.c,v 1.10 2019/11/09 12:46:44 mrg Exp $	*/
 
 /*
- * Copyright (c) 2002 Matthew R. Green
+ * Copyright (c) 2002, 2013, 2015 Matthew R. Green
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: sun.c,v 1.9 2015/08/05 06:54:39 mrg Exp $");
+__RCSID("$NetBSD: sun.c,v 1.10 2019/11/09 12:46:44 mrg Exp $");
 #endif
 
 

Index: src/usr.bin/audio/common/wav.c
diff -u src/usr.bin/audio/common/wav.c:1.14 src/usr.bin/audio/common/wav.c:1.15
--- 

Re: CVS commit: src/usr.bin/audio/record

2011-09-22 Thread Marc Balmer

Am 21.09.2011 um 16:32 schrieb Christos Zoulas:

 Module Name:  src
 Committed By: christos
 Date: Wed Sep 21 14:32:14 UTC 2011
 
 Modified Files:
   src/usr.bin/audio/record: record.c
 
 Log Message:
 PR/45384: Henning Petersen: Swapped arguments in lseek
 
 
 To generate a diff of this commit:
 cvs rdiff -u -r1.51 -r1.52 src/usr.bin/audio/record/record.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/audio/record/record.c
 diff -u src/usr.bin/audio/record/record.c:1.51 
 src/usr.bin/audio/record/record.c:1.52
 --- src/usr.bin/audio/record/record.c:1.51Sat Aug 27 21:17:48 2011
 +++ src/usr.bin/audio/record/record.c Wed Sep 21 10:32:14 2011
 @@ -1,4 +1,4 @@
 -/*   $NetBSD: record.c,v 1.51 2011/08/28 01:17:48 joerg Exp $*/
 +/*   $NetBSD: record.c,v 1.52 2011/09/21 14:32:14 christos Exp $ */
 
 /*
  * Copyright (c) 1999, 2002, 2003, 2005, 2010 Matthew R. Green
 @@ -32,7 +32,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
 -__RCSID($NetBSD: record.c,v 1.51 2011/08/28 01:17:48 joerg Exp $);
 +__RCSID($NetBSD: record.c,v 1.52 2011/09/21 14:32:14 christos Exp $);
 #endif
 
 
 @@ -755,7 +755,7 @@
   if (outfd == STDOUT_FILENO)
   return;
 
 - if (lseek(outfd, SEEK_SET, 0)  0)
 + if (lseek(outfd, (off_t)0, SEEK_SET) == (off_t)-1)
   err(1, could not seek to start of file for header rewrite);

Fwiw, this never caused a problem since SEEK_SET is defined 0.  But why is an 
explicit typecast to off_t needed?  Aren't integer cast automatically?


write_header();
 
 }
 


Freundliche GrĂ¼sse,
micro systems

Marc Balmer

--
Marc Balmer
micro systems, Wiesendamm 2a, Postfach, 4019 Basel
fon +41 61 383 05 10, fax +41 61 383 05 12, http://www.msys.ch/



Re: CVS commit: src/usr.bin/audio/record

2011-09-22 Thread Christos Zoulas
In article dbe1242c-f99e-4b75-b356-516245aca...@msys.ch,
Marc Balmer  m...@msys.ch wrote:
  if (outfd == STDOUT_FILENO)
  return;
 
 -if (lseek(outfd, SEEK_SET, 0)  0)
 +if (lseek(outfd, (off_t)0, SEEK_SET) == (off_t)-1)
  err(1, could not seek to start of file for header rewrite);

Fwiw, this never caused a problem since SEEK_SET is defined 0.  But why
is an explicit typecast to off_t needed?  Aren't integer cast
automatically?

It is belt-and-suspenders if the prototype is not in scope.

christos



Re: CVS commit: src/usr.bin/audio/record

2011-09-22 Thread Marc Balmer

Am 22.09.2011 um 19:34 schrieb Christos Zoulas:

 In article dbe1242c-f99e-4b75-b356-516245aca...@msys.ch,
 Marc Balmer  m...@msys.ch wrote:
 if (outfd == STDOUT_FILENO)
 return;
 
 -   if (lseek(outfd, SEEK_SET, 0)  0)
 +   if (lseek(outfd, (off_t)0, SEEK_SET) == (off_t)-1)
 err(1, could not seek to start of file for header rewrite);
 
 Fwiw, this never caused a problem since SEEK_SET is defined 0.  But why
 is an explicit typecast to off_t needed?  Aren't integer cast
 automatically?
 
 It is belt-and-suspenders if the prototype is not in scope.
 

In this case, wouldn't it do the right thing even without a prototype in scope? 
 Would it even compile without a prototype in scope?




Re: CVS commit: src/usr.bin/audio/record

2011-09-22 Thread David Laight
On Thu, Sep 22, 2011 at 09:28:56PM +0200, Marc Balmer wrote:
 
 Am 22.09.2011 um 19:34 schrieb Christos Zoulas:
 
  In article dbe1242c-f99e-4b75-b356-516245aca...@msys.ch,
  Marc Balmer  m...@msys.ch wrote:
if (outfd == STDOUT_FILENO)
return;
  
  - if (lseek(outfd, SEEK_SET, 0)  0)
  + if (lseek(outfd, (off_t)0, SEEK_SET) == (off_t)-1)
err(1, could not seek to start of file for header rewrite);
  
  Fwiw, this never caused a problem since SEEK_SET is defined 0.  But why
  is an explicit typecast to off_t needed?  Aren't integer cast
  automatically?
  
  It is belt-and-suspenders if the prototype is not in scope.
  
 
 In this case, wouldn't it do the right thing even without a
 prototype in scope?

Depends on the architecture.

 Would it even compile without a prototype in scope?

Depends on the compilation options.

Personally I'd compile with the missing prototype being a compile error,
and remove the cast.

David

-- 
David Laight: da...@l8s.co.uk