Re: CVS commit: src/share/man/man4

2021-03-12 Thread Tetsuya Isaki
At Fri, 12 Mar 2021 08:03:24 +,
Nia Alarie wrote:
> Committed By: nia
> Date: Fri Mar 12 08:03:24 UTC 2021
> 
> Modified Files:
>   src/share/man/man4: hdaudio.4
> 
> Log Message:
> Clarify problem.
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.18 -r1.19 src/share/man/man4/hdaudio.4

> @@ -133,5 +133,8 @@
:
> +but these will be converted down to 16-bit before output,  because converting
> +to a hardware precision that isn't a power of two is not yet handled.

This looks incorrect.

MI audio layer synthesizes all streams coming from userland in 16bit,
even if the userland stream has precision higher than 16bit.
MI audio layer can and does handle any precision of underlying
hardware.  For example, the hardware of vraiu(4) on hpcmips (probably)
accepts only 10bit, the hardware of mavb(4) on sgimips (probably)
accepts only 24bit.
If the hardware supports 16bit precision and one or more precision
higher than 16bit like hdafg(4), I think that there is no or less
advantage for MD drivers to choice/support the precision higher than
16bit.

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/share/man/man9

2021-02-08 Thread Tetsuya Isaki
At Sun, 7 Feb 2021 09:22:39 +,
nia wrote:
> > > -It is called at any time.
> > > +It can be called at any time.
> > 
> > The later sounds to me "You(developer of MD driver) can call
> > it at any time".  If so, it's incorrect.
> 
> Maybe "it can be called by the MI layer at any time" is clearer
> here, then? I can change it to that.

That's true, but sounds a bit redundant.
Because these all are callback functions called by the MI layer.

Is there any better text?
The MI layer can(will?) call this in the Opened phase or in the
Closed phase, or even in the Attach phase.  This means, for example,
that you (MD driver) cannot assume that you can prepare(initialize)
something in open() before this (since this can be called in the
Closed phase), and you cannot assume that it has returned from MI
attach (since this can be called in the Attach phase).

> > Is "only" a typo?  or is it better to remove it in English?
> 
> I think it's clear that conversion of other formats is not
> supported by the rest of the paragraph, so it doesn't need to
> be mentioned here, where the primary purpose of the sentence
> is to explain why you don't need to handle conversion in that
> case yourself.

If it's clear for readers, no problem to me.

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/share/man/man9

2021-02-06 Thread Tetsuya Isaki
Hello,

At Sat, 6 Feb 2021 13:55:40 +,
Nia Alarie wrote:
> Module Name:  src
> Committed By: nia
> Date: Sat Feb  6 13:55:40 UTC 2021
> 
> Modified Files:
>   src/share/man/man9: audio.9
> 
> Log Message:
> Fix various typos, etc
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.59 -r1.60 src/share/man/man9/audio.9

> @@ -175,9 +175,9 @@
>  .Vt audio_format_t
>  structure according to given number
>  .Va afp->index .
> -If there is no format with given number, return
> +If there is no format with the given number, return
>  .Er EINVAL .
> -It is called at any time.
> +It can be called at any time.

The later sounds to me "You(developer of MD driver) can call
it at any time".  If so, it's incorrect.

>  Similarly, if the driver supports
>  .Dv SLINEAR_OE:16
>  and the upper layer chooses it,
> -the driver does not need to provide a conversion function.
> -Because the upper layer only supports conversion between
> +the driver does not need to provide a conversion function,
> +because the upper layer supports conversion between

Is "only" a typo?  or is it better to remove it in English?

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys/arch/hppa/gsc

2021-02-04 Thread Tetsuya Isaki
Hello,

At Wed, 3 Feb 2021 13:37:24 -0500,
Michael wrote:
> > Committed By:   isaki
> > Date:   Wed Feb  3 15:13:49 UTC 2021
> > 
> > Modified Files:
> > src/sys/arch/hppa/gsc: harmony.c
> > 
> > Log Message:
> > Fix locking against myself.
> > trigger_output will be called with sc_intr_lock held.
> > From source code review, not tested.
> 
> I just tested this on my C200 - playback works.

Thank you for quick response!

> The sample rate seems off - everything plays too slow, but that's
> probably completely unrelated.

Oops, this was my mistake.
I hope that harmony.c,v 1.9 will fix this problem.
Sorry for breaking it.
---
Tetsuya Isaki 



Re: CVS commit: src/sys/dev/audio

2020-05-30 Thread Tetsuya Isaki
At Fri, 29 May 2020 12:32:39 +,
nia wrote:
> OK... Can you request a pullup to ensure resuming with a stream
> playing doesn't panic on 9.1?

I will do it on next weekend.

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys/dev/audio

2020-05-28 Thread Tetsuya Isaki
At Wed, 27 May 2020 13:19:22 +,
nia wrote:
> I think this is because audio_rmixer_start is used unguarded
> in audio_open (it doesn't check for the sc_rbusy flag).
> This isn't the case for pmixer. 
> 
> So, if the audio device is opened for recording for the 
> first time after system resumption, a panic will occur
> due to an assertion failure (the recording mixer would
> already be busy).

It's because your change didn't restore [pr]mixer's running
state correctly.  I have fixed it.

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys/dev/audio

2020-05-27 Thread Tetsuya Isaki
nia,

At Tue, 26 May 2020 15:20:16 +,
Nia Alarie wrote:
> Module Name:  src
> Committed By: nia
> Date: Tue May 26 15:20:16 UTC 2020
> 
> Modified Files:
>   src/sys/dev/audio: audio.c
> 
> Log Message:
> audio: Only restart recording mixer on resume if it's already been started
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.73 -r1.74 src/sys/dev/audio/audio.c

Why are playback and recording asymmetric?

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-05-01 Thread Tetsuya Isaki
At Fri, 01 May 2020 15:41:14 +1000,
matthew green wrote:
> > > .. I mean, if it's a "tuneable" value like this rather than a constant 
> > > like
> > > __HAVE_SLOW_COMPUTER. :-)
> > 
> > I see.  I like this feeling. (not strong opinion too though)
> > How about you, mrg@?
> 
> works for me.   i like Andrew's argument fo param.h for values
> and types.h for yes/no.

I've commited it.  Thank you!
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-04-30 Thread Tetsuya Isaki
At Wed, 29 Apr 2020 21:59:59 +,
Andrew Doran wrote:
> > > How about this diff?
> > > The old platforms are the same as before, hppa, m68k, sh3, sparc(!64)
> > > and vax.
> > 
> > machine/param.h seems more natural to me.  I don't have a strong opinion
> > though.
> 
> .. I mean, if it's a "tuneable" value like this rather than a constant like
> __HAVE_SLOW_COMPUTER. :-)

I see.  I like this feeling. (not strong opinion too though)
How about you, mrg@?

Thanks,
---
Tetsuya Isaki 

diff --git a/sys/arch/hppa/include/param.h b/sys/arch/hppa/include/param.h
index 39ce45623..69686c405 100644
--- a/sys/arch/hppa/include/param.h
+++ b/sys/arch/hppa/include/param.h
@@ -88,3 +88,8 @@
 
 #define btop(x)((unsigned long)(x) >> PGSHIFT)
 #define ptob(x)((unsigned long)(x) << PGSHIFT)
+
+/* Default audio blocksize in msec.  See sys/dev/audio/audio.c */
+#if defined(_KERNEL)
+#define__AUDIO_BLK_MS (40)
+#endif
diff --git a/sys/arch/m68k/include/param.h b/sys/arch/m68k/include/param.h
index f0bbe169e..ae67a324c 100644
--- a/sys/arch/m68k/include/param.h
+++ b/sys/arch/m68k/include/param.h
@@ -95,4 +95,9 @@
 #definem68k_btop(x)((vaddr_t)(x) >> PGSHIFT)
 #definem68k_ptob(x)((vaddr_t)(x) << PGSHIFT)
 
+/* Default audio blocksize in msec.  See sys/dev/audio/audio.c */
+#if defined(_KERNEL)
+#define__AUDIO_BLK_MS (40)
+#endif
+
 #endif /* !_M68K_PARAM_H_ */
diff --git a/sys/arch/sh3/include/param.h b/sys/arch/sh3/include/param.h
index 547b791f2..66b6d578e 100644
--- a/sys/arch/sh3/include/param.h
+++ b/sys/arch/sh3/include/param.h
@@ -91,4 +91,9 @@
 #defineNKMEMPAGES_MIN_DEFAULT  ((16 * 1024 * 1024) >> PAGE_SHIFT)
 #defineNKMEMPAGES_MAX_DEFAULT  ((128 * 1024 * 1024) >> PAGE_SHIFT)
 
+/* Default audio blocksize in msec.  See sys/dev/audio/audio.c */
+#if defined(_KERNEL)
+#define__AUDIO_BLK_MS (40)
+#endif
+
 #endif /* !_SH3_PARAM_H_ */
diff --git a/sys/arch/sparc/include/param.h b/sys/arch/sparc/include/param.h
index f6112f886..2225a52a2 100644
--- a/sys/arch/sparc/include/param.h
+++ b/sys/arch/sparc/include/param.h
@@ -155,4 +155,7 @@ extern void delay(unsigned int);
 #  define PGSHIFT  pgshift
 #endif
 
+/* Default audio blocksize in msec.  See sys/dev/audio/audio.c */
+#define__AUDIO_BLK_MS (40)
+
 #endif /* _KERNEL || _STANDALONE */
diff --git a/sys/arch/vax/include/param.h b/sys/arch/vax/include/param.h
index 57685709c..f350237b7 100644
--- a/sys/arch/vax/include/param.h
+++ b/sys/arch/vax/include/param.h
@@ -118,6 +118,10 @@ void   delay(int);
 
 #defineDELAY(x) delay(x)
 #defineMAXEXEC 1
+
+/* Default audio blocksize in msec.  See sys/dev/audio/audio.c */
+#define__AUDIO_BLK_MS (40)
+
 #endif /* _KERNEL */
 
 #endif /* _VAX_PARAM_H_ */
diff --git a/sys/dev/audio/audio.c b/sys/dev/audio/audio.c
index 13386ccfb..ef1424d48 100644
--- a/sys/dev/audio/audio.c
+++ b/sys/dev/audio/audio.c
@@ -454,38 +454,25 @@ audio_track_bufstat(audio_track_t *track, struct 
audio_track_debugbuf *buf)
 /*
  * Default hardware blocksize in msec.
  *
- * We use 10 msec for most platforms.  This period is good enough to play
- * audio and video synchronizely.
+ * We use 10 msec for most modern platforms.  This period is good enough to
+ * play audio and video synchronizely.
  * In contrast, for very old platforms, this is usually too short and too
  * severe.  Also such platforms usually can not play video confortably, so
- * it's not so important to make the blocksize shorter.
+ * it's not so important to make the blocksize shorter.  If the platform
+ * defines its own value as __AUDIO_BLK_MS in its , it
+ * uses this instead.
+ *
  * In either case, you can overwrite AUDIO_BLK_MS by your kernel
  * configuration file if you wish.
- *
- * 40 msec was initially choosen for the following reason:
- * (1 / 40ms) = 25 = 5^2.  Thus, the frequency is factored by 5.
- * In this case, the number of frames in a block can be an integer
- * even if the frequency is a multiple of 100 (44100, 48000, etc),
- * or even if 15625Hz (vs(4)).
  */
-#if defined(__hppa__)  || \
-defined(__m68k__)  || \
-defined(__sh3__)   || \
-(defined(__sparc__) && !defined(__sparc64__))  || \
-defined(__vax__)
-#define AUDIO_TOO_SLOW_ARCHS 1
-#endif
-
 #if !defined(AUDIO_BLK_MS)
-# if defined(AUDIO_TOO_SLOW_ARCHS)
-#  define AUDIO_BLK_MS 40
+# if defined(__AUDIO_BLK_MS)
+#  define AUDIO_BLK_MS __AUDIO_BLK_MS
 # else
-#  define AUDIO_BLK_MS 10
+#  define AUDIO_BLK_MS (10)
 # endif
 #endif
 
-#undef AUDIO_TOO_SLOW_ARCHS
-
 /* Device timeout in msec */
 #define AUDIO_TIMEOUT  (3000)
 


Re: CVS commit: src/sys

2020-04-28 Thread Tetsuya Isaki
At Wed, 29 Apr 2020 12:22:01 +0900,
Tetsuya Isaki wrote:
> > i would just put it in types.h called __AUDIO_BLK_MS,
> > and leave a default used in the code if unset.
> It sounds nice.
> I commit once here, and then I will try it.

How about this diff?
The old platforms are the same as before, hppa, m68k, sh3, sparc(!64)
and vax.

Thanks,

--- a/sys/arch/hppa/include/types.h
+++ b/sys/arch/hppa/include/types.h
@@ -103,4 +103,8 @@ extern const char __CONCAT(name,_ras_start[]), 
__CONCAT(name,_ras_end[])
 #define__HAVE_MM_MD_DIRECT_MAPPED_PHYS
 #define__HAVE_MM_MD_KERNACC
 
+#if defined(_KERNEL)
+#define__AUDIO_BLK_MS (40) /* See sys/dev/audio/audio.c */
+#endif
+
 #endif /* _HPPA_TYPES_H_ */
diff --git a/sys/arch/m68k/include/types.h b/sys/arch/m68k/include/types.h
index d8b1347ae..0a581dff0 100644
--- a/sys/arch/m68k/include/types.h
+++ b/sys/arch/m68k/include/types.h
@@ -80,6 +80,7 @@ typedef int   __register_t;
 
 #if defined(_KERNEL)
 #define__HAVE_RAS
+#define__AUDIO_BLK_MS (40) /* See sys/dev/audio/audio.c */
 #endif
 
 #endif /* !_M68K_TYPES_H_ */
diff --git a/sys/arch/sh3/include/types.h b/sys/arch/sh3/include/types.h
index 9a8b247be..f0a8e92d7 100644
--- a/sys/arch/sh3/include/types.h
+++ b/sys/arch/sh3/include/types.h
@@ -79,6 +79,7 @@ typedef   int __register_t;
 
 #if defined(_KERNEL)
 #define__HAVE_RAS
+#define__AUDIO_BLK_MS (40) /* See sys/dev/audio/audio.c */
 #endif
 
 #define__HAVE_CPU_LWP_SETPRIVATE
diff --git a/sys/arch/sparc/include/types.h b/sys/arch/sparc/include/types.h
index 01af19775..360bb069a 100644
--- a/sys/arch/sparc/include/types.h
+++ b/sys/arch/sparc/include/types.h
@@ -141,4 +141,10 @@ typedef unsigned long int  __register_t;
 #define__HAVE_TLS_VARIANT_II
 #define__HAVE_COMMON___TLS_GET_ADDR
 
+#if defined(_KERNEL)
+#if !defined(__arch64__)
+#define__AUDIO_BLK_MS (40) /* See sys/dev/audio/audio.c */
+#endif
+#endif
+
 #endif /* _MACHTYPES_H_ */
diff --git a/sys/arch/vax/include/types.h b/sys/arch/vax/include/types.h
index e49c9db96..8ab482051 100644
--- a/sys/arch/vax/include/types.h
+++ b/sys/arch/vax/include/types.h
@@ -82,6 +82,7 @@ typedef int   __register_t;
 #define__HAVE_OLD_DISKLABEL
 #ifdef _KERNEL
 #define__HAVE_RAS
+#define__AUDIO_BLK_MS (40) /* See sys/dev/audio/audio.c */
 #endif
 
 #define__HAVE___LWP_GETPRIVATE_FAST
diff --git a/sys/dev/audio/audio.c b/sys/dev/audio/audio.c
index 13386ccfb..20a0c6c10 100644
--- a/sys/dev/audio/audio.c
+++ b/sys/dev/audio/audio.c
@@ -183,6 +183,7 @@ __KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.41 2020/01/11 
04:53:10 isaki Exp $");
 #include 
 
 #include 
+#include  /* for __AUDIO_BLK_MS */
 
 #include 
 
@@ -454,38 +455,25 @@ audio_track_bufstat(audio_track_t *track, struct 
audio_track_debugbuf *buf)
 /*
  * Default hardware blocksize in msec.
  *
- * We use 10 msec for most platforms.  This period is good enough to play
- * audio and video synchronizely.
+ * We use 10 msec for most modern platforms.  This period is good enough to
+ * play audio and video synchronizely.
  * In contrast, for very old platforms, this is usually too short and too
  * severe.  Also such platforms usually can not play video confortably, so
- * it's not so important to make the blocksize shorter.
+ * it's not so important to make the blocksize shorter.  If the platform
+ * defines its own value as __AUDIO_BLK_MS in its , it
+ * uses this instead.
+ *
  * In either case, you can overwrite AUDIO_BLK_MS by your kernel
  * configuration file if you wish.
- *
- * 40 msec was initially choosen for the following reason:
- * (1 / 40ms) = 25 = 5^2.  Thus, the frequency is factored by 5.
- * In this case, the number of frames in a block can be an integer
- * even if the frequency is a multiple of 100 (44100, 48000, etc),
- * or even if 15625Hz (vs(4)).
  */
-#if defined(__hppa__)  || \
-defined(__m68k__)  || \
-defined(__sh3__)   || \
-(defined(__sparc__) && !defined(__sparc64__))  || \
-defined(__vax__)
-#define AUDIO_TOO_SLOW_ARCHS 1
-#endif
-
 #if !defined(AUDIO_BLK_MS)
-# if defined(AUDIO_TOO_SLOW_ARCHS)
-#  define AUDIO_BLK_MS 40
+# if defined(__AUDIO_BLK_MS)
+#  define AUDIO_BLK_MS __AUDIO_BLK_MS
 # else
-#  define AUDIO_BLK_MS 10
+#  define AUDIO_BLK_MS (10)
 # endif
 #endif
 
-#undef AUDIO_TOO_SLOW_ARCHS
-
 /* Device timeout in msec */
 #define AUDIO_TIMEOUT  (3000)

---
Tetsuya Isaki 
 


Re: CVS commit: src/sys

2020-04-28 Thread Tetsuya Isaki
At Tue, 28 Apr 2020 05:33:45 +1000,
matthew green wrote:
> i would just put it in types.h called __AUDIO_BLK_MS,
> and leave a default used in the code if unset.

It sounds nice.
I commit once here, and then I will try it.

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-04-28 Thread Tetsuya Isaki
At Mon, 27 Apr 2020 15:58:01 +0200,
Joerg Sonnenberger wrote:
> > Then how about this?
> > (thanks tsutsui@ for comment about choosing archs)
> > This #ifdefs may not look elegance, but I think it's simple and
> > realistic.
> 
> I'd just move it the whole block into audio.c, but otherwise this sounds
> like a good step forward.

Thank you.  I will do so.
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-04-27 Thread Tetsuya Isaki
As a result of some discussion here, adding 60+ one-line header
files like  is troublesome or annoying.
And I have no good idea to generate a suitable border line from
existing parameters or something.

Then how about this?
(thanks tsutsui@ for comment about choosing archs)
This #ifdefs may not look elegance, but I think it's simple and
realistic.

Thanks,

--- a/sys/dev/audio/audiodef.h
+++ b/sys/dev/audio/audiodef.h
@@ -43,9 +43,15 @@
 #define AUMINNOBLK (3)
 
 /*
- * Hardware blocksize in msec.
- * We use 10 msec as default for most platforms.  But it's too severe for
- * most m68k.
+ * Default hardware blocksize in msec.
+ *
+ * We use 10 msec for most platforms.  This period is good enough to play
+ * audio and video synchronizely.
+ * In contrast, for very old platforms, this is usually too short and too
+ * severe.  Also such platforms usually can not play video confortably, so
+ * it's not so important to make the blocksize shorter.
+ * In either case, you can overwrite AUDIO_BLK_MS by your kernel
+ * configuration file if you wish.
  *
  * 40 msec was initially choosen for the following reason:
  * (1 / 40ms) = 25 = 5^2.  Thus, the frequency is factored by 5.
@@ -53,14 +59,24 @@
  * even if the frequency is a multiple of 100 (44100, 48000, etc),
  * or even if 15625Hz (vs(4)).
  */
+#if defined(__hppa__)  || \
+defined(__m68k__)  || \
+defined(__sh3__)   || \
+(defined(__sparc__) && !defined(__sparc64__))  || \
+defined(__vax__)
+#define AUDIO_TOO_SLOW_ARCHS 1
+#endif
+
 #if !defined(AUDIO_BLK_MS)
-# if defined(__m68k__)
+# if defined(AUDIO_TOO_SLOW_ARCHS)
 #  define AUDIO_BLK_MS 40
 # else
 #  define AUDIO_BLK_MS 10
 # endif
 #endif
 
+#undef AUDIO_TOO_SLOW_ARCHS
+
 /*
  * Whether the playback mixer use single buffer mode.
  * It reduces the latency one block but needs machine power.

---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-04-11 Thread Tetsuya Isaki
At Thu, 9 Apr 2020 16:54:12 +0200,
Joerg Sonnenberger wrote:
> There are two possible reasons for a lower limit for the buffer size:
> (1) The device requires a certain amount.
> (2) The system wants to ensure the interrupt rate doesn't go over a
> certain rate.
>
> The real value shouldn't be a constant, but the maximum of the two?

# Thanks for rewording!

I think what you are talking about is not so wrong, but our topics
don't seem the same.

(a1) The audio driver has blk_ms variable (in audio_softc).
 (In fact, blk_ms is not an integer in millisec, is rational number
 though.  But this is not main topic here)

(a2) The initial value of blk_ms is AUDIO_BLK_MS constant defined
 in sys/dev/audio/audiodef.h .
(a3) And you can overwrite AUDIO_BLK_MS in your kernel configuration
 file (if you wish).

(a4) When attaching audio, or when chaning hardware frequency (by
 audiocfg), or when changing blk_ms (by sysctl), the audio layer
 (re-)calculates blocksize (in bytes) from blk_ms and hardware
 frequency.  And audio negotiates the blocksize to MD driver (using
 round_blocksize interface).  Then audio uses obtained blocksize.
 Thus, (as you may know,) audio interrupt period is decided by the
 blocksize, not by HZ.

 # By the way, originally, round_blocksize is not a negotiation
 # interface.  It just "rounds (down or up)" given blocksize.

(a5) However even if the blocksize is agreed between audio layer
 and MD driver, it's different problem that whether the final output
 sound is useful or comfortable by human user.  For example,
 - You may be able to notice out-of-sync between audio and video
   if the blocksize is too large.
 - It may not be able to process audio data within a given interrupt
   period if the blocksize is too small.  This is noticeable on
   older machines.
   Note that MD driver agreed the blocksize but MD driver doesn't
   need to consider the time that audio layer takes to process and
   synthesize tracks on that system.
 This will be a long topic so that I don't go here.

Your (1) looks almost (a4) and it should work.
Your (2) and later looks to me to (a2)/(a4) ?.

I don't intend about lower limit here (If my previous yds example
was bad or shortage in word, it was my fault).
What I intended was default value in (a2) with considering (a5).
Does this help to share the topic?

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-04-09 Thread Tetsuya Isaki
At Fri, 3 Apr 2020 17:51:21 +0200,
Joerg Sonnenberger wrote:
> It seems perfectly
> sensible to me that the final output device can provide a lower limit as
> well as having one derived from HZ and using whatever is higher.

Sorry, I could not translate well and I didn't understand.
Could you write that in another way?

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-04-06 Thread Tetsuya Isaki
At Fri, 3 Apr 2020 17:48:54 +0200, 
Martin Husemann wrote: 
> > I don't think so.  Each driver/hardware may have their specific 
> > restrictions.  Some driver/hardware may be able to set at 1msec 
> > but others may not.  It's nature.  And this is also why we 
> > should not be eager to reduce default blk_ms. 
>  
> What I meant is that the generic audio system may have a way to query 
> the concrete driver(s) in use for a minimum value they support, and then 
> auto-scales the blk_ms appropriately. 

If you are talking about my previous this text, I maybe
misunderstood.
 > On Fri, Apr 03, 2020 at 09:45:20PM +0900, Tetsuya Isaki wrote:
 > >  But I was not able to set 1msec on yds(4) PCI sound card on

In this case, yds(4) is attached at 5msec automatically.
When attaching, audio layer calculates the blocksize from
AUDI_BLK_MS etc and query it to MD driver (this is round_blocksize
in audio(9)).  If the requested size is too small (or too large)
for the MD driver, it will return alternative blocksize.  If audio
layer can accept it, then use it.
Is this right?

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-04-03 Thread Tetsuya Isaki
At Fri, 3 Apr 2020 15:15:36 +0200,
Martin Husemann wrote:
> >  [*] On my alpha (500MHz), wss(4)/ISA works even on blk_ms=1.
> >  But I was not able to set 1msec on yds(4) PCI sound card on
> >  the same machine.  Its lower limit was 5msec (due to driver's
> >  or hardware's restriction, I don't know details though).
> 
> Should we allow the driver to set a lower minimum for this?

(sorry if I misunderstood your text.)
I don't think so.  Each driver/hardware may have their specific
restrictions.  Some driver/hardware may be able to set at 1msec
but others may not.  It's nature.  And this is also why we
should not be eager to reduce default blk_ms.

> Then all m68k and vax drivers could just request (say) 100ms and we are 
> done?

I don't think so.  It breaks MI/MD separation (though the most
drivers on m68k/vax are port-specific).
It's better to handle separately "how long default blk_ms is
better?" and "blocksize driver/hardware supports".

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-04-03 Thread Tetsuya Isaki
At Fri, 3 Apr 2020 06:15:04 -0700,
Jason Thorpe wrote:
> > By the way, I am planning the following.  How about this?
> 
> I very much dislike creating an additional header file for this.

Me too :)  (this is why I haven't done it before)

> I would prefer if the default were tuned for modern systems and overridable 
> by a value exported (in a namespace-appropriate way) by a header that already 
> exists on all platforms.

What header file do you think better?

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-04-03 Thread Tetsuya Isaki
At Sun, 29 Mar 2020 15:11:39 +0200,
Joerg Sonnenberger wrote:
> > CPU load or performance is not subject.  I know that my
> > implementation will work on the most modern real hardware.
> > But I feel that at least 4msec is too rush to be default.
> > A default should not be for one game application.
> 
> I would allow at least 1/HZ as baseline.

Thank you for comment.
Using HZ sounds interesting idea, but unfortunately this will not
make desired results (if what you are talking about can be written
like following).


#if !defined(AUDIO_BLK_MS)
# define AUDIO_BLK_MS (1000 / ((HZ > 1000) ? 1000 : HZ))
#endif


amd64 uses HZ=100 so that blk_ms=10.  It looks good.
alpha uses HZ=1024 (thanks thorpej@).  If we assume upper limit
HZ=1000, then blk_ms=1.  It works [*] but I think that it's a bit
small for default.
m68k often uses HZ=60~100 so that blk_ms=10~16.  This is obviously
too small for m68k default.

 [*] On my alpha (500MHz), wss(4)/ISA works even on blk_ms=1.
 But I was not able to set 1msec on yds(4) PCI sound card on
 the same machine.  Its lower limit was 5msec (due to driver's
 or hardware's restriction, I don't know details though).


By the way, I am planning the following.  How about this?

 dev/audio/audiodef.h 
#include 

#if !defined(AUDIO_BLK_MS)
# if defined(AUDIO_BLK_MS_MACHDEP) // or better name?
   /* Use machine dependent default if specified */
#  define AUDIO_BLK_MS AUDIO_BLK_MS_MACHDEP
# else
   /* Otherwise use MI default */
#  define AUDIO_BLK_MS (10)
# endif
#endif

 arch//include/audio_machdep.h 
/* Use MI default, see dev/audio/audiodef.h */
#undef AUDIO_BLK_MS_MACHDEP

 arch//include/audio_machdep.h 
#define AUDIO_BLK_MS_MACHDEP (100) // for example



Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-03-29 Thread Tetsuya Isaki
At Sat, 28 Mar 2020 10:40:26 +0100,
Martin Husemann wrote:
> It would be good to have a file somewhere in the audio code where the
> default is selected based on some ifdefs - if we don't have anything
> better something like:
> 
> #if defined(__m68k__) || defined(__vax__) || \
>   (defined(__sparc__) && !defined(_LP64)
> 
> #else
> ...   4ms
> #endif
> 
> Or create (if we don't have yet) a  and define it there.

I try it.

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys

2020-03-28 Thread Tetsuya Isaki
At Sat, 28 Mar 2020 09:34:11 +,
nia wrote:
> > - 4msec is (probably no problem for most modern real hardware but)
> >   too aggressive to be default.
> > - 10msec is too severe for antique machines but it's hard to draw a line.
> 
> <5ms blk_ms is required by real world applications; see emulators/mednafen.

If you found such problem, you should have reported it,
rather than changing amd64/conf/GENERIC.

I look emulators/mednafen later.  By the way, blk_ms is fixed at
50msec in netbsd-7 or prior, and is 50msec default (but uncertain)
in netbsd-8.  How was it able to run in those days?

> I would prefer if blk_ms were kept below 5ms on amd64 and aarch64.
> We don't have to worry about the CPU load of playing audio on these platforms.

CPU load or performance is not subject.  I know that my
implementation will work on the most modern real hardware.
But I feel that at least 4msec is too rush to be default.
A default should not be for one game application.

> We also released 9 with blk_ms=4 on these platforms and nobody complained.

If you want to say so, you should have discussed before commit.

9.0-RELEASE/amd64 (blk_ms=4) on VirtualBox6 on OSX plays too bad
sound.  With blk_ms=8, it's almost good but a bit strange.
With blk_ms=10, it's fine.  At least in my environment.

In result, there are two problems.
- You claimed that emulators/mednafen requires blk_ms <= 5msec
- I reported that  VirtualBox6 on OSX requires blk_ms >= 10msec

> > - It's not good idea to set such parameter in individual GENERICs.
> 
> It's not a good idea to punish the majority of NetBSD users because m68k
> is incredibly slow.

As martin pointed out, you seem to misunderstand.
I just dropped m68k from majority.

Thanks,
---
Tetsuya Isaki 



Re: CVS commit: src/share/man/man4

2020-03-18 Thread Tetsuya Isaki
At Mon, 16 Mar 2020 09:20:01 +,
Nia Alarie wrote:
> Committed By: nia
> Date: Mon Mar 16 09:20:01 UTC 2020
> 
> Modified Files:
>   src/share/man/man4: audio.4
> 
> Log Message:
> audio.4: O_NONBLOCK isn't the actual problem

> @@ -818,6 +818,8 @@
> .Xr mmap 2
> it is currently always mapped for writing (playing) due to VM system 
> weirdness.
> .Sh CAVEATS
>-The audio device cannot be reliably used with O_NONBLOCK or event notification
>-mechanisms. Users are generally expected to only read and write a limited 
>number
>-of samples at a time, limiting the time spent in the system call. 
>+The audio device cannot be reliably used with event notification mechanisms
>+such as
>+.Xr poll 2 .
>+Most users are expected to only read and write a limited number of samples at
>+a time, limiting the time spent in the system call. 

What problem of poll() are you talking about?
---
Tetsuya Isaki 


Re: CVS commit: src/share/man/man4

2020-03-17 Thread Tetsuya Isaki
At Tue, 17 Mar 2020 10:50:59 +,
Nia Alarie wrote:
> Module Name:  src
> Committed By: nia
> Date: Tue Mar 17 10:50:59 UTC 2020
> 
> Modified Files:
>   src/share/man/man4: audio.4
> 
> Log Message:
> audio.4: 1-12 channels are only universally supported for playback.
> 
> When a mono recording device is set to use 1 channel, the kernel will
> correct the number of channels back down to 1. This information can be
> obtained with AUDIO_GETINFO...

Please revert and send a bug report if so.
---
Tetsuya Isaki 


CVS commit: src/sys/dev/ic

2019-11-27 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Nov 28 05:07:27 UTC 2019

Modified Files:
src/sys/dev/ic: ac97.c am7990.c

Log Message:
Use NULL for pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/dev/ic/ac97.c
cvs rdiff -u -r1.79 -r1.80 src/sys/dev/ic/am7990.c

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

Modified files:

Index: src/sys/dev/ic/ac97.c
diff -u src/sys/dev/ic/ac97.c:1.98 src/sys/dev/ic/ac97.c:1.99
--- src/sys/dev/ic/ac97.c:1.98	Wed May  8 13:40:18 2019
+++ src/sys/dev/ic/ac97.c	Thu Nov 28 05:07:27 2019
@@ -1,4 +1,4 @@
-/*  $NetBSD: ac97.c,v 1.98 2019/05/08 13:40:18 isaki Exp $ */
+/*  $NetBSD: ac97.c,v 1.99 2019/11/28 05:07:27 isaki Exp $ */
 /*	$OpenBSD: ac97.c,v 1.8 2000/07/19 09:01:35 csapuntz Exp $	*/
 
 /*
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ac97.c,v 1.98 2019/05/08 13:40:18 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ac97.c,v 1.99 2019/11/28 05:07:27 isaki Exp $");
 
 #include 
 #include 
@@ -1691,7 +1691,7 @@ ac97_query_devinfo(struct ac97_codec_if 
 		else if (si->class)
 			name = si->class;
 		else
-			name = 0;
+			name = NULL;
 
 		if (name)
 			strcpy(dip->label.name, name);

Index: src/sys/dev/ic/am7990.c
diff -u src/sys/dev/ic/am7990.c:1.79 src/sys/dev/ic/am7990.c:1.80
--- src/sys/dev/ic/am7990.c:1.79	Tue Jun 26 06:48:00 2018
+++ src/sys/dev/ic/am7990.c	Thu Nov 28 05:07:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: am7990.c,v 1.79 2018/06/26 06:48:00 msaitoh Exp $	*/
+/*	$NetBSD: am7990.c,v 1.80 2019/11/28 05:07:27 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: am7990.c,v 1.79 2018/06/26 06:48:00 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: am7990.c,v 1.80 2019/11/28 05:07:27 isaki Exp $");
 
 #include 
 #include 
@@ -483,7 +483,7 @@ am7990_start(struct ifnet *ifp)
 		}
 
 		IFQ_DEQUEUE(>if_snd, m);
-		if (m == 0)
+		if (m == NULL)
 			break;
 
 		/*



CVS commit: src/sys/dev/ic

2019-11-27 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Nov 28 05:07:27 UTC 2019

Modified Files:
src/sys/dev/ic: ac97.c am7990.c

Log Message:
Use NULL for pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/dev/ic/ac97.c
cvs rdiff -u -r1.79 -r1.80 src/sys/dev/ic/am7990.c

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



CVS commit: src/share/man/man4

2019-11-12 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Nov 13 07:52:25 UTC 2019

Modified Files:
src/share/man/man4: audio.4

Log Message:
Add some audio drivers in SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/share/man/man4/audio.4

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



CVS commit: src/share/man/man4

2019-11-12 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Nov 13 07:52:25 UTC 2019

Modified Files:
src/share/man/man4: audio.4

Log Message:
Add some audio drivers in SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/share/man/man4/audio.4

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

Modified files:

Index: src/share/man/man4/audio.4
diff -u src/share/man/man4/audio.4:1.92 src/share/man/man4/audio.4:1.93
--- src/share/man/man4/audio.4:1.92	Tue Nov 12 12:50:04 2019
+++ src/share/man/man4/audio.4	Wed Nov 13 07:52:25 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.4,v 1.92 2019/11/12 12:50:04 wiz Exp $
+.\"	$NetBSD: audio.4,v 1.93 2019/11/13 07:52:25 isaki Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -757,9 +757,13 @@ string values.
 .Xr mixerctl 1 ,
 .Xr ioctl 2 ,
 .Xr ossaudio 3 ,
+.Xr acorn32/vidcaudio 4 ,
+.\" .Xr amiga/aucc 4 ,
+.\" .Xr amiga/melody 4 ,
 .Xr arcofi 4 ,
 .Xr aria 4 ,
 .Xr auacer 4 ,
+.Xr audiocs 4 ,
 .Xr auich 4 ,
 .Xr auixp 4 ,
 .\" .Xr ausoc 4 ,
@@ -778,6 +782,10 @@ string values.
 .Xr esm 4 ,
 .Xr eso 4 ,
 .Xr ess 4 ,
+.\" .Xr evbarm/aaci 4 ,
+.\" .Xr evbarm/digfilt 4 ,
+.\" .Xr evbarm/pxaacu 4 ,
+.\" .Xr evbarm/udassio 4 ,
 .Xr fms 4 ,
 .Xr gcscaudio 4 ,
 .Xr gus 4 ,



CVS commit: src/sys/dev/audio

2019-11-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Nov  6 13:37:28 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Fix a wrong calculation of recording ring buffer.  Reported on
http://mail-index.netbsd.org/current-users/2019/11/04/msg036976.html


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/audio/audio.c

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



CVS commit: src/sys/dev/audio

2019-11-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Nov  6 13:37:28 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Fix a wrong calculation of recording ring buffer.  Reported on
http://mail-index.netbsd.org/current-users/2019/11/04/msg036976.html


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/audio/audio.c

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.32 src/sys/dev/audio/audio.c:1.33
--- src/sys/dev/audio/audio.c:1.32	Fri Oct 18 04:09:02 2019
+++ src/sys/dev/audio/audio.c	Wed Nov  6 13:37:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.32 2019/10/18 04:09:02 msaitoh Exp $	*/
+/*	$NetBSD: audio.c,v 1.33 2019/11/06 13:37:27 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.32 2019/10/18 04:09:02 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.33 2019/11/06 13:37:27 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4510,7 +4510,7 @@ audio_track_record(audio_track_t *track)
 		int bytes1;
 		int bytes2;
 
-		bytes1 = auring_get_contig_used(usrbuf);
+		bytes1 = auring_get_contig_free(usrbuf);
 		KASSERT(bytes1 % framesize == 0);
 		memcpy((uint8_t *)usrbuf->mem + auring_tail(usrbuf),
 		(uint8_t *)outbuf->mem + outbuf->head * framesize,



CVS commit: src/sys/dev/usb

2019-11-03 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Mon Nov  4 05:46:39 UTC 2019

Modified Files:
src/sys/dev/usb: uaudio.c

Log Message:
Use kmem_zalloc() instead of kmem_alloc() to initialize structure.
struct audio_format added a member since isaki-audio2.
Fix PR kern/54662 "uaudio sometimes not recognized".


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/dev/usb/uaudio.c

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



CVS commit: src/sys/dev/usb

2019-11-03 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Mon Nov  4 05:46:39 UTC 2019

Modified Files:
src/sys/dev/usb: uaudio.c

Log Message:
Use kmem_zalloc() instead of kmem_alloc() to initialize structure.
struct audio_format added a member since isaki-audio2.
Fix PR kern/54662 "uaudio sometimes not recognized".


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/dev/usb/uaudio.c

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

Modified files:

Index: src/sys/dev/usb/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.161 src/sys/dev/usb/uaudio.c:1.162
--- src/sys/dev/usb/uaudio.c:1.161	Thu Jun  6 12:59:33 2019
+++ src/sys/dev/usb/uaudio.c	Mon Nov  4 05:46:39 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.161 2019/06/06 12:59:33 isaki Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.162 2019/11/04 05:46:39 isaki Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.161 2019/06/06 12:59:33 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.162 2019/11/04 05:46:39 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1795,13 +1795,12 @@ uaudio_identify_as(struct uaudio_softc *
 	}
 
 	/* build audio_format array */
-	sc->sc_formats = kmem_alloc(sizeof(struct audio_format) * sc->sc_nalts,
+	sc->sc_formats = kmem_zalloc(sizeof(struct audio_format) * sc->sc_nalts,
 	KM_SLEEP);
 	sc->sc_nformats = sc->sc_nalts;
 	for (i = 0; i < sc->sc_nalts; i++) {
 		auf = >sc_formats[i];
 		t1desc = sc->sc_alts[i].asf1desc;
-		auf->driver_data = NULL;
 		if (UE_GET_DIR(sc->sc_alts[i].edesc->bEndpointAddress) == UE_DIR_OUT)
 			auf->mode = AUMODE_PLAY;
 		else



CVS commit: src

2019-11-03 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Nov  3 11:13:46 UTC 2019

Modified Files:
src/lib/libossaudio: ossaudio.c
src/sys/compat/ossaudio: ossaudio.c

Log Message:
Use record field for recording even on
SNDCTL_DSP_STEREO, SNDCTL_DSP_SETFMT, and SNDCTL_DSP_CHANNELS.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libossaudio/ossaudio.c
cvs rdiff -u -r1.77 -r1.78 src/sys/compat/ossaudio/ossaudio.c

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

Modified files:

Index: src/lib/libossaudio/ossaudio.c
diff -u src/lib/libossaudio/ossaudio.c:1.37 src/lib/libossaudio/ossaudio.c:1.38
--- src/lib/libossaudio/ossaudio.c:1.37	Sat Nov  2 11:48:23 2019
+++ src/lib/libossaudio/ossaudio.c	Sun Nov  3 11:13:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ossaudio.c,v 1.37 2019/11/02 11:48:23 isaki Exp $	*/
+/*	$NetBSD: ossaudio.c,v 1.38 2019/11/03 11:13:45 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: ossaudio.c,v 1.37 2019/11/02 11:48:23 isaki Exp $");
+__RCSID("$NetBSD: ossaudio.c,v 1.38 2019/11/03 11:13:45 isaki Exp $");
 
 /*
  * This is an OSS (Linux) sound API emulator.
@@ -57,6 +57,10 @@ __RCSID("$NetBSD: ossaudio.c,v 1.37 2019
 #define TO_OSSVOL(x)	(((x) * 100 + 127) / 255)
 #define FROM_OSSVOL(x)	x) > 100 ? 100 : (x)) * 255 + 50) / 100)
 
+#define GETPRINFO(info, name)	\
+	(((info)->mode == AUMODE_RECORD) \
+	? (info)->record.name : (info)->play.name)
+
 static struct audiodevinfo *getdevinfo(int);
 
 static void setblocksize(int, struct audio_info *);
@@ -104,6 +108,8 @@ audio_ioctl(int fd, unsigned long com, v
 	char version[32] = "4.01";
 	char license[16] = "NetBSD";
 	u_int u;
+	u_int encoding;
+	u_int precision;
 	int idat, idata;
 	int retval;
 	int i;
@@ -134,10 +140,7 @@ audio_ioctl(int fd, unsigned long com, v
 		retval = ioctl(fd, AUDIO_GETBUFINFO, );
 		if (retval < 0)
 			return retval;
-		if (tmpinfo.mode == AUMODE_RECORD)
-			INTARG = tmpinfo.record.sample_rate;
-		else
-			INTARG = tmpinfo.play.sample_rate;
+		INTARG = GETPRINFO(, sample_rate);
 		break;
 	case SNDCTL_DSP_STEREO:
 		AUDIO_INITINFO();
@@ -147,7 +150,7 @@ audio_ioctl(int fd, unsigned long com, v
 		retval = ioctl(fd, AUDIO_GETBUFINFO, );
 		if (retval < 0)
 			return retval;
-		INTARG = tmpinfo.play.channels - 1;
+		INTARG = GETPRINFO(, channels) - 1;
 		break;
 	case SNDCTL_DSP_GETBLKSIZE:
 		retval = ioctl(fd, AUDIO_GETBUFINFO, );
@@ -246,7 +249,9 @@ audio_ioctl(int fd, unsigned long com, v
 		retval = ioctl(fd, AUDIO_GETBUFINFO, );
 		if (retval < 0)
 			return retval;
-		switch (tmpinfo.play.encoding) {
+		encoding = GETPRINFO(, encoding);
+		precision = GETPRINFO(, precision);
+		switch (encoding) {
 		case AUDIO_ENCODING_ULAW:
 			idat = AFMT_MU_LAW;
 			break;
@@ -254,33 +259,33 @@ audio_ioctl(int fd, unsigned long com, v
 			idat = AFMT_A_LAW;
 			break;
 		case AUDIO_ENCODING_SLINEAR_LE:
-			if (tmpinfo.play.precision == 32)
+			if (precision == 32)
 idat = AFMT_S32_LE;
-			else if (tmpinfo.play.precision == 24)
+			else if (precision == 24)
 idat = AFMT_S24_LE;
-			else if (tmpinfo.play.precision == 16)
+			else if (precision == 16)
 idat = AFMT_S16_LE;
 			else
 idat = AFMT_S8;
 			break;
 		case AUDIO_ENCODING_SLINEAR_BE:
-			if (tmpinfo.play.precision == 32)
+			if (precision == 32)
 idat = AFMT_S32_BE;
-			else if (tmpinfo.play.precision == 24)
+			else if (precision == 24)
 idat = AFMT_S24_BE;
-			else if (tmpinfo.play.precision == 16)
+			else if (precision == 16)
 idat = AFMT_S16_BE;
 			else
 idat = AFMT_S8;
 			break;
 		case AUDIO_ENCODING_ULINEAR_LE:
-			if (tmpinfo.play.precision == 16)
+			if (precision == 16)
 idat = AFMT_U16_LE;
 			else
 idat = AFMT_U8;
 			break;
 		case AUDIO_ENCODING_ULINEAR_BE:
-			if (tmpinfo.play.precision == 16)
+			if (precision == 16)
 idat = AFMT_U16_BE;
 			else
 idat = AFMT_U8;
@@ -306,7 +311,7 @@ audio_ioctl(int fd, unsigned long com, v
 		retval = ioctl(fd, AUDIO_GETBUFINFO, );
 		if (retval < 0)
 			return retval;
-		INTARG = tmpinfo.play.channels;
+		INTARG = GETPRINFO(, channels);
 		break;
 	case SOUND_PCM_WRITE_FILTER:
 	case SOUND_PCM_READ_FILTER:

Index: src/sys/compat/ossaudio/ossaudio.c
diff -u src/sys/compat/ossaudio/ossaudio.c:1.77 src/sys/compat/ossaudio/ossaudio.c:1.78
--- src/sys/compat/ossaudio/ossaudio.c:1.77	Sat Nov  2 11:56:34 2019
+++ src/sys/compat/ossaudio/ossaudio.c	Sun Nov  3 11:13:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ossaudio.c,v 1.77 2019/11/02 11:56:34 isaki Exp $	*/
+/*	$NetBSD: ossaudio.c,v 1.78 2019/11/03 11:13:46 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ossaudio.c,v 1.77 2019/11/02 11:56:34 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ossaudio.c,v 1.78 2019/11/03 11:13:46 isaki Exp $");
 
 #include 

CVS commit: src

2019-11-03 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Nov  3 11:13:46 UTC 2019

Modified Files:
src/lib/libossaudio: ossaudio.c
src/sys/compat/ossaudio: ossaudio.c

Log Message:
Use record field for recording even on
SNDCTL_DSP_STEREO, SNDCTL_DSP_SETFMT, and SNDCTL_DSP_CHANNELS.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libossaudio/ossaudio.c
cvs rdiff -u -r1.77 -r1.78 src/sys/compat/ossaudio/ossaudio.c

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



CVS commit: src/sys/compat/ossaudio

2019-11-02 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Nov  2 11:56:34 UTC 2019

Modified Files:
src/sys/compat/ossaudio: ossaudio.c

Log Message:
Use record.sample_rate for recording on SNDCTL_DSP_SPEED.
It's kernel side of PR lib/54667.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/compat/ossaudio/ossaudio.c

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

Modified files:

Index: src/sys/compat/ossaudio/ossaudio.c
diff -u src/sys/compat/ossaudio/ossaudio.c:1.76 src/sys/compat/ossaudio/ossaudio.c:1.77
--- src/sys/compat/ossaudio/ossaudio.c:1.76	Thu Sep 26 01:37:52 2019
+++ src/sys/compat/ossaudio/ossaudio.c	Sat Nov  2 11:56:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ossaudio.c,v 1.76 2019/09/26 01:37:52 christos Exp $	*/
+/*	$NetBSD: ossaudio.c,v 1.77 2019/11/02 11:56:34 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ossaudio.c,v 1.76 2019/09/26 01:37:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ossaudio.c,v 1.77 2019/11/02 11:56:34 isaki Exp $");
 
 #include 
 #include 
@@ -238,7 +238,10 @@ oss_ioctl_audio(struct lwp *l, const str
 			 __func__, error));
 			goto out;
 		}
-		idat = tmpinfo.play.sample_rate;
+		if (tmpinfo.mode == AUMODE_RECORD)
+			idat = tmpinfo.record.sample_rate;
+		else
+			idat = tmpinfo.play.sample_rate;
 		DPRINTF(("%s: SNDCTL_PCM_READ_RATE < %d\n", __func__, idat));
 		error = copyout(, SCARG(uap, data), sizeof idat);
 		if (error) {



CVS commit: src/sys/compat/ossaudio

2019-11-02 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Nov  2 11:56:34 UTC 2019

Modified Files:
src/sys/compat/ossaudio: ossaudio.c

Log Message:
Use record.sample_rate for recording on SNDCTL_DSP_SPEED.
It's kernel side of PR lib/54667.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/compat/ossaudio/ossaudio.c

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



CVS commit: src/lib/libossaudio

2019-11-02 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Nov  2 11:48:23 UTC 2019

Modified Files:
src/lib/libossaudio: ossaudio.c

Log Message:
Use record.sample_rate for recording on SNDCTL_DSP_SPEED.
Fix PR lib/54667.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/libossaudio/ossaudio.c

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



CVS commit: src/lib/libossaudio

2019-11-02 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Nov  2 11:48:23 UTC 2019

Modified Files:
src/lib/libossaudio: ossaudio.c

Log Message:
Use record.sample_rate for recording on SNDCTL_DSP_SPEED.
Fix PR lib/54667.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/libossaudio/ossaudio.c

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

Modified files:

Index: src/lib/libossaudio/ossaudio.c
diff -u src/lib/libossaudio/ossaudio.c:1.36 src/lib/libossaudio/ossaudio.c:1.37
--- src/lib/libossaudio/ossaudio.c:1.36	Sat Feb  2 04:52:16 2019
+++ src/lib/libossaudio/ossaudio.c	Sat Nov  2 11:48:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ossaudio.c,v 1.36 2019/02/02 04:52:16 isaki Exp $	*/
+/*	$NetBSD: ossaudio.c,v 1.37 2019/11/02 11:48:23 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: ossaudio.c,v 1.36 2019/02/02 04:52:16 isaki Exp $");
+__RCSID("$NetBSD: ossaudio.c,v 1.37 2019/11/02 11:48:23 isaki Exp $");
 
 /*
  * This is an OSS (Linux) sound API emulator.
@@ -134,7 +134,10 @@ audio_ioctl(int fd, unsigned long com, v
 		retval = ioctl(fd, AUDIO_GETBUFINFO, );
 		if (retval < 0)
 			return retval;
-		INTARG = tmpinfo.play.sample_rate;
+		if (tmpinfo.mode == AUMODE_RECORD)
+			INTARG = tmpinfo.record.sample_rate;
+		else
+			INTARG = tmpinfo.play.sample_rate;
 		break;
 	case SNDCTL_DSP_STEREO:
 		AUDIO_INITINFO();



CVS commit: src/sys/dev/audio

2019-09-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Sep  6 06:44:45 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Tune some debug message level.
These messages are important for debugging hardware driver.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/audio/audio.c

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



CVS commit: src/sys/dev/audio

2019-09-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Sep  6 06:44:45 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Tune some debug message level.
These messages are important for debugging hardware driver.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/audio/audio.c

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.30 src/sys/dev/audio/audio.c:1.31
--- src/sys/dev/audio/audio.c:1.30	Thu Aug 29 13:01:07 2019
+++ src/sys/dev/audio/audio.c	Fri Sep  6 06:44:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.30 2019/08/29 13:01:07 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.31 2019/09/06 06:44:45 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.30 2019/08/29 13:01:07 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.31 2019/09/06 06:44:45 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4621,7 +4621,7 @@ audio_mixer_init(struct audio_softc *sc,
 		audio_params_t p = format2_to_params(>hwbuf.fmt);
 		rounded = sc->hw_if->round_blocksize(sc->hw_hdl, blksize,
 		mode, );
-		TRACE(2, "round_blocksize %d -> %d", blksize, rounded);
+		TRACE(1, "round_blocksize %d -> %d", blksize, rounded);
 		if (rounded != blksize) {
 			if ((rounded * NBBY) % (mixer->hwbuf.fmt.stride *
 			mixer->hwbuf.fmt.channels) != 0) {
@@ -4646,7 +4646,7 @@ audio_mixer_init(struct audio_softc *sc,
 		size_t rounded;
 		rounded = sc->hw_if->round_buffersize(sc->hw_hdl, mode,
 		bufsize);
-		TRACE(2, "round_buffersize %zd -> %zd", bufsize, rounded);
+		TRACE(1, "round_buffersize %zd -> %zd", bufsize, rounded);
 		if (rounded < bufsize) {
 			/* buffersize needs NBLKHW blocks at least. */
 			device_printf(sc->sc_dev,
@@ -4669,7 +4669,7 @@ audio_mixer_init(struct audio_softc *sc,
 			capacity = mixer->frames_per_block * hwblks;
 		}
 	}
-	TRACE(2, "buffersize for %s = %zu",
+	TRACE(1, "buffersize for %s = %zu",
 	(mode == AUMODE_PLAY) ? "playback" : "recording",
 	bufsize);
 	mixer->hwbuf.capacity = capacity;



CVS commit: src/sys/dev/audio

2019-08-29 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Aug 29 13:01:07 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c audiovar.h

Log Message:
Fix lock assertion on async I/O mode.
psignal() must be called without any spin locks.
Thanks maxv@!


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/audio/audiovar.h

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.29 src/sys/dev/audio/audio.c:1.30
--- src/sys/dev/audio/audio.c:1.29	Fri Aug 23 09:41:26 2019
+++ src/sys/dev/audio/audio.c	Thu Aug 29 13:01:07 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.29 2019/08/23 09:41:26 maxv Exp $	*/
+/*	$NetBSD: audio.c,v 1.30 2019/08/29 13:01:07 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.29 2019/08/23 09:41:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.30 2019/08/29 13:01:07 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -5730,6 +5730,36 @@ audio_track_drain(struct audio_softc *sc
 }
 
 /*
+ * Send signal to process.
+ * This is intended to be called only from audio_softintr_{rd,wr}.
+ * Must be called with sc_lock && sc_intr_lock held.
+ */
+static inline void
+audio_psignal(struct audio_softc *sc, pid_t pid, int signum)
+{
+	proc_t *p;
+
+	KASSERT(mutex_owned(sc->sc_lock));
+	KASSERT(mutex_owned(sc->sc_intr_lock));
+	KASSERT(pid != 0);
+
+	/*
+	 * psignal() must be called without spin lock held.
+	 * So leave intr_lock temporarily here.
+	 */
+	mutex_exit(sc->sc_intr_lock);
+
+	mutex_enter(proc_lock);
+	p = proc_find(pid);
+	if (p)
+		psignal(p, signum);
+	mutex_exit(proc_lock);
+
+	/* Enter intr_lock again */
+	mutex_enter(sc->sc_intr_lock);
+}
+
+/*
  * This is software interrupt handler for record.
  * It is called from recording hardware interrupt everytime.
  * It does:
@@ -5747,7 +5777,6 @@ audio_softintr_rd(void *cookie)
 {
 	struct audio_softc *sc = cookie;
 	audio_file_t *f;
-	proc_t *p;
 	pid_t pid;
 
 	mutex_enter(sc->sc_lock);
@@ -5767,10 +5796,7 @@ audio_softintr_rd(void *cookie)
 		pid = f->async_audio;
 		if (pid != 0) {
 			TRACEF(4, f, "sending SIGIO %d", pid);
-			mutex_enter(proc_lock);
-			if ((p = proc_find(pid)) != NULL)
-psignal(p, SIGIO);
-			mutex_exit(proc_lock);
+			audio_psignal(sc, pid, SIGIO);
 		}
 	}
 	mutex_exit(sc->sc_intr_lock);
@@ -5799,7 +5825,6 @@ audio_softintr_wr(void *cookie)
 	struct audio_softc *sc = cookie;
 	audio_file_t *f;
 	bool found;
-	proc_t *p;
 	pid_t pid;
 
 	TRACE(4, "called");
@@ -5826,14 +5851,13 @@ audio_softintr_wr(void *cookie)
 		 */
 		if (track->usrbuf.used <= track->usrbuf_usedlow &&
 		!track->is_pause) {
+			/* For selnotify */
 			found = true;
+			/* For SIGIO */
 			pid = f->async_audio;
 			if (pid != 0) {
 TRACEF(4, f, "sending SIGIO %d", pid);
-mutex_enter(proc_lock);
-if ((p = proc_find(pid)) != NULL)
-	psignal(p, SIGIO);
-mutex_exit(proc_lock);
+audio_psignal(sc, pid, SIGIO);
 			}
 		}
 	}

Index: src/sys/dev/audio/audiovar.h
diff -u src/sys/dev/audio/audiovar.h:1.4 src/sys/dev/audio/audiovar.h:1.5
--- src/sys/dev/audio/audiovar.h:1.4	Wed Jun 26 06:57:45 2019
+++ src/sys/dev/audio/audiovar.h	Thu Aug 29 13:01:07 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiovar.h,v 1.4 2019/06/26 06:57:45 isaki Exp $	*/
+/*	$NetBSD: audiovar.h,v 1.5 2019/08/29 13:01:07 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -149,7 +149,8 @@ struct audio_softc {
 
 	/*
 	 * List of opened descriptors.
-	 * Must be protected by sc_intr_lock.
+	 * Must be protected by sc_lock || sc_intr_lock for traversal(FOREACH).
+	 * Must be protected by sc_lock && sc_intr_lock for insertion/removal.
 	 */
 	SLIST_HEAD(, audio_file) sc_files;
 



CVS commit: src/sys/dev/audio

2019-08-29 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Aug 29 13:01:07 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c audiovar.h

Log Message:
Fix lock assertion on async I/O mode.
psignal() must be called without any spin locks.
Thanks maxv@!


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/audio/audiovar.h

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;



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.



CVS commit: src/sbin/disklabel

2019-08-02 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug  3 04:21:37 UTC 2019

Modified Files:
src/sbin/disklabel: main.c

Log Message:
Fix a trivial wrong comment.  x68k's arch is not m68010.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sbin/disklabel/main.c

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



CVS commit: src/sbin/disklabel

2019-08-02 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug  3 04:21:37 UTC 2019

Modified Files:
src/sbin/disklabel: main.c

Log Message:
Fix a trivial wrong comment.  x68k's arch is not m68010.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sbin/disklabel/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/sbin/disklabel/main.c
diff -u src/sbin/disklabel/main.c:1.52 src/sbin/disklabel/main.c:1.53
--- src/sbin/disklabel/main.c:1.52	Wed Jul  3 07:05:27 2019
+++ src/sbin/disklabel/main.c	Sat Aug  3 04:21:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.52 2019/07/03 07:05:27 mlelstv Exp $	*/
+/*	$NetBSD: main.c,v 1.53 2019/08/03 04:21:37 isaki Exp $	*/
 
 /*
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 19
 static char sccsid[] = "@(#)disklabel.c	8.4 (Berkeley) 5/4/95";
 /* from static char sccsid[] = "@(#)disklabel.c	1.2 (Symmetric) 11/28/85"; */
 #else
-__RCSID("$NetBSD: main.c,v 1.52 2019/07/03 07:05:27 mlelstv Exp $");
+__RCSID("$NetBSD: main.c,v 1.53 2019/08/03 04:21:37 isaki Exp $");
 #endif
 #endif	/* not lint */
 
@@ -220,7 +220,7 @@ static const struct disklabel_params {
 	{ "pmax",	0, 0,  8, 2, 0,  64, LITTLE_ENDIAN },	/* mips */
 	{ "sun2",	0, 0,  8, 2, 0,  64, BIG_ENDIAN },	/* m68k */
 	{ "sun68k",	0, 0,  8, 2, 0,  64, BIG_ENDIAN },	/* m68010 */
-	{ "x68k",	0, 0,  8, 2, 0,  64, BIG_ENDIAN },	/* m68010 */
+	{ "x68k",	0, 0,  8, 2, 0,  64, BIG_ENDIAN },	/* m68k */
 
 	{ "vax",	0, 0, 12, 2, 8,  64, LITTLE_ENDIAN },	/* vax */
 



CVS commit: src/sys/dev/audio

2019-07-10 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jul 10 13:26:47 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Use kmem_alloc/free() instead of old kern_malloc/free().


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/audio/audio.c

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.27 src/sys/dev/audio/audio.c:1.28
--- src/sys/dev/audio/audio.c:1.27	Wed Jul 10 13:17:57 2019
+++ src/sys/dev/audio/audio.c	Wed Jul 10 13:26:47 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.27 2019/07/10 13:17:57 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.28 2019/07/10 13:26:47 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.27 2019/07/10 13:17:57 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28 2019/07/10 13:26:47 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4685,13 +4685,7 @@ audio_mixer_init(struct audio_softc *sc,
 			return ENOMEM;
 		}
 	} else {
-		mixer->hwbuf.mem = kern_malloc(bufsize, M_NOWAIT);
-		if (mixer->hwbuf.mem == NULL) {
-			device_printf(sc->sc_dev,
-			"%s: malloc hwbuf(%zu) failed\n",
-			__func__, bufsize);
-			return ENOMEM;
-		}
+		mixer->hwbuf.mem = kmem_alloc(bufsize, KM_SLEEP);
 	}
 
 	/* From here, audio_mixer_destroy is necessary to exit. */
@@ -4811,7 +4805,7 @@ audio_mixer_destroy(struct audio_softc *
 		if (sc->hw_if->freem) {
 			sc->hw_if->freem(sc->hw_hdl, mixer->hwbuf.mem, bufsize);
 		} else {
-			kern_free(mixer->hwbuf.mem);
+			kmem_free(mixer->hwbuf.mem, bufsize);
 		}
 		mixer->hwbuf.mem = NULL;
 	}



CVS commit: src/sys/dev/audio

2019-07-10 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jul 10 13:26:47 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Use kmem_alloc/free() instead of old kern_malloc/free().


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/audio/audio.c

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



CVS commit: src/sys/dev/audio

2019-07-10 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jul 10 13:17:57 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Fix freem() argument.  The 3rd argument is bufsize, not direction...


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/audio/audio.c

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



CVS commit: src/sys/dev/audio

2019-07-10 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jul 10 13:17:57 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Fix freem() argument.  The 3rd argument is bufsize, not direction...


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/audio/audio.c

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.26 src/sys/dev/audio/audio.c:1.27
--- src/sys/dev/audio/audio.c:1.26	Sun Jul  7 06:29:14 2019
+++ src/sys/dev/audio/audio.c	Wed Jul 10 13:17:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.26 2019/07/07 06:29:14 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.27 2019/07/10 13:17:57 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.26 2019/07/07 06:29:14 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.27 2019/07/10 13:17:57 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4801,16 +4801,15 @@ abort:
 static void
 audio_mixer_destroy(struct audio_softc *sc, audio_trackmixer_t *mixer)
 {
-	int mode;
+	int bufsize;
 
 	KASSERT(mutex_owned(sc->sc_lock));
 
-	mode = mixer->mode;
-	KASSERT(mode == AUMODE_PLAY || mode == AUMODE_RECORD);
+	bufsize = frametobyte(>hwbuf.fmt, mixer->hwbuf.capacity);
 
 	if (mixer->hwbuf.mem != NULL) {
 		if (sc->hw_if->freem) {
-			sc->hw_if->freem(sc->hw_hdl, mixer->hwbuf.mem, mode);
+			sc->hw_if->freem(sc->hw_hdl, mixer->hwbuf.mem, bufsize);
 		} else {
 			kern_free(mixer->hwbuf.mem);
 		}



CVS commit: src/sys/dev/audio

2019-07-07 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Jul  7 06:29:15 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Avoid memory reallocation on SET_FORMAT.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/audio/audio.c

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.25 src/sys/dev/audio/audio.c:1.26
--- src/sys/dev/audio/audio.c:1.25	Sun Jul  7 06:14:21 2019
+++ src/sys/dev/audio/audio.c	Sun Jul  7 06:29:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.25 2019/07/07 06:14:21 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.26 2019/07/07 06:29:14 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.25 2019/07/07 06:14:21 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.26 2019/07/07 06:29:14 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -5967,11 +5967,14 @@ audio_mixers_init(struct audio_softc *sc
 	KASSERT(mutex_owned(sc->sc_lock));
 
 	if ((mode & AUMODE_PLAY)) {
-		if (sc->sc_pmixer) {
+		if (sc->sc_pmixer == NULL) {
+			sc->sc_pmixer = kmem_zalloc(sizeof(*sc->sc_pmixer),
+			KM_SLEEP);
+		} else {
+			/* destroy() doesn't free memory. */
 			audio_mixer_destroy(sc, sc->sc_pmixer);
-			kmem_free(sc->sc_pmixer, sizeof(*sc->sc_pmixer));
+			memset(sc->sc_pmixer, 0, sizeof(*sc->sc_pmixer));
 		}
-		sc->sc_pmixer = kmem_zalloc(sizeof(*sc->sc_pmixer), KM_SLEEP);
 		error = audio_mixer_init(sc, AUMODE_PLAY, phwfmt, pfil);
 		if (error) {
 			aprint_error_dev(sc->sc_dev,
@@ -5982,11 +5985,14 @@ audio_mixers_init(struct audio_softc *sc
 		}
 	}
 	if ((mode & AUMODE_RECORD)) {
-		if (sc->sc_rmixer) {
+		if (sc->sc_rmixer == NULL) {
+			sc->sc_rmixer = kmem_zalloc(sizeof(*sc->sc_rmixer),
+			KM_SLEEP);
+		} else {
+			/* destroy() doesn't free memory. */
 			audio_mixer_destroy(sc, sc->sc_rmixer);
-			kmem_free(sc->sc_rmixer, sizeof(*sc->sc_rmixer));
+			memset(sc->sc_rmixer, 0, sizeof(*sc->sc_rmixer));
 		}
-		sc->sc_rmixer = kmem_zalloc(sizeof(*sc->sc_rmixer), KM_SLEEP);
 		error = audio_mixer_init(sc, AUMODE_RECORD, rhwfmt, rfil);
 		if (error) {
 			aprint_error_dev(sc->sc_dev,



CVS commit: src/sys/dev/audio

2019-07-07 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Jul  7 06:29:15 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Avoid memory reallocation on SET_FORMAT.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/audio/audio.c

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



CVS commit: src/sys/dev/audio

2019-07-07 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Jul  7 06:14:21 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Rearrange some KASSERT and debug messages, to sync with others.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/audio/audio.c

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



CVS commit: src/sys/dev/audio

2019-07-07 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Jul  7 06:14:21 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Rearrange some KASSERT and debug messages, to sync with others.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/audio/audio.c

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.24 src/sys/dev/audio/audio.c:1.25
--- src/sys/dev/audio/audio.c:1.24	Sun Jul  7 06:06:46 2019
+++ src/sys/dev/audio/audio.c	Sun Jul  7 06:14:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.24 2019/07/07 06:06:46 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.25 2019/07/07 06:14:21 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.24 2019/07/07 06:06:46 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.25 2019/07/07 06:14:21 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2213,6 +2213,8 @@ audio_read(struct audio_softc *sc, struc
 	audio_ring_t *input;
 	int error;
 
+	KASSERT(!mutex_owned(sc->sc_lock));
+
 	/*
 	 * On half-duplex hardware, O_RDWR is treated as O_WRONLY.
 	 * However read() system call itself can be called because it's
@@ -2223,8 +2225,6 @@ audio_read(struct audio_softc *sc, struc
 		return EBADF;
 	}
 
-	KASSERT(!mutex_owned(sc->sc_lock));
-
 	/* I think it's better than EINVAL. */
 	if (track->mmapped)
 		return EPERM;
@@ -2340,18 +2340,19 @@ audio_write(struct audio_softc *sc, stru
 	audio_ring_t *outbuf;
 	int error;
 
+	KASSERT(!mutex_owned(sc->sc_lock));
+
 	track = file->ptrack;
 	KASSERT(track);
-	TRACET(2, track, "%sresid=%zd pid=%d.%d ioflag=0x%x",
-	audiodebug >= 3 ? "begin " : "",
-	uio->uio_resid, (int)curproc->p_pid, (int)curlwp->l_lid, ioflag);
-
-	KASSERT(!mutex_owned(sc->sc_lock));
 
 	/* I think it's better than EINVAL. */
 	if (track->mmapped)
 		return EPERM;
 
+	TRACET(2, track, "%sresid=%zd pid=%d.%d ioflag=0x%x",
+	audiodebug >= 3 ? "begin " : "",
+	uio->uio_resid, (int)curproc->p_pid, (int)curlwp->l_lid, ioflag);
+
 	if (uio->uio_resid == 0) {
 		track->eofcounter++;
 		return 0;



CVS commit: src/sys/dev/audio

2019-07-07 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Jul  7 06:06:46 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Fix to evaluate the validity of this track at earlier on audio_read().
It fixes a panic on read() against descriptor opened as O_RDWR on the
half duplex device.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/audio/audio.c

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



CVS commit: src/sys/dev/audio

2019-07-07 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Jul  7 06:06:46 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Fix to evaluate the validity of this track at earlier on audio_read().
It fixes a panic on read() against descriptor opened as O_RDWR on the
half duplex device.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/audio/audio.c

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.23 src/sys/dev/audio/audio.c:1.24
--- src/sys/dev/audio/audio.c:1.23	Sat Jul  6 12:58:58 2019
+++ src/sys/dev/audio/audio.c	Sun Jul  7 06:06:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.23 2019/07/06 12:58:58 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.24 2019/07/07 06:06:46 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.23 2019/07/06 12:58:58 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.24 2019/07/07 06:06:46 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2213,9 +2213,15 @@ audio_read(struct audio_softc *sc, struc
 	audio_ring_t *input;
 	int error;
 
+	/*
+	 * On half-duplex hardware, O_RDWR is treated as O_WRONLY.
+	 * However read() system call itself can be called because it's
+	 * opened with O_RDWR.  So in this case, deny this read().
+	 */
 	track = file->rtrack;
-	KASSERT(track);
-	TRACET(2, track, "resid=%zd", uio->uio_resid);
+	if (track == NULL) {
+		return EBADF;
+	}
 
 	KASSERT(!mutex_owned(sc->sc_lock));
 
@@ -2223,6 +2229,8 @@ audio_read(struct audio_softc *sc, struc
 	if (track->mmapped)
 		return EPERM;
 
+	TRACET(2, track, "resid=%zd", uio->uio_resid);
+
 #ifdef AUDIO_PM_IDLE
 	mutex_enter(sc->sc_lock);
 	if (device_is_active(>sc_dev) || sc->sc_idle)
@@ -2230,15 +2238,6 @@ audio_read(struct audio_softc *sc, struc
 	mutex_exit(sc->sc_lock);
 #endif
 
-	/*
-	 * On half-duplex hardware, O_RDWR is treated as O_WRONLY.
-	 * However read() system call itself can be called because it's
-	 * opened with O_RDWR.  So in this case, deny this read().
-	 */
-	if ((file->mode & AUMODE_RECORD) == 0) {
-		return EBADF;
-	}
-
 	usrbuf = >usrbuf;
 	input = track->input;
 



CVS commit: src/sys/dev/audio

2019-07-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jul  6 12:58:58 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c audiodef.h

Log Message:
Implement auto recovery of the mixing volume.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/audio/audiodef.h

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



CVS commit: src/sys/dev/audio

2019-07-06 Thread Tetsuya Isaki
(aint2_t)AINT_T_MAX * 256 / maxval);
+		} else {
+			newvol = (int)((aint2_t)AINT_T_MIN * 256 / minval);
+		}
+
+		/*
+		 * Change the volume only if new one is smaller.
+		 * Reset the timer even if the volume isn't changed.
+		 */
+		if (newvol <= mixer->volume) {
+			mixer->volume = newvol;
+			mixer->voltimer = 0;
+#if defined(AUDIO_DEBUG_AGC)
+			TRACE(1, "auto volume adjust: %d", mixer->volume);
+#endif
+		}
+	}
+}
+
+/*
  * Mix one track.
  * 'mixed' specifies the number of tracks mixed so far.
  * It returns the number of tracks mixed.  In other words, it returns

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.6 src/sys/dev/audio/audiodef.h:1.7
--- src/sys/dev/audio/audiodef.h:1.6	Wed Jun 26 06:57:45 2019
+++ src/sys/dev/audio/audiodef.h	Sat Jul  6 12:58:58 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.6 2019/06/26 06:57:45 isaki Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.7 2019/07/06 12:58:58 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -214,6 +214,11 @@ struct audio_trackmixer {
 	 * Must be protected by sc_intr_lock.
 	 */
 	u_int		volume;
+	/*
+	 * Volume recovery timer in auto gain control.
+	 * Must be protected by sc_intr_lock.
+	 */
+	int		voltimer;
 
 	audio_format2_t	mixfmt;
 	void		*mixsample;	/* mixing buf in double-sized int */



CVS commit: src/sys/dev/pad

2019-06-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 26 12:21:40 UTC 2019

Modified Files:
src/sys/dev/pad: pad.c

Log Message:
Fix return value.  fo_poll expects revents, not errno.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/dev/pad/pad.c

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

Modified files:

Index: src/sys/dev/pad/pad.c
diff -u src/sys/dev/pad/pad.c:1.62 src/sys/dev/pad/pad.c:1.63
--- src/sys/dev/pad/pad.c:1.62	Wed Jun 26 11:53:15 2019
+++ src/sys/dev/pad/pad.c	Wed Jun 26 12:21:40 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: pad.c,v 1.62 2019/06/26 11:53:15 isaki Exp $ */
+/* $NetBSD: pad.c,v 1.63 2019/06/26 12:21:40 isaki Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.62 2019/06/26 11:53:15 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.63 2019/06/26 12:21:40 isaki Exp $");
 
 #include 
 #include 
@@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.62
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -453,7 +454,7 @@ static int
 fops_pad_poll(struct file *fp, int events)
 {
 
-	return ENODEV;
+	return POLLERR;
 }
 
 static int



CVS commit: src/sys/dev/pad

2019-06-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 26 12:21:40 UTC 2019

Modified Files:
src/sys/dev/pad: pad.c

Log Message:
Fix return value.  fo_poll expects revents, not errno.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/dev/pad/pad.c

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



CVS commit: src/sys/dev/pad

2019-06-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 26 11:53:15 UTC 2019

Modified Files:
src/sys/dev/pad: pad.c padvar.h

Log Message:
Style fixes.  No functional changes intended.
- Rename some functions for consistency.
- Rearrange some functions for readability.
- Unify to struct pad_softc.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/dev/pad/pad.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/pad/padvar.h

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



CVS commit: src/sys/dev/pad

2019-06-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 26 11:53:15 UTC 2019

Modified Files:
src/sys/dev/pad: pad.c padvar.h

Log Message:
Style fixes.  No functional changes intended.
- Rename some functions for consistency.
- Rearrange some functions for readability.
- Unify to struct pad_softc.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/dev/pad/pad.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/pad/padvar.h

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

Modified files:

Index: src/sys/dev/pad/pad.c
diff -u src/sys/dev/pad/pad.c:1.61 src/sys/dev/pad/pad.c:1.62
--- src/sys/dev/pad/pad.c:1.61	Wed Jun 19 12:52:41 2019
+++ src/sys/dev/pad/pad.c	Wed Jun 26 11:53:15 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: pad.c,v 1.61 2019/06/19 12:52:41 isaki Exp $ */
+/* $NetBSD: pad.c,v 1.62 2019/06/26 11:53:15 isaki Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.61 2019/06/19 12:52:41 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.62 2019/06/26 11:53:15 isaki Exp $");
 
 #include 
 #include 
@@ -93,9 +93,9 @@ static int	pad_set_format(void *, int,
 		const audio_params_t *, const audio_params_t *,
 		audio_filter_reg_t *, audio_filter_reg_t *);
 static int	pad_start_output(void *, void *, int,
-void (*)(void *), void *);
+		void (*)(void *), void *);
 static int	pad_start_input(void *, void *, int,
-   void (*)(void *), void *);
+		void (*)(void *), void *);
 static int	pad_halt_output(void *);
 static int	pad_halt_input(void *);
 static int	pad_getdev(void *, struct audio_device *);
@@ -108,32 +108,35 @@ static void	pad_get_locks(void *, kmutex
 static void	pad_done_output(void *);
 static void	pad_swvol_codec(audio_filter_arg_t *);
 
-static int pad_close(struct pad_softc *);
-static int pad_read(struct pad_softc *, off_t *, struct uio *, kauth_cred_t, int);
-
-static int fops_pad_close(struct file *);
-static int fops_pad_read(struct file *, off_t *, struct uio *, kauth_cred_t, int);
-static int pad_write(struct file *, off_t *, struct uio *, kauth_cred_t, int);
-static int pad_ioctl(struct file *, u_long, void *);
-static int pad_kqfilter(struct file *, struct knote *);
-static int pad_poll(struct file *, int);
-static int pad_stat(struct file *, struct stat *);
-static int pad_mmap(struct file *, off_t *, size_t, int, int *, int *,
-			   struct uvm_object **, int *);
+static int	pad_close(struct pad_softc *);
+static int	pad_read(struct pad_softc *, off_t *, struct uio *,
+		kauth_cred_t, int);
+
+static int	fops_pad_close(struct file *);
+static int	fops_pad_read(struct file *, off_t *, struct uio *,
+		kauth_cred_t, int);
+static int	fops_pad_write(struct file *, off_t *, struct uio *,
+		kauth_cred_t, int);
+static int	fops_pad_ioctl(struct file *, u_long, void *);
+static int	fops_pad_kqfilter(struct file *, struct knote *);
+static int	fops_pad_poll(struct file *, int);
+static int	fops_pad_stat(struct file *, struct stat *);
+static int	fops_pad_mmap(struct file *, off_t *, size_t, int, int *, int *,
+		struct uvm_object **, int *);
 
 static const struct audio_hw_if pad_hw_if = {
-	.query_format = pad_query_format,
-	.set_format = pad_set_format,
-	.start_output = pad_start_output,
-	.start_input = pad_start_input,
-	.halt_output = pad_halt_output,
-	.halt_input = pad_halt_input,
-	.getdev = pad_getdev,
-	.set_port = pad_set_port,
-	.get_port = pad_get_port,
-	.query_devinfo = pad_query_devinfo,
-	.get_props = pad_get_props,
-	.get_locks = pad_get_locks,
+	.query_format	= pad_query_format,
+	.set_format	= pad_set_format,
+	.start_output	= pad_start_output,
+	.start_input	= pad_start_input,
+	.halt_output	= pad_halt_output,
+	.halt_input	= pad_halt_input,
+	.getdev		= pad_getdev,
+	.set_port	= pad_set_port,
+	.get_port	= pad_get_port,
+	.query_devinfo	= pad_query_devinfo,
+	.get_props	= pad_get_props,
+	.get_locks	= pad_get_locks,
 };
 
 #define PAD_NFORMATS	1
@@ -152,43 +155,44 @@ static const struct audio_format pad_for
 
 extern void	padattach(int);
 
-static int	pad_add_block(pad_softc_t *, uint8_t *, int);
-static int	pad_get_block(pad_softc_t *, pad_block_t *, int);
+static int	pad_add_block(struct pad_softc *, uint8_t *, int);
+static int	pad_get_block(struct pad_softc *, pad_block_t *, int);
 
-dev_type_open(pad_open);
+dev_type_open(cdev_pad_open);
 dev_type_close(cdev_pad_close);
 dev_type_read(cdev_pad_read);
 
 const struct cdevsw pad_cdevsw = {
-	.d_open = pad_open,
-	.d_close = cdev_pad_close,
-	.d_read = cdev_pad_read,
-	.d_write = nowrite,
-	.d_ioctl = noioctl,
-	.d_stop = nostop,
-	.d_tty = notty,
-	.d_poll = nopoll,
-	.d_mmap = nommap,
-	.d_kqfilter = nokqfilter,
-	.d_discard = nodiscard,
-	.d_flag = D_OTHER | D_MPSAFE,
+	.d_open		= cdev_pad_open,
+	.d_close	= cdev_pad_close,
+	.d_read		= cdev_pad_read,
+	.d_write	= nowrite,
+	.d_ioctl	= noioctl,
+	.d_stop		= 

CVS commit: src/sys/dev/audio

2019-06-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 26 07:47:25 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Improve debug message and remove duplicated one.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/audio/audio.c

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.21 src/sys/dev/audio/audio.c:1.22
--- src/sys/dev/audio/audio.c:1.21	Wed Jun 26 06:57:45 2019
+++ src/sys/dev/audio/audio.c	Wed Jun 26 07:47:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.21 2019/06/26 06:57:45 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.22 2019/06/26 07:47:25 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.21 2019/06/26 06:57:45 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.22 2019/06/26 07:47:25 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1858,8 +1858,9 @@ audio_open(dev_t dev, struct audio_softc
 	KASSERT(mutex_owned(sc->sc_lock));
 	KASSERT(sc->sc_exlock);
 
-	TRACE(1, "%sflags=0x%x po=%d ro=%d",
+	TRACE(1, "%sdev=%s flags=0x%x po=%d ro=%d",
 	(audiodebug >= 3) ? "start " : "",
+	ISDEVSOUND(dev) ? "sound" : "audio",
 	flags, sc->sc_popens, sc->sc_ropens);
 
 	af = kmem_zalloc(sizeof(audio_file_t), KM_SLEEP);
@@ -2236,8 +2237,6 @@ audio_read(struct audio_softc *sc, struc
 		return EBADF;
 	}
 
-	TRACET(3, track, "resid=%zd", uio->uio_resid);
-
 	usrbuf = >usrbuf;
 	input = track->input;
 



CVS commit: src/sys/dev/audio

2019-06-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 26 07:47:25 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Improve debug message and remove duplicated one.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/audio/audio.c

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



CVS commit: src/sys/dev/audio

2019-06-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 26 06:57:45 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c audiobell.c audiodef.h audiovar.h

Log Message:
Improve audiobell (and interfaces with audio).
- Generate pseudo sine wave if possible.  It may improve timbre.
  If it cannot represent a sine wave, it falls back to a triangular
  wave or a rectangular wave.
- Volume adjustment.
- Calculate playback frequency based on mixer frequency.
  Now audiobellopen() initializes playback parameters other than
  sample_rate, and new audiobellsetrate() sets sample_rate.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/audio/audiobell.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/audio/audiodef.h
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/audio/audiovar.h

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



CVS commit: src/sys/dev/audio

2019-06-26 Thread Tetsuya Isaki
ep = 8;
+		offset = 4;
+	}
 
-	buf = malloc(wave1len, M_TEMP, M_WAITOK);
+	wave1count = __arraycount(sinewave) / step;
+	play_sample_rate = pitch * wave1count;
+	audiobellsetrate(file, play_sample_rate);
+
+	/* msec to sample count */
+	remaincount = play_sample_rate * period / 1000;
+	/* Roundup to full wave */
+	remaincount = roundup(remaincount, wave1count);
+	remainbytes = remaincount * sizeof(int16_t);
+	wave1bytes = wave1count * sizeof(int16_t);
+
+	blkbytes = ptrack->usrbuf_blksize;
+	blkbytes = rounddown(blkbytes, wave1bytes);
+	blkbytes = uimin(blkbytes, remainbytes);
+	buf = malloc(blkbytes, M_TEMP, M_WAITOK);
 	if (buf == NULL)
 		goto out;
 
-	/* Generate single square wave.  It's enough to beep. */
-	vol = 32767 * volume / 100;
-	for (i = 0; i < wave1count / 2; i++) {
-		buf[i] = vol;
-	}
-	vol = -vol;
-	for (; i < wave1count; i++) {
-		buf[i] = vol;
+	/* Generate sinewave with specified volume */
+	j = offset;
+	for (i = 0; i < blkbytes / sizeof(int16_t); i++) {
+		/* XXX audio already has track volume feature though #if 0 */
+		buf[i] = AUDIO_SCALEDOWN(sinewave[j] * (int)volume, 16);
+		j += step;
+		j %= __arraycount(sinewave);
 	}
 
-	/* Write while paused to avoid begin inserted silence. */
+	/* Write while paused to avoid inserting silence. */
 	ptrack->is_pause = true;
-	for (; remainlen > 0; remainlen -= wave1len) {
-		len = uimin(remainlen, wave1len);
+	for (; remainbytes > 0; remainbytes -= len) {
+		len = uimin(remainbytes, blkbytes);
 		aiov.iov_base = (void *)buf;
 		aiov.iov_len = len;
 		auio.uio_iov = 

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.5 src/sys/dev/audio/audiodef.h:1.6
--- src/sys/dev/audio/audiodef.h:1.5	Tue Jun 25 13:07:48 2019
+++ src/sys/dev/audio/audiodef.h	Wed Jun 26 06:57:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.5 2019/06/25 13:07:48 isaki Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.6 2019/06/26 06:57:45 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -63,6 +63,28 @@
  */
 /* #define AUDIO_SUPPORT_TRACK_VOLUME */
 
+/*
+ * AUDIO_SCALEDOWN()
+ * This macro should be used for audio wave data only.
+ *
+ * The arithmetic shift right (ASR) (in other words, floor()) is good for
+ * this purpose, and will be faster than division on the most platform.
+ * The division (in other words, truncate()) is not so bad alternate for
+ * this purpose, and will be fast enough.
+ * (Using ASR is 1.9 times faster than division on my amd64, and 1.3 times
+ * faster on my m68k.  -- isaki 201801.)
+ *
+ * However, the right shift operator ('>>') for negative integer is
+ * "implementation defined" behavior in C (note that it's not "undefined"
+ * behavior).  So only if implementation defines '>>' as ASR, we use it.
+ */
+#if defined(__GNUC__)
+/* gcc defines '>>' as ASR. */
+#define AUDIO_SCALEDOWN(value, bits)	((value) >> (bits))
+#else
+#define AUDIO_SCALEDOWN(value, bits)	((value) / (1 << (bits)))
+#endif
+
 /* conversion stage */
 typedef struct {
 	audio_ring_t srcbuf;

Index: src/sys/dev/audio/audiovar.h
diff -u src/sys/dev/audio/audiovar.h:1.3 src/sys/dev/audio/audiovar.h:1.4
--- src/sys/dev/audio/audiovar.h:1.3	Mon Jun 10 13:12:51 2019
+++ src/sys/dev/audio/audiovar.h	Wed Jun 26 06:57:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiovar.h,v 1.3 2019/06/10 13:12:51 isaki Exp $	*/
+/*	$NetBSD: audiovar.h,v 1.4 2019/06/26 06:57:45 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -318,15 +318,8 @@ audio_format2_endian(const audio_format2
 }
 
 /* Interfaces for audiobell. */
-struct audiobell_arg {
-	u_int sample_rate;	/* IN */
-	u_int encoding;		/* IN */
-	u_int channels;		/* IN */
-	u_int precision;	/* IN */
-	u_int blocksize;	/* OUT */
-	audio_file_t *file;	/* OUT */
-};
-int audiobellopen(dev_t, struct audiobell_arg *);
+int audiobellopen(dev_t, audio_file_t **);
+int audiobellsetrate(audio_file_t *, u_int);
 int audiobellclose(audio_file_t *);
 int audiobellwrite(audio_file_t *, struct uio *);
 



CVS commit: src/sys/dev/audio

2019-06-25 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Jun 25 13:07:48 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c audiodef.h

Log Message:
Put the lowered mixing volume back when all playback tracks are closed.
TODO: about long life descriptor.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/audio/audiodef.h

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.19 src/sys/dev/audio/audio.c:1.20
--- src/sys/dev/audio/audio.c:1.19	Sun Jun 23 01:46:56 2019
+++ src/sys/dev/audio/audio.c	Tue Jun 25 13:07:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.19 2019/06/23 01:46:56 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.20 2019/06/25 13:07:48 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.19 2019/06/23 01:46:56 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.20 2019/06/25 13:07:48 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -587,7 +587,6 @@ static int audio_hw_validate_format(stru
 static int audio_mixers_set_format(struct audio_softc *,
 	const struct audio_info *);
 static void audio_mixers_get_format(struct audio_softc *, struct audio_info *);
-static int audio_sysctl_volume(SYSCTLFN_PROTO);
 static int audio_sysctl_blk_ms(SYSCTLFN_PROTO);
 static int audio_sysctl_multiuser(SYSCTLFN_PROTO);
 #if defined(AUDIO_DEBUG)
@@ -1013,13 +1012,6 @@ audioattach(device_t parent, device_t se
 	if (node != NULL) {
 		sysctl_createv(>sc_log, 0, NULL, NULL,
 		CTLFLAG_READWRITE,
-		CTLTYPE_INT, "volume",
-		SYSCTL_DESCR("software volume test"),
-		audio_sysctl_volume, 0, (void *)sc, 0,
-		CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
-
-		sysctl_createv(>sc_log, 0, NULL, NULL,
-		CTLFLAG_READWRITE,
 		CTLTYPE_INT, "blk_ms",
 		SYSCTL_DESCR("blocksize in msec"),
 		audio_sysctl_blk_ms, 0, (void *)sc, 0,
@@ -2159,6 +2151,13 @@ audio_close(struct audio_softc *sc, audi
 
 		KASSERT(sc->sc_popens > 0);
 		sc->sc_popens--;
+
+		/* Restore mixing volume if all tracks are gone. */
+		if (sc->sc_popens == 0) {
+			mutex_enter(sc->sc_intr_lock);
+			sc->sc_pmixer->volume = 256;
+			mutex_exit(sc->sc_intr_lock);
+		}
 	}
 	if (file->rtrack) {
 		/* Call hw halt_input if this is the last recording track. */
@@ -5016,8 +5015,8 @@ audio_pmixer_process(struct audio_softc 
 if (mixer->volume > 128) {
 	mixer->volume =
 	(mixer->volume * 95) / 100;
-	device_printf(sc->sc_dev,
-	"auto volume adjust: volume %d\n",
+	TRACE(2,
+	"auto volume adjust: volume %d",
 	mixer->volume);
 }
 			}
@@ -7266,38 +7265,6 @@ audio_indexof_format(const struct audio_
 }
 
 /*
- * Get or set software master volume: 0..256
- * XXX It's for debug.
- */
-static int
-audio_sysctl_volume(SYSCTLFN_ARGS)
-{
-	struct sysctlnode node;
-	struct audio_softc *sc;
-	int t, error;
-
-	node = *rnode;
-	sc = node.sysctl_data;
-
-	if (sc->sc_pmixer)
-		t = sc->sc_pmixer->volume;
-	else
-		t = -1;
-	node.sysctl_data = 
-	error = sysctl_lookup(SYSCTLFN_CALL());
-	if (error || newp == NULL)
-		return error;
-
-	if (sc->sc_pmixer == NULL)
-		return EINVAL;
-	if (t < 0)
-		return EINVAL;
-
-	sc->sc_pmixer->volume = t;
-	return 0;
-}
-
-/*
  * Get or set hardware blocksize in msec.
  * XXX It's for debug.
  */

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.4 src/sys/dev/audio/audiodef.h:1.5
--- src/sys/dev/audio/audiodef.h:1.4	Mon Jun 10 13:49:39 2019
+++ src/sys/dev/audio/audiodef.h	Tue Jun 25 13:07:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.4 2019/06/10 13:49:39 isaki Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.5 2019/06/25 13:07:48 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -187,7 +187,11 @@ struct audio_trackmixer {
 
 	int		frames_per_block; /* number of frames in a block */
 
-	u_int		volume;		/* software master volume (0..256) */
+	/*
+	 * software master volume (0..256)
+	 * Must be protected by sc_intr_lock.
+	 */
+	u_int		volume;
 
 	audio_format2_t	mixfmt;
 	void		*mixsample;	/* mixing buf in double-sized int */



CVS commit: src/sys/dev/audio

2019-06-25 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Jun 25 13:07:48 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c audiodef.h

Log Message:
Put the lowered mixing volume back when all playback tracks are closed.
TODO: about long life descriptor.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/audio/audiodef.h

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



CVS commit: src/sys/dev/audio

2019-06-22 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Jun 23 01:46:56 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Restore sysctl_teardown which was unintentionally dropped.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/audio/audio.c

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.18 src/sys/dev/audio/audio.c:1.19
--- src/sys/dev/audio/audio.c:1.18	Wed Jun 19 12:49:49 2019
+++ src/sys/dev/audio/audio.c	Sun Jun 23 01:46:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.18 2019/06/19 12:49:49 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.19 2019/06/23 01:46:56 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.18 2019/06/19 12:49:49 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.19 2019/06/23 01:46:56 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1272,6 +1272,9 @@ audiodetach(device_t self, int flags)
 		cv_broadcast(>sc_rmixer->outcv);
 	mutex_exit(sc->sc_lock);
 
+	/* delete sysctl nodes */
+	sysctl_teardown(>sc_log);
+
 	/* locate the major number */
 	maj = cdevsw_lookup_major(_cdevsw);
 



CVS commit: src/sys/dev/wscons

2019-06-22 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jun 22 08:03:01 UTC 2019

Modified Files:
src/sys/dev/wscons: wsbell.c

Log Message:
Add missing SETBELL() for WSKBDIO_COMPLEXBELL.
wskbd_bell_data structure has value fields and operation bitmask field.
"xset b * * 0" doesn't touch period field (and doesn't initialized it)
and doesn't set DOPERIOD flag (this means that period field should not
be used).  SETBELL() handles this situation appropliately.
This happened during copying wsbell.c from wskbd.c.
Fix PR xsrc/54245.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/wscons/wsbell.c

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

Modified files:

Index: src/sys/dev/wscons/wsbell.c
diff -u src/sys/dev/wscons/wsbell.c:1.11 src/sys/dev/wscons/wsbell.c:1.12
--- src/sys/dev/wscons/wsbell.c:1.11	Thu Apr 18 14:01:28 2019
+++ src/sys/dev/wscons/wsbell.c	Sat Jun 22 08:03:01 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: wsbell.c,v 1.11 2019/04/18 14:01:28 isaki Exp $ */
+/* $NetBSD: wsbell.c,v 1.12 2019/06/22 08:03:01 isaki Exp $ */
 
 /*-
  * Copyright (c) 2017 Nathanial Sloss 
@@ -107,7 +107,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wsbell.c,v 1.11 2019/04/18 14:01:28 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsbell.c,v 1.12 2019/06/22 08:03:01 isaki Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "wsmux.h"
@@ -396,9 +396,9 @@ getbell:
 			return (EACCES);
 		if (data == NULL)
 			return 0;
-#define d ((struct wskbd_bell_data *)data)
-		spkr_audio_play(sc, d->pitch, d->period, d->volume);
-#undef d
+		ubdp = (struct wskbd_bell_data *)data;
+		SETBELL(ubdp, ubdp, >sc_bell_data);
+		spkr_audio_play(sc, ubdp->pitch, ubdp->period, ubdp->volume);
 		return 0;
 	}
 



CVS commit: src/sys/dev/wscons

2019-06-22 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jun 22 08:03:01 UTC 2019

Modified Files:
src/sys/dev/wscons: wsbell.c

Log Message:
Add missing SETBELL() for WSKBDIO_COMPLEXBELL.
wskbd_bell_data structure has value fields and operation bitmask field.
"xset b * * 0" doesn't touch period field (and doesn't initialized it)
and doesn't set DOPERIOD flag (this means that period field should not
be used).  SETBELL() handles this situation appropliately.
This happened during copying wsbell.c from wskbd.c.
Fix PR xsrc/54245.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/wscons/wsbell.c

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



CVS commit: src/sys/dev

2019-06-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Jun 21 09:34:30 UTC 2019

Modified Files:
src/sys/dev: spkr_audio.c

Log Message:
Use hztoms() instead of incorrect calculation.
This makes spkr work on HZ=1024 like alpha.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/spkr_audio.c

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

Modified files:

Index: src/sys/dev/spkr_audio.c
diff -u src/sys/dev/spkr_audio.c:1.7 src/sys/dev/spkr_audio.c:1.8
--- src/sys/dev/spkr_audio.c:1.7	Wed May  8 13:40:17 2019
+++ src/sys/dev/spkr_audio.c	Fri Jun 21 09:34:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: spkr_audio.c,v 1.7 2019/05/08 13:40:17 isaki Exp $	*/
+/*	$NetBSD: spkr_audio.c,v 1.8 2019/06/21 09:34:30 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spkr_audio.c,v 1.7 2019/05/08 13:40:17 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spkr_audio.c,v 1.8 2019/06/21 09:34:30 isaki Exp $");
 
 #include 
 #include 
@@ -70,7 +70,7 @@ spkr_audio_tone(device_t self, u_int xhz
 #ifdef SPKRDEBUG
 	aprint_debug_dev(self, "%s: %u %d\n", __func__, xhz, ticks);
 #endif /* SPKRDEBUG */
-	audiobell(sc->sc_audiodev, xhz, ticks * (1000 / hz),
+	audiobell(sc->sc_audiodev, xhz, hztoms(ticks),
 	sc->sc_spkr.sc_vol, 0);
 }
 
@@ -83,7 +83,7 @@ spkr_audio_rest(device_t self, int ticks
 	aprint_debug_dev(self, "%s: %d\n", __func__, ticks);
 #endif /* SPKRDEBUG */
 	if (ticks > 0)
-		audiobell(sc->sc_audiodev, 0, ticks * (1000 / hz),
+		audiobell(sc->sc_audiodev, 0, hztoms(ticks),
 		sc->sc_spkr.sc_vol, 0);
 }
 



CVS commit: src/sys/dev

2019-06-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Jun 21 09:34:30 UTC 2019

Modified Files:
src/sys/dev: spkr_audio.c

Log Message:
Use hztoms() instead of incorrect calculation.
This makes spkr work on HZ=1024 like alpha.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/spkr_audio.c

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



CVS commit: src

2019-06-20 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Jun 20 12:14:46 UTC 2019

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/dev/audio: Makefile h_pad.c t_pad.sh
Removed Files:
src/tests/dev/audio: t_pad_output.bz2.uue

Log Message:
Rewrite t_pad test.
Previous version compared the pad's output binary passed mulaw-slinear
conversion and frequency conversion with the prepared "good result".
In such case, a test may fail when the implemantation changes.  In fact,
the frequency conversion algorithm was changed in isaki-audio2, so
output waveforms is not completely the same (but that's no problem with
the audio waveforms).
New version uses slinear_le/2ch/44100Hz input data and compares the
output binary with the input data.  pad with no conversions should
output the same binary.
Fix PR kern/54187.


To generate a diff of this commit:
cvs rdiff -u -r1.816 -r1.817 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.5 -r1.6 src/tests/dev/audio/Makefile
cvs rdiff -u -r1.2 -r1.3 src/tests/dev/audio/h_pad.c
cvs rdiff -u -r1.3 -r1.4 src/tests/dev/audio/t_pad.sh
cvs rdiff -u -r1.4 -r0 src/tests/dev/audio/t_pad_output.bz2.uue

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.816 src/distrib/sets/lists/tests/mi:1.817
--- src/distrib/sets/lists/tests/mi:1.816	Fri Jun  7 21:32:34 2019
+++ src/distrib/sets/lists/tests/mi	Thu Jun 20 12:14:46 2019
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.816 2019/06/07 21:32:34 christos Exp $
+# $NetBSD: mi,v 1.817 2019/06/20 12:14:46 isaki Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1389,7 +1389,7 @@
 ./usr/tests/dev/audio/Kyuafile			tests-fs-tests		atf,rump,kyua
 ./usr/tests/dev/audio/h_pad			tests-fs-tests		atf,rump
 ./usr/tests/dev/audio/t_pad			tests-fs-tests		atf,rump
-./usr/tests/dev/audio/t_pad_output.bz2.uue	tests-fs-tests		atf,rump
+./usr/tests/dev/audio/t_pad_output.bz2.uue	tests-obsolete		obsolete
 ./usr/tests/dev/cgdtests-fs-tests		compattestfile,atf
 ./usr/tests/dev/cgd/Atffile			tests-fs-tests		compattestfile,atf
 ./usr/tests/dev/cgd/Kyuafile			tests-fs-tests		compattestfile,atf,kyua

Index: src/tests/dev/audio/Makefile
diff -u src/tests/dev/audio/Makefile:1.5 src/tests/dev/audio/Makefile:1.6
--- src/tests/dev/audio/Makefile:1.5	Sat Jan 23 21:22:48 2016
+++ src/tests/dev/audio/Makefile	Thu Jun 20 12:14:46 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.5 2016/01/23 21:22:48 christos Exp $
+#	$NetBSD: Makefile,v 1.6 2019/06/20 12:14:46 isaki Exp $
 #
 
 .include 
@@ -20,8 +20,6 @@ LDADD+=	-lrumpuser
 LDADD+=	-lrump
 LDADD+=	-lpthread
 
-FILES=		t_pad_output.bz2.uue
-
 WARNS=	4
 NOMAN=
 

Index: src/tests/dev/audio/h_pad.c
diff -u src/tests/dev/audio/h_pad.c:1.2 src/tests/dev/audio/h_pad.c:1.3
--- src/tests/dev/audio/h_pad.c:1.2	Sat Oct 15 07:08:06 2016
+++ src/tests/dev/audio/h_pad.c	Thu Jun 20 12:14:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: h_pad.c,v 1.2 2016/10/15 07:08:06 nat Exp $	*/
+/*	$NetBSD: h_pad.c,v 1.3 2019/06/20 12:14:46 isaki Exp $	*/
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -32,29 +32,114 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 #include "h_pad_musa.c"
 
 /*
- * Stuff some audio into /dev/audio, read it from /dev/pad.  Use in
- * conjunction with t_pad, which tests that we got sensible output
- * by comparing against a previous audibly good result.
+ * Stuff some audio into /dev/audio, read it from /dev/pad.
  */
 
 #define BUFSIZE 1024
 
+static const int16_t mulaw_to_slinear16[256] = {
+	0x8284, 0x8684, 0x8a84, 0x8e84, 0x9284, 0x9684, 0x9a84, 0x9e84,
+	0xa284, 0xa684, 0xaa84, 0xae84, 0xb284, 0xb684, 0xba84, 0xbe84,
+	0xc184, 0xc384, 0xc584, 0xc784, 0xc984, 0xcb84, 0xcd84, 0xcf84,
+	0xd184, 0xd384, 0xd584, 0xd784, 0xd984, 0xdb84, 0xdd84, 0xdf84,
+	0xe104, 0xe204, 0xe304, 0xe404, 0xe504, 0xe604, 0xe704, 0xe804,
+	0xe904, 0xea04, 0xeb04, 0xec04, 0xed04, 0xee04, 0xef04, 0xf004,
+	0xf0c4, 0xf144, 0xf1c4, 0xf244, 0xf2c4, 0xf344, 0xf3c4, 0xf444,
+	0xf4c4, 0xf544, 0xf5c4, 0xf644, 0xf6c4, 0xf744, 0xf7c4, 0xf844,
+	0xf8a4, 0xf8e4, 0xf924, 0xf964, 0xf9a4, 0xf9e4, 0xfa24, 0xfa64,
+	0xfaa4, 0xfae4, 0xfb24, 0xfb64, 0xfba4, 0xfbe4, 0xfc24, 0xfc64,
+	0xfc94, 0xfcb4, 0xfcd4, 0xfcf4, 0xfd14, 0xfd34, 0xfd54, 0xfd74,
+	0xfd94, 0xfdb4, 0xfdd4, 0xfdf4, 0xfe14, 0xfe34, 0xfe54, 0xfe74,
+	0xfe8c, 0xfe9c, 0xfeac, 0xfebc, 0xfecc, 0xfedc, 0xfeec, 0xfefc,
+	0xff0c, 0xff1c, 0xff2c, 0xff3c, 0xff4c, 0xff5c, 0xff6c, 0xff7c,
+	0xff88, 0xff90, 0xff98, 0xffa0, 0xffa8, 0xffb0, 0xffb8, 0xffc0,
+	0xffc8, 0xffd0, 0xffd8, 0xffe0, 0xffe8, 0xfff0, 0xfff8, 0xfffc,
+	0x7d7c, 0x797c, 0x757c, 0x717c, 0x6d7c, 0x697c, 0x657c, 0x617c,
+	0x5d7c, 0x597c, 0x557c, 0x517c, 0x4d7c, 0x497c, 0x457c, 0x417c,
+	0x3e7c, 0x3c7c, 0x3a7c, 0x387c, 0x367c, 0x347c, 0x327c, 0x307c,
+	0x2e7c, 0x2c7c, 0x2a7c, 

CVS commit: src

2019-06-20 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Jun 20 12:14:46 UTC 2019

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/dev/audio: Makefile h_pad.c t_pad.sh
Removed Files:
src/tests/dev/audio: t_pad_output.bz2.uue

Log Message:
Rewrite t_pad test.
Previous version compared the pad's output binary passed mulaw-slinear
conversion and frequency conversion with the prepared "good result".
In such case, a test may fail when the implemantation changes.  In fact,
the frequency conversion algorithm was changed in isaki-audio2, so
output waveforms is not completely the same (but that's no problem with
the audio waveforms).
New version uses slinear_le/2ch/44100Hz input data and compares the
output binary with the input data.  pad with no conversions should
output the same binary.
Fix PR kern/54187.


To generate a diff of this commit:
cvs rdiff -u -r1.816 -r1.817 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.5 -r1.6 src/tests/dev/audio/Makefile
cvs rdiff -u -r1.2 -r1.3 src/tests/dev/audio/h_pad.c
cvs rdiff -u -r1.3 -r1.4 src/tests/dev/audio/t_pad.sh
cvs rdiff -u -r1.4 -r0 src/tests/dev/audio/t_pad_output.bz2.uue

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



CVS commit: src/sys/dev/pad

2019-06-19 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 19 12:52:41 UTC 2019

Modified Files:
src/sys/dev/pad: pad.c

Log Message:
Don't call next callout when an error occurs in start_output.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/dev/pad/pad.c

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

Modified files:

Index: src/sys/dev/pad/pad.c
diff -u src/sys/dev/pad/pad.c:1.60 src/sys/dev/pad/pad.c:1.61
--- src/sys/dev/pad/pad.c:1.60	Wed Jun 19 12:51:26 2019
+++ src/sys/dev/pad/pad.c	Wed Jun 19 12:52:41 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: pad.c,v 1.60 2019/06/19 12:51:26 isaki Exp $ */
+/* $NetBSD: pad.c,v 1.61 2019/06/19 12:52:41 isaki Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.60 2019/06/19 12:51:26 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.61 2019/06/19 12:52:41 isaki Exp $");
 
 #include 
 #include 
@@ -615,12 +615,14 @@ pad_start_output(void *opaque, void *blo
 	err = pad_add_block(sc, block, blksize);
 	mutex_exit(>sc_cond_lock);
 	cv_broadcast(>sc_condvar);
+	if (err)
+		return err;
 
 	ms = blksize * 1000 / PADCHAN / (PADPREC / NBBY) / PADFREQ;
 	DPRINTF("%s: callout ms=%d\n", __func__, ms);
 	callout_reset(>sc_pcallout, mstohz(ms), pad_done_output, sc);
 
-	return err;
+	return 0;
 }
 
 static int



CVS commit: src/sys/dev/pad

2019-06-19 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 19 12:51:26 UTC 2019

Modified Files:
src/sys/dev/pad: pad.c

Log Message:
pad(4)'s output format is LE even on big endian arch.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/dev/pad/pad.c

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



CVS commit: src/sys/dev/pad

2019-06-19 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 19 12:51:26 UTC 2019

Modified Files:
src/sys/dev/pad: pad.c

Log Message:
pad(4)'s output format is LE even on big endian arch.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/dev/pad/pad.c

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

Modified files:

Index: src/sys/dev/pad/pad.c
diff -u src/sys/dev/pad/pad.c:1.59 src/sys/dev/pad/pad.c:1.60
--- src/sys/dev/pad/pad.c:1.59	Wed May  8 13:40:18 2019
+++ src/sys/dev/pad/pad.c	Wed Jun 19 12:51:26 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: pad.c,v 1.59 2019/05/08 13:40:18 isaki Exp $ */
+/* $NetBSD: pad.c,v 1.60 2019/06/19 12:51:26 isaki Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.59 2019/05/08 13:40:18 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.60 2019/06/19 12:51:26 isaki Exp $");
 
 #include 
 #include 
@@ -140,7 +140,7 @@ static const struct audio_hw_if pad_hw_i
 static const struct audio_format pad_formats[PAD_NFORMATS] = {
 	{
 		.mode		= AUMODE_PLAY,
-		.encoding	= AUDIO_ENCODING_SLINEAR_NE,
+		.encoding	= AUDIO_ENCODING_SLINEAR_LE,
 		.validbits	= PADPREC,
 		.precision	= PADPREC,
 		.channels	= PADCHAN,



CVS commit: src/sys/dev/audio

2019-06-19 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 19 12:49:50 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Don't wait until a block is filled.
This improves that short sound breaks.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/audio/audio.c

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

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.17 src/sys/dev/audio/audio.c:1.18
--- src/sys/dev/audio/audio.c:1.17	Wed Jun 12 13:53:25 2019
+++ src/sys/dev/audio/audio.c	Wed Jun 19 12:49:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.17 2019/06/12 13:53:25 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.18 2019/06/19 12:49:49 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.17 2019/06/12 13:53:25 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.18 2019/06/19 12:49:49 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4296,7 +4296,6 @@ audio_track_play(audio_track_t *track)
 	int count;
 	int framesize;
 	int bytes;
-	u_int dropcount;
 
 	KASSERT(track);
 	KASSERT(track->lock);
@@ -4315,7 +4314,6 @@ audio_track_play(audio_track_t *track)
 
 	usrbuf = >usrbuf;
 	input = track->input;
-	dropcount = 0;
 
 	/*
 	 * framesize is always 1 byte or more since all formats supported as
@@ -4336,21 +4334,6 @@ audio_track_play(audio_track_t *track)
 	count = uimin(usrbuf->used, track->usrbuf_blksize) / framesize;
 	bytes = count * framesize;
 
-	/*
-	 * If bytes is less than one block,
-	 *  if not draining, buffer is not filled so return.
-	 *  if draining, fall through.
-	 */
-	if (count < track->usrbuf_blksize / framesize) {
-		dropcount = track->usrbuf_blksize / framesize - count;
-
-		if (track->pstate != AUDIO_STATE_DRAINING) {
-			/* Wait until filled. */
-			TRACET(4, track, "not enough; return");
-			return;
-		}
-	}
-
 	track->usrbuf_stamp += bytes;
 
 	if (usrbuf->head + bytes < usrbuf->capacity) {
@@ -4412,7 +4395,7 @@ audio_track_play(audio_track_t *track)
 		}
 	}
 
-	if (dropcount != 0) {
+	if (bytes < track->usrbuf_blksize) {
 		/*
 		 * Clear all conversion buffer pointer if the conversion was
 		 * not exactly one block.  These conversion stage buffers are



CVS commit: src/sys/dev/audio

2019-06-19 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jun 19 12:49:50 UTC 2019

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Don't wait until a block is filled.
This improves that short sound breaks.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/audio/audio.c

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



  1   2   >