diff --git a/configure b/configure index fc0dcab..4b1facf 100755 --- a/configure +++ b/configure @@ -24,6 +24,7 @@ Usage: configure [options] --disable-umidi disable usb-midi backend --with-libbsd use the libbsd rather than bsd-compat/* --without-libbsd don't use libbsd +--default-dev=DEV set default device [$dev] END } @@ -49,6 +50,7 @@ unset includedir # path where to install header file unset libdir # path where to install library unset defs # no extra #defines unset ldadd # no extra libraries (-l options) +unset dev # # guess OS-specific parameters @@ -170,6 +172,9 @@ for i; do --without-libbsd) libbsd=no shift;; + --default-dev=*) + dev="${i#--default-dev=}" + shift;; CC=*|CFLAGS=*|LDFLAGS=*) vars="$vars$i$nl" shift;; @@ -241,6 +246,11 @@ if [ $libbsd = yes ]; then ldadd="$ldadd -lbsd" fi +if [ -n "$dev" ]; then + defs="$defs -DDEFAULT_DEV='\"$dev\"'" +fi + + for f in Makefile aucat/Makefile midicat/Makefile sndiod/Makefile \ libsndio/Makefile \ sndioctl/Makefile \ @@ -262,6 +272,7 @@ do -e "s:@vars@:${vars}:" \ -e "s:@precision@:$precision:" \ -e "s:@user@:$user:" \ + -e "s:@devs@:$devs:" \ < $f.in > $f done diff --git a/libsndio/sio.c b/libsndio/sio.c index 4b25930..0195f70 100644 --- a/libsndio/sio.c +++ b/libsndio/sio.c @@ -62,7 +62,7 @@ sio_open(const char *str, unsigned int mode, int nbio) if (hdl != NULL) return hdl; #if defined(USE_SUN) - return _sio_sun_open("rsnd/default", mode, nbio); + return _sio_sun_open("rsnd/0", mode, nbio); #elif defined(USE_OSS) return _sio_oss_open("rsnd/default", mode, nbio); #elif defined(USE_ALSA) diff --git a/libsndio/sio_sun.c b/libsndio/sio_sun.c index f6040b0..bc4dab8 100644 --- a/libsndio/sio_sun.c +++ b/libsndio/sio_sun.c @@ -290,14 +290,10 @@ sio_sun_getfd(const char *str, unsigned int mode, int nbio) DPRINTF("sio_sun_getfd: %s: '/' expected\n", str); return -1; } - if (strcmp(p, "default") == 0) { - devnum = 0; - } else { - p = _sndio_parsenum(p, &devnum, 255); - if (p == NULL || *p != '\0') { - DPRINTF("sio_sun_getfd: %s: number expected after '/'\n", str); - return -1; - } + p = _sndio_parsenum(p, &devnum, 255); + if (p == NULL || *p != '\0') { + DPRINTF("sio_sun_getfd: %s: number expected after '/'\n", str); + return -1; } snprintf(path, sizeof(path), DEVPATH_PREFIX "%u", devnum); if (mode == (SIO_PLAY | SIO_REC)) diff --git a/libsndio/sioctl.c b/libsndio/sioctl.c index e558404..2ecc1e8 100644 --- a/libsndio/sioctl.c +++ b/libsndio/sioctl.c @@ -45,7 +45,7 @@ sioctl_open(const char *str, unsigned int mode, int nbio) if (hdl != NULL) return hdl; #if defined(USE_SUN_MIXER) - return _sioctl_sun_open("rsnd/default", mode, nbio); + return _sioctl_sun_open("rsnd/0", mode, nbio); #else return NULL; #endif diff --git a/libsndio/sioctl_sun.c b/libsndio/sioctl_sun.c index 88a80c5..45267d7 100644 --- a/libsndio/sioctl_sun.c +++ b/libsndio/sioctl_sun.c @@ -84,14 +84,24 @@ static int initmute(struct sioctl_sun_hdl *hdl, struct mixer_devinfo *info) { struct mixer_devinfo mi; + char name[MAX_AUDIO_DEV_LEN]; - mi.index = info->next; for (mi.index = info->next; mi.index != -1; mi.index = mi.next) { if (ioctl(hdl->fd, AUDIO_MIXER_DEVINFO, &mi) < 0) break; if (strcmp(mi.label.name, AudioNmute) == 0) return mi.index; } + + /* try "_mute" suffix */ + snprintf(name, sizeof(name), "%s_mute", info->label.name); + for (mi.index = 0; ; mi.index++) { + if (ioctl(hdl->fd, AUDIO_MIXER_DEVINFO, &mi) < 0) + break; + if (info->mixer_class == mi.mixer_class && + strcmp(mi.label.name, name) == 0) + return mi.index; + } return -1; } diff --git a/sndioctl/sndioctl.1 b/sndioctl/sndioctl.1 index f8645ba..68c82ce 100644 --- a/sndioctl/sndioctl.1 +++ b/sndioctl/sndioctl.1 @@ -100,20 +100,22 @@ If .Qq \&! is used instead of a number, then the switch is toggled. .Sh EXAMPLES -The following will set all -.Ar output -channels -.Ar level -control to zero: +Increase the +.Cm level +control affecting all +.Cm output +channels by 10% of the maximum: .Pp -.Dl $ sndioctl output.level=0 +.Dl $ sndioctl output.level=+0.1 .Pp -The following set all -.Ar output -channels -.Ar mute +Mute all output channels: +.Pp +.Dl $ sndioctl output.mute=1 +.Pp +Toggle the above +.Cm mute control: .Pp -.Dl $ sndioctl output.mute=0 +.Dl $ sndioctl output.mute=! .Sh SEE ALSO .Xr sioctl_open 3 diff --git a/sndioctl/sndioctl.c b/sndioctl/sndioctl.c index a800c90..eb961bf 100644 --- a/sndioctl/sndioctl.c +++ b/sndioctl/sndioctl.c @@ -374,7 +374,14 @@ print_val(struct info *p, int mono) switch (p->desc.type) { case SIOCTL_NUM: case SIOCTL_SW: - printf("%.2g", p->curval / (float)p->desc.maxval); + if (p->desc.maxval == 1) + printf("%d", p->curval); + else + /* + * For now, maxval is always 127 or 255, + * so three decimals is always ideal. + */ + printf("%.3f", p->curval / (float)p->desc.maxval); break; case SIOCTL_VEC: case SIOCTL_LIST: @@ -389,7 +396,11 @@ print_val(struct info *p, int mono) if (more) printf(","); print_node(&e->desc.node1, mono); - printf(":%.2g", e->curval / (float)e->desc.maxval); + if (e->desc.maxval == 1) + printf(":%d", e->curval); + else + printf(":%.3f", + e->curval / (float)e->desc.maxval); more = 1; } } diff --git a/sndiod/sndiod.8 b/sndiod/sndiod.8 index 81f868d..40b9ef2 100644 --- a/sndiod/sndiod.8 +++ b/sndiod/sndiod.8 @@ -208,6 +208,14 @@ Sub-devices that are applied after will be attached to this device. Device mode and parameters are determined from sub-devices attached to it. +If no +.Fl f +option is used, +.Nm +will use +.Pa rsnd/0 , rsnd/1 , +.No ... , +.Pa rsnd/3 . .It Fl j Ar flag Control whether program channels are joined or expanded if the number of channels requested by a program is not equal diff --git a/sndiod/sndiod.c b/sndiod/sndiod.c index cacf8e3..f427be8 100644 --- a/sndiod/sndiod.c +++ b/sndiod/sndiod.c @@ -78,13 +78,6 @@ #define DEFAULT_BUFSZ 7680 #endif -/* - * default device in server mode - */ -#ifndef DEFAULT_DEV -#define DEFAULT_DEV "rsnd/default" -#endif - void sigint(int); void sighup(int); void opt_ch(int *, int *); @@ -111,6 +104,18 @@ char usagestr[] = "usage: sndiod [-d] [-a flag] [-b nframes] " "[-Q port] [-q port] [-r rate] [-s name] [-t mode] [-U unit]\n\t" "[-v volume] [-w flag] [-z nframes]\n"; +/* + * default audio devices + */ +static char *default_devs[] = { +#ifdef DEFAULT_DEV + DEFAULT_DEV, +#else + "rsnd/0", "rsnd/1", "rsnd/2", "rsnd/3", +#endif + NULL +}; + /* * default MIDI ports */ @@ -361,7 +366,7 @@ mkopt(char *path, struct dev *d, int main(int argc, char **argv) { - int c, i, background, unit; + int c, i, background, unit, devindex; int pmin, pmax, rmin, rmax; char base[SOCKPATH_MAX], path[SOCKPATH_MAX]; unsigned int mode, dup, mmc, vol; @@ -399,6 +404,7 @@ main(int argc, char **argv) aparams_init(&par); mode = MODE_PLAY | MODE_REC; tcpaddr_list = NULL; + devindex = 0; while ((c = getopt(argc, argv, "a:b:c:C:de:F:f:j:L:m:Q:q:r:s:t:U:v:w:x:z:")) != -1) { @@ -448,8 +454,8 @@ main(int argc, char **argv) break; case 's': if ((d = dev_list) == NULL) { - d = mkdev(DEFAULT_DEV, &par, 0, bufsz, round, - rate, hold, autovol); + d = mkdev(default_devs[devindex++], &par, 0, + bufsz, round, rate, hold, autovol); } if (mkopt(optarg, d, pmin, pmax, rmin, rmax, mode, vol, mmc, dup) == NULL) @@ -482,6 +488,7 @@ main(int argc, char **argv) case 'f': mkdev(optarg, &par, 0, bufsz, round, rate, hold, autovol); + devindex = -1; break; case 'F': if (dev_list == NULL) @@ -503,8 +510,12 @@ main(int argc, char **argv) for (i = 0; default_ports[i] != NULL; i++) mkport(default_ports[i], 0); } - if (dev_list == NULL) - mkdev(DEFAULT_DEV, &par, 0, bufsz, round, rate, hold, autovol); + if (devindex != -1) { + for (i = devindex; default_devs[i] != NULL; i++) { + mkdev(default_devs[i], &par, 0, + bufsz, round, rate, 0, autovol); + } + } for (d = dev_list; d != NULL; d = d->next) { if (opt_byname(d, "default")) continue; diff --git a/sndiod/sock.c b/sndiod/sock.c index 28c75b5..72a1ee5 100644 --- a/sndiod/sock.c +++ b/sndiod/sock.c @@ -151,7 +151,7 @@ sock_close(struct sock *f) } #endif if (f->pstate > SOCK_AUTH) - sock_sesrefs--; + sock_sesrefs -= f->sesrefs; if (f->slot) { slot_del(f->slot); f->slot = NULL; @@ -792,11 +792,12 @@ sock_auth(struct sock *f) if (sock_sesrefs == 0) { /* start a new session */ memcpy(sock_sescookie, p->cookie, AMSG_COOKIELEN); + f->sesrefs = 1; } else if (memcmp(sock_sescookie, p->cookie, AMSG_COOKIELEN) != 0) { /* another session is active, drop connection */ return 0; } - sock_sesrefs++; + sock_sesrefs += f->sesrefs; f->pstate = SOCK_HELLO; return 1; } diff --git a/sndiod/sock.h b/sndiod/sock.h index 41f0916..9926890 100644 --- a/sndiod/sock.h +++ b/sndiod/sock.h @@ -64,6 +64,7 @@ struct sock { #define SOCK_CTLVAL 2 /* send value changes */ unsigned int ctlops; /* bitmap of above */ int ctlsyncpending; /* CTLSYNC waiting to be transmitted */ + unsigned int sesrefs; /* 1 if socket belongs to a session */ }; struct sock *sock_new(int fd);