diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-02-03 16:28:01 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-02-03 16:28:01 -0800 |
commit | 56ccd8fe1c195b7b204aef430b75b67e37481ef7 (patch) | |
tree | 34e91b1ed74130122db1125a9aab18bbdf4d48e1 /src | |
parent | 9fc2bb60b405ae3c2153c6842972e183f939acc0 (diff) |
libs/sig: add sig_ops_{add,sub}
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/sig/Makefile.am | 2 | ||||
-rw-r--r-- | src/libs/sig/ops_add.c | 54 | ||||
-rw-r--r-- | src/libs/sig/ops_sub.c | 54 | ||||
-rw-r--r-- | src/libs/sig/sig.h | 2 |
4 files changed, 111 insertions, 1 deletions
diff --git a/src/libs/sig/Makefile.am b/src/libs/sig/Makefile.am index 8ee3dbe..55eccd0 100644 --- a/src/libs/sig/Makefile.am +++ b/src/libs/sig/Makefile.am @@ -1,3 +1,3 @@ noinst_LIBRARIES = libsig.a -libsig_a_SOURCES = ops_abs.c ops_ceil.c ops_clamp.c ops_const.c ops_expand.c ops_floor.c ops_inv.c ops_lerp.c ops_max.c ops_min.c ops_mult.c ops_pow.c ops_rand.c ops_round.c ops_scale.c ops_sin.c sig.c sig.h +libsig_a_SOURCES = ops_abs.c ops_add.c ops_ceil.c ops_clamp.c ops_const.c ops_expand.c ops_floor.c ops_inv.c ops_lerp.c ops_max.c ops_min.c ops_mult.c ops_pow.c ops_rand.c ops_round.c ops_scale.c ops_sin.c ops_sub.c sig.c sig.h libsig_a_CPPFLAGS = -I@top_srcdir@/src diff --git a/src/libs/sig/ops_add.c b/src/libs/sig/ops_add.c new file mode 100644 index 0000000..2b6c41d --- /dev/null +++ b/src/libs/sig/ops_add.c @@ -0,0 +1,54 @@ +#include <assert.h> + +#include "sig.h" + + +typedef struct ops_add_ctxt_t { + sig_t *a, *b; +} ops_add_ctxt_t; + + +static size_t ops_add_size(va_list ap) +{ + return sizeof(ops_add_ctxt_t); +} + + +static void ops_add_init(void *context, va_list ap) +{ + ops_add_ctxt_t *ctxt = context; + + assert(ctxt); + + ctxt->a = va_arg(ap, sig_t *); + ctxt->b = va_arg(ap, sig_t *); +} + + +static void ops_add_destroy(void *context) +{ + ops_add_ctxt_t *ctxt = context; + + assert(ctxt); + + sig_free(ctxt->a); + sig_free(ctxt->b); +} + + +static float ops_add_output(void *context, unsigned ticks_ms) +{ + ops_add_ctxt_t *ctxt = context; + + assert(ctxt); + + return sig_output(ctxt->a, ticks_ms) + sig_output(ctxt->b, ticks_ms); +} + + +sig_ops_t sig_ops_add = { + .size = ops_add_size, + .init = ops_add_init, + .destroy = ops_add_destroy, + .output = ops_add_output, +}; diff --git a/src/libs/sig/ops_sub.c b/src/libs/sig/ops_sub.c new file mode 100644 index 0000000..15fed1b --- /dev/null +++ b/src/libs/sig/ops_sub.c @@ -0,0 +1,54 @@ +#include <assert.h> + +#include "sig.h" + + +typedef struct ops_sub_ctxt_t { + sig_t *a, *b; +} ops_sub_ctxt_t; + + +static size_t ops_sub_size(va_list ap) +{ + return sizeof(ops_sub_ctxt_t); +} + + +static void ops_sub_init(void *context, va_list ap) +{ + ops_sub_ctxt_t *ctxt = context; + + assert(ctxt); + + ctxt->a = va_arg(ap, sig_t *); + ctxt->b = va_arg(ap, sig_t *); +} + + +static void ops_sub_destroy(void *context) +{ + ops_sub_ctxt_t *ctxt = context; + + assert(ctxt); + + sig_free(ctxt->a); + sig_free(ctxt->b); +} + + +static float ops_sub_output(void *context, unsigned ticks_ms) +{ + ops_sub_ctxt_t *ctxt = context; + + assert(ctxt); + + return sig_output(ctxt->a, ticks_ms) - sig_output(ctxt->b, ticks_ms); +} + + +sig_ops_t sig_ops_sub = { + .size = ops_sub_size, + .init = ops_sub_init, + .destroy = ops_sub_destroy, + .output = ops_sub_output, +}; diff --git a/src/libs/sig/sig.h b/src/libs/sig/sig.h index f6cb189..653202c 100644 --- a/src/libs/sig/sig.h +++ b/src/libs/sig/sig.h @@ -28,6 +28,7 @@ extern sig_ops_t sig_ops_sqr; */ extern sig_ops_t sig_ops_abs; +extern sig_ops_t sig_ops_add; extern sig_ops_t sig_ops_ceil; extern sig_ops_t sig_ops_clamp; extern sig_ops_t sig_ops_expand; @@ -40,5 +41,6 @@ extern sig_ops_t sig_ops_mult; extern sig_ops_t sig_ops_pow; extern sig_ops_t sig_ops_round; extern sig_ops_t sig_ops_scale; +extern sig_ops_t sig_ops_sub; #endif |