ncmixer

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

commit b053a679e3237e2c565703a311386364bde5b7e5
parent ef23bf8ba52a0095ca1e26dd609ffeaca2cc0187
Author: sin <sin@2f30.org>
Date:   Fri,  3 Jun 2016 14:39:02 +0100

Group the outputs together in an array

We should do something similar for the inputs too.

Diffstat:
Mncmixer.c | 52++++++++++++++++++++++------------------------------
1 file changed, 22 insertions(+), 30 deletions(-)

diff --git a/ncmixer.c b/ncmixer.c @@ -54,22 +54,20 @@ int ch1_active; int ch0_monitor; int ch1_monitor; -struct sio_hdl *sio_hdl_master; -struct sio_hdl *sio_hdl_monitor; - -/* input pcm data on channel 0 */ short ch0_buf[NSAMPLES]; int ch0_nsamples; -/* input pcm data on channel 1 */ short ch1_buf[NSAMPLES]; int ch1_nsamples; -/* master pcm data */ -short master_buf[NSAMPLES]; -int master_nsamples; -/* monitor pcm data */ -short monitor_buf[NSAMPLES]; -int monitor_nsamples; +struct output { + char *name; + struct sio_hdl *sio_hdl; + short buf[NSAMPLES]; + int nsamples; +} outputs[] = { + { .name = MASTER_DEV, .sio_hdl = NULL, .buf = { 0 }, .nsamples = 0 }, + { .name = MONITOR_DEV, .sio_hdl = NULL, .buf = { 0 }, .nsamples = 0 } +}; struct sio_hdl * audio_open(char *dev) @@ -306,6 +304,7 @@ loop(void) struct sockaddr_un sun; socklen_t len; struct pollfd pfd[5]; + struct output *out; int i, ret, clifd, nready; #define CH0_LISTEN 1 @@ -393,26 +392,19 @@ loop(void) } } - memset(master_buf, 0, sizeof(master_buf)); - master_nsamples = mix(master_buf); - if (sio_hdl_master == NULL) { - sio_hdl_master = audio_open(MASTER_DEV); - if (sio_hdl_master != NULL) - ret = audio_play(sio_hdl_master, master_buf, - master_nsamples * 2); - if (ret == -1) - audio_close(&sio_hdl_master); - } - - memset(monitor_buf, 0, sizeof(monitor_buf)); - monitor_nsamples = mix(monitor_buf); - if (sio_hdl_monitor == NULL) { - sio_hdl_monitor = audio_open(MONITOR_DEV); - if (sio_hdl_monitor != NULL) - ret = audio_play(sio_hdl_monitor, monitor_buf, - monitor_nsamples * 2); + for (i = 0; i < LEN(outputs); i++) { + out = &outputs[i]; + if (out->sio_hdl == NULL) { + out->sio_hdl = audio_open(out->name); + if (out->sio_hdl == NULL) + continue; + memset(out->buf, 0, sizeof(out->buf)); + out->nsamples = mix(out->buf); + ret = audio_play(out->sio_hdl, out->buf, + out->nsamples * 2); if (ret == -1) - audio_close(&sio_hdl_monitor); + audio_close(&out->sio_hdl); + } } draw();