ncmixer

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

commit 9fb4e2701289919ff9e947c5bab0b23b5623ddb7
parent 0d5b55aa3dba8236043d41e8692b684af56e32ed
Author: sin <sin@2f30.org>
Date:   Fri,  3 Jun 2016 18:21:40 +0100

Add primitive mixing support

Diffstat:
MMakefile | 2+-
Mncmixer.c | 22+++++++++++++++++++---
2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ CPPFLAGS = -DDEBUG CFLAGS = -Wall -LDLIBS = -lsndio -lcurses +LDLIBS = -lsndio -lcurses -lm OBJ = ncmixer.o BIN = ncmixer diff --git a/ncmixer.c b/ncmixer.c @@ -56,6 +56,7 @@ struct input { int listenfd; int clifd; short buf[NSAMPLES]; + short attenuated_buf[NSAMPLES]; int nsamples; int active; int monitor; @@ -249,15 +250,23 @@ consume(struct input *in) } void -attenuate(void) +attenuate(struct input *in, float factor) { + short *ch0 = (short *)in->buf; + short *out = (short *)in->attenuated_buf; + int i; + + for (i = 0; i < in->nsamples; i++) { + *out = *ch0 * factor; + ch0++, out++; + } } int mix(struct input *in1, struct input *in2, struct output *out) { - short *ch0 = (short *)in1->buf; - short *ch1 = (short *)in2->buf; + short *ch0 = (short *)in1->attenuated_buf; + short *ch1 = (short *)in2->attenuated_buf; short *buf = (short *)out->buf; int i; @@ -403,6 +412,13 @@ loop(void) if (out->sio_hdl == NULL) continue; } + if (xfpos <= 0) { + attenuate(&inputs[0], 1.0); + attenuate(&inputs[1], 1.0 - abs(xfpos)); + } else { + attenuate(&inputs[0], 1.0 - abs(xfpos)); + attenuate(&inputs[1], 1.0); + } mix(&inputs[0], &inputs[1], out); ret = audio_play(out->sio_hdl, out->buf, out->nsamples * 2);