aboutsummaryrefslogtreecommitdiff
path: root/preset_work.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2020-02-18 19:15:12 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2020-02-18 19:15:12 +0100
commit4ec4b2115aafd4c306d6453217ea219a1abb8235 (patch)
tree4fa084e960757e065dd3b165a44069e0bf12b3f8 /preset_work.c
parent1b114731ca6a3efca04a50627bcc412fc6368e7e (diff)
downloadjit.lv2-4ec4b2115aafd4c306d6453217ea219a1abb8235.tar.xz
redesign worker api for zero-copy operations.
Diffstat (limited to 'preset_work.c')
-rw-r--r--preset_work.c101
1 files changed, 56 insertions, 45 deletions
diff --git a/preset_work.c b/preset_work.c
index b1218b8..a39d8c4 100644
--- a/preset_work.c
+++ b/preset_work.c
@@ -8,34 +8,6 @@ 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)
{
@@ -44,8 +16,6 @@ init(jit_t *const jit)
plug_t *plug = calloc(1, sizeof(plug_t));
jit_assert(jit, plug);
- produce_val(jit);
-
return plug;
}
@@ -61,50 +31,91 @@ deinit(jit_t *const jit, void *const data)
}
static void
+_drain_val(jit_t *const jit, plug_t *plug)
+{
+ const float *val;
+ size_t len;
+
+ while( (val = jit_work_read_request(jit, &len)) )
+ {
+ plug->val = *val;
+
+ jit_work_read_advance(jit);
+ }
+}
+
+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)) )
+ {
+ *dummy = 0;
+
+ jit_work_write_advance(jit, len);
+ }
+}
+
+static void
run(jit_t *const jit, void *const data)
{
plug_t *plug = data;
jit_assert(jit, plug);
- request_val(jit);
+ _drain_val(jit, plug);
+ _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_out[n][i] = plug->val * jit->audio_in[n][i];
}
}
}
static void
-work_schedule(jit_t *const jit, void *const data JIT_UNUSED,
- void const *const buf JIT_UNUSED, size_t len JIT_UNUSED)
+_drain_dummy(jit_t *const jit)
{
- jit_printf(jit, "[%s]", __func__);
+ const uint32_t *dummy;
+ size_t len;
- produce_val(jit);
+ while( (dummy= jit_work_read_request(jit, &len)) )
+ {
+ jit_work_read_advance(jit);
+ }
}
static void
-work_response(jit_t *const jit, void *const data, void const *const buf,
- size_t len JIT_UNUSED)
+_produce_val(jit_t *const jit)
{
- jit_printf(jit, "[%s]", __func__);
+ float *val;
+ const size_t len = sizeof(float);
- plug_t *plug = data;
- jit_assert(jit, plug);
+ if( (val = jit_work_write_request(jit, len)) )
+ {
+ *val = (float)rand() / RAND_MAX;
+
+ jit_work_write_advance(jit, len);
+ }
+}
+
+static void
+work(jit_t *const jit, void *const data JIT_UNUSED)
+{
+ jit_printf(jit, "[%s]", __func__);
- float const *const val = buf;
- plug->val = *val;
+ _drain_dummy(jit);
+ _produce_val(jit);
}
JIT_EXPORT jit_desc_t const jit_desc = {
.init = init,
.deinit = deinit,
.run = run,
- .work_schedule = work_schedule,
- .work_response = work_response
+ .work = work
};
// vim: set syntax=c: