From 6b35921d2b6f9be7cd8d904666b042cca450563e Mon Sep 17 00:00:00 2001 From: Tobias Kortkamp Date: Thu, 1 Feb 2018 08:49:12 +0100 Subject: [PATCH 1/4] sio_oss.c: Add missing audio_buf_info --- libsndio/sio_oss.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libsndio/sio_oss.c b/libsndio/sio_oss.c index c44ff60..dee1d53 100644 --- a/libsndio/sio_oss.c +++ b/libsndio/sio_oss.c @@ -234,6 +234,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) { From 31cfb9b6dc7ba308fb5867f94a3621f9d4ed9e5b Mon Sep 17 00:00:00 2001 From: Tobias Kortkamp Date: Thu, 1 Feb 2018 08:53:20 +0100 Subject: [PATCH 2/4] Support rsnd/default for opening the default device --- libsndio/sio.c | 6 +++--- libsndio/sio_alsa.c | 2 ++ libsndio/sio_oss.c | 14 +++++++++----- libsndio/sio_sun.c | 12 ++++++++---- sndiod/sndiod.c | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) 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 dee1d53..982136c 100644 --- a/libsndio/sio_oss.c +++ b/libsndio/sio_oss.c @@ -249,12 +249,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 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); From f1cd80bb723060aab6e5f3b7c9c9098b145e1347 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Fri, 2 Mar 2018 07:32:49 +0100 Subject: [PATCH 3/4] oss: add support for sio_setvol(). From Tobias Kortkamp , thanks. --- libsndio/sio_oss.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/libsndio/sio_oss.c b/libsndio/sio_oss.c index 982136c..2f5e9e7 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, }; /* @@ -768,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 = 1.0 * 100 * vol / 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 * 1.0 * (vol & 0x7f) / 100; + _sio_onvol_cb(&hdl->sio, vol); +} + #endif /* defined USE_OSS */ From 220e7731bcfeca425365ecd07e01faabf9ae08d4 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Fri, 2 Mar 2018 07:42:53 +0100 Subject: [PATCH 4/4] oss: use integer arithmetic to scale volume. --- libsndio/sio_oss.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsndio/sio_oss.c b/libsndio/sio_oss.c index 2f5e9e7..56b62b5 100644 --- a/libsndio/sio_oss.c +++ b/libsndio/sio_oss.c @@ -777,7 +777,7 @@ sio_oss_setvol(struct sio_hdl *sh, unsigned int vol) int newvol; /* Scale to 0..100 */ - newvol = 1.0 * 100 * vol / SIO_MAXVOL; + newvol = (100 * vol + SIO_MAXVOL / 2) / SIO_MAXVOL; newvol = newvol | (newvol << 8); if (ioctl(hdl->fd, SNDCTL_DSP_SETPLAYVOL, &newvol) < 0) { @@ -802,7 +802,7 @@ sio_oss_getvol(struct sio_hdl *sh) } /* Use left channel volume and scale to SIO_MAXVOL */ - vol = SIO_MAXVOL * 1.0 * (vol & 0x7f) / 100; + vol = (SIO_MAXVOL * (vol & 0x7f) + 50) / 100; _sio_onvol_cb(&hdl->sio, vol); }