From a89c5fcfcb24c43838792fe59f25b0e6f4718a17 Mon Sep 17 00:00:00 2001 From: jdolecek Date: Sun, 23 Dec 2001 23:14:59 +0000 Subject: [PATCH] Merge in changes sent by Michael Shalayeff, from OpenBSD port of this driver: - use better default for DAC level (previous produced distorted output) - preserve DAC setting in between openings --- sys/dev/pci/emuxki.c | 63 +++++++++++++++++++++++++---------------- sys/dev/pci/emuxkivar.h | 4 +-- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/sys/dev/pci/emuxki.c b/sys/dev/pci/emuxki.c index 2051532bd8c4..564f5ae8b2a9 100644 --- a/sys/dev/pci/emuxki.c +++ b/sys/dev/pci/emuxki.c @@ -1,4 +1,4 @@ -/* $NetBSD: emuxki.c,v 1.6 2001/12/23 22:54:08 jdolecek Exp $ */ +/* $NetBSD: emuxki.c,v 1.7 2001/12/23 23:14:59 jdolecek Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -57,7 +57,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: emuxki.c,v 1.6 2001/12/23 22:54:08 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: emuxki.c,v 1.7 2001/12/23 23:14:59 jdolecek Exp $"); #include #include @@ -879,7 +879,7 @@ static void emuxki_chanparms_set_defaults(struct emuxki_channel *chan) { chan->fxsend.a.level = chan->fxsend.b.level = - chan->fxsend.c.level = chan->fxsend.d.level = 0xff; /* max */ + chan->fxsend.c.level = chan->fxsend.d.level = 0xc0; /* not max */ chan->fxsend.a.dest = 0x0; chan->fxsend.b.dest = 0x1; chan->fxsend.c.dest = 0x2; @@ -1241,24 +1241,31 @@ emuxki_voice_new(struct emuxki_softc *sc, u_int8_t use) struct emuxki_voice *voice; int s; - if ((voice = malloc(sizeof(*voice), M_DEVBUF, M_WAITOK)) == NULL) - return (NULL); - voice->sc = sc; + s = splaudio(); + voice = sc->lvoice; + sc->lvoice = NULL; + splx(s); + + if (!voice) { + if (!(voice = malloc(sizeof(*voice), M_DEVBUF, M_WAITOK))) + return (NULL); + voice->sc = sc; + voice->state = !EMU_VOICE_STATE_STARTED; + voice->stereo = EMU_VOICE_STEREO_NOTSET; + voice->b16 = 0; + voice->sample_rate = 0; + if (use & EMU_VOICE_USE_PLAY) + voice->dataloc.chan[0] = voice->dataloc.chan[0] = NULL; + else + voice->dataloc.source = EMU_RECSRC_NOTSET; + voice->buffer = NULL; + voice->blksize = 0; + voice->trigblk = 0; + voice->blkmod = 0; + voice->inth = NULL; + voice->inthparam = NULL; + } voice->use = use; - voice->state = !EMU_VOICE_STATE_STARTED; - voice->stereo = EMU_VOICE_STEREO_NOTSET; - voice->b16 = 0; - voice->sample_rate = 0; - if (use & EMU_VOICE_USE_PLAY) - voice->dataloc.chan[0] = voice->dataloc.chan[0] = NULL; - else - voice->dataloc.source = EMU_RECSRC_NOTSET; - voice->buffer = NULL; - voice->blksize = 0; - voice->trigblk = 0; - voice->blkmod = 0; - voice->inth = NULL; - voice->inthparam = NULL; s = splaudio(); LIST_INSERT_HEAD((&sc->voices), voice, next); @@ -1270,17 +1277,23 @@ emuxki_voice_new(struct emuxki_softc *sc, u_int8_t use) static void emuxki_voice_delete(struct emuxki_voice *voice) { - int s; + struct emuxki_softc *sc = voice->sc; + struct emuxki_voice *lvoice; + int s; if (voice->state & EMU_VOICE_STATE_STARTED) emuxki_voice_halt(voice); s = splaudio(); LIST_REMOVE(voice, next); + lvoice = sc->lvoice; + sc->lvoice = voice; splx(s); - emuxki_voice_dataloc_destroy(voice); - free(voice, M_DEVBUF); + if (lvoice) { + emuxki_voice_dataloc_destroy(lvoice); + free(lvoice, M_DEVBUF); + } } static int @@ -1299,12 +1312,12 @@ emuxki_voice_set_stereo(struct emuxki_voice *voice, u_int8_t stereo) fxsend.c.dest = 0x2; fxsend.d.dest = 0x3; if (voice->stereo) { - fxsend.a.level = fxsend.c.level = 0xff; + fxsend.a.level = fxsend.c.level = 0xc0; fxsend.b.level = fxsend.d.level = 0x00; emuxki_channel_set_fxsend(voice->dataloc.chan[0], &fxsend); fxsend.a.level = fxsend.c.level = 0x00; - fxsend.b.level = fxsend.d.level = 0xff; + fxsend.b.level = fxsend.d.level = 0xc0; emuxki_channel_set_fxsend(voice->dataloc.chan[1], &fxsend); } /* No else : default is good for mono */ diff --git a/sys/dev/pci/emuxkivar.h b/sys/dev/pci/emuxkivar.h index 1233b0852703..ab3353c8c559 100644 --- a/sys/dev/pci/emuxkivar.h +++ b/sys/dev/pci/emuxkivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: emuxkivar.h,v 1.2 2001/12/23 22:52:49 jdolecek Exp $ */ +/* $NetBSD: emuxkivar.h,v 1.3 2001/12/23 23:14:59 jdolecek Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -253,7 +253,7 @@ struct emuxki_softc { struct ac97_codec_if *codecif; struct device *sc_audev; - struct emuxki_voice *pvoice, *rvoice; + struct emuxki_voice *pvoice, *rvoice, *lvoice; }; #endif /* !_DEV_PCI_EMU10K1VAR_H_ */