sad

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

commit b86364909a9bf32c03b18f8699c493bee125c474
parent 9654660fdca4a2fa15760d1d0f02d451a6569f9a
Author: sin <sin@2f30.org>
Date:   Wed, 31 Dec 2014 17:58:19 +0000

Use Format for outputs too

Diffstat:
Malsa.c | 6+++---
Mconfig.def.h | 39++++++++++++++++++++++++++++++++++++---
Mfifo.c | 2+-
Moutput.c | 18+++++++-----------
Msad.h | 2+-
Msndio.c | 12++++++------
6 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/alsa.c b/alsa.c @@ -60,7 +60,7 @@ err0: } static int -alsaopen(int bits, int rate, int channels) +alsaopen(Format *fmt) { snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE; int r; @@ -71,12 +71,12 @@ alsaopen(int bits, int rate, int channels) } if ((r = snd_pcm_set_params(hdl, format, SND_PCM_ACCESS_RW_INTERLEAVED, - channels, rate, 1, 500000)) < 0) { + fmt->channels, fmt->rate, 1, 500000)) < 0) { warnx("send_pcm_set_params: %s\n", snd_strerror(r)); goto err0; } - framesize = (bits + 7) / 8 * channels; + framesize = (fmt->bits + 7) / 8 * fmt->channels; return 0; err0: diff --git a/config.def.h b/config.def.h @@ -1,7 +1,40 @@ #define RESAMPLEQUALITY SOXR_QQ Outputdesc outputdescs[] = { - { "sndio", 16, 44100, 2, 0, 0, &sndiooutput, NULL }, - { "alsa" , 16, 44100, 2, 1, 0, &alsaoutput, NULL }, - { "fifo", 16, 44100, 2, 0, 0, &fifooutput, NULL }, + { + .name = "sndio", + .fmt = { + .bits = 16, + .rate = 44100, + .channels = 2 + }, + .enabled = 0, + .active = 0, + .output = &sndiooutput, + .resampler = NULL + }, + { + .name = "alsa", + .fmt = { + .bits = 16, + .rate = 44100, + .channels = 2 + }, + .enabled = 0, + .active = 0, + .output = &alsaoutput, + .resampler = NULL + }, + { + .name = "fifo", + .fmt = { + .bits = 16, + .rate = 44100, + .channels = 2 + }, + .enabled = 0, + .active = 0, + .output = &fifooutput, + .resampler = NULL + }, }; diff --git a/fifo.c b/fifo.c @@ -19,7 +19,7 @@ fifovol(int vol) } static int -fifoopen(int bits, int rate, int channels) +fifoopen(Format *fmt) { unlink("/tmp/sad-fifo"); if (mkfifo("/tmp/sad-fifo", 0644) < 0) { diff --git a/output.c b/output.c @@ -12,9 +12,7 @@ typedef struct { char *name; - int bits; - int rate; - int channels; + Format fmt; int enabled; int active; Output *output; @@ -35,8 +33,8 @@ initresampler(Format *fmt, Outputdesc *desc) if (desc->resampler) soxr_delete(desc->resampler); - desc->resampler = soxr_create(fmt->rate, desc->rate, - desc->channels, + desc->resampler = soxr_create(fmt->rate, desc->fmt.rate, + desc->fmt.channels, NULL, &iospec, &quality, @@ -73,9 +71,7 @@ openoutput(Outputdesc *desc) if (desc->active) return 0; - if (desc->output->open(desc->bits, - desc->rate, - desc->channels) < 0) { + if (desc->output->open(&desc->fmt) < 0) { desc->active = 0; return -1; } @@ -144,16 +140,16 @@ playoutput(Format *fmt, Outputdesc *desc, void *inbuf, size_t nbytes) if (!desc->active) return 0; - if (desc->rate == fmt->rate) { + if (desc->fmt.rate == fmt->rate) { if (desc->output->play(inbuf, nbytes) < 0) return -1; return 0; } /* perform SRC */ - framesize = (desc->bits + 7) / 8 * desc->channels; + framesize = (desc->fmt.bits + 7) / 8 * desc->fmt.channels; inframes = nbytes / framesize; - ratio = (float)desc->rate / fmt->rate; + ratio = (float)desc->fmt.rate / fmt->rate; outframes = inframes * ratio + 1; outbuf = malloc(outframes * framesize); if (!outbuf) diff --git a/sad.h b/sad.h @@ -42,7 +42,7 @@ typedef struct { typedef struct { int (*vol)(int); - int (*open)(int, int, int); + int (*open)(Format *); int (*play)(void *, size_t); int (*close)(void); } Output; diff --git a/sndio.c b/sndio.c @@ -20,7 +20,7 @@ sndiovol(int vol) } static int -sndioopen(int bits, int rate, int channels) +sndioopen(Format *fmt) { struct sio_par par; @@ -31,9 +31,9 @@ sndioopen(int bits, int rate, int channels) } sio_initpar(&par); - par.bits = bits; - par.rate = rate; - par.pchan = channels; + par.bits = fmt->bits; + par.rate = fmt->rate; + par.pchan = fmt->channels; par.sig = 1; par.le = SIO_LE_NATIVE; @@ -42,8 +42,8 @@ sndioopen(int bits, int rate, int channels) goto err0; } - if (par.bits != bits || par.rate != rate || - par.pchan != channels || par.le != SIO_LE_NATIVE || + if (par.bits != fmt->bits || par.rate != fmt->rate || + par.pchan != fmt->channels || par.le != SIO_LE_NATIVE || par.sig != 1) { warnx("unsupported audio params"); goto err0;