struct Vector_ add;
struct Vector_ lib;
struct Vector_ mod;
+ struct SoundInfo_ *si;
m_bool loop;
} Arg;
ANN void arg_release(Arg*);
-ANN void arg_parse(Arg*, DriverInfo*);
+ANN void arg_parse(Arg*);
#endif
#ifndef __DRIVER
#define __DRIVER
-struct Driver_;
-
-typedef void (*f_diset)(struct Driver_*);
-typedef void (*f_dirun)(const VM*);
-
-typedef struct DriverInfo_ {
- uint32_t sr;
- m_str arg;
- f_diset func;
- f_dirun run;
- void* data;
- struct Driver_* driver;
- uint8_t in, out;
-} DriverInfo;
-
-typedef m_bool (*f_drvini)(VM*, DriverInfo*);
-typedef void (*f_drvrun)(VM* vm, struct DriverInfo_*);
-typedef void (*f_drvdel)(VM* vm, struct DriverInfo_*);
+typedef struct BBQ_ DriverInfo;
+typedef m_bool (*f_drvini)(VM*, struct BBQ_*);
+typedef void (*f_drvrun)(VM*, struct BBQ_*);
+typedef void (*f_drvdel)(VM*, struct BBQ_*);
typedef struct Driver_ {
f_drvini ini;
f_drvrun run;
f_drvdel del;
+ void* data;
} Driver;
-void dummy_driver(Driver*);
-ANN struct BBQ_* new_bbq(DriverInfo*);
+ANN void dummy_driver(Driver*);
+ANN void bbq_alloc(DriverInfo*);
#endif
#include "driver.h"
struct Gwion_ {
PlugInfo* plug;
- DriverInfo* di;
+// DriverInfo* di;
struct Arg_* arg;
// sym
// mem
--- /dev/null
+#ifndef __SOUND
+#define __SOUND
+struct SoundInfo_ {
+ uint32_t sr;
+ uint8_t in, out;
+ m_str arg;
+};
+#endif
HAS_OBJ
};
+struct VM_;
+struct Driver_;
+typedef void (*f_bbqset)(struct Driver_*);
+typedef void (*f_bbqrun)(const struct VM_*);
struct BBQ_ {
uint64_t pos;
m_float* in;
m_float* out;
- uint32_t sr; // int 32
- uint8_t n_in;
- uint8_t n_out;
volatile uint is_running;// : 1; // => shreduler
+ struct SoundInfo_ *si;
+ f_bbqset func;
+ f_bbqrun run;
+ struct Driver_* driver;
};
typedef struct Shreduler_* Shreduler;
#include "vm.h"
#include "driver.h"
#include "arg.h"
+#include "sound.h"
ANN static void arg_init(Arg* arg) {
vector_init(&arg->add);
"\t--sr -s\t <number> : set samplerate\n"
;
-ANN static inline void arg_add(Arg* arg) {
+ANN static inline void arg_add(Arg *arg) {
while(optind < arg->argc)
vector_add(&arg->add, (vtype)arg->argv[optind++]);
}
-ANN static void arg_drvr(DriverInfo* di, const int i) {
+ANN static void arg_drvr(struct SoundInfo_ *si, const int i) {
switch(i) {
case 'i':
- di->in = (m_uint)strtol(optarg, NULL, 10);
+ si->in = (m_uint)strtol(optarg, NULL, 10);
break;
case 'o':
- di->out = (m_uint)strtol(optarg, NULL, 10);
+ si->out = (m_uint)strtol(optarg, NULL, 10);
break;
case 's':
- di->sr = (uint)strtol(optarg, NULL, 10);
+ si->sr = (uint)strtol(optarg, NULL, 10);
break;
case 'd':
- di->arg = optarg;
+ si->arg = optarg;
break;
}
}
-ANN void arg_parse(Arg* arg, DriverInfo* di) {
+ANN void arg_parse(Arg* arg) {
int i, idx;
arg_init(arg);
while((i = getopt_long(arg->argc, arg->argv, "hl:i:o:s:d:m:p:c",
vector_add(&arg->mod, (vtype)optarg);
break;
default:
- arg_drvr(di, i);
+ arg_drvr(arg->si, i);
}
}
arg_add(arg);
#include "arg.h"
#include "gwion.h"
#include "compile.h"
+#include "sound.h"
#ifdef VMBENCH
#include <time.h>
ANN static DriverInfo* new_driverinfo(void) {
DriverInfo *di = (DriverInfo*)xcalloc(1, sizeof(DriverInfo));
- di->sr = 48000;
- di->in = di->out = 2;
di->func = dummy_driver;
di->run = vm_run;
di->driver = (Driver*)xcalloc(1, sizeof(Driver));
}
ANN m_bool gwion_audio(const Gwion gwion) {
- DriverInfo *di = gwion->di;
+ DriverInfo *di = gwion->vm->bbq;
// get driver from string.
- if(di->arg) {
+ 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);
const size_t len = strlen(name);
- if(!strncmp(name, di->arg, len)) {
- di->func = (f_diset)VVAL(&gwion->plug->drv, i);
+ if(!strncmp(name, di->si->arg, len)) {
+ di->func = (f_bbqset)VVAL(&gwion->plug->drv, i);
break;
}
}
}
di->func(di->driver);
VM* vm = gwion->vm;
- CHECK_BB(gwion->di->driver->ini(vm, di));
- vm->bbq = new_bbq(di);
+ CHECK_BB(di->driver->ini(vm, di));
+ bbq_alloc(di);
return GW_OK;
}
gwion->emit->env = gwion->env;
gwion->vm->gwion = gwion;
gwion->env->gwion = gwion;
- gwion->di = new_driverinfo();
+ gwion->vm->bbq = new_driverinfo();
gwion->arg = new_arg(argc, argv);
+ gwion->arg->si = mp_alloc(SoundInfo);
+ gwion->arg->si->in = gwion->arg->si->out = 2;
+ gwion->arg->si->sr = 48000;
gwion->plug = (PlugInfo*)xmalloc(sizeof(PlugInfo));
- arg_parse(gwion->arg, gwion->di);
+ arg_parse(gwion->arg);
+ gwion->vm->bbq->si = gwion->arg->si;
plug_discover(gwion->plug, &gwion->arg->lib);
shreduler_set_loop(gwion->vm->shreduler, gwion->arg->loop);
if(gwion_audio(gwion) > 0 && gwion_engine(gwion)) {
vm->bbq->is_running = 1;
plug_ini(gwion, &gwion->arg->mod);
VMBENCH_INI
- gwion->di->driver->run(vm, gwion->di);
+ vm->bbq->driver->run(vm, vm->bbq);
VMBENCH_END
}
-ANN static void free_driverinfo(DriverInfo* di, VM* vm) {
+ANN /* static */ void free_driverinfo(DriverInfo* di, VM* vm) {
+ mp_free(SoundInfo, di->si);
if(di->driver->del)
di->driver->del(vm, di);
xfree(di->driver);
xfree(di);
}
ANN void gwion_end(const Gwion gwion) {
- free_driverinfo(gwion->di, gwion->vm);
plug_end(gwion);
arg_release(gwion->arg);
xfree(gwion->arg);
free_env(gwion->env);
free_emitter(gwion->emit);
free_vm(gwion->vm);
+// free_driverinfo(gwion->vm->bbq, gwion->vm);
xfree(gwion->plug);
free_symbols();
}
#include "import.h"
#include "emit.h"
#include "operator.h"
+#include "sound.h"
#define CHECK_OP(op, check, func) _CHECK_OP(op, check, int_##func)
static GWION_IMPORT(values) {
VM* vm = gwi_vm(gwi);
ALLOC_PTR(d_zero, m_float, 0.0);
- ALLOC_PTR(sr, m_float, (m_float)vm->bbq->sr);
+ ALLOC_PTR(sr, m_float, (m_float)vm->bbq->si->sr);
ALLOC_PTR(samp, m_float, 1.0);
ALLOC_PTR(ms, m_float, (m_float)(*sr / 1000.));
ALLOC_PTR(second, m_float, (m_float)*sr);
#include "object.h"
#include "import.h"
#include "ugen.h"
+#include "sound.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; }
const VM* vm = gwi_vm(gwi);
struct ugen_importer hole = { vm, compute_mono, "blackhole", 1, NULL };
add_ugen(gwi, &hole);
- struct ugen_importer dac = { vm, dac_tick, "dac", vm->bbq->n_out, NULL };
+ struct ugen_importer dac = { vm, dac_tick, "dac", vm->bbq->si->out, NULL };
add_ugen(gwi, &dac);
- struct ugen_importer adc = { vm, adc_tick, "adc", vm->bbq->n_in, NULL };
+ struct ugen_importer adc = { vm, adc_tick, "adc", vm->bbq->si->in, NULL };
add_ugen(gwi, &adc);
ugen_connect(dac.ugen, hole.ugen);
SET_FLAG(t_ugen, abstract);
#include "instr.h"
#include "object.h"
#include "import.h"
+#include "sound.h"
INSTR(VecCpy) {
POP_REG(shred, instr->m_val2);
}
describe_vec3_x(interp, + v->x)
describe_vec3_x(float, * v->z * (*(m_float*)MEM(SZ_INT)) + v->x)
-describe_vec3_x(dur, * (*(m_float*)MEM(SZ_INT) / (m_float)shred->info->vm->bbq->sr) + v->x)
+describe_vec3_x(dur, * (*(m_float*)MEM(SZ_INT) / (m_float)shred->info->vm->bbq->si->sr) + v->x)
static MFUN(vec3_update) {
m_vec3* v = *(m_vec3**)MEM(0);
plug->end = DLFUNC(dl, modend, GWMODEND_NAME);
vector_add(&p->vec[GWPLUG_MODULE], (vtype)plug);
}
- const f_diset drv = DLFUNC(dl, f_diset, GWDRIVER_NAME);
+ const f_bbqset drv = DLFUNC(dl, f_bbqset, GWDRIVER_NAME);
if(drv) {
const modstr str = DLFUNC(dl, modstr, GWMODSTR_NAME);
map_set(&p->drv, (vtype)str(), (vtype)drv);
#include "oo.h"
#include "vm.h"
#include "driver.h"
+#include "sound.h"
-ANN struct BBQ_* new_bbq(DriverInfo* di) {
- struct BBQ_* bbq = (struct BBQ_*)xcalloc(1, sizeof(struct BBQ_));
- bbq->out = (m_float*)xcalloc(di->out, SZ_FLOAT);
- bbq->in = (m_float*)xcalloc(di->in, SZ_FLOAT);
- bbq->n_in = (uint8_t)di->in;
- bbq->sr = di->sr;
- bbq->n_out = (uint8_t)di->out;
- return bbq;
+ANN void bbq_alloc(DriverInfo* di) {
+ struct BBQ_* bbq = (struct BBQ_*)di;
+ bbq->out = (m_float*)xcalloc(di->si->out, SZ_FLOAT);
+ bbq->in = (m_float*)xcalloc(di->si->in, SZ_FLOAT);
}
static void dummy_run(VM* vm, DriverInfo* di) {
- while(vm->bbq->is_running) {
+ while(di->is_running) {
di->run(vm);
- ++vm->bbq->pos;
+ ++di->pos;
}
}
vector_release(&vm->shreduler->shreds);
vector_release(&vm->ugen);
if(vm->bbq) {
- xfree(vm->bbq->in);
- xfree(vm->bbq->out);
- xfree(vm->bbq);
+ if(vm->bbq->in)
+ xfree(vm->bbq->in);
+ if(vm->bbq->out)
+ xfree(vm->bbq->out);
+ free_driverinfo(vm->bbq, vm);
}
xfree(vm->shreduler);
free(vm);