Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/isaki-audio2]: src/sys/dev/isa Adapt sbdsp to audio2.
details: https://anonhg.NetBSD.org/src/rev/3e8d836a34b2
branches: isaki-audio2
changeset: 450999:3e8d836a34b2
user: isaki <isaki%NetBSD.org@localhost>
date: Fri May 03 03:00:33 2019 +0000
description:
Adapt sbdsp to audio2.
- Use new query_format/set_format interfaces.
The formats are created from sb[pr]modes tables.
- Drop INDEPENDENT property for models proir to SB_16.
diffstat:
sys/dev/isa/pas.c | 9 +-
sys/dev/isa/sb.c | 9 +-
sys/dev/isa/sbdsp.c | 511 +++++++++++++++++++++++++++++++++---------------
sys/dev/isa/sbdspvar.h | 14 +-
4 files changed, 361 insertions(+), 182 deletions(-)
diffs (truncated from 736 to 300 lines):
diff -r 2f9f3975e65f -r 3e8d836a34b2 sys/dev/isa/pas.c
--- a/sys/dev/isa/pas.c Wed May 01 13:45:52 2019 +0000
+++ b/sys/dev/isa/pas.c Fri May 03 03:00:33 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pas.c,v 1.71 2019/03/16 12:09:58 isaki Exp $ */
+/* $NetBSD: pas.c,v 1.71.2.1 2019/05/03 03:00:33 isaki Exp $ */
/*
* Copyright (c) 1991-1993 Regents of the University of California.
@@ -57,7 +57,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pas.c,v 1.71 2019/03/16 12:09:58 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pas.c,v 1.71.2.1 2019/05/03 03:00:33 isaki Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -125,8 +125,8 @@
const struct audio_hw_if pas_hw_if = {
.open = sbdsp_open,
.close = sbdsp_close,
- .query_encoding = sbdsp_query_encoding,
- .set_params = sbdsp_set_params,
+ .query_format = sbdsp_query_format,
+ .set_format = sbdsp_set_format,
.round_blocksize = sbdsp_round_blocksize,
.halt_output = sbdsp_halt_output,
.halt_input = sbdsp_halt_input,
@@ -138,7 +138,6 @@
.allocm = sb_malloc,
.freem = sb_free,
.round_buffersize = sb_round_buffersize,
- .mappage = sb_mappage,
.get_props = sbdsp_get_props,
.trigger_output = sbdsp_trigger_output,
.trigger_input = sbdsp_trigger_input,
diff -r 2f9f3975e65f -r 3e8d836a34b2 sys/dev/isa/sb.c
--- a/sys/dev/isa/sb.c Wed May 01 13:45:52 2019 +0000
+++ b/sys/dev/isa/sb.c Fri May 03 03:00:33 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sb.c,v 1.90 2019/03/16 12:09:58 isaki Exp $ */
+/* $NetBSD: sb.c,v 1.90.2.1 2019/05/03 03:00:33 isaki Exp $ */
/*
* Copyright (c) 1991-1993 Regents of the University of California.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sb.c,v 1.90 2019/03/16 12:09:58 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sb.c,v 1.90.2.1 2019/05/03 03:00:33 isaki Exp $");
#include "midi.h"
@@ -82,8 +82,8 @@
const struct audio_hw_if sb_hw_if = {
.open = sbdsp_open,
.close = sbdsp_close,
- .query_encoding = sbdsp_query_encoding,
- .set_params = sbdsp_set_params,
+ .query_format = sbdsp_query_format,
+ .set_format = sbdsp_set_format,
.round_blocksize = sbdsp_round_blocksize,
.halt_output = sbdsp_halt_output,
.halt_input = sbdsp_halt_input,
@@ -95,7 +95,6 @@
.allocm = sb_malloc,
.freem = sb_free,
.round_buffersize = sb_round_buffersize,
- .mappage = sb_mappage,
.get_props = sbdsp_get_props,
.trigger_output = sbdsp_trigger_output,
.trigger_input = sbdsp_trigger_input,
diff -r 2f9f3975e65f -r 3e8d836a34b2 sys/dev/isa/sbdsp.c
--- a/sys/dev/isa/sbdsp.c Wed May 01 13:45:52 2019 +0000
+++ b/sys/dev/isa/sbdsp.c Fri May 03 03:00:33 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sbdsp.c,v 1.139.2.1 2019/04/21 06:17:02 isaki Exp $ */
+/* $NetBSD: sbdsp.c,v 1.139.2.2 2019/05/03 03:00:33 isaki Exp $ */
/*-
* Copyright (c) 1999, 2008 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sbdsp.c,v 1.139.2.1 2019/04/21 06:17:02 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sbdsp.c,v 1.139.2.2 2019/05/03 03:00:33 isaki Exp $");
#include "midi.h"
#include "mpu.h"
@@ -95,6 +95,7 @@
#include <sys/audioio.h>
#include <dev/audio_if.h>
+#include <dev/audio/linear.h>
#include <dev/midi_if.h>
#include <dev/isa/isavar.h>
@@ -206,8 +207,34 @@
{ .model = -1 }
};
+/*
+ * We actually can specify any value within the frequency range defined
+ * above. But according to definition of SB_RATE_TO_TC macro, only some
+ * of them are dividable (it's preferable, not mandatory). There are 9
+ * values in the range that satisfy this condition but it's too much.
+ */
+static const int sbdsp_rates[] = {
+ 4000,
+ /* 5000, */
+ /* 6250, */
+ /* 10000, */
+ 12500,
+ /* 15625, */
+ 20000,
+ /* 25000, */
+ 31250,
+};
+
void sbversion(struct sbdsp_softc *);
void sbdsp_jazz16_probe(struct sbdsp_softc *);
+void sbdsp_sbmode2format(struct audio_format *, const struct sbmode *, int);
+int sbdsp_set_format16(struct sbdsp_softc *, int,
+ const audio_params_t *, const audio_params_t *,
+ audio_filter_reg_t *, audio_filter_reg_t *);
+int sbdsp_set_format8(struct sbdsp_softc *, int,
+ const audio_params_t *, const audio_params_t *,
+ audio_filter_reg_t *, audio_filter_reg_t *);
+void sbdsp_init_format(struct sbdsp_softc *);
void sbdsp_set_mixer_gain(struct sbdsp_softc *, int);
void sbdsp_pause(struct sbdsp_softc *);
int sbdsp_set_timeconst(struct sbdsp_softc *, int);
@@ -410,9 +437,6 @@
SBVER_MAJOR(sc->sc_version), SBVER_MINOR(sc->sc_version),
sc->sc_model == SB_JAZZ ? ": <Jazz16>" : "");
- /* XXX It's not true full duplex. */
- sc->sc_fullduplex = 0;
-
if (sc->sc_drq8 != -1) {
sc->sc_drq8_maxsize = isa_dmamaxsize(sc->sc_ic,
sc->sc_drq8);
@@ -438,6 +462,14 @@
}
}
+ /* Construct sc_format from model */
+ sbdsp_init_format(sc);
+ if (sc->sc_nformats == 0) {
+ aprint_error_dev(sc->sc_dev,
+ "No available formats; model mismatch?\n");
+ return;
+ }
+
if (!pmf_device_register(sc->sc_dev, NULL, sbdsp_resume))
aprint_error_dev(sc->sc_dev,
"couldn't establish power handler\n");
@@ -488,119 +520,245 @@
return val;
}
+void
+sbdsp_sbmode2format(struct audio_format *f, const struct sbmode *m, int mode)
+{
+ memset(f, 0, sizeof(*f));
+ f->mode = mode;
+ if (m->precision == 8) {
+ /* ulinear8 is always native endian */
+ f->encoding = AUDIO_ENCODING_ULINEAR_NE;
+ f->validbits = 8;
+ f->precision = 8;
+ } else {
+ f->encoding = AUDIO_ENCODING_SLINEAR_LE;
+ f->validbits = 16;
+ f->precision = 16;
+ }
+ f->channels = m->channels;
+ f->channel_mask = (m->channels == 1) ? AUFMT_MONAURAL : AUFMT_STEREO;
+ f->frequency_type = 0;
+ f->frequency[0] = m->lowrate;
+ f->frequency[1] = m->highrate;
+}
+
+/*
+ * Create sc_formats[] array from sbpmodes[], sbrmodes[].
+ */
+void
+sbdsp_init_format(struct sbdsp_softc *sc)
+{
+ struct audio_format dp[4];
+ struct audio_format dr[4];
+ struct audio_format *dbase;
+ struct audio_format *d;
+ struct audio_format tmp;
+ struct sbmode *sbmodes;
+ struct sbmode *m;
+ int mode;
+ int minrate;
+ int maxrate;
+ int idx;
+ int model;
+ int i;
+ int j;
+ int n;
+
+ /* Later models work like SB16. */
+ model = uimin(sc->sc_model, SB_16);
+
+ memset(&dp, 0, sizeof(dp));
+ memset(&dr, 0, sizeof(dr));
+
+ /*
+ * Step1. Extract elements corresponding to this model.
+ */
+ for (i = 0; i < 2; i++) {
+ if (i == 0) {
+ mode = AUMODE_PLAY;
+ sbmodes = sbpmodes;
+ dbase = dp;
+ } else {
+ mode = AUMODE_RECORD;
+ sbmodes = sbrmodes;
+ dbase = dr;
+ }
+ for (m = sbmodes; m->model != -1; m++) {
+ if (m->model != model)
+ continue;
+
+ sbdsp_sbmode2format(&tmp, m, mode);
+ /*
+ * [0] 8bit mono
+ * [1] 8bit st
+ * [2] 16bit mono
+ * [3] 16bit st
+ */
+ idx = (m->precision / 16) * 2 + (m->channels - 1);
+ d = &dbase[idx];
+ if (d->mode == 0) {
+ /* The first elements of this room */
+ *d = tmp;
+ continue;
+ }
+
+ /* Otherwise merge frequency */
+ /*
+ * Currently the frequency of multiple elements in
+ * the same model are all contiguous.
+ */
+ if (tmp.frequency[0] == d->frequency[1]) {
+ d->frequency[1] = tmp.frequency[1];
+ } else if (tmp.frequency[1] == d->frequency[0]) {
+ d->frequency[0] = tmp.frequency[0];
+ } else {
+ panic("frequency range must be contiguous. "
+ "model=%d\n", model);
+ }
+ DPRINTF(("%s: 1 [%d] mode=%d freq={ %d, %d }\n",
+ __func__, idx, d->mode,
+ d->frequency[0], d->frequency[1]));
+ }
+ }
+
+ /*
+ * Step2. Merge dr into dp.
+ */
+ for (i = 0; i < __arraycount(dp); i++) {
+ if (dp[i].mode == 0 && dr[i].mode == 0)
+ continue;
+ /* Currently all entries in sb[pr]modes are PLAY|REC */
+ if (dp[i].mode == 0 || dr[i].mode == 0)
+ panic("invalid sb[pr]mode table?. model=%d\n", model);
+ dp[i].mode |= dr[i].mode;
+
+ /*
+ * Usually, the recording range is the same or smaller than
+ * the playback range. So extract the common range.
+ */
+ if (dp[i].frequency[0] < dr[i].frequency[0])
+ dp[i].frequency[0] = dr[i].frequency[0];
+ if (dp[i].frequency[1] > dr[i].frequency[1])
+ dp[i].frequency[1] = dr[i].frequency[1];
+
+ DPRINTF(("%s: 2 [%d] mode=%d freq={ %d, %d }\n",
+ __func__, i, dp[i].mode,
+ dp[i].frequency[0], dp[i].frequency[1]));
+ }
+
+ /*
+ * Step3. Prior to SB16, use fixed frequencies rather than raw
+ * frequency range.
+ */
+ if (!ISSB16CLASS(sc)) {
+ for (i = 0; i < __arraycount(dp); i++) {
+ if (dp[i].mode == 0)
+ continue;
+ minrate = dp[i].frequency[0];
+ maxrate = dp[i].frequency[1];
Home |
Main Index |
Thread Index |
Old Index