Source-Changes-HG archive

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

[src/isaki-audio2]: src/sys/dev Add audio_indexof_format(). It finds index m...



details:   https://anonhg.NetBSD.org/src/rev/dc83f05e742e
branches:  isaki-audio2
changeset: 450854:dc83f05e742e
user:      isaki <isaki%NetBSD.org@localhost>
date:      Sat Apr 27 12:05:28 2019 +0000

description:
Add audio_indexof_format().  It finds index matches with specified
audio_param_t from array of audio_format_t.
Formerly, it was auconv_set_converter() that convert userland
params to the hardware native (linear) format and such conversion
is unnecessary in audio2.  But some drivers have gotten index from
this format array using auconv_set_converter().  This function is
an alternative to such usage.

diffstat:

 sys/dev/audio/audio.c |  56 +++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/dev/audio_if.h    |   4 ++-
 2 files changed, 57 insertions(+), 3 deletions(-)

diffs (95 lines):

diff -r e15230ee7f63 -r dc83f05e742e sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Sat Apr 27 11:52:53 2019 +0000
+++ b/sys/dev/audio/audio.c     Sat Apr 27 12:05:28 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.1.2.2 2019/04/24 12:14:56 isaki Exp $      */
+/*     $NetBSD: audio.c,v 1.1.2.3 2019/04/27 12:05:28 isaki Exp $      */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -154,7 +154,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.1.2.2 2019/04/24 12:14:56 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.1.2.3 2019/04/27 12:05:28 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -7515,6 +7515,58 @@
 }
 
 /*
+ * This function is provided for the hardware driver's set_format() to
+ * find index matches with 'param' from array of audio_format_t 'formats'.
+ * 'mode' is either of AUMODE_PLAY or AUMODE_RECORD.
+ * It returns the matched index and never fails.  Because param passed to
+ * set_format() is selected from query_format().
+ * This function will be an alternative to auconv_set_converter() to
+ * find index.
+ */
+int
+audio_indexof_format(const struct audio_format *formats, int nformats,
+       int mode, const audio_params_t *param)
+{
+       const struct audio_format *f;
+       int index;
+       int j;
+
+       for (index = 0; index < nformats; index++) {
+               f = &formats[index];
+
+               if (!AUFMT_IS_VALID(f))
+                       continue;
+               if ((f->mode & mode) == 0)
+                       continue;
+               if (f->encoding != param->encoding)
+                       continue;
+               if (f->validbits != param->precision)
+                       continue;
+               if (f->channels != param->channels)
+                       continue;
+
+               if (f->frequency_type == 0) {
+                       if (param->sample_rate < f->frequency[0] ||
+                           param->sample_rate > f->frequency[1])
+                               continue;
+               } else {
+                       for (j = 0; j < f->frequency_type; j++) {
+                               if (param->sample_rate == f->frequency[j])
+                                       break;
+                       }
+                       if (j == f->frequency_type)
+                               continue;
+               }
+
+               /* Then, matched */
+               return index;
+       }
+
+       /* Not matched.  This should not be happened. */
+       panic("%s: cannot find matched format\n", __func__);
+}
+
+/*
  * Get or set software master volume: 0..256
  * XXX It's for debug.
  */
diff -r e15230ee7f63 -r dc83f05e742e sys/dev/audio_if.h
--- a/sys/dev/audio_if.h        Sat Apr 27 11:52:53 2019 +0000
+++ b/sys/dev/audio_if.h        Sat Apr 27 12:05:28 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio_if.h,v 1.70.24.1 2019/04/21 04:28:59 isaki Exp $ */
+/*     $NetBSD: audio_if.h,v 1.70.24.2 2019/04/27 12:05:28 isaki Exp $ */
 
 /*
  * Copyright (c) 1994 Havard Eidnes.
@@ -275,6 +275,8 @@
 
 extern int audio_query_format(const struct audio_format *, int,
        audio_format_query_t *);
+extern int audio_indexof_format(const struct audio_format *, int, int,
+       const audio_params_t *);
 extern const char *audio_encoding_name(int);
 
 /* Device identity flags */



Home | Main Index | Thread Index | Old Index