ncmixer

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

commit d060ee88e4d1d995d472bcd533d4725730023579
parent c4f556d850b4e2f0879a3e930b813251d21c8499
Author: sin <sin@2f30.org>
Date:   Fri Jun  3 11:21:57 +0100

Make audio_*() functions more flexible

Diffstat:
ncmixer.c | 32+++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/ncmixer.c b/ncmixer.c @@ -51,7 +51,8 @@ int ch1_active; int ch0_monitor; int ch1_monitor; -struct sio_hdl *sio_hdl; +struct sio_hdl *sio_hdl_master; +struct sio_hdl *sio_hdl_monitor; /* input pcm data on channel 0 */ unsigned short ch0_buf[NSAMPLES]; @@ -63,15 +64,16 @@ unsigned ch1_nsamples; unsigned short out_buf[NSAMPLES]; unsigned out_nsamples; -int -audio_open(void) +struct sio_hdl * +audio_open(char *dev) { + struct sio_hdl *sio_hdl; struct sio_par par; - sio_hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0); + sio_hdl = sio_open(dev, SIO_PLAY, 0); if (sio_hdl == NULL) { warnx("failed to open audio device"); - return -1; + return NULL; } sio_initpar(&par); @@ -114,25 +116,25 @@ audio_open(void) goto err0; } - return 0; + return sio_hdl; err0: sio_close(sio_hdl); sio_hdl = NULL; - return -1; + return NULL; } int -audio_play(void *buf, int n) +audio_play(struct sio_hdl *sio_hdl, void *buf, int n) { return sio_write(sio_hdl, buf, n); } void -audio_close(void) +audio_close(struct sio_hdl **sio_hdl) { - if (sio_hdl != NULL) - sio_close(sio_hdl); - sio_hdl = NULL; + if (*sio_hdl != NULL) + sio_close(*sio_hdl); + *sio_hdl = NULL; } /* XXX: curses input function */ @@ -388,7 +390,7 @@ loop(void) attenuate(); mix(); - audio_play(out_buf, out_nsamples * 2); + audio_play(sio_hdl_master, out_buf, out_nsamples * 2); draw(); } } @@ -423,10 +425,10 @@ int main(void) { curses_init(); - audio_open(); + sio_hdl_master = audio_open(SIO_DEVANY); draw(); loop(); - audio_close(); + audio_close(&sio_hdl_master); curses_exit(); return 0; }