summaryrefslogtreecommitdiff
path: root/src/libs/sig/ops_sub.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2020-02-03 16:28:01 -0800
committerVito Caputo <vcaputo@pengaru.com>2020-02-03 16:28:01 -0800
commit56ccd8fe1c195b7b204aef430b75b67e37481ef7 (patch)
tree34e91b1ed74130122db1125a9aab18bbdf4d48e1 /src/libs/sig/ops_sub.c
parent9fc2bb60b405ae3c2153c6842972e183f939acc0 (diff)
libs/sig: add sig_ops_{add,sub}
Diffstat (limited to 'src/libs/sig/ops_sub.c')
-rw-r--r--src/libs/sig/ops_sub.c54
1 files changed, 54 insertions, 0 deletions
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,
+};
© All Rights Reserved