summaryrefslogtreecommitdiff
path: root/src/libs/sig/ops_min.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2020-02-03 15:02:14 -0800
committerVito Caputo <vcaputo@pengaru.com>2020-02-03 15:02:14 -0800
commitda8c82023ed772ab91a71d034d8995373704f58e (patch)
tree2f970d653e4269083ee73d1764fec8be1e957a4f /src/libs/sig/ops_min.c
parenta88b3a6bd7de2f00457f628e70349fe383919efd (diff)
libs/sig: add sig_ops_{max,min}
Supply two sig_t *'s: a, b
Diffstat (limited to 'src/libs/sig/ops_min.c')
-rw-r--r--src/libs/sig/ops_min.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/libs/sig/ops_min.c b/src/libs/sig/ops_min.c
new file mode 100644
index 0000000..bda80d9
--- /dev/null
+++ b/src/libs/sig/ops_min.c
@@ -0,0 +1,62 @@
+#include <assert.h>
+
+#include "sig.h"
+
+
+typedef struct ops_min_ctxt_t {
+ sig_t *a, *b;
+} ops_min_ctxt_t;
+
+
+static size_t ops_min_size(va_list ap)
+{
+ return sizeof(ops_min_ctxt_t);
+}
+
+
+/* supply two sig_t's to be multiplied, this sig_t takes
+ * ownership of them so they'll be freed by the multiplier
+ * on destroy when that sig_t is freed.
+ */
+static void ops_min_init(void *context, va_list ap)
+{
+ ops_min_ctxt_t *ctxt = context;
+
+ assert(ctxt);
+
+ ctxt->a = va_arg(ap, sig_t *);
+ ctxt->b = va_arg(ap, sig_t *);
+}
+
+
+static void ops_min_destroy(void *context)
+{
+ ops_min_ctxt_t *ctxt = context;
+
+ assert(ctxt);
+
+ sig_free(ctxt->a);
+ sig_free(ctxt->b);
+}
+
+
+static float ops_min_output(void *context, unsigned ticks_ms)
+{
+ ops_min_ctxt_t *ctxt = context;
+ float a, b;
+
+ assert(ctxt);
+
+ a = sig_output(ctxt->a, ticks_ms);
+ b = sig_output(ctxt->b, ticks_ms);
+
+ return a < b ? a : b;
+}
+
+
+sig_ops_t sig_ops_min = {
+ .size = ops_min_size,
+ .init = ops_min_init,
+ .destroy = ops_min_destroy,
+ .output = ops_min_output,
+};
© All Rights Reserved