#include "driver.h"
#include "gwi.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; }
-ANN static inline void ugop_mul (const UGen u, const m_float f) { u->in *= f; }
-ANN static inline void ugop_div (const UGen u, const m_float f) { u->in /= f; }
-
static TICK(dac_tick) {
m_float* out = ((VM*)u->module.gen.data)->bbq->out;
uint i = 0;
for(uint i = 1; i < size; ++i) {
const UGen w = (UGen)vector_at(vec, i);
COMPUTE(w)
- u->op(u, w->out);
+ static const void* dispatch[] = { &&add, &&sub, &&mul, &&div };
+ do {
+ goto *dispatch[u->op];
+ add:
+ u->in += w->out;
+ break;
+ sub:
+ u->in -= w->out;
+ break;
+ mul:
+ u->in *= w->out;
+ break;
+ div:
+ u->in *= w->out;
+ break;
+ }while(0);
}
}
}
ANEW static UGen new_UGen(MemPool p) {
const UGen u = mp_calloc(p, UGen);
- u->op = ugop_add;
+ u->op = 0;
u->compute = gen_compute_mono;
return u;
}
}
static MFUN(ugen_get_op) {
- const f_ugop f = UGEN(o)->op;
- if(f == ugop_add)
- *(m_uint*)RETURN = 1;
- else if(f == ugop_sub)
- *(m_uint*)RETURN = 2;
- else if(f == ugop_mul)
- *(m_uint*)RETURN = 3;
- else if(f == ugop_div)
- *(m_uint*)RETURN = 4;
-}
-
-ANN static void set_op(const UGen u, const f_ugop f) {
+ *(m_uint*)RETURN = UGEN(o)->op;
+}
+
+ANN static void set_op(const UGen u, const uint f) {
if(u->multi) {
for(uint i = u->connect.multi->n_chan + 1; --i;)
UGEN(u->connect.multi->channel[i-1])->op = f;
static MFUN(ugen_set_op) {
const m_int i = *(m_int*)MEM(SZ_INT);
- if(i == 1)
- set_op(UGEN(o), ugop_add);
- else if(i == 2)
- set_op(UGEN(o), ugop_sub);
- else if(i == 3)
- set_op(UGEN(o), ugop_mul);
- else if(i == 4)
- set_op(UGEN(o), ugop_div);
+ if(i >= 1 && i <= 4)
+ set_op(UGEN(o), i-1);
*(m_int*)RETURN = i;
}