ncmixer

ncurses audio mixer for DJ'ing
git clone git://git.2f30.org/ncmixer
Log | Files | Refs | README | LICENSE

commit 8667fc2dcea62389ed4f781ab5a45b495f0a3999
parent d35783849afae22e289d6da06cc159e9e5cd7ad3
Author: sin <sin@2f30.org>
Date:   Thu,  2 Jun 2016 18:06:38 +0100

Be explicit about errors when initializing sndio

Allow some tolerance for sample rate.  When used with sndiod this
is never an issue but if the underlying card is used directly the sample
rate reported could vary a little bit.

Diffstat:
Mncmixer.c | 35++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/ncmixer.c b/ncmixer.c @@ -61,7 +61,7 @@ audio_open(void) sio_hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0); if (sio_hdl == NULL) { - warnx("sio_open: failed"); + warnx("failed to open audio device"); return -1; } @@ -72,23 +72,36 @@ audio_open(void) par.sig = 1; par.le = SIO_LE_NATIVE; - if (sio_setpar(sio_hdl, &par) == 0 || - sio_getpar(sio_hdl, &par) == 0) { - warnx("sio_{set,get}par: failed"); + if (sio_setpar(sio_hdl, &par) == 0) { + warnx("failed to set params"); goto err0; } - if (par.bits != BITS || - par.rate != RATE || - par.pchan != CHANS || - par.le != SIO_LE_NATIVE || - par.sig != 1) { - warnx("unsupported audio params"); + if (sio_getpar(sio_hdl, &par) == 0) { + warnx("failed to get params"); + goto err0; + } + + if (par.pchan != CHANS) { + warnx("failed to set number of channels"); + goto err0; + } + + if (par.sig != 1 || + par.bits != BITS || + par.le != SIO_LE_NATIVE) { + warnx("failed to set format"); + goto err0; + } + + if (par.rate < RATE * 995 / 1000 || + par.rate > RATE * 1005 / 1000) { + warnx("failed to set rate"); goto err0; } if (sio_start(sio_hdl) == 0) { - warnx("sio_start: failed"); + warnx("failed to start audio device"); goto err0; }