diff --git a/libsndio/sio.c b/libsndio/sio.c index acb7a74..717e0fa 100644 --- a/libsndio/sio.c +++ b/libsndio/sio.c @@ -63,11 +63,11 @@ sio_open(const char *str, unsigned int mode, int nbio) if (hdl != NULL) return hdl; #if defined(USE_SUN) - return _sio_sun_open("rsnd/0", mode, nbio); + return _sio_sun_open("rsnd/default", mode, nbio); #elif defined(USE_OSS) - return _sio_oss_open("rsnd/0", mode, nbio); + return _sio_oss_open("rsnd/default", mode, nbio); #elif defined(USE_ALSA) - return _sio_alsa_open("rsnd/0", mode, nbio); + return _sio_alsa_open("rsnd/default", mode, nbio); #else return NULL; #endif diff --git a/libsndio/sio_alsa.c b/libsndio/sio_alsa.c index c4b0d23..615cbed 100644 --- a/libsndio/sio_alsa.c +++ b/libsndio/sio_alsa.c @@ -304,6 +304,8 @@ _sio_alsa_open(const char *str, unsigned mode, int nbio) if (err < 0) DALSA("couldn't attach to stderr", err); #endif + if (strcmp(p, "default") == 0) + p = "0"; len = strlen(p); hdl->devname = malloc(len + sizeof(DEVNAME_PREFIX)); if (hdl->devname == NULL) diff --git a/libsndio/sio_oss.c b/libsndio/sio_oss.c index c44ff60..56b62b5 100644 --- a/libsndio/sio_oss.c +++ b/libsndio/sio_oss.c @@ -108,6 +108,8 @@ static int sio_oss_xrun(struct sio_oss_hdl *); static size_t sio_oss_read(struct sio_hdl *, void *, size_t); static size_t sio_oss_write(struct sio_hdl *, const void *, size_t); static void sio_oss_close(struct sio_hdl *); +static int sio_oss_setvol(struct sio_hdl *, unsigned int); +static void sio_oss_getvol(struct sio_hdl *); static struct sio_ops sio_oss_ops = { sio_oss_close, @@ -121,8 +123,8 @@ static struct sio_ops sio_oss_ops = { sio_oss_nfds, sio_oss_pollfd, sio_oss_revents, - NULL, /* setvol */ - NULL, /* getvol */ + sio_oss_setvol, + sio_oss_getvol, }; /* @@ -234,6 +236,7 @@ sio_oss_getfd(const char *str, unsigned int mode, int nbio) char path[DEVPATH_MAX]; unsigned int devnum; int fd, flags, val; + audio_buf_info bi; p = _sndio_parsetype(str, "rsnd"); if (p == NULL) { @@ -248,12 +251,16 @@ sio_oss_getfd(const char *str, unsigned int mode, int nbio) DPRINTF("sio_oss_getfd: %s: '/' expected\n", str); return -1; } - p = _sndio_parsenum(p, &devnum, 255); - if (p == NULL || *p != '\0') { - DPRINTF("sio_oss_getfd: %s: number expected after '/'\n", str); - return -1; + if (strcmp(p, "default") == 0) { + strlcpy(path, DEVPATH_PREFIX, sizeof(path)); + } else { + 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); } - snprintf(path, sizeof(path), DEVPATH_PREFIX "%u", devnum); if (mode == (SIO_PLAY | SIO_REC)) flags = O_RDWR; else @@ -763,4 +770,40 @@ sio_oss_revents(struct sio_hdl *sh, struct pollfd *pfd) return revents; } +static int +sio_oss_setvol(struct sio_hdl *sh, unsigned int vol) +{ + struct sio_oss_hdl *hdl = (struct sio_oss_hdl *)sh; + int newvol; + + /* Scale to 0..100 */ + newvol = (100 * vol + SIO_MAXVOL / 2) / SIO_MAXVOL; + newvol = newvol | (newvol << 8); + + if (ioctl(hdl->fd, SNDCTL_DSP_SETPLAYVOL, &newvol) < 0) { + DPERROR("sio_oss_setvol"); + hdl->sio.eof = 1; + return 0; + } + + return 1; +} + +static void +sio_oss_getvol(struct sio_hdl *sh) +{ + struct sio_oss_hdl *hdl = (struct sio_oss_hdl *)sh; + int vol; + + if (ioctl(hdl->fd, SNDCTL_DSP_GETPLAYVOL, &vol) < 0) { + DPERROR("sio_oss_getvol"); + hdl->sio.eof = 1; + return; + } + + /* Use left channel volume and scale to SIO_MAXVOL */ + vol = (SIO_MAXVOL * (vol & 0x7f) + 50) / 100; + _sio_onvol_cb(&hdl->sio, vol); +} + #endif /* defined USE_OSS */ diff --git a/libsndio/sio_sun.c b/libsndio/sio_sun.c index 6901b5d..ab73e08 100644 --- a/libsndio/sio_sun.c +++ b/libsndio/sio_sun.c @@ -291,10 +291,14 @@ sio_sun_getfd(const char *str, unsigned int mode, int nbio) DPRINTF("sio_sun_getfd: %s: '/' expected\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; + 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; + } } snprintf(path, sizeof(path), DEVPATH_PREFIX "%u", devnum); if (mode == (SIO_PLAY | SIO_REC)) diff --git a/sndiod/sndiod.c b/sndiod/sndiod.c index b2c6e4c..8158966 100644 --- a/sndiod/sndiod.c +++ b/sndiod/sndiod.c @@ -82,7 +82,7 @@ * default device in server mode */ #ifndef DEFAULT_DEV -#define DEFAULT_DEV "rsnd/0" +#define DEFAULT_DEV "rsnd/default" #endif void sigint(int);