aboutsummaryrefslogtreecommitdiff
path: root/preset_work.c
diff options
context:
space:
mode:
Diffstat (limited to 'preset_work.c')
-rw-r--r--preset_work.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/preset_work.c b/preset_work.c
new file mode 100644
index 0000000..b1218b8
--- /dev/null
+++ b/preset_work.c
@@ -0,0 +1,111 @@
+#include <jit.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+typedef struct _plug_t plug_t;
+
+struct _plug_t {
+ float val;
+};
+
+static void
+produce_val(jit_t *const jit)
+{
+ float *val;
+ const size_t len = sizeof(float);
+
+ if( (val= jit_work_request(jit, len)) )
+ {
+ *val = (float)rand() / RAND_MAX;
+
+ jit_work_advance(jit, len);
+ }
+}
+
+static void
+request_val(jit_t *const jit)
+{
+ uint32_t *dummy;
+ const size_t len = sizeof(uint32_t);
+
+ if( (dummy = jit_work_request(jit, len)) )
+ {
+ *dummy = 0;
+
+ jit_work_advance(jit, len);
+ }
+}
+
+static void *
+init(jit_t *const jit)
+{
+ jit_printf(jit, "[%s]", __func__);
+
+ plug_t *plug = calloc(1, sizeof(plug_t));
+ jit_assert(jit, plug);
+
+ produce_val(jit);
+
+ return plug;
+}
+
+static void
+deinit(jit_t *const jit, void *const data)
+{
+ jit_printf(jit, "[%s]", __func__);
+
+ plug_t *plug = data;
+ jit_assert(jit, plug);
+
+ free(plug);
+}
+
+static void
+run(jit_t *const jit, void *const data)
+{
+ plug_t *plug = data;
+ jit_assert(jit, plug);
+
+ request_val(jit);
+
+ for(uint32_t n = 0; n < jit->nchannels; n++)
+ {
+ for(uint32_t i = 0; i < jit->nsamples; i++)
+ {
+ jit->audio_out[n][i] = plug->val;
+ }
+ }
+}
+
+static void
+work_schedule(jit_t *const jit, void *const data JIT_UNUSED,
+ void const *const buf JIT_UNUSED, size_t len JIT_UNUSED)
+{
+ jit_printf(jit, "[%s]", __func__);
+
+ produce_val(jit);
+}
+
+static void
+work_response(jit_t *const jit, void *const data, void const *const buf,
+ size_t len JIT_UNUSED)
+{
+ jit_printf(jit, "[%s]", __func__);
+
+ plug_t *plug = data;
+ jit_assert(jit, plug);
+
+ float const *const val = buf;
+ plug->val = *val;
+}
+
+JIT_EXPORT jit_desc_t const jit_desc = {
+ .init = init,
+ .deinit = deinit,
+ .run = run,
+ .work_schedule = work_schedule,
+ .work_response = work_response
+};
+
+// vim: set syntax=c:
+// jit: gcc -std=c11 -ffast-math -fvisibility=hidden -O3 -shared -fpic -fPIC -Wall -Wextra -Wpedantic -Wl,-z,defs -I %b -o %o -xc %i -lm 2>&1: