typedef void (*f_drvrun)(struct VM_*, struct BBQ_*);
typedef void (*f_drvdel)(struct VM_*, struct BBQ_*);
-#define DRVINI(a) ANN m_bool a(struct VM_ *vm __attribute__((unused)), struct BBQ_* di __attribute__((unused)))
-#define DRVRUN(a) ANN void a(struct VM_ *vm __attribute__((unused)), struct BBQ_* di __attribute__((unused)))
-#define DRVDEL(a) ANN void a(struct VM_ *vm __attribute__((unused)), struct BBQ_* di __attribute__((unused)))
-
typedef struct DriverData_ {
void* data;
f_drvini ini;
f_drvdel del;
} DriverData;
+struct SoundInfo_ {
+ uint32_t sr;
+ uint8_t in, out;
+ m_str arg;
+};
+
+typedef void (*f_bbqset)(struct DriverData_*);
+typedef void (*f_bbqrun)(const struct VM_*);
+typedef struct BBQ_ {
+ uint64_t pos;
+ m_float* in;
+ m_float* out;
+ volatile uint is_running;
+ struct SoundInfo_ *si;
+ f_bbqset func;
+ f_bbqrun run;
+ struct DriverData_* driver;
+} Driver;
+
+#define DRVINI(a) ANN m_bool a(struct VM_ *vm __attribute__((unused)), Driver* di __attribute__((unused)))
+#define DRVRUN(a) ANN void a(struct VM_ *vm __attribute__((unused)), Driver* di __attribute__((unused)))
+#define DRVDEL(a) ANN void a(struct VM_ *vm __attribute__((unused)), Driver* di __attribute__((unused)))
+
ANN void dummy_driver(DriverData*);
-ANN void bbq_alloc(struct BBQ_*);
+ANN void driver_alloc(Driver*);
+ANN Driver* new_driver(void);
+ANN void free_driver(Driver*, struct VM_*);
#endif
+++ /dev/null
-#ifndef __SOUND
-#define __SOUND
-struct SoundInfo_ {
- uint32_t sr;
- uint8_t in, out;
- m_str arg;
-};
-#endif
HAS_OBJ
};
-struct VM_;
-struct DriverData_;
-typedef void (*f_bbqset)(struct DriverData_*);
-typedef void (*f_bbqrun)(const struct VM_*);
-struct BBQ_ {
- uint64_t pos;
- m_float* in;
- m_float* out;
- volatile uint is_running;
- struct SoundInfo_ *si;
- f_bbqset func;
- f_bbqrun run;
- struct DriverData_* driver;
-};
-
typedef struct Shreduler_* Shreduler;
typedef struct Emitter_ * Emitter;
typedef struct VM_ {
#include "vm.h"
#include "driver.h"
#include "arg.h"
-#include "sound.h"
#define GWIONRC ".gwionrc"
ANN static inline void config_end(const Vector config) {
#include "arg.h"
#include "gwion.h"
#include "compile.h"
-#include "sound.h"
#ifdef VMBENCH
#include <time.h>
#define VMBENCH_END
#endif
-ANN static struct BBQ_ * new_driverinfo(void) {
- struct BBQ_ * di = (struct BBQ_*)mp_alloc(BBQ);
- di->func = dummy_driver;
- di->run = vm_run;
- di->driver = (DriverData*)mp_alloc(DriverData);
- di->is_running = 1;
- return di;
-}
-
ANN m_bool gwion_audio(const Gwion gwion) {
- struct BBQ_ *di = gwion->vm->bbq;
- // get driver from string.
+ Driver* di = gwion->vm->bbq;
if(di->si->arg) {
for(m_uint i = 0; i < map_size(&gwion->plug->drv); ++i) {
const m_str name = (m_str)VKEY(&gwion->plug->drv, i);
}
}
di->func(di->driver);
- VM* vm = gwion->vm;
- CHECK_BB(di->driver->ini(vm, di));
- bbq_alloc(di);
+ CHECK_BB(di->driver->ini(gwion->vm, di));
+ driver_alloc(di);
return GW_OK;
}
gwion->emit->env = gwion->env;
gwion->vm->gwion = gwion;
gwion->env->gwion = gwion;
- gwion->vm->bbq = new_driverinfo();
gwion->vm->bbq->si = mp_alloc(SoundInfo);
gwion->vm->bbq->si->in = gwion->vm->bbq->si->out = 2;
gwion->vm->bbq->si->sr = 48000;
VMBENCH_END
}
-ANN /* static */ void free_driverinfo(struct BBQ_* bbq, VM* vm) {
- mp_free(SoundInfo, bbq->si);
- if(bbq->driver->del)
- bbq->driver->del(vm, bbq);
- mp_free(DriverData, bbq->driver);
- mp_free(BBQ, bbq);
-}
-
ANN void gwion_end(const Gwion gwion) {
free_env(gwion->env);
free_emitter(gwion->emit);
#include "import.h"
#include "emit.h"
#include "operator.h"
-#include "sound.h"
+#include "driver.h"
#define CHECK_OP(op, check, func) _CHECK_OP(op, check, int_##func)
#include "object.h"
#include "import.h"
#include "ugen.h"
-#include "sound.h"
+#include "driver.h"
ANN static inline void ugop_add (const UGen u, const m_float f) { u->in += f; }
ANN static inline void ugop_sub (const UGen u, const m_float f) { u->in -= f; }
#include "instr.h"
#include "object.h"
#include "import.h"
-#include "sound.h"
+#include "driver.h"
INSTR(VecCpy) {
POP_REG(shred, instr->m_val2);
#include "oo.h"
#include "vm.h"
#include "driver.h"
-#include "sound.h"
-ANN void bbq_alloc(struct BBQ_ *bbq) {
- bbq->out = (m_float*)xcalloc(bbq->si->out, SZ_FLOAT);
- bbq->in = (m_float*)xcalloc(bbq->si->in, SZ_FLOAT);
+ANN Driver* new_driver(void) {
+ Driver* di = (Driver*)mp_alloc(BBQ);
+ di->func = dummy_driver;
+ di->run = vm_run;
+ di->driver = (DriverData*)mp_alloc(DriverData);
+ di->is_running = 1;
+ return di;
+}
+
+ANN void free_driver(Driver *d, VM *vm) {
+ if(d->in)
+ xfree(d->in);
+ if(d->out)
+ xfree(d->out);
+ mp_free(SoundInfo, d->si);
+ if(d->driver->del)
+ d->driver->del(vm, d);
+ mp_free(DriverData, d->driver);
+ mp_free(BBQ, d);
+}
+
+ANN void driver_alloc(Driver *d) {
+ d->out = (m_float*)xcalloc(d->si->out, SZ_FLOAT);
+ d->in = (m_float*)xcalloc(d->si->in, SZ_FLOAT);
}
static DRVRUN(dummy_run) {
return GW_OK;
}
-void dummy_driver(DriverData* d) {
- d->ini = dummy_ini;
- d->run = dummy_run;
+void dummy_driver(DriverData* dd) {
+ dd->ini = dummy_ini;
+ dd->run = dummy_run;
}
#include "vm.h"
#include "object.h"
#include "shreduler_private.h"
+#include "driver.h"
ANN void shreduler_set_loop(const Shreduler s, const m_bool loop) {
s->loop = loop < 0 ? 0 : 1;
vm->shreduler->vm = vm;
vector_init(&vm->shreduler->shreds);
vector_init(&vm->ugen);
+ vm->bbq = new_driver();
gw_seed(vm->rand, (uint64_t)time(NULL));
return vm;
}
ANN void free_vm(VM* vm) {
vector_release(&vm->shreduler->shreds);
vector_release(&vm->ugen);
- struct BBQ_* bbq = vm->bbq;
- if(vm->bbq) {
- if(vm->bbq->in)
- xfree(vm->bbq->in);
- if(vm->bbq->out)
- xfree(vm->bbq->out);
- free_driverinfo(vm->bbq, vm);
- }
+ if(vm->bbq)
+ free_driver(vm->bbq, vm);
xfree(vm->shreduler);
free(vm);
}