sad

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

commit 4464316187a2b41156437b5f5c3ed009edfeede1
parent e291d818db0a570743cab248d3c8eab72dede827
Author: sin <sin@2f30.org>
Date:   Sat, 27 Dec 2014 14:21:56 +0000

Mostly style fixes

Diffstat:
Moutput.c | 80++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Msndio.c | 2--
2 files changed, 49 insertions(+), 33 deletions(-)

diff --git a/output.c b/output.c @@ -8,14 +8,16 @@ #include "sad.h" -static struct { +typedef struct { char *name; int bits; long rate; int channels; int enabled; Output *output; -} outputs[] = { +} Outputdesc; + +static Outputdesc Outputdescs[] = { { "sndio", 16, 44100, 2, 1, &sndiooutput }, }; @@ -26,65 +28,79 @@ static int inchannels; int openoutput(const char *name) { + Outputdesc *desc; int i; - for (i = 0; i < LEN(outputs); i++) { - if (!outputs[i].enabled) + for (i = 0; i < LEN(Outputdescs); i++) { + desc = &Outputdescs[i]; + if (!desc->enabled) continue; - if (strcmp(outputs[i].name, name)) + if (strcmp(desc->name, name)) continue; - return outputs[i].output->open(outputs[i].bits, - outputs[i].rate, - outputs[i].channels); + return desc->output->open(desc->bits, + desc->rate, + desc->channels); } return -1; } int -closeoutput(const char *name) +openoutputs(void) { - int i; + int i, r = 0; - for (i = 0; i < LEN(outputs); i++) { - if (!outputs[i].enabled) - continue; - if (strcmp(outputs[i].name, name)) - continue; - return outputs[i].output->close(); + for (i = 0; i < LEN(Outputdescs); i++) { + if (openoutput(Outputdescs[i].name) < 0) + r = -1; + else + printf("Opened %s output\n", + Outputdescs[i].name); } + return r; } int -closeoutputs(void) +closeoutput(const char *name) { - int i, r = 0; + Outputdesc *desc; + int i; - for (i = 0; i < LEN(outputs); i++) - if (closeoutput(outputs[i].name) < 0) - r = -1; - return r; + for (i = 0; i < LEN(Outputdescs); i++) { + desc = &Outputdescs[i]; + if (!desc->enabled) + continue; + if (strcmp(desc->name, name)) + continue; + return desc->output->close(); + } + return -1; } int -openoutputs(void) +closeoutputs(void) { int i, r = 0; - for (i = 0; i < LEN(outputs); i++) - if (openoutput(outputs[i].name) < 0) + for (i = 0; i < LEN(Outputdescs); i++) + if (closeoutput(Outputdescs[i].name) < 0) r = -1; + else + printf("Closed %s output\n", + Outputdescs[i].name); return r; } int playoutput(void *buf, size_t nbytes) { + Outputdesc *desc; int i, r = 0; - for (i = 0; i < LEN(outputs); i++) { - if (!outputs[i].enabled) + for (i = 0; i < LEN(Outputdescs); i++) { + desc = &Outputdescs[i]; + if (!desc->enabled) continue; - if (outputs[i].output->play(buf, nbytes) < 0) + if (desc->output->play(buf, nbytes) < 0) r = -1; } return r; @@ -93,12 +109,14 @@ playoutput(void *buf, size_t nbytes) int voloutput(int vol) { + Outputdesc *desc; int i, r = 0; - for (i = 0; i < LEN(outputs); i++) { - if (!outputs[i].enabled) + for (i = 0; i < LEN(Outputdescs); i++) { + desc = &Outputdescs[i]; + if (!desc->enabled) continue; - if (outputs[i].output->vol(vol) < 0) + if (desc->output->vol(vol) < 0) r = -1; } return r; diff --git a/sndio.c b/sndio.c @@ -54,7 +54,6 @@ sndioopen(int bits, int rate, int channels) goto err0; } - puts("Opened sndio output"); return 0; err0: @@ -75,7 +74,6 @@ sndioclose(void) if (hdl) sio_close(hdl); hdl = NULL; - puts("Closed sndio output"); return 0; }