aboutsummaryrefslogtreecommitdiff
path: root/preset_work.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2021-04-22 20:26:21 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2021-04-22 20:26:21 +0200
commitbe6677824afbaa40ccd7e765b77189a0192b436d (patch)
tree3babe362adbf070de170d2d70ced823a3041cb71 /preset_work.c
parent51f2effceb09291979b8f4460113f51801324fe7 (diff)
downloadjit.lv2-be6677824afbaa40ccd7e765b77189a0192b436d.tar.xz
pset: create per-sample noise.
Diffstat (limited to 'preset_work.c')
-rw-r--r--preset_work.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/preset_work.c b/preset_work.c
index 75ddb9c..0d25cfd 100644
--- a/preset_work.c
+++ b/preset_work.c
@@ -4,21 +4,48 @@
#include <jit_api.h>
#include <jit_util.h>
+static void
+_produce_val(jit_t *const jit)
+{
+ float *val;
+ const size_t len = sizeof(float);
+
+ while( (val = jit_work_write_request(jit, len)) )
+ {
+ *val = (float)rand() / RAND_MAX - 0.5f;
+
+ jit_work_write_advance(jit, len);
+ }
+}
+
+static void *
+init(jit_t *const jit)
+{
+ // pre-fill ringbuffer with noise
+ _produce_val(jit);
+
+ return NULL;
+}
+
static float
_drain_val(jit_t *const jit)
{
float const *val;
size_t len;
- float gain = 0.f;
+ float noise = 0.f;
- while( (val = jit_work_read_request(jit, &len)) )
+ if( (val = jit_work_read_request(jit, &len)) )
{
- gain = *val;
+ noise = *val;
jit_work_read_advance(jit);
}
+ else
+ {
+ jit_printf(jit, "[%s] buffer underrun", __func__);
+ }
- return gain;
+ return noise;
}
static void
@@ -28,19 +55,24 @@ _wake_worker(jit_t *const jit)
{
jit_work_write_advance(jit, 0);
}
+ else
+ {
+ jit_printf(jit, "[%s] buffer overrun", __func__);
+ }
}
static void
run(jit_t *const jit, void *const data JIT_UNUSED)
{
- 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] = gain * jit->audio_in[n][i];
+ float const noise = _drain_val(jit);
+
+ jit->audio_out[n][i] = noise;
}
}
}
@@ -57,27 +89,15 @@ _drain_dummy(jit_t *const jit)
}
static void
-_produce_val(jit_t *const jit)
-{
- float *val;
- const size_t len = sizeof(float);
-
- 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)
{
_drain_dummy(jit);
+ // re-fill ringbuffer with noise
_produce_val(jit);
}
JIT_EXPORT jit_desc_t const jit_desc = {
+ .init = init,
.run = run,
.work = work
};