aboutsummaryrefslogtreecommitdiff
path: root/preset_work.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2020-02-19 09:54:28 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2020-02-19 09:54:28 +0100
commit95ac39d28288c4a6144af0ca61241178fc6e81e2 (patch)
treeea4d76dc2c2c7ac3d73d6fcfca584340db9f43bb /preset_work.c
parent4ec4b2115aafd4c306d6453217ea219a1abb8235 (diff)
downloadjit.lv2-95ac39d28288c4a6144af0ca61241178fc6e81e2.tar.xz
finalize redesign of zero-copy worker api.
Diffstat (limited to 'preset_work.c')
-rw-r--r--preset_work.c64
1 files changed, 13 insertions, 51 deletions
diff --git a/preset_work.c b/preset_work.c
index a39d8c4..4b0871f 100644
--- a/preset_work.c
+++ b/preset_work.c
@@ -2,76 +2,43 @@
#include <stddef.h>
#include <stdlib.h>
-typedef struct _plug_t plug_t;
-
-struct _plug_t {
- float val;
-};
-
-static void *
-init(jit_t *const jit)
+static float
+_drain_val(jit_t *const jit)
{
- jit_printf(jit, "[%s]", __func__);
-
- plug_t *plug = calloc(1, sizeof(plug_t));
- jit_assert(jit, plug);
-
- 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
-_drain_val(jit_t *const jit, plug_t *plug)
-{
- const float *val;
+ float const *val;
size_t len;
+ float gain = 0.f;
while( (val = jit_work_read_request(jit, &len)) )
{
- plug->val = *val;
+ gain = *val;
jit_work_read_advance(jit);
}
+
+ return gain;
}
static void
_wake_worker(jit_t *const jit)
{
- uint32_t *dummy;
- const size_t len = sizeof(uint32_t);
-
- if( (dummy = jit_work_write_request(jit, len)) )
+ if(jit_work_write_request(jit, 0))
{
- *dummy = 0;
-
- jit_work_write_advance(jit, len);
+ jit_work_write_advance(jit, 0);
}
}
static void
-run(jit_t *const jit, void *const data)
+run(jit_t *const jit, void *const data JIT_UNUSED)
{
- plug_t *plug = data;
- jit_assert(jit, plug);
-
- _drain_val(jit, plug);
+ float const gain = _drain_val(jit);
_wake_worker(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 * jit->audio_in[n][i];
+ jit->audio_out[n][i] = gain * jit->audio_in[n][i];
}
}
}
@@ -79,10 +46,9 @@ run(jit_t *const jit, void *const data)
static void
_drain_dummy(jit_t *const jit)
{
- const uint32_t *dummy;
size_t len;
- while( (dummy= jit_work_read_request(jit, &len)) )
+ while(jit_work_read_request(jit, &len))
{
jit_work_read_advance(jit);
}
@@ -105,15 +71,11 @@ _produce_val(jit_t *const jit)
static void
work(jit_t *const jit, void *const data JIT_UNUSED)
{
- jit_printf(jit, "[%s]", __func__);
-
_drain_dummy(jit);
_produce_val(jit);
}
JIT_EXPORT jit_desc_t const jit_desc = {
- .init = init,
- .deinit = deinit,
.run = run,
.work = work
};