commit 9799fa01fb5625e5e8f5866453441fa9fd488fcf
parent 9fb4e2701289919ff9e947c5bab0b23b5623ddb7
Author: sin <sin@2f30.org>
Date: Fri, 3 Jun 2016 18:34:48 +0100
Mix monitor as well
Diffstat:
M | ncmixer.c | | | 37 | +++++++++++++++++++++++++++++++++---- |
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/ncmixer.c b/ncmixer.c
@@ -52,6 +52,13 @@ int xfading;
int xftimeout; /* in milliseconds */
enum { NONE, LEFT, RIGHT } direction;
+/* forward decls */
+struct input;
+struct output;
+
+int mix_master(struct output *, struct input *, struct input *);
+int mix_monitor(struct output *, struct input *, struct input *);
+
struct input {
int listenfd;
int clifd;
@@ -70,9 +77,10 @@ struct output {
struct sio_hdl *sio_hdl;
short buf[NSAMPLES];
int nsamples;
+ int (*mix)(struct output *, struct input *, struct input *);
} outputs[] = {
- { .name = MASTER_DEV },
- { .name = MONITOR_DEV }
+ { .name = MASTER_DEV, .mix = mix_master },
+ { .name = MONITOR_DEV, .mix = mix_monitor }
};
void
@@ -263,7 +271,7 @@ attenuate(struct input *in, float factor)
}
int
-mix(struct input *in1, struct input *in2, struct output *out)
+mix_master(struct output *out, struct input *in1, struct input *in2)
{
short *ch0 = (short *)in1->attenuated_buf;
short *ch1 = (short *)in2->attenuated_buf;
@@ -280,6 +288,27 @@ mix(struct input *in1, struct input *in2, struct output *out)
}
int
+mix_monitor(struct output *out, struct input *in1, struct input *in2)
+{
+ short *ch0 = (short *)in1->buf;
+ short *ch1 = (short *)in2->buf;
+ short *buf = (short *)out->buf;
+ int i;
+
+ memset(out->buf, 0, sizeof(out->buf));
+ out->nsamples = MAX(in1->nsamples, in2->nsamples);
+ for (i = 0; i < out->nsamples; i++) {
+ if (in1->monitor == 0)
+ *ch0 = 0;
+ if (in2->monitor == 0)
+ *ch1 = 0;
+ *buf = *ch0 * 0.707 + *ch1 * 0.707;
+ ch0++, ch1++, buf++;
+ }
+ return out->nsamples;
+}
+
+int
server_listen(char *name)
{
struct sockaddr_un sun;
@@ -419,7 +448,7 @@ loop(void)
attenuate(&inputs[0], 1.0 - abs(xfpos));
attenuate(&inputs[1], 1.0);
}
- mix(&inputs[0], &inputs[1], out);
+ out->mix(out, &inputs[0], &inputs[1]);
ret = audio_play(out->sio_hdl, out->buf,
out->nsamples * 2);
if (ret == -1)