summaryrefslogtreecommitdiff
path: root/src
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
parenta88b3a6bd7de2f00457f628e70349fe383919efd (diff)
libs/sig: add sig_ops_{max,min}
Supply two sig_t *'s: a, b
Diffstat (limited to 'src')
-rw-r--r--src/libs/sig/Makefile.am2
-rw-r--r--src/libs/sig/ops_max.c62
-rw-r--r--src/libs/sig/ops_min.c62
-rw-r--r--src/libs/sig/sig.h2
4 files changed, 127 insertions, 1 deletions
diff --git a/src/libs/sig/Makefile.am b/src/libs/sig/Makefile.am
index ce99edc..efec325 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_floor.c ops_lerp.c ops_mult.c ops_pow.c ops_rand.c ops_round.c ops_sin.c sig.c sig.h
+libsig_a_SOURCES = ops_abs.c ops_ceil.c ops_clamp.c ops_const.c ops_floor.c ops_lerp.c ops_max.c ops_min.c ops_mult.c ops_pow.c ops_rand.c ops_round.c ops_sin.c sig.c sig.h
libsig_a_CPPFLAGS = -I@top_srcdir@/src
diff --git a/src/libs/sig/ops_max.c b/src/libs/sig/ops_max.c
new file mode 100644
index 0000000..9065027
--- /dev/null
+++ b/src/libs/sig/ops_max.c
@@ -0,0 +1,62 @@
+#include <assert.h>
+
+#include "sig.h"
+
+
+typedef struct ops_max_ctxt_t {
+ sig_t *a, *b;
+} ops_max_ctxt_t;
+
+
+static size_t ops_max_size(va_list ap)
+{
+ return sizeof(ops_max_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_max_init(void *context, va_list ap)
+{
+ ops_max_ctxt_t *ctxt = context;
+
+ assert(ctxt);
+
+ ctxt->a = va_arg(ap, sig_t *);
+ ctxt->b = va_arg(ap, sig_t *);
+}
+
+
+static void ops_max_destroy(void *context)
+{
+ ops_max_ctxt_t *ctxt = context;
+
+ assert(ctxt);
+
+ sig_free(ctxt->a);
+ sig_free(ctxt->b);
+}
+
+
+static float ops_max_output(void *context, unsigned ticks_ms)
+{
+ ops_max_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_max = {
+ .size = ops_max_size,
+ .init = ops_max_init,
+ .destroy = ops_max_destroy,
+ .output = ops_max_output,
+};
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,
+};
diff --git a/src/libs/sig/sig.h b/src/libs/sig/sig.h
index 194bdcf..bc2b28b 100644
--- a/src/libs/sig/sig.h
+++ b/src/libs/sig/sig.h
@@ -32,6 +32,8 @@ extern sig_ops_t sig_ops_ceil;
extern sig_ops_t sig_ops_clamp;
extern sig_ops_t sig_ops_floor;
extern sig_ops_t sig_ops_lerp;
+extern sig_ops_t sig_ops_max;
+extern sig_ops_t sig_ops_min;
extern sig_ops_t sig_ops_mult;
extern sig_ops_t sig_ops_pow;
extern sig_ops_t sig_ops_round;
© All Rights Reserved