diff options
author | Jacob Meuser <jakemsr@cvs.openbsd.org> | 2008-10-25 22:30:44 +0000 |
---|---|---|
committer | Jacob Meuser <jakemsr@cvs.openbsd.org> | 2008-10-25 22:30:44 +0000 |
commit | fe8114f730e5473eba5ee55c81c541e29edbeea8 (patch) | |
tree | 545de71dde8d0a2e03bc8556eeaa4beb581824dd /sys | |
parent | d54880b2f6a9ada7238d4417b82adb8ce1f2ae77 (diff) |
audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.
some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.
be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.
with/ok ratchov@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/i386/pci/auglx.c | 10 | ||||
-rw-r--r-- | sys/dev/audio.c | 18 | ||||
-rw-r--r-- | sys/dev/isa/ess.c | 15 | ||||
-rw-r--r-- | sys/dev/pci/auacer.c | 6 | ||||
-rw-r--r-- | sys/dev/pci/auich.c | 39 | ||||
-rw-r--r-- | sys/dev/pci/auixp.c | 12 | ||||
-rw-r--r-- | sys/dev/pci/autri.c | 16 | ||||
-rw-r--r-- | sys/dev/pci/auvia.c | 24 | ||||
-rw-r--r-- | sys/dev/pci/azalia.c | 212 | ||||
-rw-r--r-- | sys/dev/pci/cmpci.c | 16 | ||||
-rw-r--r-- | sys/dev/pci/cs4280.c | 46 | ||||
-rw-r--r-- | sys/dev/pci/cs4281.c | 20 | ||||
-rw-r--r-- | sys/dev/pci/eap.c | 15 | ||||
-rw-r--r-- | sys/dev/pci/emuxki.c | 21 | ||||
-rw-r--r-- | sys/dev/pci/envy.c | 4 | ||||
-rw-r--r-- | sys/dev/pci/esa.c | 15 | ||||
-rw-r--r-- | sys/dev/pci/eso.c | 15 | ||||
-rw-r--r-- | sys/dev/pci/maestro.c | 7 | ||||
-rw-r--r-- | sys/dev/pci/neo.c | 4 | ||||
-rw-r--r-- | sys/dev/pci/sv.c | 12 | ||||
-rw-r--r-- | sys/dev/pci/yds.c | 14 |
21 files changed, 330 insertions, 211 deletions
diff --git a/sys/arch/i386/pci/auglx.c b/sys/arch/i386/pci/auglx.c index c42bcec981d..c72587da196 100644 --- a/sys/arch/i386/pci/auglx.c +++ b/sys/arch/i386/pci/auglx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auglx.c,v 1.2 2008/07/09 02:47:03 brad Exp $ */ +/* $OpenBSD: auglx.c,v 1.3 2008/10/25 22:30:43 jakemsr Exp $ */ /* * Copyright (c) 2008 Marc Balmer <mbalmer@openbsd.org> @@ -575,6 +575,10 @@ auglx_set_params(void *v, int setmode, int usemode, struct audio_params *play, if (setmode & AUMODE_PLAY) { play->factor = 1; play->sw_code = NULL; + if (play->precision > 16) + play->precision = 16; + if (play->channels > 2) + play->channels = 2; switch(play->encoding) { case AUDIO_ENCODING_ULAW: switch (play->channels) { @@ -766,6 +770,10 @@ auglx_set_params(void *v, int setmode, int usemode, struct audio_params *play, if (setmode & AUMODE_RECORD) { rec->factor = 1; rec->sw_code = 0; + if (rec->precision > 16) + rec->precision = 16; + if (rec->channels > 2) + rec->channels = 2; switch(rec->encoding) { case AUDIO_ENCODING_ULAW: switch (rec->channels) { diff --git a/sys/dev/audio.c b/sys/dev/audio.c index 00dec2c10d2..819da85fca4 100644 --- a/sys/dev/audio.c +++ b/sys/dev/audio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: audio.c,v 1.98 2008/09/29 02:27:38 jakemsr Exp $ */ +/* $OpenBSD: audio.c,v 1.99 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: audio.c,v 1.119 1999/11/09 16:50:47 augustss Exp $ */ /* @@ -2257,6 +2257,12 @@ audio_rint(void *v) int audio_check_params(struct audio_params *p) { + if (p->channels < 1 || p->channels > 12) + return (EINVAL); + + if (p->precision < 8 || p->precision > 32) + return (EINVAL); + if (p->encoding == AUDIO_ENCODING_PCM16) { if (p->precision == 8) p->encoding = AUDIO_ENCODING_ULINEAR; @@ -2287,15 +2293,13 @@ audio_check_params(struct audio_params *p) case AUDIO_ENCODING_ALAW: case AUDIO_ENCODING_ADPCM: if (p->precision != 8) - return (EINVAL); + p->precision = 8; break; case AUDIO_ENCODING_SLINEAR_LE: case AUDIO_ENCODING_SLINEAR_BE: case AUDIO_ENCODING_ULINEAR_LE: case AUDIO_ENCODING_ULINEAR_BE: - if (p->precision != 8 && p->precision != 16 && - p->precision != 32) - return (EINVAL); + p->precision = (p->precision + 7) & ~7; break; case AUDIO_ENCODING_MPEG_L1_STREAM: case AUDIO_ENCODING_MPEG_L1_PACKETS: @@ -2308,10 +2312,6 @@ audio_check_params(struct audio_params *p) return (EINVAL); } - /* sanity check # of channels */ - if (p->channels < 1 || p->channels > 12) - return (EINVAL); - return (0); } diff --git a/sys/dev/isa/ess.c b/sys/dev/isa/ess.c index a2941cf06bd..99c330ee742 100644 --- a/sys/dev/isa/ess.c +++ b/sys/dev/isa/ess.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ess.c,v 1.13 2008/04/21 00:32:42 jakemsr Exp $ */ +/* $OpenBSD: ess.c,v 1.14 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: ess.c,v 1.44.4.1 1999/06/21 01:18:00 thorpej Exp $ */ /* @@ -1229,11 +1229,14 @@ ess_set_params(addr, setmode, usemode, play, rec) p = mode == AUMODE_PLAY ? play : rec; - if (p->sample_rate < ESS_MINRATE || - p->sample_rate > ESS_MAXRATE || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2)) - return (EINVAL); + if (p->sample_rate < ESS_MINRATE) + p->sample_rate = ESS_MINRATE; + if (p->sample_rate > ESS_MAXRATE) + p->sample_rate = ESS_MAXRATE; + if (p->precision > 16) + p->precision = 16; + if (p->channels > 2) + p->channels = 2; p->factor = 1; p->sw_code = 0; diff --git a/sys/dev/pci/auacer.c b/sys/dev/pci/auacer.c index 24e68e3740c..55e6601ee23 100644 --- a/sys/dev/pci/auacer.c +++ b/sys/dev/pci/auacer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auacer.c,v 1.3 2008/10/21 05:36:46 fkr Exp $ */ +/* $OpenBSD: auacer.c,v 1.4 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: auacer.c,v 1.3 2004/11/10 04:20:26 kent Exp $ */ /*- @@ -578,8 +578,8 @@ auacer_set_params(void *v, int setmode, int usemode, struct audio_params *play, p->sw_code = NULL; if (mode == AUMODE_RECORD) { - if (p->channels < 1 || p->channels > 2) - return EINVAL; + if (p->channels > 2) + p->channels = 2; } switch (p->encoding) { diff --git a/sys/dev/pci/auich.c b/sys/dev/pci/auich.c index 97147001f97..e2b7e1b739c 100644 --- a/sys/dev/pci/auich.c +++ b/sys/dev/pci/auich.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auich.c,v 1.76 2008/10/23 21:50:01 jakemsr Exp $ */ +/* $OpenBSD: auich.c,v 1.77 2008/10/25 22:30:43 jakemsr Exp $ */ /* * Copyright (c) 2000,2001 Michael Shalayeff @@ -748,16 +748,21 @@ auich_set_params(v, setmode, usemode, play, rec) if (setmode & AUMODE_PLAY) { /* only 16-bit 48kHz slinear_le if s/pdif enabled */ - if (sc->sc_spdif && - ((play->sample_rate != 48000) || (play->precision != 16) || - (play->encoding != AUDIO_ENCODING_SLINEAR_LE))) - return (EINVAL); + if (sc->sc_spdif) { + play->sample_rate = 48000; + play->precision = 16; + play->encoding = AUDIO_ENCODING_SLINEAR_LE; + } } if (setmode & AUMODE_PLAY) { play->factor = 1; play->sw_code = NULL; + if (play->precision > 16) + play->precision = 16; switch(play->encoding) { case AUDIO_ENCODING_ULAW: + if (play->channels > 2) + play->channels = 2; switch (play->channels) { case 1: play->factor = 4; @@ -774,6 +779,8 @@ auich_set_params(v, setmode, usemode, play, rec) case AUDIO_ENCODING_SLINEAR_LE: switch (play->precision) { case 8: + if (play->channels > 2) + play->channels = 2; switch (play->channels) { case 1: play->factor = 4; @@ -788,6 +795,10 @@ auich_set_params(v, setmode, usemode, play, rec) } break; case 16: + if (play->channels > 6) + play->channels = 6; + if (play->channels > 1) + play->channels &= ~1; switch (play->channels) { case 1: play->factor = 2; @@ -798,23 +809,23 @@ auich_set_params(v, setmode, usemode, play, rec) case 4: ext_id = codec->vtbl->get_caps(codec); if (!(ext_id & AC97_EXT_AUDIO_SDAC)) - return (EINVAL); + play->channels = 2; break; case 6: ext_id = codec->vtbl->get_caps(codec); if ((ext_id & AC97_BITS_6CH) != AC97_BITS_6CH) - return (EINVAL); + play->channels = 2; break; default: return (EINVAL); } break; - default: - return (EINVAL); } break; case AUDIO_ENCODING_ULINEAR_LE: + if (play->channels > 2) + play->channels = 2; switch (play->precision) { case 8: switch (play->channels) { @@ -848,6 +859,8 @@ auich_set_params(v, setmode, usemode, play, rec) } break; case AUDIO_ENCODING_ALAW: + if (play->channels > 2) + play->channels = 2; switch (play->channels) { case 1: play->factor = 4; @@ -862,6 +875,8 @@ auich_set_params(v, setmode, usemode, play, rec) } break; case AUDIO_ENCODING_SLINEAR_BE: + if (play->channels > 2) + play->channels = 2; switch (play->precision) { case 8: switch (play->channels) { @@ -895,6 +910,8 @@ auich_set_params(v, setmode, usemode, play, rec) } break; case AUDIO_ENCODING_ULINEAR_BE: + if (play->channels > 2) + play->channels = 2; switch (play->precision) { case 8: switch (play->channels) { @@ -968,6 +985,10 @@ auich_set_params(v, setmode, usemode, play, rec) if (setmode & AUMODE_RECORD) { rec->factor = 1; rec->sw_code = 0; + if (rec->channels > 2) + rec->channels = 2; + if (rec->precision > 16) + rec->precision = 16; switch(rec->encoding) { case AUDIO_ENCODING_ULAW: switch (rec->channels) { diff --git a/sys/dev/pci/auixp.c b/sys/dev/pci/auixp.c index 9304863aca2..5fda4e24b1f 100644 --- a/sys/dev/pci/auixp.c +++ b/sys/dev/pci/auixp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auixp.c,v 1.21 2008/09/24 19:09:05 chl Exp $ */ +/* $OpenBSD: auixp.c,v 1.22 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: auixp.c,v 1.9 2005/06/27 21:13:09 thorpej Exp $ */ /* @@ -377,6 +377,10 @@ auixp_set_params(void *hdl, int setmode, int usemode, if (setmode & AUMODE_PLAY) { play->factor = 1; play->sw_code = NULL; + if (play->channels > 2) + play->channels = 2; + if (play->precision > 16) + play->precision = 16; switch(play->encoding) { case AUDIO_ENCODING_ULAW: switch (play->channels) { @@ -561,9 +565,13 @@ auixp_set_params(void *hdl, int setmode, int usemode, } - if (setmode & AUMODE_RECORD) { + if (setmode & AUMODE_RECORD) { rec->factor = 1; rec->sw_code = 0; + if (rec->channels > 2) + rec->channels = 2; + if (rec->precision > 16) + rec->precision = 16; switch(rec->encoding) { case AUDIO_ENCODING_ULAW: rec->sw_code = ulinear8_to_mulaw; diff --git a/sys/dev/pci/autri.c b/sys/dev/pci/autri.c index e5b8fceff18..8ef9d3fb6ce 100644 --- a/sys/dev/pci/autri.c +++ b/sys/dev/pci/autri.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autri.c,v 1.21 2008/04/21 00:32:42 jakemsr Exp $ */ +/* $OpenBSD: autri.c,v 1.22 2008/10/25 22:30:43 jakemsr Exp $ */ /* * Copyright (c) 2001 SOMEYA Yoshihiko and KUROSAWA Takahiro. @@ -1012,12 +1012,14 @@ autri_set_params(addr, setmode, usemode, play, rec) continue; p = mode == AUMODE_PLAY ? play : rec; - - if (p->sample_rate < 4000 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2)) - return (EINVAL); - + if (p->sample_rate < 4000) + p->sample_rate = 4000; + if (p->sample_rate > 48000) + p->sample_rate = 48000; + if (p->precision > 16) + p->precision = 16; + if (p->channels > 2) + p->channels = 2; p->factor = 1; p->sw_code = 0; switch (p->encoding) { diff --git a/sys/dev/pci/auvia.c b/sys/dev/pci/auvia.c index 9a6eab62cc7..0a785295abd 100644 --- a/sys/dev/pci/auvia.c +++ b/sys/dev/pci/auvia.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auvia.c,v 1.43 2008/10/23 21:50:01 jakemsr Exp $ */ +/* $OpenBSD: auvia.c,v 1.44 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: auvia.c,v 1.28 2002/11/04 16:38:49 kent Exp $ */ /*- @@ -648,16 +648,26 @@ auvia_set_params(void *addr, int setmode, int usemode, && (ext_id & AC97_BITS_6CH) == AC97_BITS_6CH) { /* ok */ } else { - return (EINVAL); + p->channels = 2; } } else { - if (p->channels != 1 && p->channels != 2) - return (EINVAL); + if (p->channels > 2) + p->channels = 2; } - if ((p->sample_rate < 4000 || p->sample_rate > 48000) || - (p->precision != 8 && p->precision != 16)) - return (EINVAL); + if (p->sample_rate < 4000) + p->sample_rate = 4000; + if (p->sample_rate > 48000) + p->sample_rate = 48000; + if (p->precision > 16) + p->precision = 16; + + /* XXX only 16-bit 48kHz slinear_le if s/pdif enabled ? */ + if (sc->sc_spdif) { + p->sample_rate = 48000; + p->precision = 16; + p->encoding = AUDIO_ENCODING_SLINEAR_LE; + } /* XXX only 16-bit 48kHz slinear_le if s/pdif enabled ? */ if (sc->sc_spdif && diff --git a/sys/dev/pci/azalia.c b/sys/dev/pci/azalia.c index 02c8677e734..d4a52b4c4dd 100644 --- a/sys/dev/pci/azalia.c +++ b/sys/dev/pci/azalia.c @@ -1,4 +1,4 @@ -/* $OpenBSD: azalia.c,v 1.61 2008/10/23 02:06:53 jakemsr Exp $ */ +/* $OpenBSD: azalia.c,v 1.62 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: azalia.c,v 1.20 2006/05/07 08:31:44 kent Exp $ */ /*- @@ -277,6 +277,10 @@ int azalia_params2fmt(const audio_params_t *, uint16_t *); int azalia_create_encodings(struct audio_format *, int, struct audio_encoding_set **); +int azalia_match_format(codec_t *, audio_params_t *); +int azalia_set_params_sub(codec_t *, int, audio_params_t *); + + /* variables */ struct cfattach azalia_ca = { sizeof(azalia_t), azalia_pci_match, azalia_pci_attach, @@ -2209,99 +2213,151 @@ azalia_get_default_params(void *addr, int mode, struct audio_params *params) } int -azalia_set_params(void *v, int smode, int umode, audio_params_t *p, - audio_params_t *r) +azalia_match_format(codec_t *codec, audio_params_t *par) { - azalia_t *az; - codec_t *codec; - void (*pswcode)(void *, u_char *, int) = NULL; - void (*rswcode)(void *, u_char *, int) = NULL; + int i; + + for (i = 0; i < codec->nformats; i++) { + if (par->encoding != codec->formats[i].encoding) + continue; + if (par->precision != codec->formats[i].precision) + continue; + if (par->channels != codec->formats[i].channels) + continue; + break; + } + + return (i); +} + +int +azalia_set_params_sub(codec_t *codec, int mode, audio_params_t *par) +{ + void (*swcode)(void *, u_char *, int) = NULL; + char *cmode; int i, j; + uint ochan, oenc, opre; - az = v; - codec = &az->codecs[az->codecno]; - if (smode & AUMODE_RECORD && r != NULL) { - for (i = 0; i < codec->nformats; i++) { - if (r->encoding != codec->formats[i].encoding) - continue; - if (r->precision != codec->formats[i].precision) - continue; - if (r->channels != codec->formats[i].channels) - continue; - break; - } - /* find a 2 channel format and emulate mono */ - if (i == codec->nformats && r->channels == 1) { - r->factor = 2; - rswcode = linear16_decimator; - for (i = 0; i < codec->nformats; i++) { - if (r->encoding != codec->formats[i].encoding) - continue; - if (r->precision != codec->formats[i].precision) - continue; - if (codec->formats[i].channels != 2) - continue; - break; - } - } + if (mode == AUMODE_PLAY) + cmode = "play"; + else + cmode = "record"; - if (i == codec->nformats) { - DPRINTF(("%s: can't find record format %u/%u/%u\n", - __func__, r->encoding, r->precision, r->channels)); - return (EINVAL); - } - for (j = 0; j < codec->formats[i].frequency_type; j++) { - if (r->sample_rate != codec->formats[i].frequency[j]) - continue; - break; - } - if (j == codec->formats[i].frequency_type) { - DPRINTF(("%s: can't find record rate %u\n", - __func__, r->sample_rate)); - return (EINVAL); + ochan = par->channels; + oenc = par->encoding; + opre = par->precision; + + i = azalia_match_format(codec, par); + if (i == codec->nformats && par->channels == 1) { + /* find a 2 channel format and emulate mono */ + par->channels = 2; + i = azalia_match_format(codec, par); + if (i != codec->nformats) { + par->factor = 2; + if (mode == AUMODE_RECORD) + swcode = linear16_decimator; + else + swcode = noswap_bytes_mts; + par->channels = 1; } - r->sw_code = rswcode; } - if (smode & AUMODE_PLAY && p != NULL) { - for (i = 0; i < codec->nformats; i++) { - if (p->encoding != codec->formats[i].encoding) - continue; - if (p->precision != codec->formats[i].precision) - continue; - if (p->channels != codec->formats[i].channels) - continue; - break; - } + par->channels = ochan; + if (i == codec->nformats && (par->precision != 16 || par->encoding != + AUDIO_ENCODING_SLINEAR_LE)) { + /* try with default encoding/precision */ + par->encoding = AUDIO_ENCODING_SLINEAR_LE; + par->precision = 16; + i = azalia_match_format(codec, par); + } + if (i == codec->nformats && par->channels == 1) { /* find a 2 channel format and emulate mono */ - if (i == codec->nformats && p->channels == 1) { - p->factor = 2; - pswcode = noswap_bytes_mts; - for (i = 0; i < codec->nformats; i++) { - if (p->encoding != codec->formats[i].encoding) - continue; - if (p->precision != codec->formats[i].precision) - continue; - if (codec->formats[i].channels != 2) - continue; - break; - } + par->channels = 2; + i = azalia_match_format(codec, par); + if (i != codec->nformats) { + par->factor = 2; + if (mode == AUMODE_RECORD) + swcode = linear16_decimator; + else + swcode = noswap_bytes_mts; + par->channels = 1; } + } + par->channels = ochan; + if (i == codec->nformats && par->channels != 2) { + /* try with default channels */ + par->encoding = oenc; + par->precision = opre; + par->channels = 2; + i = azalia_match_format(codec, par); + } + /* try with default everything */ + if (i == codec->nformats) { + par->encoding = AUDIO_ENCODING_SLINEAR_LE; + par->precision = 16; + par->channels = 2; + i = azalia_match_format(codec, par); if (i == codec->nformats) { - DPRINTF(("%s: can't find playback format %u/%u/%u\n", - __func__, p->encoding, p->precision, p->channels)); - return (EINVAL); + DPRINTF(("%s: can't find %s format %u/%u/%u\n", + __func__, cmode, par->encoding, + par->precision, par->channels)); + return EINVAL; } + } + if (codec->formats[i].frequency_type == 0) { + DPRINTF(("%s: matched %s format %d has 0 frequencies\n", + __func__, cmode, i)); + return EINVAL; + } + + for (j = 0; j < codec->formats[i].frequency_type; j++) { + if (par->sample_rate != codec->formats[i].frequency[j]) + continue; + break; + } + if (j == codec->formats[i].frequency_type) { + /* try again with default */ + par->sample_rate = 48000; for (j = 0; j < codec->formats[i].frequency_type; j++) { - if (p->sample_rate != codec->formats[i].frequency[j]) + if (par->sample_rate != codec->formats[i].frequency[j]) continue; break; } if (j == codec->formats[i].frequency_type) { - DPRINTF(("%s: can't find playback rate %u\n", - __func__, p->sample_rate)); - return (EINVAL); + DPRINTF(("%s: can't find %s rate %u\n", + __func__, cmode, par->sample_rate)); + return EINVAL; } - p->sw_code = pswcode; + } + par->sw_code = swcode; + + return (0); +} + +int +azalia_set_params(void *v, int smode, int umode, audio_params_t *p, + audio_params_t *r) +{ + azalia_t *az; + codec_t *codec; + int ret; + + az = v; + codec = &az->codecs[az->codecno]; + if (codec->nformats == 0) { + DPRINTF(("%s: codec has no formats\n", __func__)); + return EINVAL; + } + + if (smode & AUMODE_RECORD && r != NULL) { + ret = azalia_set_params_sub(codec, AUMODE_RECORD, r); + if (ret) + return (ret); + } + + if (smode & AUMODE_PLAY && p != NULL) { + ret = azalia_set_params_sub(codec, AUMODE_PLAY, p); + if (ret) + return (ret); } return (0); diff --git a/sys/dev/pci/cmpci.c b/sys/dev/pci/cmpci.c index 753fb0569f8..a2604de5f97 100644 --- a/sys/dev/pci/cmpci.c +++ b/sys/dev/pci/cmpci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmpci.c,v 1.20 2008/05/29 07:20:15 jakemsr Exp $ */ +/* $OpenBSD: cmpci.c,v 1.21 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: cmpci.c,v 1.25 2004/10/26 06:32:20 xtraeme Exp $ */ /* @@ -676,7 +676,7 @@ cmpci_set_params(void *handle, int setmode, int usemode, if (setmode & AUMODE_RECORD) { if (p->channels > 2) - return (EINVAL); + p->channels = 2; sc->sc_play_channel = 0; cmpci_reg_clear_reg_misc(sc, CMPCI_REG_ENDBDAC); cmpci_reg_clear_reg_misc(sc, CMPCI_REG_XCHGDAC); @@ -703,6 +703,8 @@ cmpci_set_params(void *handle, int setmode, int usemode, CMPCI_REG_CHB3D8C); /* format */ + if (p->precision > 16) + p->precision = 16; p->sw_code = NULL; switch (p->channels) { case 1: @@ -723,7 +725,7 @@ cmpci_set_params(void *handle, int setmode, int usemode, CMPCI_REG_LEGACY_CTRL, CMPCI_REG_NXCHG); } else - return (EINVAL); + p->channels = 2; } md_format = CMPCI_REG_FORMAT_STEREO; break; @@ -744,7 +746,7 @@ cmpci_set_params(void *handle, int setmode, int usemode, CMPCI_REG_LEGACY_CTRL, CMPCI_REG_NXCHG); } else - return (EINVAL); + p->channels = 2; } md_format = CMPCI_REG_FORMAT_STEREO; break; @@ -768,7 +770,7 @@ cmpci_set_params(void *handle, int setmode, int usemode, CMPCI_REG_LEGACY_CTRL, CMPCI_REG_NXCHG); } else - return (EINVAL); + p->channels = 2; } md_format = CMPCI_REG_FORMAT_STEREO; break; @@ -777,8 +779,6 @@ cmpci_set_params(void *handle, int setmode, int usemode, } switch (p->encoding) { case AUDIO_ENCODING_ULAW: - if (p->precision != 8) - return (EINVAL); if (mode & AUMODE_PLAY) { p->factor = 2; p->sw_code = mulaw_to_slinear16_le; @@ -789,8 +789,6 @@ cmpci_set_params(void *handle, int setmode, int usemode, } break; case AUDIO_ENCODING_ALAW: - if (p->precision != 8) - return (EINVAL); if (mode & AUMODE_PLAY) { p->factor = 2; p->sw_code = alaw_to_slinear16_le; diff --git a/sys/dev/pci/cs4280.c b/sys/dev/pci/cs4280.c index 29d9ce9d995..a17ccf3d66a 100644 --- a/sys/dev/pci/cs4280.c +++ b/sys/dev/pci/cs4280.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cs4280.c,v 1.31 2008/05/29 02:10:01 jakemsr Exp $ */ +/* $OpenBSD: cs4280.c,v 1.32 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: cs4280.c,v 1.5 2000/06/26 04:56:23 simonb Exp $ */ /* @@ -1117,37 +1117,33 @@ cs4280_set_params(addr, setmode, usemode, play, rec) if ((setmode & mode) == 0) continue; - p = mode == AUMODE_PLAY ? play : rec; - + p = mode == AUMODE_PLAY ? play : rec; if (p == play) { DPRINTFN(5,("play: sample=%ld precision=%d channels=%d\n", p->sample_rate, p->precision, p->channels)); - /* play back data format may be 8- or 16-bit and - * either stereo or mono. - * playback rate may range from 8000Hz to 48000Hz - */ - if (p->sample_rate < 8000 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2) ) { - return (EINVAL); - } } else { DPRINTFN(5,("rec: sample=%ld precision=%d channels=%d\n", p->sample_rate, p->precision, p->channels)); - /* capture data format must be 16bit stereo - * and sample rate range from 11025Hz to 48000Hz. - * - * XXX: it looks like to work with 8000Hz, - * although data sheets say lower limit is - * 11025 Hz. - */ - - if (p->sample_rate < 8000 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2) ) { - return (EINVAL); - } } + /* play back data format may be 8- or 16-bit and + * either stereo or mono. + * playback rate may range from 8000Hz to 48000Hz + * + * capture data format must be 16bit stereo + * and sample rate range from 11025Hz to 48000Hz. + * + * XXX: it looks like to work with 8000Hz, + * although data sheets say lower limit is + * 11025 Hz. + */ + if (p->sample_rate < 8000) + p->sample_rate = 8000; + if (p->sample_rate > 48000) + p->sample_rate = 48000; + if (p->precision > 16) + p->precision = 16; + if (p->channels > 2) + p->channels = 2; p->factor = 1; p->sw_code = 0; diff --git a/sys/dev/pci/cs4281.c b/sys/dev/pci/cs4281.c index 690c4e096ff..3f2f658ccee 100644 --- a/sys/dev/pci/cs4281.c +++ b/sys/dev/pci/cs4281.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cs4281.c,v 1.21 2008/04/21 00:32:43 jakemsr Exp $ */ +/* $OpenBSD: cs4281.c,v 1.22 2008/10/25 22:30:43 jakemsr Exp $ */ /* $Tera: cs4281.c,v 1.18 2000/12/27 14:24:45 tacha Exp $ */ /* @@ -517,20 +517,18 @@ cs4281_set_params(addr, setmode, usemode, play, rec) if (p == play) { DPRINTFN(5,("play: samp=%ld precision=%d channels=%d\n", p->sample_rate, p->precision, p->channels)); - if (p->sample_rate < 6023 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2)) { - return (EINVAL); - } } else { DPRINTFN(5,("rec: samp=%ld precision=%d channels=%d\n", p->sample_rate, p->precision, p->channels)); - if (p->sample_rate < 6023 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2)) { - return (EINVAL); - } } + if (p->sample_rate < 6023) + p->sample_rate = 6023; + if (p->sample_rate > 48000) + p->sample_rate = 48000; + if (p->precision > 16) + p->precision = 16; + if (p->channels > 2) + p->channels = 2; p->factor = 1; p->sw_code = 0; diff --git a/sys/dev/pci/eap.c b/sys/dev/pci/eap.c index 9461fc12dd7..5de9a1d109c 100644 --- a/sys/dev/pci/eap.c +++ b/sys/dev/pci/eap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eap.c,v 1.34 2008/06/26 05:42:17 ray Exp $ */ +/* $OpenBSD: eap.c,v 1.35 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: eap.c,v 1.46 2001/09/03 15:07:37 reinoud Exp $ */ /* @@ -944,11 +944,14 @@ eap_set_params(void *addr, int setmode, int usemode, p = mode == AUMODE_PLAY ? play : rec; - if (p->sample_rate < 4000 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2)) - return (EINVAL); - + if (p->sample_rate < 4000) + p->sample_rate = 4000; + if (p->sample_rate > 48000) + p->sample_rate = 48000; + if (p->precision > 16) + p->precision = 16; + if (p->channels > 2) + p->channels = 2; p->factor = 1; p->sw_code = 0; switch (p->encoding) { diff --git a/sys/dev/pci/emuxki.c b/sys/dev/pci/emuxki.c index 5d0a0274342..0fce95915e5 100644 --- a/sys/dev/pci/emuxki.c +++ b/sys/dev/pci/emuxki.c @@ -1,4 +1,4 @@ -/* $OpenBSD: emuxki.c,v 1.29 2008/06/26 05:42:17 ray Exp $ */ +/* $OpenBSD: emuxki.c,v 1.30 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: emuxki.c,v 1.1 2001/10/17 18:39:41 jdolecek Exp $ */ /*- @@ -1573,16 +1573,20 @@ int emuxki_voice_set_srate(struct emuxki_voice *voice, u_int32_t srate) { if (voice->use & EMU_VOICE_USE_PLAY) { - if ((srate < 4000) || (srate > 48000)) - return (EINVAL); + if (srate < 4000) + srate = 4000; + if (srate > 48000) + srate = 48000; voice->sample_rate = srate; emuxki_channel_set_srate(voice->dataloc.chan[0], srate); if (voice->stereo) emuxki_channel_set_srate(voice->dataloc.chan[1], srate); } else { - if ((srate < 8000) || (srate > 48000)) - return (EINVAL); + if (srate < 8000) + srate = 8000; + if (srate > 48000) + srate = 48000; voice->sample_rate = srate; if (emuxki_voice_adc_rate(voice) < 0) { voice->sample_rate = 0; @@ -2117,8 +2121,11 @@ emuxki_set_vparms(struct emuxki_voice *voice, struct audio_params *p) AUMODE_PLAY : AUMODE_RECORD; p->factor = 1; p->sw_code = NULL; - if (p->channels != 1 && p->channels != 2) - return (EINVAL);/* Will change when streams come in use */ + if (p->channels > 2) + p->channels = 2; + if (p->precision > 16) + p->precision = 16; + /* Will change when streams come in use */ /* * Always use slinear_le for recording, as how to set otherwise diff --git a/sys/dev/pci/envy.c b/sys/dev/pci/envy.c index 0693dd91cba..47ce102268c 100644 --- a/sys/dev/pci/envy.c +++ b/sys/dev/pci/envy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: envy.c,v 1.9 2008/04/30 17:31:26 ratchov Exp $ */ +/* $OpenBSD: envy.c,v 1.10 2008/10/25 22:30:43 jakemsr Exp $ */ /* * Copyright (c) 2007 Alexandre Ratchov <alex@caoua.org> * @@ -688,7 +688,7 @@ envy_set_params(void *self, int setmode, int usemode, if (setmode == (AUMODE_PLAY | AUMODE_RECORD) && p->sample_rate != r->sample_rate) { DPRINTF("%s: play/rec rates mismatch\n", DEVNAME(sc)); - return EINVAL; + r->sample_rate = p->sample_rate; } rate = (setmode & AUMODE_PLAY) ? p->sample_rate : r->sample_rate; for (i = 0; envy_rates[i].rate < rate; i++) { diff --git a/sys/dev/pci/esa.c b/sys/dev/pci/esa.c index c549cd9d09b..798aa358a1c 100644 --- a/sys/dev/pci/esa.c +++ b/sys/dev/pci/esa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: esa.c,v 1.15 2008/05/29 02:10:01 jakemsr Exp $ */ +/* $OpenBSD: esa.c,v 1.16 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: esa.c,v 1.12 2002/03/24 14:17:35 jmcneill Exp $ */ /* @@ -282,11 +282,14 @@ esa_set_params(void *hdl, int setmode, int usemode, struct audio_params *play, break; } - if (p->sample_rate < ESA_MINRATE || - p->sample_rate > ESA_MAXRATE || - (p->precision != 8 && p->precision != 16) || - (p->channels < 1 || p->channels > 2)) - return (EINVAL); + if (p->sample_rate < ESA_MINRATE) + p->sample_rate = ESA_MINRATE; + if (p->sample_rate > ESA_MAXRATE) + p->sample_rate = ESA_MAXRATE; + if (p->precision > 16) + p->precision = 16; + if (p->channels > 2) + p->channels = 2; p->factor = 1; p->sw_code = 0; diff --git a/sys/dev/pci/eso.c b/sys/dev/pci/eso.c index b26aec62434..86fb61f0f7e 100644 --- a/sys/dev/pci/eso.c +++ b/sys/dev/pci/eso.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eso.c,v 1.26 2008/05/29 07:20:15 jakemsr Exp $ */ +/* $OpenBSD: eso.c,v 1.27 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: eso.c,v 1.48 2006/12/18 23:13:39 kleink Exp $ */ /* @@ -708,11 +708,14 @@ eso_set_params(void *hdl, int setmode, int usemode, p = (mode == AUMODE_PLAY) ? play : rec; - if (p->sample_rate < ESO_MINRATE || - p->sample_rate > ESO_MAXRATE || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2)) - return (EINVAL); + if (p->sample_rate < ESO_MINRATE) + p->sample_rate = ESO_MINRATE; + if (p->sample_rate > ESO_MAXRATE) + p->sample_rate = ESO_MAXRATE; + if (p->precision > 16) + p->precision = 16; + if (p->channels > 2) + p->channels = 2; p->factor = 1; p->sw_code = NULL; diff --git a/sys/dev/pci/maestro.c b/sys/dev/pci/maestro.c index 0fadf6321fc..a8751dbd8e0 100644 --- a/sys/dev/pci/maestro.c +++ b/sys/dev/pci/maestro.c @@ -1,4 +1,4 @@ -/* $OpenBSD: maestro.c,v 1.25 2008/05/29 02:10:01 jakemsr Exp $ */ +/* $OpenBSD: maestro.c,v 1.26 2008/10/25 22:30:43 jakemsr Exp $ */ /* $FreeBSD: /c/ncvs/src/sys/dev/sound/pci/maestro.c,v 1.3 2000/11/21 12:22:11 julian Exp $ */ /* * FreeBSD's ESS Agogo/Maestro driver @@ -1090,9 +1090,8 @@ maestro_set_params(hdl, setmode, usemode, play, rec) play->factor = 1; play->sw_code = NULL; - if (play->channels != 1 && play->channels != 2) - return (EINVAL); - + if (play->channels > 2) + play->channels = 2; sc->play.mode = MAESTRO_PLAY; if (play->channels == 2) diff --git a/sys/dev/pci/neo.c b/sys/dev/pci/neo.c index 2baccef69de..f67cc61505d 100644 --- a/sys/dev/pci/neo.c +++ b/sys/dev/pci/neo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: neo.c,v 1.22 2008/05/29 02:10:01 jakemsr Exp $ */ +/* $OpenBSD: neo.c,v 1.23 2008/10/25 22:30:43 jakemsr Exp $ */ /* * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk> @@ -862,8 +862,6 @@ neo_set_params(addr, setmode, usemode, play, rec) if (p->sample_rate < (samplerates[x] + samplerates[x + 1]) / 2) break; - if (x == 8) return (EINVAL); - p->sample_rate = samplerates[x]; nm_loadcoeff(sc, mode, x); diff --git a/sys/dev/pci/sv.c b/sys/dev/pci/sv.c index 678388a3c2f..b3146af3706 100644 --- a/sys/dev/pci/sv.c +++ b/sys/dev/pci/sv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sv.c,v 1.24 2008/04/21 00:32:43 jakemsr Exp $ */ +/* $OpenBSD: sv.c,v 1.25 2008/10/25 22:30:43 jakemsr Exp $ */ /* * Copyright (c) 1998 Constantine Paul Sapuntzakis @@ -709,12 +709,14 @@ sv_set_params(addr, setmode, usemode, p, r) mode = SV_DMAA_FORMAT16 | SV_DMAC_FORMAT16; else mode = 0; + if (p->channels > 2) + p->channels = 2; if (p->channels == 2) mode |= SV_DMAA_STEREO | SV_DMAC_STEREO; - else if (p->channels != 1) - return (EINVAL); - if (p->sample_rate < 2000 || p->sample_rate > 48000) - return (EINVAL); + if (p->sample_rate < 2000) + p->sample_rate = 2000; + if (p->sample_rate > 48000) + p->sample_rate = 48000; p->sw_code = pswcode; r->sw_code = rswcode; diff --git a/sys/dev/pci/yds.c b/sys/dev/pci/yds.c index 64d3885ea7a..aed3abfe339 100644 --- a/sys/dev/pci/yds.c +++ b/sys/dev/pci/yds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: yds.c,v 1.30 2008/05/29 02:10:01 jakemsr Exp $ */ +/* $OpenBSD: yds.c,v 1.31 2008/10/25 22:30:43 jakemsr Exp $ */ /* $NetBSD: yds.c,v 1.5 2001/05/21 23:55:04 minoura Exp $ */ /* @@ -1211,10 +1211,14 @@ yds_set_params(addr, setmode, usemode, play, rec) p = mode == AUMODE_PLAY ? play : rec; - if (p->sample_rate < 4000 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2)) - return (EINVAL); + if (p->sample_rate < 4000) + p->sample_rate = 4000; + if (p->sample_rate > 48000) + p->sample_rate = 48000; + if (p->precision > 16) + p->precision = 16; + if (p->channels > 2) + p->channels = 2; p->factor = 1; p->sw_code = 0; |