ncmixer

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

commit abcd809f86cfdefa8da5afa63dc2b54a7fc6fa2c
parent d72e2c3cda2bc4b736352e4315bd700504f0d2e1
Author: sin <sin@2f30.org>
Date:   Wed,  8 Jun 2016 09:55:57 +0100

Always clear input buffers to avoid mixing stale data

If one of the two inputs were ready ncmixer would mix stale
data on the input that was not ready.  Now it just mixes in
silence instead.

Diffstat:
Mncmixer.c | 13+++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/ncmixer.c b/ncmixer.c @@ -266,7 +266,6 @@ consume(struct input *in) { int n; - memset(in->buf, 0, sizeof(in->buf)); do { n = read(in->clifd, in->buf, sizeof(in->buf)); } while (n == -1 && errno == EINTR); @@ -297,7 +296,6 @@ mix_master(struct output *out, struct input *in0, struct input *in1) short *buf = (short *)out->buf; int i; - memset(out->buf, 0, sizeof(out->buf)); out->nsamples = MAX(in0->nsamples, in1->nsamples); for (i = 0; i < out->nsamples; i++) { *buf = *ch0 * 0.707 + *ch1 * 0.707; @@ -314,7 +312,6 @@ mix_monitor(struct output *out, struct input *in0, struct input *in1) short *buf = (short *)out->buf; int i; - memset(out->buf, 0, sizeof(out->buf)); out->nsamples = MAX(in0->nsamples, in1->nsamples); for (i = 0; i < out->nsamples; i++) { *ch0 *= in0->monitor; @@ -412,7 +409,7 @@ loop(void) struct pollfd pfd[16]; struct input *in; struct output *out; - int i, ret, clifd, nready, gotdata; + int i, ret, clifd, nready; for (i = 0; i < LEN(pfd); i++) { pfd[i].fd = -1; @@ -472,9 +469,10 @@ loop(void) } /* read pcm data from sockets */ - gotdata = 0; for (i = 0; i < LEN(inputs); i++) { in = &inputs[i]; + memset(in->buf, 0, sizeof(in->buf)); + in->nsamples = 0; if (in->clifd == -1) continue; if (pfd[in->clifd].revents & (POLLIN | POLLHUP)) { @@ -484,14 +482,12 @@ loop(void) pfd[in->clifd].events = 0; close(in->clifd); in->clifd = -1; - } else { - gotdata = 1; } } } /* play dat shit! */ - for (i = 0; gotdata != 0 && i < LEN(outputs); i++) { + for (i = 0; i < LEN(outputs); i++) { out = &outputs[i]; /* open output device on demand */ if (out->sio_hdl == NULL) { @@ -507,6 +503,7 @@ loop(void) attenuate(&inputs[0], 1.0f - fabsf(xfpos)); attenuate(&inputs[1], 1.0f); } + memset(out->buf, 0, sizeof(out->buf)); out->mix(out, &inputs[0], &inputs[1]); ret = audio_play(out->sio_hdl, out->buf, out->nsamples * 2);