aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--VERSION2
-rw-r--r--preset_work.c60
2 files changed, 41 insertions, 21 deletions
diff --git a/VERSION b/VERSION
index 0e4bed1..759f8fc 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.397
+0.1.411
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
};