From 220e7731bcfeca425365ecd07e01faabf9ae08d4 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Fri, 2 Mar 2018 07:42:53 +0100 Subject: [PATCH] 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); }