ncmixer

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

commit ef23bf8ba52a0095ca1e26dd609ffeaca2cc0187
parent 134e02da998c064d90bf0de4b0151d9850607c6c
Author: sin <sin@2f30.org>
Date:   Fri,  3 Jun 2016 11:55:42 +0100

Open and mix monitor output as well

Diffstat:
Mncmixer.c | 64+++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 25 deletions(-)

diff --git a/ncmixer.c b/ncmixer.c @@ -58,14 +58,18 @@ struct sio_hdl *sio_hdl_master; struct sio_hdl *sio_hdl_monitor; /* input pcm data on channel 0 */ -unsigned short ch0_buf[NSAMPLES]; -unsigned ch0_nsamples; +short ch0_buf[NSAMPLES]; +int ch0_nsamples; /* input pcm data on channel 1 */ -unsigned short ch1_buf[NSAMPLES]; -unsigned ch1_nsamples; +short ch1_buf[NSAMPLES]; +int ch1_nsamples; + /* master pcm data */ -unsigned short master_buf[NSAMPLES]; -unsigned master_nsamples; +short master_buf[NSAMPLES]; +int master_nsamples; +/* monitor pcm data */ +short monitor_buf[NSAMPLES]; +int monitor_nsamples; struct sio_hdl * audio_open(char *dev) @@ -236,22 +240,19 @@ attenuate(void) { } -/* mix channel 0 with channel 1 */ -void -mix(void) +int +mix(short *buf) { short *ch0 = (short *)ch0_buf; short *ch1 = (short *)ch1_buf; - short *out = (short *)master_buf; - int i; - - memset(master_buf, 0, sizeof(master_buf)); - master_nsamples = MAX(ch0_nsamples, ch1_nsamples); - for (i = 0; i < master_nsamples; i++) { - *out = *ch0 * 0.707 + *ch1 * 0.707; - ch0++, ch1++, out++; + int i, nsamples; + + nsamples = MAX(ch0_nsamples, ch1_nsamples); + for (i = 0; i < nsamples; i++) { + *buf = *ch0 * 0.707 + *ch1 * 0.707; + ch0++, ch1++, buf++; } - /* XXX: mix monitor buffer as well */ + return nsamples; } int @@ -305,7 +306,7 @@ loop(void) struct sockaddr_un sun; socklen_t len; struct pollfd pfd[5]; - int i, clifd, nready; + int i, ret, clifd, nready; #define CH0_LISTEN 1 #define CH1_LISTEN 2 @@ -392,15 +393,28 @@ loop(void) } } - attenuate(); - mix(); + 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 && - audio_play(sio_hdl_master, master_buf, - master_nsamples * 2) == -1) - audio_close(&sio_hdl_master); + 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); + if (ret == -1) + audio_close(&sio_hdl_monitor); + } + draw(); } }