Module Name: src
Committed By: isaki
Date: Sat Apr 27 12:05:28 UTC 2019
Modified Files:
src/sys/dev [isaki-audio2]: audio_if.h
src/sys/dev/audio [isaki-audio2]: audio.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.70.24.1 -r1.70.24.2 src/sys/dev/audio_if.h
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 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_if.h
diff -u src/sys/dev/audio_if.h:1.70.24.1 src/sys/dev/audio_if.h:1.70.24.2
--- src/sys/dev/audio_if.h:1.70.24.1 Sun Apr 21 04:28:59 2019
+++ src/sys/dev/audio_if.h Sat Apr 27 12:05:28 2019
@@ -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 @@ int audioprint(void *, const char *);
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 */
Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.1.2.2 src/sys/dev/audio/audio.c:1.1.2.3
--- src/sys/dev/audio/audio.c:1.1.2.2 Wed Apr 24 12:14:56 2019
+++ src/sys/dev/audio/audio.c Sat Apr 27 12:05:28 2019
@@ -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 @@ audio_query_format(const struct audio_fo
}
/*
+ * 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.
*/