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"
|
|
|
|
|
|
|
|
static struct bus bus[256];
|
|
|
|
short mastermix[BUF_FRAMES*CHANNELS];
|
|
|
|
|
2022-07-06 17:17:06 -05:00
|
|
|
struct bus *first_free_bus(struct dsp_filter in) {
|
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) {
|
|
|
|
bus[i].on = 1;
|
|
|
|
bus[i].in = in;
|
|
|
|
return &bus[i];
|
|
|
|
}
|
2022-07-05 20:49:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-07-19 15:13:15 -05:00
|
|
|
void bus_free(struct bus *bus)
|
|
|
|
{
|
|
|
|
bus->on = 0;
|
|
|
|
}
|
|
|
|
|
2022-07-06 17:17:06 -05:00
|
|
|
void bus_fill_buffers(short *master, int n) {
|
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
|
|
|
}
|
|
|
|
|
2022-07-06 17:17:06 -05:00
|
|
|
memset(master, 0, BUF_FRAMES*CHANNELS*sizeof(short));
|
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
|
|
|
}
|
2022-11-25 07:12:31 -06:00
|
|
|
}
|