sad

simple audio daemon
git clone git://git.2f30.org/sad
Log | Files | Refs | LICENSE

commit 2b3ed27b5266a539ae42872c6460e08456df9256
parent 588471687b811345cf05be4689386b3bff7f6452
Author: sin <sin@2f30.org>
Date:   Thu, 25 Dec 2014 14:49:29 +0000

Add volume control

Diffstat:
Mcmd.c | 13+++++++++++++
Msad.h | 1+
Msndio.c | 8++++++++
3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/cmd.c b/cmd.c @@ -17,6 +17,19 @@ cmdstatus(int fd, int argc, char **argv) void cmdvolume(int fd, int argc, char **argv) { + int vol; + + if (argc != 2) { + dprintf(fd, "ERR \"usage: volume [0-100]\"\n"); + return; + } + + vol = atoi(argv[1]); + if (vol < 0 || vol > 100) { + dprintf(fd, "ERR \"volume should be between [0, 100]\"\n"); + return; + } + output->vol(vol); } void diff --git a/sad.h b/sad.h @@ -35,6 +35,7 @@ typedef struct { typedef struct { int (*init)(void); + int (*vol)(int); int (*open)(int, int, int); void (*play)(void *, size_t); int (*close)(void); diff --git a/sndio.c b/sndio.c @@ -16,6 +16,13 @@ sndioinit(void) } static int +sndiovol(int vol) +{ + sio_setvol(hdl, (SIO_MAXVOL * vol) / 100); + return 0; +} + +static int sndioopen(int bits, int rate, int channels) { struct sio_par par; @@ -82,6 +89,7 @@ sndioexit(void) Output sndiooutput = { .init = sndioinit, + .vol = sndiovol, .open = sndioopen, .play = sndioplay, .close = sndioclose,