2022-07-05 20:49:51 -05:00
|
|
|
#include "mix.h"
|
|
|
|
#include "stddef.h"
|
2022-07-06 17:17:06 -05:00
|
|
|
#include "time.h"
|
2022-07-05 20:49:51 -05:00
|
|
|
#include "sound.h"
|
2022-12-14 13:01:42 -06:00
|
|
|
#include "dsp.h"
|
|
|
|
#include <string.h>
|
2022-07-05 20:49:51 -05:00
|
|
|
|
|
|
|
static struct bus bus[256];
|
2023-01-15 11:16:25 -06:00
|
|
|
static int first = 0; /* First bus available */
|
|
|
|
static int first_on = -1;
|
2022-07-05 20:49:51 -05:00
|
|
|
short mastermix[BUF_FRAMES*CHANNELS];
|
|
|
|
|
2023-01-15 11:16:25 -06:00
|
|
|
void mixer_init() {
|
2022-07-05 20:49:51 -05:00
|
|
|
for (int i = 0; i < 256; i++) {
|
2023-01-15 11:16:25 -06:00
|
|
|
bus[i].next = i+1;
|
|
|
|
bus[i].on = 0;
|
|
|
|
bus[i].id = i;
|
2022-07-05 20:49:51 -05:00
|
|
|
}
|
|
|
|
|
2023-01-15 11:16:25 -06:00
|
|
|
bus[255].next = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bus *first_free_bus(struct dsp_filter in) {
|
|
|
|
if (first == -1) return NULL;
|
|
|
|
struct bus *ret = bus[first];
|
|
|
|
first = ret->next;
|
|
|
|
ret->on = 1;
|
|
|
|
ret->in = in;
|
|
|
|
|
|
|
|
ret->next = first_on;
|
|
|
|
first_on = ret->id;
|
|
|
|
|
|
|
|
return ret;
|
2022-07-05 20:49:51 -05:00
|
|
|
}
|
|
|
|
|
2022-07-19 15:13:15 -05:00
|
|
|
void bus_free(struct bus *bus)
|
|
|
|
{
|
2023-01-15 11:16:25 -06:00
|
|
|
bus->next = first;
|
2022-07-19 15:13:15 -05:00
|
|
|
bus->on = 0;
|
2023-01-15 11:16:25 -06:00
|
|
|
first = bus->id;
|
2022-07-19 15:13:15 -05:00
|
|
|
}
|
|
|
|
|
2022-07-06 17:17:06 -05:00
|
|
|
void bus_fill_buffers(short *master, int n) {
|
2023-01-15 11:16:25 -06:00
|
|
|
int curbus = first_one
|
|
|
|
memset(master, 0, BUF_FRAMES*CHANNELS*sizeof(short));
|
|
|
|
while (bus[curbus].next != -1) {
|
|
|
|
dsp_run(bus[curbus].in, bus[curbus].buf, BUF_FRAMES);
|
|
|
|
for (int i = 0; i < BUF_FRAMES*CHANNELS; i++)
|
|
|
|
master[i] += bus[curbus].buf[i];
|
|
|
|
|
|
|
|
curbus = bus[curbus].next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-07-05 20:49:51 -05:00
|
|
|
for (int i = 0; i < 256; i++) {
|
2022-07-06 17:17:06 -05:00
|
|
|
if (bus[i].on != 1) continue;
|
|
|
|
dsp_run(bus[i].in, bus[i].buf, BUF_FRAMES);
|
2022-07-05 20:49:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < 256; j++) {
|
|
|
|
if (!bus[j].on) continue;
|
2022-07-06 17:17:06 -05:00
|
|
|
for (int i = 0; i < BUF_FRAMES*CHANNELS; i++) {
|
|
|
|
master[i] += bus[j].buf[i];
|
|
|
|
}
|
2022-07-05 20:49:51 -05:00
|
|
|
}
|
2023-01-15 11:16:25 -06:00
|
|
|
*/
|
2022-11-25 07:12:31 -06:00
|
|
|
}
|