From: fennecdjay Date: Wed, 13 Mar 2019 00:53:01 +0000 (+0100) Subject: :art: Some clean X-Git-Tag: nightly~2741 X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=5bc30b8988db721016a8b36c9e8a2069154a0d0e;p=gwion.git :art: Some clean --- diff --git a/include/driver.h b/include/driver.h index 2dc2956c..b336f6f8 100644 --- a/include/driver.h +++ b/include/driver.h @@ -5,10 +5,6 @@ typedef m_bool (*f_drvini)(struct VM_*, struct BBQ_*); 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; @@ -16,6 +12,31 @@ typedef struct DriverData_ { 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 diff --git a/include/sound.h b/include/sound.h deleted file mode 100644 index 5b4784a8..00000000 --- a/include/sound.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __SOUND -#define __SOUND -struct SoundInfo_ { - uint32_t sr; - uint8_t in, out; - m_str arg; -}; -#endif diff --git a/include/vm.h b/include/vm.h index 1e7c2715..4ba888ee 100644 --- a/include/vm.h +++ b/include/vm.h @@ -14,21 +14,6 @@ struct VM_Code_ { 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_ { diff --git a/src/arg.c b/src/arg.c index a30226a0..44a1d174 100644 --- a/src/arg.c +++ b/src/arg.c @@ -4,7 +4,6 @@ #include "vm.h" #include "driver.h" #include "arg.h" -#include "sound.h" #define GWIONRC ".gwionrc" ANN static inline void config_end(const Vector config) { diff --git a/src/gwion.c b/src/gwion.c index e9d8a2d2..d60af876 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -11,7 +11,6 @@ #include "arg.h" #include "gwion.h" #include "compile.h" -#include "sound.h" #ifdef VMBENCH #include @@ -26,18 +25,8 @@ #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); @@ -49,9 +38,8 @@ ANN m_bool gwion_audio(const Gwion gwion) { } } 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; } @@ -71,7 +59,6 @@ ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) { 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; @@ -94,14 +81,6 @@ ANN void gwion_run(const Gwion gwion) { 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); diff --git a/src/lib/prim.c b/src/lib/prim.c index fc44fa45..15f1764c 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -9,7 +9,7 @@ #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) diff --git a/src/lib/ugen.c b/src/lib/ugen.c index 3e9a2eb8..43be23a6 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -9,7 +9,7 @@ #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; } diff --git a/src/lib/vec.c b/src/lib/vec.c index 3f0e8ef4..00c9d747 100644 --- a/src/lib/vec.c +++ b/src/lib/vec.c @@ -7,7 +7,7 @@ #include "instr.h" #include "object.h" #include "import.h" -#include "sound.h" +#include "driver.h" INSTR(VecCpy) { POP_REG(shred, instr->m_val2); diff --git a/src/vm/driver.c b/src/vm/driver.c index d73e6f74..e025b7cb 100644 --- a/src/vm/driver.c +++ b/src/vm/driver.c @@ -8,11 +8,31 @@ #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) { @@ -26,7 +46,7 @@ static DRVINI(dummy_ini) { 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; } diff --git a/src/vm/shreduler.c b/src/vm/shreduler.c index 865f8457..025d7a56 100644 --- a/src/vm/shreduler.c +++ b/src/vm/shreduler.c @@ -5,6 +5,7 @@ #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; diff --git a/src/vm/vm.c b/src/vm/vm.c index 0aeb113c..3dc1c685 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -54,6 +54,7 @@ VM* new_vm(void) { 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; } @@ -71,14 +72,8 @@ void vm_remove(const VM* vm, const m_uint index) { 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); }